forked from jpginc/windows10DesktopManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitorMapper.ahk
50 lines (46 loc) · 1.39 KB
/
monitorMapper.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
;taken from optimist__prime https://autohotkey.com/boards/viewtopic.php?t=9224
class MonitorMapperClass
{
; This part figures out how many times we need to hit Tab to get to the
; monitor with the window we are trying to send to another desktop.
getRequiredTabCount(hwnd)
{
activemonitor := this.getWindowsMonitorNumber(hwnd)
SysGet, monitorcount, MonitorCount
SysGet, primarymonitor, MonitorPrimary
If (activemonitor > primarymonitor)
{
tabCount := activemonitor - primarymonitor
}
else If (activemonitor < primarymonitor)
{
tabCount := monitorcount - primarymonitor + activemonitor
}
else
{
tabCount := 0
}
tabCount *= 2
return tabCount
}
/*
* This function returns the monitor number of the window with the given hwnd
*/
getWindowsMonitorNumber(hwnd)
{
WinGetPos, x, y, width, height, % "Ahk_id" hwnd
debugger("Window Position/Size:`nX: " X "`nY: " Y "`nWidth: " width "`nHeight: " height)
SysGet, monitorcount, MonitorCount
SysGet, primarymonitor, MonitorPrimary
debugger("Monitor Count: " MonitorCount)
Loop %monitorcount%
{
SysGet, mon, Monitor, %a_index%
debugger("Primary Monitor: " primarymonitor "`nDistance between monitor #" a_index "'s right border and Primary monitor's left border (Left < 0, Right > 0):`n" monRight "px")
If (x < monRight - width / 2 || monitorcount = a_index)
{
return %a_index%
}
}
}
}