@@ -62,7 +62,6 @@ class VD {
62
62
; conditionally assign method to method
63
63
this._dll_GetCurrentDesktop:=this._dll_GetCurrentDesktop_Win10
64
64
this._dll_GetDesktops:=this._dll_GetDesktops_Win10
65
- this._dll_SwitchDesktop:=this._dll_SwitchDesktop_Win10
66
65
this._dll_CreateDesktop:=this._dll_CreateDesktop_Win10
67
66
this._dll_GetName:=this._dll_GetName_Win10
68
67
this.RegisterDesktopNotifications:=this.RegisterDesktopNotifications_Win10
@@ -75,7 +74,6 @@ class VD {
75
74
; conditionally assign method to method
76
75
this._dll_GetCurrentDesktop:=this._dll_GetCurrentDesktop_Win11
77
76
this._dll_GetDesktops:=this._dll_GetDesktops_Win11
78
- this._dll_SwitchDesktop:=this._dll_SwitchDesktop_Win11
79
77
this._dll_CreateDesktop:=this._dll_CreateDesktop_Win11
80
78
this._dll_GetName:=this._dll_GetName_Win11
81
79
this.RegisterDesktopNotifications:=this.RegisterDesktopNotifications_Win11
@@ -98,7 +96,7 @@ class VD {
98
96
99
97
this.GetDesktops := this._vtable(this.IVirtualDesktopManagerInternal, 7 ) ; void GetDesktops(out IObjectArray desktops);
100
98
; this.GetAdjacentDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 8) ; int GetAdjacentDesktop(IVirtualDesktop from, int direction, out IVirtualDesktop desktop);
101
- this.SwitchDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 9 ) ; void SwitchDesktop(IVirtualDesktop desktop);
99
+ ; this.SwitchDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 9) ; void SwitchDesktop(IVirtualDesktop desktop);
102
100
this.Ptr_CreateDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 10 ) ; IVirtualDesktop CreateDesktop();
103
101
this.Ptr_RemoveDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 11 ) ; void RemoveDesktop(IVirtualDesktop desktop, IVirtualDesktop fallback);
104
102
this.FindDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 12 ) ; IVirtualDesktop FindDesktop(ref Guid desktopid);
@@ -107,7 +105,7 @@ class VD {
107
105
108
106
this.GetDesktops := this._vtable(this.IVirtualDesktopManagerInternal, 7 ) ; void GetDesktops(IntPtr hWndOrMon, out IObjectArray desktops);
109
107
; this.GetAdjacentDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 8) ; int GetAdjacentDesktop(IVirtualDesktop from, int direction, out IVirtualDesktop desktop);
110
- this.SwitchDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 9 ) ; void SwitchDesktop(IntPtr hWndOrMon, IVirtualDesktop desktop);
108
+ ; this.SwitchDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 9) ; void SwitchDesktop(IntPtr hWndOrMon, IVirtualDesktop desktop);
111
109
this.Ptr_CreateDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 10 ) ; IVirtualDesktop CreateDesktop(IntPtr hWndOrMon);
112
110
; this.MoveDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 11) ; void MoveDesktop(IVirtualDesktop desktop, IntPtr hWndOrMon, int nIndex);
113
111
this.Ptr_RemoveDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 12 ) ; void RemoveDesktop(IVirtualDesktop desktop, IVirtualDesktop fallback);
@@ -118,7 +116,7 @@ class VD {
118
116
; this.GetAllCurrentDesktops := this._vtable(this.IVirtualDesktopManagerInternal, 7) ; IObjectArray GetAllCurrentDesktops();
119
117
this.GetDesktops := this._vtable(this.IVirtualDesktopManagerInternal, 8 ) ; void GetDesktops(IntPtr hWndOrMon, out IObjectArray desktops);
120
118
; this.GetAdjacentDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 9) ; int GetAdjacentDesktop(IVirtualDesktop from, int direction, out IVirtualDesktop desktop);
121
- this.SwitchDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 10 ) ; void SwitchDesktop(IntPtr hWndOrMon, IVirtualDesktop desktop);
119
+ ; this.SwitchDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 10) ; void SwitchDesktop(IntPtr hWndOrMon, IVirtualDesktop desktop);
122
120
this.Ptr_CreateDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 11 ) ; IVirtualDesktop CreateDesktop(IntPtr hWndOrMon);
123
121
; this.MoveDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 12) ; void MoveDesktop(IVirtualDesktop desktop, IntPtr hWndOrMon, int nIndex);
124
122
this.Ptr_RemoveDesktop := this._vtable(this.IVirtualDesktopManagerInternal, 13 ) ; void RemoveDesktop(IVirtualDesktop desktop, IVirtualDesktop fallback);
@@ -183,12 +181,6 @@ class VD {
183
181
DllCall (this.GetDesktops, " UPtr" , this.IVirtualDesktopManagerInternal, " Ptr" , 0 , " UPtr*" , IObjectArray)
184
182
return IObjectArray
185
183
}
186
- _dll_SwitchDesktop_Win10 (IVirtualDesktop ) {
187
- DllCall (this.SwitchDesktop, " ptr" , this.IVirtualDesktopManagerInternal, " UPtr" , IVirtualDesktop)
188
- }
189
- _dll_SwitchDesktop_Win11 (IVirtualDesktop ) {
190
- DllCall (this.SwitchDesktop, " ptr" , this.IVirtualDesktopManagerInternal, " Ptr" , 0 , " UPtr" , IVirtualDesktop)
191
- }
192
184
_dll_CreateDesktop_Win10 () {
193
185
IVirtualDesktop_ofNewDesktop:=0
194
186
DllCall (this.Ptr_CreateDesktop, " UPtr" , this.IVirtualDesktopManagerInternal, " Ptr*" , IVirtualDesktop_ofNewDesktop)
@@ -244,26 +236,30 @@ class VD {
244
236
return this._GetDesktops_Obj().GetCount()
245
237
}
246
238
247
- goToDesktopNum (desktopNum ) {
248
- IVirtualDesktop:=this._GetDesktops_Obj().GetAt(desktopNum)
249
- this._SwitchIVirtualDesktop(IVirtualDesktop)
239
+ goToDesktopNum (desktopNum ) { ; Lej77 https://github.com/Grabacr07/VirtualDesktop/pull/23#issuecomment-334918711
240
+ Gui VD_animation_gui:New, % " -Border -SysMenu +Owner -Caption +HwndVD_animation_gui_hwnd"
241
+ IVirtualDesktop := this._GetDesktops_Obj().GetAt(desktopNum)
242
+ GetId:=this._vtable(IVirtualDesktop, 4 )
243
+ VarSetCapacity (GUID_Desktop, 16 )
244
+ DllCall (GetId, " Ptr" , IVirtualDesktop, " Ptr" , & GUID_Desktop)
245
+ DllCall (this.MoveWindowToDesktop, " Ptr" , this.IVirtualDesktopManager, " Ptr" , VD_animation_gui_hwnd, " Ptr" , & GUID_Desktop)
246
+ Gui VD_animation_gui:Show
247
+ Sleep 100
248
+ Gui VD_animation_gui:Destroy
249
+ ; "ahk_class TPUtilWindow ahk_exe HxD.exe" instead of "ahk_class WorkerW ahk_exe explorer.exe"
250
+ Sleep 50
251
+ if (activeHwnd:=WinExist (" A" )) {
252
+ if (! this._isValidWindow(activeHwnd)) {
253
+ if (this._activateWindowUnder()==- 1 ) {
254
+ WinActivate % " ahk_class WorkerW ahk_exe explorer.exe"
255
+ }
256
+ }
250
257
251
- if (this._isWindowFullScreen(" A" )) {
252
- timerFunc := ObjBindMethod(this, " _pleaseSwitchDesktop" , desktopNum) ; https://www.autohotkey.com/docs/commands/SetTimer.htm#ExampleClass
253
- SetTimer % timerFunc, - 50
258
+ } else {
259
+ if (this._activateWindowUnder()==- 1 ) {
260
+ WinActivate % " ahk_class WorkerW ahk_exe explorer.exe"
261
+ }
254
262
}
255
-
256
- }
257
- animationToDesktopNum (desktopNum ) { ; Lej77 https://github.com/Grabacr07/VirtualDesktop/pull/23#issuecomment-334918711
258
- Gui VD_animation_gui:New, % " -Border -SysMenu +Owner -Caption +HwndVD_animation_gui_hwnd"
259
- IVirtualDesktop := this._GetDesktops_Obj().GetAt(desktopNum)
260
- GetId:=this._vtable(IVirtualDesktop, 4 )
261
- VarSetCapacity (GUID_Desktop, 16 )
262
- DllCall (GetId, " Ptr" , IVirtualDesktop, " Ptr" , & GUID_Desktop)
263
- DllCall (this.MoveWindowToDesktop, " Ptr" , this.IVirtualDesktopManager, " Ptr" , VD_animation_gui_hwnd, " Ptr" , & GUID_Desktop)
264
- Gui VD_animation_gui:Show
265
- Sleep 100
266
- Gui VD_animation_gui:Destroy
267
263
}
268
264
269
265
_getLocalizedWord_Desktop () {
@@ -311,18 +307,27 @@ class VD {
311
307
}
312
308
}
313
309
314
- MoveWindowToDesktopNum(wintitle, desktopNum)
315
- {
310
+ MoveWindowToDesktopNum (wintitle, desktopNum ) {
316
311
found:=this._getFirstValidWindow(wintitle)
317
312
if (! found) {
318
313
return - 1 ; for false
319
314
}
320
315
theHwnd:=found[1 ]
321
316
thePView:=found[2 ]
322
317
318
+ needActivateWindowUnder:=False
319
+ if (activeHwnd:=WinExist (" A" )) {
320
+ if (activeHwnd==theHwnd) {
321
+ needActivateWindowUnder:=true
322
+ }
323
+ }
324
+
323
325
IVirtualDesktop:=this._GetDesktops_Obj().GetAt(desktopNum)
326
+ DllCall (this.MoveViewToDesktop, " ptr" , this.IVirtualDesktopManagerInternal, " Ptr" , thePView, " Ptr" , IVirtualDesktop)
324
327
325
- this._MoveView_to_IVirtualDesktop(thePView, IVirtualDesktop)
328
+ if (needActivateWindowUnder) {
329
+ this._activateWindowUnder()
330
+ }
326
331
}
327
332
328
333
getRelativeDesktopNum(anchor_desktopNum, relative_count)
@@ -357,8 +362,7 @@ class VD {
357
362
this.goToDesktopNum(this.getRelativeDesktopNum(this.getCurrentDesktopNum(), relative_count))
358
363
}
359
364
360
- MoveWindowToCurrentDesktop(wintitle, activateYourWindow:=true )
361
- {
365
+ MoveWindowToCurrentDesktop (wintitle, activateYourWindow:=true ) {
362
366
found:=this._getFirstValidWindow(wintitle)
363
367
if (! found) {
364
368
return - 1 ; for false
@@ -369,7 +373,7 @@ class VD {
369
373
currentDesktopNum:=this.getCurrentDesktopNum()
370
374
IVirtualDesktop:=this._GetDesktops_Obj().GetAt(currentDesktopNum)
371
375
372
- this._MoveView_to_IVirtualDesktop( thePView, IVirtualDesktop)
376
+ DllCall ( this.MoveViewToDesktop, " ptr " , this.IVirtualDesktopManagerInternal, " Ptr " , thePView, " Ptr " , IVirtualDesktop)
373
377
374
378
if (activateYourWindow) {
375
379
WinActivate % " ahk_id " theHwnd
@@ -796,28 +800,6 @@ class VD {
796
800
; actual methods end
797
801
798
802
; internal methods start
799
- _MoveView_to_IVirtualDesktop (thePView, IVirtualDesktop ) {
800
- DllCall (this.MoveViewToDesktop, " ptr" , this.IVirtualDesktopManagerInternal, " Ptr" , thePView, " Ptr" , IVirtualDesktop)
801
- DllCall (this.MoveViewToDesktop, " ptr" , this.IVirtualDesktopManagerInternal, " Ptr" , thePView, " Ptr" , IVirtualDesktop)
802
- this._activateWindowUnder()
803
- }
804
- _SwitchIVirtualDesktop (IVirtualDesktop ) {
805
- ; activate taskbar before ;https://github.com/mzomparelli/zVirtualDesktop/issues/59#issuecomment-317613971
806
- WinActivate , ahk_class Shell_TrayWnd
807
- WinWaitActive , ahk_class Shell_TrayWnd
808
-
809
- this._dll_SwitchDesktop(IVirtualDesktop)
810
- this._dll_SwitchDesktop(IVirtualDesktop)
811
- this._activateWindowUnder()
812
- }
813
-
814
- _pleaseSwitchDesktop (desktopNum ) {
815
- ; IVirtualDesktop should be calculated again because IVirtualDesktop could have changed
816
- ; what we want is the same desktopNum
817
- IVirtualDesktop:=this._GetDesktops_Obj().GetAt(desktopNum)
818
- this._SwitchIVirtualDesktop(IVirtualDesktop)
819
- ; this method is goToDesktopNum(), but without the recursion, to prevent recursion
820
- }
821
803
822
804
_activateWindowUnder () {
823
805
; if this doesn't work
0 commit comments