I use a Danish and English (US) keyboard layout, on a keyboard with Nordic geometry, meaning it has a less/greater key. I use the Danish layout for leisure, and the English (US) for work.

I would like this key to be Compose only when I am using the English (US) layout.

Similarly I would like Caps Lock and Escape to swap under those same circumstances.

That is, I need this functionality switch to "conceptually depend" on the keyboard layout widget's state. Which probably means I have to do something in XKB.

Is this possible? How?

Additional information:

~$ setxkbmap -print -verbose 10
Setting verbose level to 10
locale is C
Trying to load rules file ./rules/evdev...
Trying to load rules file /usr/share/X11/xkb/rules/evdev...
Applied rules from evdev:
rules:      evdev
model:      pc105
layout:     dk,us
variant:    ,
Trying to build keymap using the following components:
keycodes:   evdev+aliases(qwerty)
types:      complete
compat:     complete
symbols:    pc+dk+us:2+inet(evdev)
geometry:   pc(pc105)
xkb_keymap {
    xkb_keycodes  { include "evdev+aliases(qwerty)" };
    xkb_types     { include "complete"  };
    xkb_compat    { include "complete"  };
    xkb_symbols   { include "pc+dk+us:2+inet(evdev)"    };
    xkb_geometry  { include "pc(pc105)" };

I can't help with xkb but you can still change the mapping with xmodmap which remains compatible. For example, if I have configured my keyboard with xkb to, eg:

setxkbmap -layout us,fr -option "grp:lctrl_lshift_toggle,compose:102"

and I then dump the mapping with

xmodmap -pke | egrep -i 'less|greater|multi|caps|escape'

it lists the keycodes and the keysyms of interest:

keycode   9 = Escape NoSymbol Escape
keycode  59 = comma less semicolon period horizconnector multiply
keycode  60 = period greater colon slash periodcentered division
keycode  66 = Caps_Lock NoSymbol Caps_Lock
keycode  94 = Multi_key Multi_key Multi_key Multi_key

I can simply move around the columns for the key that I want to change and set up a new mapping for it. You can guess what the columns are for by looking at the keycode for an alphabetic key like "w":

keycode  25 = w W z Z guillemotleft less

The columns in this line seem to be: us, us-shift, fr, fr-shift, fr-altgr, fr-altgr-shift.

So the Escape in column 1 of keycode 9 applies to my keyboard in us mode. If I want Caps_Lock in us mode I do:

xmodmap -e 'keycode 9 = Caps_Lock NoSymbol Escape'

The change should be immediate. When you have tried all the changes, put all the new "keycode =" lines in a file and pipe them into xmodmap - at each login.

| improve this answer | |
  • Unfortunately, this approach is incompatible with what I need it to do: xmodmap is system-wide, is it not? The compose:102 functionality interferes with the Danish keyboard's function, among other problems. – Karl Damgaard Asmussen Aug 15 '15 at 7:36
  • I'm not sure what you mean by "system-wide". There's only one place where the keyboard keycodes are handled, and where the mapping from keycode to keysym is held, and that is in the X11 graphics server. setxkbmap, localectl, xmodmap and any GUI configurator all manipulate this one table. My setxkbmap with compose:102 was just an example I used so that I had a Multi_key compose keysym in my xmodmap output. – meuh Aug 15 '15 at 7:47
  • If I use xmodmap to set Caps lock to escape, then swap keyboard layouts, it is still swapped. I don't want that. I want one layout out of many to be altered. – Karl Damgaard Asmussen Aug 16 '15 at 9:59
  • can you edit your original post and add the output of setxkbmap -print -verbose 10 to it? – meuh Aug 16 '15 at 10:07
  • 1
    @Fabby oh my god, I am so sorry. Don't know how I managed that blunder. – Karl Damgaard Asmussen Aug 17 '15 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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