Repository navigation
fix(macos): post media and volume keys as system-defined events #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Nachox07
wants to merge
2
commits into
LizardByte:master
Choose a base branch
from
Nachox07:fix/macos-media-keys
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /** | ||
| * @file src/platform/macos/macos_media_key.hpp | ||
| * @brief macOS media and volume key event creation. | ||
| */ | ||
| #pragma once | ||
|
|
||
| // standard includes | ||
| #include <cstdint> | ||
|
|
||
| // platform includes | ||
| #include <ApplicationServices/ApplicationServices.h> | ||
|
|
||
| namespace lvh::detail::macos_media_key { | ||
|
|
||
| /** | ||
| * @brief Pack the data1 field of an auxiliary-control event. | ||
| * | ||
| * @param key_type NX_KEYTYPE_* value. | ||
| * @param pressed Whether the key is pressed or released. | ||
| * @return Key type in the upper 16 bits and the key state (0xA down, 0xB up) in bits 8-15. | ||
| */ | ||
| constexpr std::int64_t event_data(int key_type, bool pressed) { | ||
| const std::int64_t key_state = pressed ? 0xA : 0xB; | ||
| return (static_cast<std::int64_t>(key_type) << 16) | (key_state << 8); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Create an NX_SYSDEFINED auxiliary-control event for a media key. | ||
| * | ||
| * A physical media or volume key arrives as a system-defined event, not as a key | ||
| * code event, and this builds the same event. | ||
| * | ||
| * @param key_type NX_KEYTYPE_* value. | ||
| * @param pressed Whether the key is pressed or released. | ||
| * @return Retained CoreGraphics event, or null when the event could not be created. | ||
| */ | ||
| CGEventRef create_event(int key_type, bool pressed); | ||
|
|
||
| } // namespace lvh::detail::macos_media_key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /** | ||
| * @file src/platform/macos/macos_media_key.mm | ||
| * @brief macOS media and volume key event creation. | ||
| */ | ||
|
|
||
| // local includes | ||
| #include "platform/macos/macos_media_key.hpp" | ||
|
|
||
| // platform includes | ||
| #import <AppKit/AppKit.h> | ||
|
|
||
| namespace lvh::detail::macos_media_key { | ||
|
|
||
| CGEventRef create_event(int key_type, bool pressed) { | ||
| @autoreleasepool { | ||
| constexpr short aux_control_buttons_subtype = 8; // NX_SUBTYPE_AUX_CONTROL_BUTTONS | ||
| const NSInteger key_state = pressed ? 0xA : 0xB; | ||
|
|
||
| NSEvent *event = [NSEvent otherEventWithType:NSEventTypeSystemDefined | ||
| location:NSZeroPoint | ||
| modifierFlags:static_cast<NSEventModifierFlags>(key_state << 8) | ||
| timestamp:0 | ||
| windowNumber:0 | ||
| context:nil | ||
| subtype:aux_control_buttons_subtype | ||
| data1:static_cast<NSInteger>(event_data(key_type, pressed)) | ||
| data2:-1]; | ||
| const CGEventRef cg_event = event ? event.CGEvent : nullptr; | ||
| if (!cg_event) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| CFRetain(cg_event); | ||
| return cg_event; | ||
| } | ||
| } | ||
|
|
||
| } // namespace lvh::detail::macos_media_key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Keep the media source on the CXX compile rule
With
LIBVIRTUALHID_BUILD_MACOS_BROKER=ON(the macOS default), the rootCMakeLists.txtenablesOBJCXXafteradd_subdirectory(src). CMake then classifies this new.mmsource as Objective-C++, but the already-processedsrcdirectory has no Objective-C++ compile rule. A clean configure at this head fails during generation withMissing variable is: CMAKE_OBJCXX_COMPILE_OBJECT; the same broker-enabled configuration succeeds on target commitbef56ce. This blocks normal macOS builds and the Universal macOS broker CI job.To preserve the intended CXX-only consumer integration, explicitly retain CMake's CXX rule while telling Clang to parse this file as Objective-C++:
I tested this exact correction on macOS 27.2.1 with AppleClang 21 and CMake 4.4.3: the broker, license CLI, and library build successfully, and both CXX-only and OBJCXX-enabled
add_subdirectoryconsumers build and run.Review completed by Codex | Model: gpt-6.1-sol | Thinking: xhigh