xkbcommon / libxkbcommon

keymap handling library for toolkits and window systems
https://xkbcommon.org
Other
286 stars 125 forks source link

Map a key to a specific real mod ONLY for the currently active layout #511

Closed valkalon closed 1 month ago

valkalon commented 2 months ago

Hi I'm on Ubuntu 22.04 Wayland,learning how to create my personal keyboard layout. I have a question on a behavior that I don't understand. I have 2 active layouts : French and "personal".

I want to map \<LALT> to mod3 in the personal layout ONLY (do not impact other layouts).

I have tested these options but none of them match the need:

case 1 : key \<LALT> { ISO_Level5_Shift }; it applies to all layouts. Not good.

case 2: key \<LALT> { F23 }; I use a compat interpret statement to map F23 to Mod3. Here it works but the ubuntu terminal writes a tilde every time \<LALT> is pushed due to not recognizing the F23 keysym.

case 3: LALT to NoSymbol (suprising result)

key <LALT> {
        symbols[Group1]=[ NoSymbol ],
        actions[Group1]=[SetMods(modifiers=Mod3)]
};

Suprising for me the behavior of LALT on the french layout is disabled, as shown by xkbcomp $DISPLAY :

key <LALT> {
//      type[group1]= "TWO_LEVEL",
        type[group2]= "ONE_LEVEL",

        symbols[Group1]= [           Alt_L,          Meta_L ],
        actions[Group1]= [ NoAction(), NoAction() ],
        symbols[Group2]= [        NoSymbol ],
        actions[Group2]= [ SetMods(modifiers=Mod3) ]
};

Case 3 would be the best solution but I don't understand why it disables the action in the french layout.

Would you have a solution please?

wismill commented 2 months ago

Could you dump the whole keymaps and add case 1 here, then add the diff between the remaining cases, so we have all data to check this?

See: xkbcli compile-keymap.

valkalon commented 2 months ago

I did the dump and investigated but the result does not show what happens to me.

xkbcli compile-keymap gives the output for one layout but the problem appears when input-sources are merged on Ubuntu (french defined as group 1 and "personal" defined as group 2).

I have found a workaround for my need in the meantime using kmonad so I'm good. I don't want to waste your time on this, I close the issue. Thank you!

wismill commented 2 months ago

xkbcli compile-keymap gives the output for one layout but the problem appears when input-sources are merged on Ubuntu (french defined as group 1 and "personal" defined as group 2).

You can pass 2 layouts by separating them with a comma, e.g.:

xkbcli compile-keymap --layout fr,custom
valkalon commented 2 months ago

I did it. The problem was coming from me. I was messing up the compat files. Case 1 solved thank you!

About case 3 though I'm wondering what's happening. Defining symbol/action inline in the symbol file deactivates the actions for the same key in other groups. This happens with any keysym. (I'm aware inlining is not recommended by the documentation at xkbcommon.org)

For the sake of example: rules: evdev compat: complete types: complete

image

and the output from :

xkbcli compile-keymap --include /home/gm/.config/xkb --include-defaults --layout fr,mod8 > keymap_kbd.log

keymap_xkb.log

image

Am I doing something wrong?

wismill commented 2 months ago

I get the same result with setxkbmap | xkbcomp. I think what happens here is that explicit actions is a characteristic of the whole key, not just the key’s group. So by setting explicitly in one group you actually set it explicitly in every group, but your group 1 does have explicit action, thus the NoAction() and no use of interpret entries. Will have to check that again though.

You should probably use modmap None { … }; to get rid of the modifier mapping on <LALT> and keep the ISO_Level5_Shift. Check modifier bindings.

wismill commented 1 month ago

This is actually part of the XKB protocol: “Explicit Keyboard Mapping Components](https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Explicit_Keyboard_Mapping_Components)”.

But I think we should actually set a flag per group and use it to check whether to apply interprets or not to each group.

valkalon commented 1 month ago

Ok I see. indeed a flag would make sense. As a newcomer, the "per group" apply of interprets was my initial assumption.