Add libei/portal fallback for input on KDE/GNOME compositors#2008
Add libei/portal fallback for input on KDE/GNOME compositors#2008r33drichards wants to merge 3 commits into
Conversation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BY1JBgWq3gxNST3htj3Ysy
…Wayland input dispatch (#1982) Wire the existing libei/xdg-desktop-portal RemoteDesktop backend into the Wayland input dispatch as the fallback when the compositor exposes no zwlr_virtual_pointer_v1 (KWin/Plasma, Mutter/GNOME) or no virtual-keyboard (wtype). The libei backend was implemented but only reachable from the example; now click/scroll/move/drag/type_text/press_key fall back to it on a portal-libei build, via a single seam (with_libei_fallback / with_wtype_libei_fallback) keyed on a NO_VPTR_MARKER sentinel. This fixes the silent no-op on KDE/GNOME Wayland where input events were dropped because no wlroots virtual-pointer manager is present. No behavior change for the published no-feature build (the libei branch is cfg'd out). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BY1JBgWq3gxNST3htj3Ysy
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a Wayland libei fallback path for missing virtual-pointer support and routes pointer/keyboard input through it. Also adds a Git ignore rule for ChangesWayland libei fallback for non-wlroots input
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
libs/cua-driver/rust/crates/platform-linux/src/wayland/mod.rs (2)
935-941: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy liftNormalize libei click coordinates like the vptr path.
click(…, 0, 0, …)currently means “center” in the wlroots path, but the libei fallback clicks the top-left corner and records(0, 0). Share the same default/clamp behavior before callinglibei::move_absolute/libei::click.Also applies to: 1359-1368
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@libs/cua-driver/rust/crates/platform-linux/src/wayland/mod.rs` around lines 935 - 941, The libei click path is not normalizing coordinates the same way as the wlroots/vptr path, so `click(…, 0, 0, …)` ends up using the top-left instead of center. Update the coordinate handling in the Wayland click flow (the code around the `px`/`py` normalization and the `libei::move_absolute` / `libei::click` calls, including the duplicate location noted in the comment) to apply the same “0,0 ნიშნავს center” default and clamp behavior used by the vptr path before dispatching the click.
856-874: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winCheck virtual-pointer before unrelated foreign-toplevel failures.
Line 857 can bail before Line 867 emits
NO_VPTR_MARKER, sowith_libei_fallbacknever runs on compositors that lack both protocols. Move thevptr_managermarker check earlier, and only requirezwlr_foreign_toplevel_manager_v1when activation is actually needed.🐛 Proposed routing fix
- if state.manager.is_none() { - anyhow::bail!("compositor does not expose zwlr_foreign_toplevel_manager_v1"); - } for _ in 0..4 { queue.roundtrip(&mut state)?; } + let mgr = state.vptr_manager.clone().ok_or_else(|| { + if PORTAL_LIBEI_ENABLED { + anyhow::anyhow!( + "compositor does not expose zwlr_virtual_pointer_manager_v1 \ + ({NO_VPTR_MARKER})" + ) + } else { + anyhow::anyhow!( + "no input backend for this compositor ({NO_VPTR_MARKER}): it \ + exposes no zwlr_virtual_pointer_manager_v1 and this build was \ + compiled without libei/portal support (`#1982`). Use the \ + portal-enabled Linux build for input on KDE Plasma / GNOME, or \ + a wlroots compositor (sway, labwc, hyprland)." + ) + } + })?; + + if activate_window_id.is_some() && state.manager.is_none() { + anyhow::bail!("compositor does not expose zwlr_foreign_toplevel_manager_v1"); + } + let seat = state .seat .clone() .ok_or_else(|| anyhow::anyhow!("compositor exposed no wl_seat for virtual-pointer input"))?; - let mgr = state.vptr_manager.clone().ok_or_else(|| { - if PORTAL_LIBEI_ENABLED { - anyhow::anyhow!( - "compositor does not expose zwlr_virtual_pointer_manager_v1 \ - ({NO_VPTR_MARKER})" - ) - } else { - anyhow::anyhow!( - "no input backend for this compositor ({NO_VPTR_MARKER}): it \ - exposes no zwlr_virtual_pointer_manager_v1 and this build was \ - compiled without libei/portal support (`#1982`). Use the \ - portal-enabled Linux build for input on KDE Plasma / GNOME, or \ - a wlroots compositor (sway, labwc, hyprland)." - ) - } - })?;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@libs/cua-driver/rust/crates/platform-linux/src/wayland/mod.rs` around lines 856 - 874, The virtual-pointer fallback path in the Wayland logic is checking `state.manager` before it verifies the `vptr_manager` marker, so compositors that lack both protocols bail out too early and never trigger `with_libei_fallback`. Reorder the checks in the affected flow around `state.manager`, `state.vptr_manager`, and `PORTAL_LIBEI_ENABLED` so the `NO_VPTR_MARKER` path is evaluated first, then only enforce `zwlr_foreign_toplevel_manager_v1` when foreign-toplevel activation is actually required.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@libs/cua-driver/rust/crates/platform-linux/src/wayland/mod.rs`:
- Around line 1398-1423: The libei_drag fallback currently simulates a drag with
move→click-at-end, but that does not perform a real drag and still returns
success. Update libei_drag to either use a proper libei press/move/release
sequence with the existing libei adapter helpers, or change it to return an
explicit unsupported error when button-hold is unavailable. Make sure the
behavior of libei_drag and its call sites no longer report Ok(()) for non-drag
click-only fallback.
- Around line 1199-1211: The portal-libei branch in the hotkey handling path is
rejecting all keys, even when `mods` is empty and the input is just a single key
press. Update the logic around the `portal-libei` fallback to allow non-chord
hotkeys to proceed by reusing `libei_press_key`, and keep the existing bail-out
only for modifier chords in the relevant hotkey delivery function.
- Around line 1434-1465: The libei input path in libei_press_key/key_to_evdev
only handles a small set of navigation and control keys, so portal-libei builds
still fail for common inputs like letters, digits, and function keys. Extend
key_to_evdev to recognize basic alphanumeric keys and F1–F12, and keep
libei_press_key using the expanded mapping so the fallback can press the same
common keys as the other input path.
---
Outside diff comments:
In `@libs/cua-driver/rust/crates/platform-linux/src/wayland/mod.rs`:
- Around line 935-941: The libei click path is not normalizing coordinates the
same way as the wlroots/vptr path, so `click(…, 0, 0, …)` ends up using the
top-left instead of center. Update the coordinate handling in the Wayland click
flow (the code around the `px`/`py` normalization and the `libei::move_absolute`
/ `libei::click` calls, including the duplicate location noted in the comment)
to apply the same “0,0 ნიშნავს center” default and clamp behavior used by the
vptr path before dispatching the click.
- Around line 856-874: The virtual-pointer fallback path in the Wayland logic is
checking `state.manager` before it verifies the `vptr_manager` marker, so
compositors that lack both protocols bail out too early and never trigger
`with_libei_fallback`. Reorder the checks in the affected flow around
`state.manager`, `state.vptr_manager`, and `PORTAL_LIBEI_ENABLED` so the
`NO_VPTR_MARKER` path is evaluated first, then only enforce
`zwlr_foreign_toplevel_manager_v1` when foreign-toplevel activation is actually
required.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3e55c545-3737-4f50-a6a0-2705a4094544
📒 Files selected for processing (2)
.gitignorelibs/cua-driver/rust/crates/platform-linux/src/wayland/mod.rs
Linux visual regression artifactsMatrix jobs now run independently. Download visual artifacts from this workflow run.
|
- Routing order: open_vptr_session now emits NO_VPTR_MARKER (via the vptr_manager check) BEFORE requiring zwlr_foreign_toplevel_manager_v1, and only requires foreign-toplevel when activate_window_id is set. This lets with_libei_fallback trigger on KDE/GNOME (which expose neither wlroots protocol) instead of erroring out before the marker is reached. - Coordinate normalization: libei click/move now reproduce the vptr path's default-to-centre + clamp behaviour via a wl_output dimension probe, so click(.., 0, 0, ..) lands on centre rather than top-left. - Drag honesty: libei_drag now bails with an explicit "unsupported" error instead of simulating a drag as move->click-at-end (which holds no button), since the libei worker exposes no button-hold primitive. - Non-chord hotkey: a modifier-less hotkey now routes through the wtype->libei fallback as a single key press; only true modifier chords remain unsupported on the libei backend. - Keymap coverage: key_to_evdev now maps a-z, 0-9 and F1-F12 to their Linux evdev codes so the portal-libei path can press letters/digits/ function keys when wtype is unavailable. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BY1JBgWq3gxNST3htj3Ysy
|
@coderabbitai review Addressed all five review findings in commit 124e711 (libs/cua-driver/rust/crates/platform-linux/src/wayland/mod.rs):
The Generated by Claude Code |
|
✅ Action performedReview finished.
|
Summary
Implements a fallback input mechanism for compositors that don't support wlroots virtual-pointer protocol (KDE Plasma, GNOME). When the
portal-libeifeature is enabled, input operations (pointer, scroll, drag, typing) automatically fall back to libei/portal interfaces instead of failing.Key Changes
Fallback infrastructure: Added
with_libei_fallback()andwith_wtype_libei_fallback()helper functions that detect when wlroots virtual-pointer is unavailable and route operations through libei adapters on portal-enabled builds.Marker-based error detection: Introduced
NO_VPTR_MARKERconstant to tag "no virtual-pointer" errors, allowing the dispatch layer to distinguish recoverable failures from hard errors.Refactored input functions: Split public input APIs (
click,scroll,move_cursor_absolute,drag) into thin wrappers that call either wlroots or libei implementations based on compositor capabilities.libei adapter implementations: Added coordinate/button/key translation layer that bridges wlroots-shaped APIs (output-relative integers, X keysyms, CUA button codes) to libei's logical device-region floats and evdev codes:
libei_click(),libei_scroll(),libei_move_absolute(),libei_drag()libei_type_text(),libei_press_key()key_to_evdev()mapping for keyboard inputTyping/keyboard fallback: Modified
type_text(),press_key(), andhotkey()to detect wtype failures and fall back to libei when available. Note:hotkey()with modifier chords is not yet supported via libei and fails with a clear error message.Stub implementations: For builds without
portal-libeifeature, libei adapters are compiled as unreachable stubs so closures type-check while the feature-gated dispatch seams prevent their execution.Implementation Details
anyhow::Resultsignatures by using string markers rather than typed errors.Fixes #1982.
https://claude.ai/code/session_01BY1JBgWq3gxNST3htj3Ysy
Summary by CodeRabbit
New Features
Bug Fixes
wtype-related errors through the fallback when enabled.Chores