We now take into account keypad keys

However, num lock is not accounted for. This still needs to be
implemented.
This commit is contained in:
Sasha Koshka 2022-11-24 18:20:47 -05:00
parent 5a76bd0c22
commit 33ed2af075
3 changed files with 74 additions and 24 deletions

View File

@ -111,7 +111,7 @@ func (backend *Backend) handleKeyPress (
event xevent.KeyPressEvent,
) {
keyEvent := *event.KeyPressEvent
button := backend.keycodeToButton(keyEvent.Detail, keyEvent.State)
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,
})
}
@ -128,7 +129,7 @@ func (backend *Backend) handleKeyRelease (
event xevent.KeyReleaseEvent,
) {
keyEvent := *event.KeyReleaseEvent
button := backend.keycodeToButton(keyEvent.Detail, keyEvent.State)
button, _ := backend.keycodeToButton(keyEvent.Detail, keyEvent.State)
backend.callbackManager.RunRelease(button)
}

View File

@ -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,
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 {
// look up in keypad table
button, numberPad = keypadCodeTable[selectedKeysym]
if numberPad { return }
// otherwise, use the rune
button = stone.Button(selectedRune)
}
return
}

View File

@ -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
}