forked from joejulian/gio
app: run driver callbacks after event processing
Running, for example, Window.Close during a FrameEvent processing doesn't end well on platforms that immediately destroys the window. This change defers callbacks to after the completing the current event. Fixes: https://todo.sr.ht/~eliasnaur/gio/340 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+7
-4
@@ -48,6 +48,7 @@ type Window struct {
|
|||||||
|
|
||||||
waiting bool
|
waiting bool
|
||||||
waitEvents []event.Event
|
waitEvents []event.Event
|
||||||
|
defers []func(d driver)
|
||||||
out chan event.Event
|
out chan event.Event
|
||||||
frames chan *op.Ops
|
frames chan *op.Ops
|
||||||
frameAck chan struct{}
|
frameAck chan struct{}
|
||||||
@@ -428,6 +429,10 @@ func (c *callbacks) Event(e event.Event) {
|
|||||||
c.w.waitEvents = c.w.waitEvents[:len(c.w.waitEvents)-1]
|
c.w.waitEvents = c.w.waitEvents[:len(c.w.waitEvents)-1]
|
||||||
c.w.processEvent(c.d, we)
|
c.w.processEvent(c.d, we)
|
||||||
}
|
}
|
||||||
|
for _, f := range c.w.defers {
|
||||||
|
f(c.d)
|
||||||
|
}
|
||||||
|
c.w.defers = nil
|
||||||
c.w.updateState(c.d)
|
c.w.updateState(c.d)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -465,7 +470,7 @@ func (w *Window) waitAck(d driver) {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case f := <-w.driverFuncs:
|
case f := <-w.driverFuncs:
|
||||||
f(d)
|
w.defers = append(w.defers, f)
|
||||||
case w.out <- ackEvent:
|
case w.out <- ackEvent:
|
||||||
// A dummy event went through, so we know the application has processed the previous event.
|
// A dummy event went through, so we know the application has processed the previous event.
|
||||||
return
|
return
|
||||||
@@ -500,7 +505,7 @@ func (w *Window) waitFrame(d driver) (*op.Ops, bool) {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case f := <-w.driverFuncs:
|
case f := <-w.driverFuncs:
|
||||||
f(d)
|
w.defers = append(w.defers, f)
|
||||||
case frame := <-w.frames:
|
case frame := <-w.frames:
|
||||||
// The client called FrameEvent.Frame.
|
// The client called FrameEvent.Frame.
|
||||||
return frame, true
|
return frame, true
|
||||||
@@ -554,8 +559,6 @@ func (w *Window) collectSemanticDiffs(diffs *[]router.SemanticID, n router.Seman
|
|||||||
func (w *Window) updateState(d driver) {
|
func (w *Window) updateState(d driver) {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case f := <-w.driverFuncs:
|
|
||||||
f(d)
|
|
||||||
case <-w.redraws:
|
case <-w.redraws:
|
||||||
w.setNextFrame(time.Time{})
|
w.setNextFrame(time.Time{})
|
||||||
w.updateAnimation(d)
|
w.updateAnimation(d)
|
||||||
|
|||||||
Reference in New Issue
Block a user