From 700d8d8c2c6d212d6106fc9a2b8c79517780a469 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Mon, 8 Jun 2020 14:59:59 +0200 Subject: [PATCH] io/router: merge grab and types for multiple InputOps for same handler Signed-off-by: Elias Naur --- io/router/pointer.go | 6 ++++-- io/router/pointer_test.go | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/io/router/pointer.go b/io/router/pointer.go index c179865e..250b5338 100644 --- a/io/router/pointer.go +++ b/io/router/pointer.go @@ -109,8 +109,8 @@ func (q *pointerQueue) collectHandlers(r *ops.Reader, events *handlerEvents, t o } h.active = true h.area = area - h.wantsGrab = op.Grab - h.types = op.Types + h.wantsGrab = h.wantsGrab || op.Grab + h.types = h.types | op.Types } } } @@ -169,6 +169,8 @@ func (q *pointerQueue) Frame(root *op.Ops, events *handlerEvents) { for _, h := range q.handlers { // Reset handler. h.active = false + h.wantsGrab = false + h.types = 0 } q.hitTree = q.hitTree[:0] q.areas = q.areas[:0] diff --git a/io/router/pointer_test.go b/io/router/pointer_test.go index fe05ae3f..2cc6a4f3 100644 --- a/io/router/pointer_test.go +++ b/io/router/pointer_test.go @@ -242,7 +242,12 @@ func TestMultipleAreas(t *testing.T) { var ops op.Ops addPointerHandler(&ops, handler, image.Rect(0, 0, 100, 100)) - addPointerHandler(&ops, handler, image.Rect(50, 50, 200, 200)) + st := op.Push(&ops) + pointer.Rect(image.Rect(50, 50, 200, 200)).Add(&ops) + // Second area has no Types set, yet should receive events because + // Types for the same handles are or-ed together. + pointer.InputOp{Tag: handler}.Add(&ops) + st.Pop() var r Router r.Frame(&ops)