Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

On my laptop, I tweak some keybindings and keyboard preferences with xmodmap and xset. When I plug an external USB keyboard, the configuration for that new keyboard is the default, i.e., without my tweaks. If I xmodmap and xset again, then these preferences are applied to the newly plugged keyboard too, but on pluging/unpluging, they are again reseted to the default. Note that the pluging/unpluging never affects the configuration of the laptop keyboard, which stay tuned during the whole process.

Question: How can I have one xmodmap and xset preference set, which applies to any keyboard (plugged now and in the future).

Configuration: Arch Linux on 3.1.1 kernel, Xorg 1.11.2 with no homemade configuration, window manager: awesome 3.4.11, no kde or gnome stuff

Thanks!

share|improve this question
    
What distribution are you using, and what desktop environment? This looks like some program on your system is hooking onto the hardware event notifications and imposing its own configuration when an plug/unplug event occurs. –  Gilles Jan 13 '12 at 23:07
    
Gilles, thanks for your answer. I didn't think my environment was relevant, sorry. As I've added, I have no desktop environment but a simple window manager. Thanks! –  Michaël Jan 14 '12 at 3:13

3 Answers 3

@Patkos Csaba: It changed: now the default is that you don't have to configure anything at all and it works automagically. In a certain way, adding setxkbmap to .xinitrc became way easier than changing the server configuration.

Nowadays you can plug an USB keyboard or mouse and have X11 add it and recognize it, no need to rely on /dev/mice or something like that.

Now I've experienced the issue and, IMHO, the perfect solution would be some way to tell Xorg to inherit the new keyboard settings from the currently connected keyboard or to tell setxkbmap to set the options as the server default for current and future keyboards.

So far, I did not find any way to do so. The only way to avoid running setxkbmap/xmodmap again is to edit the default settings employed by hald when configuring new devices, see the freebsd documentation, §6.4.2 (some paragraphs below the section header, has two examples of setting keyboard defaults). See also "option 2" at Klaas Teschauer's tutorial on the hal migration. There's also a question on Stackoverflow with links about triggering a script on hardware additions, if you prefer to do it that way.

share|improve this answer

I never used it, but 'usbd' seems to be what you are looking for. According to it's documentation it watches usb ports and executes user commands on specific changes.

Here is the man page.

share|improve this answer
    
The main point of my question is that the device-specific xmodmap and xset properties is probably a feature. Xorg tracks back which device is triggered, and acts accordingly. I have the feeling that this can be disabled; I didn't plan to add more mechanisms --- though of course, if no better answer is given, yours will be chosen. –  Michaël Jan 14 '12 at 18:11
    
I do not know about X.org monitoring input devices. Maybe something changed in the past couple of years since I used multiple keyboards, but as far as I know X.org knows what you have connected when it starts. After that you need some mechanism to notify it. Of course, you could just put an icon on the desktop or assign a shortcut to run those commands. –  Patkos Csaba Jan 15 '12 at 9:55

I managed to solve this problem by using Xorg configuration files generated with localectl. I use a dvorak/qwerty layout with capslock as an extra control key. I previously had this in my .xinitrc:

setxkbmap -layout us,us -variant dvorak, \
-option 'grp:alt_space_toggle' \
-option 'grp_led:caps' \
-option 'ctrl:nocaps'

To get the equivalent setup in an Xorg configuration file, I used

sudo localectl set-x11-keymap us,us "" dvorak, 'grp:alt_space_toggle,grp_led:caps,ctrl:nocaps'

which gets stored in the file /etc/X11/xorg.conf.d/00-keyboard.conf.

From the archwiki keyboard configuration page:

For convenience, the tool localectl may be used instead of manually editing X configuration files. It will save the configuration in /etc/X11/xorg.conf.d/00-keyboard.conf, this file should not be manually edited, because localectl will overwrite the changes on next start.

The usage is as follows:

  $ localectl set-x11-keymap layout [model] [variant] [options]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.