io,app: route all unhandled key events to the topmost handler

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-02-06 17:10:21 -06:00
parent 32c6a9b10d
commit 0dba85f52e
3 changed files with 27 additions and 1 deletions
+2
View File
@@ -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
}
+20 -1
View File
@@ -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) {