From 4d635d88b91ceaff8ac6a933a19a422fc11f8f49 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Mon, 22 Jul 2024 19:04:59 -0700 Subject: [PATCH] save peak meter window size --- backend/config.go | 10 ++++++++++ ui/controller/visualizations.go | 9 +++++++++ ui/mainwindow.go | 9 ++++----- ui/util/util.go | 7 +++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/backend/config.go b/backend/config.go index 1cf2d143..cb364810 100644 --- a/backend/config.go +++ b/backend/config.go @@ -124,6 +124,11 @@ type TranscodingConfig struct { ForceRawFile bool } +type PeakMeterConfig struct { + WindowHeight int + WindowWidth int +} + type Config struct { Application AppConfig Servers []*ServerConfig @@ -141,6 +146,7 @@ type Config struct { ReplayGain ReplayGainConfig Transcoding TranscodingConfig Theme ThemeConfig + PeakMeter PeakMeterConfig } var SupportedStartupPages = []string{"Albums", "Favorites", "Playlists"} @@ -221,6 +227,10 @@ func DefaultConfig(appVersionTag string) *Config { Theme: ThemeConfig{ Appearance: "Dark", }, + PeakMeter: PeakMeterConfig{ + WindowWidth: 375, + WindowHeight: 100, + }, } } diff --git a/ui/controller/visualizations.go b/ui/controller/visualizations.go index 3ff12d66..15b09016 100644 --- a/ui/controller/visualizations.go +++ b/ui/controller/visualizations.go @@ -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" ) @@ -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() diff --git a/ui/mainwindow.go b/ui/mainwindow.go index 9b1fbefb..6c48f6d5 100644 --- a/ui/mainwindow.go +++ b/ui/mainwindow.go @@ -3,7 +3,6 @@ package ui import ( "fmt" "log" - "math" "runtime" "strings" "time" @@ -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" @@ -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) } diff --git a/ui/util/util.go b/ui/util/util.go index b4792881..3dad8bfb 100644 --- a/ui/util/util.go +++ b/ui/util/util.go @@ -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