Skip to content

Commit

Permalink
Pull unreleased run loop optimization from fyne-io/pull/4184
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Nov 3, 2023
1 parent 8725463 commit b6f79d3
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions internal/driver/glfw/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,15 @@ func (d *gLDriver) runGL() {
//case <-eventTick.C:
default:
d.tryWaitEventsTimeout(0.08333)
newWindows := []fyne.Window{}
reassign := false
windowsToRemove := 0
for _, win := range d.windowList() {
w := win.(*window)
if w.viewport == nil {
continue
}

if w.viewport.ShouldClose() {
reassign = true
windowsToRemove++
w.viewLock.Lock()
w.visible = false
v := w.viewport
Expand Down Expand Up @@ -165,13 +164,35 @@ func (d *gLDriver) runGL() {
}
}

newWindows = append(newWindows, win)

if drawOnMainThread {
d.drawSingleFrame()
}
}
if reassign {
if windowsToRemove > 0 {
oldWindows := d.windowList()
newWindows := make([]fyne.Window, 0, len(oldWindows)-windowsToRemove)

for _, win := range oldWindows {
w := win.(*window)
if w.viewport == nil {
continue
}

if w.viewport.ShouldClose() {
w.viewLock.Lock()
w.visible = false
v := w.viewport
w.viewLock.Unlock()

// remove window from window list
v.Destroy()
w.destroy(d)
continue
}

newWindows = append(newWindows, win)
}

d.windowLock.Lock()
d.windows = newWindows
d.windowLock.Unlock()
Expand Down

0 comments on commit b6f79d3

Please sign in to comment.