diff --git a/internal/desktop/xorg.go b/internal/desktop/xorg.go index 52494000..0172b69f 100644 --- a/internal/desktop/xorg.go +++ b/internal/desktop/xorg.go @@ -68,8 +68,10 @@ func (manager *DesktopManagerCtx) SetKeyboardModifiers(mod types.KeyboardModifie } func (manager *DesktopManagerCtx) GetKeyboardModifiers() types.KeyboardModifiers { - NumLock := xorg.GetKeyboardModifier(xorg.KBD_NUM_LOCK) - CapsLock := xorg.GetKeyboardModifier(xorg.KBD_CAPS_LOCK) + modifiers := xorg.GetKeyboardModifiers() + + NumLock := (modifiers & xorg.KBD_NUM_LOCK) != 0 + CapsLock := (modifiers & xorg.KBD_CAPS_LOCK) != 0 return types.KeyboardModifiers{ NumLock: &NumLock, diff --git a/internal/desktop/xorg/xorg.c b/internal/desktop/xorg/xorg.c index 498f455d..afbd4135 100644 --- a/internal/desktop/xorg/xorg.c +++ b/internal/desktop/xorg/xorg.c @@ -132,11 +132,11 @@ void XSetKeyboardModifier(int mod, int on) { XFlush(display); } -int XGetKeyboardModifier(int mod) { +char XGetKeyboardModifiers() { XkbStateRec xkbState; Display *display = getXDisplay(); XkbGetState(display, XkbUseCoreKbd, &xkbState); - return xkbState.locked_mods & mod; + return xkbState.locked_mods; } XFixesCursorImage *XGetCursorImage(void) { diff --git a/internal/desktop/xorg/xorg.go b/internal/desktop/xorg/xorg.go index d1489f1a..686e1afa 100644 --- a/internal/desktop/xorg/xorg.go +++ b/internal/desktop/xorg/xorg.go @@ -17,7 +17,7 @@ import ( "demodesk/neko/internal/types" ) -type KbdModifiers int +type KbdModifiers uint8 const ( KBD_CAPS_LOCK KbdModifiers = 2 @@ -230,11 +230,11 @@ func SetKeyboardModifier(mod KbdModifiers, active bool) { C.XSetKeyboardModifier(C.int(mod), num) } -func GetKeyboardModifier(mod KbdModifiers) bool { +func GetKeyboardModifiers() KbdModifiers { mu.Lock() defer mu.Unlock() - return C.XGetKeyboardModifier(C.int(mod)) == C.int(1) + return KbdModifiers(C.XGetKeyboardModifiers()) } func GetCursorImage() *types.CursorImage { diff --git a/internal/desktop/xorg/xorg.h b/internal/desktop/xorg/xorg.h index 6f4aeca1..0b1cf5c5 100644 --- a/internal/desktop/xorg/xorg.h +++ b/internal/desktop/xorg/xorg.h @@ -27,5 +27,5 @@ short XGetScreenRate(); void SetKeyboardLayout(char *layout); void XSetKeyboardModifier(int mod, int on); -int XGetKeyboardModifier(int mod); +char XGetKeyboardModifiers(); XFixesCursorImage *XGetCursorImage(void);