Typing glyphs on Linux: Difference between revisions

Jump to navigation Jump to search
10,263 bytes added ,  15:59, 19 July 2021
Add entry on xmodmap
(Extracted from "Typing Glyphs")
 
(Add entry on xmodmap)
(17 intermediate revisions by 6 users not shown)
Line 1: Line 1:
Since mid-2012, most Linux distributions with [[wikipedia:X_Window_System|X11]] have [[Dyalog APL]] keyboard support included with the distribution,<ref>[[Dyalog]] [[Forums]]. [https://forums.dyalog.com/viewtopic.php?f=20&t=210 Keyboard setup on Linux]. Sep 21, 2010.</ref> using <source lang=console inline>xkb</source>, the [https://www.x.org/wiki/XKB/ X Keyboard Extension].<ref>[[Geoff Streeter]]. [https://www.dyalog.com/uploads/conference/dyalog10/presentations/P19_Streeter_Keyboards.pdf Supporting APL keyboards on Linux]. [[Dyalog '10]].</ref>
Since mid-2012, most Linux distributions with [[wikipedia:X_Window_System|X11]] have [[Dyalog APL]] keyboard support included with the distribution,<ref>[[Dyalog]] [[Forums]]. [https://forums.dyalog.com/viewtopic.php?f=20&t=210 Keyboard setup on Linux]. Sep 21, 2010.</ref> using <source lang=console inline>xkb</source>, the [https://www.x.org/wiki/XKB/ X Keyboard Extension].<ref name="Dyalog APL XKB">[[Geoff Streeter]]. [https://www.dyalog.com/uploads/conference/dyalog10/presentations/P19_Streeter_Keyboards.pdf Supporting APL keyboards on Linux]. [[Dyalog '10]].</ref>


== setxkbmap ==
== setxkbmap ==
Line 19: Line 19:
A full list of keys that can be used to switch layouts is included in <source lang=console inline>/usr/share/X11/xkb/rules/evdev.lst</source> under the <source lang=console inline>option</source> category.
A full list of keys that can be used to switch layouts is included in <source lang=console inline>/usr/share/X11/xkb/rules/evdev.lst</source> under the <source lang=console inline>option</source> category.


'''Note:''' these changes are not permanent; the user will have to select one of a myriad of methods to run the command on startup. Alternatively, if they use one of the [[wikipedia:Desktop_environment|desktop environments]] listed below, they can follow those instructions.
Note:
 
* These changes are not permanent; the user will have to select one of a myriad of methods to run the command on startup. Alternatively, if they use one of the [[wikipedia:Desktop_environment|desktop environments]] listed below, they can follow those instructions.
 
* If you want to specify a different language, say for United Kingdom, specify <source lang=console inline>gb</source> instead of <source lang=console inline>us</source> (not <source lang=console inline>uk</source>)


== GNOME ==
== GNOME ==
Line 105: Line 109:
X-MATE-Autostart-Delay=0
X-MATE-Autostart-Delay=0
</source>
</source>
== Wayland ==
Currently, [https://en.wikipedia.org/wiki/Wayland_%28display_server_protocol%29 Wayland] uses [https://www.x.org/wiki/XKB/ XKB] for keyboards, but they are not modifiable during runtime using e.g. <code lang=console>setxkbmap</code> by default. The keyboard layout must be configured and then the session restarted.
=== GNOME Tweaks ===
The [https://wiki.gnome.org/Apps/Tweaks Tweaks] tool allows configuration beyond the defaults enabled in GNOME.
# Install GNOME Tweaks using [https://wiki.debian.org/Apt apt] or [https://fedoraproject.org/wiki/DNF dnf], or by searching your distribution's Software Center.
# Start GNOME Tweaks by either:
## Using a terminal, type <code lang=console>gnome-tweaks</code> and press <kbd>Enter</kbd>.
## Using the GUI:
### Open the Activities menu; this is located in the top-left corner of a default GNOME 3 session (alternatively, use your <kbd>Super</kbd> key to open the Activities overlay):<br>[[File:Gnome-kbd-setup-1.png|frameless|Wayland Keyboard set up with GNOME Tweaks Step 2.1: Open Activities Menu]]
### Search for "Tweaks"<br>[[File:GnomeTweaks.png|frameless|200px|Wayland Keyboard set up with GNOME Tweaks Step 2.2: Start GNOME Tweaks]]
# Open Keyboard & Mouse Panel and enable "Show Extended Input Sources" <br>[[File:GnomeTweaksKeyboards.png|frameless|600px|Wayland Keyboard set up with GNOME Tweaks Step 3: Open Keyboard & Mouse Panel]]
# Open the Additional Layout Options and tick one or more of the options under "Switching to another layout"<br>[[File:GnomeTweaksKeyboardsAdditional.png|frameless|350px|Wayland Keyboard set up with GNOME Tweaks Step 4: Open Additional Layout Options]]
# Go to Settings → Region & Language → Add a new input source. Both English (United Kingdom) and English (United States) will have several APL layout options to choose from.
# Restart the session (for example, by logging out and logging in again).


== Xfce ==
== Xfce ==


A tutorial specific to Xfce's config files can be found [https://github.com/hashslingrz/apl-keyboard-xfce at this GitHub repository].
Xfce's GUI (<code>Settings Manager</code> → <code>Keyboard</code> → <code>Layout</code>) is unable to set up an APL-compatible keyboard. Therefore, we must do it ourselves.
 
Xfce ships with a utility, [https://docs.xfce.org/xfce/xfconf/xfconf-query xfconf-query], which allows you to manage Xfce's XML configuration files on the command line. Enter the following commands into your terminal:
 
<source lang=console>
xfconf-query -c keyboard-layout -n -p '/Default/XkbDisable' -t 'bool' -s 'false'
</source>
 
This enables [https://www.x.org/wiki/XKB/ XKB], allowing us to manage our keyboard layout.
 
<source lang=console>
xfconf-query -c keyboard-layout -n -p '/Default/XkbLayout' -t 'string' -s 'us,apl'
</source>
 
Defines the keyboard layout itself. The comma-delimited <code>apl</code> specifies a second layout group. Make sure you replace <code>us</code> with the code for your language; a list of these can be found in <code>/usr/share/X11/xkb/rules/evdev.lst</code>, under the <code>layout</code> category.
 
<source lang=console>
xfconf-query -c keyboard-layout -n -p '/Default/XkbOptions/Group' -t 'string' -s 'grp:win_switch'
</source>
 
This tells Xfce to switch to the APL layout only when the <kbd>Windows</kbd> key is pressed. When the <kbd>Windows</kbd> key is released, the layout will return to its previous setting. This is incredibly useful as the <code>apl</code> layouts in XKB do not support <kbd>Space</kbd>, <kbd>Enter</kbd>, or the arrow keys (among basically all the others). A full list of possible keys for switching between keyboard groups is located in <code>/usr/share/X11/xkb/rules/evdev.lst</code>, under the <code>option</code> category.
 
<source lang=console>
xfconf-query -c keyboard-layout -n -p '/Default/XkbVariant' -t 'string' -s ',dyalog'
</source>
 
Specifies that the variant applies to the second layout, <code>apl</code>, due to the preceding comma. The <code>dyalog</code> variant is unique to [[Dyalog]].
 
And you're done! Try holding down the Windows key and pressing <kbd>H</kbd> on your keyboard — you should see a <code>∆</code>.
 
== xmodmap ==
 
Modifying the Linux keyboard to support APL keys via [https://linux.die.net/man/1/xmodmap xmodmap(1)] is possible, but not recommended — it has been superseded by the [https://wiki.archlinux.org/title/X_keyboard_extension X keyboard extension] (XKB). Generally <source lang=console inline>xmodmap</source> is best for simple tasks,<ref>ArchWiki Contributors. [https://wiki.archlinux.org/title/xmodmap xmodmap]. 19 July 2021</ref> which APL keyboards often tend not to be. [[Dyalog APL]], for example, has native support for XKB.<ref name="Dyalog APL XKB"/>
 
For users who understand the pitfalls, an example <source lang=console inline>~/.Xmodmap</source> can be [https://gist.github.com/Russtopia/20ae5ab571d5bed73359ca956d9010a7 found at this GitHub Gist].
 
== Troubleshooting ==
 
=== Gnome catches keystrokes before Dyalog ===
After upgrading Ubuntu 21.04 (Hirsute Hippo), Gnome catches the keystrokes from the <kbd>Super</kbd> key to show the list of applications, before Dyalog can receive it. [[#setxkbmap|Changing the shifting key]] from <source lang=console inline>grp:win_switch</source> to <source lang=console inline>grp:caps_switch</source> avoids the issue. Changing it to <source lang=console inline>grp:rctrl_switch</source> does not work.
 
=== Dyalog Overrides Current Keyboard Settings ===
 
By default, Dyalog APL overrides the current [https://www.x.org/wiki/XKB/ XKB] configuration to use the Meta ("Windows") key as the modifier for entering APL symbols. If the user manages their keyboard configuration manually using the techniques described on this page, this behavior can be quite troublesome.
 
To run Dyalog in the terminal without overriding ("hijacking") the user keyboard configuration, run <code>dyalog</code> with the <code>-nokbd</code> option:
 
<source lang=bash>
dyalog -nokbd
</source>
 
The following script can be used to launch RIDE, immediately connecting a new Dyalog instance, without changing the xkb settings:
 
<source lang=bash>
#!/usr/bin/env sh
env RIDE_CONNECT=localhost:4502 ride &
dyalog +s -q -nokbd RIDE_INIT=SERVE:*:4502
</source>
 
The keyboard layout changing is done by the file at <code>/opt/mdyalog/*/64/unicode/aplkeys.sh</code>, so changing it changes the behavior (clearing it entirely stops the automatic keyboard layout switching). Note that the file exists for each installed version and is reset on any update, so it may need to be modified multiple times.
 
=== APL Keyboard Remains After Dyalog is Closed ===
 
Dyalog overrides the current keyboard configuration, as described in [[#Dyalog_Overrides_Current_Keyboard_Settings|this section]], but fails to return the user to their previous keyboard configuration on exit. To solve this, create a custom [[wikipedia:Bash_(Unix_shell)|Bash]] script to save and revert keyboard settings upon exiting Dyalog APL:<ref>Adám Brudzewsky. [https://stackoverflow.com/questions/63431922/dyalog-apl-hijack-windows-key-and-do-not-give-it-back-fedora-32-gnome-free-lic/63433845#63433845 Stack Overflow answer]. 17 Aug, 2020</ref>
 
<source lang=bash>
#!/usr/bin/sh
OLDLAYOUT=$(setxkbmap -query | sed -n 's/^layout://p')
OLDVARIANT=$(setxkbmap -query | sed -n 's/^variant://p')
OLDOPTION=$(setxkbmap -query | sed -n 's/^options://p')
dyalog
OLDLAYOUT=$(echo $OLDLAYOUT | sed 's/^$/,/')
OLDVARIANT=$(echo $OLDVARIANT | sed 's/^$/,/')
setxkbmap -layout $OLDLAYOUT -variant $OLDVARIANT -option -option $OLDOPTION
</source>
 
=== Settings reverted during X Windows session ===
 
Since at least March 2020 there have been issues with <source lang=console inline>setxkbmap</source> settings being reset without user instruction under the [[wikipedia:X Windows System|X Windows System]].
 
Below is a script written in [[wikipedia:Raku (programming language)|Raku]] that continuously checks for this undesirable reset behavior and puts the intended settings back in place.<ref>John Longwalker. [https://5ab5traction5.bearblog.dev/ 5ab5traction5 blog]. [https://5ab5traction5.bearblog.dev/apl-keyboard-keeper/ Raku to the Rescue: APL Keyboard Keeper]. 29 Jun, 2020</ref>
 
<source lang=perl6>
#!/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 ==
45

edits

Navigation menu