-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathwinautohide.ahk
200 lines (168 loc) · 5.35 KB
/
winautohide.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
* BoD winautohide v1.02.
*
* This program and its source are in the public domain.
* Contact BoD@JRAF.org for more information.
*
* Version history:
* 2008-06-13: v1.00
* 2024-03-01: v1.01 Modded by hzhbest
*/
#SingleInstance ignore
;@Ahk2Exe-SetMainIcon %A_ScriptDir%\winautohide.ico
/*
* Hotkey bindings
*/
Hotkey, #right, toggleWindowRight
Hotkey, #left, toggleWindowLeft
Hotkey, #up, toggleWindowUp
Hotkey, #down, toggleWindowDown
; uncomment the following lines to use ctrl+alt+shift instead if you don't have a "windows" key
;Hotkey, !^+right, toggleWindowRight
;Hotkey, !^+left, toggleWindowLeft
;Hotkey, !^+up, toggleWindowUp
;Hotkey, !^+down, toggleWindowDown
/*
* Timer initialization.
*/
SetTimer, watchCursor, 300
/*
* Tray menu initialization.
*/
Menu, tray, NoStandard
Menu, tray, Add, About..., menuAbout
Menu, tray, Add, Un-autohide all windows, menuUnautohideAll
Menu, tray, Add, Exit, menuExit
Menu, tray, Default, About...
return ; end of code that is to be executed on script start-up
/*
* Tray menu implementation.
*/
menuAbout:
MsgBox, 8256, About, BoD winautohide v1.02.`nModded by hzhbest`nhttps://github.com/hzhbest/winautohide`n`nThis program and its source are in the public domain.`nContact BoD@JRAF.org for more information.
return
menuUnautohideAll:
Loop, Parse, autohideWindows, `,
{
curWinId := A_LoopField
if (autohide_%curWinId%) {
Gosub, unautohide
}
}
return
menuExit:
Gosub, menuUnautohideAll
ExitApp
return
/*
* Timer implementation.
*/
watchCursor:
MouseGetPos, , , winId ; get window under mouse pointer
WinGet winPid, PID, ahk_id %winId% ; get the PID for process recognition
if (autohide_%winId% || autohide_%winPid%) { ; window or process is on the list of 'autohide' windows
if (hidden_%winId%) { ; window is in 'hidden' position
previousActiveWindow := WinExist("A")
WinActivate, ahk_id %winId% ; activate the window
WinMove, ahk_id %winId%, , showing_%winId%_x, showing_%winId%_y ; move it to 'showing' position
hidden_%winId% := false
needHide := winId ; store it for next iteration
}
} else {
if (needHide) {
WinMove, ahk_id %needHide%, , hidden_%needHide%_x, hidden_%needHide%_y ; move it to 'hidden' position
WinActivate, ahk_id %previousActiveWindow% ; activate previously active window
hidden_%needHide% := true
needHide := false ; do that only once
}
}
return
/*
* Hotkey implementation.
*/
toggleWindowRight:
mode := "right"
Gosub, toggleWindow
return
toggleWindowLeft:
mode := "left"
Gosub, toggleWindow
return
toggleWindowUp:
mode := "up"
Gosub, toggleWindow
return
toggleWindowDown:
mode := "down"
Gosub, toggleWindow
return
toggleWindow:
WinGet, curWinId, ID, A
WinGet, curWinPId, PID, A
autohideWindows = %autohideWindows%,%curWinId%
if (autohide_%curWinId%) {
Gosub, unautohide
} else {
autohide_%curWinId% := true
autohide_%curWinPid% := true ; record the process in the list
Gosub, workWindow
WinGetPos, orig_%curWinId%_x, orig_%curWinId%_y, width, height, ahk_id %curWinId% ; get the window size and store original position
if (mode = "right") {
showing_%curWinId%_x := A_ScreenWidth - width
showing_%curWinId%_y := orig_%curWinId%_y
prehid_%curWinId%_x := A_ScreenWidth - 51
prehid_%curWinId%_y := orig_%curWinId%_y
hidden_%curWinId%_x := A_ScreenWidth - 1
hidden_%curWinId%_y := orig_%curWinId%_y
} else if (mode = "left") {
showing_%curWinId%_x := 0
showing_%curWinId%_y := orig_%curWinId%_y
prehid_%curWinId%_x := -width + 51
prehid_%curWinId%_y := orig_%curWinId%_y
hidden_%curWinId%_x := -width + 1
hidden_%curWinId%_y := orig_%curWinId%_y
} else if (mode = "up") {
showing_%curWinId%_x := orig_%curWinId%_x
showing_%curWinId%_y := 0
prehid_%curWinId%_x := orig_%curWinId%_x
prehid_%curWinId%_y := -height + 51
hidden_%curWinId%_x := orig_%curWinId%_x
hidden_%curWinId%_y := -height + 1
} else { ; down
showing_%curWinId%_x := orig_%curWinId%_x
showing_%curWinId%_y := A_ScreenHeight - height
prehid_%curWinId%_x := orig_%curWinId%_x
prehid_%curWinId%_y := A_ScreenHeight - 51
hidden_%curWinId%_x := orig_%curWinId%_x
hidden_%curWinId%_y := A_ScreenHeight - 1
}
WinMove, ahk_id %curWinId%, , prehid_%curWinId%_x, prehid_%curWinId%_y
Sleep 300
WinMove, ahk_id %curWinId%, , hidden_%curWinId%_x, hidden_%curWinId%_y ; hide the window
hidden_%curWinId% := true
}
return
unautohide:
autohide_%curWinId% := false
autohide_%curWinPid% := false
needHide := false
Gosub, unworkWindow
WinMove, ahk_id %curWinId%, , orig_%curWinId%_x, orig_%curWinId%_y ; go back to original position
hidden_%curWinId% := false
return
workWindow:
DetectHiddenWindows, On
WinSet, AlwaysOnTop, on, ahk_id %curWinId% ; always-on-top
WinHide, ahk_id %curWinId%
WinSet, Style, -0xC00000, ahk_id %curWinId% ; no title bar
WinSet, ExStyle, +0x80, ahk_id %curWinId% ; remove from task bar
WinShow, ahk_id %curWinId%
return
unworkWindow:
DetectHiddenWindows, On
WinSet, AlwaysOnTop, off, ahk_id %curWinId% ; always-on-top
WinHide, ahk_id %curWinId%
WinSet, Style, +0xC00000, ahk_id %curWinId% ; title bar
WinSet, ExStyle, -0x80, ahk_id %curWinId% ; remove from task bar
WinShow, ahk_id %curWinId%
return