~eliasnaur/gio

c0d3f67b04687492e56a561ad3a149abdf98d4a0 — Elias Naur 1 year, 8 months ago ad3db52
app: really do deliver top-level key events

This is a fixup of 0dba85f52e5131c03d903c84355fb90cdb978811.
See discussion at

https://lists.sr.ht/~eliasnaur/gio-patches/%3C20230201160926.240528-1-alessandro.arzilli%40gmail.com%3E#%3C20230404144001.n2pndo5r5aqk46gq@x1%3E

Signed-off-by: Elias Naur <mail@eliasnaur.com>
1 files changed, 28 insertions(+), 27 deletions(-)

M app/window.go
M app/window.go => app/window.go +28 -27
@@ 604,8 604,6 @@ func (w *Window) moveFocus(dir router.FocusDirection, d driver) {
		dist := v.Mul(int(w.metric.Dp(scrollABit)))
		w.queue.q.ScrollFocus(dist)
	}
	w.setNextFrame(time.Time{})
	w.updateAnimation(d)
}

func (c *callbacks) ClickFocus() {


@@ 914,35 912,38 @@ func (w *Window) processEvent(d driver, e event.Event) bool {
		w.out <- e2
	case event.Event:
		handled := w.queue.q.Queue(e2)
		if e, ok := e.(key.Event); ok && !handled {
			if e.State == key.Press {
				handled = true
				isMobile := runtime.GOOS == "ios" || runtime.GOOS == "android"
				switch {
				case e.Name == key.NameTab && e.Modifiers == 0:
					w.moveFocus(router.FocusForward, d)
				case e.Name == key.NameTab && e.Modifiers == key.ModShift:
					w.moveFocus(router.FocusBackward, d)
				case e.Name == key.NameUpArrow && e.Modifiers == 0 && isMobile:
					w.moveFocus(router.FocusUp, d)
				case e.Name == key.NameDownArrow && e.Modifiers == 0 && isMobile:
					w.moveFocus(router.FocusDown, d)
				case e.Name == key.NameLeftArrow && e.Modifiers == 0 && isMobile:
					w.moveFocus(router.FocusLeft, d)
				case e.Name == key.NameRightArrow && e.Modifiers == 0 && isMobile:
					w.moveFocus(router.FocusRight, d)
				default:
					handled = false
				}
			}
			// As a special case, the top-most input handler receives all unhandled
			// events.
			if !handled {
				handled = w.queue.q.QueueTopmost(e)
			}
		}
		w.updateCursor(d)
		if handled {
			w.setNextFrame(time.Time{})
			w.updateAnimation(d)
		} else if e, ok := e.(key.Event); ok && e.State == key.Press {
			handled = true
			isMobile := runtime.GOOS == "ios" || runtime.GOOS == "android"
			switch {
			case e.Name == key.NameTab && e.Modifiers == 0:
				w.moveFocus(router.FocusForward, d)
			case e.Name == key.NameTab && e.Modifiers == key.ModShift:
				w.moveFocus(router.FocusBackward, d)
			case e.Name == key.NameUpArrow && e.Modifiers == 0 && isMobile:
				w.moveFocus(router.FocusUp, d)
			case e.Name == key.NameDownArrow && e.Modifiers == 0 && isMobile:
				w.moveFocus(router.FocusDown, d)
			case e.Name == key.NameLeftArrow && e.Modifiers == 0 && isMobile:
				w.moveFocus(router.FocusLeft, d)
			case e.Name == key.NameRightArrow && e.Modifiers == 0 && isMobile:
				w.moveFocus(router.FocusRight, d)
			default:
				handled = false
			}
		}
		// As a sepcial case, the top-most input handler receives all unhandled
		// events.
		if e, ok := e.(key.Event); ok && !handled {
			handled = w.queue.q.QueueTopmost(e)
		}
		w.updateCursor(d)
		return handled
	}
	return true