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

When reconnecting the kitty window (which is being hidden in the tray) will cause the active window to lose focus #238

Closed
char101 opened this issue Oct 19, 2020 · 16 comments

Comments

@char101
Copy link

@char101 char101 commented Oct 19, 2020

When reconnecting the kitty window which is being hidden in the tray area will activate for a very short term thus taking the focus from current active window.

Steps to reproduce

  1. run kitty, enable reconnection, minimize to tray
  2. disconnect Internet connection
  3. reconnect Internet connection
  4. the kitty window will flash for a bit and the currently focused window will lose focus.

Verified using focus.exe from https://www.happydroid.com/focus to monitor the focused windows.

@ml-cms
Copy link

@ml-cms ml-cms commented Oct 21, 2020

We have the same annoying problem

@cyd01
Copy link
Owner

@cyd01 cyd01 commented Oct 31, 2020

Did you try to change your bell setting in Terminal/Bell panel ?

@char101
Copy link
Author

@char101 char101 commented Oct 31, 2020

I just tried to change it from alert sound to none and then disconnecting and reconnecting the Internet connection. The result is the same: the kitty window which is hidden in the tray still steal focus when it is reconnecting.

@cyd01
Copy link
Owner

@cyd01 cyd01 commented Oct 31, 2020

Can you test this build ?
Is the focus still stolen ?

@char101
Copy link
Author

@char101 char101 commented Nov 1, 2020

Yes the focus is still stolen with that build.

If you want to test it yourself you could also use Process Hacker, close the kitty connection to port 22 in the Network tab in Process Hacker, and see the Process Hacker window losing focus after a while, while kitty is reconnecting.

@cyd01
Copy link
Owner

@cyd01 cyd01 commented Nov 1, 2020

I did not reproduce. Can you send me a memory dump of the session that steal the focus ?
I need to be exactly in the same situation.

@char101
Copy link
Author

@char101 char101 commented Nov 1, 2020

I hooked the kitty process to winapioverride and found that these two functions are called when it steal focus

https://github.com/cyd01/KiTTY/blob/master/0.74_My_PuTTY/windows/window.c#L3336

BringWindowToTop( hwnd ) ;
SetForegroundWindow( hwnd ) ;

Maybe a check can be added there to skip calling those functions if the window is currently hidden in the tray.

@leifclaesson
Copy link

@leifclaesson leifclaesson commented Nov 1, 2020

For what it's worth, I'm seeing the exact problem with 0.74.2.7, it's not just @char101.

I came here to see if there was a solution :).

I can't think of a single situation where it's appropriate to steal focus.
If I'm looking at the window, great. If not then I'm looking at something else and the window should stay where I left it.
It's better to let the user select when they want to focus the window, there is no reason to call SetForegroundWindow. Windows are automatically set to the foreground when you start an application.

@char101 char101 changed the title When reconnecting the kitty window (which is being hidden in the tray) will flash When reconnecting the kitty window (which is being hidden in the tray) will cause the active window to lose focus Nov 1, 2020
@char101
Copy link
Author

@char101 char101 commented Nov 1, 2020

I may have used the wrong term here. Flashing seems to meant that the taskbar icon is flashing, while what I meant was the kitty window appear and disappear for a very short time (although I guess it isn't what is happening here). The actual problem is that the currently foreground window (e.g. the editor I'm typing in) will suddenly lose focus.

@cyd01
Copy link
Owner

@cyd01 cyd01 commented Nov 1, 2020

I thought to something else.
Can you download this last build ?

@cyd01
Copy link
Owner

@cyd01 cyd01 commented Nov 1, 2020

That's exactly what @char101 has proposed.

@char101
Copy link
Author

@char101 char101 commented Nov 2, 2020

Can you download this last build ?

Unfortunately the focus is still lost with this build.

Winapioverride still shows that BringWindowToTop and SetForegroundWindow is still called when kitty is reconnecting while it is hidden in the tray.

2020-11-02 08_00_40-WinAPIOverride64

@cyd01
Copy link
Owner

@cyd01 cyd01 commented Nov 3, 2020

Are you sure ?
I've double checked, and it is not called anymore.

@char101
Copy link
Author

@char101 char101 commented Nov 4, 2020

I have just tested it again (kitty-debug.exe, Last-Modified: Tue, 03 Nov 2020 22:10:29 GMT) and now it does not steal focus anymore. Thanks.

@cyd01
Copy link
Owner

@cyd01 cyd01 commented Nov 4, 2020

Keep this debug build.
I don't known when I will upload a new release on Fosshub.

@cyd01 cyd01 closed this Nov 4, 2020
@char101
Copy link
Author

@char101 char101 commented Nov 4, 2020

I already downloaded the new release from the release page on github though, so no need to wait for fosshub.

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

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.