1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#Requires AutoHotkey v2
#SingleInstance Force
; https://stackoverflow.com/a/68547452
GetWindowMonitorIndex(hwnd) {
;Get number of monitor
monCount := MonitorGetCount()
windowX := 0
windowY := 0
windowWidth := 0
windowHeight := 0
;Get the position of the focus window
WinGetPos(&windowX, &windowY, &windowWidth, &windowHeight, hwnd)
;Make an array to hold the sub-areas of the window contained within each monitor
monitorSubAreas := []
;Iterate through each monitor
Loop monCount {
;Get Monitor working area
monitorLeft := 0
monitorTop := 0
monitorRight := 0
monitorBottom := 0
MonitorGet(A_Index, &monitorLeft, &monitorTop, &monitorRight, &monitorBottom)
;Calculate sub-area of the window contained within each monitor
xStart := max(windowX, monitorLeft)
xEnd := min(windowX + windowWidth, monitorRight)
yStart := max(windowY, monitorTop)
yEnd := min(windowY + windowHeight, monitorBottom)
area := (xEnd - xStart) * (yEnd - yStart)
;Remember these areas, and which monitor they were associated with
monitorSubAreas.push({area: area, index: A_Index})
}
;Loop to figure out which monitor's recorded sub-area was largest
winningMonitor := 0
winningArea := 0
for index, monitor in monitorSubAreas {
winningMonitor := monitor.area > winningArea ? monitor.index : winningMonitor
winningArea := monitor.area > winningArea ? monitor.area : winningArea
}
return winningMonitor
}
monitorCount := MonitorGetCount()
;; contains hwnds of all windows in the workspace
workspaces
workspaces := [
[], ; 1
[], ; 2
[], ; 3
[], ; 4
[], ; 5
[], ; 6
[], ; 7
[], ; 8
[], ; 9
[], ; 10 (0)
]
monitorWorkspaces := []
if (monitorCount == 2) {
monitorWorkspaces := [
[1, 2, 3, 4, 5, 6], ; 1
[7, 8, 9, 10] ; 2
]
} else {
for i in range(1, monitorCount) {
monitorWorkspaces.push([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
}
}
UpdateWorkspaceIds(workspace_id) {
global workspaces
global monitorWorkspaces
global monitorCount
; get all windows
ids := WinGetList(,, "Program Manager") ; tbh idk why program manager
; loop through all windows
for windowId in windowList {
; get window's monitor
windowMonitor := GetWindowMonitor(windowId)
; if window is on the workspace we're updating
if (windowMonitor == workspace_id) {
; add it to the workspace
workspaces[workspace_id].push(windowId)
}
}
}
ids := WinGetList(,, "Program Manager")
for this_id in ids {
this_class := WinGetClass(this_id)
this_title := WinGetTitle(this_id)
result := MsgBox(
(
"Visiting All Windows
" A_Index " of " ids.Length "
ahk_id " this_id "
ahk_class " this_class "
" this_title "
monitor " GetWindowMonitorIndex(this_id) "
Continue?"
),, 4)
if (result = "No")
break
}
|