From 9a6ca9b5b01eb2ad1f1c98d691d5bbb31c8b4469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Mon, 15 Jun 2020 18:57:28 +0200 Subject: [PATCH] send keysyms in uint64 --- client/src/neko/base.ts | 12 +++---- server/internal/remote/manager.go | 4 +-- server/internal/types/remote.go | 4 +-- server/internal/webrtc/handle.go | 10 +++--- server/internal/xorg/xorg.go | 53 +++++++++++++++++-------------- 5 files changed, 44 insertions(+), 39 deletions(-) diff --git a/client/src/neko/base.ts b/client/src/neko/base.ts index 26fc4f24..d8a40b3f 100644 --- a/client/src/neko/base.ts +++ b/client/src/neko/base.ts @@ -123,19 +123,19 @@ export abstract class BaseClient extends EventEmitter { break case 'keydown': case 'mousedown': - buffer = new ArrayBuffer(5) + buffer = new ArrayBuffer(11) payload = new DataView(buffer) payload.setUint8(0, OPCODE.KEY_DOWN) - payload.setUint16(1, 1, true) - payload.setUint16(3, data.key, true) + payload.setUint16(1, 8, true) + payload.setBigUint64(3, BigInt(data.key), true) break case 'keyup': case 'mouseup': - buffer = new ArrayBuffer(5) + buffer = new ArrayBuffer(11) payload = new DataView(buffer) payload.setUint8(0, OPCODE.KEY_UP) - payload.setUint16(1, 1, true) - payload.setUint16(3, data.key, true) + payload.setUint16(1, 8, true) + payload.setBigUint64(3, BigInt(data.key), true) break default: this.emit('warn', `unknown data event: ${event}`) diff --git a/server/internal/remote/manager.go b/server/internal/remote/manager.go index b9be8982..9a4a4e27 100644 --- a/server/internal/remote/manager.go +++ b/server/internal/remote/manager.go @@ -187,7 +187,7 @@ func (manager *RemoteManager) ButtonDown(code int) error { return xorg.ButtonDown(code) } -func (manager *RemoteManager) KeyDown(code int) error { +func (manager *RemoteManager) KeyDown(code uint64) error { return xorg.KeyDown(code) } @@ -195,7 +195,7 @@ func (manager *RemoteManager) ButtonUp(code int) error { return xorg.ButtonUp(code) } -func (manager *RemoteManager) KeyUp(code int) error { +func (manager *RemoteManager) KeyUp(code uint64) error { return xorg.KeyUp(code) } diff --git a/server/internal/types/remote.go b/server/internal/types/remote.go index 2814d04f..3bdf7fd1 100644 --- a/server/internal/types/remote.go +++ b/server/internal/types/remote.go @@ -16,9 +16,9 @@ type RemoteManager interface { Move(x, y int) Scroll(x, y int) ButtonDown(code int) error - KeyDown(code int) error + KeyDown(code uint64) error ButtonUp(code int) error - KeyUp(code int) error + KeyUp(code uint64) error ReadClipboard() string WriteClipboard(data string) ResetKeys() diff --git a/server/internal/webrtc/handle.go b/server/internal/webrtc/handle.go index a84b5bc9..35c4b235 100644 --- a/server/internal/webrtc/handle.go +++ b/server/internal/webrtc/handle.go @@ -33,7 +33,7 @@ type PayloadScroll struct { type PayloadKey struct { PayloadHeader - Key uint16 + Key uint64 } func (manager *WebRTCManager) handle(id string, msg webrtc.DataChannelMessage) error { @@ -87,13 +87,13 @@ func (manager *WebRTCManager) handle(id string, msg webrtc.DataChannelMessage) e if payload.Key < 8 { err := manager.remote.ButtonDown(int(payload.Key)) if err != nil { - manager.logger.Warn().Err(err).Msg("key down failed") + manager.logger.Warn().Err(err).Msg("button down failed") return nil } manager.logger.Debug().Msgf("button down %d", payload.Key) } else { - err := manager.remote.KeyDown(int(payload.Key)) + err := manager.remote.KeyDown(uint64(payload.Key)) if err != nil { manager.logger.Warn().Err(err).Msg("key down failed") return nil @@ -119,9 +119,9 @@ func (manager *WebRTCManager) handle(id string, msg webrtc.DataChannelMessage) e manager.logger.Debug().Msgf("button up %d", payload.Key) } else { - err := manager.remote.KeyUp(int(payload.Key)) + err := manager.remote.KeyUp(uint64(payload.Key)) if err != nil { - manager.logger.Warn().Err(err).Msg("keyup failed") + manager.logger.Warn().Err(err).Msg("key up failed") return nil } diff --git a/server/internal/xorg/xorg.go b/server/internal/xorg/xorg.go index 072c43a8..852a1551 100644 --- a/server/internal/xorg/xorg.go +++ b/server/internal/xorg/xorg.go @@ -19,7 +19,8 @@ import ( var ScreenConfigurations = make(map[int]types.ScreenConfiguration) -var debounce = make(map[int]time.Time) +var debounce_button = make(map[int]time.Time) +var debounce_key = make(map[uint64]time.Time) var mu = sync.Mutex{} func init() { @@ -54,25 +55,25 @@ func ButtonDown(code int) error { mu.Lock() defer mu.Unlock() - if _, ok := debounce[code]; ok { + if _, ok := debounce_button[code]; ok { return fmt.Errorf("debounced button %v", code) } - debounce[code] = time.Now() + debounce_button[code] = time.Now() C.XButton(C.uint(code), C.int(1)) return nil } -func KeyDown(code int) error { +func KeyDown(code uint64) error { mu.Lock() defer mu.Unlock() - if _, ok := debounce[code]; ok { + if _, ok := debounce_key[code]; ok { return fmt.Errorf("debounced key %v", code) } - debounce[code] = time.Now() + debounce_key[code] = time.Now() C.XKey(C.ulong(code), C.int(1)) return nil @@ -82,25 +83,25 @@ func ButtonUp(code int) error { mu.Lock() defer mu.Unlock() - if _, ok := debounce[code]; !ok { + if _, ok := debounce_button[code]; !ok { return fmt.Errorf("debounced button %v", code) } - delete(debounce, code) + delete(debounce_button, code) C.XButton(C.uint(code), C.int(0)) return nil } -func KeyUp(code int) error { +func KeyUp(code uint64) error { mu.Lock() defer mu.Unlock() - if _, ok := debounce[code]; !ok { + if _, ok := debounce_key[code]; !ok { return fmt.Errorf("debounced key %v", code) } - delete(debounce, code) + delete(debounce_key, code) C.XKey(C.ulong(code), C.int(0)) return nil @@ -127,31 +128,35 @@ func WriteClipboard(data string) { } func ResetKeys() { - for code := range debounce { - if code < 8 { - ButtonUp(code) - } else { - KeyUp(code) - } + for code := range debounce_button { + ButtonUp(code) - delete(debounce, code) + delete(debounce_button, code) + } + for code := range debounce_key { + KeyUp(code) + + delete(debounce_key, code) } } func CheckKeys(duration time.Duration) { t := time.Now() - for code, start := range debounce { + for code, start := range debounce_button { if t.Sub(start) < duration { continue } + ButtonUp(code) - if code < 8 { - ButtonUp(code) - } else { - KeyUp(code) + delete(debounce_button, code) + } + for code, start := range debounce_key { + if t.Sub(start) < duration { + continue } + KeyUp(code) - delete(debounce, code) + delete(debounce_key, code) } }