neutrinolabs / xorgxrdp

Xorg drivers for xrdp
Other
428 stars 108 forks source link

xfreerdp: caps lock sometimes gets out of sync / works inverted #259

Open abma opened 1 year ago

abma commented 1 year ago

sometimes when i press caps lock, the state on the server doesn't change: i.e. the led indicator shows on but when i type all letters are upcase and vice versa.

To Reproduce press caps lock.

Expected behavior led indicator matches rdp state.

Additional context to test i've used: watch -n 0.1 "xset q"

server + client is debian 12.

xrdp is v0.9.21.1-1

i reported the same to freerdp: https://github.com/FreeRDP/FreeRDP/issues/8946

matt335672 commented 1 year ago

Hi @abma

More details please:-

abma commented 1 year ago

What client are you using on debian 12?

xfreerdp

What is your keyboard layout?

on client: de / pc105, on server: de / pc105,

Which xrdp backend are you using? Xorg or Xvnc? If the former, what is the version of xorgxrdp?

xorg with xorgxrdp v0.9.19-1

i've noticed in ~/.xorgxrdp..log that the the line

[746023.837] KbdSync: toggling caps lock

only sometimes occours when i press caps lock. i don't get this line with working remmina / mstsc as client to the xrdp server. it seems the problem and this log line seems to match: as long as this log message doesn't occour keyboard led + caps lock state on server side are in sync. when this message occours its out of sync.

also i would expect that this line should occour every time i press caps lock, right?! but it only occours maybe in one of 10 presses.

matt335672 commented 1 year ago

Thanks - that's useful.

The message is generated when the client sends this RDP event (or its fastpath variant):-

https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/6c5d0ef9-4653-4d69-9ba9-09ba3acd660f

It's a sync event, so isn't sent every time caps lock is pressed.

matt335672 commented 1 year ago

I've also read the comments on the freerdp issue.

If it's at all possible to come up with a way to reproduce this it will be a lot easier to look at.

matt335672 commented 1 year ago

I can reproduce this on devel now, with a UK keyboard.

I ran a simple session with just an xterm in it running watch -n 0.1 "xset q" as suggested in the linked issue (nice suggestion @abma)

Connecting with xfreerdp 2.9.0 resulted in the caps lock state not always changing when the key was pressed.

It looks like xfreerdp is sending a capslock down, capslock up, and also a sync request very close to each other. Remmina does not send the sync requests like this.

Problem does not occur at all with Xvnc, so I'm moving this to the xorgxrdp repo.

matt335672 commented 1 year ago

My guess is that things are going wrong in KbdSync:-

https://github.com/neutrinolabs/xorgxrdp/blob/5f6177df83bb7ebe79635c21f5378fcdf43f4417/xrdpkeyb/rdpKeyboard.c#L484-L510

Because the sync is sent so closely after the keypresses, it's possible the call to XkbStateFieldFromRec is getting stale information. This is a complete guess however - I don't know enough about X server internals to be sure about this.

zeusin commented 1 year ago

Experience same problem with xorgxrdp ... It also happens with num lock

zeusin commented 11 months ago

@abma Have you tried rdesktop to see if the problem persist?

There is also this option in rdesktop -N Enable numlock syncronization between the Xserver and the remote RDP session. This is useful with applications that looks at the numlock state, but might cause problems with some Xservers like Xvnc

tsz8899 commented 1 month ago

one type issue where the caps num lock sometimes gets out of sync.

The freerdp client, when connecting to XRDP, switching the client operating system window focus, clicking caps num key, will perform sync.

if initial state, when the server system starts up, the Xorg process for each user is not started.

When the freerdp client first connects to XRDP, it triggers the startup of the respective user's Xorg in the server system, which takes a few seconds to fully start Xorg. However, at this point, the freerdp client has already sent the caps and num lock sync. Since Xorg is not yet ready, it cannot respond to the client lock status conveyed by xrdp+xorgxrdp. When Xorg is fully ready, it will use the server's default caps and num lock settings, causing inconsistency on both ends.

Such as:

  1. Confirm that the xorg for the server user is not started by default.
  2. Activate the caps lock key as uppercase on the client computer.
  3. Connect using freerdp.
  4. A few seconds later, the session window will open, and at this point, the caps lock key inside the session will be lowercase.
  5. Do not log out of the session, just close the connection window directly.
  6. Reconnect to the session; since Xorg is not logged out and is already ready, the caps lock key inside the session will be sync with the client computer's normal state.

Investigate further to find a method to trigger caps num sync again after the session stabilizes, or to perform sync periodically.