Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_create_and_remove_desktop: Revert original focus #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stdedos
Copy link
Contributor

@stdedos stdedos commented Feb 29, 2024

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

Signed-off-by: Stavros Ntentos 133706+stdedos@users.noreply.github.com

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

Signed-off-by: Stavros Ntentos <133706+stdedos@users.noreply.github.com>
@@ -95,6 +95,7 @@ def test_create_and_remove_desktop():

time.sleep(1) # Got to wait for the animation before we can return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think that could be replaced with

STDMETHOD(HRESULT, "WaitForAnimationToComplete"),

?

And/or overload the "future method" with time.sleep(1) on unsupporting platforms?

(However, I wouldn't know how to code that 😅)

@mrob95
Copy link
Owner

mrob95 commented Mar 2, 2024

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

@stdedos
Copy link
Contributor Author

stdedos commented Mar 4, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants