From b1c4eb34de868dcf79f840ffd798116b19ecb093 Mon Sep 17 00:00:00 2001 From: shun-iwasawa Date: Tue, 28 Jul 2026 17:52:10 +0900 Subject: [PATCH] fix macos dock icon --- sources/CMakeLists.txt | 16 ++++++++++++++++ sources/instancemanager.cpp | 12 ++++++++++++ sources/macdockicon.h | 25 +++++++++++++++++++++++++ sources/macdockicon.mm | 9 +++++++++ 4 files changed, 62 insertions(+) create mode 100644 sources/macdockicon.h create mode 100644 sources/macdockicon.mm diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index b076074..d406f8d 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -20,6 +20,7 @@ set(HEADERS xdtsio.h pathutils.h commandmanager.h + macdockicon.h ${MOC_HEADERS} ) @@ -56,6 +57,18 @@ else() message(ERROR "Unsupported build environment, only MSVC and APPLE are supported") endif() +# macdockicon.mm is Objective-C++ (hides the mothership process's Dock icon +# on macOS); only compiled for the Apple build, MSVC cannot build .mm files. +# macdockicon.mmはObjective-C++(macOSで母艦プロセスのDockアイコンを隠す +# ためのもの)。Appleビルドでのみコンパイルする。MSVCは.mmファイルを +# ビルドできない。 +if(BUILD_ENV_APPLE) + set(SOURCES + ${SOURCES} + macdockicon.mm + ) +endif() + #----------------------------------------------------------------------------- # Build Options option(WITH_TRANSLATION "Generate translation projects as well" ON) @@ -166,6 +179,9 @@ if(BUILD_ENV_MSVC) target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::Network ${PSD_SDK_LIB} ) else() target_link_libraries(${PROJECT_NAME} Qt5::Widgets Qt5::Network) + # AppKit is needed by macdockicon.mm (NSApplicationActivationPolicy). + # AppKitはmacdockicon.mm(NSApplicationActivationPolicy)に必要。 + target_link_libraries(${PROJECT_NAME} "-framework AppKit") endif() add_definitions( diff --git a/sources/instancemanager.cpp b/sources/instancemanager.cpp index 47cbe3f..52f28c3 100644 --- a/sources/instancemanager.cpp +++ b/sources/instancemanager.cpp @@ -2,6 +2,7 @@ #include "pathutils.h" #include "xdtsio.h" #include "dialogs.h" +#include "macdockicon.h" #include #include @@ -171,6 +172,17 @@ void InstanceManager::startMothership(const QString& initialPath) { // –¾Ž¦“I‚ɐ§Œ䂷‚é�B qApp->setQuitOnLastWindowClosed(false); + // The mothership has no window, but on macOS every process that starts a + // Cocoa event loop still gets a Dock icon by default; hide it so the app + // doesn't show two Dock icons (one for this process, one for the worker + // window it spawns). + // •êŠ͂̓EƒBƒ“ƒhƒE‚ðŽ�‚½‚Ȃ¢‚ª�AmacOS‚łÍCocoa‚̃Cƒxƒ“ƒgƒ‹�[ƒv‚ðŠJŽn‚µ‚½ + // Šeƒvƒ�ƒZƒX‚͊ù’è‚ÅDockƒAƒCƒRƒ“‚ðŽ�‚B‹N“®‚·‚郏�[ƒJ�[ƒEƒBƒ“ƒhƒE‚Ì + // ƒAƒCƒRƒ“‚ƕÀ‚ñ‚Å2‚•\ަ‚³‚ê‚Ȃ¢‚悤�A‚±‚±‚ʼnB‚·�B +#ifdef __MACOS__ + hideDockIcon(); +#endif + // Treat our own launch argument the same way as a request coming from // another process (always spawns a worker, since nothing is registered // yet at this point). diff --git a/sources/macdockicon.h b/sources/macdockicon.h new file mode 100644 index 0000000..e79478e --- /dev/null +++ b/sources/macdockicon.h @@ -0,0 +1,25 @@ +#pragma once +#ifndef MACDOCKICON_H +#define MACDOCKICON_H + +#ifdef __MACOS__ +// Hides this process's Dock icon and Cmd+Tab entry +// (NSApplicationActivationPolicyAccessory). The invisible mothership +// process has no window of its own, but every process that starts a Cocoa +// event loop gets a Dock icon by default -- without this, launching XDTS +// Viewer shows two Dock icons (one for the mothership, one for the +// per-file worker window) instead of one. Safe to call at any time after +// QApplication is constructed; it does not prevent this process from +// later showing dialogs (e.g. the CSP sync picker) in the foreground. +// このプロセスのDockアイコンとCmd+Tabへの表示を隠す +// (NSApplicationActivationPolicyAccessory)。母艦プロセスは自身の +// ウィンドウを持たないが、Cocoaのイベントループを開始した各プロセスは +// 既定でDockアイコンを1つ持つため、これを行わないとXDTS Viewer起動時に +// Dockアイコンが2つ(母艦用とファイルごとのワーカーウィンドウ用)表示 +// されてしまう。QApplication構築後であればいつ呼んでも良く、これを +// 呼んだ後もこのプロセスがCSP同期ピッカーなどのダイアログを前面に表示 +// することは妨げられない。 +void hideDockIcon(); +#endif + +#endif diff --git a/sources/macdockicon.mm b/sources/macdockicon.mm new file mode 100644 index 0000000..000dd84 --- /dev/null +++ b/sources/macdockicon.mm @@ -0,0 +1,9 @@ +#include "macdockicon.h" + +#ifdef __MACOS__ +#import + +void hideDockIcon() { + [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory]; +} +#endif