only use X11 resize hack when needed

This commit is contained in:
Drew Weymouth
2024-06-23 14:10:09 -07:00
parent a36be97830
commit 361ec68d59
2 changed files with 20 additions and 9 deletions
+15 -3
View File
@@ -60,9 +60,14 @@ func main() {
// hacky workaround for https://github.com/fyne-io/fyne/issues/4964 // hacky workaround for https://github.com/fyne-io/fyne/issues/4964
if runtime.GOOS == "linux" { if runtime.GOOS == "linux" {
time.Sleep(350 * time.Millisecond) time.Sleep(350 * time.Millisecond)
w, h := mainWindow.DesiredSize() canvas := mainWindow.Window.Canvas()
scale := mainWindow.Window.Canvas().Scale() size := canvas.Size()
SendResizeToPID(os.Getpid(), int(w*scale), int(h*scale)) 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...") log.Println("Running shutdown tasks...")
myApp.Shutdown() 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
}
+5 -6
View File
@@ -141,21 +141,20 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string,
return m return m
} }
func (m *MainWindow) DesiredSize() (w, h float32) { func (m *MainWindow) DesiredSize() fyne.Size {
w = float32(m.App.Config.Application.WindowWidth) w := float32(m.App.Config.Application.WindowWidth)
if w <= 1 { if w <= 1 {
w = 1000 w = 1000
} }
h = float32(m.App.Config.Application.WindowHeight) h := float32(m.App.Config.Application.WindowHeight)
if h <= 1 { if h <= 1 {
h = 800 h = 800
} }
return w, h return fyne.NewSize(w, h)
} }
func (m *MainWindow) setInitialSize() { func (m *MainWindow) setInitialSize() {
w, h := m.DesiredSize() m.Window.Resize(m.DesiredSize())
m.Window.Resize(fyne.NewSize(w, h))
} }
func (m *MainWindow) StartupPage() controller.Route { func (m *MainWindow) StartupPage() controller.Route {