xmodmap
has no notion of state, so it has no way to reset state directly. You can simulate it by using xmodmap -pke >.xmodmap.orig
before making any changes (although it doesn't save the modifier map, which you would have to save and restore manually) — but it's a bit too late for that.
Modern systems don't generally use xmodmap
to configure the keyboard, though. setxkbmap
is the modern way to do it; and that does reset bindings when run. So you may be able to use setxkbmap -layout us
to reset things to normal. More complete would be to check for the default configuration in /etc/X11/xorg.conf
. For example, on my system
jinx:718 Z$ sed -n '/Identifier.*Keyboard/,/EndSection/p' /etc/X11/xorg.conf
Identifier "Generic Keyboard"
Driver "kbd"
Option "XkbModel" "pc105"
Option "XkbLayout" "us"
Option "XkbOptions" "grp:alt_shift_toggle"
EndSection
The corresponding command is
setxkbmap -model pc105 -layout us -option grp:alt_shift_toggle
If there were an XkbVariant
entry in the output, you would pass its value with -variant
. One thing to watch out for is that options are handled specially: you can only set one option per -option
parameter, and you need to use -option ''
to reset parameters first. So to fully reset when there is something like XkbOptions "grp:alt_shift_toggle,grp:ctrls_toggle"
you would need
setxkbmap -model pc105 -layout us -option '' -option grp:alt_shift_toggle -option grp:ctrls_toggle
@i08in https://askubuntu.com/a/92235/72576 seems to do the job.
This is what I ended up with on my Debian jessie, KDE.
/etc/pm/sleep.d/20_xmodmap.sh
case "${1}" in
resume|thaw)
su $USER -c "sleep 3; /usr/bin/xmodmap /home/$USER/.Xmodmap" &
;;
esac
Note: At first it may seem to not work, but just give it a minute or so. There seems to be something with X that cuses this delay, though I haven't cared enough to check on it... See https://superuser.com/q/626769/185360 for more info.
Best Answer
I think the problem is that you are mixing
xmodmap
commands withsetxkbmap
commands (whether on the command-line or by using the graphical settings menus). As you have observed, thesetxkbmap
commands will override thexmodmap
commands when you change your keyboard layout. The logical solution would therefore be to usesetxkbmap
to change both your layout and the keypad comma to a decimal period.When you use
setxkbmap
to change your layout any specified customisations will also be applied: the full list of options is available at/usr/share/X11/xkb/rules/evdev.lst
. I don't know which language layouts you use, so I have placed just two examples at the end of the following command, which you can use to switch layouts with ALt+Shift. If you have any more key mappings or bindings you want to activate, simply add them to the command:The first command switch (
-option ''
) clears any current settings, as when new settings are given they are added to and do not replace any existing ones unless this option is used. The second (-option kpdl:dot
) makes sure that the appropriate keypad key is a dot or period; the third command switch (-option grp:switch,grp:alt_shift_toggle
) sets up your ability to switch the layouts with ALt+Shift, and the last (gb,nl
) specifies the layouts to switch to.To check your settings, you can enter
which results in:
Add the full
setxkbmap
line further above as a startup item to make sure it is activated and available for you to use.More information on
setxkbmap
is available by enteringman setxkbmap
or by viewing the Ubuntu manpages online.