io/key: implement key.Release state

Implement key state for the following platforms:
js, wayland, windows, x11.

Unsupported platforms will continue to function as before, sending
key.Press for all key events.

Signed-off-by: Josiah Niedrauer <josiah@niedrauer.com>
This commit is contained in:
Josiah Niedrauer
2020-10-29 15:46:41 -07:00
committed by Elias Naur
parent ef652f4922
commit 42e568775c
7 changed files with 57 additions and 14 deletions
+15 -5
View File
@@ -964,13 +964,14 @@ func gio_onKeyboardKey(data unsafe.Pointer, keyboard *C.struct_wl_keyboard, seri
t := time.Duration(timestamp) * time.Millisecond
s.disp.repeat.Stop(t)
w.resetFling()
kc := mapXKBKeycode(uint32(keyCode))
ks := mapXKBKeyState(uint32(state))
for _, e := range w.disp.xkb.DispatchKey(kc, ks) {
w.w.Event(e)
}
if state != C.WL_KEYBOARD_KEY_STATE_PRESSED {
return
}
kc := mapXKBKeycode(uint32(keyCode))
for _, e := range w.disp.xkb.DispatchKey(kc) {
w.w.Event(e)
}
if w.disp.xkb.IsRepeatKey(kc) {
w.disp.repeat.Start(w, kc, t)
}
@@ -981,6 +982,15 @@ func mapXKBKeycode(keyCode uint32) uint32 {
return keyCode + 8
}
func mapXKBKeyState(state uint32) key.State {
switch state {
case C.WL_KEYBOARD_KEY_STATE_RELEASED:
return key.Release
default:
return key.Press
}
}
func (r *repeatState) Start(w *window, keyCode uint32, t time.Duration) {
if r.rate <= 0 {
return
@@ -1046,7 +1056,7 @@ func (r *repeatState) Repeat(d *wlDisplay) {
if r.last+delay > now {
break
}
for _, e := range d.xkb.DispatchKey(r.key) {
for _, e := range d.xkb.DispatchKey(r.key, key.Press) {
r.win.Event(e)
}
r.last += delay