-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Complete rewrite of the tray icon implementation #6466
base: master
Are you sure you want to change the base?
Conversation
38aace8
to
3af870a
Compare
I just wanted these references to appear here in the GitHub UI explicitly to make sure everything is linked together correctly. |
With https://dev.azure.com/Mumble-VoIP/Mumble/_build/results?buildId=8469&view=results, on Windows 10: Able to receive desktop notifications?
With minimize to tray enabled, does clicking the tray icon and/or clicking the first action of the context menu of the tray icon hide and show Mumble correctly?
With minimize to tray and "ask on quit" dialog disabled, does pressing the close button in the title bar hide Mumble correctly?
With minimize to tray and "ask on quit" dialog enabled, does pressing the minimize button in the dialog hide Mumble correctly?
With minimize to tray enabled, does pressing the minimize button in the title bar hide Mumble correctly?
Is a maximized Mumble MainWindow still hiding and restoring correctly?
In Settings -> User Interface, is there a settings group box called "Tray"?
Does pressing "OK" in the settings dialog not hide Mumble?
Receive a message for which "highlight" is enabled. Does the tray icon blink using the "i"-icon every two seconds until the MainWindow receives focus?
Does clicking a desktop notification restore and focus Mumble?
Does starting Mumble with --hidden actually work?
|
There is a checkbox for "highlight" in the Settings -> Messages table view. If enabled, it should highlight the application in the task bar (some sort of blinking iirc) and as of this PR also change the tray icon. The effect should only apply, if Mumble has no focus and only lasts until the Window receives focus again.
It does: mumble/src/mumble/MainWindow.cpp Lines 3631 to 3638 in e0cd306
It first restores the window from minimization and adds a timer to the
Good catch, I think this is a regression I should try to fix. |
That's what I was missing, thanks! Highlighting works as expected. Unrelated to this PR but the first column of that table has some usability issues as the text is cut off, at least in Windows, making it hard to know what you're enabling highlighting (or any other option) for.
Ahh sorry, what I meant was that during testing, I couldn't find any discernable difference in functionality between this version and 1.5.634. |
Nice.
Ah ok. Well as stated in your original issue, it is sadly not possible for us to arbitrarily focus the Mumble MainWindow. But it is good to know that de-minimization works as expected. |
953ecff
to
fdbb8cb
Compare
Not quite - what you want here is to make e.g. the MainWindow have (new) signals that it emits. These are then wired up to the tray icon's slots. That makes things conventional again (signals of a class are only emitted by that class itself in reaction to an observed change).
I guess - I'm not sure how Qt handles class-external parts emitting a class's signals 😅 |
Ah. Ok. Well, that would work. I am just not sure, if that would make sense from a structural perspective. Because that would mean we would have tray icon specific signals in the MainWindow class just for that purpose?
Should make no difference as |
Just don't frame them as tray-icon specific. The tray icon reacts to certain events. Make these events signals (with a name that only reflects the event, not something like
Yes, but Qt does some magic on its own when handling signals and slots (e.g. in order to implement the thread safety features) |
I see. Yes, I guess that would work! Check out the latest changes to the experimental commit. |
Yes, that's what I had in mind 👍 |
3fc78a6
to
55ea907
Compare
@Krzmbrzl Anything left to do here? :) |
@@ -803,13 +805,32 @@ void Log::log(MsgType mt, const QString &console, const QString &terse, bool own | |||
if (!(Global::get().mw->isActiveWindow() && Global::get().mw->qdwLog->isVisible())) { | |||
// Message notification with window highlight | |||
if (flags & Settings::LogHighlight) { | |||
QApplication::alert(Global::get().mw); | |||
Global::get().mw->highlightWindow(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably be done via a signal
msgIcon = QSystemTrayIcon::Information; | ||
break; | ||
} | ||
Global::get().trayIcon->showMessage(msgName(mt), plain, msgIcon); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably be done via a signal
bool wasMinimizedState = (windowStateEvent->oldState() & Qt::WindowMinimized); | ||
bool isMinimizedState = (windowState() & Qt::WindowMinimized); | ||
if (!wasMinimizedState && isMinimizedState) { | ||
Global::get().trayIcon->on_hideAction_triggered(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably be done via a signal
} else { | ||
Global::get().mw->show(); | ||
} | ||
Global::get().trayIcon->toggleShowHide(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably be done via a signal
} | ||
|
||
void TrayIcon::on_icon_update() { | ||
std::reference_wrapper< QIcon > newIcon = Global::get().mw->qiIcon; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you using a reference_wrapper
for this? That class is usually only used when storing references as a member or in a container.
Furthermore, I would like to ask you to link all issues that this PR (fully) addresses to the PR so that these get closed once we merge this PR (this can be done on the right side under the "Development" header). |
The existing code for the tray icon was ancient, buggy and possibly entirely broken in more than one place. This commit removes all tray related code, such that it can be completely written from scratch.
65848df
to
d5380c6
Compare
The old tray icon implementation was very old and contained a lot of workaround for things that probably are no longer an issue. Furthermore, the event loop was modified in a way such that it could end up in an infinite loop draining CPU time and rendering Mumble unusable. Based on the new Qt5 implementation, this commit introduces a complete rewrite of the tray icon. The following things should be noted: * We assume the information in the Qt documentation [1] is valid. This means that all versions of Windows, all Linux window managers/compositors that implement the d-bus StatusNotifierItem specification, and all versions of macos support the functionality of QSystemTrayIcon and its notification system. That means we can drop the platform-specific code branches and handle messages directly with QSystemTrayIcon::sendMessage. This should for example also be true for recent versions of Gnome, which do not have an actual system tray, but implement the d-bus StatusNotifierItem specification. Therefore, we can actually merge and simplify the notification code for Windows and Unix*. * With regards to the bullet point above, we only limit the "hide to tray" functionality behind QSystemTrayIcon::isSystemTrayAvailable (because otherwise you would not get the Mumble window back without binding a shortcut first). Other code branches that were previously limited when isSystemTrayAvailable returned false were removed. According to Qt, the QSystemTrayIcon code does not actually care if a system tray is available and will even retroactively add itself if a tray becomes available after the application was started. * On (X)Wayland, the minimize button in the window frame does not trigger a minimize change event. This means that users with such a system may only be able to "hide to tray" by 1) pressing the close button in the window frame and enabling "minimize instead of close" 2) clicking the tray icon or the tray icon hide action or 3) binding a shortcut to hide the window. This is either a bug or a deliberate decision by Qt or Wayland and we have no way to do anything about that. (QTBUG-74310) * The "messageClicked" event is buggy in Qt on some platforms. That means that clicking the system notification spawned by Mumble via QSystemTrayIcon::sendMessage will (on some systems) never trigger anything especially not showing and activating the window. This is a long-standing bug in Qt (QTBUG-87329), but we have absolutely no way to work around this. The event is correctly hooked up in Mumble and if this is ever fixed in Qt, this will start working again automatically. * The tray icon has been redesigned according to state-of-the-art tray icon design guidelines [2]. Which basically just means: 1) d9a2d47 has been reverted to provide the user with a consistent menu 2) The main action of the tray icon (toggle show/hide) is the first entry in the context menu and the default action when the icon is clicked and 3) the TalkingUI toggle action was added. Actions for double and middle mouse clicks were removed as they might have contributed to infinite loops. * There is no way in Windows to show and activate a window that is not part of the current active process. If you have Mumble running in the background and receive a message, we can not raise the Window without you clicking the Mumble taskbar item or tray icon yourself. This is deliberate by Microsoft and can and should not be circumvented. (mumble-voip#5701) * This also fixes the case where the Mumble MainWindow would disappear when pressing "OK" in the settings dialog. This happened because users would have "minimize to tray" and "minimize on close" enabled. [1] https://doc.qt.io/qt-5/qsystemtrayicon.html#details https://doc.qt.io/qt-6/qsystemtrayicon.html#details [2] https://learn.microsoft.com/en-us/windows/win32/uxguide/winenv-notification Fixes mumble-voip#1486 Fixes mumble-voip#3028 Fixes mumble-voip#3722 Fixes mumble-voip#3977 Fixes mumble-voip#3999 Fixes mumble-voip#5012
Previously, only "window highlighting" was supported by Mumble. However, when Mumble was minimized to tray, there was no way to observe that highlighting. As requested in mumble-voip#4584, this commit introduces highlighting to the tray icon. When a highlight message is received, the tray icon will flash the "information icon" every two seconds until the MainWindow of Mumble receives focus again. To enable this for a specific message type, the user needs to check the "highlight" box in the "Messages" configuration dialog. Fixes mumble-voip#4584
This commit introduces the "--hidden" cli option which prevents Mumble and the ConnectDialog to show up on startup. This is especially useful for users who want to automate the startup process without human interaction. Fixes mumble-voip#3879
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Not sure if this is waiting on a review so I just reviewed to be sure :D)
Otherwise the unresolved comments from above remain valid.
@@ -0,0 +1,203 @@ | |||
// Copyright 2024 The Mumble Developers. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The date should be removed now that we have removed it from all other copyright headers on master
#include "../ClientUser.h" | ||
#include "../MainWindow.h" | ||
#include "../Global.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't do the include "normally" as these files should be compiled with the regular include path? 🤔
Having explicit include paths is always a bit fishy 👀
void TrayIcon::on_icon_update() { | ||
std::reference_wrapper< QIcon > newIcon = Global::get().mw->qiIcon; | ||
|
||
ClientUser *p = ClientUser::get(Global::get().uiSession); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ClientUser *p = ClientUser::get(Global::get().uiSession); | |
const ClientUser *p = ClientUser::get(Global::get().uiSession); |
Just have to get to this PR again at some point :) I want do the fixes for 1.5 first |
FEAT(client): Fully rewrite tray icon implementation
The old tray icon implementation was very old and contained a lot of workaround for things that probably are no longer an issue.
Furthermore, the event loop was modified in a way such that it could end up in an infinite loop draining CPU time and rendering Mumble unusable.
Based on the new Qt5 implementation, this commit introduces a complete rewrite of the tray icon. The following things should be noted:
We assume the information in the Qt documentation [1] is valid. This means that all versions of Windows, all Linux window managers/compositors that implement the d-bus StatusNotifierItem specification, and all versions of macos support the functionality of QSystemTrayIcon and its notification system. That means we can drop the platform-specific code branches and handle messages directly with QSystemTrayIcon::sendMessage. This should for example also be true for recent versions of Gnome, which do not have an actual system tray, but implement the d-bus StatusNotifierItem specification. Therefore, we can actually merge and simplify the notification code for Windows and Unix*.
With regards to the bullet point above, we only limit the "hide to tray" functionality behind QSystemTrayIcon::isSystemTrayAvailable (because otherwise you would not get the Mumble window back without binding a shortcut first). Other code branches that were previously limited when isSystemTrayAvailable
returned false were removed. According to Qt, the QSystemTrayIcon code does not actually care if a system tray is available and will even retroactively add itself if a tray becomes available after the application was started.
On (X)Wayland, the minimize button in the window frame does not trigger a minimize change event. This means that users with such a system may only be able to "hide to tray" by 1) pressing the close button in the window frame and enabling "minimize instead of close" 2) clicking the tray icon or the tray icon hide action or 3) binding a shortcut to hide the window. This is either a bug or a deliberate decision by Qt or Wayland and we have no way to do anything
about that. (QTBUG-74310)
The "messageClicked" event is buggy in Qt on some platforms. That means that clicking the system notification spawned by Mumble via QSystemTrayIcon::sendMessage will (on some systems) never trigger anything especially not showing and activating the window. This is a long-standing bug in Qt (QTBUG-87329), but we have absolutely no way to work around this. The event is correctly hooked up in Mumble and if this is ever fixed in Qt, this will start working again automatically.
The tray icon has been redesigned according to state-of-the-art tray icon design guidelines [2]. Which basically just means: 1) d9a2d47 has been reverted to provide the user with a consistent menu 2) The main action of the tray icon (toggle show/hide) is the first entry in the context menu and the default action when the icon is clicked and 3) the TalkingUI toggle action was added. Actions for double and middle mouse clicks were removed as they might have contributed to infinite loops.
There is no way in Windows to show and activate a window that is not part of the current active process. If you have Mumble running in the background and receive a message, we can not raise the Window without
you clicking the Mumble taskbar item or tray icon yourself. This is deliberate by Microsoft and can and should not be circumvented. (Main window doesn't receive focus when Mumble-specific Windows notification is clicked #5701)
This also fixes the case where the Mumble MainWindow would disappear when pressing "OK" in the settings dialog. This happened because users would have "minimize to tray" and "minimize on close" enabled.
[1]
https://doc.qt.io/qt-5/qsystemtrayicon.html#details
https://doc.qt.io/qt-6/qsystemtrayicon.html#details
[2] https://learn.microsoft.com/en-us/windows/win32/uxguide/winenv-notification
FEAT(client): Implement tray icon highlighting
Previously, only "window highlighting" was supported by Mumble. However, when Mumble was minimized to tray,
there was no way to observe that highlighting.
As requested in #4584, this commit introduces highlighting to the tray icon. When a highlight message is received, the
tray icon will flash the "information icon" every two seconds until the MainWindow of Mumble receives focus again.
To enable this for a specific message type, the user needs to check the "highlight" box in the "Messages" configuration dialog.
FEAT(client): Add --hidden cli option to start Mumble hidden in tray
This commit introduces the "--hidden" cli option which prevents Mumble and the ConnectDialog to show up on startup.
This is especially useful for users who want to automate the startup process without human interaction.
Testing:
--hidden
actually work?Closes #1486
Closes #3028
Closes #3722
Closes #3879
Closes #3977
Closes #3999
Closes #4584
Closes #5012