diff --git a/main.go b/main.go index 5d3f9ca..016562d 100644 --- a/main.go +++ b/main.go @@ -68,16 +68,7 @@ func RestoreWindowPositions(client *hypr.Client) error { continue } - // retrieve the bounds of the monitor in which the window is actually drawn. - // This can be the default value of Rect(-1, -1, -1, -1) - // if the windows is out of bounds for any monitor - boundsOfActualMonitor := image.Rect(-1, -1, -1, -1) - for _, monitorBounds := range monitorBoundsByID { - if windowBounds.In(monitorBounds) { - boundsOfActualMonitor = monitorBounds - break - } - } + boundsOfActualMonitor := GetMonitorBoundsByWindowBounds(windowBounds, monitorBoundsByID) // calculate new position based on the position of the window and its actual monitor diff := windowBounds.Min.Sub(boundsOfActualMonitor.Min) @@ -105,3 +96,14 @@ func RestoreWindowPositions(client *hypr.Client) error { return nil } + +// GetMonitorBoundsByWindowBounds returns the monitor bounds which contains windowBounds +// or image.Rect(-1, -1, -1, -1) if windowBounds is outside any monitor bounds +func GetMonitorBoundsByWindowBounds(windowBounds image.Rectangle, monitorBoundsByID map[int]image.Rectangle) image.Rectangle { + for _, monitorBounds := range monitorBoundsByID { + if windowBounds.In(monitorBounds) { + return monitorBounds + } + } + return image.Rect(-1, -1, -1, -1) +}