Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions pyvda/com_defns.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
* http://grabacr.net/archives/5601
* https://www.cyberforum.ru/blogs/105416/blog3671.html
"""
import os
import sys
from ctypes import HRESULT, POINTER, c_ulonglong
from ctypes.wintypes import (
BOOL,
Expand Down Expand Up @@ -205,7 +203,6 @@ class IVirtualDesktopManagerInternal(IUnknown):
COMMETHOD([], HRESULT, "SetWallpaperForAllDesktops", (["in"], HSTRING, "path")),
COMMETHOD([], HRESULT, "CopyDesktopState", (["in"], POINTER(IApplicationView), "pView0"), (["in"], POINTER(IApplicationView), "pView0")),
COMMETHOD([], HRESULT, "CreateRemoteDesktop", (["in"], HSTRING, "a1"), (["out"], POINTER(POINTER(IVirtualDesktop)), "out")),
STDMETHOD(HRESULT, "pDesktop", (POINTER(IVirtualDesktop),)),
STDMETHOD(HRESULT, "SwitchRemoteDesktop", (POINTER(IVirtualDesktop), UINT)),
STDMETHOD(HRESULT, "SwitchDesktopWithAnimation", (POINTER(IVirtualDesktop),)),
COMMETHOD([], HRESULT, "GetLastActiveDesktop", (["out"], POINTER(POINTER(IVirtualDesktop)), "pDesktop"),),
Expand All @@ -230,7 +227,6 @@ class IVirtualDesktopManagerInternal(IUnknown):
COMMETHOD([], HRESULT, "SetWallpaperForAllDesktops", (["in"], HSTRING, "path")),
COMMETHOD([], HRESULT, "CopyDesktopState", (["in"], POINTER(IApplicationView), "pView0"), (["in"], POINTER(IApplicationView), "pView0")),
COMMETHOD([], HRESULT, "CreateRemoteDesktop", (["in"], HSTRING, "a1"), (["out"], POINTER(POINTER(IVirtualDesktop)), "out")),
STDMETHOD(HRESULT, "pDesktop", (POINTER(IVirtualDesktop),)),
STDMETHOD(HRESULT, "SwitchRemoteDesktop", (POINTER(IVirtualDesktop), UINT)),
STDMETHOD(HRESULT, "SwitchDesktopWithAnimation", (POINTER(IVirtualDesktop),)),
COMMETHOD([], HRESULT, "GetLastActiveDesktop", (["out"], POINTER(POINTER(IVirtualDesktop)), "pDesktop"),),
Expand Down Expand Up @@ -361,6 +357,18 @@ def switch_desktop(self, target: IVirtualDesktop) -> IVirtualDesktop:
else:
return self.SwitchDesktop(target) # type: ignore

def switch_desktop_with_animation(self, target: IVirtualDesktop):
"""Switch to a virtual desktop with animation.

Only available on Windows 11 builds 22631 and later.
"""
if build.OVER_22631:
return self.SwitchDesktopWithAnimation(target) # type: ignore
else:
raise NotImplementedError(
"SwitchDesktopWithAnimation is only available on Windows 11 build 22631 and later"
)


GUID_IVirtualDesktopManagerInternal2 = GUID("{0F3A72B0-4566-487E-9A33-4ED302F6D6CE}")
class IVirtualDesktopManagerInternal2(IUnknown):
Expand Down
10 changes: 7 additions & 3 deletions pyvda/pyvda.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, hwnd: Optional[int] = None, view: Optional['IApplicationView'
elif view:
self._view = view
else:
raise Exception(f"Must pass 'hwnd' or 'view'")
raise Exception("Must pass 'hwnd' or 'view'")

def __eq__(self, other):
return self.hwnd == other.hwnd
Expand Down Expand Up @@ -385,18 +385,22 @@ def remove(self, fallback: Optional[VirtualDesktop] = None):
fallback = VirtualDesktop(1)
managers.manager_internal.RemoveDesktop(self._virtual_desktop, fallback._virtual_desktop) # type: ignore

def go(self, allow_set_foreground: bool = True):
def go(self, allow_set_foreground: bool = True, animation: bool = False):
"""Switch to this virtual desktop.

Args:
allow_set_foreground (bool, optional): Call AllowSetForegroundWindow(ASFW_ANY) before switching. This partially fixes an issue where the focus remains behind after switching. Defaults to True.
animation (bool, optional): Use the Windows desktop switching animation. Only available on Windows 11 build 22631 and later. Defaults to False.

Note:
More details at https://github.com/Ciantic/VirtualDesktopAccessor/issues/4 and https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-allowsetforegroundwindow.
"""
if allow_set_foreground:
windll.user32.AllowSetForegroundWindow(ASFW_ANY)
managers.manager_internal.switch_desktop(self._virtual_desktop) # type: ignore
if animation:
managers.manager_internal.switch_desktop_with_animation(self._virtual_desktop) # type: ignore
else:
managers.manager_internal.switch_desktop(self._virtual_desktop) # type: ignore

def apps_by_z_order(self, include_pinned: bool = True) -> List[AppView]:
"""Get a list of AppViews, ordered by their Z position, with
Expand Down