Compare commits

..

No commits in common. "v1.0.0" and "main" have entirely different histories.
v1.0.0 ... main

56
main.go
View File

@ -52,59 +52,53 @@ func RestoreWindowPositions(client *hypr.Client) error {
} }
for _, window := range windows { for _, window := range windows {
// ignore all special workspaces because they can't be moved between monitors
if window.Workspace.ID < 0 { if window.Workspace.ID < 0 {
continue continue
} }
//monitor := monitorByID[window.MonitorID]
windowBounds := image.Rect( windowBounds := image.Rect(
window.At[0], window.At[0],
window.At[1], window.At[1],
window.At[0]+window.Size[0], window.At[0]+window.Size[0],
window.At[1]+window.Size[1]) window.At[1]+window.Size[1])
monitorBounds := monitorBoundsByID[window.MonitorID] shouldMonitorBounds := monitorBoundsByID[window.MonitorID]
if windowBounds.In(monitorBounds) {
if windowBounds.In(shouldMonitorBounds) {
continue continue
} }
boundsOfActualMonitor := GetMonitorBoundsByWindowBounds(windowBounds, monitorBoundsByID) // fmt.Println("IMPOSSIBLE WINDOW POSITION DETECTED", window.Title, window.Address)
// fmt.Println("workspace:", window.Workspace.ID)
// fmt.Println("monitor:", shouldMonitorBounds)
// fmt.Println("window:", windowBounds)
shouldPos := image.Pt(-1, -1) isMonitorBounds := image.Rect(-1, -1, -1, -1)
if boundsOfActualMonitor == nil { for _, monitorBounds := range monitorBoundsByID {
// use coords [0,0] respective to the wanted monitor if window is completely OOB if windowBounds.In(monitorBounds) {
shouldPos = monitorBounds.Min isMonitorBounds = monitorBounds
} else { break
// 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( diff := windowBounds.Min.Sub(isMonitorBounds.Min)
shouldPos := shouldMonitorBounds.Min.Add(diff)
if isMonitorBounds == image.Rect(-1, -1, -1, -1) {
shouldPos = shouldMonitorBounds.Min
}
client.DispatchExpectOK(fmt.Sprintf(
"movewindowpixel exact %d %d,address:%s", "movewindowpixel exact %d %d,address:%s",
shouldPos.X, shouldPos.X,
shouldPos.Y, shouldPos.Y,
window.Address) window.Address,
))
if err := client.DispatchExpectOK(cmd); err != nil {
log.Printf("invalid position could NOT be restored successfully for window (class: '%s' | title: '%s')\n", window.Class, window.Title)
continue
}
log.Printf("invalid position restored for window (class: '%s' | title: '%s')\n", window.Class, window.Title) log.Printf("invalid position restored for window (class: '%s' | title: '%s')\n", window.Class, window.Title)
} }
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) {
newBounds := windowBounds
return &newBounds
}
}
return nil
}