refactor #3
This commit is contained in:
parent
e9e0ed153a
commit
6b14350251
21
main.go
21
main.go
@ -70,14 +70,14 @@ func RestoreWindowPositions(client *hypr.Client) error {
|
|||||||
|
|
||||||
boundsOfActualMonitor := GetMonitorBoundsByWindowBounds(windowBounds, monitorBoundsByID)
|
boundsOfActualMonitor := GetMonitorBoundsByWindowBounds(windowBounds, monitorBoundsByID)
|
||||||
|
|
||||||
// calculate new position based on the position of the window and its actual monitor
|
shouldPos := image.Pt(-1, -1)
|
||||||
diff := windowBounds.Min.Sub(boundsOfActualMonitor.Min)
|
if boundsOfActualMonitor == nil {
|
||||||
shouldPos := monitorBounds.Min.Add(diff)
|
// use coords [0,0] respective to the wanted monitor if window is completely OOB
|
||||||
|
|
||||||
// use coords [0,0] respective to the wanted monitor
|
|
||||||
// if window is completely OOB
|
|
||||||
if boundsOfActualMonitor == image.Rect(-1, -1, -1, -1) {
|
|
||||||
shouldPos = monitorBounds.Min
|
shouldPos = monitorBounds.Min
|
||||||
|
} else {
|
||||||
|
// calculate new position based on the position of the window and its actual monitor
|
||||||
|
diff := windowBounds.Min.Sub(boundsOfActualMonitor.Min)
|
||||||
|
shouldPos = monitorBounds.Min.Add(diff)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := fmt.Sprintf(
|
cmd := fmt.Sprintf(
|
||||||
@ -99,11 +99,12 @@ func RestoreWindowPositions(client *hypr.Client) error {
|
|||||||
|
|
||||||
// GetMonitorBoundsByWindowBounds returns the monitor bounds which contains windowBounds
|
// GetMonitorBoundsByWindowBounds returns the monitor bounds which contains windowBounds
|
||||||
// or image.Rect(-1, -1, -1, -1) if windowBounds is outside any monitor bounds
|
// 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 {
|
func GetMonitorBoundsByWindowBounds(windowBounds image.Rectangle, monitorBoundsByID map[int]image.Rectangle) *image.Rectangle {
|
||||||
for _, monitorBounds := range monitorBoundsByID {
|
for _, monitorBounds := range monitorBoundsByID {
|
||||||
if windowBounds.In(monitorBounds) {
|
if windowBounds.In(monitorBounds) {
|
||||||
return monitorBounds
|
newBounds := windowBounds
|
||||||
|
return &newBounds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return image.Rect(-1, -1, -1, -1)
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user