Skip to content

Commit a1522c9

Browse files
committed
qt: apply new runtime icons if running on macOS
1 parent 262274c commit a1522c9

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

src/qt/bitcoingui.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,16 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle,
116116
#ifdef ENABLE_WALLET
117117
enableWallet = WalletModel::isWalletEnabled();
118118
#endif // ENABLE_WALLET
119-
QApplication::setWindowIcon(m_network_style->getTrayAndWindowIcon());
120-
setWindowIcon(m_network_style->getTrayAndWindowIcon());
119+
120+
QIcon icon{m_network_style->getTrayAndWindowIcon()};
121+
#ifdef Q_OS_MACOS
122+
if (auto macos_icon{m_network_style->getMacIcon()}) {
123+
icon = macos_icon.value();
124+
}
125+
#endif // Q_OS_MACOS
126+
QApplication::setWindowIcon(icon);
127+
setWindowIcon(icon);
128+
121129
updateWindowTitle();
122130

123131
rpcConsole = new RPCConsole(node, this, enableWallet ? Qt::Window : Qt::Widget);

src/qt/networkstyle.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ static const struct {
2121
const char *appName;
2222
const int iconColorHueShift;
2323
const int iconColorSaturationReduction;
24+
const char *macIconPath;
2425
const std::string titleAddText;
2526
} network_styles[] = {
26-
{"main", QAPP_APP_NAME_DEFAULT, 0, 0, ""},
27-
{"test", QAPP_APP_NAME_TESTNET, 190, 20, ""},
28-
{"devnet", QAPP_APP_NAME_DEVNET, 35, 15, "[devnet: %s]"},
29-
{"regtest", QAPP_APP_NAME_REGTEST, 160, 30, ""}
27+
{"main", QAPP_APP_NAME_DEFAULT, 0, 0, ":/icons/dash_macos_mainnet", ""},
28+
{"test", QAPP_APP_NAME_TESTNET, 190, 20, ":/icons/dash_macos_testnet", ""},
29+
{"devnet", QAPP_APP_NAME_DEVNET, 35, 15, ":/icons/dash_macos_devnet", "[devnet: %s]"},
30+
{"regtest", QAPP_APP_NAME_REGTEST, 160, 30, ":/icons/dash_macos_regtest", ""},
3031
};
3132

3233
void NetworkStyle::rotateColor(QColor& col, const int iconColorHueShift, const int iconColorSaturationReduction)
@@ -62,7 +63,8 @@ void NetworkStyle::rotateColors(QImage& img, const int iconColorHueShift, const
6263
}
6364

6465
// titleAddText needs to be const char* for tr()
65-
NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *_titleAddText):
66+
NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift, const int iconColorSaturationReduction,
67+
const char *_macIconPath, const char *_titleAddText, const std::string &networkId):
6668
appName(_appName),
6769
titleAddText(qApp->translate("SplashScreen", _titleAddText)),
6870
badgeColor(QColor(0, 141, 228)) // default badge color is the original Dash's blue, regardless of the current theme
@@ -86,6 +88,12 @@ NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift,
8688
appIcon = QIcon(appIconPixmap);
8789
trayAndWindowIcon = QIcon(appIconPixmap.scaled(QSize(256,256)));
8890
splashImage = QPixmap(":/images/splash");
91+
92+
#ifdef Q_OS_MAC
93+
if (_macIconPath) {
94+
m_macos_icon = QIcon(QPixmap(_macIconPath));
95+
}
96+
#endif // Q_OS_MAC
8997
}
9098

9199
const NetworkStyle* NetworkStyle::instantiate(const std::string& networkId)
@@ -107,7 +115,9 @@ const NetworkStyle* NetworkStyle::instantiate(const std::string& networkId)
107115
appName.c_str(),
108116
network_style.iconColorHueShift,
109117
network_style.iconColorSaturationReduction,
110-
titleAddText.c_str());
118+
network_style.macIconPath,
119+
titleAddText.c_str(),
120+
networkId);
111121
}
112122
}
113123
return nullptr;

src/qt/networkstyle.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <QPixmap>
1111
#include <QString>
1212

13+
#include <optional>
14+
1315
/* Coin network-specific GUI style information */
1416
class NetworkStyle
1517
{
@@ -23,16 +25,23 @@ class NetworkStyle
2325
const QIcon &getTrayAndWindowIcon() const { return trayAndWindowIcon; }
2426
const QString &getTitleAddText() const { return titleAddText; }
2527
const QColor &getBadgeColor() const { return badgeColor; }
28+
#ifdef Q_OS_MAC
29+
std::optional<QIcon> getMacIcon() const { return m_macos_icon; }
30+
#endif // Q_OS_MAC
2631

2732
private:
28-
NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction, const char *titleAddText);
33+
NetworkStyle(const QString &appName, const int iconColorHueShift, const int iconColorSaturationReduction,
34+
const char *macIconPath, const char *titleAddText, const std::string &networkId);
2935

3036
QString appName;
3137
QIcon appIcon;
3238
QPixmap splashImage;
3339
QIcon trayAndWindowIcon;
3440
QString titleAddText;
3541
QColor badgeColor;
42+
#ifdef Q_OS_MAC
43+
std::optional<QIcon> m_macos_icon;
44+
#endif // Q_OS_MAC
3645

3746
void rotateColor(QColor& col, const int iconColorHueShift, const int iconColorSaturationReduction);
3847
void rotateColors(QImage& img, const int iconColorHueShift, const int iconColorSaturationReduction);

0 commit comments

Comments
 (0)