This commit is contained in:
Milarin 2024-04-05 13:54:28 +02:00
parent 18dbd68f04
commit e9e0ed153a

22
main.go
View File

@ -68,16 +68,7 @@ func RestoreWindowPositions(client *hypr.Client) error {
continue continue
} }
// retrieve the bounds of the monitor in which the window is actually drawn. boundsOfActualMonitor := GetMonitorBoundsByWindowBounds(windowBounds, monitorBoundsByID)
// 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
}
}
// calculate new position based on the position of the window and its actual monitor // calculate new position based on the position of the window and its actual monitor
diff := windowBounds.Min.Sub(boundsOfActualMonitor.Min) diff := windowBounds.Min.Sub(boundsOfActualMonitor.Min)
@ -105,3 +96,14 @@ func RestoreWindowPositions(client *hypr.Client) error {
return nil 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)
}