8

I want to type A with dots (Ä / ä) as one-level keybinding in Ubuntu 16.04's keyboard of Macbook Air 2013-mid, output of setxkbmap -query

rules:      evdev
model:      pc105
layout:     us,us
variant:    dvorak,
options:    ctrl:nocaps

By default, there is no AltGr in the keyboard, just two Alts. This command makes your right alt the compose key (AltGr) but maintains your own custom keyboard configurations etc having Capslock as CTRL by caps:ctrl_modifier, see here

gsettings set org.gnome.desktop.input-sources xkb-options \
    "$(gsettings get org.gnome.desktop.input-sources xkb-options \ 
    | sed "s/]/, 'compose:ralt']/")"

It would be really great to have xmodmap independent solution if this is going to be changed because it is going to be depreciated.

Two-level keybinding approach

We can only do two-level keybinding approach with Dvorak International with deadkeys.

  • SeverusTux's answer is two-level command as AltGr-Shift-Q + A, which works only in us-drovak, international with deadkeys.
  • SeverusTux. Ctrl+Shift+u +e4 + Enter works and gives you ä. How can you map this to a one-level keybinding Alt-a?

I do where you see that the GUI make the change elsewhere. I really want to know where

masi@masi:~$ cat /usr/share/X11/locale/en_US.UTF-8/Compose > /home/masi/Desktop/test1
% I make here a change in the GUI as proposed by Severus: compose key = right Alt
masi@masi:~$ cat /usr/share/X11/locale/en_US.UTF-8/Compose > /home/masi/Desktop/test2
masi@masi:~$ diff /home/masi/Desktop/test1 /home/masi/Desktop/test2
[ no output ]

This shows that the xserver does not update fast. You have to change your keyboard to something else and back again, for the change.

One-level Keybinding Approach

I want one-level command as AltGr-A for ä and AltGr-Shift-A for Ä in English(US-dvorak). I do xev -e keyboard and press AltGr

[ignore the beginning; press AltGr]
KeyPress event, serial 28, synthetic NO, window 0x4400001, 
root 0xd6, subw 0x0, time 13661220, (186,522), root:(186,574), 
state 0x0, keycode 108 (keysym 0xffea, Alt_R), same_screen YES, 
XLookupString gives 0 bytes: 
XmbLookupString gives 0 bytes: 
XFilterEvent returns: False 

KeyRelease event, serial 28, synthetic NO, window 0x4400001, 
root 0xd6, subw 0x0, time 13661284, (186,522), root:(186,574), 
state 0x8, keycode 108 (keysym 0xffea, Alt_R), same_screen YES, 
XLookupString gives 0 bytes: 
XFilterEvent returns: False

You can get all possible switches by more /usr/share/X11/xkb/rules/xorg.lst | grep lv3 but we are only interested in lv3:ralt_switch

  lv3:switch           Right Ctrl
  lv3:menu_switch      Menu
  lv3:win_switch       Any Win key
  lv3:lwin_switch      Left Win
  lv3:rwin_switch      Right Win
  lv3:alt_switch       Any Alt key
  lv3:lalt_switch      Left Alt
  lv3:ralt_switch      Right Alt
  lv3:ralt_switch_multikey Right Alt, Shift+Right Alt key is Compose
  lv3:ralt_alt         Right Alt key never chooses 3rd level
  lv3:enter_switch     Enter on keypad
  lv3:caps_switch      Caps Lock
  lv3:bksl_switch      Backslash
  lv3:lsgt_switch      <Less/Greater>
  lv3:caps_switch_latch Caps Lock chooses 3rd level, acts as onetime lock when pressed together with another 3rd-level-chooser
  lv3:bksl_switch_latch Backslash chooses 3rd level, acts as onetime lock when pressed together with another 3rd-level-chooser
  lv3:lsgt_switch_latch <Less/Greater> chooses 3rd level, acts as onetime lock when pressed together with another 3rd-level-chooser

My keyboard layouts tested but main English(US-dvorak)

enter image description here

Final solution [Sneetsher]

I set A with dots in English(dvorak) by AltGr-a. Merge the changes in/usr/share/X11/xkb/symbols/us; now German-Dvorak because it works very well for Scandinavian languages too (from here)

// based on a keyboard map from an 'xkb/symbols/dk' file
// Added A with dots and O with dots for AltGr-A and AltGr-O, respectively. Sneether and Masi, 17-June-2016.

partial alphanumeric_keys
xkb_symbols "dvorak" {

    name[Group1]= "English (Dvorak)";

    key <TLDE> { [       grave, asciitilde, dead_grave, dead_tilde      ] };

    key <AE01> { [          1,  exclam          ]       };
    key <AE02> { [          2,  at              ]       };
    key <AE03> { [          3,  numbersign      ]       };
    key <AE04> { [          4,  dollar          ]       };
    key <AE05> { [          5,  percent         ]       };
    key <AE06> { [          6,  asciicircum, dead_circumflex, dead_circumflex ] };
    key <AE07> { [          7,  ampersand       ]       };
    key <AE08> { [          8,  asterisk        ]       };
    key <AE09> { [          9,  parenleft,  dead_grave] };
    key <AE10> { [          0,  parenright      ]       };
    key <AE11> { [ bracketleft, braceleft       ]       };
    key <AE12> { [ bracketright, braceright,  dead_tilde] };

    key <AD01> { [  apostrophe, quotedbl, dead_acute, dead_diaeresis    ] };
    key <AD02> { [      comma,  less,   dead_cedilla, dead_caron        ] };
    key <AD03> { [      period, greater, dead_abovedot, periodcentered  ] };
    key <AD04> { [          p,  P               ]       };
    key <AD05> { [          y,  Y               ]       };
    key <AD06> { [          f,  F               ]       };
    key <AD07> { [          g,  G               ]       };
    key <AD08> { [          c,  C               ]       };
    key <AD09> { [          r,  R               ]       };
    key <AD10> { [          l,  L               ]       };
    key <AD11> { [      slash,  question        ]       };
    key <AD12> { [      equal,  plus            ]       };

    key <AC01> {[ a,          A,    adiaeresis,       Adiaeresis ]      };
    key <AC02> {[ o,          O,    odiaeresis,       Odiaeresis ]      };
    key <AC03> { [ e, E, ediaeresis, Ediaeresis ] };
    key <AC04> { [ u, U, udiaeresis, Udiaeresis ] };
    key <AC05> { [          i,  I               ]       };
    key <AC06> { [          d,  D               ]       };
    key <AC07> { [          h,  H               ]       };
    key <AC08> { [          t,  T               ]       };
    key <AC09> { [          n,  N               ]       };
    key <AC10> { [ s, S, ssharp ] };
    key <AC11> { [      minus,  underscore      ]       };

    key <AB01> { [   semicolon, colon, dead_ogonek, dead_doubleacute ] };
    key <AB02> { [          q,  Q               ]       };
    key <AB03> { [          j,  J               ]       };
    key <AB04> { [          k,  K               ]       };
    key <AB05> { [          x,  X               ]       };
    key <AB06> { [          b,  B               ]       };
    key <AB07> { [          m,  M               ]       };
    key <AB08> { [          w,  W               ]       };
    key <AB09> { [          v,  V               ]       };
    key <AB10> { [          z,  Z               ]       };

    key <BKSL> { [  backslash,  bar             ]       };

    include "level3(ralt_switch)"
};

Or use the script which is however still buggy

# restore your current keyboard settings 
sudo apt-get install --reinstall xkb-data
gsettings set org.gnome.desktop.input-sources xkb-options "['compose:ralt', 'caps:ctrl_modifier']"

sudo sed -i.bak 's/[[ \t]*a,[ \t]*A[ \t]*]/[ a,          A,    adiaeresis,       Adiaeresis ]/g;' /usr/share/X11/xkb/symbols/us; 
sudo sed -i.bak 's/[[ \t]*o,[ \t]*O[ \t]*]/[ o,          O,    odiaeresis,       Odiaeresis ]/g;' /usr/share/X11/xkb/symbols/us; 
# German-Dvorak feels better
#sudo sed -i.bak 's/[[ \t]*e,[ \t]*E[ \t]*]/[ e,          E,    ediaeresis,       Ediaeresis ]/g;' /usr/share/X11/xkb/symbols/us; 
#sudo sed -i.bak 's/[[ \t]*u,[ \t]*U[ \t]*]/[ u,          U,    udiaeresis,       Udiaeresis ]/g;' /usr/share/X11/xkb/symbols/us; 
#sudo sed -i.bak 's/[[ \t]*s,[ \t]*S[ \t]*]/[ s,          S,    ssharp ]/g;' /usr/share/X11/xkb/symbols/us; 

# add     include "level3(ralt_switch)" to the end of the environment
# https://unix.stackexchange.com/a/290407/16920
# https://unix.stackexchange.com/q/290405/16920
pos=( $( sed -n -f - /usr/share/X11/xkb/symbols/us <<END_SED
    /xkb_symbols "dvorak" {/,/^};/{
            /xkb_symbols "dvorak" {/=
            /^};/=
    }
END_SED
) )
sudo sed -i.bak "${pos[1]}i\    include \"level3(ralt_switch)\"" /usr/share/X11/xkb/symbols/us

sudo dpkg-reconfigure xkb-data
# Change your keyboard. Change Back. Should work. But some bug. I cannot get the script works stably. 

Bugs

  1. TODO problem with reloading the keyboard back to xserver https://unix.stackexchange.com/q/290449/16920 The manual change does not work always.
  2. Complications: Xserver does not load those keys fast and not even in all cases after restart/logout.

Systems: Ubuntu 16.04
Linux kernel: 4.4 - 4.6
Keyboard model: pc105
Keyboard layout for two-level keybinding approach: US-dvorak international with deadkeys
Keyboard layout for one-level keybinding approach: English (Dvorak) = US-dvorak, but also English (Classic Dvorak)

  • 1
    Press ctrl+shift+u then type e4 and press enter. If this works then you can try further to get a simple key for that. – Severus Tux Jun 7 '16 at 12:53
  • I have written an answer for what I said earlier, please leave comments if you have any doubts – Severus Tux Jun 7 '16 at 14:49
8
  • To type ä , unicode is U00E4

  • To type Ä , unicode is U00C4

If you want the unicodes of other characters, you can get them from gucharmap

To enter it manually, press ctrl+shift+u and followed by 00e4 and hit Enter , this should type ä

But there is a better way to do this using Compose Keys.

If you want to set your Right alt as the compose key using command line: just execute this :

gsettings set org.gnome.desktop.input-sources xkb-options "['compose:ralt']"

If you want to set it suing GUI :

Enable compose key by going to System Settings --> Keyboard --> Typing --> Right Alt. (you can chose a different key if you wish)

enter image description here

Thats all !!

Now go to your favorite text editor and do this :

Press and release Right Alt followed by " followed by a. now you should see ä .

The same can be done for Ä , Press and release Right Alt followed by " followed by A

NOTE : you might need to press Shift+' to get "

TIP:

If you wish to see all similar shortcuts view this file : /usr/share/X11/locale/en_US.UTF-8/Compose

  • @Masi That file is just a list of all Compose key combos. Just extra info. – UniversallyUniqueID Jun 7 '16 at 15:02
  • @Masi you don't have to edit that file or replace anything with sed, that is extra info as @BharadwajRaju said, you can simply view it if you want the shortcut key for some other special symbol. That is a huge list of all such shortcuts – Severus Tux Jun 7 '16 at 15:04
  • 1
    @Masi so you just want to set compose key using command line instead of using GUI ?? – Severus Tux Jun 7 '16 at 15:23
  • @Masi Answer updated :-) you don't need any script for doing that. just a simple command will do the trick. hope this is what you wanted – Severus Tux Jun 7 '16 at 15:43
  • What did you use to make that awesome gif? Nice touch. – Bhikkhu Subhuti Jun 12 '16 at 9:08
7
+100

English (Dvorak, international with dead keys) - dvorak-intl works fine!

I can type Ä using ShiftAltGrq with default setup. See file /usr/share/X11/xkb/symbols/us where the q key declared as

key <AB02> { [ q, Q, adiaeresis, Adiaeresis ] };

and with level3(ralt_switch) at the bottom to use Right Alt/AltGr as 3rd level shift such that

  • 1st column qq
  • 2nd column QShiftq
  • 3rd column äAltGrq
  • 4th column ÄShiftAltGrq

Visualization

X11 XKB layout levels

  • dvorak-intl defines only 4 levels, I draw the all 8 levels as XKB supports so you can get general overview.
  • Shift is a standard level2 shift, AltGr is the default level3 shift for most layouts which need level3&4. Only few layouts define levels5,6,7,8 and so the level5 shift key, I used RCtrl just for explaination.
  • All those 4 lines which define <AB02> key are equivalent.

Setting ä & Ä at 3rd &4th level of a key on English (Dvorak) - dvorak layout

Plus ö & Ö ato key. (It doesn't appear in screen-shot, as it was added after screen-shot)

Same as dvorak-intl, we can make same setup for dvorak.

  1. Clear previous modifications

    sudo apt-get install --reinstall xkb-data
    gsettings set org.gnome.desktop.input-sources xkb-options "[]"
    
  2. Checkpoint

    • Try English (Dvorak, international with dead keys) - dvorak-intl

      AltGrq prints ä.If it didn't work then it will be same problem with this setup. There is something prevent Right Alt from working as level3 shift.

      English (Dvorak, international with dead keys)

    • Verify the current map of dvorak

      English (Dvorak)

    • Verify Right Alt mapping, it should be Alt_R

      $ xev -e keyboard
      [ignore start things; press AltGr]
      
      KeyPress event, serial 28, synthetic NO, window 0x3400001,
          root 0x281, subw 0x0, time 1855861, (769,284), root:(834,336),
          state 0x10, keycode 108 (keysym 0xffea, Alt_R), same_screen YES,
          XLookupString gives 0 bytes: 
          XmbLookupString gives 0 bytes: 
          XFilterEvent returns: False
      
      KeyRelease event, serial 28, synthetic NO, window 0x3400001,
          root 0x281, subw 0x0, time 1855965, (769,284), root:(834,336),
          state 0x18, keycode 108 (keysym 0xffea, Alt_R), same_screen YES,
          XLookupString gives 0 bytes: 
          XFilterEvent returns: False
      
  3. Modify a map

    $ sudo vim /usr/share/X11/xkb/symbols/us +224
    
    key <AD11> { [      slash,  question        ]       };
    key <AD12> { [      equal,  plus            ]       };
    
    key <AC01> { [          a,  A, adiaeresis, Adiaeresis ]       };
    key <AC02> { [          o,  O, odiaeresis, Odiaeresis ]       };
    key <AC03> { [          e,  E               ]       };
    
  4. Setting Right Alt as level3 shift

    $ sudo vim /usr/share/X11/xkb/symbols/us +248
    
        key <AB09> { [          v,  V               ]       };
        key <AB10> { [          z,  Z               ]       };
    
        key <BKSL> { [  backslash,  bar             ]       };
    
        include "level3(ralt_switch)"
    };
    
    // Dvorak international with dead keys
    

    There are many keys that can be used as ISO_Level3_Shift. Check available options

    $ more /usr/share/X11/xkb/rules/xorg.lst | grep lv3:
      lv3:switch           Right Ctrl
      lv3:menu_switch      Menu
      lv3:win_switch       Any Win key
      lv3:lwin_switch      Left Win
      lv3:rwin_switch      Right Win
      lv3:alt_switch       Any Alt key
      lv3:lalt_switch      Left Alt
      lv3:ralt_switch      Right Alt
      lv3:ralt_switch_multikey Right Alt, Shift+Right Alt key is Compose
      lv3:ralt_alt         Right Alt key never chooses 3rd level
      lv3:enter_switch     Enter on keypad
      lv3:caps_switch      Caps Lock
      lv3:bksl_switch      Backslash
      lv3:lsgt_switch      &lt;Less/Greater&gt;
      lv3:caps_switch_latch Caps Lock chooses 3rd level, acts as onetime lock when pressed together with another 3rd-level-chooser
      lv3:bksl_switch_latch Backslash chooses 3rd level, acts as onetime lock when pressed together with another 3rd-level-chooser
      lv3:lsgt_switch_latch &lt;Less/Greater&gt; chooses 3rd level, acts as onetime lock when pressed together with another 3rd-level-chooser
    

    For example, if you like to use Caps Lock as the level3 shift then enter include "level3(caps_switch)" instead of include "level3(ralt_switch)".

  5. Force reload of layouts

    sudo dpkg-reconfigure xkb-data
    

    Change to another layout then back.

  6. Check point

    • Verify the current map of dvorak

      English (Dvorak)

    • Verify Right Alt mapping. It should be ISO_Level3_Shift

      $ xev -e keyboard
      
      KeyPress event, serial 35, synthetic NO, window 0x3600001,
          root 0x281, subw 0x0, time 4755266, (154,154), root:(219,206),
          state 0x0, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES,
          XKeysymToKeycode returns keycode: 92
          XLookupString gives 0 bytes: 
          XmbLookupString gives 0 bytes: 
          XFilterEvent returns: False
      
      KeyRelease event, serial 35, synthetic NO, window 0x3600001,
          root 0x281, subw 0x0, time 4755435, (154,154), root:(219,206),
          state 0x80, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES,
          XKeysymToKeycode returns keycode: 92
          XLookupString gives 0 bytes: 
          XFilterEvent returns: False
      

Now, it should work!


One-liner command

cd /; \
echo -e "--- /usr/share/X11/xkb/symbols/us\t2016-01-22 09:38:25.000000000 +0100\n+++ /usr/share/X11/xkb/symbols/us\t2016-06-17 15:43:07.656076074 +0100\n@@ -221,8 +221,8 @@\n     key <AD11> { [\tslash,\tquestion\t]\t};\n     key <AD12> { [\tequal,\tplus\t\t]\t};\n \n-    key <AC01> { [\t    a,\tA \t\t]\t};\n-    key <AC02> { [\t    o,\tO\t\t]\t};\n+    key <AC01> { [\t    a,\tA, adiaeresis, Adiaeresis ]\t};\n+    key <AC02> { [\t    o,\tO, odiaeresis, Odiaeresis ]\t};\n     key <AC03> { [\t    e,\tE\t\t]\t};\n     key <AC04> { [\t    u,\tU\t\t]\t};\n     key <AC05> { [\t    i,\tI\t\t]\t};\n@@ -245,6 +245,8 @@\n     key <AB10> { [\t    z,\tZ\t\t]\t};\n \n     key <BKSL> { [  backslash,  bar             ]       };\n+\n+    include \"level3(ralt_switch)\"\n };\n \n // Dvorak international with dead keys\n" \
| sudo patch -p1; \
sudo dpkg-reconfigure xkb-data; \
cl=$(gsettings get org.gnome.desktop.input-sources current); \
gsettings set org.gnome.desktop.input-sources current 0; \
gsettings set org.gnome.desktop.input-sources current 1; \
gsettings set org.gnome.desktop.input-sources current "$cl"
  • 2
    Comments are not for extended discussion; this conversation has been moved to chat. – Mitch Jun 15 '16 at 10:32
  • 1
    I have found out that the manual change of the keyboard does not work always. The change is not valid until you log out. I am thinking a solution here unix.stackexchange.com/questions/290449/… – Léo Léopold Hertz 준영 Jun 19 '16 at 9:59
  • I found a bug which I do not understand. This line sudo sed -i "${pos[1]}i\ include 'level3(ralt_switch)'" /usr/share/X11/xkb/symbols/us makes the keyboard unusable at the startup. You cannot type any key in the keyboard. It just adds level3 at the end Dvorak environment at the line 249. Is the line 249 correct position? – Léo Léopold Hertz 준영 Jun 19 '16 at 12:46
  • @Masi, yep but it should be in 248 not 249! and sure you have ${pos[1]} defined before. – user.dz Jun 19 '16 at 12:54
  • I opened a new thread about the case here unix.stackexchange.com/q/346073/16920 because I really need such features more stably in the OS. – Léo Léopold Hertz 준영 Feb 19 '17 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.