[rkward/work/frameworks-Mac] rkward/rbackend: Start rkward.rbackend as an "agent"

R.J.V. Bertin null at kde.org
Wed May 17 20:29:50 UTC 2017

Git commit e647a5f6f99d14fcde643ca697e2691ffeed697f by R.J.V. Bertin.
Committed on 17/05/2017 at 20:29.
Pushed by rjvbb into branch 'work/frameworks-Mac'.

Start rkward.rbackend as an "agent"

Meaning it has no menubar and doesn't show up in the Dock or app switcher.
This is the programmatic version of setting LSUIElement to 1 in the
Info.plist file.
Doesn't quite work in practice yet for an unknown reason which I suspect is
related to R.

M  +3    -0    rkward/rbackend/CMakeLists.txt
M  +18   -0    rkward/rbackend/rkrbackendprotocol_backend.cpp


diff --git a/rkward/rbackend/CMakeLists.txt b/rkward/rbackend/CMakeLists.txt
index 9fb90a6f..2720b16a 100644
--- a/rkward/rbackend/CMakeLists.txt
+++ b/rkward/rbackend/CMakeLists.txt
 ADD_EXECUTABLE(rkward.rbackend ${rbackend_BACKEND_SRCS})
 TARGET_LINK_LIBRARIES(rkward.rbackend rkgraphicsdevice.backend ${R_USED_LIBS} ${CMAKE_THREAD_LIBS_INIT} Qt5::Network Qt5::Core ${LibIntl_LIBRARIES})
+    TARGET_LINK_LIBRARIES(rkward.rbackend "-framework CoreFoundation")
 	# on Widows, we install to the rbackend subdirectory, because 1) LIBEXEC_INSTALL_DIR == BIN_INSTALL_DIR and 2) we don't want the backend to pick up
diff --git a/rkward/rbackend/rkrbackendprotocol_backend.cpp b/rkward/rbackend/rkrbackendprotocol_backend.cpp
index 84a87884..8880e9d6 100644
--- a/rkward/rbackend/rkrbackendprotocol_backend.cpp
+++ b/rkward/rbackend/rkrbackendprotocol_backend.cpp
@@ -35,6 +35,10 @@
 #include <QDir>
 #include <QUrl>
+#ifdef Q_OS_MACOS
+#include <CoreFoundation/CoreFoundation.h>
 	void RK_setupGettext (const char*);
 	int RK_Debug_Level = 2;
 	int RK_Debug_Flags = DEBUG_ALL;
@@ -68,6 +72,20 @@
 	int main(int argc, char *argv[]) {
+#ifdef Q_OS_MACOS
+		CFBundleRef mainBundle = CFBundleGetMainBundle();
+		if (mainBundle) {
+			// get the application's Info Dictionary. For app bundles this would live in the bundle's Info.plist,
+			// for regular executables it is obtained in another way.
+			CFMutableDictionaryRef infoDict = (CFMutableDictionaryRef) CFBundleGetInfoDictionary(mainBundle);
+			if (infoDict) {
+				// Add or set the "LSUIElement" key with/to value "1". This can simply be a CFString.
+				CFDictionarySetValue(infoDict, CFSTR("LSUIElement"), CFSTR("1"));
+				// That's it. We're now considered as an "agent" by the window server, and thus will have
+				// neither menubar nor presence in the Dock or App Switcher.
+			}
+		}
 		QCoreApplication app (argc, argv);
 		setvbuf (stdout, NULL, _IONBF, 0);

More information about the rkward-tracker mailing list