From 33ed2af0752a6740f462c262686d2072529bd0c8 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Thu, 24 Nov 2022 18:20:47 -0500 Subject: [PATCH] We now take into account keypad keys However, num lock is not accounted for. This still needs to be implemented. --- backends/x/event.go | 9 +++---- backends/x/unicode.go | 55 ++++++++++++++++++++++++++++++++++++++----- input.go | 34 +++++++++++++++----------- 3 files changed, 74 insertions(+), 24 deletions(-) diff --git a/backends/x/event.go b/backends/x/event.go index b2b55a4..442eff1 100644 --- a/backends/x/event.go +++ b/backends/x/event.go @@ -110,8 +110,8 @@ func (backend *Backend) handleKeyPress ( connection *xgbutil.XUtil, event xevent.KeyPressEvent, ) { - keyEvent := *event.KeyPressEvent - button := backend.keycodeToButton(keyEvent.Detail, keyEvent.State) + keyEvent := *event.KeyPressEvent + button, num := backend.keycodeToButton(keyEvent.Detail, keyEvent.State) backend.callbackManager.RunPress (button, stone.Modifiers { // FIXME these may not be correct in all cases Shift: (keyEvent.State & xproto.ModMaskShift) > 0, @@ -120,6 +120,7 @@ func (backend *Backend) handleKeyPress ( // Meta: (keyEvent.State & xproto.??) > 0, Super: (keyEvent.State & xproto.ModMask4) > 0, // Hyper: (keyEvent.State & xproto.??) > 0, + NumberPad: num, }) } @@ -127,8 +128,8 @@ func (backend *Backend) handleKeyRelease ( connection *xgbutil.XUtil, event xevent.KeyReleaseEvent, ) { - keyEvent := *event.KeyReleaseEvent - button := backend.keycodeToButton(keyEvent.Detail, keyEvent.State) + keyEvent := *event.KeyReleaseEvent + button, _ := backend.keycodeToButton(keyEvent.Detail, keyEvent.State) backend.callbackManager.RunRelease(button) } diff --git a/backends/x/unicode.go b/backends/x/unicode.go index 8f88a6f..ec917d3 100644 --- a/backends/x/unicode.go +++ b/backends/x/unicode.go @@ -71,11 +71,51 @@ var buttonCodeTable = map[xproto.Keysym] stone.Button { 0xFF20: stone.KeyDead, } +var keypadCodeTable = map[xproto.Keysym] stone.Button { + 0xff80: stone.Button(' '), + 0xff89: stone.KeyTab, + 0xff8d: stone.KeyEnter, + 0xff91: stone.KeyF1, + 0xff92: stone.KeyF2, + 0xff93: stone.KeyF3, + 0xff94: stone.KeyF4, + 0xff95: stone.KeyHome, + 0xff96: stone.KeyLeft, + 0xff97: stone.KeyUp, + 0xff98: stone.KeyRight, + 0xff99: stone.KeyDown, + 0xff9a: stone.KeyPageUp, + 0xff9b: stone.KeyPageDown, + 0xff9c: stone.KeyEnd, + 0xff9d: stone.KeyHome, + 0xff9e: stone.KeyInsert, + 0xff9f: stone.KeyDelete, + 0xffbd: stone.Button('='), + 0xffaa: stone.Button('*'), + 0xffab: stone.Button('+'), + 0xffac: stone.Button(','), + 0xffad: stone.Button('-'), + 0xffae: stone.Button('.'), + 0xffaf: stone.Button('/'), + + 0xffb0: stone.Button('0'), + 0xffb1: stone.Button('1'), + 0xffb2: stone.Button('2'), + 0xffb3: stone.Button('3'), + 0xffb4: stone.Button('4'), + 0xffb5: stone.Button('5'), + 0xffb6: stone.Button('6'), + 0xffb7: stone.Button('7'), + 0xffb8: stone.Button('8'), + 0xffb9: stone.Button('9'), +} + func (backend *Backend) keycodeToButton ( keycode xproto.Keycode, state uint16, ) ( - button stone.Button, + button stone.Button, + numberPad bool, ) { // FIXME: also set shift to true if the lock modifier is on and the lock // modifier is interpreted as shiftLock @@ -168,14 +208,17 @@ func (backend *Backend) keycodeToButton ( selectedRune = symbol2Rune } - // look up in table + // look up in control code table var isControl bool button, isControl = buttonCodeTable[selectedKeysym] + if isControl { return } - // if it wasn't found, - if !isControl { - button = stone.Button(selectedRune) - } + // look up in keypad table + button, numberPad = keypadCodeTable[selectedKeysym] + if numberPad { return } + + // otherwise, use the rune + button = stone.Button(selectedRune) return } diff --git a/input.go b/input.go index 026a5d1..9b7189a 100644 --- a/input.go +++ b/input.go @@ -44,20 +44,20 @@ const ( KeyDelete Button = 127 - MouseButton1 Button = 128 - MouseButton2 Button = 129 - MouseButton3 Button = 130 - MouseButton4 Button = 131 - MouseButton5 Button = 132 - MouseButton6 Button = 133 - MouseButton7 Button = 134 - MouseButton8 Button = 135 - MouseButton9 Button = 136 - MouseButtonLeft Button = MouseButton1 - MouseButtonMiddle Button = MouseButton2 - MouseButtonRight Button = MouseButton3 - MouseButtonBack Button = MouseButton8 - MouseButtonForward Button = MouseButton9 + MouseButton1 Button = 128 + MouseButton2 Button = 129 + MouseButton3 Button = 130 + MouseButton4 Button = 131 + MouseButton5 Button = 132 + MouseButton6 Button = 133 + MouseButton7 Button = 134 + MouseButton8 Button = 135 + MouseButton9 Button = 136 + MouseButtonLeft Button = MouseButton1 + MouseButtonMiddle Button = MouseButton2 + MouseButtonRight Button = MouseButton3 + MouseButtonBack Button = MouseButton8 + MouseButtonForward Button = MouseButton9 KeyF1 Button = 144 KeyF2 Button = 145 @@ -94,4 +94,10 @@ type Modifiers struct { Meta bool Super bool Hyper bool + + // NumberPad does not represent a key, but it behaves like one. If it is + // set to true, the button was pressed on the number pad. It is treated + // as a modifier key because if you don't care whether a key was pressed + // on the number pad or not, you can just ignore this value. + NumberPad bool }