Skip to content

Commit

Permalink
Merge pull request #460 from dweymouth/resize-hack-rework
Browse files Browse the repository at this point in the history
Linux window misdrawing workaround, redux
  • Loading branch information
dweymouth authored Aug 8, 2024
2 parents fba9b0f + ca90bf5 commit 58eb35e
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 127 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace fyne.io/fyne/v2 v2.5.0 => github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240805144743-24df77c3cc7e
replace fyne.io/fyne/v2 v2.5.0 => github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240807180232-d2b0dad0b17d
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ github.com/dweymouth/fyne-lyrics v0.0.0-20240528234907-15eee7ce5e64 h1:RUIrnGY03
github.com/dweymouth/fyne-lyrics v0.0.0-20240528234907-15eee7ce5e64/go.mod h1:3YrjFDHMlhCsSZ/OvmJCxWm9QHSgOVWZBxnraZz9Z7c=
github.com/dweymouth/fyne-tooltip v0.2.0 h1:6Zy3gryctuPoQfYf8Xp3tjenioebMt11NBGW/QXIvxE=
github.com/dweymouth/fyne-tooltip v0.2.0/go.mod h1:zEgy7p9tSVIuy2GufFbOCoK3Q04zhyDPOotlU4G3Ma4=
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240805144743-24df77c3cc7e h1:FSTLNY9xV0+4/x9jKPXqUpwPZfhkAMz5ZnzLBkRirMw=
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240805144743-24df77c3cc7e/go.mod h1:9D4oT3NWeG+MLi/lP7ItZZyujHC/qqMJpoGTAYX5Uqc=
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240807180232-d2b0dad0b17d h1:A8HSVm7wn1aEMdT/8YPtuP5XGwasqZ5kxcdBhIfxXvU=
github.com/dweymouth/fyne/v2 v2.3.0-rc1.0.20240807180232-d2b0dad0b17d/go.mod h1:9D4oT3NWeG+MLi/lP7ItZZyujHC/qqMJpoGTAYX5Uqc=
github.com/dweymouth/go-jellyfin v0.0.0-20240517151952-5ceca61cb645 h1:KzqSaQwG3HsTZQlEtkp0BeUy9vmYZ0rq0B15qIPSiBs=
github.com/dweymouth/go-jellyfin v0.0.0-20240517151952-5ceca61cb645/go.mod h1:fcUagHBaQnt06GmBAllNE0J4O/7064zXRWdqnTTtVjI=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down
43 changes: 13 additions & 30 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"log"
"os"
"runtime"
"sync"
"time"

"github.com/dweymouth/supersonic/backend"
Expand Down Expand Up @@ -59,39 +59,22 @@ func main() {
} else {
mainWindow.Controller.DoConnectToServerWorkflow(defaultServer)
}
}()

// hacky workaround for https://github.com/fyne-io/fyne/issues/4964
if runtime.GOOS == "linux" {
time.Sleep(350 * time.Millisecond)
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()
for i := 0; i < 3 && !inDelta(size, desired, 1); i++ {
if i > 0 {
// if resize didn't work the first time, try again with slightly
// different desired size
desired.Subtract(fyne.NewSize(2, 2))
}
SendResizeToPID(os.Getpid(), int(desired.Width*scale), int(desired.Height*scale))
time.Sleep(100 * time.Millisecond)
size = canvas.Size()
}
}
}
// slightly hacky workaround for https://github.com/fyne-io/fyne/issues/4964
workaroundWindowSize := sync.OnceFunc(func() {
time.Sleep(50 * time.Millisecond)
s := mainWindow.DesiredSize()
mainWindow.Window.Resize(s.Subtract(fyne.NewSize(4, 0)))
time.Sleep(50 * time.Millisecond)
mainWindow.Window.Resize(s) // back to desired size
})
fyneApp.Lifecycle().SetOnEnteredForeground(func() {
workaroundWindowSize()
})

}()
mainWindow.ShowAndRun()

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
}
6 changes: 3 additions & 3 deletions ui/mainwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string,
}

m.BottomPanel = NewBottomPanel(app.PlaybackManager, app.ImageManager, m.Controller)
m.container = container.NewBorder(nil, m.BottomPanel, nil, nil, m.BrowsingPane)
m.Window.SetContent(fynetooltip.AddWindowToolTipLayer(m.container, m.Window.Canvas()))
m.setInitialSize()
app.PlaybackManager.OnSongChange(func(item mediaprovider.MediaItem, _ *mediaprovider.Track) {
if item == nil {
m.Window.SetTitle(displayAppName)
Expand Down Expand Up @@ -138,6 +135,9 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string,
m.BrowsingPane.DisableNavigationButtons()
m.addShortcuts()

m.container = container.NewBorder(nil, m.BottomPanel, nil, nil, m.BrowsingPane)
m.Window.SetContent(fynetooltip.AddWindowToolTipLayer(m.container, m.Window.Canvas()))
m.setInitialSize()
m.Window.SetCloseIntercept(func() {
m.SaveWindowSize()
if app.Config.Application.CloseToSystemTray && m.HaveSystemTray() {
Expand Down
68 changes: 0 additions & 68 deletions xresize.c

This file was deleted.

3 changes: 0 additions & 3 deletions xresize.h

This file was deleted.

5 changes: 0 additions & 5 deletions xresize_other.go

This file was deleted.

15 changes: 0 additions & 15 deletions xresize_x11.go

This file was deleted.

0 comments on commit 58eb35e

Please sign in to comment.