Skip to content

Commit 171af5b

Browse files
committed
qt: generate tray icons for macOS, update script, set at runtime
1 parent a1522c9 commit 171af5b

File tree

9 files changed

+41
-1
lines changed

9 files changed

+41
-1
lines changed

contrib/devtools/gen_macos_icons.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
("macos_regtest.png", "dash_macos_regtest.png"),
2626
("macos_testnet.png", "dash_macos_testnet.png"),
2727
]
28+
TRAY = os.path.join(DIR_SRC, "tray.svg")
2829

2930
# Canvas to filename mapping for bundle icon
3031
ICNS_MAP = [
@@ -40,6 +41,14 @@
4041
(1024, "icon_512x512@2x.png"),
4142
]
4243

44+
# Maximum height of canvas is 22pt, we use max height instead of recommended
45+
# 16pt canvas to prevent the icon from looking undersized due to icon width.
46+
# See https://bjango.com/articles/designingmenubarextras/
47+
TRAY_MAP = [
48+
(22, "dash_macos_tray.png"),
49+
(44, "dash_macos_tray@2x.png")
50+
]
51+
4352

4453
def sips_resample_padded(src, dst, canvas_size):
4554
content_size = max(round(canvas_size * CONTENT_RATIO), 1)
@@ -49,6 +58,13 @@ def sips_resample_padded(src, dst, canvas_size):
4958
)
5059

5160

61+
def sips_svg_to_png(svg_path, png_path, height):
62+
subprocess.check_call(
63+
["sips", "-s", "format", "png", "--resampleHeight", str(height), svg_path, "--out", png_path],
64+
stdout=subprocess.DEVNULL,
65+
)
66+
67+
5268
def generate_icns(tmpdir):
5369
iconset = os.path.join(tmpdir, "dash.iconset")
5470
os.makedirs(iconset)
@@ -86,6 +102,11 @@ def main():
86102
sips_resample_padded(src, dst, 256)
87103
print(f"Created: {dst}")
88104

105+
# Generate tray icons
106+
for canvas_px, filename in TRAY_MAP:
107+
dst = os.path.join(DIR_OUT, filename)
108+
sips_svg_to_png(TRAY, dst, canvas_px)
109+
print(f"Created: {dst}")
89110

90111
if __name__ == "__main__":
91112
main()

src/Makefile.qt.include

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ QT_RES_ICONS = \
220220
qt/res/icons/dash_macos_mainnet.png \
221221
qt/res/icons/dash_macos_regtest.png \
222222
qt/res/icons/dash_macos_testnet.png \
223+
qt/res/icons/dash_macos_tray.png \
224+
qt/res/icons/dash_macos_tray@2x.png \
223225
qt/res/icons/dash_testnet.ico \
224226
qt/res/icons/editcopy.png \
225227
qt/res/icons/editpaste.png \

src/qt/bitcoingui.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,13 @@ void BitcoinGUI::createTrayIcon()
11211121
assert(QSystemTrayIcon::isSystemTrayAvailable());
11221122

11231123
if (QSystemTrayIcon::isSystemTrayAvailable()) {
1124-
trayIcon = new QSystemTrayIcon(m_network_style->getTrayAndWindowIcon(), this);
1124+
QIcon icon{m_network_style->getTrayAndWindowIcon()};
1125+
#ifdef Q_OS_MACOS
1126+
if (auto macos_tray{m_network_style->getMacTray()}) {
1127+
icon = macos_tray.value();
1128+
}
1129+
#endif // Q_OS_MACOS
1130+
trayIcon = new QSystemTrayIcon(icon, this);
11251131
QString toolTip = tr("%1 client").arg(PACKAGE_NAME) + " " + m_network_style->getTitleAddText();
11261132
trayIcon->setToolTip(toolTip);
11271133
}

src/qt/dash.qrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<file alias="dash_macos_mainnet">res/icons/dash_macos_mainnet.png</file>
66
<file alias="dash_macos_regtest">res/icons/dash_macos_regtest.png</file>
77
<file alias="dash_macos_testnet">res/icons/dash_macos_testnet.png</file>
8+
<file alias="dash_macos_tray">res/icons/dash_macos_tray.png</file>
9+
<file alias="dash_macos_tray@2x">res/icons/dash_macos_tray@2x.png</file>
810
<file alias="warning">res/icons/warning.png</file>
911
<file alias="address-book">res/icons/address-book.png</file>
1012
<file alias="connect_1">res/icons/connect1_16.png</file>

src/qt/networkstyle.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ NetworkStyle::NetworkStyle(const QString &_appName, const int iconColorHueShift,
9393
if (_macIconPath) {
9494
m_macos_icon = QIcon(QPixmap(_macIconPath));
9595
}
96+
m_macos_tray = QIcon(QPixmap(":/icons/dash_macos_tray"));
97+
m_macos_tray->setIsMask(true);
9698
#endif // Q_OS_MAC
9799
}
98100

src/qt/networkstyle.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class NetworkStyle
2727
const QColor &getBadgeColor() const { return badgeColor; }
2828
#ifdef Q_OS_MAC
2929
std::optional<QIcon> getMacIcon() const { return m_macos_icon; }
30+
std::optional<QIcon> getMacTray() const { return m_macos_tray; }
3031
#endif // Q_OS_MAC
3132

3233
private:
@@ -41,6 +42,7 @@ class NetworkStyle
4142
QColor badgeColor;
4243
#ifdef Q_OS_MAC
4344
std::optional<QIcon> m_macos_icon;
45+
std::optional<QIcon> m_macos_tray;
4446
#endif // Q_OS_MAC
4547

4648
void rotateColor(QColor& col, const int iconColorHueShift, const int iconColorSaturationReduction);
680 Bytes
Loading
1.38 KB
Loading

src/qt/res/src/tray.svg

Lines changed: 5 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)