From 6b143502511e4ed858b178be2e4fe94bca8d32f2 Mon Sep 17 00:00:00 2001 From: Milarin Date: Fri, 5 Apr 2024 14:00:33 +0200 Subject: [PATCH] refactor #3 --- main.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 016562d..a3d9239 100644 --- a/main.go +++ b/main.go @@ -70,14 +70,14 @@ func RestoreWindowPositions(client *hypr.Client) error { boundsOfActualMonitor := GetMonitorBoundsByWindowBounds(windowBounds, monitorBoundsByID) - // 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) - - // use coords [0,0] respective to the wanted monitor - // if window is completely OOB - if boundsOfActualMonitor == image.Rect(-1, -1, -1, -1) { + shouldPos := image.Pt(-1, -1) + if boundsOfActualMonitor == nil { + // use coords [0,0] respective to the wanted monitor if window is completely OOB 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( @@ -99,11 +99,12 @@ func RestoreWindowPositions(client *hypr.Client) error { // 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 { +func GetMonitorBoundsByWindowBounds(windowBounds image.Rectangle, monitorBoundsByID map[int]image.Rectangle) *image.Rectangle { for _, monitorBounds := range monitorBoundsByID { if windowBounds.In(monitorBounds) { - return monitorBounds + newBounds := windowBounds + return &newBounds } } - return image.Rect(-1, -1, -1, -1) + return nil }