io/input: discard pointer reset event if filter doesn't match

New handlers receive reset events the first time Source.Event is called.
However, in case the filter doesn't match a reset event it shouldn't be
reported.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-11-27 19:33:16 -06:00
parent 1fc646a8c2
commit f5aa745038
2 changed files with 11 additions and 1 deletions
+10
View File
@@ -19,6 +19,16 @@ import (
"gioui.org/op/clip"
)
func TestFilterReset(t *testing.T) {
r := new(Router)
if _, ok := r.Event(pointer.Filter{}); ok {
t.Fatal("empty filter matched reset event")
}
if _, ok := r.Event(pointer.Filter{Kinds: pointer.Cancel}); ok {
t.Fatal("second call to Event matched reset event")
}
}
func TestPointerNilTarget(t *testing.T) {
r := new(Router)
r.Event(pointer.Filter{Kinds: pointer.Press})
+1 -1
View File
@@ -255,7 +255,7 @@ func (q *Router) Event(filters ...event.Filter) (event.Event, bool) {
break
}
h := q.stateFor(f.Target)
if reset, ok := h.pointer.ResetEvent(); ok {
if reset, ok := h.pointer.ResetEvent(); ok && h.filter.pointer.Matches(reset) {
return reset, true
}
}