mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
all: replace InvalidateOp with InvalidateCmd command
Curiously, InvalidateCmd is probably the only command that is appropriate to call during layout. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+9
-22
@@ -3,7 +3,6 @@
|
||||
package input
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"image"
|
||||
"io"
|
||||
"strings"
|
||||
@@ -44,7 +43,7 @@ type Router struct {
|
||||
|
||||
reader ops.Reader
|
||||
|
||||
// InvalidateOp summary.
|
||||
// InvalidateCmd summary.
|
||||
wakeup bool
|
||||
wakeupTime time.Time
|
||||
|
||||
@@ -261,7 +260,6 @@ func (q *Router) Frame(frame *op.Ops) {
|
||||
}
|
||||
}
|
||||
q.transfers = nil
|
||||
q.wakeup = false
|
||||
q.deferring = false
|
||||
for _, h := range q.handlers {
|
||||
h.filter, h.nextFilter = h.nextFilter, h.filter
|
||||
@@ -470,6 +468,11 @@ func (q *Router) executeCommand(c Command) (event.Tag, stateChange) {
|
||||
case pointer.GrabCmd:
|
||||
tag = req.Tag
|
||||
state.pointerState, evts = q.pointer.queue.grab(state.pointerState, req)
|
||||
case op.InvalidateCmd:
|
||||
if !q.wakeup || req.At.Before(q.wakeupTime) {
|
||||
q.wakeup = true
|
||||
q.wakeupTime = req.At
|
||||
}
|
||||
}
|
||||
return tag, stateChange{state: state, events: evts}
|
||||
}
|
||||
@@ -727,12 +730,6 @@ func (q *Router) collect() {
|
||||
var t f32.Affine2D
|
||||
for encOp, ok := q.reader.Decode(); ok; encOp, ok = q.reader.Decode() {
|
||||
switch ops.OpType(encOp.Data[0]) {
|
||||
case ops.TypeInvalidate:
|
||||
op := decodeInvalidateOp(encOp.Data)
|
||||
if !q.wakeup || op.At.Before(q.wakeupTime) {
|
||||
q.wakeup = true
|
||||
q.wakeupTime = op.At
|
||||
}
|
||||
case ops.TypeSave:
|
||||
id := ops.DecodeSave(encOp.Data)
|
||||
if extra := id - len(q.savedTrans) + 1; extra > 0 {
|
||||
@@ -822,19 +819,9 @@ func (q *Router) collect() {
|
||||
// WakeupTime returns the most recent time for doing another frame,
|
||||
// as determined from the last call to Frame.
|
||||
func (q *Router) WakeupTime() (time.Time, bool) {
|
||||
return q.wakeupTime, q.wakeup
|
||||
}
|
||||
|
||||
func decodeInvalidateOp(d []byte) op.InvalidateOp {
|
||||
bo := binary.LittleEndian
|
||||
if ops.OpType(d[0]) != ops.TypeInvalidate {
|
||||
panic("invalid op")
|
||||
}
|
||||
var o op.InvalidateOp
|
||||
if nanos := bo.Uint64(d[1:]); nanos > 0 {
|
||||
o.At = time.Unix(0, int64(nanos))
|
||||
}
|
||||
return o
|
||||
w := q.wakeup
|
||||
q.wakeup = false
|
||||
return q.wakeupTime, w
|
||||
}
|
||||
|
||||
func (s SemanticGestures) String() string {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"gioui.org/io/pointer"
|
||||
"gioui.org/op"
|
||||
)
|
||||
|
||||
func TestNoFilterAllocs(t *testing.T) {
|
||||
@@ -22,3 +23,12 @@ func TestNoFilterAllocs(t *testing.T) {
|
||||
t.Fatalf("expected 0 AllocsPerOp, got %d", allocs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRouterWakeup(t *testing.T) {
|
||||
r := new(Router)
|
||||
r.Source().Execute(op.InvalidateCmd{})
|
||||
r.Frame(new(op.Ops))
|
||||
if _, wake := r.WakeupTime(); !wake {
|
||||
t.Errorf("InvalidateCmd did not trigger a redraw")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user