-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathclass_Tiling.ahk
390 lines (314 loc) · 9.12 KB
/
class_Tiling.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
#NoEnv
#SingleInstance Force
#WinActivateForce
SetTitleMatchMode, 3
CoordMode, Mouse, Screen
DetectHiddenWindows, Off
class Monitor{
__New(leftBound, topBound, rightBound, bottomBound, taskbarLeft, taskbarRight, taskbarTop, taskbarBottom, BorHor, BorVert, PadHor, PadVert, PortWin){
this.workspace := 1
this.Mode := 1
this.LeftX := leftBound
this.TopY := topBound
this.RightX := rightBound
this.BottomY := bottomBound
this.Width := this.RightX - this.LeftX
this.Height := this.BottomY - this.TopY
this.Windows := Object()
this.NumberWindows := 0
this.WindowPaddingHorizontal := PadHor
this.WindowPaddingVertical := PadVert
this.BorderHorizontal := BorHor
this.BorderVertical := BorVert
this.WindowsInPort := PortWin
this.usableSpace(taskbarLeft, taskbarRight, taskbarTop, taskbarBottom, BorHor, BorVert)
}
usableSpace(taskbarLeftSize, taskbarRightSize, taskbarTopSize, taskbarBottomSize, padHor, padVert){
this.UsableWidth := this.Width - taskbarRightSize - taskbarLeftSize - (padHor * 2)
this.UsableHeight := this.Height - taskbarTopSize - taskbarBottomSize - (padVert * 2)
}
details(){
MsgBox, % "Monitor Details - Height: " this.Height " - Width: " this.Width " - LeftBound, RightBound, TopBound, BottomBound, in order: " this.LeftX "," this.RightX "," this.TopY "," this.BottomY
temp := this.NumberWindows
Loop, %temp%
{
String := String ", " this.Windows[A_Index]
}
MsgBox, % String
}
Swap(IDToMove, positionToMoveTo){
temp := this.Windows[positionToMoveTo]
temp2 := this.NumberWindows
if(positionToMoveTo > temp2)
{
return 0
}
Loop, %temp2%
{
temp3 := this.Windows[A_Index]
if(temp3 = IDToMove)
{
this.Windows[positionToMoveTo] := temp3
this.Windows[A_Index] := temp
return 1
}
}
}
SendWindowToMonitor(tempID, monitor)
{
temp := this.NumberWindows
Loop, %temp%
{
temp2 := this.Windows[A_Index]
if(tempID = temp2)
{
temp3 := monitor.NumberWindows
monitor.Windows[temp3+1] := tempID
monitor.NumberWindows += 1
temp4 := this.NumberWindows - A_Index
temp5 := A_Index
Loop, %temp4%
{
this.Windows[temp5+(A_Index-1)] := this.Windows[temp5+(A_Index)]
}
this.NumberWindows -= 1
this.Ship()
monitor.Ship()
return 1
}
}
}
Ship()
{
global
local result, tempWin, tempNum, tempHorPad, tempVertPad, tempPW, tempN, PortWindowSizeVertical, PortWindowSizeHorizontal, PortWindowVerticalMovement, DeckWindowSizeVertical, DeckWindowSizeHorizontal, DeckWindowVerticalMovement
tempNum := this.NumberWindows
tempHorBor := this.BorderHorizontal
tempVertBor := this.BorderVertical
tempHorPad := this.WindowPaddingHorizontal
tempVertPad := this.WindowPaddingVertical
tempPW := this.WindowsInPort
tempN := this.NumberWindows - tempPW
PortWindowSizeVertical := (this.UsableHeight - (tempPW - 1)*tempVertPad)/tempPW
PortWindowSizeHorizontal := 2*(this.UsableWidth - (tempHorPad))/3
PortWindowVerticalMovement := PortWindowSizeVertical+tempVertPad
DeckWindowSizeVertical := (this.UsableHeight - (tempN - 1)*tempVertPad)/tempN
DeckWindowSizeHorizontal := (this.UsableWidth - (tempHorPad))/3
DeckWindowVerticalMovement := DeckWindowSizeVertical+tempVertPad
DeckWindowHorizontalMovement := PortWindowSizeHorizontal + tempHorPad
Loop, %tempNum%
{
tempWin := this.Windows[A_index]
; Move Windows in the Ports
if(A_Index<=tempPW)
{
WinMove, ahk_id %tempWin%,, this.LeftX + tempHorBor, this.TopY + ToolbarPaddingTop + tempVertBor + PortWindowVerticalMovement*(A_Index - 1), PortWindowSizeHorizontal, PortWindowSizeVertical
} else {
WinMove, ahk_id %tempWin%,, this.LeftX + tempHorBor + DeckWindowHorizontalMovement, this.TopY + tempVertBor + ToolbarPaddingTop + DeckWindowVerticalMovement*(A_Index-tempPW-1), DeckWindowSizeHorizontal, DeckWindowSizeVertical
}
}
}
AddFakeWindow()
{
this.NumberWindows += 1
}
RemoveFakeWindows()
{
tempNum := this.NumberWindows
Loop, %tempNum%
{
tempID := this.Windows[A_Index]
If %tempID%
{
; Do Nothing
} else {
this.Windows[A_Index] := this.Windows[A_Index+1]
this.NumberWindows -= 1
}
}
}
}
class Window{
__New(aHwnd, aTitle){
this.Hwnd := aHwnd
WinGetClass, class, ahk_id %aHwnd%
this.Title := 1
this.OnTop := 0
this.Initialized := 1
this.titleAway(WindowTitlesOn)
}
titleAway(Bool){
temp := this.Hwnd
if(Bool = 0 && Title = 1)
{
WinSet, Style, -0xC00000, ahk_id %temp%
WinSet, Style, -0x800000, ahk_id %temp%
Title := 0
} Else {
WinSet, Style, +0xC00000, ahk_id %temp%
WinSet, Style, +0x800000, ahk_id %temp%
Title := 1
}
WinSet, Redraw,, ahk_id %temp%
}
}
Configure(){
global
titlesOn := 1
ignoreList := "Shell_SecondaryTrayWnd, Shell_TrayWnd, EdgeUiInputTopWndClass, WorkerW, Progman, Launchy, Valve001"
ReadOptionsFromIni()
SysGet, numMonitors, MonitorCount
Loop, %numMonitors%
{
topTaskbar := ToolbarPaddingTop
bottomTaskbar := ToolbarPaddingBot
rightTaskbar := ToolbarPaddingRight
leftTaskbar := ToolbarPaddingLeft
SysGet, mon, Monitor, %A_Index%
mon%A_Index% := new Monitor(monLeft, monTop, monRight, monBottom, leftTaskbar, rightTaskbar, topTaskbar, bottomTaskbar, BorderHor, BorderVert, PaddingHor, PaddingVert, InitialPortWindows)
}
return
}
ReadOptionsFromIni()
{
Global
IfNotExist, Config.ini
{
IniWrite, 10, Config.ini, Windows, BorderHor
IniWrite, 10, Config.ini, Windows, BorderVert
IniWrite, 10, Config.ini, Windows, PaddingHor
IniWrite, 10, Config.ini, Windows, PaddingVert
IniWrite, 1, Config.ini, Settings, InitialPortWindows
IniWrite, 1, Config.ini, Settings, WindowTitlesOn
IniWrite, 0, Config.ini, Settings, ToolbarPaddingTop
IniWrite, 0, Config.ini, Settings, ToolbarPaddingBot
IniWrite, 0, Config.ini, Settings, ToolbarPaddingLeft
IniWrite, 0, Config.ini, Settings, ToolbarPaddingRight
}
IniRead, BorderHor, Config.ini, Windows, BorderHor
IniRead, BorderVert, Config.ini, Windows, BorderVert
IniRead, PaddingHor, Config.ini, Windows, PaddingHor
IniRead, PaddingVert, Config.ini, Windows, PaddingVert
IniRead, InitialPortWindows, Config.ini, Settings, InitialPortWindows
IniRead, WindowTitlesOn, Config.ini, Settings, WindowTitlesOn
IniRead, ToolbarPaddingTop, Config.ini, Settings, ToolbarPaddingTop
IniRead, ToolbarPaddingBot, Config.ini, Settings, ToolbarPaddingBot
IniRead, ToolbarPaddingLeft, Config.ini, Settings, ToolbarPaddingLeft
IniRead, ToolbarPaddingRight, Config.ini, Settings, ToolbarPaddingRight
}
CreateWindows(){
global
local tempid, tempTitle, tempclass
DetectHiddenWindows, Off
windowArray := Object()
tempTitle :=
Loop, %windows%
{
VarSetCapacity(windows%A_Index%,0)
}
WinGet, windows, List
Loop, %windows%
{
tempid := windows%A_Index%
WinGetTitle, tempTitle, ahk_id %tempid%
WinGetClass, tempclass, ahk_id%tempid%
if(tempTitle != ""){
ifNotInString, ignoreList, %tempclass%
{
windowArray[A_Index] := new Window(tempid, titlesOn)
}
}
}
return
}
DetectMonitorMouse(){
global
local mouseTempX, mouseTempY, currentMonitor
MouseGetPos, mouseTempX, mouseTempY
Loop, %numMonitors%{
currentMonitor := mon%A_Index%
if(currentMonitor.LeftX <= mouseTempX && mouseTempX < currentMonitor.RightX && currentMonitor.TopY <= mouseTempY && mouseTempY < currentMonitor.BottomY){
return %A_Index%
}
}
return 0
}
DetectMonitorWindow(WindowID){
global
local winX, winY, currentMonitor
WinGetPos, winX, winY,,,ahk_id %WindowID%
Loop, %numMonitors% {
currentMonitor := mon%A_Index%
if(currentMonitor.LeftX <= winX && winX < currentMonitor.RightX && currentMonitor.TopY <= winY && winY < currentMonitor.BottomY){
return %A_Index%
}
}
return 0
}
SendWindowToMonitorArray(WindowID){
global
local windowLocation, temp, tempmon
windowLocation := DetectMonitorWindow(WindowID)
tempmon := mon%windowLocation%
temp := tempmon.NumberWindows+1
tempmon.Windows[temp] := WindowID
tempmon.NumberWindows := temp
return
}
SendAllWindowsToMonitorArray(){
global
local temp
Loop, %windows%
{
temp := windowArray[A_Index].Hwnd
SendWindowToMonitorArray(temp)
}
}
SearchAndDestroyWindow(WindowID)
{
global
local temp, temp2, temp3, tempID, monitor
Loop, %numMonitors%
{
monitor := mon%A_Index%
temp := monitor.NumberWindows
Loop, %temp%
{
tempID := monitor.Windows[A_Index]
if(WindowID = tempID)
{
temp2 := temp - A_Index
temp3 := A_Index
Loop, %temp2%
{
monitor.Windows[temp3+(A_Index-1)] := monitor.Windows[temp3+A_Index]
}
monitor.Windows[temp] := ""
monitor.NumberWindows := temp - 1
return monitor
}
}
}
}
ShellMessage(wParam, lParam){
Global
local temp, tempmon
if(wParam = 1){
;Window Created
temp := DetectMonitorWindow(lParam)
tempmon := mon%temp%
tempWindow := new Window(lParam, titlesOn)
SendWindowToMonitorArray(lParam)
tempmon.Ship()
} else if(wParam = 4 || wParam = 3 || wParam = 6){
;Window active
temp := DetectMonitorWindow(lParam)
tempmon := mon%temp%
tempmon.Ship()
} else if(wParam = 2){
temp := DetectMonitorWindow(lParam)
tempmon := SearchAndDestroyWindow(lParam)
tempmon.Ship()
}
return
}