Skip to content

Release the focus when hiding #332

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

Closed
dreadnaut opened this issue Oct 22, 2018 · 9 comments
Closed

Release the focus when hiding #332

dreadnaut opened this issue Oct 22, 2018 · 9 comments

Comments

@dreadnaut
Copy link

Keypirinha currently keeps focus when it executes a command, e.g., it launches a program. This goes usually unnoticed, because the newly launched program opens a new window and takes the focus.

However, if the command does not open a window, the focus stays with Keypirinha, even if Keypirinha is configured to hide from view. Programs that behave like this often open as a tray icon, such as PuTTY's credentials agent.

Hitting Alt-F4 at this point would close Keypirinha, instead of the topmost window.

I suppose the launcher hides its window, but does not actually "minimize" and drop in the window stack. It's a minor annoyance, but hopefully not too difficult to fix.

@dreadnaut dreadnaut changed the title Drop to the background when hiding Release the focus when hiding Oct 22, 2018
@polyvertex
Copy link
Member

I'm not sure to understand what you mean here. If you execute an item of the Env package for instance, which does not run any external application, KP still releases the focus upon execution and after its window is closed, then allowing the OS to give the focus back to the application that was in use beforehand.

Said differently, KP just closes its window upon execution, regardless of the kind of "execution" it does (i.e. launch an app or not).

You say you observe something different? If so, please provide step-by-step instructions to reproduce the issue.

@dreadnaut
Copy link
Author

Sorry, by "command" I meant "external command", an actual executable, not a plugin entry.

I can reproduce the behaviour with the above-mentioned PuTTY agent, any shortcut based on NirCMD, and in general executables which do not open windows, not even a console window.

I search for the entry, press Enter to run. I can see my previously-in-the-foreground window not getting the focus back, and if I press Alt-F4, the launcher terminates.

I am using Kp 2.21, with these relevant non-default settings:

always_on_top = yes
hide_on_focus_lost = yes
show_on_taskbar = no

@polyvertex
Copy link
Member

Makes sense then. Already corrected for the next release!

@polyvertex
Copy link
Member

Fixed (hopefully) in v2.22

@dreadnaut
Copy link
Author

Briefly tested, I can confirm it fixed. Thank you!

@polyvertex
Copy link
Member

Well, it seems there's quite a serious drawback to the fix as it was applied: when the Open as Administrator action is used, its makes the Windows UAC popup showing background, requiring the user to Alt+Tab to switch to it.

This requires a bit of digging but if I cannot find a acceptable workaround, I may have to revert the modification applied to v2.22...

I will report here. Reopening this in the meantime.

@polyvertex polyvertex reopened this Nov 2, 2018
@polyvertex
Copy link
Member

I tested different combination of tricks and spent more time on it than I'm willing to admit. It appears the best but not ideal option remains to revert the change made to v2.22. So as of v2.22.1, your initial issue will persists and your request is not honored anymore. Sorry for that.

@dreadnaut
Copy link
Author

dreadnaut commented Nov 3, 2018

I tested different combination of tricks and spent more time on it than I'm willing to admit

Sorry to hear that, didn't know it was going to be a pain!

I tested Colibri and Launchy: neither show the original issue (not returning focus), and they also don't have trouble with UAC prompts. That's running on Windows 8.1, with default UAC settings.

Their hide functions call ShowWindow(), and that's about it. See Colibri's hide(), launch() and Launchy's HideLaunchy(), Run() for reference.

Happy to have a look at the specific bit of code in KP, if you can post a snippet.

@polyvertex
Copy link
Member

polyvertex commented Nov 3, 2018

KP does no magic regarding those parts. I.e.: ShowWindow(m_handle, SW_HIDE);

To launch executable and to perform shell actions, only ShellExecuteEx is used by KP itself as well as its official plugins. With the SW_SHOWNORMAL flag set by default, which is modifiable via KP's Python API by the plugins if needed but official plugins don't do that. Historically, the SW_SHOWDEFAULT flag was used before but for some reason, some applications were not responding very well to it.

The problem obviously lies elsewhere, or it's a combination of things. Maybe because of the satellite window (icon) for instance. But this would require more time.

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

No branches or pull requests

2 participants