mattermost / desktop

Mattermost Desktop application for Windows, Mac and Linux
Apache License 2.0
2.02k stars 827 forks source link

Application keeps focus after closing the window #233

Closed nmatt closed 8 years ago

nmatt commented 8 years ago

I confirm (by marking "x" in the [ ] below):


Summary

When closing the desktop application window, it remains in the Windows tab list until the user activates a different window (i.e. another application). The normal behavior when closing applications under Windows is that the next top-level window is activated (gets focus). This doesn't happen here. It has the irritating effect that when using Alt+Tab to switch to a different window after closing the Mattermost window, Mattermost still appears in the Alt+Tab list. It only disappears after having switched to another application. Even when cancelling Alt+Tab with Esc or switching back with Alt+Shift+Tab, the focus appears to remain on the (invisible) Mattermost application, and then doing Alt+Tab again still shows it.

Steps to reproduce

Steps to reproduce the issue: 1) Open some windows/applications 2) Open the Mattermost desktop application 3) Close the Mattermost application window using Alt+F4, the system menu (Alt+Space, C) or the window's "Close" icon (cross symbol) –> Note that no other application window receives focus 4) Press Alt+Tab and keep Alt pressed –> Mattermost is still in the Alt+Tab list 5) While having Alt pressed, press Esc to cancel Alt+Tab, then release Alt 6) Again press Alt+Tab and keep Alt pressed 7) While having Alt pressed, press Shift+Tab, then release Alt, to remain on the (invisible) Mattermost application 8) Use Alt+Tab to switch to a different application 9) Again press Alt+Tab and keep Alt pressed

Expected behavior

When closing the Mattermost application window, the next top-level window should immediately receive focus, and Mattermost should not appear in the Alt+Tab list.

Observed behavior

A) After step 3, no other application window receives focus. B) Also, when Alt+F4, the system menu (Alt+Space, C) or the window's "Close" icon (cross symbol) is used to close the application in step 3, then Mattermost still appears in the Alt+Tab list on steps 4 and 6. It only disappears after step 8.

When using Ctrl+Q to close the application in step 3, only A is observed, not B. In other words, Mattermost does not appear in the Alt+Tab list in steps 4 and 6 when Ctrl+Q was used.

jasonblais commented 8 years ago

Thank you @nmatt for the report! The detail you provided is excellent, much appreciated!

This might be related to the issue reported in https://github.com/mattermost/desktop/issues/231 (After clicking on Desktop app in webview, keyboard shortcuts don't work until you click on the app for a second time, as the app isn't properly focused).

Would the community have any thoughts on a potential fix? @yuya-oc mentioned earlier that it might be a side effect of https://github.com/mattermost/desktop/commit/f2209aa9dd8f01c07cab1d487abdd55f82d76a93, which added the following functionality:

1) Have Mattermost desktop app focused on the message box 2) Switch to another windows 3) Go back to Mattermost desktop app via taskbar or system tray icon Observed: Focus is kept in the message box Observed without commit https://github.com/mattermost/desktop/commit/f2209aa9dd8f01c07cab1d487abdd55f82d76a93: Focus is no longer in the message box

yuya-oc commented 8 years ago

@nmatt I could not observed the behavior B) in Windows 7 and 10, So I fixed the behavior A) first. Would you check whether following artifacts fix this issue? https://circleci.com/gh/mattermost/desktop/641#artifacts

nmatt commented 8 years ago

@yuya-oc: I tried the 64-bit version and it solves both A and B for me. Thanks! FWIW, I'm using the Windows classic look and the classic Alt+Tab dialog (cf. http://winaero.com/blog/how-to-get-the-old-alt-tab-dialog-in-windows-10/), so that might explain the difference regarding behavior B.

yuya-oc commented 8 years ago

@nmatt Thank you for testing and kind description! Your report is very helpful to know the problem!

nmatt commented 7 years ago

I get this behavior again with version 3.5.0. Can you please reopen the issue?

jasonblais commented 7 years ago

Thanks @nmatt - is it on Windows 7 Pro? Can your other team members reproduce the issue as well (and which platforms do they have)?

nmatt commented 7 years ago

@jasonblais: We can reproduce it under Windows 7, 8.1 and 10 Enterprise/Pro. Behavior B (see above) happens with the classic Alt+Tab switcher. You can temporarily activate the classic Alt+Tab switcher by holding the left Alt key down while pressing and releasing the right Alt key and then pressing the Tab key.

jasonblais commented 7 years ago

Thanks @nmatt, here are the steps for me. Let me know if one of them is incorrect / I'm missing any of them?

Would be happy to create a new issue or reopen this one, just want to make sure we have the exact repro steps for it as these ones didn't show me the Mattermost dialog:

1) Download v3.5.0 from https://about.mattermost.com/downloads 2) Launch the app 3) Close the app window using the "Close" button 4) Press Left Alt key 5) Press Tab, then release it so you're only holding the Left Alt key 6) Press Right Alt key, then release it so you're again only holding the Left Alt key 7) Press Tab (while holding the Left Alt key)

Observed = Expected (for me): Mattermost app doesn't appear on the list

nmatt commented 7 years ago

Hi @jasonblais. For behavior A: 1) Launch Mattermost desktop 3.5.0 2) Launch some other application 3) Alt+Tab back to Mattermost desktop 4) Close Mattermost desktop using keyboard or Close button => Focus is not back on the other application (but is still on the now invisible Mattermost desktop application)

For behavior B: 1) Launch Mattermost desktop 3.5.0 2) Launch some other application (to ensure there will be something else to show in the Alt+Tab switcher) 3) Alt+Tab back to Mattermost desktop 4) Close Mattermost desktop using keyboard or Close button Invoke the classic Alt+Tab switcher as follows: 5) Press and hold the left Alt key 6) Press and release the right Alt key (while still holding the left Alt key) 7) Press the Tab key (while still holding the left Alt key) => The icon of the Mattermost desktop application is still in the classic Alt+Tab switcher list. It only disappears from it after having switched to a different application.

Both behaviors were fixed in the version provided by yuya-oc and (I believe) in version 3.4.0.

jasonblais commented 7 years ago

Thanks for the repro steps! I was able to reproduce both

@yuya-oc Looks like this commit, for instance, changed the function name from hide_window(mainWindow) to hideWindow(window) that controls what gets focus after the app window is closed:

https://github.com/mattermost/desktop/commit/16788b5a6f0effebca908e9566e60651e7bf5c1d#diff-1c90ff38a08209f9ebd4d05d1e43358e

Wondering if that commit might have caused the regression? It went into 3.5 so the timing matches.

yuya-oc commented 7 years ago

That part should not cause the regression because the funtion name is also changed to hideWindow() in the switch statement. Otherwise, I think that the window never close.

jasonblais commented 7 years ago

Thanks all! I created new issues for the two bugs: #430 and #431

Thanks @nmatt for the detailed description, really useful.