From 3b6b550ac0832376062c6c7e7e37b85b46454ecd Mon Sep 17 00:00:00 2001 From: Alexander Barker Date: Sat, 19 Mar 2022 20:44:03 -0700 Subject: [PATCH] Change USE_OBJC flag to USE_APPKIT. Fixes #133 --- CMakeLists.txt | 12 ++---------- README.md | 2 +- src/darwin/input_hook.c | 18 +++++++++--------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a880277a..45a65ca0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -249,16 +249,8 @@ elseif(APPLE) target_link_libraries(uiohook "${IOKIT}") endif() - # FIXME Change USE_OBJC flag to USE_APPKIT - #option(USE_APPKIT "AppKit framework (default: ON)" ON) - option(USE_OBJC "Objective-C API (default: ON)" ON) - if(USE_OBJC) - # FIXME Drop USE_OBJC as it is included in AppKit - find_library(OBJC objc REQUIRED) - add_compile_definitions(USE_OBJC) - target_include_directories(uiohook PRIVATE "${OBJC}") - target_link_libraries(uiohook "${OBJC}") - + option(USE_APPKIT "AppKit framework (default: ON)" ON) + if(USE_APPKIT) find_library(APPKIT AppKit REQUIRED) add_compile_definitions(USE_APPKIT) target_include_directories(uiohook PRIVATE "${APPKIT}") diff --git a/README.md b/README.md index 46f38077..601895d7 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ $ cmake --build . --parallel 2 --target install | | USE_EPOCH_TIME:BOOL | unix epch event times | OFF | | __OSX__ | USE_APPLICATION_SERVICES:BOOL | framework | ON | | | USE_IOKIT:BOOL | framework | ON | -| | USE_OBJC:BOOL | obj-c api | ON | +| | USE_APPKIT:BOOL | obj-c api | ON | | __Win32__ | | | | | __Linux__ | USE_EVDEV:BOOL | generic input driver | ON | | __*nix__ | USE_XF86MISC:BOOL | xfree86-misc extension | OFF | diff --git a/src/darwin/input_hook.c b/src/darwin/input_hook.c index 33934d52..d2a4a54f 100644 --- a/src/darwin/input_hook.c +++ b/src/darwin/input_hook.c @@ -19,7 +19,7 @@ #include #include -#ifdef USE_OBJC +#ifdef USE_APPKIT #include #include #endif @@ -44,7 +44,7 @@ typedef struct _event_runloop_info { CFRunLoopObserverRef observer; } event_runloop_info; -#ifdef USE_OBJC +#ifdef USE_APPKIT static id auto_release_pool; typedef struct { @@ -504,7 +504,7 @@ static inline void process_modifier_changed(uint64_t timestamp, CGEventRef event } } -#ifdef USE_OBJC +#ifdef USE_APPKIT static void obcj_message(void *info) { TISEventMessage *data = (TISEventMessage *) info; @@ -527,7 +527,7 @@ static inline void process_system_key(uint64_t timestamp, CGEventRef event_ref) UInt32 subtype = 0; UInt32 data1 = 0; - #ifdef USE_OBJC + #ifdef USE_APPKIT bool is_runloop_main = CFEqual(event_loop, CFRunLoopGetMain()); tis_event_message->event = event_ref; tis_event_message->subtype = 0; @@ -580,7 +580,7 @@ static inline void process_system_key(uint64_t timestamp, CGEventRef event_ref) free(buffer); CFRelease(data_ref); - #ifdef USE_OBJC + #ifdef USE_APPKIT } #endif @@ -1323,7 +1323,7 @@ UIOHOOK_API int hook_run() { return UIOHOOK_ERROR_OUT_OF_MEMORY; } - #ifdef USE_OBJC + #ifdef USE_APPKIT tis_event_message = (TISEventMessage *) calloc(1, sizeof(TISEventMessage)); if (tis_event_message == NULL) { logger(LOG_LEVEL_ERROR, "%s [%u]: Failed to allocate memory for TIS event structure!\n", @@ -1384,7 +1384,7 @@ UIOHOOK_API int hook_run() { } } - #ifdef USE_OBJC + #ifdef USE_APPKIT // Contributed by Alex // Create a garbage collector to handle Cocoa events correctly. Class NSAutoreleasePool_class = (Class) objc_getClass("NSAutoreleasePool"); @@ -1399,7 +1399,7 @@ UIOHOOK_API int hook_run() { CFRunLoopRun(); - #ifdef USE_OBJC + #ifdef USE_APPKIT // Contributed by Alex eventWithoutCGEvent(auto_release_pool, sel_registerName("release")); #endif @@ -1414,7 +1414,7 @@ UIOHOOK_API int hook_run() { pthread_mutex_unlock(&main_runloop_mutex); #endif - #ifdef USE_OBJC + #ifdef USE_APPKIT free(tis_event_message); #endif free(tis_keycode_message);