From 361ec68d59c95128595057fdcc8ca32693274f4d Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sun, 23 Jun 2024 14:10:09 -0700 Subject: [PATCH] only use X11 resize hack when needed --- main.go | 18 +++++++++++++++--- ui/mainwindow.go | 11 +++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index a035402f..eaedb0c3 100644 --- a/main.go +++ b/main.go @@ -60,9 +60,14 @@ func main() { // hacky workaround for https://github.com/fyne-io/fyne/issues/4964 if runtime.GOOS == "linux" { time.Sleep(350 * time.Millisecond) - w, h := mainWindow.DesiredSize() - scale := mainWindow.Window.Canvas().Scale() - SendResizeToPID(os.Getpid(), int(w*scale), int(h*scale)) + canvas := mainWindow.Window.Canvas() + size := canvas.Size() + desired := mainWindow.DesiredSize() + if !inDelta(size, desired, 1) { + // window drawn at incorrect size on startup + scale := canvas.Scale() + SendResizeToPID(os.Getpid(), int(desired.Width*scale), int(desired.Height*scale)) + } } }() @@ -82,3 +87,10 @@ func main() { log.Println("Running shutdown tasks...") myApp.Shutdown() } + +func inDelta(a, b fyne.Size, delta float32) bool { + diffW := a.Width - b.Width + diffH := a.Height - b.Height + return diffW < delta && diffW > -delta && + diffH < delta && diffH > -delta +} diff --git a/ui/mainwindow.go b/ui/mainwindow.go index 81cd04af..5e5229b8 100644 --- a/ui/mainwindow.go +++ b/ui/mainwindow.go @@ -141,21 +141,20 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string, return m } -func (m *MainWindow) DesiredSize() (w, h float32) { - w = float32(m.App.Config.Application.WindowWidth) +func (m *MainWindow) DesiredSize() fyne.Size { + w := float32(m.App.Config.Application.WindowWidth) if w <= 1 { w = 1000 } - h = float32(m.App.Config.Application.WindowHeight) + h := float32(m.App.Config.Application.WindowHeight) if h <= 1 { h = 800 } - return w, h + return fyne.NewSize(w, h) } func (m *MainWindow) setInitialSize() { - w, h := m.DesiredSize() - m.Window.Resize(fyne.NewSize(w, h)) + m.Window.Resize(m.DesiredSize()) } func (m *MainWindow) StartupPage() controller.Route {