mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
io/router: replace cursor stack with area field
There's no need to track cursors separately from areas. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+22
-31
@@ -17,7 +17,6 @@ import (
|
|||||||
type pointerQueue struct {
|
type pointerQueue struct {
|
||||||
hitTree []hitNode
|
hitTree []hitNode
|
||||||
areas []areaNode
|
areas []areaNode
|
||||||
cursors []cursorNode
|
|
||||||
cursor pointer.Cursor
|
cursor pointer.Cursor
|
||||||
handlers map[event.Tag]*pointerHandler
|
handlers map[event.Tag]*pointerHandler
|
||||||
pointers []pointerInfo
|
pointers []pointerInfo
|
||||||
@@ -44,11 +43,6 @@ type hitNode struct {
|
|||||||
pass bool
|
pass bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type cursorNode struct {
|
|
||||||
cursor pointer.Cursor
|
|
||||||
area int
|
|
||||||
}
|
|
||||||
|
|
||||||
type pointerInfo struct {
|
type pointerInfo struct {
|
||||||
id pointer.ID
|
id pointer.ID
|
||||||
pressed bool
|
pressed bool
|
||||||
@@ -87,6 +81,8 @@ type areaNode struct {
|
|||||||
trans f32.Affine2D
|
trans f32.Affine2D
|
||||||
area areaOp
|
area areaOp
|
||||||
|
|
||||||
|
cursor pointer.Cursor
|
||||||
|
|
||||||
// Tree indices, with -1 being the sentinel.
|
// Tree indices, with -1 being the sentinel.
|
||||||
parent int
|
parent int
|
||||||
firstChild int
|
firstChild int
|
||||||
@@ -312,10 +308,9 @@ func (c *pointerCollector) semanticDisabled(disabled bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *pointerCollector) cursor(cursor pointer.Cursor) {
|
func (c *pointerCollector) cursor(cursor pointer.Cursor) {
|
||||||
c.q.cursors = append(c.q.cursors, cursorNode{
|
areaID := c.currentArea()
|
||||||
cursor: cursor,
|
area := &c.q.areas[areaID]
|
||||||
area: len(c.q.areas) - 1,
|
area.cursor = cursor
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *pointerCollector) sourceOp(op transfer.SourceOp, events *handlerEvents) {
|
func (c *pointerCollector) sourceOp(op transfer.SourceOp, events *handlerEvents) {
|
||||||
@@ -432,7 +427,7 @@ func (q *pointerQueue) SemanticAt(pos f32.Point) (SemanticID, bool) {
|
|||||||
q.assignSemIDs()
|
q.assignSemIDs()
|
||||||
for i := len(q.hitTree) - 1; i >= 0; i-- {
|
for i := len(q.hitTree) - 1; i >= 0; i-- {
|
||||||
n := &q.hitTree[i]
|
n := &q.hitTree[i]
|
||||||
hit := q.hit(n.area, pos)
|
hit, _ := q.hit(n.area, pos)
|
||||||
if !hit {
|
if !hit {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -444,18 +439,22 @@ func (q *pointerQueue) SemanticAt(pos f32.Point) (SemanticID, bool) {
|
|||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *pointerQueue) opHit(pos f32.Point) []event.Tag {
|
func (q *pointerQueue) opHit(pos f32.Point) ([]event.Tag, pointer.Cursor) {
|
||||||
// Track whether we're passing through hits.
|
// Track whether we're passing through hits.
|
||||||
pass := true
|
pass := true
|
||||||
hits := q.scratch[:0]
|
hits := q.scratch[:0]
|
||||||
idx := len(q.hitTree) - 1
|
idx := len(q.hitTree) - 1
|
||||||
|
cursor := pointer.CursorDefault
|
||||||
for idx >= 0 {
|
for idx >= 0 {
|
||||||
n := &q.hitTree[idx]
|
n := &q.hitTree[idx]
|
||||||
hit := q.hit(n.area, pos)
|
hit, c := q.hit(n.area, pos)
|
||||||
if !hit {
|
if !hit {
|
||||||
idx--
|
idx--
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if cursor == pointer.CursorDefault {
|
||||||
|
cursor = c
|
||||||
|
}
|
||||||
pass = pass && n.pass
|
pass = pass && n.pass
|
||||||
if pass {
|
if pass {
|
||||||
idx--
|
idx--
|
||||||
@@ -469,7 +468,7 @@ func (q *pointerQueue) opHit(pos f32.Point) []event.Tag {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
q.scratch = hits[:0]
|
q.scratch = hits[:0]
|
||||||
return hits
|
return hits, cursor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *pointerQueue) invTransform(areaIdx int, p f32.Point) f32.Point {
|
func (q *pointerQueue) invTransform(areaIdx int, p f32.Point) f32.Point {
|
||||||
@@ -479,16 +478,20 @@ func (q *pointerQueue) invTransform(areaIdx int, p f32.Point) f32.Point {
|
|||||||
return q.areas[areaIdx].trans.Invert().Transform(p)
|
return q.areas[areaIdx].trans.Invert().Transform(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *pointerQueue) hit(areaIdx int, p f32.Point) bool {
|
func (q *pointerQueue) hit(areaIdx int, p f32.Point) (bool, pointer.Cursor) {
|
||||||
|
c := pointer.CursorDefault
|
||||||
for areaIdx != -1 {
|
for areaIdx != -1 {
|
||||||
a := &q.areas[areaIdx]
|
a := &q.areas[areaIdx]
|
||||||
|
if c == pointer.CursorDefault {
|
||||||
|
c = a.cursor
|
||||||
|
}
|
||||||
p := a.trans.Invert().Transform(p)
|
p := a.trans.Invert().Transform(p)
|
||||||
if !a.area.Hit(p) {
|
if !a.area.Hit(p) {
|
||||||
return false
|
return false, c
|
||||||
}
|
}
|
||||||
areaIdx = a.parent
|
areaIdx = a.parent
|
||||||
}
|
}
|
||||||
return true
|
return true, c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *pointerQueue) reset() {
|
func (q *pointerQueue) reset() {
|
||||||
@@ -505,7 +508,6 @@ func (q *pointerQueue) reset() {
|
|||||||
}
|
}
|
||||||
q.hitTree = q.hitTree[:0]
|
q.hitTree = q.hitTree[:0]
|
||||||
q.areas = q.areas[:0]
|
q.areas = q.areas[:0]
|
||||||
q.cursors = q.cursors[:0]
|
|
||||||
q.semantic.idsAssigned = false
|
q.semantic.idsAssigned = false
|
||||||
for k, ids := range q.semantic.contentIDs {
|
for k, ids := range q.semantic.contentIDs {
|
||||||
for i := len(ids) - 1; i >= 0; i-- {
|
for i := len(ids) - 1; i >= 0; i-- {
|
||||||
@@ -687,7 +689,7 @@ func (q *pointerQueue) deliverEnterLeaveEvents(p *pointerInfo, events *handlerEv
|
|||||||
if e.Source != pointer.Mouse && !p.pressed && e.Type != pointer.Press {
|
if e.Source != pointer.Mouse && !p.pressed && e.Type != pointer.Press {
|
||||||
// Consider non-mouse pointers leaving when they're released.
|
// Consider non-mouse pointers leaving when they're released.
|
||||||
} else {
|
} else {
|
||||||
hits = q.opHit(e.Position)
|
hits, q.cursor = q.opHit(e.Position)
|
||||||
if p.pressed {
|
if p.pressed {
|
||||||
// Filter out non-participating handlers,
|
// Filter out non-participating handlers,
|
||||||
// except potential transfer targets when a transfer has been initiated.
|
// except potential transfer targets when a transfer has been initiated.
|
||||||
@@ -723,20 +725,9 @@ func (q *pointerQueue) deliverEnterLeaveEvents(p *pointerInfo, events *handlerEv
|
|||||||
events.Add(k, e)
|
events.Add(k, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Deliver Enter events and update cursor.
|
// Deliver Enter events.
|
||||||
q.cursor = pointer.CursorDefault
|
|
||||||
cursorFound := false
|
|
||||||
for _, k := range hits {
|
for _, k := range hits {
|
||||||
h := q.handlers[k]
|
h := q.handlers[k]
|
||||||
if !cursorFound {
|
|
||||||
for i := len(q.cursors) - 1; i >= 0; i-- {
|
|
||||||
if c := q.cursors[i]; c.area == h.area {
|
|
||||||
q.cursor = c.cursor
|
|
||||||
cursorFound = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if _, found := searchTag(p.entered, k); found {
|
if _, found := searchTag(p.entered, k); found {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user