Skip to content

Commit

Permalink
FEAT(client): Fully rewrite tray icon implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartmnt committed Jun 12, 2024
1 parent 138eb71 commit 6441e47
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/mumble/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ set(MUMBLE_SOURCES
"widgets/SearchDialogTree.h"
"widgets/SemanticSlider.cpp"
"widgets/SemanticSlider.h"
"widgets/TrayIcon.cpp"
"widgets/TrayIcon.h"


"${SHARED_SOURCE_DIR}/ACL.cpp"
Expand Down
1 change: 1 addition & 0 deletions src/mumble/Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ void Global::migrateDataDir(const QDir &toDir) {

Global::Global(const QString &qsConfigPath) {
mw = 0;
trayIcon = 0;
db = 0;
pluginManager = 0;
nam = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/mumble/Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class OverlayClient;
class LogEmitter;
class DeveloperConsole;
class TalkingUI;
class TrayIcon;

class QNetworkAccessManager;

Expand All @@ -50,6 +51,7 @@ struct Global Q_DECL_FINAL {
static Global &get();

MainWindow *mw;
TrayIcon *trayIcon;
Settings s;
boost::shared_ptr< ServerHandler > sh;
boost::shared_ptr< AudioInput > ai;
Expand Down
28 changes: 23 additions & 5 deletions src/mumble/Log_unix.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
// Copyright 2012-2023 The Mumble Developers. All rights reserved.
// Copyright 2012-2024 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#include "Log.h"
#include "MainWindow.h"
#include "Settings.h"

#include <QDBusInterface>
#include "widgets/TrayIcon.h"
#include "Global.h"

void Log::postNotification(MsgType mt, const QString &plain) {
// FIXME
if (mt == MsgType::TextMessage || mt == MsgType::PrivateTextMessage) {
// Use custom icon for text messages
Global::get().trayIcon->showMessage(msgName(mt), plain, Global::get().mw->iconComment);
return;
}

QSystemTrayIcon::MessageIcon msgIcon;
switch (mt) {
case DebugInfo:
case CriticalError:
msgIcon = QSystemTrayIcon::Critical;
break;
case Warning:
msgIcon = QSystemTrayIcon::Warning;
break;
default:
msgIcon = QSystemTrayIcon::Information;
break;
}
Global::get().trayIcon->showMessage(msgName(mt), plain, msgIcon);
}
26 changes: 24 additions & 2 deletions src/mumble/Log_win.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
// Copyright 2012-2023 The Mumble Developers. All rights reserved.
// Copyright 2012-2024 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

#include "Log.h"
#include "MainWindow.h"
#include "widgets/TrayIcon.h"
#include "Global.h"

void Log::postNotification(MsgType mt, const QString &plain) {
// FIXME
if (mt == MsgType::TextMessage || mt == MsgType::PrivateTextMessage) {
// Use custom icon for text messages
Global::get().trayIcon->showMessage(msgName(mt), plain, Global::get().mw->iconComment);
return;
}

QSystemTrayIcon::MessageIcon msgIcon;
switch (mt) {
case DebugInfo:
case CriticalError:
msgIcon = QSystemTrayIcon::Critical;
break;
case Warning:
msgIcon = QSystemTrayIcon::Warning;
break;
default:
msgIcon = QSystemTrayIcon::Information;
break;
}
Global::get().trayIcon->showMessage(msgName(mt), plain, msgIcon);
}
47 changes: 38 additions & 9 deletions src/mumble/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include <QtWidgets/QWhatsThis>

#include "widgets/SemanticSlider.h"
#include "widgets/TrayIcon.h"

#ifdef Q_OS_WIN
# include <dbt.h>
Expand Down Expand Up @@ -111,6 +112,7 @@ MainWindow::MainWindow(QWidget *p)
SvgIcon::addSvgPixmapsToIcon(qiTalkingOn, QLatin1String("skin:talking_on.svg"));
SvgIcon::addSvgPixmapsToIcon(qiTalkingShout, QLatin1String("skin:talking_alt.svg"));
SvgIcon::addSvgPixmapsToIcon(qiTalkingWhisper, QLatin1String("skin:talking_whisper.svg"));
SvgIcon::addSvgPixmapsToIcon(iconComment, QLatin1String("skin:comment.svg"));

#ifdef Q_OS_MAC
if (QFile::exists(QLatin1String("skin:mumble.icns")))
Expand Down Expand Up @@ -193,6 +195,7 @@ MainWindow::MainWindow(QWidget *p)

QObject::connect(this, &MainWindow::serverSynchronized, Global::get().pluginManager,
&PluginManager::on_serverSynchronized);
QObject::connect(this, &MainWindow::serverSynchronized, this, &MainWindow::userStateChanged);

QAccessible::installFactory(AccessibleSlider::semanticSliderFactory);
}
Expand Down Expand Up @@ -622,7 +625,7 @@ void MainWindow::closeEvent(QCloseEvent *e) {
mb.setCheckBox(qcbRemember);
mb.exec();
if (mb.clickedButton() == qpbMinimize) {
showMinimized();
setWindowState(windowState() | Qt::WindowMinimized);
e->ignore();

// If checkbox is checked and not connected, always minimize
Expand All @@ -645,7 +648,7 @@ void MainWindow::closeEvent(QCloseEvent *e) {
}
#endif
} else if (!forceQuit && (alwaysMinimize || minimizeDueToConnected)) {
showMinimized();
setWindowState(windowState() | Qt::WindowMinimized);
e->ignore();
return;
}
Expand Down Expand Up @@ -700,7 +703,24 @@ void MainWindow::showEvent(QShowEvent *e) {
QMainWindow::showEvent(e);
}

#include <QDebug>

void MainWindow::changeEvent(QEvent *e) {
// Hide in tray when minimized
if (Global::get().s.bHideInTray && e->type() == QEvent::WindowStateChange) {
// This code block is not triggered on (X)Wayland due to a Qt bug we can do nothing about (QTBUG-74310)
QWindowStateChangeEvent *windowStateEvent = static_cast< QWindowStateChangeEvent * >(e);
if (windowStateEvent) {
bool wasMinimizedState = (windowStateEvent->oldState() & Qt::WindowMinimized) != 0;
bool isMinimizedState = (windowState() & Qt::WindowMinimized) != 0;
qDebug() << "was_minimized " << wasMinimizedState << " is_minimized " << isMinimizedState;
if (!wasMinimizedState && isMinimizedState) {
emit Global::get().trayIcon->on_hideAction_triggered();
}
return;
}
}

QWidget::changeEvent(e);
}

Expand Down Expand Up @@ -2532,6 +2552,8 @@ void MainWindow::updateMenuPermissions() {
}

void MainWindow::userStateChanged() {
Global::get().trayIcon->updateIcon();

ClientUser *user = ClientUser::get(Global::get().uiSession);
if (!user) {
Global::get().bAttenuateOthers = false;
Expand Down Expand Up @@ -2602,6 +2624,7 @@ void MainWindow::on_qaAudioMute_triggered() {
}

updateAudioToolTips();
Global::get().trayIcon->updateIcon();
}

void MainWindow::setAudioMute(bool mute) {
Expand Down Expand Up @@ -2646,6 +2669,7 @@ void MainWindow::on_qaAudioDeaf_triggered() {
}

updateAudioToolTips();
Global::get().trayIcon->updateIcon();
}

void MainWindow::setAudioDeaf(bool deaf) {
Expand Down Expand Up @@ -2758,6 +2782,7 @@ void MainWindow::pttReleased() {
void MainWindow::on_PushToMute_triggered(bool down, QVariant) {
Global::get().bPushToMute = down;
updateUserModel();
Global::get().trayIcon->updateIcon();
}

void MainWindow::on_VolumeUp_triggered(bool down, QVariant) {
Expand Down Expand Up @@ -3371,6 +3396,7 @@ void MainWindow::serverDisconnected(QAbstractSocket::SocketError err, QString re
qaServerBanList->setEnabled(false);
qtvUsers->setCurrentIndex(QModelIndex());
qteChat->setEnabled(false);
Global::get().trayIcon->updateIcon();

#ifdef Q_OS_MAC
// Remove App Nap suppression now that we're disconnected.
Expand Down Expand Up @@ -3578,6 +3604,8 @@ void MainWindow::serverDisconnected(QAbstractSocket::SocketError err, QString re
if (Global::get().s.bMinimalView) {
qdwMinimalViewNote->show();
}

Global::get().trayIcon->updateIcon();
}

void MainWindow::resolverError(QAbstractSocket::SocketError, QString reason) {
Expand All @@ -3596,13 +3624,13 @@ void MainWindow::resolverError(QAbstractSocket::SocketError, QString reason) {
}

void MainWindow::showRaiseWindow() {
if (isMinimized()) {
setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
}

show();
raise();
activateWindow();
setWindowState(windowState() & ~Qt::WindowMinimized);
QTimer::singleShot(0, [this]() {
show();
raise();
activateWindow();
setWindowState(windowState() | Qt::WindowActive);
});
}

void MainWindow::on_qaTalkingUIToggle_triggered() {
Expand Down Expand Up @@ -3980,6 +4008,7 @@ void MainWindow::openConfigDialog() {
setupView(false);
updateTransmitModeComboBox(Global::get().s.atTransmit);
updateUserModel();
Global::get().trayIcon->updateIcon();

if (Global::get().s.requireRestartToApply) {
if (Global::get().s.requireRestartToApply
Expand Down
1 change: 1 addition & 0 deletions src/mumble/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class MainWindow : public QMainWindow, public Ui::MainWindow {
QIcon qiIcon, qiIconMutePushToMute, qiIconMuteSelf, qiIconMuteServer, qiIconDeafSelf, qiIconDeafServer,
qiIconMuteSuppressed;
QIcon qiTalkingOn, qiTalkingWhisper, qiTalkingShout, qiTalkingOff;
QIcon iconComment;
std::unordered_map< unsigned int, qt_unique_ptr< UserLocalNicknameDialog > > qmUserNicknameTracker;

/// "Action" for when there are no actions available
Expand Down
4 changes: 4 additions & 0 deletions src/mumble/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#include "VersionCheck.h"
#include "Global.h"

#include "widgets/TrayIcon.h"

#include <QLocale>
#include <QScreen>
#include <QtCore/QProcess>
Expand Down Expand Up @@ -684,6 +686,8 @@ int main(int argc, char **argv) {
Global::get().mw = new MainWindow(nullptr);
Global::get().mw->show();

Global::get().trayIcon = new TrayIcon();

Global::get().talkingUI = new TalkingUI();

// Set TalkingUI's position
Expand Down
Loading

0 comments on commit 6441e47

Please sign in to comment.