From 820c7d4f6a44d9389a3e3240c94f0580e069c3b4 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Mon, 14 Nov 2022 15:58:34 -0500 Subject: [PATCH] Made separate function for converting keycode to keysym --- backends/x/event.go | 9 ++++----- backends/x/factory.go | 4 ++++ backends/x/unicode.go | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/backends/x/event.go b/backends/x/event.go index e306795..45d7ebb 100644 --- a/backends/x/event.go +++ b/backends/x/event.go @@ -5,7 +5,6 @@ import "image" import "github.com/jezek/xgbutil" import "github.com/jezek/xgb/xproto" import "github.com/jezek/xgbutil/xevent" -import "github.com/jezek/xgbutil/keybind" import "git.tebibyte.media/sashakoshka/stone" @@ -59,16 +58,16 @@ func (backend *Backend) handleKeyPress ( event xevent.KeyPressEvent, ) { keyEvent := *event.KeyPressEvent - keysym := keybind.KeysymGet(backend.connection, keyEvent.Detail, 0) + keysym := backend.keycodeToKeysym(keyEvent.Detail) backend.channel <- stone.EventPress(keysymToButtonCode(keysym)) } func (backend *Backend) handleKeyRelease ( connection *xgbutil.XUtil, - event xevent.KeyPressEvent, + event xevent.KeyReleaseEvent, ) { - keyEvent := *event.KeyPressEvent - keysym := keybind.KeysymGet(backend.connection, keyEvent.Detail, 0) + keyEvent := *event.KeyReleaseEvent + keysym := backend.keycodeToKeysym(keyEvent.Detail) backend.channel <- stone.EventRelease(keysymToButtonCode(keysym)) } diff --git a/backends/x/factory.go b/backends/x/factory.go index 2ed9b3c..1885496 100644 --- a/backends/x/factory.go +++ b/backends/x/factory.go @@ -122,6 +122,10 @@ func factory (application *stone.Application) (output stone.Backend, err error) Connect(backend.connection, backend.window.Id) xevent.MotionNotifyFun(backend.handleMotionNotify). Connect(backend.connection, backend.window.Id) + xevent.KeyPressFun(backend.handleKeyPress). + Connect(backend.connection, backend.window.Id) + xevent.KeyReleaseFun(backend.handleKeyRelease). + Connect(backend.connection, backend.window.Id) output = backend return diff --git a/backends/x/unicode.go b/backends/x/unicode.go index 1c0445f..b1c2df3 100644 --- a/backends/x/unicode.go +++ b/backends/x/unicode.go @@ -1,6 +1,7 @@ package x import "github.com/jezek/xgb/xproto" +import "github.com/jezek/xgbutil/keybind" import "git.tebibyte.media/sashakoshka/stone" // when making changes to this file, look at keysymdef.h @@ -54,6 +55,24 @@ var buttonCodeTable = map[xproto.Keysym] stone.Button { 0xFFC9: stone.KeyF12, } +func (backend *Backend) keycodeToKeysym ( + keycode xproto.Keycode, +) ( + keysym xproto.Keysym, +) { + keysym = keybind.KeysymGet(backend.connection, keycode, 0) + + // TODO: shift isnt working. follow + // https://tronche.com/gui/x/xlib/input/keyboard-encoding.html + + println("--") + println(keycode) + println(keysym) + println(stone.EventPress(keysymToButtonCode(keysym))) + + return +} + func keysymToButtonCode (keysym xproto.Keysym) (button stone.Button) { var isControl bool button, isControl = buttonCodeTable[keysym]