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

sws: Wrong window is selected when unfocused window requests to be the foreground window and the OS denies the request #1084

Closed
valinet opened this issue May 17, 2022 · 3 comments
Labels
Bug Something isn't working fixed

Comments

@valinet
Copy link
Owner

valinet commented May 17, 2022

From: Onur Er onurer@gmail.com
Date: Mon, 16 May 2022 20:52:16 -0700
Message-ID: CAE99sRy4AwFUOM-yYPDow1vPKQ=DJMXLD5ii8cn4Xmb0UiOy2Q@mail.gmail.com
Subject: Explorer Patcher Bug Report (kind of)
To: valentingabrielradu@gmail.com
Content-Type: multipart/related; boundary="000000000000b19f2805df2d1147"

--000000000000b19f2805df2d1147
Content-Type: multipart/alternative; boundary="000000000000b19f2605df2d1146"

--000000000000b19f2605df2d1146
Content-Type: text/plain; charset="UTF-8"

Hello.

First of all, thank you for your great work for making this patch
available. You are a lifesaver.

I was going to report this bug in the discussions section but for some
reason, I couldn't find the "create/new discussion" button so I had to
email you directly.

There is a bug(or a big annoyance) in the Simple Window Switcher which none
of the other switchers has.

It shows the flashing window as the first window always even if the window
itself is not the first window.

image

When I took this screenshot, Before I pressed Alt+Tab, the active window
was Chrome (The Settlement page) and Heroes Of the Storm was in the
background but it was flashing on the taskbar due to the game trying to
notify me about an in-game event.

When I press alt-tab, as you can see, the active window (chrome) isn't
listed as the first window (as opposed to all other switchers). Instead the
flashing game window is listed as the first window. If I stop holding Alt
key, The switcher disappears and I am left with the already active window
which was Chrome.

So, pressing Alt+Tab actually did nothing.

Instead it should have switched to the next window. This is the default
behaviour of Windows and all other switchers you list in the Properties
window.

Do you think this problem can be fixed in Simple Task Switcher?

Basically, we don't need to see the flashing effect and the flashing window
shouldn't be listed as the first window when it's a background window
(non-active window).

Thank you very much.

@valinet valinet added Bug Something isn't working investigating labels May 17, 2022
valinet added a commit to valinet/sws that referenced this issue May 17, 2022
@valinet
Copy link
Owner Author

valinet commented May 17, 2022

Hi,

I was going to report this bug in the discussions section but for some reason, I couldn't find the "create/new discussion" button so I had to email you directly.

Thanks for the report. The discussions forum is read-only at the moment due to reasons listed at #1068.

Basically, we don't need to see the flashing effect and the flashing window shouldn't be listed as the first window when it's a background window (non-active window).

No, flashing windows in sws is actual functionality of the switcher, "we" need it, it won't be discarded just because of this potential bug.

There is a bug(or a big annoyance) in the Simple Window Switcher [...]

Yeah, I have looked on it and was able to reproduce this behavior, it indeed is a bug. When an application wants to have the foreground window, either of these 2 things can happen:

  1. The request is granted.

  2. The request is denied. When this happens, Windows flashes the taskbar button in order to alert the user that the application requires attention.

The system has a complex set of conditions to determine whether to grant the request, so as to prevent bad behaving applications from stealing the focus when the user is working on different tasks.

sws subscribes to foreground window change requests, but it unfortunately assumed that all requests were granted, or, rather, updated the last use time of the respective window each time a request was made about it, regardless of whether the system actually granted or denied the request. This is obviously wrong and is what was generating the issue you described in the email. In my test case, what I did was code a small app that opens a window, then I open a context menu while the app waits 2 seconds, and then the app requests the system to foreground that window. It indeed failed the same way you described in the situation. The fix was to check whether the system granted the request (the foreground window actually became the respective window) when the switcher is notified that the foreground window changed, so as not to update the order if the request was denied, so the actual order di not change. This seems to elegantly fix this problem.

Going on the footsteps regarding this bug, I also thought about yet another problematic case: a window spawning randomly on the desktop, while working in another application. This can happen under rare circumstances, but it nevertheless can happen. The stock Alt-Tab seems to place it rather randomly somewhere in the window stack, not affecting the current and previously used application displayed by the list, so that quickly alt-tabbing still works logically, between the last 2 apps you interacted with. For sws, I decided to place windows created under such circumstances (which were not actually active at any point) at the end of the list, eventually flashing if the system deems so to be appropriate.

These changes are all contained in pre-releases starting with 22000.675.45.1, which you can test by right clicking the taskbar - Properties - Updates, check "Receieve pre-release versions, if available", then click "Update program and restart File Explorer". It should be fixed considering the changes I have made.

Thank you very much for the report.

@valinet
Copy link
Owner Author

valinet commented May 17, 2022

From: Onur Er onurer@gmail.com
Date: Tue, 17 May 2022 13:11:16 -0700
Message-ID: CAE99sRws=XfXF6FkzP50DuG=aA5Zn9PQZ7sk7aAcHX0KXb7Z9Q@mail.gmail.com
Subject: Re: Explorer Patcher Bug Report (kind of)
To: Valentin Radu valentingabrielradu@gmail.com
Content-Type: multipart/related; boundary="000000000000c2fd2d05df3abe40"

--000000000000c2fd2d05df3abe40
Content-Type: multipart/alternative; boundary="000000000000c2fd2b05df3abe3f"

--000000000000c2fd2b05df3abe3f
Content-Type: text/plain; charset="UTF-8"

Thank you for the detailed explanation.

I'm sorry to hear about the problems you had with the community on GitHub. I hope you feel better and open the public discussions in the future but even if you can't do that, please know that you are a hero for many people protecting them against the serious cruelty of Microsoft.

Yea. Flashing behaviour in SWS is cool actually and it matches the flashing of taskbar buttons. As long as the "first window" bug is fixed, flashing in SWS is very welcome.

I'm familiar with the "a window requesting to be foreground and it being granted or denied" system. On my windows, they are always denied so they always flash. Again, thanks for the detailed explanation.

It's awesome that you were able to repro the bug to fix it quickly. I tested it on the pre-release version and it works great. I'm able to switch to the flashing app easily now.

Thank you very much for everything!

@valinet
Copy link
Owner Author

valinet commented May 17, 2022

Thanks for the confirmation, that sounds great, I am glad that it is fixed. A slight oversight, should have not been there in the first place, but it's hard to catch everything with the limited amount of testing that I do. At least, as you said, I was able to reproduce and eventually develop a fix for it.

Thank you for the kind words as well. Yeah, I dislike the recent changes to Windows as well; I hope that the kind of patches that ExplorerPatcher does can be maintained well in the future.

As for discussions on GitHub, to be honest, I do not plan on opening them again anymore. As it stands right now, people can contact me by email just fine, but by the nature of email, things are much more organized and I receive way less messages, to the point where it isn't taking up my entire life anymore. On GitHub, I hoped for more developer engagement, yet the project failed to attract a sensible amount of third party contributions, so I don't really see a point in keeping it open to the public. The way it is right now allows me to better manage the issue tracker and only have there what is actually problematic, so to speak. As I said, this doesn't mean no communication whatsoever, email being a perfectly fine channel for doing so. I do not have much free time anymore to work on ExplorerPatcher, but hope I will be able (maybe with the help of the community) to maintain it and keep it going on the next major OS build(s) as well.

Thanks again for the support.

Kind regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

1 participant