You are not logged in.

#1 2024-03-15 18:12:53

colegu
Member
Registered: 2022-04-14
Posts: 59

key remapping with xkb

hi all

i'm trying to emulate the behavior of xmodmap into the world of wayland and i'm facing some issues.
basically if i type <a> i want the character "a" to be printed. if i type Shift + a, the character "A" to be displayed, and, if i'm adding an extra modifier key, say, Alt+a, the character aring (å) should be printed, when pressing Shift+Alt+a, another character should be displayed, and so on.

to achieve this i modified /usr/share/X11/xkb/types/pc and added a new modifier type

    type "BaseShiftAlt" {
        modifiers = Control+Alt+Shift;
        map[None] = Level1;
        map[Shift] = Level2;
        map[Control+Alt] = Level3;
        map[Control+Alt+Shift] = Level4;
        level_name[Level1] = "Base";
        level_name[Level2] = "Shift";
        level_name[Level3] = "Alt Base";
        level_name[Level4] = "Shift Alt";
    };

added a custom symbol setting in
/usr/share/X11/xkb/rules/evdev.lst

  baseshiftalt             some random text
  baseshiftalt:xxx_ex     other random text

/usr/share/X11/xkb/rules/evdev

! option    =   symbols
  baseshiftalt:xxx_ex  =   +baseshiftalt(xxx_ex)

and finally created the new symbol map /usr/share/X11/xkb/symbols/baseshiftalt

partial alphanumeric_keys
xkb_symbols "xxx_ex" {
    key.type = "BaseShiftAlt"; 
    key  <a> { type = "BaseShiftAlt",   [ a, A, 0x0103, aring ] };
};

and finally i set the new layout with the extra defined option

setxkbmap -layout us -option baseshiftalt:xxx_ex

however, this does not have the desired effect, and nothing happens if I press alt+a, or shift+alt+a (as specified in the first file mentioned in this post)

if i select a different key mapping, say

    key <LWIN> { [ aring, 0x0103 ] };

, when i press the windows key, the proper a ring character appears. but if I want to select a different modifier type, nothing happens.

somehow, it seems that i'm not properly referencing the "BaseShiftAlt" modifier type,

i know this is not the proper way to do things, since the files above will be overwritten when updating the xkeyboard-config package. at first i just want to see if it's possible to achieve what i want smile

thanks

Offline

#2 2024-03-15 18:37:28

seth
Member
Registered: 2012-09-03
Posts: 51,682

Re: key remapping with xkb

Stay away from everything but the symbols.
The variant is addressed w/ the -variant switch, not an option - the "basic" variant of your layout will be picked automatically.

You probably want to include some "us" layout(variant) - the complete us layout has 37650 less than 40k lines and probably already includes some variants you'd like to pick as base for your custom layout.
Or you can just start with its basic layout and add the higher levels there as you wish.

For an option of your iso level 3 swicth, see

grep lv3 /usr/share/X11/xkb/rules/base.lst

You're probably interested in lv3:ralt_switch ?
You could also include that as

include "level3(ralt_switch)"

in your layout (see eg. xkb_symbols "intl" in the US layout)

Offline

#3 2024-03-15 19:06:13

colegu
Member
Registered: 2022-04-14
Posts: 59

Re: key remapping with xkb

 key  <a> {[ a, A, aring ] };
    include "level3(ralt_switch)"

in the symbols file does exactly nothing. alt gr + a does not generate "a ring"

even if I specify level3(win_switch) still i am not getting the expected result
or maybe the command that i 'm running is wrong (setxkbmap -layout us -option symbols_file:symbols_definition_text) . but, as previously stated, if i am modifying the first 2 definitions then i get the expected results. (i.e. key <a> {[ aring, 0x105 ]};)

the problem comes if i want to add extra modifier keys...

alt gr has the following code

KeyRelease event, serial 39, synthetic NO, window 0x2800001,
    root 0x4a6, subw 0x0, time 48313947, (-152,617), root:(1038,1326),
    state 0x8, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES,
    XKeysymToKeycode returns keycode: 92
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

and the windows key

KeyRelease event, serial 39, synthetic NO, window 0x2800001,
    root 0x4a6, subw 0x0, time 48311379, (-152,617), root:(1038,1326),
    state 0x40, keycode 133 (keysym 0xffeb, Super_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

so i dont thing there is a problem with these particular modifier keys (level 3, in the context above), just referencing their use with the include directive seems not to be working

Last edited by colegu (2024-03-15 19:08:59)

Offline

#4 2024-03-15 19:29:06

seth
Member
Registered: 2012-09-03
Posts: 51,682

Re: key remapping with xkb

That's not a proper layout file and if the setxkbmap command is literal, that's probably nonsense (what is symbols_definition_text?)

You're way overcomplicating things.
Reset the xkb definitions to their defaults and try

setxkbamp -layout us -variant intl
setxkbmap -print -query # post that 

This should get you the us/intl layout which has the lv3 modifier on the right alt key (if you want it somewhere else/in addition, please describe the desired outcome)

If you're going to edit the layout, post that.

nb. that setxkbmap will probably not be useful on wayland, so yout want to test this in either an x11 session or a nested x11 server - the wayland compositors use xkb, but don't necessarily provide any kind of interface that would wire the x11 calls of setxkbmap to their internal implementation.

Offline

#5 2024-03-15 19:49:22

colegu
Member
Registered: 2022-04-14
Posts: 59

Re: key remapping with xkb

seth wrote:

That's not a proper layout file and if the setxkbmap command is literal, that's probably nonsense (what is symbols_definition_text?)


partial alphanumeric_keys
xkb_symbols "symbols_definition_text" {
   
    key  <a> {  [ 0x0111, aring ] };
};

this works, although you re saying that it s nonsense. but it is not the desired effect that i want.

You're way overcomplicating things.

im doing my best with the documentation available to me. it is not something that i enjoy, though smile


setxkbamp -layout us -variant intl

i have tried this but i cannot get to that level 3 and above modified keys. nor using alt gr, nor win key (also changing the include option in the intl section, from altgr)  or any other key

This should get you the us/intl layout which has the lv3 modifier on the right alt key (if you want it somewhere else/in addition, please describe the desired outcome)

but the fact of the matter is that it does not do that.


    key <AD02> { [	   w,          W,         aring,            Aring ] };

this is from the us intl symbols, and there is no way i can obtain the aring and Aring characters by selecting alt gr + w, or shift + alt gr + w

nb. that setxkbmap will probably not be useful on wayland, so yout want to test this in either an x11 session or a nested x11 server - the wayland compositors use xkb, but don't necessarily provide any kind of interface that would wire the x11 calls of setxkbmap to their internal implementation.

now this explains why it does not work in my case. most probably wayland is limited to the first two characters in a key definition. in the example above, w and W will work, but not aring or Aring. only if i swap them, but then i will loose the w and W characters and i don´t want that smile


setxkbmap -print -query # post that 
WARNING: Running setxkbmap against an Xwayland server
xkb_keymap {
        xkb_keycodes  { include "evdev+aliases(qwerty)" };
        xkb_types     { include "complete"      };
        xkb_compat    { include "complete"      };
        xkb_symbols   { include "pc+us(intl)+inet(evdev)"       };
        xkb_geometry  { include "pc(pc105)"     };
};
rules:      evdev
model:      pc105
layout:     us
variant:    intl

using AltGr key has no effect in this case. i have to admit that i ignored the warning. since i managed to produce an actual modification on the keys behavior despite the error. but as i said, maybe i am limited to only two definitions per key, although i did not find this information anywhere tbh...

Last edited by colegu (2024-03-15 19:55:25)

Offline

#6 2024-03-15 20:15:57

seth
Member
Registered: 2012-09-03
Posts: 51,682

Re: key remapping with xkb

The main problem is that you're configuring an xwayland server and the other wayland clients don't see any of this - it'll probably affect eg. Xterm, but the easiest way to test yor layout adjustments is to do this on an x11 session and the configure the wayland session to use the resulting layout.

And yes, the partial layout extension will work, but you don't want to do this by adding more symbols and symbols_definition_text just sounded like a generic placeholder tongue

Offline

#7 2024-03-16 06:53:53

colegu
Member
Registered: 2022-04-14
Posts: 59

Re: key remapping with xkb

configuring x11 is no option due to the overall stability and flickering.

indeed, in xterm i am able to ¨see" the effect of alt gr, but this is not what iḿ looking for .

i'll take a look on how can i start a wayland session directly with the us intl layout. maybe that'll work

Offline

#8 2024-03-16 07:59:23

seth
Member
Registered: 2012-09-03
Posts: 51,682

Re: key remapping with xkb

Afaiu the problem in X11 is only the lockscreen flicker?

Either way, you can test the impact in xterm, but the intl layout doesn't reflect your previous modmap (nothing does, it's highly custom) - the idea is then to copy something like the us intl layout into a custom /usr/share/X11/xkb/symbols/colegu or so and tweak that to your preferences (it's really just "{[plain, shift, altgr, shift+altgr]}"; and then use that layout as default in X11 and wayland.

I'd expect plasma to read /etc/X11/xorg.conf.d/00-keyboard.conf and possibly (still) ~/.config/kxkbrc

Offline

#9 2024-03-16 08:25:13

colegu
Member
Registered: 2022-04-14
Posts: 59

Re: key remapping with xkb

yes, i can tune the intl layout, that is not an issue here. as long as I'll have a functioning extra modifier key (alt gr, windows, etc. doesn´t matter) than it's mission accomplished.


my problem was that i tried to change the default layout but i could see no difference in the current wayland session. it was quite revelatory to test things in a new xterm session.

Offline

#10 2024-03-16 09:00:22

seth
Member
Registered: 2012-09-03
Posts: 51,682

Re: key remapping with xkb

Ok, as a reminder: editing the /usr/share/X11/xkb/symbols/us file is a bad idea, it'll be unconditionally overwritten w/o any warning w/ the next xkb update and all your efforts be lost.

Good luck with your efforts - when you're done, I'll tell you about the iso level 5 shift and xcompose tongue

Offline

#11 2024-03-16 14:55:51

colegu
Member
Registered: 2022-04-14
Posts: 59

Re: key remapping with xkb

it's not that easy, i can't seem to convince wayland to work with any other layout instead of the standard us. it works in xterm or other applications, but not within kde.. sad

Offline

#12 2024-03-16 15:02:44

seth
Member
Registered: 2012-09-03
Posts: 51,682

Re: key remapping with xkb

What exactly did you try?
You can probably forget about the GUI, you'll have to advertise the layout in the rules/*.{lst,xml} but setting it in the xorg config or the kxkbrc config directly should™ work (provided it's a valid layout and loads w/o errors in X11)

Offline

#13 2024-03-17 17:08:50

colegu
Member
Registered: 2022-04-14
Posts: 59

Re: key remapping with xkb

I've set the variant in ~/.config/kxkbrc, but nothing happened. except the fact that it got overwritten or smth...
and I tried something else but forgot what. didn't had the time to work on this too much..

Offline

Board footer

Powered by FluxBB