-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindowMenu.ahk
450 lines (358 loc) · 18.2 KB
/
WindowMenu.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
#Include Lib\Logging.ahk
#Include Lib\WindowObjects.ahk
#Include Lib\StringUtils.ahk
#Include Lib\ArrayUtils.ahk
#Include Lib\MathUtils.ahk
#Include Lib\MenuFunctions.ahk
#Include Lib\WindowFunctions.ahk
#Include Lib\WindowPositions.ahk
#Include Lib\DesktopIcons.ahk
#Include Lib\ListViewSelector.ahk
#Include WindowExtensionsUserConfig.ahk
;--------------------------------------------------------------------------------
; Globals
IconLibrary := []
WindowMenuName :=
G_SelectableWindowPositions := []
G_SelectableDesktopIcons := []
;--------------------------------------------------------------------------------
; Initialisation
WindowMenu_OnInit()
{
global WindowMenuName
WindowMenuName := "WindowMenu"
BuildIconLibrary()
}
;--------------------------------------------------------------------------------
; OnStartup
WindowMenu_OnStartup()
{
BuildWindowMenu()
}
;--------------------------------------------------------------------------------
; OnExit
WindowMenu_OnExit()
{
RestoreRollupWindows() ; This line will unroll any rolled up windows if the script exits for any reason:
}
;--------------------------------------------------------------------------------
; Build Menu
BuildWindowMenu()
{
global G_UserConfig
global G_MonitorCount
global G_MenuTitle
global IconLibraryFileName
global MenuLocationWindowMenu
global WindowMenuName
menuIndex := 0
desktopSize := GetDesktopSize()
try Menu, %WindowMenuName%, DeleteAll
menuIndex := AddMenuItem(WindowMenuName, G_MenuTitle, "NullHandler", menuIndex)
Menu, %WindowMenuName%, Icon, %G_MenuTitle%, Shell32.dll, 20
; Standard Window Sizes
menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "&Optimum Size", "OptimumSizeHandler", IconLibraryFileName, GetIconLibraryIndex("MOVESIZE_COMMON_OPTIMUM"), menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Su&b-Optimum Size", "SubOptimumSizeHandler", IconLibraryFileName, GetIconLibraryIndex("MOVESIZE_COMMON_SUBOPTIMUM"), menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "M&edium Size", "MediumSizeHandler", IconLibraryFileName, GetIconLibraryIndex("MOVESIZE_COMMON_MEDIUM"), menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Sma&ll Size", "SmallSizeHandler", IconLibraryFileName, GetIconLibraryIndex("MOVESIZE_COMMON_SMALL"), menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "T&iny Size", "TinySizeHandler", IconLibraryFileName, GetIconLibraryIndex("MOVESIZE_COMMON_TINY"), menuIndex)
; Move to known columns of the Screen
menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "&Left Column", "MoveColumnLeftHandler", IconLibraryFileName, GetIconLibraryIndex("MOVESIZE_COLUMN_LEFT"), menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Ce&ntre Column", "MoveColumnCentreHandler", IconLibraryFileName, GetIconLibraryIndex("MOVESIZE_COLUMN_CENTRE"), menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "&Right Column", "MoveColumnRightHandler", IconLibraryFileName, GetIconLibraryIndex("MOVESIZE_COLUMN_RIGHT"), menuIndex)
; Multi-Monitor spanning
menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "&Fit Current Monitor", "SpanCurrentMonitorHandler", IconLibraryFileName, GetIconLibraryIndex("MONITOR_FIT"), menuIndex)
if (G_MonitorCount > 1)
{
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Span &Monitor Width", "SpanMonitorWidthHandler", IconLibraryFileName, GetIconLibraryIndex("MONITOR_SPAN_WIDTH"), menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Span &Monitor Height", "SpanMonitorHeightHandler", IconLibraryFileName, GetIconLibraryIndex("MONITOR_SPAN_HEIGHT"), menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Span &All Monitors", "SpanAllMonitorsHandler", IconLibraryFileName, GetIconLibraryIndex("MONITOR_SPAN_ALL"), menuIndex)
}
; Window Positions
if (ContainsFlag(G_UserConfig.MenuControl_WindowPositionsMenuLocation, MenuLocationWindowMenu))
{
menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex)
saveTitle := "Save Window &Positions (" . desktopSize.DimensionsText . ")"
menuIndex := AddMenuItemWithIcon(WindowMenuName, saveTitle, "SaveWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_SAVE"), menuIndex)
restoreTitle := "Restore Last Window &Positions (" . desktopSize.DimensionsText . ")"
menuIndex := AddMenuItemWithIcon(WindowMenuName, restoreTitle, "RestoreWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_RESTORE"), menuIndex)
restoreEnabled := HasSavedWindowPositionsFile(desktopSize)
EnableMenuItem(WindowMenuName, restoreTitle, restoreEnabled)
if (HasMultipleSavedWindowPositionsFiles(desktopSize))
{
restoreTitle := "Restore Window &Positions (" . desktopSize.DimensionsText . ")..."
menuIndex := AddMenuItemWithIcon(WindowMenuName, restoreTitle, "RestoreMultipleWindowPositionsHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_RESTORE"), menuIndex)
}
}
; Move to Corners
menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Move &Centre", "CentreHandler", IconLibraryFileName, GetIconLibraryIndex("MOVE_CENTRE"), menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Move &Top Left", "MoveTopLeftHandler", IconLibraryFileName, GetIconLibraryIndex("MOVE_CORNER_TOPLEFT"), menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Move &Top Right", "MoveTopRightHandler", IconLibraryFileName, GetIconLibraryIndex("MOVE_CORNER_TOPRIGHT"), menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Move &Bottom Left", "MoveBottomLeftHandler", IconLibraryFileName, GetIconLibraryIndex("MOVE_CORNER_BOTTOMLEFT"), menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Move &Bottom Right", "MoveBottomRightHandler", IconLibraryFileName, GetIconLibraryIndex("MOVE_CORNER_BOTTOMRIGHT"), menuIndex)
; Rollup
menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Roll&up", "RollupHandler", IconLibraryFileName, GetIconLibraryIndex("SIZE_COMMON_ROLLUP"), menuIndex)
; Topmost handling
menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Set Top&Most On", "TopmostSetHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_ZORDER_TOPMOSTON"), menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Set Top&Most Off", "TopmostUnsetHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_ZORDER_TOPMOSTOFF"), menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "&Toggle TopMost", "TopmostToggleHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_ZORDER_TOPMOSTTOGGLE"), menuIndex)
; Transparency
menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Set Transparency &75%", "TransparencySet75Handler", IconLibraryFileName, GetIconLibraryIndex("POSITION_TRANSPARENCY75"), menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Set Transparency &50%", "TransparencySet50Handler", IconLibraryFileName, GetIconLibraryIndex("POSITION_TRANSPARENCY50"), menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Set Transparency &25%", "TransparencySet25Handler", IconLibraryFileName, GetIconLibraryIndex("POSITION_TRANSPARENCY25"), menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Set Transparency &0%", "TransparencySet0Handler", IconLibraryFileName, GetIconLibraryIndex("POSITION_TRANSPARENCY0"), menuIndex)
; Send to back
menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex)
menuIndex := AddMenuItemWithIcon(WindowMenuName, "Send to Bac&k", "SendToBackHandler", IconLibraryFileName, GetIconLibraryIndex("POSITION_ZORDER_SENDTOBACK"), menuIndex)
; Desktop Icons
if (ContainsFlag(G_UserConfig.MenuControl_DesktopIconsMenuLocation, MenuLocationWindowMenu))
{
menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex)
saveTitle := "Save &Desktop Icons (" . desktopSize.DimensionsText . ")"
menuIndex := AddMenuItemWithIcon(WindowMenuName, saveTitle, "SaveDesktopIconsHandler", IconLibraryFileName, GetIconLibraryIndex("DESKTOPICONS_SAVE"), menuIndex)
restoreTitle := "Restore &Desktop Icons (" . desktopSize.DimensionsText . ")"
menuIndex := AddMenuItemWithIcon(WindowMenuName, restoreTitle, "RestoreDesktopIconsHandler", IconLibraryFileName, GetIconLibraryIndex("DESKTOPICONS_RESTORE"), menuIndex)
restoreEnabled := HasSavedDesktopIconsFile(desktopSize)
EnableMenuItem(WindowMenuName, restoreTitle, restoreEnabled)
if (HasMultipleSavedDesktopIconsFiles(desktopSize))
{
restoreTitle := "Restore &Desktop Icons (" . desktopSize.DimensionsText . ")..."
menuIndex := AddMenuItemWithIcon(WindowMenuName, restoreTitle, "RestoreMultipleDesktopIconsHandler", IconLibraryFileName, GetIconLibraryIndex("DESKTOPICONS_RESTORE"), menuIndex)
}
}
; Cancel menu
menuIndex := AddMenuItemSeparator(WindowMenuName, menuIndex)
menuIndex := AddMenuItem(WindowMenuName, "&Cancel", "NullHandler", menuIndex)
}
;--------------------------------------------------------------------------------
; BuildIconLibrary - Build Icon Library
BuildIconLibrary()
{
global IconLibrary
IconLibrary := []
IconLibrary.push("MONITOR_FIT")
IconLibrary.push("MOVESIZE_COLUMN_CENTRE")
IconLibrary.push("MOVESIZE_COLUMN_LEFT")
IconLibrary.push("MOVESIZE_COLUMN_RIGHT")
IconLibrary.push("MOVESIZE_COMMON_MEDIUM")
IconLibrary.push("MOVESIZE_COMMON_OPTIMUM")
IconLibrary.push("MOVESIZE_COMMON_SMALL")
IconLibrary.push("MOVESIZE_COMMON_SUBOPTIMUM")
IconLibrary.push("MOVESIZE_COMMON_TINY")
IconLibrary.push("MOVE_CENTRE")
IconLibrary.push("MOVE_CORNER_BOTTOMLEFT")
IconLibrary.push("MOVE_CORNER_BOTTOMRIGHT")
IconLibrary.push("MOVE_CORNER_TOPLEFT")
IconLibrary.push("MOVE_CORNER_TOPRIGHT")
IconLibrary.push("POSITION_TRANSPARENCY0")
IconLibrary.push("POSITION_TRANSPARENCY25")
IconLibrary.push("POSITION_TRANSPARENCY50")
IconLibrary.push("POSITION_TRANSPARENCY75")
IconLibrary.push("POSITION_ZORDER_SENDTOBACK")
IconLibrary.push("POSITION_ZORDER_TOPMOSTOFF")
IconLibrary.push("POSITION_ZORDER_TOPMOSTON")
IconLibrary.push("POSITION_ZORDER_TOPMOSTTOGGLE")
IconLibrary.push("SIZE_COMMON_ROLLUP")
IconLibrary.push("MONITOR_SPAN_ALL")
IconLibrary.push("MONITOR_SPAN_HEIGHT")
IconLibrary.push("MONITOR_SPAN_WIDTH")
IconLibrary.push("POSITION_RESTORE")
IconLibrary.push("POSITION_SAVE")
IconLibrary.push("DESKTOPICONS_RESTORE")
IconLibrary.push("DESKTOPICONS_SAVE")
}
;--------------------------------------------------------------------------------
; GetIconIndex - Find the array index of a named icon
GetIconLibraryIndex(iconName)
{
global IconLibrary
return IndexOf(IconLibrary, iconName)
}
;--------------------------------------------------------------------------------
; Menu Handlers
;--------------------------------------------------------------------------------
;--------------------------------------------------------------------------------
OptimumSizeHandler:
SetWindowByGutter(G_ActiveWindow, (G_UserConfig.General_CascadeGutterSize * 1))
return
SubOptimumSizeHandler:
SetWindowByGutter(G_ActiveWindow, (G_UserConfig.General_CascadeGutterSize * 2))
return
MediumSizeHandler:
SetWindowByGutter(G_ActiveWindow, (G_UserConfig.General_CascadeGutterSize * 3))
return
SmallSizeHandler:
SetWindowByGutter(G_ActiveWindow, (G_UserConfig.General_CascadeGutterSize * 4))
return
TinySizeHandler:
SetWindowByGutter(G_ActiveWindow, (G_UserConfig.General_CascadeGutterSize * 5))
return
;--------------------------------------------------------------------------------
MoveColumnLeftHandler:
SetWindowByColumn(G_ActiveWindow, 1, 3, G_UserConfig.General_ColumnGutterSize)
return
MoveColumnCentreHandler:
SetWindowByColumn(G_ActiveWindow, 2, 3, G_UserConfig.General_ColumnGutterSize)
return
MoveColumnRightHandler:
SetWindowByColumn(G_ActiveWindow, 3, 3, G_UserConfig.General_ColumnGutterSize)
return
;--------------------------------------------------------------------------------
SpanCurrentMonitorHandler:
monitor := new Monitor(G_ActiveWindow.MonitorIndex)
monitorWorkArea := monitor.WorkArea
SetWindowSpanMonitors(G_ActiveWindow, monitorWorkArea.Left, monitorWorkArea.Top, monitorWorkArea.Right, monitorWorkArea.Bottom, G_UserConfig.General_SpanMonitorGutterSize)
return
SpanMonitorWidthHandler:
monitor := new Monitor(G_ActiveWindow.MonitorIndex)
monitorWorkArea := monitor.WorkArea
SetWindowSpanMonitors(G_ActiveWindow, "", monitorWorkArea.Top, "", monitorWorkArea.Bottom, G_UserConfig.General_SpanMonitorGutterSize)
return
SpanMonitorHeightHandler:
monitor := new Monitor(G_ActiveWindow.MonitorIndex)
monitorWorkArea := monitor.WorkArea
SetWindowSpanMonitors(G_ActiveWindow, monitorWorkArea.Left, "", monitorWorkArea.Right, "", G_UserConfig.General_SpanMonitorGutterSize)
return
SpanAllMonitorsHandler:
SetWindowSpanMonitors(G_ActiveWindow, "", "", "", "", G_UserConfig.General_SpanMonitorGutterSize)
return
;--------------------------------------------------------------------------------
SaveWindowPositionsHandler:
SaveWindowPositions(G_UserConfig.WindowPositions_IncludeOffScreenWindows, true)
return
RestoreWindowPositionsHandler:
RestoreWindowPositions(GetLatestWindowPositionsDataFileName(GetDesktopSize()), G_UserConfig.WindowPositions_IncludeOffScreenWindows)
return
RestoreMultipleWindowPositionsHandler:
RestoreWindowPositionsFromFile(GetDesktopSize())
return
;--------------------------------------------------------------------------------
CentreHandler:
SetWindowToCentre(G_ActiveWindow)
return
MoveTopLeftHandler:
SetWindowByGrid(G_ActiveWindow, 1, 1, 2, 2, G_UserConfig.General_GridGutterSize)
return
MoveTopRightHandler:
SetWindowByGrid(G_ActiveWindow, 1, 2, 2, 2, G_UserConfig.General_GridGutterSize)
return
MoveBottomLeftHandler:
SetWindowByGrid(G_ActiveWindow, 2, 1, 2, 2, G_UserConfig.General_GridGutterSize)
return
MoveBottomRightHandler:
SetWindowByGrid(G_ActiveWindow, 2, 2, 2, 2, G_UserConfig.General_GridGutterSize)
return
;--------------------------------------------------------------------------------
RollupHandler:
RollupToggleWindow(G_ActiveWindow, G_CaptionHitHeight)
return
;--------------------------------------------------------------------------------
TopmostSetHandler:
SetWindowTop(G_ActiveWindow, 1)
return
TopmostUnsetHandler:
SetWindowTop(G_ActiveWindow, 0)
return
TopmostToggleHandler:
SetWindowTop(G_ActiveWindow, -1)
return
;--------------------------------------------------------------------------------
TransparencySet75Handler:
SetWindowTransparency(G_ActiveWindow, 64)
return
TransparencySet50Handler:
SetWindowTransparency(G_ActiveWindow, 128)
return
TransparencySet25Handler:
SetWindowTransparency(G_ActiveWindow, 192)
return
TransparencySet0Handler:
SetWindowTransparency(G_ActiveWindow, 255)
return
;--------------------------------------------------------------------------------
SaveDesktopIconsHandler:
SaveDesktopIcons(true)
return
RestoreDesktopIconsHandler:
RestoreDesktopIcons(GetLatestWindowPositionsDataFileName(GetDesktopSize()))
return
RestoreMultipleDesktopIconsHandler:
RestoreDesktopIconsFromFile(GetDesktopSize())
return
;--------------------------------------------------------------------------------
SendToBackHandler:
SendWindowToBack(G_ActiveWindow)
return
;--------------------------------------------------------------------------------
NullHandler:
return
;--------------------------------------------------------------------------------
; ShowMenu - Show the Window Control Menu
ShowMenu(theWindow)
{
global G_MenuTitle
global WindowMenuName
BuildWindowMenu()
; Build Window Details
newMenuTitle := theWindow.Title . " (" . theWindow.ProcessName . ") [" . theWindow.Left . ", " . theWindow.Top . ", " . theWindow.Width . ", " . theWindow.Height . "]"
; Change Menu MainTitle
if (newMenuTitle <> G_MenuTitle)
{
G_MenuTitle := newMenuTitle
Menu, %WindowMenuName%, Rename, 1&, %G_MenuTitle%
}
processPath := theWindow.ProcessPath
try Menu, %WindowMenuName%, Icon, 1&, %processPath%, 0
; Enable / Disable as appropriate
enableTopMostOff := IsWindowTopMost(theWindow.WindowHandle)
enableTopMostOn := !enableTopMostOff
EnableMenuItem(WindowMenuName, "Set Top&Most On", enableTopMostOn)
EnableMenuItem(WindowMenuName, "Set Top&Most Off", enableTopMostOff)
; Show Popup Menu
Menu, %WindowMenuName%, Show
}
;--------------------------------------------------------------------------------
; WindowsKey+W
#w::
; Get Active Window
WinGet, theWindow, ID, A
MouseGetPos, mouseX, mouseY
G_ActiveWindow := New Window(theWindow)
G_CurrentMouse := New Coordinate(mouseX, mouseY)
ShowMenu(G_ActiveWindow)
return
;--------------------------------------------------------------------------------
; RightMouseButton
$~Rbutton::
; Get MousePos and Active Window
MouseGetPos, mouseX, mouseY, theWindow
G_ActiveWindow := New Window(theWindow)
G_CurrentMouse := New Coordinate(mouseX, mouseY)
LogText("G_ActiveWindow: " . G_ActiveWindow.Description)
LogText("G_CurrentMouse: " . G_CurrentMouse.Description)
; Get Mouse Monitor
currentMouseMonitor := New Monitor(G_CurrentMouse.MonitorIndex)
LogText("currentMouseMonitor: " . currentMouseMonitor.Description)
LogText("currentMouseMonitor.WorkArea: " . currentMouseMonitor.WorkArea.Description)
if (!G_CurrentMouse.IsInRectangle(currentMouseMonitor.WorkArea))
{
LogText("Outside Monitor Area: " . currentMouseMonitor.WorkArea.Description)
return
}
hitArea := G_ActiveWindow.GetHitArea(G_CaptionHeight)
if (!G_currentMouse.IsInRectangle(hitArea))
{
LogText("Outside Window Hit Area: " . hitArea.Description)
return
}
title := G_ActiveWindow.Title
description := G_ActiveWindow.Description
ShowMenu(G_ActiveWindow)
return