forked from jpginc/windows10DesktopManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
windowMover.ahk
97 lines (86 loc) · 2.34 KB
/
windowMover.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
class JPGIncWindowMoverClass
{
moveActiveWindowToDesktopFunctionName := "moveActiveWindowToDesktop"
moveToNextFunctionName := "moveActiveWindowToNextDesktop"
moveToPreviousFunctionName := "moveActiveWindowToPreviousDesktop"
postMoveWindowFunctionName := ""
followToNewDesktop := false
__new()
{
this.dllWindowMover := new JPGIncDllWindowMover()
this.desktopMapper := new DesktopMapperClass(new VirtualDesktopManagerClass())
this.monitorMapper := new MonitorMapperClass()
return this
}
doPostMoveWindow()
{
callFunction(this.postMoveWindowFunctionName)
return this
}
moveActiveWindowToDesktop(targetDesktop, follow := false)
{
activeHwnd := WinExist("A")
if(this.dllWindowMover.isAvailable())
{
this.dllWindowMover.moveActiveWindowToDesktop(targetDesktop)
} else
{
currentDesktop := this.desktopMapper.getDesktopNumber()
if(currentDesktop == targetDesktop)
{
return this
}
numberOfTabsNeededToSelectActiveMonitor := this.monitorMapper.getRequiredTabCount(WinActive("A"))
numberOfDownsNeededToSelectDesktop := this.getNumberOfDownsNeededToSelectDesktop(targetDesktop, currentDesktop)
openMultitaskingViewFrame()
send("{tab " numberOfTabsNeededToSelectActiveMonitor "}")
send("{Appskey}m{Down " numberOfDownsNeededToSelectDesktop "}{Enter}")
closeMultitaskingViewFrame()
}
this._followWindow(activeHwnd)
.doPostMoveWindow()
return this
}
moveActiveWindowToNextDesktop(follow := false)
{
currentDesktop := this.desktopMapper.getDesktopNumber()
return this.moveActiveWindowToDesktop(currentDesktop + 1, follow)
}
moveActiveWindowToPreviousDesktop(follow := false)
{
currentDesktop := this.desktopMapper.getDesktopNumber()
if(currentDesktop == 1)
{
return this
}
return this.moveActiveWindowToDesktop(currentDesktop - 1, follow)
}
getNumberOfDownsNeededToSelectDesktop(targetDesktop, currentDesktop)
{
; This part figures out how many times we need to push down within the context menu to get the desktop we want.
if (targetDesktop > currentDesktop)
{
targetDesktop -= 2
}
else
{
targetdesktop--
}
return targetDesktop
}
_followWindow(hwnd)
{
if(this.followToNewDesktop)
{
this._deActivateActiveWindow()
WinActivate, % "ahk_id " hwnd
}
return this
}
_deActivateActiveWindow()
{
Gui, new
Gui, Show
Gui, destroy
}
}