UP  |  HOME

xkb

Table of Contents

Change Caps to Left Ctrl, Left Ctrl to Left Hyper.

These are edits to existing files in /usr/share/X11/xkb.

I first created the key remapping in the symbols file. This was based on existing mappings (mostly ctrl:nocaps).

I presume this could also be done in your own unique file.

Next I edited the evdev rules because setxkbmap -print output indicated that evdev was being used.

  • evdev - handles mapping between the ctrl:rule and ctrl(rule) format
  • evdev.lst - is a rule and description listing
  • evdev.xml - has the rules and description in xml grouped appropriately

I suspect the last two are used by dpkg-reconfigure keyboard-configuration to present descriptions. Anyway the evdev file is definitely required to handle the name mapping.

After these changes you can specify your new rule in /etc/default/keyboard or via setxkbmap -option "rule:name"

Listing 1: /etc/default/keyboard
XKBOPTIONS="ctrl:caps_ctrl_hyper"
Listing 2: /usr/share/X11/xkb/rules/evdev (diff)
--- xkb/rules/evdev     2017-07-18 02:38:55.000000000 -0500
+++ rules/evdev 2017-12-20 00:57:09.874129289 -0600
@@ -1050,6 +1050,7 @@
   ctrl:swap_lwin_lctl  =       +ctrl(swap_lwin_lctl)
   ctrl:swap_rwin_rctl  =       +ctrl(swap_rwin_rctl)
   ctrl:swap_lalt_lctl_lwin  =  +ctrl(swap_lalt_lctl_lwin)
+  ctrl:caps_ctrl_hyper  =      +ctrl(caps_ctrl_hyper)
   compose:ralt         =       +compose(ralt)
   compose:lwin         =       +compose(lwin)
   compose:lwin-altgr   =       +compose(lwin-altgr)
Listing 3: /usr/share/X11/xkb/rules/evdev.lst (diff)
--- xkb/rules/evdev.lst 2017-07-18 02:38:55.000000000 -0500
+++ rules/evdev.lst     2017-12-20 00:58:08.146484448 -0600
@@ -788,6 +788,7 @@
   ctrl:swap_lwin_lctl  Swap Left Win key with Left Ctrl key
   ctrl:swap_rwin_rctl  Swap Right Win key with Right Ctrl key
   ctrl:swap_lalt_lctl_lwin Left Alt as Ctrl, Left Ctrl as Win, Left Win as Alt
+  ctrl:caps_ctrl_hyper Caps functions as a left Ctrl. Left ctrl functions as left Hyper
   grp_led              Use keyboard LED to show alternative layout
   grp_led:num          Num Lock
   grp_led:caps         Caps Lock
Listing 4: /usr/share/X11/xkb/rules/evdev.xml (diff)
--- xkb/rules/evdev.xml 2017-07-18 02:38:55.000000000 -0500
+++ rules/evdev.xml     2017-12-20 00:59:42.119034510 -0600
@@ -6410,6 +6410,12 @@
           <description>Left Alt as Ctrl, Left Ctrl as Win, Left Win as Alt</description>
         </configItem>
       </option>
+      <option>
+        <configItem>
+          <name>ctrl:caps_ctrl_hyper</name>
+          <description>Caps functions as a left Ctrl. Left ctrl functions as left Hyper</description>
+        </configItem>
+      </option>
     </group>
     <group allowMultipleSelection="true">
Listing 5: /usr/share/X11/xkb/symbols/ctrl (diff)
--- xkb/symbols/ctrl    2017-07-18 02:38:55.000000000 -0500
+++ symbols/ctrl        2017-12-20 01:00:56.923455108 -0600
@@ -85,3 +85,12 @@
     replace key <LWIN> { [ Alt_L, Meta_L ] };
     replace key <LCTL> { [ Super_L ] };
 };
+
+// Caps functions as a left Ctrl. Left ctrl functions as left Hyper.
+partial modifier_keys
+xkb_symbols "caps_ctrl_hyper" {
+    replace key <LCTL> { [ Hyper_L, Hyper_L ] };
+    modifier_map  Mod4 { <LCTL> };
+    replace key <CAPS> { [ Control_L, Control_L ] };
+    modifier_map  Control { <CAPS> };
+};