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
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
}
+5 -6
View File
@@ -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 {