|
1 | 1 | from dragonfly import Window, Key |
2 | 2 | from ctypes import windll |
3 | | -# https://github.com/mrob95/py-VirtualDesktopAccessor |
| 3 | + |
| 4 | +# https://github.com/mirober/pyvda |
4 | 5 | try: |
5 | | - import pyvda # pylint: disable=import-error |
| 6 | + from pyvda import VirtualDesktop, AppView, get_virtual_desktops # pylint: disable=import-error |
6 | 7 | except Exception as e: |
7 | 8 | # This could fail on linux or windows <10 |
8 | 9 | print("Importing package pyvda failed with exception %s" % str(e)) |
9 | 10 |
|
10 | 11 | ASFW_ANY = -1 |
11 | 12 |
|
12 | | - |
13 | 13 | def go_to_desktop_number(n): |
14 | 14 | # Helps make sure that the target desktop gets focus |
15 | 15 | windll.user32.AllowSetForegroundWindow(ASFW_ANY) |
16 | | - pyvda.GoToDesktopNumber(n) |
17 | | - |
| 16 | + VirtualDesktop(n).go() |
18 | 17 |
|
19 | 18 | 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)) |
22 | 21 | if follow: |
23 | 22 | go_to_desktop_number(n) |
24 | 23 |
|
25 | | - |
26 | 24 | 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() |
0 commit comments