Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into cleanup-of-unnee…
Browse files Browse the repository at this point in the history
…ded-locks
  • Loading branch information
Jacalz committed Jan 11, 2025
2 parents 784c7bd + b7b8a61 commit dd5028f
Show file tree
Hide file tree
Showing 28 changed files with 149 additions and 165 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (a *fyneApp) NewWindow(title string) fyne.Window {
}

func (a *fyneApp) Run() {
go a.lifecycle.RunEventQueue(a.driver.CallFromGoroutine)
go a.lifecycle.RunEventQueue(a.driver.DoFromGoroutine)
a.driver.Run()
}

Expand Down
2 changes: 1 addition & 1 deletion app/preferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (p *preferences) resetSavedRecently() {
time.Sleep(time.Millisecond * 100) // writes are not always atomic. 10ms worked, 100 is safer.

// For test reasons we need to use current app not what we were initialised with as they can differ
fyne.CurrentApp().Driver().CallFromGoroutine(func() {
fyne.Do(func() {
p.prefLock.Lock()
p.savedRecently = false
changedDuringSaving := p.changedDuringSaving
Expand Down
2 changes: 1 addition & 1 deletion app/preferences_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ func (p *preferences) watch() {
return
}

fyne.CurrentApp().Driver().CallFromGoroutine(p.load)
fyne.Do(p.load)
})
}
2 changes: 1 addition & 1 deletion app/settings_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func watchFile(path string, callback func()) *fsnotify.Watcher {

watchFileAddTarget(watcher, path)
} else {
callback()
fyne.Do(callback)
}
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/fyne/internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ func normaliseVersion(str string) string {

if pos := strings.Index(str, "-0.20"); pos != -1 {
str = str[:pos] + "-dev"
} else if pos = strings.Index(str, "-rc"); pos != -1 {
str = str[:pos] + "-dev"
}
return version.Normalize(str)
}
1 change: 1 addition & 0 deletions cmd/fyne/internal/commands/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,5 @@ func Test_NormaliseVersion(t *testing.T) {
assert.Equal(t, "2.3.0.0", normaliseVersion("v2.3"))
assert.Equal(t, "2.4.0.0", normaliseVersion("v2.4.0"))
assert.Equal(t, "2.3.6.0-dev", normaliseVersion("v2.3.6-0.20230711180435-d4b95e1cb1eb"))
assert.Equal(t, "2.4.1.0-dev", normaliseVersion("v2.4.1-rc7.0.20230711180435-d4b95e1cb1eb"))
}
2 changes: 1 addition & 1 deletion cmd/fyne_demo/tutorials/advanced.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func advancedScreen(win fyne.Window) fyne.CanvasObject {

go func(canvas fyne.Canvas) {
for range time.NewTicker(time.Second).C {
fyne.CurrentApp().Driver().CallFromGoroutine(func() {
fyne.Do(func() {
scale.SetText(scaleToString(canvas))
tex.SetText(textureScaleToString(canvas))
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne_demo/tutorials/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func canvasScreen(_ fyne.Window) fyne.CanvasObject {
gradient := canvas.NewHorizontalGradient(color.NRGBA{0x80, 0, 0, 0xff}, color.NRGBA{0, 0x80, 0, 0xff})
go func() {
for range time.NewTicker(time.Second).C {
fyne.CurrentApp().Driver().CallFromGoroutine(func() {
fyne.Do(func() {
gradient.Angle += 45
if gradient.Angle >= 360 {
gradient.Angle -= 360
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne_demo/tutorials/welcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func welcomeScreen(_ fyne.Window) fyne.CanvasObject {
fyne.CurrentApp().Settings().AddChangeListener(listen)
go func() {
for range listen {
fyne.CurrentApp().Driver().CallFromGoroutine(func() {
fyne.Do(func() {
bgColor = withAlpha(theme.Color(theme.ColorNameBackground), 0xe0)
bg.FillColor = bgColor
bg.Refresh()
Expand Down
4 changes: 2 additions & 2 deletions cmd/fyne_demo/tutorials/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func makeActivityTab(win fyne.Window) fyne.CanvasObject {
a2.Show()

time.AfterFunc(10*time.Second, func() {
fyne.CurrentApp().Driver().CallFromGoroutine(func() {
fyne.Do(func() {
a1.Stop()
a1.Hide()
a2.Stop()
Expand Down Expand Up @@ -90,7 +90,7 @@ func makeActivityTab(win fyne.Window) fyne.CanvasObject {
d.Show()

time.AfterFunc(5*time.Second, func() {
fyne.CurrentApp().Driver().CallFromGoroutine(func() {
fyne.Do(func() {
a3.Stop()
d.Hide()
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne_demo/tutorials/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func windowScreen(_ fyne.Window) fyne.CanvasObject {
w.Show()

time.AfterFunc(3*time.Second, func() {
fyne.CurrentApp().Driver().CallFromGoroutine(w.Close)
fyne.Do(w.Close)
})
}))
}
Expand Down
2 changes: 1 addition & 1 deletion data/binding/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ func queueItem(f func()) {
return
}

fyne.CurrentApp().Driver().CallFromGoroutine(f)
fyne.Do(f)
}
143 changes: 76 additions & 67 deletions dialog/file_xdg_flatpak.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,103 +12,112 @@ import (
"github.com/rymdport/portal/filechooser"
)

func openFolder(parentWindowHandle string, callback func(fyne.ListableURI, error), options *filechooser.OpenFileOptions) {
func openFolder(parentWindowHandle string, options *filechooser.OpenFileOptions) (fyne.ListableURI, error) {
uris, err := filechooser.OpenFile(parentWindowHandle, "Open Folder", options)
if err != nil {
callback(nil, err)
return nil, err
}

if len(uris) == 0 {
callback(nil, nil)
return
return nil, nil
}

uri, err := storage.ParseURI(uris[0])
if err != nil {
callback(nil, err)
return
return nil, err
}

callback(storage.ListerForURI(uri))
return storage.ListerForURI(uri)
}

func openFile(parentWindowHandle string, callback func(fyne.URIReadCloser, error), options *filechooser.OpenFileOptions) {
func openFile(parentWindowHandle string, options *filechooser.OpenFileOptions) (fyne.URIReadCloser, error) {
uris, err := filechooser.OpenFile(parentWindowHandle, "Open File", options)
if err != nil {
callback(nil, err)
return
return nil, err
}

if len(uris) == 0 {
callback(nil, nil)
return
return nil, nil
}

uri, err := storage.ParseURI(uris[0])
if err != nil {
callback(nil, err)
return
return nil, err
}

callback(storage.Reader(uri))
return storage.Reader(uri)
}

func saveFile(parentWindowHandle string, options *filechooser.SaveFileOptions) (fyne.URIWriteCloser, error) {
uris, err := filechooser.SaveFile(parentWindowHandle, "Save File", options)
if err != nil {
return nil, err
}

if len(uris) == 0 {
return nil, nil
}

uri, err := storage.ParseURI(uris[0])
if err != nil {
return nil, err
}

return storage.Writer(uri)
}

func fileOpenOSOverride(d *FileDialog) bool {
go func() {
folderCallback, folder := d.callback.(func(fyne.ListableURI, error))
options := &filechooser.OpenFileOptions{
Directory: folder,
AcceptLabel: d.confirmText,
}
if d.startingLocation != nil {
options.CurrentFolder = d.startingLocation.Path()
}

parentWindowHandle := windowHandleForPortal(d.parent)

if folder {
openFolder(parentWindowHandle, folderCallback, options)
return
}

fileCallback := d.callback.(func(fyne.URIReadCloser, error))
openFile(parentWindowHandle, fileCallback, options)
}()
folderCallback, folder := d.callback.(func(fyne.ListableURI, error))
fileCallback, _ := d.callback.(func(fyne.URIReadCloser, error))
options := &filechooser.OpenFileOptions{
Directory: folder,
AcceptLabel: d.confirmText,
}

if d.startingLocation != nil {
options.CurrentFolder = d.startingLocation.Path()
}

windowHandle := windowHandleForPortal(d.parent)

if folder {
go func() {
folder, err := openFolder(windowHandle, options)
fyne.Do(func() {
folderCallback(folder, err)
})
}()
} else {
go func() {
file, err := openFile(windowHandle, options)
fyne.Do(func() {
fileCallback(file, err)
})
}()
}

return true
}

func fileSaveOSOverride(d *FileDialog) bool {
options := &filechooser.SaveFileOptions{
AcceptLabel: d.confirmText,
CurrentName: d.initialFileName,
}
if d.startingLocation != nil {
options.CurrentFolder = d.startingLocation.Path()
}

callback := d.callback.(func(fyne.URIWriteCloser, error))
windowHandle := windowHandleForPortal(d.parent)

go func() {
options := &filechooser.SaveFileOptions{
AcceptLabel: d.confirmText,
CurrentName: d.initialFileName,
}
if d.startingLocation != nil {
options.CurrentFolder = d.startingLocation.Path()
}

parentWindowHandle := windowHandleForPortal(d.parent)

callback := d.callback.(func(fyne.URIWriteCloser, error))
uris, err := filechooser.SaveFile(parentWindowHandle, "Open File", options)
if err != nil {
callback(nil, err)
return
}

if len(uris) == 0 {
callback(nil, nil)
return
}

uri, err := storage.ParseURI(uris[0])
if err != nil {
callback(nil, err)
return
}

callback(storage.Writer(uri))
file, err := saveFile(windowHandle, options)
fyne.Do(func() {
callback(file, err)
})
}()

return true
}

Expand All @@ -117,14 +126,14 @@ func x11WindowHandleToString(handle uintptr) string {
}

func windowHandleForPortal(window fyne.Window) string {
parentWindowHandle := ""
windowHandle := ""
if !build.IsWayland {
window.(driver.NativeWindow).RunNative(func(context any) {
handle := context.(driver.X11WindowContext).WindowHandle
parentWindowHandle = x11WindowHandleToString(handle)
windowHandle = x11WindowHandleToString(handle)
})
}

// TODO: We need to get the Wayland handle from the xdg_foreign protocol and convert to string on the form "wayland:{id}".
return parentWindowHandle
return windowHandle
}
12 changes: 9 additions & 3 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import "time"
// Driver defines an abstract concept of a Fyne render driver.
// Any implementation must provide at least these methods.
type Driver interface {
// CreateWindow creates a new UI Window.
// CreateWindow creates a new UI Window for a certain implementation.
// Developers should use [App.NewWindow].
CreateWindow(string) Window
// AllWindows returns a slice containing all app windows.
AllWindows() []Window
Expand All @@ -29,8 +30,10 @@ type Driver interface {
Quit()

// StartAnimation registers a new animation with this driver and requests it be started.
// Developers should use the [Animation.Start] function.
StartAnimation(*Animation)
// StopAnimation stops an animation and unregisters from this driver.
// Developers should use the [Animation.Stop] function.
StopAnimation(*Animation)

// DoubleTapDelay returns the maximum duration where a second tap after a first one
Expand All @@ -44,8 +47,11 @@ type Driver interface {
// Since: 2.5
SetDisableScreenBlanking(bool)

// CallFromGoroutine provides a way to queue a function that is running on a goroutine back to the main thread.
// DoFromGoroutine provides a way to queue a function that is running on a goroutine back to
// the central thread for Fyne updates.
// The driver provides the implementation normally accessed through [fyne.Do].
// This is required when background tasks want to execute code safely in the graphical context.
//
// Since: 2.6
CallFromGoroutine(func())
DoFromGoroutine(func())
}
14 changes: 9 additions & 5 deletions internal/driver/glfw/canvas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,16 +411,20 @@ func TestGlCanvas_ResizeWithOtherOverlay(t *testing.T) {
w.Canvas().Overlays().Add(over)
ensureCanvasSize(t, w, fyne.NewSize(69, 36))
// TODO: address #707; overlays should always be canvas size
over.Resize(w.Canvas().Size())
size := w.Canvas().Size()
runOnMain(func() {
over.Resize(size)
})

size := fyne.NewSize(200, 100)
size = fyne.NewSize(200, 100)
assert.NotEqual(t, size, content.Size())
assert.NotEqual(t, size, over.Size())

w.Resize(size)
ensureCanvasSize(t, w, size)
assert.Equal(t, size, content.Size(), "canvas content is resized")
assert.Equal(t, size, over.Size(), "canvas overlay is resized")
runOnMain(func() {
assert.Equal(t, size, content.Size(), "canvas content is resized")
assert.Equal(t, size, over.Size(), "canvas overlay is resized")
})
}

func TestGlCanvas_ResizeWithOverlays(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/driver/glfw/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func toOSIcon(icon []byte) ([]byte, error) {
return buf.Bytes(), nil
}

func (d *gLDriver) CallFromGoroutine(f func()) {
func (d *gLDriver) DoFromGoroutine(f func()) {
runOnMain(f)
}

Expand Down
15 changes: 6 additions & 9 deletions internal/driver/glfw/window_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ import (
var _ driver.NativeWindow = (*window)(nil)

func (w *window) RunNative(f func(any)) {
runOnMain(func() {
var nsWindow uintptr
if v := w.view(); v != nil {
nsWindow = uintptr(v.GetCocoaWindow())
}
f(driver.MacWindowContext{
NSWindow: nsWindow,
})
})
context := driver.MacWindowContext{}
if v := w.view(); v != nil {
context.NSWindow = uintptr(v.GetCocoaWindow())
}

f(context)
}
Loading

0 comments on commit dd5028f

Please sign in to comment.