x-backend #2

Merged
sashakoshka merged 34 commits from x-backend into main 2022-11-14 21:40:25 -07:00
3 changed files with 27 additions and 5 deletions
Showing only changes of commit 820c7d4f6a - Show all commits

View File

@ -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))
}

View File

@ -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

View File

@ -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]