app: ensure deferred functions are run outside of FrameEvents

Simplify callbacks.Event a bit while here.

Fixes: https://todo.sr.ht/~eliasnaur/gio/348
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-01-27 12:13:20 +01:00
parent 6294390df2
commit 1bad440ef6
+6 -2
View File
@@ -398,19 +398,23 @@ func (c *callbacks) Event(e event.Event) {
if c.d == nil { if c.d == nil {
panic("event while no driver active") panic("event while no driver active")
} }
c.waitEvents = append(c.waitEvents, e)
if c.busy { if c.busy {
c.waitEvents = append(c.waitEvents, e)
return return
} }
c.busy = true c.busy = true
defer func() { defer func() {
c.busy = false c.busy = false
}() }()
c.w.processEvent(c.d, e)
for _, e := range c.waitEvents { for _, e := range c.waitEvents {
c.w.processEvent(c.d, e) c.w.processEvent(c.d, e)
} }
c.waitEvents = c.waitEvents[:0] c.waitEvents = c.waitEvents[:0]
select {
case f := <-c.w.driverFuncs:
c.w.defers = append(c.w.defers, f)
default:
}
for _, f := range c.w.defers { for _, f := range c.w.defers {
f(c.d) f(c.d)
} }