kernc/logkeys

Can't get Capslock state on wayland

Opened this issue · 5 comments

This statement is only applicable to OS using xorg, and cannot get the value of capslock correctly in Wayland
key_state.capslock_in_effect = execute(COMMAND_STR_CAPSLOCK_STATE).size() >= 2;
I'm curious how to get the capslock value in Wayland

kernc commented

Does setleds work, as pointed out in this SO thread?

kernc commented

We already use setleds in case xset fails:

#define COMMAND_STR_CAPSLOCK_STATE ("{ { xset q 2>/dev/null | grep -q -E 'Caps Lock: +on'; } || { setleds 2>/dev/null | grep -q 'CapsLock on'; }; } && echo on")

Do you have it installed (part of kbd package).

#define COMMAND_STR_CAPSLOCK_STATE ("{ { xset q 2>/dev/null | grep -q -E 'Caps Lock: +on'; } || { setleds 2>/dev/null | grep -q 'CapsLock on'; }; } && echo on") It can get correct result on Xorg but the result is always 0 when it work on wayland.
I have tried setleds -D +caps command ,it can work at both Xorg and wayland , but it only works well on VT(i mean Ctrl+Alt+F2orF3 that window), it don't work on GUI.
I also tried using ioctl(fd,KBGETLED,&res);,but it always get 0.
Is it because of my virtual machine problem?
My OS is ubuntu16.04 using Xorg and ubuntu21.04 usging wayland.

I tried ioctl(fd,KDETLED,0x04) and it works well on GUI
However, regardless of the value of capslock, the return value of kdgetled is always 0. However, after kdset led, 0x04, no matter how you press the capslock key, the value of kdgetled will become 0x04 instead the true value of capslock state
It seems that the value of kdgetled is only 0 or the value modified by kdsetled, regardless of the state of the key itself
Any ideas?