Skip to content

Commit

Permalink
Let tray image blend into macOS menu bar
Browse files Browse the repository at this point in the history
The expected style for macOS menu bar images is a template image than
can adapt to the user's appearance settings. Also, high-res screens
("Retina" in Apple speak) need higher resolution images.

Based on /res/barrier.svg, I created black and transparent SVGs for the
three icon states. I had to remove some details to make the image scale
down to icon size without becoming too crowded, and I drew a new
checkmark and the transfer arrow.
  • Loading branch information
tiwoc committed Nov 21, 2019
1 parent 1246ec3 commit 8ef0668
Show file tree
Hide file tree
Showing 8 changed files with 381 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/gui/res/Barrier.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,8 @@
<file>image/spinning-wheel.gif</file>
<file>icons/16x16/padlock.png</file>
<file>icons/16x16/barrier-transfering.png</file>
<file>icons/32x32/barrier-connected-mask.png</file>
<file>icons/32x32/barrier-disconnected-mask.png</file>
<file>icons/32x32/barrier-transfering-mask.png</file>
</qresource>
</RCC>
Binary file added src/gui/res/icons/32x32/barrier-connected-mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 114 additions & 0 deletions src/gui/res/icons/32x32/barrier-connected-mask.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions src/gui/res/icons/32x32/barrier-disconnected-mask.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/gui/res/icons/32x32/barrier-transfering-mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
148 changes: 148 additions & 0 deletions src/gui/res/icons/32x32/barrier-transfering-mask.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 14 additions & 2 deletions src/gui/src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,17 @@ static const QString barrierConfigFilter(QObject::tr("Barrier Configurations (*.

static const char* barrierIconFiles[] =
{
#if defined(Q_OS_MAC)
":/res/icons/32x32/barrier-disconnected-mask.png",
":/res/icons/32x32/barrier-disconnected-mask.png",
":/res/icons/32x32/barrier-connected-mask.png",
":/res/icons/32x32/barrier-transfering-mask.png"
#else
":/res/icons/16x16/barrier-disconnected.png",
":/res/icons/16x16/barrier-disconnected.png",
":/res/icons/16x16/barrier-connected.png",
":/res/icons/16x16/barrier-transfering.png"
#endif
};

static const char* barrierLargeIcon = ":/res/icons/256x256/barrier.ico";
Expand Down Expand Up @@ -288,8 +295,13 @@ void MainWindow::saveSettings()

void MainWindow::setIcon(qBarrierState state)
{
if (m_pTrayIcon)
m_pTrayIcon->setIcon(QIcon(barrierIconFiles[state]));
if (m_pTrayIcon) {
QIcon icon = QIcon(barrierIconFiles[state]);
#if defined(Q_OS_MAC)
icon.setIsMask(true);
#endif
m_pTrayIcon->setIcon(icon);
}
}

void MainWindow::trayActivated(QSystemTrayIcon::ActivationReason reason)
Expand Down

0 comments on commit 8ef0668

Please sign in to comment.