mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 01:45:36 +00:00
io/router: don't trigger redraw for handler reset events
key.InputOp and pointer.InputOp handlers are reset on first registration
through a key.FocusEvent{false} or pointer.Cancel, respectively.
However, the mere act of registering a handle shouldn't result in a
redraw. This is particularly true for misconfigured handlers where a new
tag is supplied every frame, resulting in continously redrawing.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -11,6 +11,28 @@ import (
|
||||
"gioui.org/op"
|
||||
)
|
||||
|
||||
func TestKeyWakeup(t *testing.T) {
|
||||
handler := new(int)
|
||||
var ops op.Ops
|
||||
key.InputOp{Tag: handler}.Add(&ops)
|
||||
|
||||
var r Router
|
||||
// Test that merely adding a handler doesn't trigger redraw.
|
||||
r.Frame(&ops)
|
||||
if _, wake := r.WakeupTime(); wake {
|
||||
t.Errorf("adding key.InputOp triggered a redraw")
|
||||
}
|
||||
// However, adding a handler queues a Focus(false) event.
|
||||
if evts := r.Events(handler); len(evts) != 1 {
|
||||
t.Errorf("no Focus event for newly registered key.InputOp")
|
||||
}
|
||||
// Verify that r.Events does trigger a redraw.
|
||||
r.Frame(&ops)
|
||||
if _, wake := r.WakeupTime(); !wake {
|
||||
t.Errorf("key.FocusEvent event didn't trigger a redraw")
|
||||
}
|
||||
}
|
||||
|
||||
func TestKeyMultiples(t *testing.T) {
|
||||
handlers := make([]int, 3)
|
||||
ops := new(op.Ops)
|
||||
|
||||
Reference in New Issue
Block a user