Unified Wayland support via XDG GlobalShortcuts portal#1
Closed
Conversation
Restructure Linux backend to support both X11 and Wayland transparently. The existing public API (register/unregister/GlobalHotKeyEvent) works identically on both display servers with runtime detection via WAYLAND_DISPLAY env var. Wayland backend uses ashpd crate to communicate with the XDG GlobalShortcuts portal. HotKey IDs are used as portal action IDs, ensuring event round-trip compatibility. App ID can be set via GLOBAL_HOTKEY_APP_ID env var.
Applications that already run a tokio runtime (like Tauri apps) would panic with 'Cannot start a runtime from within a runtime' because #[tokio::main] tries to create a nested runtime. Instead, explicitly build a new current_thread runtime on the dedicated event processor thread.
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.
Summary
Adds transparent Wayland support to the
global-hotkeycrate without breaking the existing public API. The sameregister()/unregister()/GlobalHotKeyEvent::receiver()calls work on both X11 and Wayland with zero consumer code changes.This is an alternative approach to tauri-apps/global-hotkey#162 which introduces a separate Wayland API surface (
wl_register_all(),WlNewHotKeyAction, etc.). Instead, this fork keeps the API unified by handling Wayland differences internally.Related upstream issues:
How it works
WAYLAND_DISPLAYenv var atGlobalHotKeyManager::new()timeashpdcrate to communicate with XDG GlobalShortcuts portal via D-BusHotKey::id()(u32) as portal action IDs, ensuring event round-trip compatibilityBindShortcutscall per register/unregister operationcurrent_threadruntime on a dedicated OS thread (no nested runtime issues with Tauri)GLOBAL_HOTKEY_APP_IDorFLATPAK_IDenv vars, with a default fallbackFile changes
src/platform_impl/mod.rs: path changed fromx11/tolinux/src/platform_impl/linux/mod.rs: new runtime dispatch layer withis_wayland()detectionsrc/platform_impl/linux/x11.rs: existing X11 backend (moved fromx11/mod.rs, trimmed)src/platform_impl/linux/wayland.rs: new Wayland backend (~400 lines)Cargo.toml: addedashpd,tokio,futures(Linux only)src/lib.rs: updated docs from "X11 Only" to "X11 and Wayland"Tested on