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()
}
func (manager *RemoteManager) SetKeyboard(layout string) {
xorg.SetKeyboard(layout)
func (manager *RemoteManager) SetKeyboardLayout(layout string) {
xorg.SetKeyboardLayout(layout)
}
func (manager *RemoteManager) SetKeyboardModifiers(NumLock int, CapsLock int, ScrollLock int) {

View File

@ -22,6 +22,6 @@ type RemoteManager interface {
ReadClipboard() string
WriteClipboard(data string)
ResetKeys()
SetKeyboard(layout string)
SetKeyboardLayout(layout string)
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
if payload.Layout != nil {
h.remote.SetKeyboard(*payload.Layout)
}
// set caps lock
var CapsLock = 0
if payload.CapsLock == nil {
CapsLock = -1
} else if *payload.CapsLock {
CapsLock = 1
h.remote.SetKeyboardLayout(*payload.Layout)
}
// set num lock
@ -144,6 +136,14 @@ func (h *MessageHandler) controlKeyboard(id string, session types.Session, paylo
NumLock = 1
}
// set caps lock
var CapsLock = 0
if payload.CapsLock == nil {
CapsLock = -1
} else if *payload.CapsLock {
CapsLock = 1
}
// set scroll lock
var ScrollLock = 0
if payload.ScrollLock == nil {
@ -152,6 +152,6 @@ func (h *MessageHandler) controlKeyboard(id string, session types.Session, paylo
ScrollLock = 1
}
h.remote.SetKeyboardModifiers(CapsLock, NumLock, ScrollLock)
h.remote.SetKeyboardModifiers(NumLock, CapsLock, ScrollLock)
return nil
}

View File

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

View File

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

View File

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