Archived
2
0

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

This commit is contained in:
m1k1o 2020-06-20 02:16:11 +02:00
commit 3826541804
6 changed files with 68 additions and 21 deletions

View File

@ -32,6 +32,12 @@ func New(config *config.Remote) *RemoteManager {
emmiter: events.New(), emmiter: events.New(),
config: config, config: config,
streaming: false, streaming: false,
keyboardModifierState: {
CapsLock: false,
NumLock: false,
ScrollLock: false,
}
} }
} }
@ -219,4 +225,8 @@ func (manager *RemoteManager) GetScreenSize() *types.ScreenSize {
func (manager *RemoteManager) SetKeyboard(layout string) { func (manager *RemoteManager) SetKeyboard(layout string) {
xorg.SetKeyboard(layout) xorg.SetKeyboard(layout)
} }
func (manager *RemoteManager) SetKeyboard(NumLock int, CapsLock int, ScrollLock int) {
xorg.SetKeyboardModifiers(NumLock, CapsLock, ScrollLock)
}

View File

@ -23,4 +23,5 @@ type RemoteManager interface {
WriteClipboard(data string) WriteClipboard(data string)
ResetKeys() ResetKeys()
SetKeyboard(layout string) SetKeyboard(layout string)
SetKeyboard(NumLock int, CapsLock int, ScrollLock int)
} }

View File

@ -116,11 +116,6 @@ func (h *MessageHandler) controlClipboard(id string, session types.Session, payl
return nil return nil
} }
// TODO: Refactor
var CapsLock = false
var NumLock = false
var ScrollLock = false
func (h *MessageHandler) controlKeyboard(id string, session types.Session, payload *message.Keyboard) error { func (h *MessageHandler) controlKeyboard(id string, session types.Session, payload *message.Keyboard) error {
// check if session is host // check if session is host
if !h.sessions.IsHost(id) { if !h.sessions.IsHost(id) {
@ -134,28 +129,29 @@ func (h *MessageHandler) controlKeyboard(id string, session types.Session, paylo
} }
// set caps lock // set caps lock
if payload.CapsLock != nil && *payload.CapsLock != CapsLock { var CapsLock = 0
h.remote.KeyDown(0xffe5) if payload.CapsLock == nil {
h.remote.KeyUp(0xffe5) CapsLock = -1
} else if *payload.CapsLock {
CapsLock = *payload.CapsLock CapsLock = 1
} }
// set num lock // set num lock
if payload.NumLock != nil && *payload.NumLock != NumLock { var NumLock = 0
h.remote.KeyDown(0xff7f) if payload.NumLock == nil {
h.remote.KeyUp(0xff7f) NumLock = -1
} else if *payload.NumLock {
NumLock = *payload.NumLock NumLock = 1
} }
// set scroll lock // set scroll lock
if payload.ScrollLock != nil && *payload.ScrollLock != ScrollLock { var ScrollLock = 0
h.remote.KeyDown(0xff14) if payload.ScrollLock == nil {
h.remote.KeyUp(0xff14) ScrollLock = -1
} else if *payload.ScrollLock {
ScrollLock = *payload.ScrollLock ScrollLock = 1
} }
h.remote.SetKeyboardModifiers(CapsLock, NumLock, ScrollLock)
return nil return nil
} }

View File

@ -172,3 +172,35 @@ void SetKeyboard(char *layout) {
strncat(cmd, layout, 2); strncat(cmd, layout, 2);
system(cmd); system(cmd);
} }
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);
}
// 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);
}
/* 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);
}
*/
}

View File

@ -225,6 +225,13 @@ func SetKeyboard(layout string) {
C.SetKeyboard(layoutUnsafe) C.SetKeyboard(layoutUnsafe)
} }
func SetKeyboardModifiers(num_lock int, caps_lock int, scroll_lock int) {
mu.Lock()
defer mu.Unlock()
C.SetKeyboardModifiers(C.int(num_lock), C.int(caps_lock), C.int(scroll_lock))
}
//export goCreateScreenSize //export goCreateScreenSize
func goCreateScreenSize(index C.int, width C.int, height C.int, mwidth C.int, mheight C.int) { func goCreateScreenSize(index C.int, width C.int, height C.int, mwidth C.int, mheight C.int) {
ScreenConfigurations[int(index)] = types.ScreenConfiguration{ ScreenConfigurations[int(index)] = types.ScreenConfiguration{

View File

@ -40,5 +40,6 @@
void XDisplaySet(char *input); void XDisplaySet(char *input);
void SetKeyboard(char *layout); void SetKeyboard(char *layout);
void SetKeyboardModifiers(int num_lock, int caps_lock, int scroll_lock);
#endif #endif