Skip to content

Commit

Permalink
save peak meter window size
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Jul 23, 2024
1 parent 9d0b381 commit 4d635d8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
10 changes: 10 additions & 0 deletions backend/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ type TranscodingConfig struct {
ForceRawFile bool
}

type PeakMeterConfig struct {
WindowHeight int
WindowWidth int
}

type Config struct {
Application AppConfig
Servers []*ServerConfig
Expand All @@ -141,6 +146,7 @@ type Config struct {
ReplayGain ReplayGainConfig
Transcoding TranscodingConfig
Theme ThemeConfig
PeakMeter PeakMeterConfig
}

var SupportedStartupPages = []string{"Albums", "Favorites", "Playlists"}
Expand Down Expand Up @@ -221,6 +227,10 @@ func DefaultConfig(appVersionTag string) *Config {
Theme: ThemeConfig{
Appearance: "Dark",
},
PeakMeter: PeakMeterConfig{
WindowWidth: 375,
WindowHeight: 100,
},
}
}

Expand Down
9 changes: 9 additions & 0 deletions ui/controller/visualizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/lang"
"github.com/dweymouth/supersonic/ui/util"
"github.com/dweymouth/supersonic/ui/visualizations"
)

Expand Down Expand Up @@ -35,7 +36,15 @@ func (c *Controller) ShowPeakMeter() {
c.stopVisualizationAnim()
c.peakMeter = nil
win.Close()
util.SaveWindowSize(win,
&c.App.Config.PeakMeter.WindowWidth,
&c.App.Config.PeakMeter.WindowHeight)
})
if c.App.Config.PeakMeter.WindowHeight > 0 {
win.Resize(fyne.NewSize(
float32(c.App.Config.PeakMeter.WindowWidth),
float32(c.App.Config.PeakMeter.WindowHeight)))
}
c.peakMeter = visualizations.NewPeakMeter()
win.SetContent(c.peakMeter)
c.startVisualizationAnim()
Expand Down
9 changes: 4 additions & 5 deletions ui/mainwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package ui
import (
"fmt"
"log"
"math"
"runtime"
"strings"
"time"
Expand All @@ -16,6 +15,7 @@ import (
"github.com/dweymouth/supersonic/ui/dialogs"
"github.com/dweymouth/supersonic/ui/os"
"github.com/dweymouth/supersonic/ui/theme"
"github.com/dweymouth/supersonic/ui/util"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
Expand Down Expand Up @@ -432,8 +432,7 @@ func (m *MainWindow) Quit() {
}

func (m *MainWindow) SaveWindowSize() {
// round sizes to even to avoid Wayland issues with 2x scaling factor
// https://github.com/dweymouth/supersonic/issues/212
m.App.Config.Application.WindowHeight = int(math.RoundToEven(float64(m.Window.Canvas().Size().Height)))
m.App.Config.Application.WindowWidth = int(math.RoundToEven(float64(m.Window.Canvas().Size().Width)))
util.SaveWindowSize(m.Window,
&m.App.Config.Application.WindowWidth,
&m.App.Config.Application.WindowHeight)
}
7 changes: 7 additions & 0 deletions ui/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,13 @@ func NewTrailingAlignLabel() *widget.Label {
return rt
}

func SaveWindowSize(w fyne.Window, wPtr, hPtr *int) {
// round sizes to even to avoid Wayland issues with 2x scaling factor
// https://github.com/dweymouth/supersonic/issues/212
*wPtr = int(math.RoundToEven(float64(w.Canvas().Size().Width)))
*hPtr = int(math.RoundToEven(float64(w.Canvas().Size().Height)))
}

type HSpace struct {
widget.BaseWidget

Expand Down

0 comments on commit 4d635d8

Please sign in to comment.