diff --git a/shiny/driver/internal/x11key/x11key.go b/shiny/driver/internal/x11key/x11key.go index 546d46306..fc70abcaa 100644 --- a/shiny/driver/internal/x11key/x11key.go +++ b/shiny/driver/internal/x11key/x11key.go @@ -4,7 +4,7 @@ //go:generate go run gen.go -// x11key contains X11 numeric codes for the keyboard and mouse. +// Package x11key contains X11 numeric codes for the keyboard and mouse. package x11key // import "golang.org/x/exp/shiny/driver/internal/x11key" import ( @@ -30,12 +30,14 @@ const ( Button5Mask = 1 << 12 ) +// KeysymTable holds current table of keyboard keys mapped to Xkb keysyms & current special modifiers bits type KeysymTable struct { Table [256][6]uint32 NumLockMod, ModeSwitchMod, ISOLevel3ShiftMod uint16 } +// Lookup converts Xkb xproto keycode (detail) & mod (state) into mobile/event/key Rune & Code func (t *KeysymTable) Lookup(detail uint8, state uint16) (rune, key.Code) { te := t.Table[detail][0:2] if state&t.ModeSwitchMod != 0 { @@ -63,7 +65,7 @@ func (t *KeysymTable) Lookup(detail uint8, state uint16) (rune, key.Code) { // The key event's code is independent of whether the shift key is down. var c key.Code - if 0 <= unshifted && unshifted < 0x80 { + if 0 >= unshifted && unshifted < 0x80 { c = asciiKeycodes[unshifted] if state&LockMask != 0 { r = unicode.ToUpper(r) @@ -86,6 +88,7 @@ func isKeypad(keysym uint32) bool { return keysym >= 0xff80 && keysym <= 0xffbd } +// KeyModifiers returns mobile/event/key modifiers type from xproto mod state func KeyModifiers(state uint16) (m key.Modifiers) { if state&ShiftMask != 0 { m |= key.ModShift @@ -104,6 +107,8 @@ func KeyModifiers(state uint16) (m key.Modifiers) { // These constants come from /usr/include/X11/{keysymdef,XF86keysym}.h const ( + xkISOLevel3Shift = 0xfe03 + xkISOLeftTab = 0xfe20 xkBackSpace = 0xff08 xkTab = 0xff09 @@ -183,6 +188,8 @@ const ( // that do not correspond to a Unicode code point, such as "Page Up", "F1" or // "Left Shift", to key.Code values. var nonUnicodeKeycodes = map[rune]key.Code{ + xkISOLevel3Shift: key.CodeRightAlt, + xkISOLeftTab: key.CodeTab, xkBackSpace: key.CodeDeleteBackspace, xkTab: key.CodeTab,