Skip to content

Commit

Permalink
Removing windowlock as well
Browse files Browse the repository at this point in the history
But make sure our unit tests still use correct context
  • Loading branch information
andydotxyz committed Dec 17, 2024
1 parent 3261a07 commit 70f9cf8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 17 deletions.
12 changes: 1 addition & 11 deletions internal/driver/glfw/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"image"
"os"
"runtime"
"sync"

"github.com/fyne-io/image/ico"

Expand All @@ -33,7 +32,6 @@ var curWindow *window
var _ fyne.Driver = (*gLDriver)(nil)

type gLDriver struct {
windowLock sync.RWMutex
windows []fyne.Window
done chan struct{}
waitForStart chan struct{}
Expand Down Expand Up @@ -104,21 +102,15 @@ func (d *gLDriver) Quit() {
}

func (d *gLDriver) addWindow(w *window) {
d.windowLock.Lock()
defer d.windowLock.Unlock()
d.windows = append(d.windows, w)
}

// a trivial implementation of "focus previous" - return to the most recently opened, or master if set.
// This may not do the right thing if your app has 3 or more windows open, but it was agreed this was not much
// of an issue, and the added complexity to track focus was not needed at this time.
func (d *gLDriver) focusPreviousWindow() {
d.windowLock.RLock()
wins := d.windows
d.windowLock.RUnlock()

var chosen *window
for _, w := range wins {
for _, w := range d.windows {
win := w.(*window)
if !win.visible {
continue
Expand All @@ -136,8 +128,6 @@ func (d *gLDriver) focusPreviousWindow() {
}

func (d *gLDriver) windowList() []fyne.Window {
d.windowLock.RLock()
defer d.windowLock.RUnlock()
return d.windows
}

Expand Down
2 changes: 0 additions & 2 deletions internal/driver/glfw/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ func (d *gLDriver) runGL() {
newWindows = append(newWindows, win)
}

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

if len(newWindows) == 0 {
d.Quit()
Expand Down
2 changes: 0 additions & 2 deletions internal/driver/glfw/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,6 @@ func (d *gLDriver) CreateWindow(title string) fyne.Window {

// handling multiple windows by overlaying on the root for web
var root fyne.Window
d.windowLock.RLock()
hasVisible := false
for _, w := range d.windows {
if w.(*window).visible {
Expand All @@ -884,7 +883,6 @@ func (d *gLDriver) CreateWindow(title string) fyne.Window {
break
}
}
d.windowLock.RUnlock()

if !hasVisible {
return d.createWindow(title, true)
Expand Down
7 changes: 5 additions & 2 deletions internal/driver/glfw/window_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1678,8 +1678,11 @@ func TestWindow_SetFullScreen(t *testing.T) {
// }

func createWindow(title string) fyne.Window {
w := d.CreateWindow(title)
w.(*window).create()
var w fyne.Window
runOnMain(func() {
w = d.CreateWindow(title)
w.(*window).create()
})
return w
}

Expand Down

0 comments on commit 70f9cf8

Please sign in to comment.