Skip to content

Commit

Permalink
only use X11 resize hack when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Jun 23, 2024
1 parent a36be97 commit 361ec68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
18 changes: 15 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

}()
Expand All @@ -82,3 +87,10 @@ func main() {
log.Println("Running shutdown tasks...")
myApp.Shutdown()
}

func inDelta(a, b fyne.Size, delta float32) bool {

Check failure on line 91 in main.go

View workflow job for this annotation

GitHub Actions / build

undefined: fyne

Check failure on line 91 in main.go

View workflow job for this annotation

GitHub Actions / build

undefined: fyne

Check failure on line 91 in main.go

View workflow job for this annotation

GitHub Actions / build

undefined: fyne

Check failure on line 91 in main.go

View workflow job for this annotation

GitHub Actions / build

undefined: fyne
diffW := a.Width - b.Width
diffH := a.Height - b.Height
return diffW < delta && diffW > -delta &&
diffH < delta && diffH > -delta
}
11 changes: 5 additions & 6 deletions ui/mainwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 361ec68

Please sign in to comment.