From ec7f029c9b7d9f9c324730acb9400a35fd98f310 Mon Sep 17 00:00:00 2001 From: Michael Zabka Date: Tue, 29 Dec 2020 20:38:26 +0000 Subject: [PATCH 1/5] Fix wrong condition in x11key Lookup for ASCII code * the condition was never met because rune is usually unsigned int * the logical result of checking whether unshifted key rune is ASCII is range from 0 to 0x80 --- shiny/driver/internal/x11key/x11key.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shiny/driver/internal/x11key/x11key.go b/shiny/driver/internal/x11key/x11key.go index 546d46306..9fe2cea92 100644 --- a/shiny/driver/internal/x11key/x11key.go +++ b/shiny/driver/internal/x11key/x11key.go @@ -63,7 +63,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) From 56ae3d946c419c1356e31f0323668179551bd58a Mon Sep 17 00:00:00 2001 From: Michael Zabka Date: Sun, 3 Jan 2021 16:24:36 +0000 Subject: [PATCH 2/5] Add missing XK ISO Level 3 shift non unicode char in x11key map * The most appropriate description here: https://unix.stackexchange.com/a/55154/440266 * Right Alt ~ AltGr ~ ISO level 3 shift (but just for back compatibility) * in new sense the SwitchMode is replaced by XK_ISO_Group_Shift and aliases in some languages (keyboard layouts) --- shiny/driver/internal/x11key/x11key.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shiny/driver/internal/x11key/x11key.go b/shiny/driver/internal/x11key/x11key.go index 9fe2cea92..3e44fba09 100644 --- a/shiny/driver/internal/x11key/x11key.go +++ b/shiny/driver/internal/x11key/x11key.go @@ -104,6 +104,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 +185,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, From 5e9556e5c0692cb58608d3e11186ca291e83acd1 Mon Sep 17 00:00:00 2001 From: Michael Zabka Date: Sun, 3 Jan 2021 16:40:40 +0000 Subject: [PATCH 3/5] Add missing methods descriptions * adjust package comments to match golint --- shiny/driver/internal/x11key/x11key.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shiny/driver/internal/x11key/x11key.go b/shiny/driver/internal/x11key/x11key.go index 3e44fba09..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 { @@ -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 From 1779ad942aaa998d468962db06294297b5adfa62 Mon Sep 17 00:00:00 2001 From: Michael Zabka Date: Sun, 3 Jan 2021 18:00:23 +0000 Subject: [PATCH 4/5] Replace wrong XK_menu mapped values to correct CodeProps * it's alternativelly code for menu (not GUI) --- go.mod | 2 ++ go.sum | 2 ++ shiny/driver/internal/x11key/x11key.go | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 00c5b4566..c5d212315 100644 --- a/go.mod +++ b/go.mod @@ -13,3 +13,5 @@ require ( golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 ) + +replace golang.org/x/mobile => github.com/misak113/mobile v0.0.0-20210103170524-21e5a0da1870 diff --git a/go.sum b/go.sum index 545190e0d..7840b7e2d 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 h1:1BDTz0u9nC3//pOC github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4 h1:WtGNWLvXpe6ZudgnXrq0barxBImvnnJoMEhXAzcbM0I= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/misak113/mobile v0.0.0-20210103170524-21e5a0da1870 h1:aY61pPEbj2YiIDdjBvnvbkTxxGuBps3CS7Qirb1AODg= +github.com/misak113/mobile v0.0.0-20210103170524-21e5a0da1870/go.mod h1:skQtrUTUwhdJvXM/2KKJzY8pDgNr9I/FOMqDVRPBUS4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= diff --git a/shiny/driver/internal/x11key/x11key.go b/shiny/driver/internal/x11key/x11key.go index fc70abcaa..cefa5f6e9 100644 --- a/shiny/driver/internal/x11key/x11key.go +++ b/shiny/driver/internal/x11key/x11key.go @@ -204,7 +204,7 @@ var nonUnicodeKeycodes = map[rune]key.Code{ xkPageDown: key.CodePageDown, xkEnd: key.CodeEnd, xkInsert: key.CodeInsert, - xkMenu: key.CodeRightGUI, // TODO: CodeRightGUI or CodeMenu?? + xkMenu: key.CodeProps, xkHelp: key.CodeHelp, xkNumLock: key.CodeKeypadNumLock, xkMultiKey: key.CodeCompose, From 73e06796dda710f29510b400961040e6e4593036 Mon Sep 17 00:00:00 2001 From: Michael Zabka Date: Sun, 3 Jan 2021 18:02:42 +0000 Subject: [PATCH 5/5] Add support for more event key modifiers for x11 (capslock, numlock & switch modes * it's currently using default bits reserved for switch modes & caps/num lock by X11. * However, it can differs depend on keyboard layout. The real bit values are available in KeysymTable. * but this change woul mean change of interface --- shiny/driver/internal/x11key/x11key.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/shiny/driver/internal/x11key/x11key.go b/shiny/driver/internal/x11key/x11key.go index cefa5f6e9..ecdd9d0e8 100644 --- a/shiny/driver/internal/x11key/x11key.go +++ b/shiny/driver/internal/x11key/x11key.go @@ -89,6 +89,8 @@ func isKeypad(keysym uint32) bool { } // KeyModifiers returns mobile/event/key modifiers type from xproto mod state +// ModCapsLock, ModNumLock & ModLevel3Shift are currently implemented using default general modifier bits +// it should be method of KeysymTable with current keyboard mapping func KeyModifiers(state uint16) (m key.Modifiers) { if state&ShiftMask != 0 { m |= key.ModShift @@ -102,6 +104,18 @@ func KeyModifiers(state uint16) (m key.Modifiers) { if state&Mod4Mask != 0 { m |= key.ModMeta } + if state&LockMask != 0 { + m |= key.ModCapsLock + } + if state&Mod2Mask != 0 { // TODO should goes from t.NumLockMod instead because it's dynamic + m |= key.ModNumLock + } + if state&Mod5Mask != 0 { // TODO should goes from t.ISOLevel3ShiftMod instead because it's dynamic + m |= key.ModLevel3Shift + } + if state&Mod5Mask != 0 { // TODO should goes from t.ModeSwitchMod instead because it's dynamic + m |= key.ModModeSwitch + } return m }