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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
;; Window management ----------------------------------------------------------
;; -> init
GroupAdd, WindowsExplorer, ahk_class CabinetWClass
GroupAdd, WindowsExplorer, ahk_class ExploreWClass
Gui, FakeWindow:+LastFound +Owner +Disabled -Caption
Gui, +hwndFakeWindowHwnd
y := A_ScreenHeight - 100
Gui, FakeWindow:Show, x0 y%y% AutoSize NA, FakeWindow
;; -> body
#q::WinSet, Bottom,, A
#a::WinSet, Top,, A
#t::WinSet, AlwaysOnTop, Toggle, A
#y::
WinGet, t, Transparent, A
if (t = OFF)
WinSet, Transparent, 180, A
else
WinSet, Transparent, OFF, A
return
#b::WinSet, Bottom,, A
#!m::WinMove, A,, 0, 0
#z::WinMinimize, A
#v::
WinGet, mm, MinMax, A
if (mm = 1)
WinRestore, A
else
WinMaximize, A
return
#x:: ; minimize all except current
WinGet, hwnd, id, A
WinGet, s, Style, ahk_id %hwnd%
WinSet, Style, -0x20000, ahk_id %hwnd% ; WS_MINIMIZEBOX
WinMinimizeAll
Sleep, 50
WinSet, Style, % s, ahk_id %hwnd%
WinActivate, ahk_id %hwnd%
WinGet, mm, MinMax, ahk_id %hwnd%
if (mm = -1)
WinRestore, ahk_id %hwnd%
return
#c:: ; minimize last window
SendInput, !{Tab}
Sleep, 50
WinMinimize, A
return
;; -> body
/*
#!m:: ; fix minimization bug (?)
WinGet, hwnd, id, A
parent := DllCall("GetParent", "uint", hwnd)
WinGet, progman, id, Program Manager ahk_class Progman
DllCall("SetParent", "uint", hwnd, "uint", progman)
DllCall("SetParent", "uint", hwnd, "uint", parent)
return
*/
/*
#c::
GWL_HWNDPARENT := -8
MouseGetPos,,, hwnd
WindowDisabled := hwnd
return
*/
/*
$!Tab::
HandleAltTab:
if (WindowDisabled)
WinSet, Disable,, ahk_id %WindowDisabled%
SendInput, {LAlt Down}{Tab}
Hotkey, $!Tab, HandleAltTab, Off
Hotkey, $!+Tab, HandleAltShiftTab, Off
while (GetKeyState("LAlt", "P") and not esc := GetKeyState("Esc", "P"))
Sleep, 1
if (esc)
SendInput, {Esc}
SendInput, {LAlt Up}
Hotkey, $!Tab, HandleAltTab, On
Hotkey, $!+Tab, HandleAltShiftTab, On
WinSet, Enable,, ahk_id %WindowDisabled%
return
$!+Tab::
HandleAltShiftTab:
if (WindowDisabled)
WinSet, Disable,, ahk_id %WindowDisabled%
if (WinActive("A") = WindowDisabled)
SendInput, {LAlt Down}{LShift Down}{Tab}{LShift Up}{Tab}
else
SendInput, {LAlt Down}{LShift Down}{Tab}{LShift Up}
Hotkey, $!Tab, HandleAltTab, Off
Hotkey, $!+Tab, HandleAltShiftTab, Off
while (GetKeyState("LAlt", "P") and not esc := GetKeyState("Esc", "P"))
Sleep, 1
if (esc)
SendInput, {Esc}
SendInput, {LAlt Up}
Hotkey, $!Tab, HandleAltTab, On
Hotkey, $!+Tab, HandleAltShiftTab, On
WinSet, Enable,, ahk_id %WindowDisabled%
return
*/
^RButton::
hwndp := WinActive("A")
MouseGetPos,,, hwnd
if (hwnd = hwndp)
{
WinSet, Top,, A
return
}
DllCall("SetForegroundWindow", "UInt", hwnd)
WinSet, AlwaysOnTop, On, ahk_id %hwndp%
WinSet, AlwaysOnTop, Off, ahk_id %hwndp%
return
;; Fix inconsistent z-order after minimization via taskbar --------------------
;; -> library
WindowsWindowMessage(wParam, lParam)
{
static HSHELL_GETMINRECT := 5
; The active window is 0 during minimization (if animated)
if (wParam = HSHELL_GETMINRECT and WinActive("A") = 0)
{
hwnd := NumGet(lParam + 0)
WinWaitNotActive, ahk_id 0
Sleep, 20
InsertAfter(hwnd, "BOTTOM")
}
}
;; -> init
WindowMessageHandlers.Push("WindowsWindowMessage")
;; Change the position of a given window in the z-order -----------------------
;; -> library
InsertAfter(hwnd = "", position = "BOTTOM")
{
static SWP_NOSIZE := 0x0001
static SWP_NOMOVE := 0x0002
static SWP_ASYNCWINDOWPOS := 0x4000
static HWND_BOTTOM := 1
static HWND_NOTOPMOST := -2
static HWND_TOP := 0
static HWND_TOPMOST := -1
if (hwnd = "")
WinGet, hwnd, id, A
DllCall("SetWindowPos"
, "UInt", hwnd
, "UInt", HWND_%position%
, "Int", 0
, "Int", 0
, "Int", 0
, "Int", 0
, "UInt", SWP_NOSIZE | SWP_NOMOVE | SWP_ASYNCWINDOWPOS)
}
|