forked from jpginc/windows10DesktopManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesktopChanger.ahk
103 lines (93 loc) · 2.55 KB
/
desktopChanger.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
class JPGIncDesktopChangerClass
{
goToDesktopCallbackFunctionName := "goToDesktop"
nextDesktopFunctionName := "goToNextDesktop"
PreviousDesktopFunctionName := "goToPreviousDesktop"
postGoToDesktopFunctionName := ""
__new()
{
this.DllWindowMover := new JPGIncDllWindowMover()
this.desktopMapper := new DesktopMapperClass(new VirtualDesktopManagerClass())
Gui, destkopChanginGUI: new,
return this
}
goToNextDesktop(keyCombo := "")
{
send("^#{right}")
return this.doPostGoToDesktop()
}
goToPreviousDesktop(keyCombo := "")
{
send("^#{left}")
return this.doPostGoToDesktop()
}
/*
* swap to the given virtual desktop number
*/
goToDesktop(newDesktopNumber)
{
debugger("in go to desktop changing to " newDesktopNumber)
this._makeDesktopsIfRequired(newDesktopNumber)
._goToDesktop(newDesktopNumber)
this.doPostGoToDesktop()
return this
}
_makeDesktopsIfRequired(minimumNumberOfDesktops)
{
currentNumberOfDesktops := this.desktopMapper.getNumberOfDesktops()
loop, % minimumNumberOfDesktops - currentNumberOfDesktops
{
send("#^d")
}
return this
}
_goToDesktop(newDesktopNumber)
{
if(this.DllWindowMover.isAvailable())
{
Gui destkopChanginGUI: show, W0 H0
Gui destkopChanginGUI: +HwnddesktopChangingGuiHwnd
this.DllWindowMover.moveWindowToDesktop(newDesktopNumber, desktopChangingGuiHwnd)
;doing 2 win shows doesn't appear to change desktops
WinActivate, ahk_class Shell_TrayWnd
Gui destkopChanginGUI: show, W0 H0
Gui destkopChanginGUI: hide,
} else
{
currentDesktop := this.desktopMapper.getDesktopNumber()
direction := currentDesktop - newDesktopNumber
distance := Abs(direction)
debugger("distance to move is " distance "`ndirectin" direction)
if(direction < 0)
{
debugger("Sending right! " distance "times")
send("^#{right " distance "}")
} else
{
send("^#{left " distance "}")
}
}
return this
}
doPostGoToDesktop()
{
this._activateTopMostWindow()
callFunction(this.postGoToDesktopFunctionName)
return this
}
_activateTopMostWindow()
{
;if the desktop has focus before changing virtual desktops then the top most window isn't activated on the new desktop
;so check if the desktop has focus after switching to a new one. if it does send an alt + tab to focus the window on that desktop
If(this._doesDesktopHaveFocus() && ! isMultiTaskingViewActive())
{
send !{tab}
}
return this
}
_doesDesktopHaveFocus()
{
;CabinetWClass is file explorer
return WinActive("ahk_exe explorer.exe") && ! WinActive("ahk_class CabinetWClass")
}
}