Skip to content

libobs: Add Wayland global hotkeys through the GlobalShortcuts portal - #245

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/240-wayland-global-hotkeys
Oct 11, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/240-wayland-global-hotkeys

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

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.

  1. test: Add failing tests for Wayland global hotkeys through the portal: obs_nix_hotkey_state gains shortcuts reported active by the portal, and a portal client is added. Both are stubs here. test_wayland_hotkeys gains 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_shortcuts runs a fake GlobalShortcuts portal (with the host app Registry) on a private bus from GTestDBus, 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 when dbus-daemon is missing.
  2. libobs: Add Wayland global hotkeys through the GlobalShortcuts portal: a portal client (libobs/obs-nix-portal-shortcuts.c) runs on its own thread, GMainContext and private D-Bus connection, started by the Wayland hotkey platform. It binds one shortcut per distinct key combination in the current bindings (id ctrl+shift+OBS_KEY_F13, preferred trigger CTRL+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 last hotkey_bindings_changed/hotkey_unregister signal, and binds again after a portal restart. It is built only with Wayland and gio. All tests pass.

Design choices

  1. Portal only: no xx-hotkey-v1. The portal is desktop-agnostic and KDE has said KWin will not implement the protocol.
  2. One shortcut per key combination, not per action: ids do not depend on the profile or scene collection, so switching them keeps the desktop's triggers, and one key drives every action bound to it. Whatever trigger the user gives a shortcut on the desktop drives the OBS combination its id names.
  3. App id: the client calls 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.
  4. Rebinding: it follows the hotkey_bindings_changed/hotkey_unregister signals instead of polling. Each signal pushes back a 500 ms one-shot timer, so loading a profile binds once. The portal allows one BindShortcuts per session, so a change binds in a new session.
  5. Re-prompts: a set the user cancels, or a session the desktop closes (access revoked), is not bound again until a new combination is assigned, so a dismissed prompt never comes back by itself. A portal restart, detected from its bus name, binds again.
  6. Simultaneous shortcuts: strict modifiers are unchanged. Holding F13 and Ctrl+F14 together reads as Ctrl held, exactly as physically holding those keys does on X11.
  7. Scope: keyboard combinations only. Mouse-button and modifier-only bindings stay focus-only. ShortcutsChanged is logged. Showing the desktop's triggers in Settings and a "Configure shortcuts" button (ConfigureShortcuts, portal v2) are UI follow-ups.
  8. Where: in libobs, in the Wayland hotkey platform next to the existing focused-key state. The hotkey thread, profiles and per-source hotkeys all live there, so it needs no new API, and the X11 platform already lives there too.

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/BindShortcuts flow 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:

  • mihawk90 on #13680: per-action shortcuts break profiles, since triggers must be reassigned after every switch, and one key could not drive several actions. Here ids name key combinations, so they are the same in every profile, and one portal shortcut presses every binding on that combination.
  • tytan652 on #13680: scene collections have the same problem as profiles. The ids do not depend on either.
  • tytan652 on #13661: OBS should rely only on portals or upstream protocols. This uses only the portal.

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:

bind = , F13, global, com.obsproject.Studio:OBS_KEY_F13
bind = CTRL SHIFT, F14, global, com.obsproject.Studio:ctrl+shift+OBS_KEY_F14

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 HOME and XDG_RUNTIME_DIR, private Xvfb, software GL). At the RED commit, test_wayland_hotkeys fails 4 of 8 and test_portal_shortcuts fails 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) with ENABLE_RUST_LIBOBS OFF 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 changes obs-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 Hyprland global binds:

  • master: hyprctl globalshortcuts lists none, and OBS receives no press or release.
  • this PR: Hyprland lists com.obsproject.Studio:OBS_KEY_F13 and com.obsproject.Studio:ctrl+shift+OBS_KEY_F14.
    • Holding F13 for 800 ms pressed push-to-talk and push-to-mute and released both 776 to 802 ms later.
    • Holding Ctrl+Shift+F14 for 300 ms pressed and released record (275 ms).
    • A tap of F13 pressed and released both (25 ms).
    • After OBS rebound push-to-mute to F14 while running, a new session bound F13, Ctrl+Shift+F14 and F14. F13 then drove only push-to-talk, and F14 only push-to-mute.
    • The terminal kept focus throughout. Results were the same in all 6 runs with ENABLE_RUST_LIBOBS=OFF and 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:

  • GNOME and KDE Plasma portal backends, including their confirmation dialogs and how they treat the preferred trigger.
  • Flatpak (app id from the sandbox).
  • A physical keyboard. The end-to-end run used a virtual keyboard through the same compositor binds.
  • The full frontend (OBS Studio's settings and profile switching), as opposed to libobs hotkeys driven directly.
  • ShortcutsChanged and a portal restart against a real portal (both are covered against the fake portal).
  • FreeBSD (the same sources are added to its build).
  • The Docker lanes of the local gate.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.
  • I have used AI tooling in the creation of this PR
  • I am an AI agent being used to assist with this pull request: Claude Code (Claude Opus 5.5) wrote the code, commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

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]>
@rdoupe
rdoupe requested a review from zackees as a code owner October 11, 2026 16:13
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
zackees force-pushed the fix/240-wayland-global-hotkeys branch from d6d68db to 85a51df Compare October 11, 2026 16:30
@zackees

zackees commented Oct 11, 2026

Copy link
Copy Markdown
Member

Verified locally, rebased onto master and stamped.

  • RED (c82361053): Tier 2 passed 80 of 82. test_wayland_hotkeys failed (:122), and test_portal_shortcuts failed under a private dbus-daemon: portal_drives_push_to_talk, portal_shortcut_holds_push_to_talk, portal_shortcut_with_modifiers, one_shortcut_drives_every_bound_action, rebinds_when_bindings_change, rebinds_after_portal_restart, burst_of_changes_binds_once and closed_session_is_not_rebound.
  • GREEN (d6d68db31): Tier 2 passed 82 of 82 with ENABLE_RUST_LIBOBS OFF and 82 of 82 with it ON. Both tests passed with dbus installed, and the local gate passed.

The only lines removed from the existing test_wayland_hotkeys.c are its header comment. The test bodies are additions. Merging once CI is green.

@zackees
zackees merged commit 763b0a5 into obs-rust:master Oct 11, 2026
23 checks passed
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: libobs: Wayland hotkeys and push-to-talk do nothing while OBS is unfocused (upstream #13169, #10538)

2 participants