From 0ab2a60635f883faba5108f39dd33ba4a2874cf0 Mon Sep 17 00:00:00 2001 From: Jacob Date: Thu, 23 Nov 2023 19:39:02 +0100 Subject: [PATCH 1/2] Remove old clipboard workarounds after changes in GLFW See https://github.com/fyne-io/fyne/pull/1136. The clipboard no longer crashes when pasting empy content (also verified locally). The clipboard also no longer require access to the window struct. Clean up the code. As the clipboard no longer needs the viewport, we can also remove a possible crash when getting a clipboard from a window that has yet to be set up. --- internal/driver/glfw/clipboard.go | 10 +--------- internal/driver/glfw/window.go | 9 +-------- internal/driver/glfw/window_desktop.go | 2 -- 3 files changed, 2 insertions(+), 19 deletions(-) diff --git a/internal/driver/glfw/clipboard.go b/internal/driver/glfw/clipboard.go index a0bd540135..41fb2edd07 100644 --- a/internal/driver/glfw/clipboard.go +++ b/internal/driver/glfw/clipboard.go @@ -16,9 +16,7 @@ import ( var _ fyne.Clipboard = (*clipboard)(nil) // clipboard represents the system clipboard -type clipboard struct { - window *glfw.Window -} +type clipboard struct{} // Content returns the clipboard content func (c *clipboard) Content() string { @@ -64,12 +62,6 @@ func (c *clipboard) SetContent(content string) { func (c *clipboard) setContent(content string) { runOnMain(func() { - defer func() { - if r := recover(); r != nil { - fyne.LogError("GLFW clipboard error (details above)", nil) - } - }() - glfw.SetClipboardString(content) }) } diff --git a/internal/driver/glfw/window.go b/internal/driver/glfw/window.go index 971fc486d0..c0f1dd21d3 100644 --- a/internal/driver/glfw/window.go +++ b/internal/driver/glfw/window.go @@ -229,14 +229,7 @@ func (w *window) ShowAndRun() { // Clipboard returns the system clipboard func (w *window) Clipboard() fyne.Clipboard { - if w.view() == nil { - return nil - } - - if w.clipboard == nil { - w.clipboard = &clipboard{window: w.viewport} - } - return w.clipboard + return &clipboard{} } func (w *window) Content() fyne.CanvasObject { diff --git a/internal/driver/glfw/window_desktop.go b/internal/driver/glfw/window_desktop.go index d04fccd421..48515ed858 100644 --- a/internal/driver/glfw/window_desktop.go +++ b/internal/driver/glfw/window_desktop.go @@ -77,8 +77,6 @@ type window struct { icon fyne.Resource mainmenu *fyne.MainMenu - clipboard fyne.Clipboard - master bool fullScreen bool centered bool From 529a3d6bf6dc83a2cd4d602abfee7aa002cf0799 Mon Sep 17 00:00:00 2001 From: Jacob Date: Thu, 23 Nov 2023 19:39:22 +0100 Subject: [PATCH 2/2] Add comments to GLFW workarounds still needed --- internal/driver/glfw/loop_desktop.go | 1 + internal/driver/glfw/loop_goxjs.go | 1 + 2 files changed, 2 insertions(+) diff --git a/internal/driver/glfw/loop_desktop.go b/internal/driver/glfw/loop_desktop.go index 652e6cf023..988cbd5bf5 100644 --- a/internal/driver/glfw/loop_desktop.go +++ b/internal/driver/glfw/loop_desktop.go @@ -26,6 +26,7 @@ func (d *gLDriver) initGLFW() { func (d *gLDriver) tryPollEvents() { defer func() { + // See https://github.com/glfw/glfw/issues/1785 and https://github.com/fyne-io/fyne/issues/1024. if r := recover(); r != nil { fyne.LogError(fmt.Sprint("GLFW poll event error: ", r), nil) } diff --git a/internal/driver/glfw/loop_goxjs.go b/internal/driver/glfw/loop_goxjs.go index e5082800ac..baa46fac3c 100644 --- a/internal/driver/glfw/loop_goxjs.go +++ b/internal/driver/glfw/loop_goxjs.go @@ -26,6 +26,7 @@ func (d *gLDriver) initGLFW() { func (d *gLDriver) tryPollEvents() { defer func() { + // See https://github.com/glfw/glfw/issues/1785 and https://github.com/fyne-io/fyne/issues/1024. if r := recover(); r != nil { fyne.LogError(fmt.Sprint("GLFW poll event error: ", r), nil) }