My hack to allow disabling of numlock without messing with my xmonad mod key

In short: I've thrown a script together that executes the xmodmap command needed to completely disable to numlock key. What this script does is make sure that xmonad is up and running _before_ xmodmap is called. Combined with Adam's addition to my handleEventHook in xmonad.hs I've now managed to squash the numlock key into oblivion. Mission accomplished! I can't say I like this solution, but at least it gets the job done. I would still very much prefer if this could've been fixed in xmonad.hs, or if xmonad would just let me do my xmodmap'ing without destroying my mod key, but as that does not seem to be possible, I'll settle for second best. So if anybody else out there is having this problem, a bit of BASH will solve it. Just make sure you have this in your handleEventHook: ( \e -> case e of MappingNotifyEvent {} -> return (All False) _ -> mempty) and that your xmodmap calls are done _after_ xmonad is fully loaded. I call my script from .xinitrc just before I start xmonad. The script is backgrounded and it simply loops until it finds a running xmonad instance. :o) Thomas Løcke

On Wed, Mar 20, 2013 at 8:11 AM, Thomas Løcke
I would still very much prefer if this could've been fixed in xmonad.hs, or if xmonad would just let me do my xmodmap'ing without destroying my mod key, but as that does not seem to be possible, I'll settle for second best.
Again, you cannot fix this reliably with xmodmap, you must use Xkb. Your solution will work as long as the interaction *in the X server* between Xkb and xmodmap is not disturbed (luckily for you, even the xorg devs are terrified of disturbing it...). And again, this is not really an xmonad issue. You are fighting against the essential incompatibility between Xkb keymaps and xmodmap with respect to any modifier whose behavior is hardcoded into an Xkb keymap, a problem which has been known for years (the XFree86/xorg folks have tried to deprecate xmodmap many times since Xkb was added because of this incompatibility, but users won't use complex-looking Xkb mechanisms to e.g. swap caps lock and control keys). This *cannot* be fixed in xmonad; the problem is happening in the guts of the keyboard driver in the X server, and by the time xmonad gets involved it's far too late to deal with it. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

On Wed, Mar 20, 2013 at 2:26 PM, Brandon Allbery
Again, you cannot fix this reliably with xmodmap, you must use Xkb. Your solution will work as long as the interaction *in the X server* between Xkb and xmodmap is not disturbed (luckily for you, even the xorg devs are terrified of disturbing it...).
Xkb is scary. I've looked at it, and I cannot even begin to grasp what I need to do in order to accomplish what a short xmodmap one-liner does. That said, I would of course much prefer to do this the right way, instead of my current hackish solution.
And again, this is not really an xmonad issue. You are fighting against the essential incompatibility between Xkb keymaps and xmodmap with respect to any modifier whose behavior is hardcoded into an Xkb keymap, a problem which has been known for years (the XFree86/xorg folks have tried to deprecate xmodmap many times since Xkb was added because of this incompatibility, but users won't use complex-looking Xkb mechanisms to e.g. swap caps lock and control keys).
I'm not saying this is an xmonad issue as such, I'm saying that when I'm using xmonad, weird stuff happens when I use xmodmap to clear my numlock key. The same weird stuff does not happen when I use KDE or Fluxbox. These two WM's happily accept my .Xmodmap file and numlock stays disabled without other keyboard shortcuts being affected.
This *cannot* be fixed in xmonad; the problem is happening in the guts of the keyboard driver in the X server, and by the time xmonad gets involved it's far too late to deal with it.
I guess I need to find myself an Xkb wizard and bribe him/her to help me kill the numlock key the right way. Does anybody here happen to know such a person? :) Thomas Løcke

On Wed, Mar 20, 2013 at 10:57 AM, Thomas Løcke
I'm not saying this is an xmonad issue as such, I'm saying that when I'm using xmonad, weird stuff happens when I use xmodmap to clear my numlock key. The same weird stuff does not happen when I use KDE or Fluxbox. These two WM's happily accept my .Xmodmap file and numlock stays disabled without other keyboard shortcuts being affected.
They appear to be using different ways to intercept keys. xmonad is minimalist, and deliberately avoiding the higher level mechanisms in favor of simple passive grabs... but that means we rely on the X server doing the right thing with the keys at a low level, and if you try to use xmodmap to modify things hardcoded into Xkb's config this breaks. (Actually, I would not be too surprised if they're trapping things at an even lower level which would let them avoid this, but that would be a lot of additional complex code. It's not too surprising that KDE at least might do so, since it also lets them avoid some differences in behavior with non-X11 interfaces [KDE has limited Windows support and somewhat buggy but functional native OS X support]. I have not studied fluxbox's code, but it may also be doing this. I can say that I would not particularly want to trap raw keycode events and implement the modifiers myself, as would be necessary with this approach; but it would at least partially avoid the X server getting confused about the modifiers because of Xkb/xmodmap conflicts.) As for Xkb wizards, there are few such. Not even the xorg devs really understand it that well! See http://www.charvolant.org/~doug/xkb/html/index.html (although it seems to not be responding for me right now). It's a bit of a crawling horror, which nobody really understands (else they would have sorted out this mess, since they've known about it for something like ten years) and everyone is afraid to touch. That said, the basic solution is to use that web page as a guide, copy the Xkb keymap definition you're using and remove all the numlock-related parts. (Unfortunately, that may be easier said than done, given the mess that is Xkb.) -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

On Wed, Mar 20, 2013 at 4:28 PM, Brandon Allbery
As for Xkb wizards, there are few such. Not even the xorg devs really understand it that well! See http://www.charvolant.org/~doug/xkb/html/index.html (although it seems to not be responding for me right now). It's a bit of a crawling horror, which nobody really understands (else they would have sorted out this mess, since they've known about it for something like ten years) and everyone is afraid to touch. That said, the basic solution is to use that web page as a guide, copy the Xkb keymap definition you're using and remove all the numlock-related parts. (Unfortunately, that may be easier said than done, given the mess that is Xkb.)
Yea, that URL seems somewhat dead at the moment. I did though manage to find this one: http://thomer.com/howtos/kxkb_xmodmap.html That does not seem overly complicated. Whether it can actually be used to completely disable the numlock key I'm not sure, but it is worth a shot. If I can't outright disable the numlock key, maybe I can map it to something else, like this Thomer guy have done with the caps key. All in all this truly is a mess. Disabling a key should be dead-simple. I'm guessing it is issues such as this one that the wayland/mir people are trying to solve? :o) Thomas Løcke

Hi, On Wed, Mar 20, 2013 at 05:40:34PM +0100, Thomas Løcke wrote:
All in all this truly is a mess. Disabling a key should be dead-simple. I'm guessing it is issues such as this one that the wayland/mir people are trying to solve?
Here's my config that I can explain :) modifier_map entries affect only applications using the core (old protocol), that includes Xmonad. key entries affect the whole configuration and allow for easy remapping. Probably all you need to disable numlock is modifier_map none { <NMLK> }; // use right alt exclusively for alt, left alt for meta // map to *_L keys because xvkbd can emulate only left modifiers partial modifier_keys xkb_symbols "ralt_as_mod3" { key <RALT> { [ Alt_L, Alt_L ] }; modifier_map Mod3 { Alt_L }; key <LALT> { [ Meta_L, Meta_L ] }; }; // Switch left control and left shift for healthier Emacsing xkb_symbols "switch_lctl_lfsh" { key <LCTL> { [ Shift_L, Shift_L ] }; key <LFSH> { [ Control_L, Control_L ] }; }; // This is needed to workaround a bug in xvkbd to make // it use Mode_Switch for AltGr (to choose 2nd group) partial modifier_keys xkb_symbols "remove_lvl3_from_mod5" { modifier_map none { <LVL3> }; }; -- Be free, use free (http://www.gnu.org/philosophy/free-sw.html) software! mailto:fercerpav@gmail.com

Hi, On 20.03.2013 17:40, Thomas Løcke wrote:
On Wed, Mar 20, 2013 at 4:28 PM, Brandon Allbery
wrote: http://www.charvolant.org/~doug/xkb/html/index.html (although it seems to not be responding for me right now).
Yea, that URL seems somewhat dead at the moment.
That's a pity, it was a pretty fine resource. I used it to write my xkb conf. However, I'd like to throw another helpful document on configuring xkb. Not as vast as charvolant, but it helped me a lot too. http://pascal.tsu.ru/en/xkb/ Not sure if it helps you, but I could send you my config with some comments off-list if you want. Wishes, Jochen

On Wed, Mar 20, 2013 at 8:44 PM, Jochen Keil
That's a pity, it was a pretty fine resource. I used it to write my xkb conf. However, I'd like to throw another helpful document on configuring xkb. Not as vast as charvolant, but it helped me a lot too.
Not sure if it helps you, but I could send you my config with some comments off-list if you want.
Great link, and yes I would be very grateful for your commented config. :)

Hello, I'm sending this to the list as well, maybe someone else will find it useful too. On 20.03.2013 22:07, Thomas Løcke wrote:
Great link, and yes I would be very grateful for your commented config. :)
It's not very sophisticated and does only a few simple things: Map 'Menu' to Mod4 and Replace 'Caps Lock' with Escape I also had Caps Lock to set the 'Ctrl' modifier together with sending the 'Escape' keysym which work fine. However, I didn't like the behaviour so I turned it off again. It is really important to set the directory structure properly, e.g. like so (this was one source for headache): .xkb ├── keymap │ └── default -> /home/jrk/.xkb/keymap/default └── symbols ├── capslock -> /home/jrk/.xkb/symbols/capslock └── modmap -> /home/jrk/.xkb/symbols/modmap xkbcomp is also very peculiar on how it wants to be called. You can try and fiddle around with the include paths, but I remember it being quite cumbersome. # xkbcomp -I${HOME}/.xkb ${HOME}/.xkb/keymap/default $DISPLAY symbols/capslock: // Replace Caps Lock with Escape // hidden: a variant that can only be used within the configuration file // partial: not a complete keymap, used to augment/modify other maps partial hidden modifier_keys xkb_symbols "capsescape" { replace key <CAPS> { type[Group1] = "ONE_LEVEL", symbols[Group1] = [ Escape ] // this would additionally set the 'Ctrl' modifier // (notice the comma after 'Escape') // key names like Escape are taken from // /usr/include/X11/keysymdef.h without the 'XK_' prefix // symbols[Group1] = [ Escape ], // actions[Group1] = [ SetMods(modifiers=Control) ] }; }; symbols/modmap: // you can have more than definition here, depends on with one you load // in your keymap file partial hidden modifier_keys xkb_symbols "mod1" { modifier_map Mod1 { Menu }; }; partial hidden modifier_keys xkb_symbols "menu" { modifier_map Mod4 { Menu }; }; keymap/default: // kind of a minimal complete definition // required: xkb_{keycodes,types,compat,symbols} default xkb_keymap "default" { // re xkb_keycodes { include "evdev+aliases(qwerty)" }; xkb_types { include "complete" }; xkb_compat { include "complete" }; xkb_symbols { // need a complete keymap, e.g. altgr-intl include "pc+us(altgr-intl)+inet(evdev)" // our own modifications include "capslock(capsescape)" include "modmap(menu)" }; }; There are also several useful resources on you system where you can look at. Keymaps and modification maps can be found in /usr/share/X11/xkb. Look at symbols/capslock for a good start. Options, etc. can be found in the rules *.lst files. And finally here's another link I found useful: http://madduck.net/docs/extending-xkb/ I hope this helped you, Jochen

Thank you to you all for trying to help me solve this issue.
I tried going down the setxkbmap route, but after several hours of failing
I went with the simplest possible solution: I re-mapped <NMLK> to a keycode
that apparently only triggers on Japanese keyboards. This works a charm, as
long as I don't use a Japanese keyboard, in which case I will then toggle
numlock on some to me unknown key. :D
The "fix" was extremely simple: Edit the <NMLK> = 77; line in
/etc/X11/xkb/keycodes/evdev and restart X. Numlock is now dead as a
doorknob, at least on my Danish keyboard.
I understand that this is not really the right way to do things, but since
I simply could not figure out how to do this the right way, I'm going to
have to settle. And at least I'm not using xmodmap!
:o)
Thomas Løcke
On Thu, Mar 21, 2013 at 10:35 AM, Jochen Keil
Hello,
I'm sending this to the list as well, maybe someone else will find it useful too.
On 20.03.2013 22:07, Thomas Løcke wrote:
Great link, and yes I would be very grateful for your commented config. :)
It's not very sophisticated and does only a few simple things: Map 'Menu' to Mod4 and Replace 'Caps Lock' with Escape
I also had Caps Lock to set the 'Ctrl' modifier together with sending the 'Escape' keysym which work fine. However, I didn't like the behaviour so I turned it off again.
It is really important to set the directory structure properly, e.g. like so (this was one source for headache):
.xkb ├── keymap │ └── default -> /home/jrk/.xkb/keymap/default └── symbols ├── capslock -> /home/jrk/.xkb/symbols/capslock └── modmap -> /home/jrk/.xkb/symbols/modmap
xkbcomp is also very peculiar on how it wants to be called. You can try and fiddle around with the include paths, but I remember it being quite cumbersome.
# xkbcomp -I${HOME}/.xkb ${HOME}/.xkb/keymap/default $DISPLAY
symbols/capslock: // Replace Caps Lock with Escape // hidden: a variant that can only be used within the configuration file // partial: not a complete keymap, used to augment/modify other maps partial hidden modifier_keys xkb_symbols "capsescape" { replace key <CAPS> { type[Group1] = "ONE_LEVEL", symbols[Group1] = [ Escape ] // this would additionally set the 'Ctrl' modifier // (notice the comma after 'Escape') // key names like Escape are taken from // /usr/include/X11/keysymdef.h without the 'XK_' prefix // symbols[Group1] = [ Escape ], // actions[Group1] = [ SetMods(modifiers=Control) ] }; };
symbols/modmap: // you can have more than definition here, depends on with one you load // in your keymap file partial hidden modifier_keys xkb_symbols "mod1" { modifier_map Mod1 { Menu }; };
partial hidden modifier_keys xkb_symbols "menu" { modifier_map Mod4 { Menu }; };
keymap/default: // kind of a minimal complete definition // required: xkb_{keycodes,types,compat,symbols} default xkb_keymap "default" { // re xkb_keycodes { include "evdev+aliases(qwerty)" }; xkb_types { include "complete" }; xkb_compat { include "complete" }; xkb_symbols { // need a complete keymap, e.g. altgr-intl include "pc+us(altgr-intl)+inet(evdev)" // our own modifications include "capslock(capsescape)" include "modmap(menu)" }; };
There are also several useful resources on you system where you can look at. Keymaps and modification maps can be found in /usr/share/X11/xkb. Look at symbols/capslock for a good start. Options, etc. can be found in the rules *.lst files.
And finally here's another link I found useful: http://madduck.net/docs/extending-xkb/
I hope this helped you,
Jochen
participants (4)
-
Brandon Allbery
-
Jochen Keil
-
Paul Fertser
-
Thomas Løcke