gujjwal00 / avnc

VNC Client for Android
GNU General Public License v3.0
660 stars 59 forks source link

still AltGr / ISO-L3 key problems #149

Closed macdanger closed 1 year ago

macdanger commented 1 year ago

Hi, first of all thanks for providing one of the best VNC clients on Android IMHO! Problem: unable to type L3 characters (using the AltGr modifier) against tigervncserver on Debian while tigervncclient works well

Test cases: 1) tigervnc client (on ubuntu) against tigervncserver (debian, running gnome-shell) -> all special keys work in all apps flawlessly 2) avnc on Samsung S8 Ultra in DeX mode using Book Cover Keyboard (hardware keyboard), with "right-alt to super" mapping -> works in some apps, not in Firefox and Thunderbird 3) avnc on Samsung S8 Ultra in DeX mode using Book Cover Keyboard (hardware keyboard), without "right-alt to super" mapping -> does not work at all

For generating logs I used:

It looks like avnc is sending confusing / incorrect keypress / keyrelease events when using AltGr. When using avnc'S right-alt-to-super mapping it works e.g. in gnome terminal but not in Firefox or Thunderbird. It is especially painfull in Thunderbird as the '@' (at) is actually AltGr+Q on a German keyboard. The correct sequence (sent by tigervncclient and other working clients):

`KeyPress event, serial 28, synthetic NO, window 0x5000001, root 0x3b4, subw 0x0, time 339284754, (-858,1196), root:(489,1423), 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

KeyPress event, serial 28, synthetic NO, window 0x5000001, root 0x3b4, subw 0x0, time 339284962, (-858,1196), root:(489,1423), state 0x90, keycode 20 (keysym 0x5c, backslash), same_screen YES, XLookupString gives 1 bytes: (5c) "\" XmbLookupString gives 1 bytes: (5c) "\" XFilterEvent returns: False

KeyRelease event, serial 28, synthetic NO, window 0x5000001, root 0x3b4, subw 0x0, time 339285061, (-858,1196), root:(489,1423), state 0x90, keycode 20 (keysym 0x5c, backslash), same_screen YES, XLookupString gives 1 bytes: (5c) "\" XFilterEvent returns: False

KeyRelease event, serial 28, synthetic NO, window 0x5000001, root 0x3b4, subw 0x0, time 339285104, (-858,1196), root:(489,1423), state 0x90, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES, XKeysymToKeycode returns keycode: 92 XLookupString gives 0 bytes: XFilterEvent returns: False`

key-test_BACKSLASH_no-super-mapping_not-working_avnc.txt key-test_BACKSLASH_right-alt-to-super-mapping_half-working_avnc.txt xev_events_BACKSLASH_no-super-mapping_not-working_avnc.txt xev_events_BACKSLASH_right-alt-to-super-mapping_half-working_avnc.txt xev_events_BACKSLASH_working_tigervncviewer.txt xinput_events_BACKSLASH_no-super-mapping_not-working_avnc.txt xinput_events_BACKSLASH_right-alt-to-super-mapping_half-working_avnc.txt xinput_events_BACKSLASH_working_tigervncviewer.txt

gujjwal00 commented 1 year ago

Thank you for the very detailed report @macdanger . This is really helpful.

Before going further, lets see if using raw key events fixes this:

  1. Enable raw key handling in tigervncserver by passing -RawKeyboard=1 argument
  2. Install this APK : app-debug.zip (from #129)
  3. Test key handling
macdanger commented 1 year ago

thanks for your quick response.

60009 ? Ss 0:00 /usr/bin/perl /usr/bin/vncserver -RawKeyboard=1 -localhost no -depth 32 -geometry 1280x800 :1 60011 ? Ssl 1:00 /usr/bin/Xtigervnc :1 -rfbport 5901 -localhost=0 -SecurityTypes VncAuth,TLSVnc -PasswordFile /home/user/.vnc/passwd -ClientWaitTimeMillis 30000 -NeverShared=0 -AlwaysShared=1 -RawKeyboard=1 -geometry 1280x800 -desktop host.domain.net:1 (markus) -depth 32 -auth /home/user/.Xauthority

The RawKeyboard parameter togther with the debug version of avnc did not change much, at least it is still not working. But I can see a difference in regard to the transmitted keycodes: (does not differ if right-alt-to-super on or off):

KeyPress event, serial 28, synthetic NO, window 0x4c00001, root 0x3b4, subw 0x0, time 430664614, (593,383), root:(700,492), state 0x10, keycode 142 (keysym 0x1008ff6b, XF86Open), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False

KeyPress event, serial 28, synthetic NO, window 0x4c00001, root 0x3b4, subw 0x0, time 430664779, (593,383), root:(700,492), state 0x10, keycode 20 (keysym 0xdf, ssharp), same_screen YES, XLookupString gives 2 bytes: (c3 9f) "ß" XmbLookupString gives 2 bytes: (c3 9f) "ß" XFilterEvent returns: False

KeyRelease event, serial 28, synthetic NO, window 0x4c00001, root 0x3b4, subw 0x0, time 430664924, (593,383), root:(700,492), state 0x10, keycode 20 (keysym 0xdf, ssharp), same_screen YES, XLookupString gives 2 bytes: (c3 9f) "ß" XFilterEvent returns: False

KeyRelease event, serial 28, synthetic NO, window 0x4c00001, root 0x3b4, subw 0x0, time 430665150, (593,383), root:(700,492), state 0x10, keycode 142 (keysym 0x1008ff6b, XF86Open), same_screen YES, XLookupString gives 0 bytes: XFilterEvent returns: False

Overall with RawKeyboard it looks that there is a bigger missmatch between the Book Cover Keyboard layout and the xkb layout on the server: e.g. now I cannot use the curser keys and some other keys. Maybe the right combination of RawKeyboard and X server keyboard layout would solve the problem but I cannot imagine which keyboard layout I should choose. Currently I'm using /usr/bin/setxkbmap -layout de,us -model pc105 -variant nodeadkeys,altgr-intl And with that the right alt key (AltGr) isn't really assigned to right-alt as it seems.

EDIT: I just like to add: it does not depend on the Samsung Book Cover keyboard, using the exact same hardware keyboard from my desktop via bluetooth with avnc, avnc generates different keycodes then e.g. tigervncclient. The right-alt (AltGr) key ends up as keycode 108 with tigervncclient but is 142 with avnc using the same hardware keyboard.

gujjwal00 commented 1 year ago

Please try this APK (with RawKeyboard enabled): app-debug.zip

does not differ if right-alt-to-super on or off

Raw key events bypasses this setting.

Overall with RawKeyboard it looks that there is a bigger missmatch between the Book Cover Keyboard layout and the xkb layout on the server: e.g. now I cannot use the curser keys and some other keys.

EDIT: I just like to add: it does not depend on the Samsung Book Cover keyboard, using the exact same hardware keyboard from my desktop via bluetooth with avnc, avnc generates different keycodes then e.g. tigervncclient. The right-alt (AltGr) key ends up as keycode 108 with tigervncclient but is 142 with avnc using the same hardware keyboard.

Yeah, previous APK was not encoding raw key events correctly. I assumed scancodes received from Android were XT scancodes, but actually they are Linux kernel keycodes.

Q: Can you compile TigerVNC from source (or somehow use newer version)?

macdanger commented 1 year ago

Please try this APK (with RawKeyboard enabled): app-debug.zip

Now this new debug version works perfectly! Even the super and cursor keys work correctly! EDIT: and also with using a full blown logitech bluetooth hardware keyboard.

Q: Can you compile TigerVNC from source (or somehow use newer version)?

you mean update the server binary? I'm using the Debian standard package, which is currently on version:

Xvnc TigerVNC 1.11.0 - built 2022-01-26 17:59 Copyright (C) 1999-2020 TigerVNC Team and many others (see README.rst) See https://www.tigervnc.org for information on TigerVNC. Underlying X server release 12011000, The X.Org Foundation

gujjwal00 commented 1 year ago

you mean update the server binary?

Yes. I was testing TigerVNC 1.13 and it has improved key handling, even without raw key events.

I'm using the Debian standard package, which is currently on version:

That's why I was wondering if you could compile from source.

In any case, raw key events in AVNC still need a bit more polishing, and I will close this issue when it's ready.

gujjwal00 commented 1 year ago

v2.2.0 is now available with raw key event support. And thank you @macdanger!

macdanger commented 1 year ago

Hi, sorry to jump in here again, but it looks that the newer versions have a slightly different implementation of the raw keys. When using the 2.1.2 (debug) version from this thread, all is perfectly fine. When I use the news version, alt least the super keys don't work. Everything else seems to be the same. Shoult I open a new issue?

gujjwal00 commented 1 year ago

No problem, I will take a closer look later today.

Which specific version is not working correctly: v2.2.0 or v2.2.1

No need to open new issue, I will just reopen this one.

macdanger commented 1 year ago

2.2.1 seems not to work with super keys I did not try 2.2.0 though

gujjwal00 commented 1 year ago

After a bit of testing, it looks like Super should work correctly. My device intercepts Super key for Google app so I can't test it directly. But if map any other key to Super, it works as expected.

Please run the Key test in AVNC settings for Super keys, and paste event logs here.

macdanger commented 1 year ago

Oh man, sorry, it looks like you are right. now after cleaning up and comparing my config from the 2.1.2 (debug) with the 2.2.1 release - it just works as expected. Strange. Sorry, I hope I didn't cause too much trouble for you checking :-)

gujjwal00 commented 1 year ago

No problem, this sort of thing has happened more than once to me too when testing AVNC with different configurations.

I did find a test which was not running, so that's a net positive.