add .Xmodmap/xkb configurations

This commit is contained in:
2022-11-13 13:13:47 +01:00
parent 51e03b4386
commit 001146c53f

View File

@@ -3,17 +3,20 @@
This document will explain how to setup g910-gkeys by limiting as much as possible the usage of a global config, the idea being to setup global mapping in a static manner, and let the user set the actions in his/her own environment.
** Preamble
~g910-gkeys~ allows different actions : ~typeout~, ~shortcut~ and ~run~. All of these actions will be performed on the process environment, that is ~root~. Also, these actions are *global*.
~g910-gkeys~ allows different actions : ~typeout~, ~shortcut~ and ~run~. There are some drawbacks with that :
- All of these actions will be performed on the process environment, that is ~root~.
- These actions are *global*.
- It is impossible to use the G-keys as /normal/ keys (for example different actions with different modifiers, for example ~Shift-G1~ or ~Control-Meta-G1~).
** g910-gkeys configuration file (/etc/g910-gkeys/config.json)
The configuration chosen will ba basic: assign each ~g-key~ to a key which does not exist on physical keyboard. Any key could be used, like specific localized keys which do not exist on your keyboard (example: Japanese keys for an English keyboard), or function keys above F12.
The configuration chosen will ba basic: assign each ~G-key~ to a key which does not exist on physical keyboard. Any key could be used, like specific localized keys which do not exist on your keyboard (example: Japanese keys for an English keyboard), or function keys above F12.
We will choose to map them to Function keys ~F13~ to ~F21~. It is possible that some of these F-keys are already used on your system (example: some media keys may be assigned to ~F20~). In this case, simply use another F-key.
The ~g910-gkeys~ will be (skipping ~F20~ on my system):
The ~g910-gkeys~ will be :
#+BEGIN_SRC json
{
"__comment": "I was unable to use F20, even xev does not show the keycode. It just mutes/unmutes sound, same as the G910's <mute> button",
"__comment": "I was sometimes unable to use F20, even xev does did not show the keycode (It just muted/unmuted sound, same as the G910's <mute> button). If it is the case for you, just skip F20 and use F22 instead.",
"keyboard_mapping": "en",
"g1": {
"hotkey_type": "shortcut",
@@ -45,17 +48,17 @@ The ~g910-gkeys~ will be (skipping ~F20~ on my system):
},
"g8": {
"hotkey_type": "shortcut",
"do": "F21"
"do": "F20"
},
"g9": {
"hotkey_type": "shortcut",
"do": "F22"
"do": "F21"
}
}
#+END_SRC
** X11 keyboard mapping
By default, our F13-F22 may be mapped to some defaults (see /usr/share/X11/xkb/symbols/inet). For example, ~F13~ will return ~XF86Tools~. This is not what we want. Instead we want F13-F22 to return themselves. It could be possible to keep the default mappings, but it makes less sense.
By default, our F13-F22 keys may be mapped to some defaults (see /usr/share/X11/xkb/symbols/inet). For example, ~F13~ could return ~XF86Tools~. This is not what we want. Instead we want F13-F22 to return themselves. It could be possible to keep the default mappings, but it makes less sense, and it would probably clash with the keyboard Media keys.
You can check if this mapping is done on your system with:
#+BEGIN_SRC
@@ -68,7 +71,119 @@ keycode 200 = XF86TouchpadOn NoSymbol XF86TouchpadOn
#+END_SRC
If the output looks like the above, you will need to use one of the two above methods :
*** Fix F-keys mapping globally
You will need to find out where the mapping F-key -> Different key is done. On My system, it was in ~/usr/share/X11/xkb/symbols/inet~.
Tou find where the mapping is done on your system, you may run : ~setxkbmap -print -verbose 10~) :
#+BEGIN_SRC
$ setxkbmap -print -verbose 10
Setting verbose level to 10
locale is C
Trying to load rules file ./rules/evdev...
Trying to load rules file /usr/share/X11/xkb/rules/evdev...
Success.
Applied rules from evdev:
rules: evdev
model: pc105
layout: us
variant: altgr-intl
options: compose:ralt,grp:ctrls_toggle,lv3:ralt_switch,terminate:ctrl_alt_bksp
Trying to build keymap using the following components:
keycodes: evdev+aliases(qwerty)
types: complete
compat: complete
symbols: pc+us(altgr-intl)+inet(evdev)+group(ctrls_toggle)+level3(ralt_switch)+compose(ralt)+terminate(ctrl_alt_bksp)
geometry: pc(pc105)
xkb_keymap {
xkb_keycodes { include "evdev+aliases(qwerty)" };
xkb_types { include "complete" };
xkb_compat { include "complete" };
xkb_symbols { include "pc+us(altgr-intl)+inet(evdev)+group(ctrls_toggle)+level3(ralt_switch)+compose(ralt)+terminate(ctrl_alt_bksp)" };
xkb_geometry { include "pc(pc105)" };
};
#+END_SRC
In my case, the faulty configuration was the ~inet(evdev)~ part, meaning in the ~xkb_symbols "evdev"~ section of ~/usr/share/X11/xkb/symbols/inet~ file. I had to remove the ~FK13-FK22~ lines and add my own. For example, replacing the line :
#+BEGIN_SRC
key <FK13> { [ XF86Tools ] };
#+END_SRC
With :
#+BEGIN_SRC
key <FK13> { [ F13, F13, F13, F13 ] };
#+END_SRC
The full diff with my changes is :
#+BEGIN_SRC
$ diff -u0 inet.brsav.2022.11.13 inet
--- inet.brsav.2022.11.13 2022-02-08 18:13:55.000000000 +0100
+++ inet 2022-11-13 13:09:29.910184100 +0100
@@ -115,5 +114,0 @@
- key <FK21> { [ XF86TouchpadToggle ] };
- key <FK22> { [ XF86TouchpadOn ] };
- key <FK23> { [ XF86TouchpadOff ] };
-
- key <FK20> { [ XF86AudioMicMute ] };
@@ -204,6 +199,10 @@
- key <FK13> { [ XF86Tools ] };
- key <FK14> { [ XF86Launch5 ] };
- key <FK15> { [ XF86Launch6 ] };
- key <FK16> { [ XF86Launch7 ] };
- key <FK17> { [ XF86Launch8 ] };
- key <FK18> { [ XF86Launch9 ] };
+ key <FK13> { [ F13, F13, F13, F13 ] };
+ key <FK14> { [ F14, F14, F14, F14 ] };
+ key <FK15> { [ F15, F15, F15, F15 ] };
+ key <FK16> { [ F16, F16, F16, F16 ] };
+ key <FK17> { [ F17, F17, F17, F17 ] };
+ key <FK18> { [ F18, F18, F18, F18 ] };
+ key <FK19> { [ F19, F19, F19, F19 ] };
+ key <FK20> { [ F20, F20, F20, F20 ] };
+ key <FK21> { [ F21, F21, F21, F21 ] };
+ key <FK22> { [ F22, F22, F22, F22 ] };
#+END_SRC
*** Fix F-keys mapping with .Xmodmaprc
Add in your ~/.xmodmaprc~ :
#+BEGIN_SRC
!!!!!!!!!!!!!! Logitech G910 keyboard
! Note:
! F11-F20 have synonyms L1-L10
! F21-F35 have synonyms R1-R15
! See: /usr/include/X11/keysymdef.h
!
! original F13, F14, etc... mapping
! F13 = keycode 191 = XF86Tools NoSymbol XF86Tools
! F14 = keycode 192 = XF86Launch5 NoSymbol XF86Launch5
! F15 = keycode 193 = XF86Launch6 NoSymbol XF86Launch6
! F16 = keycode 194 = XF86Launch7 NoSymbol XF86kLaunch7
! F17 = keycode 195 = XF86Launch8 NoSymbol XF86Launch8
! F18 = keycode 196 = XF86Launch9 NoSymbol XF86Launch9
! F19 = keycode 197 = (nothing)
! F20 = keycode 198 = XF86AudioMicMute NoSymbol XF86AudioMicMute
! F21 = keycode 199 = XF86TouchpadToggle NoSymbol XF86TouchpadToggle
! F22 = keycode 200 = XF86TouchpadOn NoSymbol XF86TouchpadOn
! we map the Gkeys (G1-G9), to F13-F22,
! G1
keycode 191 = F13 F13 F13 F13 F13 F13
! G2
keycode 192 = F14 F14 F14 F14 F14 F14
! G3
keycode 193 = F15 F15 F15 F15 F15 F15
! G4
keycode 194 = F16 F16 F16 F16 F16 F16
! G5 becomes Hyper_L
keycode 194 = F16 F16 F16 F16 F16 F16
! G6
keycode 196 = F18 F18 F18 F18 F18 F18
! G7
keycode 197 = F19 F19 F19 F19 F19 F19
! F20 - problem here
keycode 198 = F20 F20 F20 F20 F20 F20
! G8
keycode 199 = F21 F21 F21 F21 F21 F21
! G9
keycode 200 = F22 F22 F22 F22 F22 F22
#+END_SRC
** User configuration
*Note*: Configuration below will make the ~G-keys~ active only when user is logged-on, as any other key.
@@ -96,16 +211,23 @@ In ~Application Shortcut~ section, click on ~Add~, then set command to ~gnome-te
We can send static/dynamic strings to active window, using ~autokey~ (on Ubuntu 22.10, autokey is provided by ~autokey-gtk~ or ~autokey-qt~ packages).
Note that you can use any combination of modifiers (for example Shift+Meta+G2).
Example 1:
Insert Japanese "山" with Shift-Control-G2 :
*Example 1*: Insert Japanese "山" with Shift-Control-G2 :
[[./img/yama.png]]
Example 2:
Insert current date to active window with G2 :
*Example 2*: Insert current date to active window with G2 :
[[./img/date.png]]
*** G5: Assign to /Hyper/ modifier
In ~$HOME/.Xmodmap~, (create if non existant) rmove any line regarding add the following lines~/Move mouse cursor to top-left corner
In ~Application Shortcut~ section, click on ~Add~, then set command to ~xvkbd -text '\x0\y0'~ (or ~xdotool mousemove 0 0~), click ~OK~, then press ~G6~ when asked.
In ~$HOME/.Xmodmap~, add the following lines :
#+CAPTION: Add an Hyper modifier to G5
#+BEGIN_SRC
! G5 becomes Hyper_L
keycode 195 = Hyper_L NoSymbol Hyper_L
clear mod3
add mod3 = Hyper_L
#+END_SRC
*** G6: Move mouse cursor to top-left corner
In ~Application Shortcut~ section, click on ~Add~, then set command to ~xvkbd -text '\x0\y0'~ (or ~xdotool mousemove 0 0~), click ~OK~, then press ~G6~ when asked.