Repository navigation
libobs: Add Wayland global hotkeys through the GlobalShortcuts portal - #245
Merged
Merged
Conversation
Wayland never sends key events to an unfocused client, so OBS hotkeys and push-to-talk only work while OBS is focused (upstream #13169, #10538). The out-of-focus source on Wayland is the xdg-desktop-portal GlobalShortcuts interface. Extend obs_nix_hotkey_state with shortcuts reported active by the portal and add a portal client that binds one shortcut per OBS key combination; both are stubs here. test_wayland_hotkeys gains four cases driving the real hotkey thread from Activated/Deactivated. test_portal_shortcuts runs a fake GlobalShortcuts portal (with the host app Registry) on a private bus from GTestDBus and checks: the shortcut ids and preferred triggers, the app id registered before any portal call, Activated/Deactivated -> press/release for every action on a combination, ShortcutsChanged and unknown ids, rebinding on a change and closing the session when the last hotkey goes, one rebind for a burst of changes, no rebind after the desktop closes the session until a new combination appears, rebinding after a portal restart, and the no-portal fallback. RED: test_wayland_hotkeys fails 4 of 8 (portal_shortcut_holds_push_to_talk, portal_shortcut_with_modifiers, one_shortcut_drives_every_bound_action, short_tap_is_not_lost); test_portal_shortcuts fails 6 of 7 (shortcut_ids_round_trip, portal_drives_push_to_talk, rebinds_when_bindings_change, burst_of_changes_binds_once, closed_session_is_not_rebound, rebinds_after_portal_restart: "portal never received BindShortcuts obs-rust#1"). no_portal_falls_back passes. Reported upstream by Slavomir9 (#13169) and mdsmendes94 (#10538). Refs obs-rust#240. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
zackees
approved these changes
Oct 11, 2026
Wayland never sends key events to an unfocused client, so OBS hotkeys and push-to-talk only worked while OBS was focused (upstream #13169, #10538). The desktop-agnostic way for an app to get out-of-focus shortcuts is the xdg-desktop-portal GlobalShortcuts interface. On the Wayland platform, a portal client on its own thread and private D-Bus connection binds one portal shortcut per distinct key combination in the current OBS bindings, with the OBS binding as preferred_trigger (for example id "ctrl+shift+OBS_KEY_F13", trigger "CTRL+SHIFT+F13"), and feeds Activated/Deactivated into obs_nix_hotkey_state. A released shortcut is kept until a hotkey poll cycle has seen it, so a short tap is not lost. The libobs hotkey thread then presses and releases the matching bindings as it does on X11, so push-to-talk/mute hold and release delay, several actions on one key, profiles and scene collections work unchanged. Binding per combination rather than per action answers the objections raised on obsproject/obs-studio#13680: the ids do not depend on the profile or scene collection, so switching them does not make the user reassign triggers, and one key drives every action bound to it even where the desktop allows a trigger on only one shortcut. The desktop keeps the final say on the trigger: whatever trigger the user gives a shortcut drives the OBS combination its id names (ShortcutsChanged is logged). The set is bound again 500 ms after the last hotkey_bindings_changed or hotkey_unregister signal, so loading a profile binds once. The portal accepts one BindShortcuts per session, so a change closes the session and binds in a new one; unchanged ids keep their triggers. The client registers the host app id (org.freedesktop.host.portal.Registry) before its first portal call, and again after a portal restart, which it detects from the bus name and answers by binding again. A set the user cancels or the portal refuses, and a session the desktop closes, are not bound again until a new combination is assigned, so a revoked or dismissed prompt does not come back by itself. Without a session bus, portal or GlobalShortcuts interface the client logs once and stops; hotkeys then work only while OBS is focused, as before. Mouse-button and modifier-only bindings are not bound, as portal triggers are keyboard shortcuts. The session/BindShortcuts flow follows Adamskye's obsproject/obs-studio#13680; feeding the hotkey thread per key combination, with taps kept until observed, follows aurelleb's obsproject/obs-studio#13661. test_wayland_hotkeys: 8/8 pass (RED 4/8); test_portal_shortcuts: 7/7 (RED 1/7). Fixes obs-rust#240. Co-Authored-By: Adam Fallon <[email protected]> Co-Authored-By: Aurelle <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Local-Gate: v1 tree=842e94ccf6d2da39884d483f9909b8c99c899c22 secs=122 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791736216,"gate":"rust/all/fmt","host":"linux-x86_64","key":"a253e13456d2287ad0ae7b22b1f6dc2c409f8eb21d8bd8cb571c52bd7cc3370a","lane":"lint","parents":["c823610532272ff5211774def3516e58a91801c7"],"secs":47,"stamp":"fe85394d58402b17871461ac5084864a","tree":"842e94ccf6d2da39884d483f9909b8c99c899c22","v":1,"via":"run"} Ci-Attestation: {"at":1791736216,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"a253e13456d2287ad0ae7b22b1f6dc2c409f8eb21d8bd8cb571c52bd7cc3370a","lane":"lint","parents":["c823610532272ff5211774def3516e58a91801c7"],"secs":47,"stamp":"9417949d69fdd020d16fd1a51fee8d2e","tree":"842e94ccf6d2da39884d483f9909b8c99c899c22","v":1,"via":"run"} Ci-Attestation: {"at":1791736216,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"cf70a7e486d597e664df2826de1810be21f14a14a9845ebbe798f97ac0cee110","lane":"rust-test","parents":["c823610532272ff5211774def3516e58a91801c7"],"secs":29,"stamp":"670b33ecb5eddefda8a1f03229c7d0fd","tree":"842e94ccf6d2da39884d483f9909b8c99c899c22","v":1,"via":"run"} Ci-Attestation: {"at":1791736216,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"714a269bada37f36a13e7f59cc901746489e83918fd54723307c1bf489c3186f","lane":"tier2-linux","parents":["c823610532272ff5211774def3516e58a91801c7"],"secs":46,"stamp":"45b2bafdc08b804375ef65e8b1cd9f5f","tree":"842e94ccf6d2da39884d483f9909b8c99c899c22","v":1,"via":"run"}
zackees
force-pushed
the
fix/240-wayland-global-hotkeys
branch
from
October 11, 2026 16:30
d6d68db to
85a51df
Compare
Member
|
Verified locally, rebased onto master and stamped.
The only lines removed from the existing |
This was referenced Oct 11, 2026
Closed
zackees
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 12, 2026
On Wayland, hotkeys work while OBS is unfocused only through the desktop's GlobalShortcuts portal (obs-rust#245), and nothing in OBS says whether that is working: Settings -> Hotkeys looks the same whether the shortcuts are bound, waiting for a desktop dialog, declined, unsupported, or (on Hyprland) missing from the compositor's config. Declare a status API in obs-hotkey.h (state, flags, per-shortcut triggers, shortcut ids, retry, a key probe) with stubs that report "native", and the Settings logic for the banner, row markers and Hyprland config lines (frontend/settings/OBSHotkeyBackground.hpp) with empty stubs. test_portal_shortcuts (fake portal on a private bus) gains eleven status cases: bound with desktop triggers (KDE/GNOME-like), bound without triggers (Hyprland-like), a shortcut the desktop left without a key, declined then asked again, closed then asked again, paused while Settings is open plus "Test a key" probing, a portal restart while paused, no portal, a portal error carrying its reason, mouse-only bindings, and the native default. test_hotkey_background_ui covers the banner, the markers, the Hyprland Lua/hyprlang lines, hand-written Lua binds hyprctl cannot identify, binds on another key, and `hyprctl -j` parsing (samples from Hyprland 0.56.2). RED: test_portal_shortcuts fails 10 of 21, test_hotkey_background_ui 15 of 16. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This was referenced Oct 12, 2026
Closed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
On Wayland, OBS hotkeys and push-to-talk only worked while OBS was focused, because Wayland never sends key events to an unfocused client. With this change, OBS binds its hotkeys through the xdg-desktop-portal GlobalShortcuts interface. Push-to-talk, push-to-mute and every other hotkey then work while another window has focus, with hold and release behaving as they do on X11.
The cause:
obs_nix_wayland_hotkeys_platform_is_pressed()(libobs/obs-nix-wayland.c:311) only knows the keys held while an OBS window has keyboard focus. The hotkey thread (obs_hotkey_thread,libobs/obs-hotkey.c:1161) polls it every 25 ms, so while OBS is unfocused every key reads as released and nothing fires.test: Add failing tests for Wayland global hotkeys through the portal:obs_nix_hotkey_stategains shortcuts reported active by the portal, and a portal client is added. Both are stubs here.test_wayland_hotkeysgains four cases that drive the real hotkey thread from Activated/Deactivated. 4 of 8 fail: a held shortcut, a shortcut with modifiers, one shortcut driving two actions, and a short tap.test_portal_shortcutsruns a fake GlobalShortcuts portal (with the host app Registry) on a private bus fromGTestDBus, against the real hotkey thread. 6 of 7 fail ("portal never received BindShortcuts feat(rust): port libobs/util/bitstream to Rust under the four-tier testing policy (first port) #1"); the no-portal fallback passes. It is skipped whendbus-daemonis missing.libobs: Add Wayland global hotkeys through the GlobalShortcuts portal: a portal client (libobs/obs-nix-portal-shortcuts.c) runs on its own thread,GMainContextand private D-Bus connection, started by the Wayland hotkey platform. It binds one shortcut per distinct key combination in the current bindings (idctrl+shift+OBS_KEY_F13, preferred triggerCTRL+SHIFT+F13) and feeds Activated/Deactivated into the key state the hotkey thread reads. A tap is kept until a poll cycle has seen it. It rebinds 500 ms after the lasthotkey_bindings_changed/hotkey_unregistersignal, and binds again after a portal restart. It is built only with Wayland and gio. All tests pass.Design choices
xx-hotkey-v1. The portal is desktop-agnostic and KDE has said KWin will not implement the protocol.org.freedesktop.host.portal.Registry.Register("com.obsproject.Studio")as its first portal call, and again after a portal restart, so host installs get a stable id even when launched from a terminal. Flatpak and older portals refuse the call, which is harmless.hotkey_bindings_changed/hotkey_unregistersignals instead of polling. Each signal pushes back a 500 ms one-shot timer, so loading a profile binds once. The portal allows oneBindShortcutsper session, so a change binds in a new session.ShortcutsChangedis logged. Showing the desktop's triggers in Settings and a "Configure shortcuts" button (ConfigureShortcuts, portal v2) are UI follow-ups.Motivation and Context
Fixes #240 (upstream obsproject/obs-studio#13169, reported by Slavomir9; obsproject/obs-studio#10538, reported by mdsmendes94)
Follows the focused held-key fix (#211), which this builds on. Prior art: the session/
BindShortcutsflow follows Adamskye's obsproject/obs-studio#13680, and feeding the hotkey thread per key combination, with taps kept until observed, follows aurelleb's obsproject/obs-studio#13661. Both are co-authors.Upstream objections this addresses:
Why this one: push-to-talk and scene hotkeys from inside a game are core streaming workflows. Wayland is now the default session on most Linux desktops, and the upstream issue has been open for years.
Hyprland users: xdg-desktop-portal-hyprland ignores
preferred_trigger, so the shortcuts must be bound in the Hyprland config, using the app id and the shortcut id OBS logs as[portal] global shortcut <id> bound:or in a Lua config,
hl.bind("F13", hl.dsp.global("com.obsproject.Studio:OBS_KEY_F13")).How Has This Been Tested?
Automated, isolated (no display or Wayland socket; private D-Bus, scratch
HOMEandXDG_RUNTIME_DIR, private Xvfb, software GL). At the RED commit,test_wayland_hotkeysfails 4 of 8 andtest_portal_shortcutsfails 6 of 7. At the GREEN commit both pass, after clean rebuilds. 30 of 30 repeated runs passed, 10 of them while a parallel build loaded the CPU. Both tests are clean under ASan/UBSan. The full ctest suite passes (81/81) withENABLE_RUST_LIBOBSOFF and ON, and both tests passed 10 of 10 repeated runs in the ON build too. clang-format and gersemi are clean, and the full build succeeds. After rebasing onto the merged multi-seat fix (#244), which also changesobs-nix-wayland.c, the Wayland, multi-seat and portal tests pass together and the full suite passes (83/83).End to end, on a Ryzen 6900HX mini PC, fully private:
dbus-run-session, a headless Hyprland 0.56.2 nested in headless Sway with a headless output, xdg-desktop-portal 1.22.1 and xdg-desktop-portal-hyprland 1.4.1 on that bus, a terminal holding keyboard focus, and a never-focused libobs client. The client bound push-to-talk and push-to-mute to F13 and record to Ctrl+Shift+F14. Keys came from a virtual keyboard (wtype) through Hyprlandglobalbinds:hyprctl globalshortcutslistsnone, and OBS receives no press or release.com.obsproject.Studio:OBS_KEY_F13andcom.obsproject.Studio:ctrl+shift+OBS_KEY_F14.ENABLE_RUST_LIBOBS=OFFand in a run with it ON (master: no events in either).Behaviour change: on Wayland with a GlobalShortcuts portal, OBS registers its keyboard hotkeys with the desktop at startup and whenever they change. GNOME and KDE may show their own dialog to confirm them. Without the portal, nothing changes.
Not tested:
ShortcutsChangedand a portal restart against a real portal (both are covered against the fake portal).Types of changes
Checklist:
🤖 Generated with Claude Code