How can I stop `gnome-screensaver` from resetting my keyboard to its default layout?

I use xmodmap to alter my keyboard layout during session startup. However, each time the GNOME screensaver/lock screen is activated, it resets the keyboard to its default layout, and I have to run xmodmap again to get my keybindings back.

I understand that resetting the keyboard layout is the right thing to do before presenting a password prompt, but Is there a way to stop the GNOME screensaver from doing it? Or a way to tell GNOME to use a custom keyboard layout all the time?


Searching with gconf-tool, I found the setting /desktop/gnome/peripherals/keyboard/general/update_handlers, which apparently is a list of Xmodmap files to be (re)loaded each time the keyboard status is reset.

Settiing this to .Xmodmap made the thing work for me (after logging out and back in).


At log in the .Xmodmap (set up as user or globally) would read properly. However, when the monitor goes to sleep, and I log back in, it would be reset and keys would work as before .Xmodmap was loaded. No setting worked around until at some point I realized that my keyboard is plugged in to the monitor and thus all sittings are lost when the monitor goes to sleep or is turned off. What helped was to plug in the keyboard directly to the computer tower. Now the initial reading of .Xmodmap right after logging in is maintained independently of the monitor being on or off.


You can change GNOME keyboard layout options in System -> Preferences -> Keyboard.

You can edit key bindings in System -> Preferences -> Keyboard Shortcuts.

These may not have the same flexibility as xmodmap, but should work properly even after screensaver/lock screen.


I have custom key bindings stored in an xkb file, which I can load with xkbcomp. I have never experienced any problems with the screensaver resetting this config.

You can then put the xkbcomp command in your .xinitrc file to load the keymap whenever x starts.