Browse Source

MacOS: places juCi++ in front at startup for MacOS versions Mojave and earlier

pipelines/143601543
eidheim 6 years ago
parent
commit
1d744ae515
  1. 4
      CMakeLists.txt
  2. 12
      src/CMakeLists.txt
  3. 11
      src/juci.cc
  4. 6
      src/window_macos.h
  5. 5
      src/window_macos.m

4
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)

12
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"

11
src/juci.cc

@ -9,6 +9,10 @@
#ifndef _WIN32
#include <csignal>
#endif
#ifdef __APPLE__
#include "dispatcher.h"
#include "window_macos.h"
#endif
int Application::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &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() {

6
src/window_macos.h

@ -0,0 +1,6 @@
#pragma once
extern "C" {
/// Based on https://stackoverflow.com/a/47497879
void macos_force_foreground_level();
}

5
src/window_macos.m

@ -0,0 +1,5 @@
#import <AppKit/AppKit.h>
void macos_force_foreground_level() {
[NSApp activateIgnoringOtherApps: YES];
}
Loading…
Cancel
Save