From 93ff0aa6d019df6c87fb8682759f3112fbc71998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ian=20Langworth=20=E2=98=A0?= Date: Sat, 8 Aug 2015 18:16:50 -0700 Subject: [PATCH] Use greyscale menubar icons on Mac OS X. --- src/gui/gui.pro | 2 ++ src/gui/src/MainWindow.cpp | 30 ++++++++++++++++++++++++++++-- src/gui/src/OSXHelpers.h | 24 ++++++++++++++++++++++++ src/gui/src/OSXHelpers.mm | 31 +++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 src/gui/src/OSXHelpers.h create mode 100644 src/gui/src/OSXHelpers.mm diff --git a/src/gui/gui.pro b/src/gui/gui.pro index 28d1ee6ee1..4fb0a133a9 100644 --- a/src/gui/gui.pro +++ b/src/gui/gui.pro @@ -119,6 +119,8 @@ macx { QSYNERGY_ICON.path = Contents/Resources QMAKE_BUNDLE_DATA += QSYNERGY_ICON LIBS += $$MACX_LIBS + HEADERS += src/OSXHelpers.h + SOURCES += src/OSXHelpers.mm } unix:!macx:LIBS += -ldns_sd debug { diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index 7f3753eddc..c2b4845333 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -35,6 +35,10 @@ #include "QUtility.h" #include "ProcessorArch.h" +#if defined(Q_OS_MAC) +#include "OSXHelpers.h" +#endif + #include #include #include @@ -67,7 +71,21 @@ static const char synergyConfigName[] = "synergy.conf"; static const QString synergyConfigFilter(QObject::tr("Synergy Configurations (*.conf);;All files (*.*)")); #endif -static const char* synergyIconFiles[] = +static const char* synergyLightIconFiles[] = +{ + ":/res/icons/64x64/synergy-light-disconnected.png", + ":/res/icons/64x64/synergy-light-disconnected.png", + ":/res/icons/64x64/synergy-light-connected.png", + ":/res/icons/64x64/synergy-light-transfering.png" +}; +static const char* synergyDarkIconFiles[] = +{ + ":/res/icons/64x64/synergy-dark-disconnected.png", + ":/res/icons/64x64/synergy-dark-disconnected.png", + ":/res/icons/64x64/synergy-dark-connected.png", + ":/res/icons/64x64/synergy-dark-transfering.png" +}; +static const char* synergyDefaultIconFiles[] = { ":/res/icons/16x16/synergy-disconnected.png", ":/res/icons/16x16/synergy-disconnected.png", @@ -313,7 +331,15 @@ void MainWindow::saveSettings() void MainWindow::setIcon(qSynergyState state) { QIcon icon; - icon.addFile(synergyIconFiles[state]); + +#ifdef Q_OS_MAC + if (isOSXInterfaceStyleDark()) + icon.addFile(synergyDarkIconFiles[state]); + else + icon.addFile(synergyLightIconFiles[state]); +#else + icon.addFile(synergyDefaultIconFiles[state]); +#endif if (m_pTrayIcon) m_pTrayIcon->setIcon(icon); diff --git a/src/gui/src/OSXHelpers.h b/src/gui/src/OSXHelpers.h new file mode 100644 index 0000000000..6b2b65bc0a --- /dev/null +++ b/src/gui/src/OSXHelpers.h @@ -0,0 +1,24 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2015 Synergy Si Ltd. + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OSXHELPERS__H) + +#define OSXHELPERS__H + +bool isOSXInterfaceStyleDark(); + +#endif diff --git a/src/gui/src/OSXHelpers.mm b/src/gui/src/OSXHelpers.mm new file mode 100644 index 0000000000..de5debbee2 --- /dev/null +++ b/src/gui/src/OSXHelpers.mm @@ -0,0 +1,31 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2015 Synergy Si Ltd. + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#import "OSXHelpers.h" + +#import +#import +#import + +bool +isOSXInterfaceStyleDark() +{ + // Implementation from http://stackoverflow.com/a/26472651 + NSDictionary* dict = [[NSUserDefaults standardUserDefaults] persistentDomainForName:NSGlobalDomain]; + id style = [dict objectForKey:@"AppleInterfaceStyle"]; + return (style && [style isKindOfClass:[NSString class]] && NSOrderedSame == [style caseInsensitiveCompare:@"dark"]); +}