zazu icon indicating copy to clipboard operation
zazu copied to clipboard

Zazu retaining focus after search window is closed.

Open PAB-me-uk opened this issue 8 years ago • 13 comments

Expected Behavior

When Zazu is hidden the focus should be returned to the previous application.

Actual Behavior

When Zazu is hidden Zazu retains the focus even though the Zazu window is hidden.

Steps to reproduce the behavior

  • Press toggle key to show Zazu.

  • Press escape or toggle key again, or select an action that doesn't launch a new window (e.g. clipboard plugin)

  • The Zazu search window is hidden

  • The focus is not returned to the previous application.

  • Pressing ctrl+F4 (Windows close application shortcut) closes the Zazu application removing the icon from the task bar which proves that Zazu still had the focus.

Versions

Zazu: 0.3.2 OS: Windows 8.1 (probably all) GIT: 2.11

Notes

This issue is particularily problematic for the clipboard plugin as after selecting a clip entry I have to manually click on the applications window to get the focus, then press ctrl+v to paste.

I think this may actually be an issue with Electron see https://github.com/electron/electron/issues/3472

PAB-me-uk avatar Jan 30 '17 17:01 PAB-me-uk

I believe this is a restriction of electron, as you suggested. On Mac there is a app.hide() api we call here, but I'm not sure how to do this on windows/linux yet, but would love to get this fixed.

bayleedev avatar Jan 30 '17 18:01 bayleedev

@PAB-me-uk The issue you linked to is closed, so I guess it's not something that's going to change from electron's side?

arieljannai avatar Apr 26 '17 21:04 arieljannai

I have requested that https://github.com/electron/electron/issues/3472 is reopened as it has not been fixed.

PAB-me-uk avatar Apr 27 '17 08:04 PAB-me-uk

I'm trying to create an AHK script as a workaround

arieljannai avatar Apr 27 '17 09:04 arieljannai

One workaround would be to use the windows api functions as follows:

When activated by hot key use GetFocus to get the hwnd of the current app.

When hiding window use SetFocus and the hwnd retrieved earlier.

Not easy from JavaScript but could be possible using node-ffi.

But ideally this will be fixed in Electron itself.

PAB-me-uk avatar Apr 27 '17 10:04 PAB-me-uk

I agree it should be from their side, but meanwhile, I use this script

arieljannai avatar Apr 27 '17 14:04 arieljannai

Thank you for the script! Is there a way to integrate that into zazu?

bayleedev avatar Apr 28 '17 16:04 bayleedev

I'm not sure it would be a nice integration - maybe it can be suggested as a fix-hack to people who uses AutoHotKey? If the user already has AHK installed, that won't be a problem - just starting the script (if not already running) when Zazu starts.

P.s the script is not perfect, I need to change it:

  • The problems it has:
    • If the last active window was desktop - it will bring back the one before desktop
    • [SOLVED] The matching is not effective, since it's by window title (so also this chrome tab in Zazu project activates the script) - I need to change it to another matching - or maybe a combination of multiple criterias.

arieljannai avatar Apr 29 '17 11:04 arieljannai

I think I solved the second problem in my script - I changed the filtering of the window to match by id. The only problem is that I don't know if the id is constant in other machines.

Could you check if the updated script works for you? Or in addition, create a script with that code, activate Zazu and press Alt+a to get a popup with the ahk_id (so I'll know if it's the same or not)

!A:: 
WinGet, WinID, ID, A
MyWin = ahk_id %WinID%
MsgBox, %MyWin%
Return

arieljannai avatar Apr 29 '17 19:04 arieljannai

NVM, Changed it again. Now it filters by the exe name, so it works

arieljannai avatar Apr 29 '17 22:04 arieljannai

@arieljannai Is this something that could be modified to work with other Electron apps? I'd love to solve this problem myself, but I don't understand your solution. Is this something that could potentially be packaged into an Electron installer?

Nantris avatar Sep 22 '17 22:09 Nantris

@Slapbox It could be integrated, but I wouldn't. At least not with my solution. It's simple and has bugs, but basically working. Still, it's a kind of workaround/patch rather than a solution for the problem. If you would improve the script so it wouldn't have bugs - it could be integrated better.

arieljannai avatar Sep 23 '17 22:09 arieljannai

Ah I'd love to but I don't even understand what your snippet does. I will revisit this thread when the time comes though and see what I can do. I'd happily share a solution to this very frustrating problem if I could find one.

What sorts of bugs do you see with it? How exactly are you using it in conjunction with Zazu?

Nantris avatar Sep 24 '17 00:09 Nantris