Ubuntu – Xmodmap and keyboard shortcuts: How does the system work? (19.04, Xorg)

keyboardkeyboard-layoutshortcut-keys

there's a lot of information about changing keyboard shortcuts (also on askubuntu). However, it's not clear to me what applies to 19.04/Xorg. I think the issue is partially confused by the earlier use of Wayland and that it's not always clear what system is referred to in answer. I'm a long-term 'command-line' user of Linux, but the Desktop system is a little new (and confusing) to me.

Question 1a: What files/programmes control keyboard setup and shortcuts (across all applications, not application specific)?

Is it just these two?

  • xmodmap
  • /usr/share/gnome-control-center/keybindings/

Are there others?

Question 1b: When I use the GUI to make changes to the keyboard layout, is this reflected in the above files? Or are there settings are can only be accessed through the GUI? (I assume there aren't, but just checking.)

Question 3: Does it matter that xkeycaps doesn't show my correct keyboard layout? (I'm on a standard UK laptop, and none of the xkeycaps layouts I found seem to reflect this accurately.)

Question 4: Application-specific keyboard shortcuts. Some applications have got changeable/settable application-specific keyboard shortcuts.

4a: Do these always override the system-wide keyboard shortcuts?

4b: Where applications do not have settable app-specific keyboard shortcuts, is there any generic way to interface with the app? (E.g. on OS X, the accessibility services can access any menu item.)

Question 5: How do the modifiers in xmodmap relate to the actual keys? For example, https://wiki.archlinux.org/index.php/Xmodmap says

Each keysym column in the table corresponds to a particular combination of modifier keys:

Key
Shift+Key
Mode_switch+Key
Mode_switch+Shift+Key
ISO_Level3_Shift+Key
ISO_Level3_Shift+Shift+Key

But: the my xmodmap has up to 10 entries for each key. So what do those correspond to? Or should this be:

Shift+Key
mod1+Key
mod1+Shift+Key
mod2+Key
mod2+Shift+Key

Further, how does

$ xmodmap -pm
xmodmap:  up to 4 keys per modifier, (keycodes in parentheses):

shift       Shift_L (0x32),  Shift_R (0x3e)
lock        Caps_Lock (0x42)
control     Control_L (0x25),  Control_R (0x69)
mod1        Alt_L (0x40),  Meta_L (0xcd)
mod2        Num_Lock (0x94)
mod3      
mod4        Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  ISO_Level3_Shift (0x6c),  Mode_switch (0x85),  Mode_switch (0xcb)

then correspond to the above? I read this list as "the function 'shift' is fulfilled by the physical keys Shift_L and Shift_R" etc. I'm on a laptop without num_lock, and isn't it also strange that mod3 is not assigned? Or is it that somehow only mod1/4/5 are used in the above list?

For example, I hvae this in the xmodmap

keycode  51 = backslash bar numbersign asciitilde dead_grave dead_breve

suggesting that there should not be unused modifers?

Note that with the settings (shown by xmodmap -pm) I cannot access the characters in the xmodmap (bar the first two columns).

Question 6: What's the difference between a 'control' key (that isn't used to move between columns in the xmodmap) vs. a 'modifier' key (that moves you between columns in xmodmap).

Question 7: Is shift the only key that can be combine with another modifier? Or is it possible to define characters for combinations of modifiers (other than shift)

I've asked these all in one post, as I assume the answers will all be linked – hope that makes sense!

Many thanks!

Best Answer

I've set up a repo here, that turns some of the answers below into practical steps. https://github.com/bjohas/Ubuntu-keyboard-map-like-OS-X

Here are some partial answers:

Question 1a: xkb and gnome-settings. xmodmap still works, but seems to be older than xkb. xkb is faster than xmodmap, see https://github.com/bjohas/Ubuntu-keyboard-map-like-OS-X. Gnome-settings is also briefly described there.

Question 1b: Yes.

Question 3/4a/b: Unsure.

Question 5/6: xmodmap seems to be outdated. The repo above provides some sample scripts that help remap modifier keys. Unsure about the number of entries in the xmodmap columns, but better to look at xkb instead!

Question 7: Unsure, but should be xkb is quite flexible.

Overall, https://github.com/bjohas/Ubuntu-keyboard-map-like-OS-X gives a number of recipies that can serve as starting points.