Archived
2
0

Merge branch 'kbd-modifier-state-sync' of github.com:m1k1o/neko into dev

This commit is contained in:
m1k1o 2020-06-21 03:13:10 +02:00
commit bfcc3efe12
6 changed files with 29 additions and 39 deletions

View File

@ -217,8 +217,8 @@ func (manager *RemoteManager) GetScreenSize() *types.ScreenSize {
return xorg.GetScreenSize() return xorg.GetScreenSize()
} }
func (manager *RemoteManager) SetKeyboard(layout string) { func (manager *RemoteManager) SetKeyboardLayout(layout string) {
xorg.SetKeyboard(layout) xorg.SetKeyboardLayout(layout)
} }
func (manager *RemoteManager) SetKeyboardModifiers(NumLock int, CapsLock int, ScrollLock int) { func (manager *RemoteManager) SetKeyboardModifiers(NumLock int, CapsLock int, ScrollLock int) {

View File

@ -22,6 +22,6 @@ type RemoteManager interface {
ReadClipboard() string ReadClipboard() string
WriteClipboard(data string) WriteClipboard(data string)
ResetKeys() ResetKeys()
SetKeyboard(layout string) SetKeyboardLayout(layout string)
SetKeyboardModifiers(NumLock int, CapsLock int, ScrollLock int) SetKeyboardModifiers(NumLock int, CapsLock int, ScrollLock int)
} }

View File

@ -125,15 +125,7 @@ func (h *MessageHandler) controlKeyboard(id string, session types.Session, paylo
// change layout // change layout
if payload.Layout != nil { if payload.Layout != nil {
h.remote.SetKeyboard(*payload.Layout) h.remote.SetKeyboardLayout(*payload.Layout)
}
// set caps lock
var CapsLock = 0
if payload.CapsLock == nil {
CapsLock = -1
} else if *payload.CapsLock {
CapsLock = 1
} }
// set num lock // set num lock
@ -144,6 +136,14 @@ func (h *MessageHandler) controlKeyboard(id string, session types.Session, paylo
NumLock = 1 NumLock = 1
} }
// set caps lock
var CapsLock = 0
if payload.CapsLock == nil {
CapsLock = -1
} else if *payload.CapsLock {
CapsLock = 1
}
// set scroll lock // set scroll lock
var ScrollLock = 0 var ScrollLock = 0
if payload.ScrollLock == nil { if payload.ScrollLock == nil {
@ -152,6 +152,6 @@ func (h *MessageHandler) controlKeyboard(id string, session types.Session, paylo
ScrollLock = 1 ScrollLock = 1
} }
h.remote.SetKeyboardModifiers(CapsLock, NumLock, ScrollLock) h.remote.SetKeyboardModifiers(NumLock, CapsLock, ScrollLock)
return nil return nil
} }

View File

@ -166,7 +166,7 @@ short XGetScreenRate() {
return XRRConfigCurrentRate(conf); return XRRConfigCurrentRate(conf);
} }
void SetKeyboard(char *layout) { void SetKeyboardLayout(char *layout) {
// TOOD: refactor, use native API. // TOOD: refactor, use native API.
char cmd[13] = "setxkbmap "; char cmd[13] = "setxkbmap ";
strncat(cmd, layout, 2); strncat(cmd, layout, 2);
@ -174,33 +174,22 @@ void SetKeyboard(char *layout) {
} }
void SetKeyboardModifiers(int num_lock, int caps_lock, int scroll_lock) { void SetKeyboardModifiers(int num_lock, int caps_lock, int scroll_lock) {
// TOOD: refactor, use native API.
// https://stackoverflow.com/questions/8427817/how-to-get-a-num-lock-state-using-c-c/8429021
Display *display = getXDisplay(); Display *display = getXDisplay();
XKeyboardState x;
XGetKeyboardControl(display, &x);
// set caps lock if (num_lock != -1) {
//printf("CapsLock is %s\n", (x.led_mask & 1) ? "On" : "Off"); XkbLockModifiers(display, XkbUseCoreKbd, 16, num_lock * 16);
if(caps_lock != -1 && x.led_mask & 1 != caps_lock) {
XKey(0xffe5, 1);
XKey(0xffe5, 0);
} }
// set num lock if (caps_lock != -1) {
//printf("NumLock is %s\n", (x.led_mask & 2) ? "On" : "Off"); XkbLockModifiers(display, XkbUseCoreKbd, 2, caps_lock * 2);
if(num_lock != -1 && x.led_mask & 2 != num_lock) {
XKey(0xff7f, 1);
XKey(0xff7f, 0);
} }
/* NOT SUPPORTED if (scroll_lock != -1) {
// set scroll lock XKeyboardControl values;
//printf("ScrollLock is %s\n", (x.led_mask & 4) ? "On" : "Off"); values.led_mode = scroll_lock ? LedModeOn : LedModeOff;
if(scroll_lock != -1 && x.led_mask & 4 != scroll_lock) { values.led = 3;
XKey(0xff14, 1); XChangeKeyboardControl(display, KBLedMode, &values);
XKey(0xff14, 0);
}
*/
} }
XFlush(display);
}

View File

@ -211,7 +211,7 @@ func GetScreenSize() *types.ScreenSize {
return nil return nil
} }
func SetKeyboard(layout string) { func SetKeyboardLayout(layout string) {
mu.Lock() mu.Lock()
defer mu.Unlock() defer mu.Unlock()
@ -222,7 +222,7 @@ func SetKeyboard(layout string) {
layoutUnsafe := C.CString(layout) layoutUnsafe := C.CString(layout)
defer C.free(unsafe.Pointer(layoutUnsafe)) defer C.free(unsafe.Pointer(layoutUnsafe))
C.SetKeyboard(layoutUnsafe) C.SetKeyboardLayout(layoutUnsafe)
} }
func SetKeyboardModifiers(num_lock int, caps_lock int, scroll_lock int) { func SetKeyboardModifiers(num_lock int, caps_lock int, scroll_lock int) {

View File

@ -4,6 +4,7 @@
#define XDISPLAY_H #define XDISPLAY_H
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/XKBlib.h>
#include <X11/extensions/Xrandr.h> #include <X11/extensions/Xrandr.h>
#include <X11/extensions/XTest.h> #include <X11/extensions/XTest.h>
#include <libclipboard.h> #include <libclipboard.h>
@ -39,7 +40,7 @@
void XDisplayClose(void); void XDisplayClose(void);
void XDisplaySet(char *input); void XDisplaySet(char *input);
void SetKeyboard(char *layout); void SetKeyboardLayout(char *layout);
void SetKeyboardModifiers(int num_lock, int caps_lock, int scroll_lock); void SetKeyboardModifiers(int num_lock, int caps_lock, int scroll_lock);
#endif #endif