Skip to content

Commit

Permalink
Change USE_OBJC flag to USE_APPKIT. Fixes #133
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhat committed May 3, 2023
1 parent 6f02c3b commit 3b6b550
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
12 changes: 2 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
18 changes: 9 additions & 9 deletions src/darwin/input_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <dlfcn.h>
#include <mach/mach_time.h>

#ifdef USE_OBJC
#ifdef USE_APPKIT
#include <objc/objc.h>
#include <objc/objc-runtime.h>
#endif
Expand All @@ -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 {
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -1384,7 +1384,7 @@ UIOHOOK_API int hook_run() {
}
}

#ifdef USE_OBJC
#ifdef USE_APPKIT
// Contributed by Alex <[email protected]>
// Create a garbage collector to handle Cocoa events correctly.
Class NSAutoreleasePool_class = (Class) objc_getClass("NSAutoreleasePool");
Expand All @@ -1399,7 +1399,7 @@ UIOHOOK_API int hook_run() {
CFRunLoopRun();


#ifdef USE_OBJC
#ifdef USE_APPKIT
// Contributed by Alex <[email protected]>
eventWithoutCGEvent(auto_release_pool, sel_registerName("release"));
#endif
Expand All @@ -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);
Expand Down

0 comments on commit 3b6b550

Please sign in to comment.