Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ee3d37e
feat(streaming): add local stream controls and input support
ReenigneArcher Nov 16, 2026
bd13571
fix(streaming): refine controls and improve input pacing
ReenigneArcher Nov 16, 2026
1e0bd20
fix(streaming): speed up overlays and correct OSK navigation
ReenigneArcher Nov 16, 2026
f946a36
feat(settings): add screenshot folder picker and creation
ReenigneArcher Nov 16, 2026
4ab5a53
perf(ui): retain folder navigation and group stream settings
ReenigneArcher Nov 16, 2026
fd6fb46
fix(settings): put screenshots in a separate Storage category
ReenigneArcher Nov 16, 2026
433198f
feat(ui): add per-app screenshot viewer
ReenigneArcher Nov 16, 2026
16c084b
feat(streaming): make menus responsive and add host app exit controls
ReenigneArcher Nov 16, 2026
0c3ab09
fix(input): recover menu gamepads after host app quit
ReenigneArcher Nov 17, 2026
39206f6
fix(streaming): prevent screenshot exit hangs and show save progress
ReenigneArcher Nov 17, 2026
2701e9e
fix(streaming): avoid overlay memory spikes during screenshot saves
ReenigneArcher Nov 17, 2026
5b348f5
docs(streaming): add stream controls and capture screenshots
ReenigneArcher Nov 17, 2026
a0ac0b0
style(cmake): list each Lucide icon on its own line
ReenigneArcher Nov 17, 2026
47cc00c
style(cmake): alphabetize Lucide icon lists
ReenigneArcher Nov 17, 2026
f87cc12
style(assets): add final newlines to controller icons
ReenigneArcher Nov 17, 2026
a6eb889
style: document include groups and keep Doxygen blocks adjacent
ReenigneArcher Nov 17, 2026
5dd75d4
style(tests): restore header-under-test include groups
ReenigneArcher Nov 17, 2026
029f93f
fix: resolve stream controls analyzer findings
ReenigneArcher Nov 17, 2026
5e3157c
docs: keep streaming instructions user focused
ReenigneArcher Nov 17, 2026
1e3e85d
refactor: finish stream controls quality cleanup
ReenigneArcher Nov 17, 2026
1acadfd
fix: clear remaining stream controls sonar findings
ReenigneArcher Nov 17, 2026
1b56148
fix: declare SDL screenshot callbacks with C linkage
ReenigneArcher Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ The project uses GoogleTest. Tests must include `<lizardbyte/common/testing.h>`
GoogleTest directly. This supplies the shared test support and output capture; Sunshine's
`tests/tests_common.h` is not part of this repository.

Group test includes under `// test includes`, then `// standard includes`, `// lib includes` and
`// local includes`, with blank lines between groups and no empty groups. Keep platform-specific headers
inside their preprocessor guards. Preserve and explain intentional include-order dependencies.
In test translation units, put the header under test first under `// test header include`. Group remaining
includes under `// standard includes`, `// lib includes`, `// local includes` and `// test includes`, in that
order, with blank lines between groups and no empty groups. Put `<lizardbyte/common/testing.h>` in the
library group and test-only support headers in the final test group. Keep platform-specific headers inside
their preprocessor guards. Preserve and explain intentional include-order dependencies.

Add or update meaningful regression tests for new or changed source behavior. Target full coverage of
changed testable source code. Keep platform-neutral logic accessible to native tests and document any
Expand Down
74 changes: 71 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ captions, and a blue focus ring shows which card will open. Running apps carry a
Missing artwork uses Lucide desktop or gamepad placeholders.
Use the D-pad or left stick to navigate, **A** to select, **B** to go back and **Y** for host or app
actions. Move up from the first PC row to reach Settings, Support and Add Host.
With a keyboard, hold the arrows to navigate, use **Enter** to select, **Esc** to go back, and **M**
for host or app actions. Button hints follow the keyboard or controller you are using.
On the hosts page, **Alt + F4** exits the client. **PgUp / PgDn** scroll the log viewer;
hold **Shift** for faster scrolling. **Backspace** dismisses a notification or changes the log pane.

PCs use grayscale moon artwork inspired by One: a full moon for paired online PCs, a half moon for
online PCs awaiting pairing, and a crescent for offline PCs. A separate orbit shows controller focus.
Expand Down Expand Up @@ -78,9 +82,71 @@ Bitrates are displayed in Mbps. You can then adjust **Stream Bitrate** manually;
until resolution or FPS changes again.
These are starting values for image quality and bandwidth, not a guarantee of Xbox decoding performance.

To quit a stream, press **Back/Select + Black + White (LB + RB)** together on any connected controller.
The client displays **Stopping stream...**, then a stream summary. Release the buttons, then press a
button to return to the menu.
Press **Back/Select + Black + White (LB + RB)** together on any connected controller to open stream
controls. Release the buttons, select a choice with either stick, then press **A** to choose it.
**B** resumes playback. A USB keyboard can open the same menu with **Ctrl + Alt + Shift + Q**;
use **Tab** to cycle through all choices, arrows to select the left wheel, **Enter** to choose, and
**Esc** to go back. Center the sticks and release the buttons before resuming gameplay.
The same shortcut returns to the wheels from the keyboard, logs or exit confirmation.

| Stick | Up | Right | Down | Left |
| ----- | -------- | ---------- | ---------- | ---------------------- |
| Left | Keyboard | Mouse mode | View logs | Exit |
| Right | Guide | Share | Screenshot | Enable / disable stats |

![Stream controls](./docs/images/screenshots/12-stream-controls.png)

**Exit** opens a confirmation dialog: **A / Enter** disconnects, **X / Q** quits the host app and **B / Esc** cancels.
**Disconnect** leaves the application running on the PC; select its pause-marked poster to resume.
Its app action menu also offers **Quit app**. Quitting can lose unsaved progress.

Use **D-pad / left stick** to move around the on-screen keyboard, **A** to type, **X** for Backspace,
**Y** for Space, and **Start** for host Enter. **Right stick click** applies Shift to the next key;
**left stick click** toggles Caps. **White / Black (LB / RB)** move the host text cursor left / right.
**LT** cycles through letters, symbols, and PC keys, including function keys and common shortcuts.
Focus a shortcut to see its combination above the keys. **RT** moves the keyboard between the top
and bottom of the screen; **B** returns to the wheels. Keys use the host's US keyboard layout.
When using a physical keyboard, use **Tab** to change page, **Shift** for one-shot Shift, **Caps Lock**
to toggle Caps, **F2** to move the panel, **Space / Backspace** to send those keys, and **Esc** to return.

![On-screen keyboard](./docs/images/screenshots/13-stream-keyboard.png)

**View logs** shows live entries. Scroll upward to read older entries; return to the bottom to follow
new entries. **Guide** and **Share** send their controller buttons to the PC; their behavior depends
on the host's virtual controller and operating system.

Screenshots are saved as BMP files, excluding local menus and statistics. The default folder is
`E:\UDATA\<title-id>\screenshots`. Open **Settings > Storage > Screenshot Folder** to browse drives
and subfolders, select the current folder, or create a new folder with the on-screen keyboard or a
USB keyboard. Press **Start / Enter** to create a folder after entering its name.
**Use default location** restores the default folder. **B / Esc** cancels without changing the destination.

Open a game or app's action menu and choose **Screenshots** to view its captures. The viewer works
offline and shows the newest capture first; use **LB / RB**, left / right or **PgUp / PgDn** to browse,
and **B / Esc** to return. Use **X / Backspace / Delete** to delete the selected image after confirmation.

Screenshots save in the background. A popup shows progress, then the saved path or an error.
The wheels close automatically after screenshot, Guide, Share, statistics and mouse-mode actions.

![Screenshot notification](./docs/images/screenshots/14-screenshot-notification.png)

Mouse mode uses the invoking controller's **left stick** for movement and **A / B** for left / right
clicks. Disable mouse mode through the wheels to use that controller for gameplay again.
Other gamepads and physical keyboards and mice can be used at the same time.

Up to four gamepads are supported as separate controllers in Sunshine.
Standard USB boot keyboards and three-button boot mice are supported through Xbox-to-USB adapters
attached to the controller ports. Devices must support HID boot protocol; mouse wheels, extra buttons
and nonstandard gaming devices may not work.

For xemu, open its Monitor with **~** and enter `device_add usb-kbd,id=kbd` or
`device_add usb-mouse,id=mouse` to attach an emulated USB device to an available port.
Remove them with `device_del kbd` and `device_del mouse`. See the
[xemu keyboard setup guide](https://xemu.app/docs/keyboard/) for explicit controller-port selection.

When Sunshine and xemu run on the same PC, prevent Sunshine's virtual controllers from being attached
to xemu. Disable automatic controller binding in **Input**, manually assign the physical controller,
and leave ports used for keyboards or mice unassigned to controllers to avoid USB port conflicts.

Enable **Settings → Display → Performance Stats** for a live panel during playback and additional
performance details in the summary. The panel works with GPU and software presentation, refreshes
Expand All @@ -89,6 +155,8 @@ decoded and rendered FPS, video bitrate, timing, frame drops, buffering and the
The stream header shows the requested FPS; the three FPS counters show measured rates.
Network latency is round-trip time. Present measures CPU frame preparation and submission,
including any scanout wait.
The stream menu can toggle these statistics for the current session; the saved setting sets the
initial state of the next session.

Video decoding runs on the CPU. Optional experimental GPU presentation accelerates color conversion
and scaling, with software fallback for unsupported frames or presentation failures. GPU
Expand Down
37 changes: 36 additions & 1 deletion cmake/nxdk.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,52 @@ function(_moonlight_prepare_nxdk_tools nxdk_dir cxbe_path source_dir build_dir o
)
endfunction()

# Install SDL adapters into the owned SDK copy and fingerprint the resulting sources.
function(_moonlight_prepare_sdl_hooks nxdk_dir out_signature)
# The vendored SDL Xbox event pump is a stub. Install small hooks only in
# the owned SDK copy; the project adapter implements boot HID and SDL events.
file(READ "${MOONLIGHT_NXDK_DIR}/lib/sdl/SDL2/src/joystick/xbox/SDL_xboxjoystick.c" joystick_source)
string(CONCAT initialize_hook
"usbh_xid_init();\n"
" extern void moonlight_usb_input_initialize(void);\n"
" moonlight_usb_input_initialize();")
string(REPLACE "usbh_xid_init();" "${initialize_hook}"
joystick_source "${joystick_source}")
file(CONFIGURE OUTPUT "${nxdk_dir}/lib/sdl/SDL2/src/joystick/xbox/SDL_xboxjoystick.c" # cmake-lint: disable=E1126
CONTENT "${joystick_source}" @ONLY)
file(READ "${MOONLIGHT_NXDK_DIR}/lib/sdl/SDL2/src/video/xbox/SDL_xbevents.c" events_source)
string(REPLACE "/* do nothing. */"
"extern void moonlight_usb_input_pump(void);\n moonlight_usb_input_pump();"
events_source "${events_source}")
file(CONFIGURE OUTPUT "${nxdk_dir}/lib/sdl/SDL2/src/video/xbox/SDL_xbevents.c" # cmake-lint: disable=E1126
CONTENT "${events_source}" @ONLY)
# An AC97 underrun can stop completion notifications. An unbounded wait
# leaves SDL_CloseAudioDevice joining a playback thread that never wakes.
file(READ "${MOONLIGHT_NXDK_DIR}/lib/sdl/SDL2/src/audio/xbox/SDL_xboxaudio.c" audio_source)
string(REPLACE "SDL_SemWait(_this->hidden->playsem);"
"SDL_SemWaitTimeout(_this->hidden->playsem, 100);"
audio_source "${audio_source}")
file(CONFIGURE OUTPUT "${nxdk_dir}/lib/sdl/SDL2/src/audio/xbox/SDL_xboxaudio.c" # cmake-lint: disable=E1126
CONTENT "${audio_source}" @ONLY)
string(SHA256 signature "${joystick_source}\n${events_source}\n${audio_source}\nNXDK_USB_ENABLE_HID=y")

set(${out_signature} "${signature}" PARENT_SCOPE)
endfunction()

# Bootstrap the vendored nxdk outputs required by the host-first Moonlight build.
function(moonlight_prepare_nxdk nxdk_dir state_dir)
file(MAKE_DIRECTORY "${state_dir}")

_moonlight_prepare_sdl_hooks("${nxdk_dir}" input_signature)

file(READ "${nxdk_dir}/.moonlight-source.signature" nxdk_revision)
set(signature_inputs
"NXDK_DIR=${nxdk_dir}"
"NXDK_REVISION=${nxdk_revision}"
"HOST_SYSTEM=${CMAKE_HOST_SYSTEM_NAME}"
"NXDK_TOOLCHAIN=${nxdk_dir}/share/toolchain-nxdk.cmake"
"NXDK_ENV_MODE=cmake-driver"
"USB_INPUT=${input_signature}"
)
list(JOIN signature_inputs "\n" signature_text)
string(SHA256 signature "${signature_text}")
Expand Down Expand Up @@ -293,7 +328,7 @@ function(moonlight_prepare_nxdk nxdk_dir state_dir)

if(need_prepare_libraries)
message(STATUS "Preparing nxdk libraries at ${nxdk_dir}")
_moonlight_run_nxdk_make("${nxdk_dir}" "nxdk bootstrap" NXDK_ONLY=y -j4)
_moonlight_run_nxdk_make("${nxdk_dir}" "nxdk bootstrap" NXDK_ONLY=y NXDK_USB_ENABLE_HID=y -j4)
else()
message(STATUS "Using existing nxdk library outputs from ${nxdk_dir}")
endif()
Expand Down
4 changes: 4 additions & 0 deletions cmake/sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ list(REMOVE_ITEM MOONLIGHT_SOURCES
"${MOONLIGHT_SOURCE_ROOT}/src/_nxdk_compat/poll_compat.cpp")

set(MOONLIGHT_TEST_EXCLUDED_SOURCES
"${MOONLIGHT_SOURCE_ROOT}/src/input/shell_controller.cpp"
"${MOONLIGHT_SOURCE_ROOT}/src/main.cpp"
"${MOONLIGHT_SOURCE_ROOT}/src/splash/splash_screen.cpp"
"${MOONLIGHT_SOURCE_ROOT}/src/streaming/ffmpeg_stream_backend.cpp"
"${MOONLIGHT_SOURCE_ROOT}/src/startup/memory_stats.cpp"
"${MOONLIGHT_SOURCE_ROOT}/src/streaming/session.cpp"
"${MOONLIGHT_SOURCE_ROOT}/src/streaming/stream_controls.cpp"
"${MOONLIGHT_SOURCE_ROOT}/src/platform/usb_input.cpp"
"${MOONLIGHT_SOURCE_ROOT}/src/ui/shell_screen.cpp"
"${MOONLIGHT_SOURCE_ROOT}/src/ui/svg_assets.cpp"
)

set(MOONLIGHT_HOST_TESTABLE_SOURCES ${MOONLIGHT_SOURCES})
Expand Down
44 changes: 40 additions & 4 deletions cmake/stage-lucide.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,32 @@ endif()

file(MAKE_DIRECTORY "${LUCIDE_ASSET_DIR}/icons" "${LUCIDE_ASSET_DIR}/licenses")
foreach(icon IN ITEMS
settings circle-question-mark circle-plus monitor gamepad-2 scroll-text rotate-ccw
network hash activity key-round save loader-circle circle-check circle-x info)
activity
camera
chart-no-axes-combined
circle-check
circle-plus
circle-question-mark
circle-x
gamepad-2
hash
info
key-round
keyboard
loader-circle
log-out
monitor
mouse
network
panels-top-left
pause
power
rotate-ccw
save
scroll-text
settings
share-2
)
set(_icon_source "${LUCIDE_SOURCE_DIR}/icons/${icon}.svg")
if(NOT EXISTS "${_icon_source}")
message(FATAL_ERROR "Required Lucide icon not found: ${_icon_source}")
Expand Down Expand Up @@ -39,7 +63,19 @@ configure_file("${LUCIDE_SOURCE_DIR}/LICENSE" "${LUCIDE_ASSET_DIR}/licenses/luci

# Remove obsolete first-party icons from existing build directories, too.
foreach(legacy_icon IN ITEMS
gear support add-host host-monitor-online host-monitor-pairing host-monitor-offline
circle-help life-buoy monitor-check monitor-dot monitor-off ethernet-port question-mark)
add-host
circle-help
ethernet-port
gear
host-monitor-offline
host-monitor-online
host-monitor-pairing
life-buoy
monitor-check
monitor-dot
monitor-off
question-mark
support
)
file(REMOVE "${LUCIDE_ASSET_DIR}/icons/${legacy_icon}.svg")
endforeach()
3 changes: 3 additions & 0 deletions cmake/xbox-build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ target_include_directories(${CMAKE_PROJECT_NAME}
"${MOONLIGHT_NXDK_NET_INCLUDE_DIR}"
"${MOONLIGHT_NXDK_LIBC_EXTENSIONS_DIR}"
"${MOONLIGHT_NXDK_LWIP_POSIX_COMPAT_DIR}"
"${NXDK_DIR}/lib/usb/libusbohci/inc"
"${NXDK_DIR}/lib/usb/libusbohci_xbox"
)
target_link_libraries(${CMAKE_PROJECT_NAME}
PUBLIC
Expand Down Expand Up @@ -111,6 +113,7 @@ target_compile_definitions(${CMAKE_PROJECT_NAME}
PRIVATE
XBOX
NXDK
USBH_USE_EXTERNAL_CONFIG="usbh_config_xbox.h"
TOML_EXCEPTIONS=0
TOML_ENABLE_WINDOWS_COMPAT=0)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
Expand Down
Binary file added docs/images/screenshots/12-stream-controls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/screenshots/13-stream-keyboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions src/_nxdk_compat/include/moonlight_time.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* @file src/_nxdk_compat/include/moonlight_time.h
* @brief Converts UTC timestamps with caller-owned storage through the Xbox kernel.
*/
#pragma once

// standard includes
#include <array>
#include <cstdint>
#include <ctime>
#include <limits>

// lib includes
#include <xboxkrnl/xboxkrnl.h>

/**
* @brief Convert nonnegative Unix time into caller-owned UTC calendar fields.
*
* PDCLib declares gmtime_s without supplying its implementation. Its gmtime uses
* shared static storage, so use the kernel conversion without changing libc feature macros.
*
* @param timestamp Unix timestamp in seconds.
* @param result Receives the complete UTC calendar fields.
* @return False if the timestamp cannot be represented as signed NT time.
*/
inline bool moonlight_gmtime(std::time_t timestamp, std::tm &result) {
constexpr std::int64_t epochOffset = 11644473600LL;
constexpr std::int64_t ticksPerSecond = 10000000;
if (timestamp < 0 || timestamp > std::numeric_limits<std::int64_t>::max() / ticksPerSecond - epochOffset) {
return false;
}
LARGE_INTEGER time {};
time.QuadPart = (static_cast<std::int64_t>(timestamp) + epochOffset) * ticksPerSecond;
TIME_FIELDS fields {};
RtlTimeToTimeFields(&time, &fields);
result = {};
result.tm_year = fields.Year - 1900;
result.tm_mon = fields.Month - 1;
result.tm_mday = fields.Day;
result.tm_hour = fields.Hour;
result.tm_min = fields.Minute;
result.tm_sec = fields.Second;
result.tm_wday = fields.Weekday;
constexpr std::array<int, 12> monthStarts {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
const bool leap = fields.Year % 4 == 0 && (fields.Year % 100 != 0 || fields.Year % 400 == 0);
result.tm_yday = monthStarts.at(result.tm_mon) + fields.Day - 1 + (fields.Month > 2 && leap ? 1 : 0);
return true;
}
Loading
Loading