Skip to content

Instantly share code, notes, and snippets.

@nh2
Created January 23, 2016 01:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nh2/ff15f412881f35ab7730 to your computer and use it in GitHub Desktop.
Save nh2/ff15f412881f35ab7730 to your computer and use it in GitHub Desktop.
xkb setup to turn Caps Lock into Mod3 on Linux (e.c. for use with the i3 window manager)

Add new symbols file

Create /usr/share/X11/xkb/symbols/nh2-thinkpad with content:

// based on a keyboard map from an 'xkb/symbols/gb' file

default  partial alphanumeric_keys
xkb_symbols "basic" {

    // Makes Caps Lock become the "Hyper" key, and be the Mod3 modifier.
    // This allows me to easily use Mod3 in the i3 window manager without
    // messing with `setxkbmap`/`xmodmap`; it even keeps working when
    // re-plugging the keyboard.

    name[Group1]="English (UK) nh2 Thinkpad";
    include "gb"

    key <CAPS>  { [ Hyper_L ] };

    modifier_map Mod3 { <CAPS> };
    modifier_map Mod3 { <HYPR> };

    include "level3(ralt_switch_multikey)"
};

Make symbols available in system-wide choice list

To /usr/share/X11/xkb/rules/evdev.xml add an entire <layout> section, copied from the <layout> section that contains <name>gb</name>, but just below that gb <layout> section. That means, put in:

    <layout>
      <configItem>
        <name>gb-nh2-thinkpad</name>
        <shortDescription>en</shortDescription>
        <description>English (UK) nh2 Thinkpad</description>
        <languageList>
          <iso639Id>eng</iso639Id>
        </languageList>
      </configItem>
      <variantList>
      </variantList>
    </layout>

Then log out and log in again.

The keyboard layout should now be available in the Unity/Gnome/whatever layout selection menu. It even appears in the GDM login screen!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment