Typing glyphs on Linux: Difference between revisions

Jump to navigation Jump to search
2,603 bytes added ,  09:16, 29 June 2020
Add information about dealing with setxkbmap resets in X windows
(Extracted from "Typing Glyphs")
 
(Add information about dealing with setxkbmap resets in X windows)
Line 109: Line 109:


A tutorial specific to Xfce's config files can be found [https://github.com/hashslingrz/apl-keyboard-xfce at this GitHub repository].
A tutorial specific to Xfce's config files can be found [https://github.com/hashslingrz/apl-keyboard-xfce at this GitHub repository].
== Troubleshooting ==
=== Why do my settings keep getting forgotten during my X windows session? ===
Since at least March 2020 there have been issues with `setxkbmap` settings being reset without user instruction under X windows.
Below is a script written in Raku that continuously checks for this undesirable reset behavior and puts the intended settings back in place. It is described in more detail in the blog post [https://5ab5traction5.bearblog.dev/apl-keyboard-keeper/ Raku to the Rescue: APL Keyboard Keeper].
<source>
#!/usr/bin/env raku
# Small script to ensure that APL keyboard layout is still set in xkb settings.
# Note that this is a patch for some sort of deranged time-based reset of these
# settings that is happening at a lower level of the Xorg-based Linux user experience.
#
# It's not clear what is causing these resets but this script allows us to more
# or less not care about it and get on with our hacking.
#
# Released under Artistic License by John Longwalker 2020
my $total-checks = 0;
sub xkbmap-contains-apl() {
  $total-checks++;
  so qx{ setxkbmap -query | grep '^layout:.*\<apl\>' }; # shell-out is easy as usual in a Perl
}
my $total-resets = 0;
sub set-xkbmap-for-apl($key, $verbose) {
  say "Reset total is now {++$total-resets} -- {DateTime.now}"
  if $verbose;
  my $xkb-settings = chomp qx{ setxkbmap -query };
  my ($layout, $variant, $options);
  if $xkb-settings ~~ /^^ "layout:" \s* $<layout>=(<.graph>*) $$/ {
  $layout = $<layout>.Str;
  } else {
  die "Aborting. The xkb settings do not specify any layout:\n$xkb-settings";
  }
  if $xkb-settings ~~ /^^ "variant:" \s* $<variant>=(<.graph>*) $$/ {
  $variant = $<variant>.Str;
  }
  if $xkb-settings ~~ /^^ "options:" \s* $<options>=(<.graph>*) $$/ {
  $options = $<options>.Str;
  }
  $layout  = ($layout, 'apl').join(',');
  $variant = $variant ?? ($variant, 'dyalog')
                      !! 'dyalog';
  $options = $options ?? ($options, "grp:$key").join(',')
                      !! "grp:$key";
  my $invocation = "setxkbmap -layout $layout -variant $variant -option $options";
  say "Invocation: $invocation"
    if $verbose;
  qqx{ $invocation };
}
# You can use --interval, --key, and -v/--verbose on the command line.
sub MAIN(:$interval = 30, :$key = 'switch', :v($verbose) = False) {
  react {
    whenever Supply.interval($interval) {
      set-xkbmap-for-apl($key, $verbose)
        if not xkbmap-contains-apl;
    }
    whenever signal(SIGINT) {
      say "Reset a total of $total-resets out of $total-checks checks"
      if $verbose;
      exit;
    }
  }
}
</source>


== References ==
== References ==
3

edits

Navigation menu