From 35e2fc8e1fe502fbc57741eef0ca44e7c97c5a00 Mon Sep 17 00:00:00 2001 From: mircearoata Date: Tue, 6 Feb 2024 20:13:11 +0100 Subject: [PATCH] Fix saved absolute position being loaded as relative to current monitor --- main.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 3f8d536d..54b6439e 100644 --- a/main.go +++ b/main.go @@ -96,11 +96,7 @@ func main() { appCommon.AppContext = ctx // Wails doesn't support setting the window position on init, so we do it here - if settings.Settings.WindowPosition != nil { - wailsRuntime.WindowSetPosition(ctx, - settings.Settings.WindowPosition.X, - settings.Settings.WindowPosition.Y) - } + loadWindowLocation(ctx) app.App.WatchWindow() //nolint:contextcheck go websocket.ListenAndServeWebsocket() @@ -140,6 +136,23 @@ func main() { } } +func loadWindowLocation(ctx context.Context) { + if settings.Settings.WindowPosition != nil { + // Setting the window location is relative to the current monitor, + // but we save it as absolute position. + + wailsRuntime.WindowSetPosition(ctx, 0, 0) + + // Get the location the window was actually placed at + monitorLeft, monitorTop := wailsRuntime.WindowGetPosition(ctx) + + x := settings.Settings.WindowPosition.X - monitorLeft + y := settings.Settings.WindowPosition.Y - monitorTop + + wailsRuntime.WindowSetPosition(ctx, x, y) + } +} + func init() { // Pass build-time variables to viper if len(version) > 0 && version[0] == 'v' {