Skip to content

Commit 985ba92

Browse files
authored
Fix virtual desktop switching on Windows 11 by using updated pyvda API (#960)
* Fix virtual desktop switching on Windows 11 by using updated pyvda API
1 parent c296d5d commit 985ba92

3 files changed

Lines changed: 15 additions & 13 deletions

File tree

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
from dragonfly import Window, Key
22
from ctypes import windll
3-
# https://github.com/mrob95/py-VirtualDesktopAccessor
3+
4+
# https://github.com/mirober/pyvda
45
try:
5-
import pyvda # pylint: disable=import-error
6+
from pyvda import VirtualDesktop, AppView, get_virtual_desktops # pylint: disable=import-error
67
except Exception as e:
78
# This could fail on linux or windows <10
89
print("Importing package pyvda failed with exception %s" % str(e))
910

1011
ASFW_ANY = -1
1112

12-
1313
def go_to_desktop_number(n):
1414
# Helps make sure that the target desktop gets focus
1515
windll.user32.AllowSetForegroundWindow(ASFW_ANY)
16-
pyvda.GoToDesktopNumber(n)
17-
16+
VirtualDesktop(n).go()
1817

1918
def move_current_window_to_desktop(n=1, follow=False):
20-
window_handle = Window.get_foreground().handle
21-
pyvda.MoveWindowToDesktopNumber(window_handle, n)
19+
hwnd = Window.get_foreground().handle
20+
AppView(hwnd).move(VirtualDesktop(n))
2221
if follow:
2322
go_to_desktop_number(n)
2423

25-
2624
def close_all_workspaces():
27-
total = pyvda.GetDesktopCount()
28-
go_to_desktop_number(total)
29-
Key("wc-f4/10:" + str(total-1)).execute()
25+
desktops = get_virtual_desktops()
26+
total = len(desktops)
27+
if total <= 1:
28+
print("Only one desktop exists; nothing to close.")
29+
return
30+
go_to_desktop_number(total - 1)
31+
Key("wc-f4/10:" + str(total - 1)).execute()

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ mock>=3.0.5
66
appdirs>=1.4.3
77
scandir>=1.10.0
88
pylint
9-
pyvda==0.0.8
9+
pyvda==0.5.0
1010
PySide2>=5.14
1111
six

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ future>=0.18.2
55
mock>=3.0.5
66
appdirs>=1.4.3
77
scandir>=1.10.0
8-
pyvda==0.0.8
8+
pyvda==0.5.0
99
PySide2>=5.14
1010
six

0 commit comments

Comments
 (0)