Skip to content

Commit

Permalink
Fix macOS 15 dark theme menu icons (#988)
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev authored Nov 24, 2024
1 parent 8d6032f commit 83f5efb
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ jobs:
matrix:
include:
- JOB_RUNNER: macos-14
JOB_NAME: macOS 14 (arm64/M1/M2)
JOB_NAME: macOS 14 (arm64 = M1/M2/M3/M4)
QT_VERSION: 6
NICE_NAME: arm64_M1_M2
- JOB_RUNNER: macos-13
Expand Down
11 changes: 4 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,10 @@ if ( "${PLATFORM}" MATCHES "osx" )
if (CMAKE_OSX_DEPLOYMENT_TARGET)
set(CMAKE_OSX_HYPERHDR_DEPLOYMENT_TARGET ${CMAKE_OSX_DEPLOYMENT_TARGET})
else()
set(VERSION_REPLACEMENT ${CMAKE_OSX_SYSROOT})
string(REPLACE "/SDKs/MacOSX" "." VERSION_REPLACEMENT ${VERSION_REPLACEMENT})
string(REPLACE "." ";" VERSION_REPLACEMENT_LIST ${VERSION_REPLACEMENT})
list(LENGTH VERSION_REPLACEMENT_LIST VERSION_REPLACEMENT_LIST_LENGTH)
if (${VERSION_REPLACEMENT_LIST_LENGTH} GREATER_EQUAL 1)
list (GET VERSION_REPLACEMENT_LIST 1 CMAKE_OSX_HYPERHDR_DEPLOYMENT_TARGET)
endif()
string(REGEX MATCH "MacOSX([0-9]+)" _ ${CMAKE_OSX_SYSROOT})
if (${CMAKE_MATCH_COUNT} EQUAL "1")
set(CMAKE_OSX_HYPERHDR_DEPLOYMENT_TARGET ${CMAKE_MATCH_1})
endif()
endif(CMAKE_OSX_DEPLOYMENT_TARGET)

if (CMAKE_OSX_HYPERHDR_DEPLOYMENT_TARGET)
Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ if [[ "$CI_NAME" == 'osx' || "$CI_NAME" == 'darwin' ]]; then
if [[ $(uname -m) == 'arm64' ]]; then
BUILD_OPTION=""
else
BUILD_OPTION="-DUSE_PRECOMPILED_HEADERS=OFF"
BUILD_OPTION="-DUSE_PRECOMPILED_HEADERS=OFF -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15"
export CCACHE_COMPILERCHECK=content
fi
else
Expand All @@ -129,7 +129,7 @@ if [[ "$CI_NAME" == 'osx' || "$CI_NAME" == 'darwin' ]]; then
ls -a build/.ccache
cd build
ccache -z -d ./.ccache || true
cmake -DPLATFORM=${PLATFORM} ${BUILD_OPTION} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DCMAKE_INSTALL_PREFIX:PATH=/usr/local ../ || exit 2
cmake -DPLATFORM=${PLATFORM} ${BUILD_OPTION} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DCMAKE_INSTALL_PREFIX:PATH=/usr/local ../ || exit 2
make -j $(sysctl -n hw.ncpu) || exit 3
sudo cpack || exit 3
ccache -sv -d ./.ccache || true
Expand Down
4 changes: 4 additions & 0 deletions include/systray/Systray.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ struct SystrayMenu
void SystrayClose();
#endif

#ifdef __APPLE__
bool SystrayDarkmode();
#endif

#ifdef _WIN32
HWND SystrayGetWindow();
#endif
Expand Down
2 changes: 1 addition & 1 deletion resources/icons/autorun.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/icons/clear.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/icons/color.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/icons/effects.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/icons/instance.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions resources/icons/settings.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion sources/hyperhdr/SystrayHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,14 @@ static void loadSvg(std::unique_ptr<SystrayMenu>& menu, QString filename, QStrin
menu->tooltip = fullPath.toStdString();
#else
std::vector<uint8_t> ar;
utils_image::svg2png(preloadSvg(filename).toStdString(), iconDim, iconDim, ar);
QString svgFile = preloadSvg(filename);
#ifdef __APPLE__
if (filename.indexOf(":/") == 0 && SystrayDarkmode())
{
svgFile.replace("fill=\"black\"", "fill=\"white\"");
}
#endif
utils_image::svg2png(svgFile.toStdString(), iconDim, iconDim, ar);

menu->icon.resize(ar.size());
memcpy(menu->icon.data(), ar.data(), ar.size());
Expand Down
6 changes: 6 additions & 0 deletions sources/systray/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ if(ENABLE_SYSTRAY AND UNIX)
target_link_libraries(systray-widget PRIVATE ${AppIndicator_LIBRARIES} )
endif()
endif()

if(APPLE)
if (${MACOS_MAJOR_VERSION} GREATER_EQUAL "14")
target_compile_definitions(systray-widget PUBLIC MACOS_VERSION_14_UP)
endif()
endif()
9 changes: 9 additions & 0 deletions sources/systray/SystrayMacOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ int SystrayLoop()
return 0;
}

bool SystrayDarkmode()
{
#ifndef MACOS_VERSION_14_UP
return NSAppearance.currentAppearance.name == NSAppearanceNameDarkAqua;
#else
return [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"] != nil;
#endif
}

void SystrayUpdate(SystrayMenu* tray)
{
double iconHeight = [[NSStatusBar systemStatusBar] thickness];
Expand Down

0 comments on commit 83f5efb

Please sign in to comment.