Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

CaptainChemist
Copy link

Summary of Changes
This pull request introduces a refactored version of the OSXEventQueueBuffer class, transitioning from the original Carbon-based implementation to a modern Grand Central Dispatch (GCD)-based approach. The key modifications include:

  • Updates the min mac OS version from 10.9 to 10.15 to allow for successful compiling.
  • Removal of Carbon Dependencies: Eliminated the use of Carbon APIs (EventRef, CreateEvent, PostEventToQueue, etc.) to modernize the codebase and improve compatibility with recent macOS versions.
  • Elimination of m_carbonEventQueue: Removed the EventQueueRef m_carbonEventQueue; member, which was previously used for managing Carbon event queues.
  • Introduction of a Thread-Safe Event Queue: Replaced the Carbon event queue with a thread-safe std::queuestd::uint32_t guarded by std::mutex and std::condition_variable.
  • Direct Usage of Main Dispatch Queue: Utilized dispatch_get_main_queue() directly within the addEvent method, removing the need to store a separate dispatch queue member variable.
  • Maintained Original Event Handling Behavior: Ensured that all events added via addEvent are treated as Syne (User) events (kUser), consistent with the original Carbon-based logic that hardcoded the event class to 'Syne'. This meant removing handling for non 'Syne' events from getEvent because we shouldn't get them in the first place since addEvent was hardcoded to 'Syne' events. Additionally, with the refactor, we can't call GetEventClass to tell the type like we could in the Carbon code so the process of having a switch statement is unnecessary in the current implementation.

The purpose of this fix is to address a repeated crashing behavior I saw in mac OS 15.2 where I'd see logs like:

Thread 3 Crashed:
0   HIToolbox                      0x1a8f35f28 PostEventToQueueInternal + 288
1   HIToolbox                      0x1a8f35dcc PostEventToQueue + 116
2   input-leapc                    0x10464a9b0 inputleap::OSXEventQueueBuffer::addEvent(unsigned int) + 108
3   input-leapc                    0x1046243c8 inputleap::EventQueue::add_event_to_buffer(inputleap::Event&&) + 284
4   input-leapc                    0x1046398bc inputleap::TCPSocket::sendEvent(inputleap::EventType) + 68
5   input-leapc                    0x10463f564 inputleap::SecureSocket::doRead() + 404
6   input-leapc                    0x10463aec4 inputleap::TCPSocket::serviceConnected(...) + 268
7   input-leapc                    0x10463c0e0 inputleap::TSocketMultiplexerMethodJob::run(...) + 68
...
Signal:  SIGSEGV (EXC_BAD_ACCESS / KERN_INVALID_ADDRESS at 0x0000000000000028)

I read that PostEventToQueue calls are strongly discouraged in modern macOS and that might explain this bad pointer reference I'm seeing.

Contributor Checklist:

  • [ X] This change affects end users and I have created a file in the doc/newsfragments directory (and made sure to read the README.md in that directory)
  • This change does not affect end users

@sithlord48
Copy link
Contributor

sithlord48 commented Jan 26, 2025

Input leap is unlikey to allow a bump to require mac os 15+ .

If this would apply to deskflow please make a PR.

@CaptainChemist
Copy link
Author

I just made and tested a version of this over on Deskflow:
deskflow/deskflow#8140

Thanks for the feedback on not being able to update the min version from 10.9 to 10.15. Out of curiosity, I do see for version 3.0.2 of Input Leap back on 2024-10-12 the following note:
Minimum MacOS version has been increased to 10.15.
Was that change rolled back? If not, I'd think we'd have to up the minimum version to reflect this change.

For context, this is the error I saw which was resolved by upping the version to 10.15:

FAILED: src/lib/io/CMakeFiles/io.dir/filesystem.cpp.o 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DINPUTLEAP_BUILD_DATE=\"20250126\" -DINPUTLEAP_REVISION=\"\" -DINPUTLEAP_USE_GULRAK_FILESYSTEM=0 -DINPUTLEAP_VERSION="\"3.0.2-'git-2025-01-25-c3d555d4'\"" -DINPUTLEAP_VERSION_MAJOR=3 -DINPUTLEAP_VERSION_MINOR=0 -DINPUTLEAP_VERSION_PATCH=2 -DINPUTLEAP_VERSION_STRING=\"\" -DSYSAPI_UNIX=1 -DWINAPI_CARBON=1 -D_THREAD_SAFE -I/Users/user/dev/input-leap/src/./lib -I/Users/user/dev/input-leap/build/src/lib -isystem /Users/user/dev/input-leap/ext/gulrak-filesystem/include --sysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk  -Wformat -DGTEST_USE_OWN_TR1_TUPLE=1 -g -std=c++17 -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk -mmacosx-version-min=10.9 -MD -MT src/lib/io/CMakeFiles/io.dir/filesystem.cpp.o -MF src/lib/io/CMakeFiles/io.dir/filesystem.cpp.o.d -o src/lib/io/CMakeFiles/io.dir/filesystem.cpp.o -c /Users/user/dev/input-leap/src/lib/io/filesystem.cpp
In file included from /Users/user/dev/input-leap/src/lib/io/filesystem.cpp:23:
/Users/user/dev/input-leap/src/lib/io/filesystem.h:37:54: error: 'path' is unavailable: introduced in macOS 10.15

Cheers!

@sithlord48
Copy link
Contributor

Im sorry I must have misread the 10.15 for OS 15

@p12tic
Copy link
Contributor

p12tic commented Jan 31, 2025

@sithlord48 I think you should refrain on commenting over what's likely in this project direction.

@CaptainChemist Thanks for the PR. I think putting the code in a few macOS version defines will allow to support old versions of macOS too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants