Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
abma opened this issue May 11, 2023 · 9 comments
Open

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

abma opened this issue May 11, 2023 · 9 comments

Comments

@abma
Copy link

abma commented May 11, 2023

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: FreeRDP/FreeRDP#8946

@matt335672
Copy link
Member

matt335672 commented May 11, 2023

Hi @abma

More details please:-

  • What client are you using on debian 12?
  • What is your keyboard layout?
  • Which xrdp backend are you using? Xorg or Xvnc? If the former, what is the version of xorgxrdp?

@abma
Copy link
Author

abma commented May 12, 2023

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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 matt335672 transferred this issue from neutrinolabs/xrdp May 15, 2023
@matt335672
Copy link
Member

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

KbdSync(rdpKeyboard *keyboard, int param1)
{
int xkb_state;
xkb_state = XkbStateFieldFromRec(&(keyboard->device->key->xkbInfo->state));
if ((!(xkb_state & 0x02)) != (!(param1 & 4))) /* caps lock */
{
LLOGLN(0, ("KbdSync: toggling caps lock"));
KbdAddEvent(keyboard, 1, 58, 0, 58, 0);
KbdAddEvent(keyboard, 0, 58, 49152, 58, 49152);
}
if ((!(xkb_state & 0x10)) != (!(param1 & 2))) /* num lock */
{
LLOGLN(0, ("KbdSync: toggling num lock"));
KbdAddEvent(keyboard, 1, 69, 0, 69, 0);
KbdAddEvent(keyboard, 0, 69, 49152, 69, 49152);
}
if ((!(keyboard->scroll_lock_down)) != (!(param1 & 1))) /* scroll lock */
{
LLOGLN(0, ("KbdSync: toggling scroll lock"));
KbdAddEvent(keyboard, 1, 70, 0, 70, 0);
KbdAddEvent(keyboard, 0, 70, 49152, 70, 49152);
}
}

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.

@matt335672 matt335672 changed the title caps lock sometimes gets out of sync / works inverted xfreerdp: caps lock sometimes gets out of sync / works inverted May 15, 2023
@zeusin
Copy link

zeusin commented Jul 4, 2023

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

@zeusin
Copy link

zeusin commented Jul 18, 2023

@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
Copy link

tsz8899 commented Jun 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants