Skip to content

Commit 53cf098

Browse files
committed
Use symbolic monochrome tray icon
1 parent 4f88834 commit 53cf098

File tree

7 files changed

+57
-3
lines changed

7 files changed

+57
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ The D-Bus introspection XML is available here: https://github.com/Audio4Linux/JD
488488

489489
This project is licensed under [GPLv3](LICENSE).
490490

491+
The project makes use of [Papirus icons](https://github.com/PapirusDevelopmentTeam/papirus-icon-theme) licensed under [GPLv3](LICENSE).
492+
491493
```
492494
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
493495
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Lines changed: 8 additions & 0 deletions
Loading

resources/icons/jamesdsp-tray.svg

Lines changed: 8 additions & 0 deletions
Loading

resources/resources.qrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,7 @@
9797
<file>translations/jamesdsp_ko.qm</file>
9898
<file>translations/jamesdsp_nl.qm</file>
9999
<file>translations/jamesdsp_no.qm</file>
100+
<file>icons/jamesdsp-tray.svg</file>
101+
<file>icons/jamesdsp-tray-light.svg</file>
100102
</qresource>
101103
</RCC>

src/MainWindow.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ MainWindow::MainWindow(IAudioService* audioService,
174174
connect(_trayIcon, &TrayIcon::changeDisableFx, this, &MainWindow::applyConfig);
175175

176176
_trayIcon->setTrayVisible(AppConfig::instance().get<bool>(AppConfig::TrayIconEnabled) || _startupInTraySwitch);
177+
178+
connect(qApp, &QApplication::paletteChanged, _trayIcon, &TrayIcon::updateTheme);
177179
}
178180

179181
// Populate preset lists

src/interface/TrayIcon.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
#include <QApplication>
88
#include <QMenu>
9+
#include <QDebug>
910
#include <QDir>
11+
#include <QStyle>
12+
#include <QGuiApplication>
13+
#include <QStyleHints>
1014

1115
namespace MenuIO
1216
{
@@ -107,10 +111,37 @@ void TrayIcon::createTrayIcon()
107111
{
108112
menuOwner = new QWidget();
109113
trayIcon = new QSystemTrayIcon(this);
110-
trayIcon->setToolTip(tr("JamesDSP for Linux"));
111-
trayIcon->setIcon(QIcon::fromTheme("jamesdsp-tray", QIcon(":/icons/icon.png")));
114+
trayIcon->setToolTip(tr("JamesDSP for Linux"));
112115

113-
connect(trayIcon, &QSystemTrayIcon::activated, this, &TrayIcon::iconEventHandler);
116+
updateTheme();
117+
118+
connect(trayIcon, &QSystemTrayIcon::activated, this, &TrayIcon::iconEventHandler);
119+
}
120+
121+
void TrayIcon::updateTheme()
122+
{
123+
// Best effort theme detection
124+
bool isDark = true;
125+
QString gtkTheme = QString::fromLocal8Bit(qgetenv("GTK_THEME"));
126+
Log::error(gtkTheme);
127+
if (gtkTheme.contains("light"))
128+
isDark = false;
129+
else if (gtkTheme.contains("dark"))
130+
isDark = true;
131+
else {
132+
// Try to derive from current app palette otherwise
133+
QPalette pal = QApplication::palette();
134+
isDark = pal.color(QPalette::Window).lightness() < 128;
135+
}
136+
137+
if (isDark)
138+
{
139+
trayIcon->setIcon(QIcon::fromTheme("jamesdsp-tray", QIcon(":/icons/jamesdsp-tray.svg")));
140+
}
141+
else
142+
{
143+
trayIcon->setIcon(QIcon::fromTheme("jamesdsp-tray", QIcon(":/icons/jamesdsp-tray-light.svg")));
144+
}
114145
}
115146

116147
void TrayIcon::setTrayVisible(bool visible)

src/interface/TrayIcon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class TrayIcon :
2626
public slots:
2727
void changedDisableFx(bool disabled);
2828
void setTrayVisible(bool visible);
29+
void updateTheme();
2930

3031
signals:
3132
void iconActivated();

0 commit comments

Comments
 (0)