-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathdesktopChanger.ahk
95 lines (84 loc) · 2.2 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
class JPGIncDesktopChangerClass
{
goToDesktopCallbackFunctionName := "goToDesktop"
nextDesktopFunctionName := "goToNextDesktop"
PreviousDesktopFunctionName := "goToPreviousDesktop"
postGoToDesktopFunctionName := ""
__new()
{
this.DllWindowMover := new JPGIncDllWindowMover()
this.desktopMapper := new DesktopMapperClass(new VirtualDesktopManagerClass())
Gui, destkopChanginGUI: new,
Gui, destkopChanginGUI: -caption,
Gui, destkopChanginGUI: -SysMenu,
return this
}
goToNextDesktop(keyCombo := "")
{
currentDesktop := this.desktopMapper.getDesktopNumber()
return this.goToDesktop(currentDesktop + 1)
}
goToPreviousDesktop(keyCombo := "")
{
currentDesktop := this.desktopMapper.getDesktopNumber()
return this.goToDesktop(currentDesktop - 1)
}
/*
* swap to the given virtual desktop number
*/
goToDesktop(newDesktopNumber, activateWindow := true)
{
debugger("in go to desktop changing to " newDesktopNumber)
this._makeDesktopsIfRequired(newDesktopNumber)
._goToDesktop(newDesktopNumber)
this.doPostGoToDesktop(activateWindow)
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)
WinActivate, ahk_class Shell_TrayWnd
Gui destkopChanginGUI: show, W0 H0
Gui destkopChanginGUI: hide,
; wait a bit for the desktop to changes
sleep 50
}
return this
}
doPostGoToDesktop(activateWindow)
{
if(activateWindow)
{
this._activateTopMostWindow()
}
callFunction(this.postGoToDesktopFunctionName)
return this
}
_activateTopMostWindow()
{
windowID := activeWindowOnCurrentDesktop()
if(windowID)
{
WinActivate, % "ahk_id " windowID
}
return this
}
_doesDesktopHaveFocus()
{
;CabinetWClass is file explorer
return WinActive("ahk_exe explorer.exe") && ! WinActive("ahk_class CabinetWClass")
}
}