Fix problems with the hide/restore functionality on the tray icon (issue #1595) (redone)#1703
Fix problems with the hide/restore functionality on the tray icon (issue #1595) (redone)#1703TheZ3ro merged 6 commits intokeepassxreboot:release/2.3.2from joanbm:release/2.3.2
Conversation
|
Builds are failing |
|
@droidmonkey They work on my Linux and Windows machines... not sure what's different in the CI environment. PS: I have also noticed that there's a slight code style problem in the test, will fix. EDIT: Think I may have found it... |
|
Fixed, looks like the CI environment has no tray and therefore the tray icon can't be tested there, so it is now skipped. |
droidmonkey
left a comment
There was a problem hiding this comment.
@weslly did you confirm that this doesn't impact functionality on MacOS?
| void MainWindow::hideWindow() | ||
| { | ||
| saveWindowInformation(); | ||
| #ifndef Q_OS_MAC |
There was a problem hiding this comment.
Why remove this guard for MacOS?
There was a problem hiding this comment.
Good catch... @phoerious said in issue #1595 that isn't probably an ancient code from the time Mac didn't have a tray icon, and I remember doing a git blame, but it looks like I misread it, because it's rather the opposite... it was introduced in 8d6db27 when the tray icon on Mac was introduced... I will add it again, along with a TODO asking for further comments.
|
|
||
| void MainWindow::toggleWindow() | ||
| { | ||
| if ((QApplication::activeWindow() == this) && isVisible() && !isMinimized()) { |
There was a problem hiding this comment.
I'm afraid this will cause undesirable effects on MacOS
There was a problem hiding this comment.
@droidmonkey Can you elaborate? A priori I can't see it causing problems, since it looks like an old check (it was there before the other two conditions were implemented), it works on Windows and Linux, and it wasn't added specifically for Mac, though it would be nice for someone to check.
There was a problem hiding this comment.
I'm just saying that we edited it and thoroughly tested on Linux and Windows but not Mac. What I meant to say is "this needs to be tested on Mac to ensure no undesirable effects"
There was a problem hiding this comment.
@droidmonkey I tested yesterday and saw no problems toggling the window from the tray icon on Mac.
|
I just noticed the "minimize on start" option doesn't work at all on macOS with or without this PR. |
Fix/work around KeePassXC flickering and not restoring from tray on some Linux systems, which happens if the window is hidden and minimized by code at the same time (see issue #1595).
Fix unreliable check on toggleWindow() which causes Windows systems to be unable to hide the window by clicking on the tray icon (see issue #1595).
Add again the wrongly removed conditional macro for Mac, along with a TODO asking for further documentation on its significance.
|
@TheZ3ro Done, all commits in release/2.3.2 are now in my fork. |
|
Thanks fot the contribution! 🎉 |
Opening another PR since PR #1700 had the wrong source branch. Sorry for the annoyance...
Fix/work around tray issues on some Linux systems such as Arch Linux, and Windows. Fixes all cases explained in issue #1595.
Description
Basically there are two separate issues at play there:
This can happen both on start (this is the case of the original bug report), if
minimizeOnStartup=trueandminimizeToTray=true, then the window is minimized but not shown:Or when clicking on the tray icon to hide the window, the window is both minimized and hidden by code on
hideWindow()(this is what is causing my flicker-restore-minimize cycle sometimes):toggleWindow(), there's aQApplication::activeWindow() == thischeck:On Windows, when clicking on the tray icon when the window is visible,
QApplication::activeWindow() = NULL. I think this is due to differences in window focus behavior between Windows and Linux (I believe Windows removes the focus from the window when clicking on the tray).Motivation and context
This change is required in order to avoid issues when hiding and restoring the KeePassXC windows from tray. One of those issues happen on Windows, and the other in some Linux systems (what exactly causes some systems and desktop environments to be affected and some not to be affected is not known, though it probably depends on the Qt version, but must also depend on some environment condition since on my system the bug only happens sometimes).
For the Linux issue, I avoid both minimizing and hiding the window at the same time by code. It should suffice to only hide the window if the event is caused by a tray icon click.
For the Windows issue, I just removed the check for QApplication::activeWindow() == this, I think it is unreliable and the other checks in the same line (which were added later) should suffice alone.
Fixes #1595
How has this been tested?
I set up some VMs for manual testing of the issue, and I found this:
Environment details:
I also ran all the automatic tests on my local Arch Linux system and they passed.
Screenshots (if appropriate):
Windows issue: https://imgur.com/fJW62v7
Linux issue (flicker on first restore): https://imgur.com/cES8olj
Types of changes
Checklist:
-DWITH_ASAN=ON. [REQUIRED]