neutrinolabs / xrdp

xrdp: an open source RDP server
http://www.xrdp.org/
Apache License 2.0
5.72k stars 1.73k forks source link

AltGr mapped incorrectly on Spanish keyboard #3292

Open gsabdiv opened 4 days ago

gsabdiv commented 4 days ago

xrdp version

0.10.1

Detailed xrdp version, build options

xrdp 0.10.1
  A Remote Desktop Protocol Server.
  Copyright (C) 2004-2024 Jay Sorg, Neutrino Labs, and all contributors.
  See https://github.com/neutrinolabs/xrdp for more information.

  Configure options:
      --build=x86_64-redhat-linux-gnu
      --host=x86_64-redhat-linux-gnu
      --program-prefix=
      --disable-dependency-tracking
      --prefix=/usr
      --exec-prefix=/usr
      --bindir=/usr/bin
      --sbindir=/usr/sbin
      --sysconfdir=/etc
      --datadir=/usr/share
      --includedir=/usr/include
      --libdir=/usr/lib64
      --libexecdir=/usr/libexec
      --localstatedir=/var
      --sharedstatedir=/var/lib
      --mandir=/usr/share/man
      --infodir=/usr/share/info
      --enable-fuse
      --enable-pixman
      --enable-painter
      --enable-vsock
      --enable-ipv6
      --with-socketdir=/run/xrdp
      --with-imlib2
      build_alias=x86_64-redhat-linux-gnu
      host_alias=x86_64-redhat-linux-gnu
      CFLAGS=-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection 
      LDFLAGS=-Wl,-z,relro  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld
      CXXFLAGS=-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
      PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig

  Compiled with OpenSSL 1.1.1k  FIPS 25 Mar 2021

Operating system & version

Red Hat Enterprise Linux 8.10 (Ootpa)

Installation method

dnf / apt / zypper / pkg / etc

Which backend do you use?

tigervnc-1.13.1-12.el8_10.x86_64

What desktop environment do you use?

xterm

Environment xrdp running on

physical

What's your client?

mstsc.exe on Windows 10

Area(s) with issue?

Keyboard / Mouse

Steps to reproduce

✔️ Expected Behavior

get a [ (when running xev see a ISO_Level3_Shift for AltGr)

❌ Actual Behavior

get nothing (when running xev see a Alt_R+Shift_L for AltGr, which does give you the "[" in some applications, but not all)

When attaching a Spanish keyboard to the Linuxmachine and running setxkbmap es, xrdp-genkeymap generates this, which is completely different to the file included in the release tarball. For some reason, the development version doesn't contain the 40a mapping. keymapspanish.txt

Anything else?

I saw #2217, but I don't think it's related, no VMs involved.

matt335672 commented 3 days ago

@gsabdiv - it's almost certainly the same issue as #2217. However, since I blundered my way through that one I've learned a lot more about how keyboard mappings work. I'm hopeful we can come up with a better solution for you.

I've got an old CentOS 8 VM I can use to look at this. I'm also lacking a Spanish keyboard, but I think I can work around that.

A couple of initial questions for you:- 1) I can't identify your keyboard on https://www.kbdlayout.info/. The Spanish keyboard listed appears to have a '{' for the Alt-GR on key you mention rather than the '['. Can you have a look at that site and tell me which keyboard you have? 2) What is the output of sudo grep keymap /var/log/xrdp.log?

Thanks.

gsabdiv commented 3 days ago

Sorry, I confused the keys. I don't have a Spanish one at my desk. You're right, { is in the row of the L key. (I think I got confused because xev did show [ and { being pressed) The xrdp.logs do have several lines of this: [INFO ] Loading keymap file /etc/xrdp/km-0000040a.ini [WARN ] local keymap file for 0x0000040a found and doesn't match built in keymap, using local keymap file They appeared before I created the new mapping.

matt335672 commented 2 days ago

I've had a look at this.

I've found an unrelated problem related to the Spanish keyboard, which is that the Left Alt key isn't being mapped correctly. We can come back to that.

The main problem we have is with the interface to TigerVNC, namely passing the AltGr key. You should be able to verify that on the login screen, this key is working as expected. The problem appears to be only when talking to the VNC server.

Historically, Windows VNC clients have not interfaced well with VNC servers. Microsoft decided to map the AltGr key to Ctrl + Alt. This has resulted in TigerVNC implementing all sorts of workarounds to cope with different clients sending different combinations which are supposed to represent AltGr:-

https://duckduckgo.com/?t=lm&q=tigervnc+altgr&atb=v320-1&ia=web

We seem to be falling foul of one of those workarounds. As far as I can tell, we're sending the correct KeySym 0xffea to TigerVNC, but it is being interpreted as ALT_L. I've tried disentangling this on the server side by changing the keymap, and hence changing the heuristic, but that's made quite a mess of the keyboard.

I'll raise a query with tigervnc and see if they can give me some ideas.

You can also try using the xorgxrdp package and the Xorg backend. That does not suffer from this problem.

matt335672 commented 2 days ago

I've just figured out a better fix for this - I've been getting confused between the right-hand ALT key (on some keyboards) and the AltGr key (on other keyboards).

@gsabdiv - Can you try installing this file as km-0000040a.ini?

km-0000040a.ini.txt

It's got changes in for the two Alt keys.