Skip to content

fix(macos): provide left/right identity for modifiers#5115

Merged
ReenigneArcher merged 1 commit into
LizardByte:masterfrom
martona:macos-keyboard-pr
May 14, 2026
Merged

fix(macos): provide left/right identity for modifiers#5115
ReenigneArcher merged 1 commit into
LizardByte:masterfrom
martona:macos-keyboard-pr

Conversation

@martona
Copy link
Copy Markdown
Contributor

@martona martona commented May 14, 2026

Description

Preserve the left/right identity of modifier keys when reflecting keyboard input on macOS.

Moonlight sends distinct virtual keycodes for left and right Shift, etc., but Sunshine previously reflected those as generic modifier state only. That works for many consumers, but it loses information that some macOS apps use to distinguish the physical modifier key. In those cases, modified key combinations arrive as if the modifier was not pressed. For example, Apple's Remote Desktop client or products built with Apple's virtualization kit all ignore modifiers completely when sent the old way.

This PR maps Moonlights left/right modifier keycodes onto the corresponding macOS device-level modifier flags before posting the event. Apps now receive both the generic modifier state and the physical left/right identity.

The switch to CGSessionEventTap is intentional: the HID-level injection path does not appear to preserve the required left/right identity. This is the main behavior change worth watching for regressions.

I checked a few open-source macOS game backends. GLFW, Godot, SDL, and O3DE all read keyboard input through NSEvent on macOS, which is the normal AppKit path for session-posted events. SDL and O3DE also split left/right modifiers using NX_DEVICEL* / NX_DEVICER* masks, which this PR now provides.

This issue was not introduced by #5102, the fix is for a separate case the old code also did not handle.

Sorry for the fourth macOS PR in three days. I think this is the last one for a bit. Famous last words, etc.

Screenshot

Issues Fixed or Closed

Roadmap Issues

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Bundle Report

Bundle size has no change ✅

@sonarqubecloud
Copy link
Copy Markdown

@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

❌ Patch coverage is 8.10811% with 34 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (master@91615e3). Learn more about missing BASE report.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/platform/macos/input.cpp 8.10% 33 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #5115   +/-   ##
=========================================
  Coverage          ?   17.84%           
=========================================
  Files             ?      111           
  Lines             ?    24029           
  Branches          ?    10619           
=========================================
  Hits              ?     4288           
  Misses            ?    16556           
  Partials          ?     3185           
Flag Coverage Δ
Archlinux 11.23% <ø> (?)
FreeBSD-14.3-amd64 13.36% <ø> (?)
Homebrew-ubuntu-22.04 13.58% <ø> (?)
Linux-AppImage 12.16% <ø> (?)
Windows-AMD64 14.84% <ø> (?)
Windows-ARM64 13.23% <ø> (?)
macOS-arm64 18.99% <8.10%> (?)
macOS-x86_64 18.35% <5.40%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/platform/macos/input.cpp 34.37% <8.10%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 91615e3...058b8f9. Read the comment docs.

@ReenigneArcher ReenigneArcher merged commit 33bdb01 into LizardByte:master May 14, 2026
74 checks passed
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.

2 participants