io/pointer: support nested scrollables

Fixes #185.

Signed-off-by: pierre <pierre.curto@gmail.com>
This commit is contained in:
pierre
2021-03-31 08:25:08 +02:00
committed by Elias Naur
parent f3d75f38a9
commit 5e1a662b94
7 changed files with 158 additions and 20 deletions
+21 -5
View File
@@ -4,6 +4,7 @@ package pointer
import (
"encoding/binary"
"fmt"
"image"
"strings"
"time"
@@ -63,6 +64,12 @@ type InputOp struct {
Grab bool
// Types is a bitwise-or of event types to receive.
Types Type
// ScrollBounds describe the maximum scrollable distances in both
// axes. Specifically, any Event e delivered to Tag will satisfy
//
// ScrollBounds.Min.X <= e.Scroll.X <= ScrollBounds.Max.X (horizontal axis)
// ScrollBounds.Min.Y <= e.Scroll.Y <= ScrollBounds.Max.Y (vertical axis)
ScrollBounds image.Rectangle
}
// PassOp sets the pass-through mode.
@@ -195,16 +202,25 @@ func (op CursorNameOp) Add(o *op.Ops) {
data[0] = byte(opconst.TypeCursor)
}
func (h InputOp) Add(o *op.Ops) {
if h.Tag == nil {
// Add panics if the scroll range does not contain zero.
func (op InputOp) Add(o *op.Ops) {
if op.Tag == nil {
panic("Tag must be non-nil")
}
data := o.Write1(opconst.TypePointerInputLen, h.Tag)
if b := op.ScrollBounds; b.Min.X > 0 || b.Max.X < 0 || b.Min.Y > 0 || b.Max.Y < 0 {
panic(fmt.Errorf("invalid scroll range value %v", b))
}
data := o.Write1(opconst.TypePointerInputLen, op.Tag)
data[0] = byte(opconst.TypePointerInput)
if h.Grab {
if op.Grab {
data[1] = 1
}
data[2] = byte(h.Types)
data[2] = byte(op.Types)
bo := binary.LittleEndian
bo.PutUint32(data[3:], uint32(op.ScrollBounds.Min.X))
bo.PutUint32(data[7:], uint32(op.ScrollBounds.Min.Y))
bo.PutUint32(data[11:], uint32(op.ScrollBounds.Max.X))
bo.PutUint32(data[15:], uint32(op.ScrollBounds.Max.Y))
}
func (op PassOp) Add(o *op.Ops) {