-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathSnapX_Functions.ahk
145 lines (128 loc) · 5.55 KB
/
SnapX_Functions.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
GetMonitorId(hwnd)
{
local wp, mon, winCenterX, winCenterY
GetWindowPlacement(hwnd, wp) ; GetWindowPlacement returns restored position of window (need this in case hwnd is minimized)
SysGet, monitorCount, MonitorCount
Loop, % monitorCount
{
mon := new SnapMonitor(A_Index)
winCenterX := (wp.rcNormalPosition.left + mon.workarea.xo + wp.rcNormalPosition.right + mon.workarea.xo) / 2 ; wp coordinates are in workspace coordinates
winCenterY := (wp.rcNormalPosition.top + mon.workarea.yo + wp.rcNormalPosition.bottom + mon.workarea.yo) / 2 ; wp coordinates are in workspace coordinates
if (winCenterX >= mon.area.x && winCenterX <= mon.area.r && winCenterY >= mon.area.y && winCenterY <= mon.area.b)
{
return % A_Index
}
}
return 1
}
NumGetInc(ByRef VarOrAddress, ByRef Offset, Type)
{
value := NumGet(VarOrAddress, Offset, Type)
Offset := Offset + SizeOf[Type]
return value
}
NumPutInc(Number, ByRef VarOrAddress, ByRef Offset, Type)
{
NumPut(Number, VarOrAddress, Offset, Type)
Offset := Offset + SizeOf[Type]
}
GetWindowPlacement(hwnd, ByRef lpwndpl)
{
VarSetCapacity(_lpwndpl, 44)
NumPut(44, _lpwndpl)
result := DllCall("GetWindowPlacement", Ptr, hwnd, Ptr, &_lpwndpl)
runningOffset := 0
lpwndpl := new WINDOWPLACEMENT(NumGetInc(_lpwndpl, runningOffset, "UInt")
, NumGetInc(_lpwndpl, runningOffset, "UInt")
, NumGetInc(_lpwndpl, runningOffset, "UInt")
, new tagPOINT(NumGetInc(_lpwndpl, runningOffset, "Int")
, NumGetInc(_lpwndpl, runningOffset, "Int"))
, new tagPOINT(NumGetInc(_lpwndpl, runningOffset, "Int")
, NumGetInc(_lpwndpl, runningOffset, "Int"))
, new _RECT(NumGetInc(_lpwndpl, runningOffset, "Int")
, NumGetInc(_lpwndpl, runningOffset, "Int")
, NumGetInc(_lpwndpl, runningOffset, "Int")
, NumGetInc(_lpwndpl, runningOffset, "Int")))
return result
}
SetWindowPlacement(hwnd, ByRef lpwndpl)
{
VarSetCapacity(_lpwndpl, 44)
runningOffset := 0
NumPutInc(lpwndpl.length , _lpwndpl, runningOffset, "UInt")
NumPutInc(lpwndpl.flags , _lpwndpl, runningOffset, "UInt")
NumPutInc(lpwndpl.showCmd, _lpwndpl, runningOffset, "UInt")
NumPutInc(lpwndpl.ptMinPosition.x, _lpwndpl, runningOffset, "Int")
NumPutInc(lpwndpl.ptMinPosition.y, _lpwndpl, runningOffset, "Int")
NumPutInc(lpwndpl.ptMaxPosition.x, _lpwndpl, runningOffset, "Int")
NumPutInc(lpwndpl.ptMaxPosition.y, _lpwndpl, runningOffset, "Int")
NumPutInc(lpwndpl.rcNormalPosition.left , _lpwndpl, runningOffset, "Int")
NumPutInc(lpwndpl.rcNormalPosition.top , _lpwndpl, runningOffset, "Int")
NumPutInc(lpwndpl.rcNormalPosition.right , _lpwndpl, runningOffset, "Int")
NumPutInc(lpwndpl.rcNormalPosition.bottom, _lpwndpl, runningOffset, "Int")
result := DllCall("SetWindowPlacement", Ptr, hwnd, Ptr, &_lpwndpl)
return result
}
GetClientRect(hwnd, ByRef lpRect)
{
VarSetCapacity(_lpRect, SizeOf.Long * 4)
NumPut(SizeOf.Long * 4, _lpRect)
result := DllCall("GetClientRect", Ptr, hwnd, Ptr, &_lpRect)
runningOffset := 0
lpRect := new _RECT(NumGetInc(_lpRect, runningOffset, "Int")
, NumGetInc(_lpRect, runningOffset, "Int")
, NumGetInc(_lpRect, runningOffset, "Int")
, NumGetInc(_lpRect, runningOffset, "Int"))
return result
}
SetWinEventHook(eventMin, eventMax, hmodWinEventProc, lpfnWinEventProc, idProcess, idThread, dwflags)
{
return DllCall("SetWinEventHook", UInt, eventMin, UInt, eventMax, UInt, hmodWinEventProc, UInt, lpfnWinEventProc, UInt, idProcess, UInt, idThread, UInt, dwflags)
}
ThisCallbackTracker := []
RegisterCallbackToThis(FunctionName, ParamCount, your_this)
{
global ThisCallbackTracker
index := ThisCallbackTracker.Push({ your_this: &your_this, FunctionName: FunctionName })
return RegisterCallback("ThisCallback", "", ParamCount, index)
}
ThisCallback( param01 = "", param02 = "", param03 = "", param04 = "", param05 = "", param06 = "", param07 = "", param08 = ""
, param09 = "", param10 = "", param11 = "", param12 = "", param13 = "", param14 = "", param15 = "", param16 = ""
, param17 = "", param18 = "", param19 = "", param20 = "", param21 = "", param22 = "", param23 = "", param24 = ""
, param25 = "", param26 = "", param27 = "", param28 = "", param29 = "", param30 = "", param31 = "")
{
global ThisCallbackTracker
this_info := ThisCallbackTracker[A_EventInfo]
;debug.write("ThisCallback: " A_EventInfo " " this_info.your_this " " this_info.FunctionName)
;debug.write(" params: " param01 " " param02 " " param03 " " param04 " " param05 " " param06 " " param07 " " param08 " "param09 " " param10 " " param11 " " param12 " " param13 " " param14 " " param15 " " param16 " " param17 " " param18 " " param19 " " param20 " " param21 " " param22 " " param23 " " param24 " " param25 " " param26 " " param27 " " param28 " " param29 " " param30 " " param31)
Object(this_info.your_this)[this_info.FunctionName]( param01, param02, param03, param04, param05, param06, param07, param08
, param09, param10, param11, param12, param13, param14, param15, param16
, param17, param18, param19, param20, param21, param22, param23, param24
, param25, param26, param27, param28, param29, param30, param31)
}
IndexOf(array, value, itemProperty = "")
{
local i, item
for i, item in array
{
if ((itemProperty <> "" && item[itemProperty] = value) || item = value)
{
return i
}
}
return 0
}
Max(a, b)
{
return a > b ? a : b
}
Join(separator, items*)
{
local i, item, joined
joined := ""
for i, item in items
{
joined := joined item separator
}
return SubStr(joined, 1, -1 * StrLen(separator))
}