r-c-f / waynergy

A synergy client for Wayland compositors
MIT License
422 stars 17 forks source link

Raw keymapping of AltGr on Windows Host not working #43

Open Kjubyte opened 2 years ago

Kjubyte commented 2 years ago

Hi, first of all: Awesome work! Thank you. I'm using waynergy for a few months now but there are two things that I couldn't get to work. One thing is the mapping of the AltGr key from ISO keyboards from a Windows host to Linux KDE using raw keymaps.

When I press AltGr (ISO_Level3_Shift) Windows is sending two different button presses: Left CTRL (0x1d) and Right Alt (0x0138), but there are some differences in the mask. See Debug Log from Barrier.

On Linux they are translated to CTRL + Alt and not AltGr.

Barrier Log Left CTRL:

[2022-07-17T15:40:04] DEBUG1: hook: 0x60a20000 0x001d0001
[2022-07-17T15:40:04] DEBUG1: hook: 0x70a20000 0x001d0001
[2022-07-17T15:40:04] DEBUG1: event: Key char=0, vk=0xa2, nagr=0, lParam=0x001d0001
[2022-07-17T15:40:04] DEBUG1: new mask: 0x2000
[2022-07-17T15:40:04] DEBUG1: new mask: 0x2002
[2022-07-17T15:40:04] DEBUG1: onKeyDown id=61411 mask=0x2002 button=0x001d
[2022-07-17T15:40:04] DEBUG1: send key down to "Groot" id=61411, mask=0x2002, button=0x001d
[2022-07-17T15:40:04] DEBUG1: hook: 0x000000a2 0x801d0001
[2022-07-17T15:40:04] DEBUG1: hook: 0x60a20000 0x801d0001
[2022-07-17T15:40:04] DEBUG1: hook: 0x70a20000 0x801d0001
[2022-07-17T15:40:04] DEBUG1: event: Key char=0, vk=0xa2, nagr=0, lParam=0x801d0001
[2022-07-17T15:40:04] DEBUG1: new mask: 0x2002
[2022-07-17T15:40:04] DEBUG1: new mask: 0x2000
[2022-07-17T15:40:04] DEBUG1: onKeyUp id=61411 mask=0x2000 button=0x001d
[2022-07-17T15:40:04] DEBUG1: send key up to "Groot" id=61411, mask=0x2000, button=0x001d

Barrier Log Right ALT (I switched to US Layout for this test):

[2022-07-17T15:42:51] DEBUG1: hook: 0x60a50000 0x21380001
[2022-07-17T15:42:51] DEBUG1: hook: 0x70a50000 0x21380001
[2022-07-17T15:42:51] DEBUG1: event: Key char=0, vk=0xa5, nagr=0, lParam=0x21380001
[2022-07-17T15:42:51] DEBUG1: new mask: 0x2000
[2022-07-17T15:42:51] DEBUG1: new mask: 0x2004
[2022-07-17T15:42:51] DEBUG1: onKeyDown id=61418 mask=0x2004 button=0x0138
[2022-07-17T15:42:51] DEBUG1: send key down to "Groot" id=61418, mask=0x2004, button=0x0138
[2022-07-17T15:42:51] DEBUG1: hook: 0x000000a5 0x81380001
[2022-07-17T15:42:51] DEBUG1: hook: 0x60a50000 0x81380001
[2022-07-17T15:42:51] DEBUG1: hook: 0x70a50000 0x81380001
[2022-07-17T15:42:51] DEBUG1: event: Key char=0, vk=0xa5, nagr=0, lParam=0x81380001
[2022-07-17T15:42:51] DEBUG1: new mask: 0x2004
[2022-07-17T15:42:51] DEBUG1: new mask: 0x2000
[2022-07-17T15:42:51] DEBUG1: onKeyUp id=61418 mask=0x2000 button=0x0138
[2022-07-17T15:42:51] DEBUG1: send key up to "Groot" id=61418, mask=0x2000, button=0x0138

Barrier Log AltGr:

[2022-07-17T15:43:33] DEBUG1: hook: 0x60a20000 0x221d0001
[2022-07-17T15:43:33] DEBUG1: hook: 0x70a20000 0x221d0001
[2022-07-17T15:43:33] DEBUG1: event: Key char=0, vk=0xa2, nagr=0, lParam=0x221d0001
[2022-07-17T15:43:33] DEBUG1: new mask: 0x2000
[2022-07-17T15:43:33] DEBUG1: new mask: 0x2002
[2022-07-17T15:43:33] DEBUG1: hook: 0x000000a5 0x21380001
[2022-07-17T15:43:33] DEBUG1: hook: 0x500000a5 0x21380001
[2022-07-17T15:43:33] DEBUG1: hook: 0x60a50000 0x21380001
[2022-07-17T15:43:33] DEBUG1: hook: 0x71a50000 0x21380001
[2022-07-17T15:43:33] DEBUG1: event: Key char=0, vk=0xa5, nagr=1, lParam=0x21380001
[2022-07-17T15:43:33] DEBUG1: new mask: 0x2002
[2022-07-17T15:43:33] DEBUG1: new mask: 0x2006
[2022-07-17T15:43:33] DEBUG1: onKeyDown id=61411 mask=0x2002 button=0x001d
[2022-07-17T15:43:33] DEBUG1: send key down to "Groot" id=61411, mask=0x2002, button=0x001d
[2022-07-17T15:43:33] DEBUG1: onKeyDown id=61418 mask=0x2006 button=0x0138
[2022-07-17T15:43:33] DEBUG1: send key down to "Groot" id=61418, mask=0x2006, button=0x0138
[2022-07-17T15:43:33] DEBUG1: hook: 0x000000a2 0x821d0001
[2022-07-17T15:43:33] DEBUG1: hook: 0x60a20000 0x821d0001
[2022-07-17T15:43:33] DEBUG1: hook: 0x70a20000 0x821d0001
[2022-07-17T15:43:33] DEBUG1: event: Key char=0, vk=0xa2, nagr=0, lParam=0x821d0001
[2022-07-17T15:43:33] DEBUG1: new mask: 0x2006
[2022-07-17T15:43:33] DEBUG1: new mask: 0x2004
[2022-07-17T15:43:33] DEBUG1: hook: 0x000000a5 0x81380001
[2022-07-17T15:43:33] DEBUG1: hook: 0x60a50000 0x81380001
[2022-07-17T15:43:33] DEBUG1: hook: 0x70a50000 0x81380001
[2022-07-17T15:43:33] DEBUG1: event: Key char=0, vk=0xa5, nagr=0, lParam=0x81380001
[2022-07-17T15:43:33] DEBUG1: new mask: 0x2004
[2022-07-17T15:43:33] DEBUG1: new mask: 0x2000
[2022-07-17T15:43:33] DEBUG1: onKeyUp id=61411 mask=0x2004 button=0x001d
[2022-07-17T15:43:33] DEBUG1: send key up to "Groot" id=61411, mask=0x2004, button=0x001d
[2022-07-17T15:43:33] DEBUG1: onKeyUp id=61418 mask=0x2000 button=0x0138
[2022-07-17T15:43:33] DEBUG1: send key up to "Groot" id=61418, mask=0x2000, button=0x0138

Waynergy Log with Debug Level 9, First button press Left CTRL, second AltGr, last right Alt with US layout (Note that I"m using offset 8)

524.566094441: [DEBUG] Keycode: 37, state 1
524.694807912: [DEBUG] Modifiers: depressed: 0 latched: 0 locked: 0 group: 0
524.694822522: [DEBUG] Keycode: 37, state 0
526.314833972: [DEBUG] Got CALV
529.316229970: [DEBUG] Got CALV
532.323438271: [DEBUG] Got CALV
535.002327250: [DEBUG] Modifiers: depressed: 4 latched: 0 locked: 0 group: 0
535.002341260: [DEBUG] Keycode: 37, state 1
535.002526958: [DEBUG] keycode greater than xkb maximum, mod not tracked
535.002533998: [DEBUG] Keycode: 320, state 1
535.126529542: [DEBUG] Modifiers: depressed: 0 latched: 0 locked: 0 group: 0
535.126542712: [DEBUG] Keycode: 37, state 0
535.127556363: [DEBUG] keycode greater than xkb maximum, mod not tracked
535.127560733: [DEBUG] Keycode: 320, state 0
...
738.985032757: [DEBUG] keycode greater than xkb maximum, mod not tracked
738.985043607: [DEBUG] Keycode: 320, state 1
739.055045259: [DEBUG] keycode greater than xkb maximum, mod not tracked
739.055060329: [DEBUG] Keycode: 320, state 0

Output of xev without Waynergy, expected result (Again for right Alt I switched to US layout):

<Press Left CTRL>

KeyPress event, serial 39, synthetic NO, window 0x1000001,
    root 0x3b4, subw 0x0, time 9664839, (168,110), root:(168,139),
    state 0x10, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 39, synthetic NO, window 0x1000001,
    root 0x3b4, subw 0x0, time 9664918, (168,110), root:(168,139),
    state 0x14, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

<Press AltGr>

KeyPress event, serial 39, synthetic NO, window 0x1000001,
    root 0x3b4, subw 0x0, time 9681887, (168,110), root:(168,139),
    state 0x10, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES,
    XKeysymToKeycode returns keycode: 92
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 39, synthetic NO, window 0x1000001,
    root 0x3b4, subw 0x0, time 9681942, (168,110), root:(168,139),
    state 0x90, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES,
    XKeysymToKeycode returns keycode: 92
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

<Press Right Alt>

KeyPress event, serial 45, synthetic NO, window 0x1000001,
    root 0x3b4, subw 0x0, time 10533214, (165,9), root:(165,38),
    state 0x10, keycode 108 (keysym 0xffea, Alt_R), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 45, synthetic NO, window 0x1000001,
    root 0x3b4, subw 0x0, time 10533300, (165,9), root:(165,38),
    state 0x18, keycode 108 (keysym 0xffea, Alt_R), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

What I actually get using Waynergy (note I mapped 0x138 to 108, otherwise there would only one button press for AltGr and Right Alt wouldn't work eider. Unfortunately it does not work because of the combination of Left CTRL and AltGr):

<Press Left CTRL>

KeyPress event, serial 47, synthetic NO, window 0x1000001,
    root 0x3b4, subw 0x0, time 10832897, (165,9), root:(165,38),
    state 0x10, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 47, synthetic NO, window 0x1000001,
    root 0x3b4, subw 0x0, time 10832986, (165,9), root:(165,38),
    state 0x14, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

<Press AltGr>

KeyPress event, serial 47, synthetic NO, window 0x1000001,
    root 0x3b4, subw 0x0, time 10834285, (165,9), root:(165,38),
    state 0x10, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyPress event, serial 47, synthetic NO, window 0x1000001,
    root 0x3b4, subw 0x0, time 10834286, (165,9), root:(165,38),
    state 0x14, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES,
    XKeysymToKeycode returns keycode: 92
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 47, synthetic NO, window 0x1000001,
    root 0x3b4, subw 0x0, time 10834353, (165,9), root:(165,38),
    state 0x94, keycode 37 (keysym 0xffe3, Control_L), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 47, synthetic NO, window 0x1000001,
    root 0x3b4, subw 0x0, time 10834353, (165,9), root:(165,38),
    state 0x90, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES,
    XKeysymToKeycode returns keycode: 92
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

<Press Right Alt>

KeyPress event, serial 49, synthetic NO, window 0x1000001,
    root 0x3b4, subw 0x0, time 11163450, (165,9), root:(165,38),
    state 0x10, keycode 108 (keysym 0xffea, Alt_R), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 49, synthetic NO, window 0x1000001,
    root 0x3b4, subw 0x0, time 11163577, (165,9), root:(165,38),
    state 0x18, keycode 108 (keysym 0xffea, Alt_R), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False
r-c-f commented 2 years ago

This is one of the the weaknesses of the KDE protocol at the moment. Within waynergy there's not much that could realistically be done, as unlike wlroots there's no control over the higher level layout to treat this combination appropriately. Does KDE have the ability to set xkb options for the virtual input device?

csarn commented 5 months ago

Any news here? Did the KDE protocol improve since this ticket was opened? I'm experiencing the same problem, with waynergy 0.0.17 on Plasma 6. On a german layout, there's just too many important symbols reachable via ISO_Level3_Shift to accept that key not working.

csarn commented 3 months ago

Being still annoyed by this bug/missing feature, I started wev to look at what keystrokes are actually received on AltGr. It is a combination of both Control_L and ISO_Level3_Shift. So I tried a workaround: Press the actual left control key, then AltGr, then release the control key. This works! It is still annoying, but way easier than copy/pasting the necessary characters from somewhere.