Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using xmodmap (and sometimes xkbcomp instead) to adjust my keyboard layout (e.g. mapping Caps Lock to the Mod3 modifier).

When I plug a USB keyboard into my laptop or insert a YubiKey (which acts like a keyboard), the settings for my laptop keyboard are immediately lost, leaving me in situations where Mod3 stops working and I cannot use my window manager any more.

How can I make my xmodmap/xkbcomp settings persistent or at least persistent per X session for my internal keyboard, so that it keeps the layout, no matter if I attach other keybaords?

share|improve this question

It looks like it is not X, but gnome-settings-daemon that resets my layouts when I attach a new keyboard.

This helped: udev rule to auto load keyboard layout when usb keyboard plugged in

dconf write /org/gnome/settings-daemon/plugins/keyboard/active false

to disable it from doing that.

share|improve this answer

You may try inputplug, a daemon which connects to your X server and listens for XInput events. It can run your script which reloads the keymap:

inputplug -c ~/.xkb_load_hook

And ~/.xkb_load_hook in my case is:

#!/bin/sh

xkbcomp -I$HOME/.xkb ~/.xkb_keymap :0 2>/dev/null 1>/dev/null
xmodmap ~/.xmodmaprc

sun_id=$(xinput list | grep "HID 0430:0005" | grep -o 'id=[0-9]*' | cut -d = -f 2)

if [ -n "$sun_id" ]
then
    xkbcomp -i "$sun_id" -I$HOME/.xkb ~/.xkb_keymap_sun :0 2>/dev/null 1>/dev/null
fi

The last bit detects a Sun Type 6 keyboard and applies different settings for it.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .