Typing glyphs on Linux

From APL Wiki
Revision as of 12:02, 19 August 2020 by Matt (talk | contribs) (Add #! to keyboard override script)
Jump to navigation Jump to search

Since mid-2012, most Linux distributions with X11 have Dyalog APL keyboard support included with the distribution,[1] using xkb, the X Keyboard Extension.[2]

setxkbmap

The simplest way to set up an APL keyboard on Linux is with the following setxkbmap command. Enter the following in your terminal emulator of choice:

setxkbmap -layout us,apl -variant ,dyalog -option grp:switch

An explanation:

  • -layout us,apl assigns us (U.S. English) to be the primary layout, whereas apl is secondary
  • -option grp:switch assigns Right Alt to switch to the secondary apl layout when it is pressed, otherwise us is used
  • -variant ,dyalog assigns the Dyalog APL variant to the apl 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 /usr/share/X11/xkb/rules/evdev.lst under the option 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 desktop environments listed below, they can follow those instructions.

GNOME

GUI

  1. Open the Activities menu; this is located in the top-left corner of a default GNOME 3 session (alternatively, use your Super key to open the Activities overlay):
    GNOME Keyboard Step 1: Open Activities Menu
  2. Search for "startup." When the Startup Applications program is highlighted, press the Enter key to open it:
    GNOME Keyboard Step 2: Search for Startup Applications
  3. Select the Add button on the right-hand side:
    GNOME Keyboard Step 3: Click the Add button in Startup Applications window
  4. Provide a name, enter your setxkbmap command, and click Add when finished:
    GNOME Keyboard Step 4: Enter the relevant information for your command

Terminal

  1. Navigate to ~/.config/autostart and create a .desktop with any name that will help you remember its function.
  2. Add the following to the contents of your file, customizing to suit your needs:
    [Desktop Entry]
    Type=Application
    Exec=setxkbmap -layout us,apl -variant ,dyalog -option grp:switch
    Hidden=false
    NoDisplay=false
    X-GNOME-Autostart-enabled=true
    Name[en_US]=apl-keyboard
    Name=apl-keyboard
    Comment[en_US]=
    Comment=

LXDE

  1. Prepend an @ to the setxkbmap command from above:
    @setxkbmap -layout us,apl -variant ,dyalog -option grp:switch
  2. Add it as a line in your user's LXDE autostart file, located at:
    ~/.config/lxsession/LXDE/autostart

For Lubuntu versions up to and including 18.04 (before the LXQt split), the location of autostart is ~/.config/lxsession/Lubuntu/autostart.

LXQt

GUI

  1. From your LXQt panel, navigate to PreferencesLXQt SettingsSession Settings; alternatively, enter lxqt-config-session in your terminal emulator. You will be greeted with the following window:
    LXQt Autostart menu of Session Settings window
  2. Select the LXQt Autostart dropdown (it will be highlighted as shown above) and click the Add button to display the following pop-up window:
    LXQt add a new autostart menu item
  3. Provide a name, enter your setxkbmap command, and click OK when finished.

Terminal

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

[Desktop Entry]
Exec=setxkbmap -layout us,apl -variant ,dyalog -option grp:switch
Name=apl-keyboard
OnlyShowIn=LXQt;
Type=Application
Version=1.0

MATE

GUI

  1. Open your MATE menu (in the top-left corner of a default environment) and select Control Center at the bottom of the window:
    Launch the Control Center from the MATE menu
  2. Scroll down through the main window, and under the Personal category, select Startup Applications:
    Scroll down to the Startup Applications option
  3. Click the Add button on the right-hand side:
    Click Add to add a new startup command
  4. Provide a name, enter your setxkbmap command, and click Add when finished:
    Enter the setxkbmap command you wish to use

Terminal

Navigate to ~/.config/autostart and create a .desktop with any name that will help you remember its function.

Add the following to the contents of your file, customizing to suit your needs:

[Desktop Entry]
Type=Application
Exec=setxkbmap -layout us,apl -variant ,dyalog -option grp:switch
Hidden=false
X-MATE-Autostart-enabled=true
Name[en_US]=apl-keyboard
Name=apl-keyboard
Comment[en_US]=
Comment=
X-MATE-Autostart-Delay=0

Xfce

A tutorial specific to Xfce's config files can be found at this GitHub repository.

Troubleshooting

Dyalog Overrides Current Keyboard Settings

By default, Dyalog APL overrides the current 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 without overriding ("hijacking") the user keyboard configuration, run dyalog with the nokbd option:

dyalog -nokbd

APL Keyboard Remains After Dyalog is Closed

Dyalog overrides the current keyboard configuration, as described in this section, but fails to return the user to their previous keyboard configuration on exit. To solve this, create a custom Bash script to save and revert keyboard settings upon exiting Dyalog APL:[3]

#!/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

Settings reverted during X Windows session

Since at least March 2020 there have been issues with setxkbmap settings being reset without user instruction under the X Windows System.

Below is a script written in Raku that continuously checks for this undesirable reset behavior and puts the intended settings back in place.[4]

#!/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;
    }
  }
}

References

APL development [edit]
Interface SessionTyping glyphs (on Linux) ∙ FontsText editors
Publications IntroductionsLearning resourcesSimple examplesAdvanced examplesMnemonicsISO 8485:1989ISO/IEC 13751:2001A Dictionary of APLCase studiesDocumentation suitesBooksPapersVideosAPL Quote QuadVector journalTerminology (Chinese, German) ∙ Neural networksError trapping with Dyalog APL (in forms)
Sharing code Backwards compatibilityAPLcartAPLTreeAPL-CationDfns workspaceTatinCider
Implementation ResourcesOpen-sourceMagic functionPerformanceAPL hardware
Developers Timeline of corporationsAPL2000DyalogIBMIPSASTSC
APL glyphs [edit]
Information GlyphTyping glyphs (on Linux) ∙ UnicodeFontsMnemonicsOverstrikesMigration level
Individual glyphs Jot () ∙ Right Shoe () ∙ Up Arrow () ∙ Zilde () ∙ High minus (¯) ∙ Dot (.) ∙ Del ()