Repository navigation
feat: background pointer input on GNOME through a virtual pen - #489
Conversation
On GNOME Wayland, click, drag and scroll with delivery "background" now go through a uinput pen and touchscreen. Mutter gives a tablet tool its own cursor and sends its events through the tablet protocol, so the user's mouse pointer stays where it is. Left, right and middle clicks are a tap and the upper and lower barrel buttons, a drag is a pen stroke inside one window, and a scroll is a one-finger touch pan. Before any input the point is checked against GNOME Shell's stacking order: it must be on the target window with no window above it. drag takes delivery and a window target for this. doctor reports the route in capabilities.background_pointer. The uinput pointer stays the default route: apps without tablet support never see the pen. The idea and the tested approach come from @Ondra-Zik. Refs #480
There was a problem hiding this comment.
This is an auto review done by revuto.
One blocking gap in the pre-input window check, plus three smaller issues. Reviewed by reading the diff and tracing callers; nothing was built or run.
Blocking
- The stacking check never verifies that the target is on the active workspace. A target on another workspace passes, and the tap or pan lands on whatever the user has at that point on the workspace they are looking at.
Smaller
- The focused fallback for a background
dragreports the target as raised, althoughdispatch_dragignores the target. Ascreenshot_after: "window"crop can then show a covering window. pan_strokesstops at 40 strokes without saying so, and the result still reports the full requested distance as sent.- The
unsafeblock inavailability()has no// SAFETY:comment.
Checked and found fine: the opt-in gating of the tests/virtual_pen.rs fixture (skips with exit 0 when the env var is unset), the new DragParams fields (all optional, so not a breaking schema change), device teardown on a partial failure, and the reaper/perform locking.
| let same_workspace = | ||
| |window: &crate::windowing::types::WindowInfo| match (window.workspace, target.workspace) { | ||
| (Some(a), Some(b)) => a == b || a < 0 || b < 0, | ||
| _ => true, | ||
| }; | ||
| let top = windows | ||
| .iter() | ||
| .rev() | ||
| .filter(|window| !window.hidden && same_workspace(window)) |
There was a problem hiding this comment.
This is an auto review done by revuto.
A target on an inactive workspace passes this check, and the input then lands on the user's active workspace.
The extension's ListWindows is built from global.get_window_actors(), which includes windows on every workspace. It reports hidden as window.minimized only, and it does not say which workspace is active (extension.js:220-249).
Here the covering scan keeps only windows on the target's workspace. So when the target is on workspace 1 and the user is on workspace 0:
- the target is not
hiddenand its frame rect contains the point; - every window on workspace 0 is filtered out by
same_workspace; - the target is therefore
top, and the check returnsOk.
The pen tap or touch pan then goes to whatever is at that point on workspace 0. That is a click in the user's window, with keyboard focus moved, while the result says the click was sent to the target. The user switching workspaces while the agent works is the normal case for delivery: "background", so this is easy to hit.
The unit test covers "a window on another workspace does not cover it" but not the case where the target itself is off the active workspace.
Suggested fix: have the extension report whether each window is on the active workspace (for example window.located_on_workspace(global.workspace_manager.get_active_workspace()), or an active_workspace index), and refuse with nothing sent when the target is not. Main.overview.visible deserves the same treatment, since frame rects do not describe what is under the point while the overview is open.
| } | ||
| } | ||
| }; | ||
| let raised = background_target_raised(true, report.as_ref()); |
There was a problem hiding this comment.
This is an auto review done by revuto.
The focused fallback claims the target was raised, but dispatch_drag never raises it.
On the fallback path the report is BackgroundReport::focused() (used: false), so background_target_raised(true, …) returns TargetRaised::Yes. That is right for click and scroll, whose focused dispatch activates the target. A focused drag ignores the target entirely (the new DragParams doc says so).
With Yes and a target, ensure_post_action_crop_shows_target skips its window.focused check. A screenshot_after: "window" on this path then crops the target's bounds out of the desktop capture even when another window covers it, and labels the crop as the target.
Before this PR, drag passed None as the target, so this could not happen. Passing TargetRaised::No for the fallback (or None as the target, as the non-background branch does) keeps the existing guard in force.
| let backward = distance < 0.0; | ||
| let mut remaining = distance.abs(); | ||
| let mut strokes = Vec::new(); | ||
| while remaining > 0.5 && strokes.len() < MAX_STROKES { |
There was a problem hiding this comment.
This is an auto review done by revuto.
The pan is silently cut at MAX_STROKES, and the result still reports the full distance.
When the loop stops at 40 strokes with remaining > 0, the leftover distance is dropped and Ok(strokes) is returned. background_pen then builds its message from the requested motion (distance = motion.0.abs() + motion.1.abs()), not from what the strokes cover.
Example: pages: 20 is 100 notches, so 6000 px. With the point 100 px below the top of the pan bounds, each stroke is 100 px. 60 strokes are needed, 40 are sent, and the result reads "a 6000 px touch pan in 40 strokes" for 4000 px delivered. MAX_SCROLL_PAGES is 100 (30000 px), which 40 strokes cannot cover from mid-window on a 1080p monitor.
Either refuse up front when the distance does not fit in MAX_STROKES, or return the delivered distance and report that the scroll was shortened.
| classify(&SessionFacts::from_env())?; | ||
| let writable = std::ffi::CString::new("/dev/uinput") | ||
| .ok() | ||
| .is_some_and(|path| unsafe { libc::access(path.as_ptr(), libc::W_OK) } == 0); |
There was a problem hiding this comment.
This is an auto review done by revuto.
This new unsafe block has no // SAFETY: comment, unlike the other FFI calls in the crate (for example keymap_fd in agent_seat.rs). One line is enough: path is a valid NUL-terminated CString that outlives the call, and access only reads it.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit edbec4c. Configure here.
| strokes.push((point(begin), point(end))); | ||
| remaining -= length; | ||
| } | ||
| Ok(strokes) |
There was a problem hiding this comment.
Large pans silently drop leftover distance
Low Severity
pan_strokes stops at MAX_STROKES (40) and still returns success, while the result text reports the full requested distance. A large pages value on a short window can therefore deliver only part of the pan and still claim the scroll was sent in full.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit edbec4c. Configure here.
- Refuse when the target is not on the workspace of the focused window, when no window has focus (the overview may be open), and while the screen is locked. - A touch pan always starts at the point, every stroke end is checked against the target, and a pan that needs more than 40 strokes is refused instead of cut short; the result reports the distance sent. - Refuse touch scrolling on a rotated monitor, and keep the pen on the whole layout whenever mutter maps it to a monitor. - Reset a device's output setting before the device exists, and hold a lock across servers while sending or removing devices, since every server shares one settings path. - A mutter without InputMapping is a missing route, not a failed call. - A background drag reports its target as not raised.
|
Independent review (a fresh-context reviewer read the diff with mutter and libinput sources; it ran nothing that makes devices), plus revuto and Bugbot. Fixed in 83c6897:
Re-run on the dev desk: fmt, clippy |
There was a problem hiding this comment.
This is an auto review done by revuto.
Re-review of 83c6897. All four earlier findings are resolved:
- Inactive workspace:
check_point_on_targetnow refuses unless a focused window shares the target's workspace, and the extension clearsfocusedwhile the overview is open. - Drag fallback:
dragpassesTargetRaised::No, so the post-action crop guard applies again. MAX_STROKES:pan_strokesrefuses instead of cutting short, and the reported distance is summed from the strokes.SAFETYcomment: added.
Two new issues in the follow-up commit, both inline. Reviewed by reading the diff and tracing callers; nothing was built or run.
| return Ok(ProcessLock { _file: file }); | ||
| } | ||
| if Instant::now() >= deadline { | ||
| return Err(PenError::NoRoute( |
There was a problem hiding this comment.
This is an auto review done by revuto.
A busy lock is reported as NoRoute, so the call falls back to focused input through the user's pointer.
perform waits 5 s for the lock (process_lock(Duration::from_secs(5))?), and the timeout returns PenError::NoRoute. In background_pen that maps to unavailable(reason) (server.rs:11428). The callers then treat it as a desktop without the route:
- the first time, the one-time notice is spent on "another computer-use-linux server is using the virtual pen";
- after that,
clickclearsparams.deliveryand sends a focused click (server.rs:1650-1656), anddragcallsdispatch_drag(server.rs:2980).
So a second server that only had to wait raises the window and moves the user's mouse, while the first server's gesture is still running on the same seat. This is the outcome delivery: "background" exists to prevent.
The 5 s limit is reachable. A pan stroke takes up to about 1 s (60 steps of 12 ms, plus 180 ms rest and 80 ms gap), and a pan may have 40 strokes. Eight 400 px strokes (a scroll of about ten pages) already hold the lock for about 5.3 s.
NoRoute is documented as "the desktop or this user lacks what the route needs". A timeout is NotSent: nothing went out and a retry will work. Returning PenError::NotSent here gives "Nothing was sent through the virtual pen: another server is using it" with no fallback. The lock-file open failure above can stay NoRoute.
| Ok(window) => window.clone(), | ||
| Err(error) => return fail(format!("Nothing was sent: {error:#}")), | ||
| }; | ||
| if pen::screen_locked().await { |
There was a problem hiding this comment.
This is an auto review done by revuto.
This check is not reached while the screen is locked, so the call is not refused as the README and CHANGELOG say.
extension_windows_stacked() runs first, ten lines up. The extension's metadata.json has no session-modes, so GNOME Shell disables it on the lock screen (the default is ["user"]). Its disable() unowns the bus name and unexports the object (extension.js:75-84, 531-534). The ListWindows call therefore fails while locked, and the function returns unavailable("... the extension did not answer ...; run setup_window_targeting") before screen_locked() is ever called.
The result on a locked screen:
- the first call spends the one-time notice on a message that blames the extension and suggests
setup_window_targeting; - later calls go to the focused fallback, which sends input through the user's pointer onto the lock screen.
Moving pen::screen_locked().await above the extension_windows_stacked() call makes the documented refusal ("Nothing was sent: the screen is locked.") the actual behaviour. I reasoned this from the metadata and the call order; I did not run it on a locked session.
Another server holding the virtual pen is a retry, not a missing route: normal input must not stand in for it. The lock screen check runs before the extension call, since GNOME Shell turns extensions off on the lock screen and that failure would read as a missing route.
|
Round two from revuto, fixed in 29a408b: a busy cross-server lock is now NotSent (retry, no focused fallback), and the lock screen check runs before the extension call, which GNOME Shell turns off on the lock screen. Suite re-run on the dev desk, GNOME Shell fixture included: all pass. |
There was a problem hiding this comment.
This is an auto review done by revuto.
Revuto completed the review and found no evidence-backed concerns.


Refs #480. The idea and the tested approach come from @Ondra-Zik: a temporary uinput pen mapped to the screen, window checks before input, and a touchscreen for scrolling. This builds that into the existing
delivery: "background"route.What changes
On GNOME Wayland,
click,dragandscrollwithdelivery: "background"and a window target go through a virtual pen and a virtual touchscreen instead of the shared pointer. Mutter gives a tablet tool its own sprite and cursor (meta-wayland-tablet-tool.c) and sends its events throughzwp_tablet_tool_v2, so the user's mouse stays where it is.click_countrepeats them.dragtakesdeliveryand window target fields for this. Results report the route asgnome-penorgnome-touchand say whether the user's keyboard focus moved.doctorreports the route and its limits incapabilities.background_pointer./dev/uinputaccess or the GNOME Shell extension, the existing one-time notice and focused fallback apply.Mapping
Mutter maps an unconfigured tablet across the whole layout and an unconfigured touchscreen to the builtin panel, and guesses a monitor when the device name contains a monitor vendor or its physical size matches (meta-input-mapper.c). The devices declare one unit per mm over a 65535 range, so the size guess never matches. Before input the server asks
org.gnome.Mutter.InputMapping.GetDeviceMappingwhere the device maps. If that is not where the point is, it writes the device's ownoutputsetting (tablet: empty, so the whole layout; touchscreen: the monitor under the point fromDisplayConfig.GetCurrentState), waits until mutter confirms, and resets the setting when the device goes away. The settings paths are the devices' own vendor and product ids (6375:7065,6375:7463); no other device's setting is touched. Capture pixels map to layout pixels the way the uinput pointer already does.Lifecycle
The devices are made on first use and removed after ten idle minutes or at exit. libinput lifts a tablet out of proximity 50 ms after its last event until the tablet has sent a proximity-out of its own, so the pen does one in-and-out at its first point; after that it hovers until it leaves proximity 8 s after the last action.
Decisions
background. Measured on GNOME Shell:wev, which binds no tablet, saw nothing of a pen click that the server reported as sent. Mutter has no pointer emulation for tablets, so a client without tablet support silently loses every click. The uinput pointer reaches every client, so it stays the default.Limits (in README and results)
Tests
tests/virtual_pen.rsrunsscripts/virtual_pen_test.py: a real GNOME Shell 46 on a vkms output, as the display server of seat0 on a VT, with libinput reading the seat (headless mutter reads no input devices, so a uinput device never reaches it). It is opt-in (COMPUTER_USE_LINUX_TEST_GNOME_SEAT=tty6), needs passwordless sudo, and refuses to run while any graphical session is on seat0. A GTK 4 window logs every event with its device. A normal click puts the user's pointer at (40, 40). Background left, right, middle and double clicks, a drag and a scroll then arrive as pen and touch events at the right points, with no mouse event in between; a relative mouse nudge afterwards shows the pointer still at (39.9, 40). A covered point is refused before input. The pen hovered 8.1 to 8.4 s. After exit no virtual device and no tablet or touchscreen setting is left.-D warnings,cargo test --no-fail-fast(all pass, the pen fixture included), rustdoc,mcp_safety_check.py,check_plugins.shand the Pi catalog--checkpass on the dev desk.Note
Medium Risk
Adds privileged input injection (
/dev/uinput), temporary GNOME peripheralgsettings, and focus-changing side effects; behavior depends on tablet/touch client support and the Shell extension for hit-testing.Overview
On GNOME Wayland,
click,drag, andscrollwithdelivery: "background"and a window target can use a new virtual pen (gnome-pen) and virtual touchscreen (gnome-touch) instead of moving the user’s mouse. Clicks map to pen taps/barrel buttons, drags to pen strokes inside one window, and scrolls to touch pans (60 logical px per notch), with pre-checks that the point is on the target and not covered by a stacked window via the GNOME Shell extension.draggainsdeliveryand the usual window selectors so background drags can use this path; MCP schemas, README/CHANGELOG/SKILL text, anddoctorare updated withcapabilities.background_pointerand route/limit reporting. Implementation lives in newsrc/virtual_pen.rs(uinput devices, Mutter display/mapping via D-Bus/gsettings, idle teardown), wired fromserver.rsfor background pointer actions andvirtual_pen::shutdown()on server exit. An opt-in integration fixturescripts/virtual_pen_test.py/tests/virtual_pen.rsexercises real GNOME Shell behavior.Reviewed by Cursor Bugbot for commit edbec4c. Configure here.