From 1d744ae515bfa2ecc0a9a5b9d68cf479d15e5e6b Mon Sep 17 00:00:00 2001 From: eidheim Date: Tue, 14 Apr 2020 14:22:13 +0200 Subject: [PATCH] MacOS: places juCi++ in front at startup for MacOS versions Mojave and earlier --- CMakeLists.txt | 4 +++- src/CMakeLists.txt | 12 +++++++++++- src/juci.cc | 11 +++++++++++ src/window_macos.h | 6 ++++++ src/window_macos.m | 5 +++++ 5 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/window_macos.h create mode 100644 src/window_macos.m diff --git a/CMakeLists.txt b/CMakeLists.txt index 99665e8..56f706e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,9 @@ set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://gitlab.com/cppit/jucipp") set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) include(CPack) -add_compile_options(-std=c++1y -pthread -Wall -Wextra -Wno-unused-parameter) +set(CMAKE_CXX_STANDARD 14) + +add_compile_options(-pthread -Wall -Wextra -Wno-unused-parameter) add_definitions(-DJUCI_VERSION="${JUCI_VERSION}") if(CMAKE_BUILD_TYPE STREQUAL "") add_compile_options(-O3) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bed80b2..713f62f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,7 +40,7 @@ target_link_libraries(juci_shared tiny-process-library ) -add_executable(juci +set(JUCI_FILES config.cc dialogs.cc dialogs_unix.cc @@ -54,8 +54,18 @@ add_executable(juci tooltips.cc window.cc ) +if(APPLE) + list(APPEND JUCI_FILES window_macos.m) +endif() + +add_executable(juci ${JUCI_FILES}) target_link_libraries(juci juci_shared) +if(APPLE) + target_link_libraries(juci "-framework Foundation -framework AppKit") +endif() + + install(TARGETS juci RUNTIME DESTINATION bin) if(${CMAKE_SYSTEM_NAME} MATCHES Linux|.*BSD|DragonFly) install(FILES "${CMAKE_SOURCE_DIR}/share/juci.desktop" diff --git a/src/juci.cc b/src/juci.cc index 462935d..8322596 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -9,6 +9,10 @@ #ifndef _WIN32 #include #endif +#ifdef __APPLE__ +#include "dispatcher.h" +#include "window_macos.h" +#endif int Application::on_command_line(const Glib::RefPtr &cmd) { Glib::set_prgname("juci"); @@ -104,6 +108,13 @@ void Application::on_activate() { view->scroll_to_cursor_delayed(true, false); } } + +#ifdef __APPLE__ + static Dispatcher dispatcher; + dispatcher.post([] { + macos_force_foreground_level(); // Must run after all other events + }); +#endif } void Application::on_startup() { diff --git a/src/window_macos.h b/src/window_macos.h new file mode 100644 index 0000000..431c524 --- /dev/null +++ b/src/window_macos.h @@ -0,0 +1,6 @@ +#pragma once + +extern "C" { +/// Based on https://stackoverflow.com/a/47497879 +void macos_force_foreground_level(); +} diff --git a/src/window_macos.m b/src/window_macos.m new file mode 100644 index 0000000..2ca0f2a --- /dev/null +++ b/src/window_macos.m @@ -0,0 +1,5 @@ +#import + +void macos_force_foreground_level() { + [NSApp activateIgnoringOtherApps: YES]; +}