~eliasnaur/gio

0dba85f52e5131c03d903c84355fb90cdb978811 — Elias Naur 9 months ago 32c6a9b
io,app: route all unhandled key events to the topmost handler

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

M app/window.go
M io/key/key.go
M io/router/router.go
M app/window.go => app/window.go +5 -0
@@ 937,6 937,11 @@ func (w *Window) processEvent(d driver, e event.Event) bool {
				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
	}

M io/key/key.go => io/key/key.go +2 -0
@@ 30,6 30,8 @@ type InputOp struct {
	Hint InputHint
	// Keys is the set of keys Tag can handle. That is, Tag will only
	// receive an Event if its key and modifiers are accepted by Keys.Contains.
	// As a special case, the topmost (first added) InputOp handler receives all
	// unhandled events.
	Keys Set
}


M io/router/router.go => io/router/router.go +20 -1
@@ 134,7 134,26 @@ func (q *Router) Frame(frame *op.Ops) {
	}
}

// Queue an event and report whether at least one handler had an event queued.
// Queue key events to the topmost handler.
func (q *Router) QueueTopmost(events ...key.Event) bool {
	var topmost event.Tag
	pq := &q.pointer.queue
	for _, h := range pq.hitTree {
		if h.ktag != nil {
			topmost = h.ktag
			break
		}
	}
	if topmost == nil {
		return false
	}
	for _, e := range events {
		q.handlers.Add(topmost, e)
	}
	return q.handlers.HadEvents()
}

// Queue events and report whether at least one handler had an event queued.
func (q *Router) Queue(events ...event.Event) bool {
	for _, e := range events {
		switch e := e.(type) {