mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
app,io/key: introduce keys for directional navigation
This change adds key.NameUp/Down/Left/Right and maps the Android TV remote directional keys to them. As a side-effect a key.InputOp can now receive directional keys (and block their focus movement). Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+11
-15
@@ -867,8 +867,6 @@ func (w *window) draw(env *C.JNIEnv, sync bool) {
|
||||
}
|
||||
}
|
||||
|
||||
type keyMapper func(devId, keyCode C.int32_t) rune
|
||||
|
||||
func runInJVM(jvm *C.JavaVM, f func(env *C.JNIEnv)) {
|
||||
if jvm == nil {
|
||||
panic("nil JVM")
|
||||
@@ -908,6 +906,14 @@ func convertKeyCode(code C.jint) (string, bool) {
|
||||
n = key.NameAlt
|
||||
case C.AKEYCODE_META_LEFT, C.AKEYCODE_META_RIGHT:
|
||||
n = key.NameSuper
|
||||
case C.AKEYCODE_DPAD_UP:
|
||||
n = key.NameUp
|
||||
case C.AKEYCODE_DPAD_DOWN:
|
||||
n = key.NameDown
|
||||
case C.AKEYCODE_DPAD_LEFT:
|
||||
n = key.NameLeft
|
||||
case C.AKEYCODE_DPAD_RIGHT:
|
||||
n = key.NameRight
|
||||
default:
|
||||
return "", false
|
||||
}
|
||||
@@ -917,19 +923,9 @@ func convertKeyCode(code C.jint) (string, bool) {
|
||||
//export Java_org_gioui_GioView_onKeyEvent
|
||||
func Java_org_gioui_GioView_onKeyEvent(env *C.JNIEnv, class C.jclass, handle C.jlong, keyCode, r C.jint, pressed C.jboolean, t C.jlong) {
|
||||
w := cgo.Handle(handle).Value().(*window)
|
||||
if pressed == C.JNI_TRUE {
|
||||
switch keyCode {
|
||||
case C.AKEYCODE_DPAD_UP:
|
||||
w.callbacks.MoveFocus(router.FocusUp)
|
||||
case C.AKEYCODE_DPAD_DOWN:
|
||||
w.callbacks.MoveFocus(router.FocusDown)
|
||||
case C.AKEYCODE_DPAD_LEFT:
|
||||
w.callbacks.MoveFocus(router.FocusLeft)
|
||||
case C.AKEYCODE_DPAD_RIGHT:
|
||||
w.callbacks.MoveFocus(router.FocusRight)
|
||||
case C.AKEYCODE_DPAD_CENTER:
|
||||
w.callbacks.ClickFocus()
|
||||
}
|
||||
if pressed == C.JNI_TRUE && keyCode == C.AKEYCODE_DPAD_CENTER {
|
||||
w.callbacks.ClickFocus()
|
||||
return
|
||||
}
|
||||
if n, ok := convertKeyCode(keyCode); ok {
|
||||
state := key.Release
|
||||
|
||||
+8
-4
@@ -506,10 +506,6 @@ func (c *callbacks) SetEditorSnippet(r key.Range) {
|
||||
c.Event(key.SnippetEvent(r))
|
||||
}
|
||||
|
||||
func (c *callbacks) MoveFocus(dir router.FocusDirection) {
|
||||
c.w.moveFocus(dir, c.d)
|
||||
}
|
||||
|
||||
func (w *Window) moveFocus(dir router.FocusDirection, d driver) {
|
||||
if w.queue.q.MoveFocus(dir) {
|
||||
w.queue.q.RevealFocus(w.viewport)
|
||||
@@ -851,6 +847,14 @@ func (w *Window) processEvent(d driver, e event.Event) {
|
||||
w.moveFocus(router.FocusForward, d)
|
||||
case e.Name == key.NameTab && e.Modifiers == key.ModShift:
|
||||
w.moveFocus(router.FocusBackward, d)
|
||||
case e.Name == key.NameUp && e.Modifiers == 0:
|
||||
w.moveFocus(router.FocusUp, d)
|
||||
case e.Name == key.NameDown && e.Modifiers == 0:
|
||||
w.moveFocus(router.FocusDown, d)
|
||||
case e.Name == key.NameLeft && e.Modifiers == 0:
|
||||
w.moveFocus(router.FocusLeft, d)
|
||||
case e.Name == key.NameRight && e.Modifiers == 0:
|
||||
w.moveFocus(router.FocusRight, d)
|
||||
}
|
||||
}
|
||||
w.updateCursor(d)
|
||||
|
||||
@@ -219,6 +219,10 @@ const (
|
||||
NameF10 = "F10"
|
||||
NameF11 = "F11"
|
||||
NameF12 = "F12"
|
||||
NameUp = "Up"
|
||||
NameDown = "Down"
|
||||
NameLeft = "Left"
|
||||
NameRight = "Right"
|
||||
)
|
||||
|
||||
// Contain reports whether m contains all modifiers
|
||||
|
||||
Reference in New Issue
Block a user