You are not logged in.

#1 2010-02-15 22:43:44

Legendin
Member
Registered: 2007-04-19
Posts: 10

setxkbmap toggling resets xmodmap mapping

Hello fellow Arch users,

I remap my Caps Lock key to Escape using the following command on X startup:

xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape'

In addition I frequently change between 'us' and 'no' (norwegian) keyboard layouts using setxkbmap. This has worked without a problem (except for the obligatory 0.5% chance of the machine freezing which keeps the nerves on edge), however when I today adopted the following script/snippet

if [ `setxkbmap -print | grep xkb_symbols | awk '{print $4}' | awk -F"+" '{print $2}'` = us ] ;then setxkbmap no ; else setxkbmap us ; fi

to enable toggling, I quickly noticed that it somehow has the adverse side effect of undoing my previously mentioned Caps Lock remap.

I find this strange, but as my bash-fu is severely limited I am left wondering as to the cause of the problem.


Are you able to verify the issue and/or find the culprit?

Offline

#2 2010-02-15 23:05:43

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 834
Website

Re: setxkbmap toggling resets xmodmap mapping

If using setxkbmap you will have to run xmodmap again. I don't want to go into your script but rather to suggest an alternative approach, make X.org work for you. In /etc/hal/fdi/policy/10-keymap.fdi you can setup something like this (only showing relevant lines):

      <merge key="input.x11_options.XkbLayout" type="string">no,us</merge>
      <merge key="input.x11_options.XkbOptions" type="string">grp:shift_toggle,grp_led:scroll</merge>

What this means? When you press both Shift keys at the same time your keyboard layout is switched. The second setting, grp_led says that your Scroll Lock will indicate which layout is in use. You can remove that one if you don't want it. By pressing both Shift keys your layout will change but your custom xmodmap will not, and it saves you with trouble with custom scripts and will work independant of window manager or desktop environment.

Here is one more tip for you you can add the option caps:escape to the above Xkb.Options line and your Caps becomes Esc without any Xmodmap modifications. Note that if you still use xorg.conf you can do all of these things there too. Have fun :^)


You need to install an RTFM interface.

Offline

#3 2010-02-15 23:47:54

Legendin
Member
Registered: 2007-04-19
Posts: 10

Re: setxkbmap toggling resets xmodmap mapping

anrxc wrote:

If using setxkbmap you will have to run xmodmap again. I don't want to go into your script but rather to suggest an alternative approach, make X.org work for you. In /etc/hal/fdi/policy/10-keymap.fdi you can setup something like this (only showing relevant lines):

      <merge key="input.x11_options.XkbLayout" type="string">no,us</merge>
      <merge key="input.x11_options.XkbOptions" type="string">grp:shift_toggle,grp_led:scroll</merge>

What this means? When you press both Shift keys at the same time your keyboard layout is switched. The second setting, grp_led says that your Scroll Lock will indicate which layout is in use. You can remove that one if you don't want it. By pressing both Shift keys your layout will change but your custom xmodmap will not, and it saves you with trouble with custom scripts and will work independant of window manager or desktop environment.

Here is one more tip for you you can add the option caps:escape to the above Xkb.Options line and your Caps becomes Esc without any Xmodmap modifications. Note that if you still use xorg.conf you can do all of these things there too. Have fun :^)

Your alternative solution is working great, and probably is a better choice in this situation for the reasons you state. My laptop does not seem to be too happy about using the scroll LED for layout indication, but that's not a big deal.

I am however still curious as to what the source of my original problem was, seeing as none of the individual components of the bash script caused the mapping to be reset when used on their own.

Anyway, thanks again for showing me a different and less messy approach smile

Offline

#4 2010-02-16 01:39:37

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 834
Website

Re: setxkbmap toggling resets xmodmap mapping

Legendin wrote:

I am however still curious as to what the source of my original problem was, seeing as none of the individual components of the bash script caused the mapping to be reset when used on their own.

The problem wasn't with your code, it was the fact that it executes setxkbmap because: "setxkbmap not only alters the alphanumeric keys to the values given in the map; it also resets all other keys to the startup default". Source: http://wiki.linuxquestions.org/wiki/Con … _keyboards

Edit: to get a LED working you can replace scroll with num or caps (but I'm not sure if they affect or confuse the keyboard, scroll is one of those most people never use so it's quite suitable for the job)

Last edited by anrxc (2010-02-16 01:44:48)


You need to install an RTFM interface.

Offline

Board footer

Powered by FluxBB