Skip to content

feat(macos): implement Unicode text input#4980

Open
boomyao wants to merge 1 commit intoLizardByte:masterfrom
boomyao:feat/macos-unicode-input
Open

feat(macos): implement Unicode text input#4980
boomyao wants to merge 1 commit intoLizardByte:masterfrom
boomyao:feat/macos-unicode-input

Conversation

@boomyao
Copy link
Copy Markdown

@boomyao boomyao commented Apr 12, 2026

Description

Implement the platf::unicode() function for macOS, which was previously a stub that only logged "Unicode input not yet implemented for MacOS".

The implementation converts incoming UTF-8 text to UTF-16 via CFString, then injects each character as a CGEvent keyboard event using CGEventKeyboardSetUnicodeString(). Surrogate pairs are handled correctly for characters outside the Basic Multilingual Plane (e.g., emoji).

This enables Moonlight clients to send composed text (e.g., CJK characters from mobile IME) directly to the macOS host, matching the existing functionality on Windows (SendInput + KEYEVENTF_UNICODE) and Linux (Ctrl+Shift+U + hex code).

Context: When using Moonlight on Android/iOS with a Chinese/Japanese/Korean input method, the IME completes text composition locally and sends the final text via LiSendUtf8TextEvent(). On Windows and Linux hosts, this text is correctly injected into the active application. On macOS, it was silently dropped because platf::unicode() was unimplemented.

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

@ReenigneArcher ReenigneArcher added the ai PR has signs of heavy ai usage (either indicated by user or assumed) label Apr 12, 2026
@ReenigneArcher

This comment was marked as resolved.

@ReenigneArcher ReenigneArcher force-pushed the feat/macos-unicode-input branch from b998390 to 71781b8 Compare April 17, 2026 20:27
@ReenigneArcher
Copy link
Copy Markdown
Member

There are clang format issues in this PR. Don't worry, it's easy to fix.

  1. Create and activate a python venv in your workspace (optional) - https://docs.python.org/3/library/venv.html#creating-virtual-environments

  2. Install dependencies with the following command:

    python -m pip install ".[lint]"
  3. Run the following command to fix lint issues:

    python scripts\update_clang_format.py

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Bundle Report

Bundle size has no change ✅

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 0% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.13%. Comparing base (a458b20) to head (7d85983).
⚠️ Report is 4 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/platform/macos/input.cpp 0.00% 25 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4980      +/-   ##
==========================================
- Coverage   18.15%   18.13%   -0.03%     
==========================================
  Files         109      109              
  Lines       23582    23604      +22     
  Branches    10406    10421      +15     
==========================================
- Hits         4282     4281       -1     
- Misses      16046    17824    +1778     
+ Partials     3254     1499    -1755     
Flag Coverage Δ
Archlinux 11.52% <ø> (ø)
FreeBSD-14.3-aarch64 ?
FreeBSD-14.3-amd64 13.74% <ø> (-0.02%) ⬇️
Homebrew-ubuntu-22.04 13.89% <ø> (ø)
Linux-AppImage 12.48% <ø> (ø)
Windows-AMD64 14.86% <ø> (ø)
Windows-ARM64 13.25% <ø> (+<0.01%) ⬆️
macOS-arm64 19.03% <0.00%> (-0.04%) ⬇️
macOS-x86_64 18.37% <0.00%> (-0.06%) ⬇️

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.68% <0.00%> (-3.32%) ⬇️

... and 30 files with indirect coverage changes

Implement the `platf::unicode()` function for macOS, which was previously
a stub that only logged a "not yet implemented" message.

The implementation converts incoming UTF-8 text to UTF-16 via CFString,
then injects each character as a CGEvent keyboard event using
`CGEventKeyboardSetUnicodeString()`. Surrogate pairs are handled
correctly for characters outside the Basic Multilingual Plane.

This enables Moonlight clients to send composed text (e.g., CJK
characters from mobile IME) directly to the macOS host, matching the
existing functionality on Windows (`SendInput` + `KEYEVENTF_UNICODE`)
and Linux (`Ctrl+Shift+U` + hex code).
@ReenigneArcher ReenigneArcher force-pushed the feat/macos-unicode-input branch from e82847b to 7d85983 Compare April 26, 2026 15:06
@sonarqubecloud
Copy link
Copy Markdown

@ReenigneArcher
Copy link
Copy Markdown
Member

There are clang format issues in this PR. Don't worry, it's easy to fix.

1. Create and activate a python venv in your workspace (optional) - https://docs.python.org/3/library/venv.html#creating-virtual-environments

2. Install dependencies with the following command:
   ```shell
   python -m pip install ".[lint]"
   ```

3. Run the following command to fix lint issues:
   ```shell
   python scripts\update_clang_format.py
   ```

still an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai PR has signs of heavy ai usage (either indicated by user or assumed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants