From 8c28c57925475d9bebc8907ef6b07224fa4dfecb Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 21 Nov 2022 23:43:22 -0500 Subject: [PATCH] Support for meta and hyper keys added Support for the compose key has also been added but it's just the button code for now, no support for actually composing stuff. There are plans for that in a fixme. --- backend.go | 6 ++--- backends/x/unicode.go | 18 ++++++++++++++- examples/printbuttons/main.go | 41 +++++++++++++++++++++++++++++++++++ input.go | 14 ++++++++---- 4 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 examples/printbuttons/main.go diff --git a/backend.go b/backend.go index d009886..bbf7a0b 100644 --- a/backend.go +++ b/backend.go @@ -17,7 +17,7 @@ type Backend interface { // Whatever the application draws from within this event handler must be // the first thing that appears on-screen. // - // The OnResize evnt handler must run whenever the window is resized. + // The OnResize event handler must run whenever the window is resized. // The backend must push updates to the screen after OnResize has been // run. // @@ -45,8 +45,8 @@ type Backend interface { Draw () } -// BackendFactory should completely initialize a backend, and return it. If -// anything goes wrong, it should stop, clean up any resources and return an +// BackendFactory must completely initialize a backend, and return it. If +// anything goes wrong, it must stop, clean up any resources and return an // error so another backend can be chosen. type BackendFactory func ( application *Application, diff --git a/backends/x/unicode.go b/backends/x/unicode.go index ecfa329..8d186b0 100644 --- a/backends/x/unicode.go +++ b/backends/x/unicode.go @@ -1,5 +1,6 @@ package x +import "fmt" import "unicode" import "github.com/jezek/xgb/xproto" import "github.com/jezek/xgbutil/keybind" @@ -36,10 +37,15 @@ var buttonCodeTable = map[xproto.Keysym] stone.Button { 0xFFE2: stone.KeyRightShift, 0xFFE3: stone.KeyLeftControl, 0xFFE4: stone.KeyRightControl, + + 0xFFE7: stone.KeyLeftMeta, + 0xFFE8: stone.KeyRightMeta, 0xFFE9: stone.KeyLeftAlt, 0xFFEA: stone.KeyRightAlt, 0xFFEB: stone.KeyLeftSuper, 0xFFEC: stone.KeyRightSuper, + 0xFFED: stone.KeyLeftHyper, + 0xFFEE: stone.KeyRightHyper, 0xFFFF: stone.KeyDelete, @@ -55,6 +61,14 @@ var buttonCodeTable = map[xproto.Keysym] stone.Button { 0xFFC7: stone.KeyF10, 0xFFC8: stone.KeyF11, 0xFFC9: stone.KeyF12, + + // TODO: send this whenever a compose key, dead key, etc is pressed, + // and then send the resulting character while witholding the key + // presses that were used to compose it. As far as the program is + // concerned, a magical key with the final character was pressed and the + // KeyDead key is just so that the program might provide some visual + // feedback to the user while input is being waited for. + 0xFF20: stone.KeyDead, } func (backend *Backend) keycodeToButton ( @@ -84,7 +98,7 @@ func (backend *Backend) keycodeToButton ( symbol3 = symbol1 case symbol3 == 0 && symbol4 == 0: symbol3 = symbol1 - symbol2 = symbol2 + symbol4 = symbol2 case symbol4 == 0: symbol4 = 0 } @@ -123,6 +137,8 @@ func (backend *Backend) keycodeToButton ( var selectedKeysym xproto.Keysym var selectedRune rune + + fmt.Printf("AAA\t%X\t%X\t%X\t%X\n", symbol1, symbol2, symbol3, symbol4) // big ol list in the middle switch { diff --git a/examples/printbuttons/main.go b/examples/printbuttons/main.go new file mode 100644 index 0000000..fc2a779 --- /dev/null +++ b/examples/printbuttons/main.go @@ -0,0 +1,41 @@ +package main + +import "os" +import "image" +import _ "image/png" +import "git.tebibyte.media/sashakoshka/stone" +import _ "git.tebibyte.media/sashakoshka/stone/backends/x" + +var application = &stone.Application { } + +func main () { + application.SetTitle("press any key") + application.SetSize(8, 1) + + iconFile16, err := os.Open("assets/scaffold16.png") + if err != nil { panic(err) } + icon16, _, err := image.Decode(iconFile16) + if err != nil { panic(err) } + iconFile16.Close() + iconFile32, err := os.Open("assets/scaffold32.png") + if err != nil { panic(err) } + icon32, _, err := image.Decode(iconFile32) + if err != nil { panic(err) } + iconFile16.Close() + + application.SetIcon([]image.Image { icon16, icon32 }) + + application.OnPress(onPress) + application.OnRelease(onRelease) + + err = application.Run() + if err != nil { panic(err) } +} + +func onPress (button stone.Button) { + println("press", button) +} + +func onRelease (button stone.Button) { + println("release", button) +} diff --git a/input.go b/input.go index e3aba82..78adbe9 100644 --- a/input.go +++ b/input.go @@ -33,10 +33,14 @@ const ( KeyRightShift Button = 21 KeyLeftControl Button = 22 KeyRightControl Button = 23 - KeyLeftAlt Button = 24 - KeyRightAlt Button = 25 - KeyLeftSuper Button = 26 - KeyRightSuper Button = 27 + KeyLeftMeta Button = 24 + KeyRightMeta Button = 25 + KeyLeftAlt Button = 26 + KeyRightAlt Button = 27 + KeyLeftSuper Button = 28 + KeyRightSuper Button = 29 + KeyLeftHyper Button = 30 + KeyRightHyper Button = 31 KeyDelete Button = 127 @@ -67,6 +71,8 @@ const ( KeyF10 Button = 153 KeyF11 Button = 154 KeyF12 Button = 155 + + KeyDead Button = 156 ) // Printable returns whether or not the character could show up on screen. If