Skip to content

Commit

Permalink
Fix saved absolute position being loaded as relative to current monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
mircearoata committed Feb 6, 2024
1 parent 1291f55 commit 35e2fc8
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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' {
Expand Down

0 comments on commit 35e2fc8

Please sign in to comment.