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' {