xorg modifiers fix mask.

This commit is contained in:
Miroslav Šedivý 2021-01-12 23:35:11 +01:00
parent a0d8f1b880
commit 8a9dceafec
4 changed files with 10 additions and 8 deletions

View File

@ -68,8 +68,10 @@ func (manager *DesktopManagerCtx) SetKeyboardModifiers(mod types.KeyboardModifie
} }
func (manager *DesktopManagerCtx) GetKeyboardModifiers() types.KeyboardModifiers { func (manager *DesktopManagerCtx) GetKeyboardModifiers() types.KeyboardModifiers {
NumLock := xorg.GetKeyboardModifier(xorg.KBD_NUM_LOCK) modifiers := xorg.GetKeyboardModifiers()
CapsLock := xorg.GetKeyboardModifier(xorg.KBD_CAPS_LOCK)
NumLock := (modifiers & xorg.KBD_NUM_LOCK) != 0
CapsLock := (modifiers & xorg.KBD_CAPS_LOCK) != 0
return types.KeyboardModifiers{ return types.KeyboardModifiers{
NumLock: &NumLock, NumLock: &NumLock,

View File

@ -132,11 +132,11 @@ void XSetKeyboardModifier(int mod, int on) {
XFlush(display); XFlush(display);
} }
int XGetKeyboardModifier(int mod) { char XGetKeyboardModifiers() {
XkbStateRec xkbState; XkbStateRec xkbState;
Display *display = getXDisplay(); Display *display = getXDisplay();
XkbGetState(display, XkbUseCoreKbd, &xkbState); XkbGetState(display, XkbUseCoreKbd, &xkbState);
return xkbState.locked_mods & mod; return xkbState.locked_mods;
} }
XFixesCursorImage *XGetCursorImage(void) { XFixesCursorImage *XGetCursorImage(void) {

View File

@ -17,7 +17,7 @@ import (
"demodesk/neko/internal/types" "demodesk/neko/internal/types"
) )
type KbdModifiers int type KbdModifiers uint8
const ( const (
KBD_CAPS_LOCK KbdModifiers = 2 KBD_CAPS_LOCK KbdModifiers = 2
@ -230,11 +230,11 @@ func SetKeyboardModifier(mod KbdModifiers, active bool) {
C.XSetKeyboardModifier(C.int(mod), num) C.XSetKeyboardModifier(C.int(mod), num)
} }
func GetKeyboardModifier(mod KbdModifiers) bool { func GetKeyboardModifiers() KbdModifiers {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
return C.XGetKeyboardModifier(C.int(mod)) == C.int(1) return KbdModifiers(C.XGetKeyboardModifiers())
} }
func GetCursorImage() *types.CursorImage { func GetCursorImage() *types.CursorImage {

View File

@ -27,5 +27,5 @@ short XGetScreenRate();
void SetKeyboardLayout(char *layout); void SetKeyboardLayout(char *layout);
void XSetKeyboardModifier(int mod, int on); void XSetKeyboardModifier(int mod, int on);
int XGetKeyboardModifier(int mod); char XGetKeyboardModifiers();
XFixesCursorImage *XGetCursorImage(void); XFixesCursorImage *XGetCursorImage(void);