-
Notifications
You must be signed in to change notification settings - Fork 3
/
windows-min-max.ahk
62 lines (55 loc) · 1.34 KB
/
windows-min-max.ahk
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
; No dependencies
minimizedWindows :=
minimizedWindowCount :=
windowThatWasActive :=
; Control+Alt+Win+D: minimize all/restore minimized windows on active monitor
WindowsMinMax:
; Determine which monitor contains the center of the active window
WinGetPos, x, y, w, h, A
activeMonitor := wp_GetMonitorAt(x+w/2, y+h/2)
; A better implementation for 'GetMonitor' is at:
; https://autohotkey.com/board/topic/94735-get-active-monitor/
If minimizedWindowCount =
{
WinGet, windowThatWasActive, ID, A
; Minimize and remember
minimizedWindows := Object()
minimizedWindowCount := 0
WinGet windows, List
Loop %windows%
{
id := windows%A_Index%
WinGetTitle title, ahk_id %id%
;Notify(A_ScriptName) ; = mike.ahk
If (title <> "" and title <> A_ScriptName)
{
WinGetPos, x, y, w, h, ahk_id %id%
monitor := wp_GetMonitorAt(x+w/2, y+h/2)
If (monitor = activeMonitor)
{
WinGet windowState, MinMax, ahk_id %id%
; Window state: 1=max, 0=normal, -1=min
If (windowState = 0 or windowState = 1)
{
WinMinimize, ahk_id %id%
If (windowState = 1) {
WinMinimize, ahk_id %id%
}
minimizedWindows.Insert(id)
minimizedWindowCount++
}
}
}
}
}
else
{
; Restore
for index, element in minimizedWindows
{
WinRestore, ahk_id %element%
}
WinActivate ahk_id %windowThatWasActive%
minimizedWindowCount :=
}
return