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

[PTRun] - only show top window per process in WndWalker #31303

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kice
Copy link

@kice kice commented Feb 5, 2024

Summary of the Pull Request

Add a feature that allow to only show most top window (or "most recent window") for each process in Window Walker.

PR Checklist

  • Closes: #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated
  • New binaries: Added on the required places
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Copy link
Collaborator

@jaimecbernardo jaimecbernardo left a comment

Choose a reason for hiding this comment

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

Thank you for opening the PR.
Can you please sign the CLA?
I'm also checking the diff and many files seem to have lots of file ending changes, is this something you'd be able to fix to make it easier to review?
Thank you, in advance.

@kice
Copy link
Author

kice commented Feb 9, 2024

@microsoft-github-policy-service agree

@kice
Copy link
Author

kice commented Feb 9, 2024

Thank you for opening the PR. Can you please sign the CLA? I'm also checking the diff and many files seem to have lots of file ending changes, is this something you'd be able to fix to make it easier to review? Thank you, in advance.

Sorry for late reply, I think I fixed the line endings.

Copy link
Collaborator

@jaimecbernardo jaimecbernardo left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution. I like how we avoid any performance impact by only running the code if the option is turned on.
However, there are some code quality issues I feel must be addressed. Can you please look into those? Thank you!

@@ -202,4 +202,7 @@
<data name="wox_plugin_windowwalker_SettingSubtitleDesktopName_Description" xml:space="preserve">
<value>This information is only shown in subtitle and tool tip, if you have at least two desktops.</value>
</data>
<data name="wox_plugin_windowwalker_SettingsTopWindowPerProcess" xml:space="preserve">
<value>Only show the top window of each processes.</value>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<value>Only show the top window of each processes.</value>
<value>Only show the top window of each process.</value>

var z = 1;
while (true)
{
hNextWnd = NativeMethods.GetWindow(hNextWnd, GetWindowCmd.GW_HWNDNEXT);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This method seems to have many issues.
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindow#remarks

Also feel uneasy seeing a while(true) in here.
Can you use the EnumChildWindows or EnumWindows as suggested instead?
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumwindows#remarks

Copy link
Author

Choose a reason for hiding this comment

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

The document call for use GetNextWindow, which is implemented as a call to the GetWindow function.

I think EnumChildWindows or EnumWindows do not guarantee the function enumerate in the correct z-order.

Maybe we could add some checks to prevent the infinite loop; but still this could return incomplete results, and we don't need to handle that case.

In the case of incomplete results, I assume the application will use the first window in the result list, and usually be the top window of that process. The users should be able to retry as well, and then likely get the complete result next time.

Ref:
https://stackoverflow.com/questions/295996/is-the-order-in-which-handles-are-returned-by-enumwindows-meaningful

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think EnumChildWindows or EnumWindows do not guarantee the function enumerate in the correct z-order.

It might do it, according to the stack overflow answer you've posted:

image

We'd prefer going with a solution that the documentation doesn't point out as unreliable 😉 . Does this make sense to you?

@jaimecbernardo jaimecbernardo added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Mar 12, 2024

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 7 changed files in this pull request and generated no comments.

Files not reviewed (2)
  • src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Properties/Resources.Designer.cs: Language not supported
  • src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Properties/Resources.resx: Language not supported
Comments suppressed due to low confidence (1)

src/modules/launcher/Plugins/Microsoft.Plugin.WindowWalker/Components/ResultHelper.cs:29

  • Ensure that the new behavior introduced in ResultHelper.cs for grouping and selecting the top window per process is covered by tests.
if (WindowWalkerSettings.Instance.ResultsFromTopWindowPerProcess)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants