Skip to content

Commit

Permalink
_activateWindowUnderFilterVD; #39
Browse files Browse the repository at this point in the history
  • Loading branch information
FuPeiJiang committed May 22, 2023
1 parent 5862e5e commit 7c0a466
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions _VD.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -237,31 +237,30 @@ class VD {
}

goToDesktopNum(desktopNum) { ; Lej77 https://github.com/Grabacr07/VirtualDesktop/pull/23#issuecomment-334918711
Gui VD_animation_gui:New, % "-Border -SysMenu +Owner -Caption +HwndVD_animation_gui_hwnd"
IVirtualDesktop := this._GetDesktops_Obj().GetAt(desktopNum)
GetId:=this._vtable(IVirtualDesktop, 4)
VarSetCapacity(GUID_Desktop, 16)
DllCall(GetId, "Ptr", IVirtualDesktop, "Ptr", &GUID_Desktop)
DllCall(this.MoveWindowToDesktop, "Ptr", this.IVirtualDesktopManager, "Ptr", VD_animation_gui_hwnd, "Ptr", &GUID_Desktop)

Gui VD_active_gui:New, % "-Border -SysMenu +Owner -Caption +HwndVD_active_gui_hwnd"
DllCall("ShowWindow","Ptr",VD_active_gui_hwnd,"Int",1) ;you can only Show gui that's in another VD if a gui of same owned/process is already active


this._WinActivateForceForceForce(VD_active_gui_hwnd) ;specifically for Teams.exe

DllCall("ShowWindow","Ptr",VD_animation_gui_hwnd,"Int",1) ;after gui on current desktop owned by current process became active window, Show gui on different desktop owned by current process
targetEmpty:=false
if (this._activateWindowUnderFilterVD(desktopNum)==-1) {
targetEmpty:=true
Gui VD_animation_gui:New, % "-Border -SysMenu +Owner -Caption +HwndVD_animation_gui_hwnd"
IVirtualDesktop := this._GetDesktops_Obj().GetAt(desktopNum)
GetId:=this._vtable(IVirtualDesktop, 4)
VarSetCapacity(GUID_Desktop, 16)
DllCall(GetId, "Ptr", IVirtualDesktop, "Ptr", &GUID_Desktop)
DllCall(this.MoveWindowToDesktop, "Ptr", this.IVirtualDesktopManager, "Ptr", VD_animation_gui_hwnd, "Ptr", &GUID_Desktop)
DllCall("ShowWindow","Ptr",VD_animation_gui_hwnd,"Int",1) ;after gui on current desktop owned by current process became active window, Show gui on different desktop owned by current process
}
loop 20 {
if (this.getCurrentDesktopNum()==desktopNum) { ; wildest hack ever..

; "ahk_class TPUtilWindow ahk_exe HxD.exe" instead of "ahk_class WorkerW ahk_exe explorer.exe"
if (this._activateWindowUnder(VD_animation_gui_hwnd)==-1) {
if (targetEmpty) {
this._activateDesktopBackground()
Gui VD_animation_gui:Destroy
}

Gui VD_animation_gui:Destroy
Gui VD_active_gui:Destroy

break
}
Sleep 25
Expand Down Expand Up @@ -893,6 +892,29 @@ class VD {
DllCall("SetForegroundWindow","Ptr",WinExist("ahk_class Progman ahk_exe explorer.exe"))
}

_activateWindowUnderFilterVD(desktopNum) {
bak_DetectHiddenWindows:=A_DetectHiddenWindows
DetectHiddenWindows, on
returnValue:=-1
WinGet, outHwndList, List
loop % outHwndList {
theHwnd:=outHwndList%A_Index%
if (pView:=this._isValidWindow(theHwnd)) {
WinGet, OutputVar_MinMax, MinMax, % "ahk_id " theHwnd
if (!(OutputVar_MinMax==-1)) { ;not Minimized
if (this._desktopNum_from_Hwnd(theHwnd) == desktopNum) {
; WinActivate % "ahk_id " theHwnd
DllCall("SetForegroundWindow","Ptr",theHwnd)
returnValue:=theHwnd
break
}
}
}
}
DetectHiddenWindows % bak_DetectHiddenWindows
return returnValue
}

_activateWindowUnder(excludeHwnd:=-1) {
bak_DetectHiddenWindows:=A_DetectHiddenWindows
DetectHiddenWindows, off
Expand Down

0 comments on commit 7c0a466

Please sign in to comment.