mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
io,app: route all unhandled key events to the topmost handler
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -937,6 +937,11 @@ func (w *Window) processEvent(d driver, e event.Event) bool {
|
|||||||
handled = false
|
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)
|
w.updateCursor(d)
|
||||||
return handled
|
return handled
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ type InputOp struct {
|
|||||||
Hint InputHint
|
Hint InputHint
|
||||||
// Keys is the set of keys Tag can handle. That is, Tag will only
|
// 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.
|
// 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
|
Keys Set
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+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 {
|
func (q *Router) Queue(events ...event.Event) bool {
|
||||||
for _, e := range events {
|
for _, e := range events {
|
||||||
switch e := e.(type) {
|
switch e := e.(type) {
|
||||||
|
|||||||
Reference in New Issue
Block a user