mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
ui/app: don't draw or handle events if window is dead
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+11
-9
@@ -36,6 +36,7 @@ type Window struct {
|
|||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
stage Stage
|
stage Stage
|
||||||
|
dead bool
|
||||||
size image.Point
|
size image.Point
|
||||||
syncGPU bool
|
syncGPU bool
|
||||||
animating bool
|
animating bool
|
||||||
@@ -121,11 +122,11 @@ func (w *Window) Draw(root *ui.Ops) {
|
|||||||
stage := w.stage
|
stage := w.stage
|
||||||
sync := w.syncGPU
|
sync := w.syncGPU
|
||||||
w.syncGPU = false
|
w.syncGPU = false
|
||||||
alive := w.isAlive()
|
dead := w.dead
|
||||||
size := w.size
|
size := w.size
|
||||||
driver := w.driver
|
driver := w.driver
|
||||||
w.mu.Unlock()
|
w.mu.Unlock()
|
||||||
if !alive || stage < StageRunning || driver == nil {
|
if dead || stage < StageRunning || driver == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if w.gpu != nil {
|
if w.gpu != nil {
|
||||||
@@ -173,7 +174,7 @@ func (w *Window) Draw(root *ui.Ops) {
|
|||||||
func (w *Window) Redraw() {
|
func (w *Window) Redraw() {
|
||||||
w.mu.Lock()
|
w.mu.Lock()
|
||||||
defer w.mu.Unlock()
|
defer w.mu.Unlock()
|
||||||
if !w.isAlive() {
|
if w.dead {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.setNextFrame(time.Time{})
|
w.setNextFrame(time.Time{})
|
||||||
@@ -186,7 +187,7 @@ func (w *Window) updateAnimation() {
|
|||||||
w.delayedDraw.Stop()
|
w.delayedDraw.Stop()
|
||||||
w.delayedDraw = nil
|
w.delayedDraw = nil
|
||||||
}
|
}
|
||||||
if !w.isAlive() {
|
if w.dead {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if w.stage >= StageRunning && w.hasNextFrame {
|
if w.stage >= StageRunning && w.hasNextFrame {
|
||||||
@@ -215,10 +216,6 @@ func (w *Window) Stage() Stage {
|
|||||||
return w.stage
|
return w.stage
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Window) isAlive() bool {
|
|
||||||
return w.driver != nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Window) contextDriver() interface{} {
|
func (w *Window) contextDriver() interface{} {
|
||||||
return w.driver
|
return w.driver
|
||||||
}
|
}
|
||||||
@@ -240,8 +237,9 @@ func (w *Window) event(e Event) {
|
|||||||
w.eventLock.Lock()
|
w.eventLock.Lock()
|
||||||
defer w.eventLock.Unlock()
|
defer w.eventLock.Unlock()
|
||||||
w.mu.Lock()
|
w.mu.Lock()
|
||||||
died := false
|
|
||||||
needAck := false
|
needAck := false
|
||||||
|
dead := w.dead
|
||||||
|
died := false
|
||||||
switch e := e.(type) {
|
switch e := e.(type) {
|
||||||
case input.Event:
|
case input.Event:
|
||||||
if w.router.Add(e) {
|
if w.router.Add(e) {
|
||||||
@@ -251,6 +249,7 @@ func (w *Window) event(e Event) {
|
|||||||
needAck = true
|
needAck = true
|
||||||
case DestroyEvent:
|
case DestroyEvent:
|
||||||
w.driver = nil
|
w.driver = nil
|
||||||
|
w.dead = true
|
||||||
died = true
|
died = true
|
||||||
case StageEvent:
|
case StageEvent:
|
||||||
w.stage = e.Stage
|
w.stage = e.Stage
|
||||||
@@ -273,6 +272,9 @@ func (w *Window) event(e Event) {
|
|||||||
stage := w.stage
|
stage := w.stage
|
||||||
w.updateAnimation()
|
w.updateAnimation()
|
||||||
w.mu.Unlock()
|
w.mu.Unlock()
|
||||||
|
if dead {
|
||||||
|
return
|
||||||
|
}
|
||||||
w.events <- e
|
w.events <- e
|
||||||
if needAck {
|
if needAck {
|
||||||
// Send a dummy event; when it gets through we
|
// Send a dummy event; when it gets through we
|
||||||
|
|||||||
Reference in New Issue
Block a user