Typing glyphs on Linux: Difference between revisions

Jump to navigation Jump to search
m
Text replacement - "</source>" to "</syntaxhighlight>"
m (Text replacement - "<source" to "<syntaxhighlight")
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 1: Line 1:
:''This article is specific for Linux. For Hardware and other platforms, see [[Typing glyphs]].''
:''This article is specific for Linux. For Hardware and other platforms, see [[Typing glyphs]].''


Since mid-2012, most Linux distributions with [[wikipedia:X_Window_System|X11]] and [[wikipedia:Wayland_(display_server_protocol)|Wayland]] 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 <syntaxhighlight 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>
Since mid-2012, most Linux distributions with [[wikipedia:X_Window_System|X11]] and [[wikipedia:Wayland_(display_server_protocol)|Wayland]] 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 <syntaxhighlight lang=console inline>xkb</syntaxhighlight>, 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 ==


The simplest way to set up an APL keyboard on Linux is with the following <syntaxhighlight lang=console inline>setxkbmap</source> command. Enter the following in your terminal emulator of choice:
The simplest way to set up an APL keyboard on Linux is with the following <syntaxhighlight lang=console inline>setxkbmap</syntaxhighlight> command. Enter the following in your terminal emulator of choice:


<syntaxhighlight lang=console>
<syntaxhighlight lang=console>
setxkbmap -layout us,apl -variant ,dyalog -option grp:switch
setxkbmap -layout us,apl -variant ,dyalog -option grp:switch
</source>
</syntaxhighlight>


An explanation:
An explanation:


* <syntaxhighlight lang=console inline>-layout us,apl</source> assigns <syntaxhighlight lang=console inline>us</source> ([[wikipedia:American_English|U.S. English]]) to be the primary layout, whereas <syntaxhighlight lang=console inline>apl</source> is secondary
* <syntaxhighlight lang=console inline>-layout us,apl</syntaxhighlight> assigns <syntaxhighlight lang=console inline>us</syntaxhighlight> ([[wikipedia:American_English|U.S. English]]) to be the primary layout, whereas <syntaxhighlight lang=console inline>apl</syntaxhighlight> is secondary


* <syntaxhighlight lang=console inline>-option grp:switch</source> assigns <kbd>Right Alt</kbd> to switch to the secondary <syntaxhighlight lang=console inline>apl</source> layout when it is pressed, otherwise <syntaxhighlight lang=console inline>us</source> is used
* <syntaxhighlight lang=console inline>-option grp:switch</syntaxhighlight> assigns <kbd>Right Alt</kbd> to switch to the secondary <syntaxhighlight lang=console inline>apl</syntaxhighlight> layout when it is pressed, otherwise <syntaxhighlight lang=console inline>us</syntaxhighlight> is used


* <syntaxhighlight lang=console inline>-variant ,dyalog</source> assigns the [[Dyalog APL]] variant to the <syntaxhighlight lang=console inline>apl</source> layout which contains modifiations unique to the Dyalog language ('''Note the preceding comma''')
* <syntaxhighlight lang=console inline>-variant ,dyalog</syntaxhighlight> assigns the [[Dyalog APL]] variant to the <syntaxhighlight lang=console inline>apl</syntaxhighlight> layout which contains modifiations unique to the Dyalog language ('''Note the preceding comma''')


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


Note:
Note:
Line 25: Line 25:
* 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.
* 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 <syntaxhighlight lang=console inline>gb</source> instead of <syntaxhighlight lang=console inline>us</source> (not <syntaxhighlight lang=console inline>uk</source>)
* If you want to specify a different language, say for United Kingdom, specify <syntaxhighlight lang=console inline>gb</syntaxhighlight> instead of <syntaxhighlight lang=console inline>us</syntaxhighlight> (not <syntaxhighlight lang=console inline>uk</syntaxhighlight>)


* If you want to specify a different layout, dvorak, bepo, etc, change the variant flag to <syntaxhighlight lang=console inline>dvorak,dyalog</source>.
* If you want to specify a different layout, dvorak, bepo, etc, change the variant flag to <syntaxhighlight lang=console inline>dvorak,dyalog</syntaxhighlight>.


== libinput ==
== libinput ==


X11 and Wayland use XKB rules to determine their layout. To set a layout create a file called <syntaxhighlight lang=console inline>00-keyboard.conf</source> at <syntaxhighlight lang=console inline>/etc/X11/xorg.conf.d</source> or <syntaxhighlight lang=console inline>/usr/etc/X11/corg.conf.d</source>, ensuring you have permissions, and edit it to:
X11 and Wayland use XKB rules to determine their layout. To set a layout create a file called <syntaxhighlight lang=console inline>00-keyboard.conf</syntaxhighlight> at <syntaxhighlight lang=console inline>/etc/X11/xorg.conf.d</syntaxhighlight> or <syntaxhighlight lang=console inline>/usr/etc/X11/corg.conf.d</syntaxhighlight>, ensuring you have permissions, and edit it to:


<syntaxhighlight lang=console>
<syntaxhighlight lang=console>
Line 41: Line 41:
         Option "XkbOptions" "grp:switch"
         Option "XkbOptions" "grp:switch"
EndSection
EndSection
</source>
</syntaxhighlight>


The options "us,apl", ",dyalog", and "grp:switch" are the same as in [[#setxkbmap|setxkbmap]] and can be changed to better suit your environment.
The options "us,apl", ",dyalog", and "grp:switch" are the same as in [[#setxkbmap|setxkbmap]] and can be changed to better suit your environment.


Once saved this will affect any future session. To change the current session and test out layouts, use <syntaxhighlight lang=console inline>setxkbmap</source>.  
Once saved this will affect any future session. To change the current session and test out layouts, use <syntaxhighlight lang=console inline>setxkbmap</syntaxhighlight>.  


== GNOME ==
== GNOME ==
Line 70: Line 70:
Comment[en_US]=
Comment[en_US]=
Comment=
Comment=
</source>
</syntaxhighlight>


== LXDE ==
== LXDE ==


# Prepend an <syntaxhighlight lang=console inline>@</source> to the <syntaxhighlight lang=console inline>setxkbmap</source> command from above:<br><syntaxhighlight lang=console>
# Prepend an <syntaxhighlight lang=console inline>@</syntaxhighlight> to the <syntaxhighlight lang=console inline>setxkbmap</syntaxhighlight> command from above:<br><syntaxhighlight lang=console>
@setxkbmap -layout us,apl -variant ,dyalog -option grp:switch
@setxkbmap -layout us,apl -variant ,dyalog -option grp:switch
</source>
</syntaxhighlight>
# Add it as a line in your user's LXDE <syntaxhighlight lang=console inline>autostart</source> file, located at:<br><syntaxhighlight lang=console>
# Add it as a line in your user's LXDE <syntaxhighlight lang=console inline>autostart</syntaxhighlight> file, located at:<br><syntaxhighlight lang=console>
~/.config/lxsession/LXDE/autostart
~/.config/lxsession/LXDE/autostart
</source>
</syntaxhighlight>


For Lubuntu versions up to and including 18.04 (before the LXQt split), the location of <syntaxhighlight lang=console inline>autostart</source> is <syntaxhighlight lang=console inline>~/.config/lxsession/Lubuntu/autostart</source>.
For Lubuntu versions up to and including 18.04 (before the LXQt split), the location of <syntaxhighlight lang=console inline>autostart</syntaxhighlight> is <syntaxhighlight lang=console inline>~/.config/lxsession/Lubuntu/autostart</syntaxhighlight>.


== LXQt ==
== LXQt ==
Line 87: Line 87:
=== GUI ===
=== GUI ===


# From your LXQt panel, navigate to ''Preferences'' → ''LXQt Settings'' → ''Session Settings''; alternatively, enter <syntaxhighlight lang=console inline>lxqt-config-session</source> in your terminal emulator. You will be greeted with the following window:<br>[[File:Lxqt-session-settings.png|frameless|LXQt Autostart menu of Session Settings window]]
# From your LXQt panel, navigate to ''Preferences'' → ''LXQt Settings'' → ''Session Settings''; alternatively, enter <syntaxhighlight lang=console inline>lxqt-config-session</syntaxhighlight> in your terminal emulator. You will be greeted with the following window:<br>[[File:Lxqt-session-settings.png|frameless|LXQt Autostart menu of Session Settings window]]
# Select the <syntaxhighlight lang=console inline>LXQt Autostart</source> dropdown (it will be highlighted as shown above) and click the <kbd>Add</kbd> button to display the following pop-up window:<br>[[File:Lxqt-add-autostart.png|frameless|LXQt add a new autostart menu item]]
# Select the <syntaxhighlight lang=console inline>LXQt Autostart</syntaxhighlight> dropdown (it will be highlighted as shown above) and click the <kbd>Add</kbd> button to display the following pop-up window:<br>[[File:Lxqt-add-autostart.png|frameless|LXQt add a new autostart menu item]]
# Provide a name, enter your <code>setxkbmap</code> command, and click <kbd>OK</kbd> when finished.
# Provide a name, enter your <code>setxkbmap</code> command, and click <kbd>OK</kbd> when finished.


=== Terminal ===
=== Terminal ===


The above GUI approach merely creates a <syntaxhighlight lang=console inline>.desktop</source> file in the user's <syntaxhighlight lang=console inline>~/.config/autostart</source>. Create your own file in the <syntaxhighlight lang=console inline>autostart</source> directory whose contents are as follows, to replicate the functionality achieved through the GUI:
The above GUI approach merely creates a <syntaxhighlight lang=console inline>.desktop</syntaxhighlight> file in the user's <syntaxhighlight lang=console inline>~/.config/autostart</syntaxhighlight>. Create your own file in the <syntaxhighlight lang=console inline>autostart</syntaxhighlight> directory whose contents are as follows, to replicate the functionality achieved through the GUI:


<syntaxhighlight lang=ini>
<syntaxhighlight lang=ini>
Line 102: Line 102:
Type=Application
Type=Application
Version=1.0
Version=1.0
</source>
</syntaxhighlight>


== MATE ==
== MATE ==
Line 130: Line 130:
Comment=
Comment=
X-MATE-Autostart-Delay=0
X-MATE-Autostart-Delay=0
</source>
</syntaxhighlight>


== Wayland ==
== Wayland ==
Line 157: Line 157:
<syntaxhighlight lang=console>
<syntaxhighlight lang=console>
xfconf-query -c keyboard-layout -n -p '/Default/XkbDisable' -t 'bool' -s 'false'
xfconf-query -c keyboard-layout -n -p '/Default/XkbDisable' -t 'bool' -s 'false'
</source>
</syntaxhighlight>


This enables [https://www.x.org/wiki/XKB/ XKB], allowing us to manage our keyboard layout.
This enables [https://www.x.org/wiki/XKB/ XKB], allowing us to manage our keyboard layout.
Line 163: Line 163:
<syntaxhighlight lang=console>
<syntaxhighlight lang=console>
xfconf-query -c keyboard-layout -n -p '/Default/XkbLayout' -t 'string' -s 'us,apl'
xfconf-query -c keyboard-layout -n -p '/Default/XkbLayout' -t 'string' -s 'us,apl'
</source>
</syntaxhighlight>


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.
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.
Line 169: Line 169:
<syntaxhighlight lang=console>
<syntaxhighlight lang=console>
xfconf-query -c keyboard-layout -n -p '/Default/XkbOptions/Group' -t 'string' -s 'grp:win_switch'
xfconf-query -c keyboard-layout -n -p '/Default/XkbOptions/Group' -t 'string' -s 'grp:win_switch'
</source>
</syntaxhighlight>


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.
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.
Line 175: Line 175:
<syntaxhighlight lang=console>
<syntaxhighlight lang=console>
xfconf-query -c keyboard-layout -n -p '/Default/XkbVariant' -t 'string' -s ',dyalog'
xfconf-query -c keyboard-layout -n -p '/Default/XkbVariant' -t 'string' -s ',dyalog'
</source>
</syntaxhighlight>


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]].
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]].
Line 183: Line 183:
== xmodmap ==
== 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 <syntaxhighlight 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"/>
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 <syntaxhighlight lang=console inline>xmodmap</syntaxhighlight> 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 <syntaxhighlight lang=console inline>~/.Xmodmap</source> can be [https://gist.github.com/Russtopia/20ae5ab571d5bed73359ca956d9010a7 found at this GitHub Gist].
For users who understand the pitfalls, an example <syntaxhighlight lang=console inline>~/.Xmodmap</syntaxhighlight> can be [https://gist.github.com/Russtopia/20ae5ab571d5bed73359ca956d9010a7 found at this GitHub Gist].


== Troubleshooting ==
== Troubleshooting ==


=== Gnome catches keystrokes before Dyalog ===
=== 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 <syntaxhighlight lang=console inline>grp:win_switch</source> to <syntaxhighlight lang=console inline>grp:caps_switch</source> avoids the issue. Changing it to <syntaxhighlight lang=console inline>grp:rctrl_switch</source> does not work.
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 <syntaxhighlight lang=console inline>grp:win_switch</syntaxhighlight> to <syntaxhighlight lang=console inline>grp:caps_switch</syntaxhighlight> avoids the issue. Changing it to <syntaxhighlight lang=console inline>grp:rctrl_switch</syntaxhighlight> does not work.


=== Dyalog Overrides Current Keyboard Settings ===
=== Dyalog Overrides Current Keyboard Settings ===
Line 200: Line 200:
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
dyalog -nokbd
dyalog -nokbd
</source>
</syntaxhighlight>


The following script can be used to launch RIDE, immediately connecting a new Dyalog instance, without changing the xkb settings:
The following script can be used to launch RIDE, immediately connecting a new Dyalog instance, without changing the xkb settings:
Line 208: Line 208:
env RIDE_CONNECT=localhost:4502 ride &
env RIDE_CONNECT=localhost:4502 ride &
dyalog +s -q -nokbd RIDE_INIT=SERVE:*:4502
dyalog +s -q -nokbd RIDE_INIT=SERVE:*:4502
</source>
</syntaxhighlight>


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.
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.
Line 218: Line 218:
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
dyalog --keyboard
dyalog --keyboard
</source>
</syntaxhighlight>


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>
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>
Line 231: Line 231:
OLDVARIANT=$(echo $OLDVARIANT | sed 's/^$/,/')
OLDVARIANT=$(echo $OLDVARIANT | sed 's/^$/,/')
setxkbmap -layout $OLDLAYOUT -variant $OLDVARIANT -option -option $OLDOPTION
setxkbmap -layout $OLDLAYOUT -variant $OLDVARIANT -option -option $OLDOPTION
</source>
</syntaxhighlight>


=== Settings reverted during X Windows session ===
=== Settings reverted during X Windows session ===


Since at least March 2020 there have been issues with <syntaxhighlight lang=console inline>setxkbmap</source> settings being reset without user instruction under the [[wikipedia:X Windows System|X Windows System]].
Since at least March 2020 there have been issues with <syntaxhighlight lang=console inline>setxkbmap</syntaxhighlight> 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>
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>
Line 304: Line 304:
   }
   }
}
}
</source>
</syntaxhighlight>


== References ==
== References ==

Navigation menu