pyvda icon indicating copy to clipboard operation
pyvda copied to clipboard

`test_create_and_remove_desktop`: Revert original focus

Open stdedos opened this issue 1 year ago • 2 comments

When using current_desktop.go(), in 18363, the focus is not restored to the original window

Signed-off-by: Stavros Ntentos [email protected]

stdedos avatar Feb 29 '24 10:02 stdedos

Is this a problem for normal usage? e.g. When you change desktops using go, does the focus get left behind? I remember this used to happen sometimes but seems to have been fixed on later Windows versions

mirober avatar Mar 02 '24 16:03 mirober

No, that's not it. Switching to a new desktop, "naturally" has no window to focus. Then, "for some reason", when coming back, there is no restored focus.

If I just switch back-and-forth from desktops that have windows, it works.

If I switch to an existing desktop that has no windows, it still works:

Python 3.11.8 (tags/v3.11.8:db85d51, Feb  6 2024, 22:03:32) [MSC v.1937 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.22.2 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from pyvda import (
   ...:     AppView,
   ...:     VirtualDesktop,
   ...:     get_virtual_desktops,
   ...:     get_apps_by_z_order,
   ...: )
   ...: import pprint
   ...: from win32gui import GetWindowText, GetForegroundWindow
   ...: import time
   ...:

In [2]:
   ...: pprint.pprint([GetWindowText(a.hwnd) for a in get_apps_by_z_order()])
   ...: print("Now focused on: ", end="")
   ...: print(GetWindowText(GetForegroundWindow()))
   ...: VirtualDesktop(3).go()
   ...: time.sleep(1)
   ...: pprint.pprint([GetWindowText(a.hwnd) for a in get_apps_by_z_order()])
   ...: print("Now focused on: ", end="")
   ...: print(GetWindowText(GetForegroundWindow()))
   ...: VirtualDesktop(1).go()
   ...: time.sleep(1)
   ...: pprint.pprint([GetWindowText(a.hwnd) for a in get_apps_by_z_order()])
   ...: print("Now focused on: ", end="")
   ...: print(GetWindowText(GetForegroundWindow()))
['IPython: E:pyvda/pyvda',
 'Extensions - Refined GitHub - Google Chrome']
Now focused on: IPython: E:pyvda/pyvda
[]
Now focused on:
['IPython: E:pyvda/pyvda',
 'Extensions - Refined GitHub - Google Chrome']
Now focused on: IPython: E:pyvda/pyvda

stdedos avatar Mar 04 '24 20:03 stdedos