Made separate function for converting keycode to keysym
This commit is contained in:
parent
aee4158d2d
commit
820c7d4f6a
@ -5,7 +5,6 @@ import "image"
|
|||||||
import "github.com/jezek/xgbutil"
|
import "github.com/jezek/xgbutil"
|
||||||
import "github.com/jezek/xgb/xproto"
|
import "github.com/jezek/xgb/xproto"
|
||||||
import "github.com/jezek/xgbutil/xevent"
|
import "github.com/jezek/xgbutil/xevent"
|
||||||
import "github.com/jezek/xgbutil/keybind"
|
|
||||||
|
|
||||||
import "git.tebibyte.media/sashakoshka/stone"
|
import "git.tebibyte.media/sashakoshka/stone"
|
||||||
|
|
||||||
@ -59,16 +58,16 @@ func (backend *Backend) handleKeyPress (
|
|||||||
event xevent.KeyPressEvent,
|
event xevent.KeyPressEvent,
|
||||||
) {
|
) {
|
||||||
keyEvent := *event.KeyPressEvent
|
keyEvent := *event.KeyPressEvent
|
||||||
keysym := keybind.KeysymGet(backend.connection, keyEvent.Detail, 0)
|
keysym := backend.keycodeToKeysym(keyEvent.Detail)
|
||||||
backend.channel <- stone.EventPress(keysymToButtonCode(keysym))
|
backend.channel <- stone.EventPress(keysymToButtonCode(keysym))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (backend *Backend) handleKeyRelease (
|
func (backend *Backend) handleKeyRelease (
|
||||||
connection *xgbutil.XUtil,
|
connection *xgbutil.XUtil,
|
||||||
event xevent.KeyPressEvent,
|
event xevent.KeyReleaseEvent,
|
||||||
) {
|
) {
|
||||||
keyEvent := *event.KeyPressEvent
|
keyEvent := *event.KeyReleaseEvent
|
||||||
keysym := keybind.KeysymGet(backend.connection, keyEvent.Detail, 0)
|
keysym := backend.keycodeToKeysym(keyEvent.Detail)
|
||||||
backend.channel <- stone.EventRelease(keysymToButtonCode(keysym))
|
backend.channel <- stone.EventRelease(keysymToButtonCode(keysym))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +122,10 @@ func factory (application *stone.Application) (output stone.Backend, err error)
|
|||||||
Connect(backend.connection, backend.window.Id)
|
Connect(backend.connection, backend.window.Id)
|
||||||
xevent.MotionNotifyFun(backend.handleMotionNotify).
|
xevent.MotionNotifyFun(backend.handleMotionNotify).
|
||||||
Connect(backend.connection, backend.window.Id)
|
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
|
output = backend
|
||||||
return
|
return
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package x
|
package x
|
||||||
|
|
||||||
import "github.com/jezek/xgb/xproto"
|
import "github.com/jezek/xgb/xproto"
|
||||||
|
import "github.com/jezek/xgbutil/keybind"
|
||||||
import "git.tebibyte.media/sashakoshka/stone"
|
import "git.tebibyte.media/sashakoshka/stone"
|
||||||
|
|
||||||
// when making changes to this file, look at keysymdef.h
|
// when making changes to this file, look at keysymdef.h
|
||||||
@ -54,6 +55,24 @@ var buttonCodeTable = map[xproto.Keysym] stone.Button {
|
|||||||
0xFFC9: stone.KeyF12,
|
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) {
|
func keysymToButtonCode (keysym xproto.Keysym) (button stone.Button) {
|
||||||
var isControl bool
|
var isControl bool
|
||||||
button, isControl = buttonCodeTable[keysym]
|
button, isControl = buttonCodeTable[keysym]
|
||||||
|
Loading…
Reference in New Issue
Block a user