17

I have ubuntu (11.04) running on a recent macbook pro. I use both the built in keyboard and an external keyboard. I want to remap capslock on both keyboards to super, and I want to swap left-alt (mac option) and left-super (mac cmd) on the built in (apple) keyboard only.

Xmodmap can't configure multiple keyboards differently, so thats out.

I am able to do this from the cli via setkbmap. Here is the script I'm using:

#!/bin/sh
#set caps to super
setxkbmap -option caps:super

#swap command and option for apple keyboard
setxkbmap -device `xinput list | grep -o -P 'Apple Internal Keyboard / Trackpad\s+id=\d+' | grep -o -P '\d+'` -option altwin:swap_lalt_lwin

If I have to, I can run this as a startup application, but I would really like to know if there is a configuration file I can add these settings to instead.

It looks like I should be able to add an option (XkbOptions) to the inputdevice section of my xorg.conf, but when I tried this, the settings had no affect (perhaps gnome overrides the X settings?). I also tried adding a new inputclass to xorg.conf but that didn't work either.

What is the correct place to configure multiple keyboards with different key bindings?

psanford
  • 436
  • 4
  • 15
  • 1
    Note: Putting this script in startup applications fixes it on login, but after resuming from suspend I have to run it manually again. There must be a better way to do this! – psanford May 14 '11 at 20:53
  • 1
    There should be... I have been setting the default layout via `/etc/default/keymap` (Debian) or `/etc/X11/xorg.conf.d/00-keyboard.conf` (Fedora) to avoid the on-resume problem, but it may not work for multiple keyboards with different options (on both OSes, this is used to specify the console keymap as well as the X keymap, and thus is somewhat restricted). – dhardy Feb 17 '14 at 11:38

1 Answers1

9

It is possible to do this in the xorg config:

Section "InputClass"
  Identifier     "Keyboard Catch All"
  MatchUSBID     "058f:9410"
  Option         "XkbOptions" "caps:super,terminate:ctrl_alt_bksp"
EndSection

Section "InputClass"
  Identifier "Apple Keyboards"
  MatchUSBID     "05ac:0236"
  Option         "XkbOptions" "altwin:swap_lalt_lwin,caps:super"
EndSection

However, GDM has its own way of managing you keyboard settings that will overwrite these xorg settings. I have not found a solution that works well with GDM.

psanford
  • 436
  • 4
  • 15