Skip to content

Commit

Permalink
Implement dead window cleanup without niling out
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Jan 20, 2025
1 parent 2127941 commit a3409a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 35 deletions.
3 changes: 0 additions & 3 deletions internal/driver/glfw/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,6 @@ func (d *gLDriver) addWindow(w *window) {
func (d *gLDriver) focusPreviousWindow() {
var chosen *window
for _, w := range d.windows {
if w == nil {
continue
}
win := w.(*window)
if !win.visible {
continue
Expand Down
39 changes: 7 additions & 32 deletions internal/driver/glfw/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ var refreshingCanvases []fyne.Canvas

func (d *gLDriver) drawSingleFrame() {
for _, win := range d.windowList() {
if win == nil {
continue
}

w := win.(*window)
canvas := w.canvas
closing := w.closing
Expand Down Expand Up @@ -117,20 +113,15 @@ func (d *gLDriver) runGL() {
f.done <- struct{}{}
case <-eventTick.C:
d.pollEvents()
runWindowCleanup := false
for i, win := range d.windowList() {
if win == nil {
continue
}

w := win.(*window)
for i := 0; i < len(d.windows); i++ {
w := d.windows[i].(*window)
if w.viewport == nil {
continue
}

if w.viewport.ShouldClose() {
d.destroyWindow(w, i)
runWindowCleanup = true
i-- // Trailing windows are moved forward one step.
continue
}

Expand All @@ -152,10 +143,6 @@ func (d *gLDriver) runGL() {

d.animation.TickAnimations()
d.drawSingleFrame()

if runWindowCleanup {
d.removeDestroyedWindows()
}
case set := <-settingsChange:
painter.ClearFontCache()
cache.ResetThemeCaches()
Expand All @@ -174,26 +161,14 @@ func (d *gLDriver) runGL() {

func (d *gLDriver) destroyWindow(w *window, index int) {
w.visible = false

// Remove window from window list:
d.windows[index] = nil
w.viewport.Destroy()
w.destroy(d)
}

func (d *gLDriver) removeDestroyedWindows() {
// Copy items from front to back to move as few objects as possible.
for i := len(d.windows) - 1; i >= 0; i-- {
if d.windows[i] != nil {
continue
}

if i < len(d.windows)-1 {
copy(d.windows[i:], d.windows[i+1:])
}
d.windows[len(d.windows)-1] = nil
d.windows = d.windows[:len(d.windows)-1]
if index < len(d.windows)-1 {
copy(d.windows[index:], d.windows[index+1:])
}
d.windows[len(d.windows)-1] = nil
d.windows = d.windows[:len(d.windows)-1]

if len(d.windows) == 0 {
d.Quit()
Expand Down

0 comments on commit a3409a1

Please sign in to comment.