app: replace uses of Window.dead with Window.destroy

There doesn't seem to be a need for a two-step shutdown sequence, so a
single channel is enough to trigger destruction of the Window.

References: https://todo.sr.ht/~eliasnaur/gio/497
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2023-05-11 16:06:40 -06:00
parent febadd3145
commit 8571b25ff7
+7 -11
View File
@@ -63,8 +63,6 @@ type Window struct {
frames chan *op.Ops frames chan *op.Ops
frameAck chan struct{} frameAck chan struct{}
destroy chan struct{} destroy chan struct{}
// dead is closed when the window is destroyed.
dead chan struct{}
stage system.Stage stage system.Stage
animating bool animating bool
@@ -172,7 +170,6 @@ func NewWindow(options ...Option) *Window {
wakeups: make(chan struct{}, 1), wakeups: make(chan struct{}, 1),
wakeupFuncs: make(chan func()), wakeupFuncs: make(chan func()),
destroy: make(chan struct{}), destroy: make(chan struct{}),
dead: make(chan struct{}),
options: make(chan []Option, 1), options: make(chan []Option, 1),
actions: make(chan system.Action, 1), actions: make(chan system.Action, 1),
nocontext: cnf.CustomRenderer, nocontext: cnf.CustomRenderer,
@@ -410,7 +407,7 @@ func (w *Window) Run(f func()) {
}) })
select { select {
case <-done: case <-done:
case <-w.dead: case <-w.destroy:
} }
} }
@@ -420,7 +417,7 @@ func (w *Window) driverDefer(f func(d driver)) {
select { select {
case w.driverFuncs <- f: case w.driverFuncs <- f:
w.wakeup() w.wakeup()
case <-w.dead: case <-w.destroy:
} }
} }
@@ -485,7 +482,7 @@ func (c *callbacks) Event(e event.Event) bool {
} }
c.busy = false c.busy = false
select { select {
case <-c.w.dead: case <-c.w.destroy:
return handled return handled
default: default:
} }
@@ -818,7 +815,7 @@ func (w *Window) updateState(d driver) {
func (w *Window) processEvent(d driver, e event.Event) bool { func (w *Window) processEvent(d driver, e event.Event) bool {
select { select {
case <-w.dead: case <-w.destroy:
return false return false
default: default:
} }
@@ -890,7 +887,7 @@ func (w *Window) processEvent(d driver, e event.Event) bool {
w.destroyGPU() w.destroyGPU()
w.out <- system.DestroyEvent{Err: err} w.out <- system.DestroyEvent{Err: err}
close(w.out) close(w.out)
w.destroy <- struct{}{} close(w.destroy)
break break
} }
w.processFrame(d, frameStart) w.processFrame(d, frameStart)
@@ -899,7 +896,7 @@ func (w *Window) processEvent(d driver, e event.Event) bool {
w.destroyGPU() w.destroyGPU()
w.out <- e2 w.out <- e2
close(w.out) close(w.out)
w.destroy <- struct{}{} close(w.destroy)
case ViewEvent: case ViewEvent:
w.out <- e2 w.out <- e2
w.waitAck(d) w.waitAck(d)
@@ -950,7 +947,7 @@ func (w *Window) run(options []Option) {
if err := newWindow(&w.callbacks, options); err != nil { if err := newWindow(&w.callbacks, options); err != nil {
w.out <- system.DestroyEvent{Err: err} w.out <- system.DestroyEvent{Err: err}
close(w.out) close(w.out)
w.destroy <- struct{}{} close(w.destroy)
return return
} }
var wakeup func() var wakeup func()
@@ -973,7 +970,6 @@ func (w *Window) run(options []Option) {
} }
timer = time.NewTimer(time.Until(t)) timer = time.NewTimer(time.Until(t))
case <-w.destroy: case <-w.destroy:
close(w.dead)
return return
case <-timeC: case <-timeC:
select { select {