logkeys icon indicating copy to clipboard operation
logkeys copied to clipboard

Can't get Capslock state on wayland

Open Yatogaii opened this issue 3 years ago • 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

Yatogaii avatar Jul 14 '21 09:07 Yatogaii

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

kernc avatar Jul 14 '21 14:07 kernc

We already use setleds in case xset fails: https://github.com/kernc/logkeys/blob/2539ccb89e20a3fbdeaa186f62e54719602a7143/src/logkeys.cc#L52 Do you have it installed (part of kbd package).

kernc avatar Jul 14 '21 14:07 kernc

Reading /sys/class/leds/inputX::capslock/brightness is another option ...

kernc avatar Jul 14 '21 14:07 kernc

#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.

Yatogaii avatar Jul 15 '21 01:07 Yatogaii

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?

Yatogaii avatar Jul 15 '21 01:07 Yatogaii