mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 17:35:36 +00:00
app: deliver one event at a time to client
If the client calls, say, Window.Configure during a frame which in turn results in a ConfigEvent, the program deadlocks. This change implements a queue of events to be delivered after processing another. Fixes: https://todo.sr.ht/~eliasnaur/gio/337 Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+23
-3
@@ -46,9 +46,11 @@ type Window struct {
|
|||||||
// scheduledRedraws is sent the most recent delayed redraw time.
|
// scheduledRedraws is sent the most recent delayed redraw time.
|
||||||
scheduledRedraws chan time.Time
|
scheduledRedraws chan time.Time
|
||||||
|
|
||||||
out chan event.Event
|
waiting bool
|
||||||
frames chan *op.Ops
|
waitEvents []event.Event
|
||||||
frameAck chan struct{}
|
out chan event.Event
|
||||||
|
frames chan *op.Ops
|
||||||
|
frameAck chan struct{}
|
||||||
// dead is closed when the window is destroyed.
|
// dead is closed when the window is destroyed.
|
||||||
dead chan struct{}
|
dead chan struct{}
|
||||||
|
|
||||||
@@ -416,7 +418,17 @@ 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")
|
||||||
}
|
}
|
||||||
|
if c.w.waiting {
|
||||||
|
c.w.waitEvents = append(c.w.waitEvents, e)
|
||||||
|
return
|
||||||
|
}
|
||||||
c.w.processEvent(c.d, e)
|
c.w.processEvent(c.d, e)
|
||||||
|
for len(c.w.waitEvents) > 0 {
|
||||||
|
we := c.w.waitEvents[0]
|
||||||
|
copy(c.w.waitEvents, c.w.waitEvents[1:])
|
||||||
|
c.w.waitEvents = c.w.waitEvents[:len(c.w.waitEvents)-1]
|
||||||
|
c.w.processEvent(c.d, we)
|
||||||
|
}
|
||||||
c.w.updateState(c.d)
|
c.w.updateState(c.d)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -447,6 +459,10 @@ func (c *callbacks) SemanticAt(pos f32.Point) (router.SemanticID, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) waitAck(d driver) {
|
func (w *Window) waitAck(d driver) {
|
||||||
|
w.waiting = true
|
||||||
|
defer func() {
|
||||||
|
w.waiting = false
|
||||||
|
}()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case f := <-w.driverFuncs:
|
case f := <-w.driverFuncs:
|
||||||
@@ -478,6 +494,10 @@ func (w *Window) destroyGPU() {
|
|||||||
// or to continue event handling. It returns whether the client
|
// or to continue event handling. It returns whether the client
|
||||||
// called Frame or not.
|
// called Frame or not.
|
||||||
func (w *Window) waitFrame(d driver) (*op.Ops, bool) {
|
func (w *Window) waitFrame(d driver) (*op.Ops, bool) {
|
||||||
|
w.waiting = true
|
||||||
|
defer func() {
|
||||||
|
w.waiting = false
|
||||||
|
}()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case f := <-w.driverFuncs:
|
case f := <-w.driverFuncs:
|
||||||
|
|||||||
Reference in New Issue
Block a user