Skip to content

feat: background pointer input on GNOME through a virtual pen - #489

Merged
avifenesh merged 3 commits into
mainfrom
feat/virtual-pen
Nov 19, 2026
Merged

avifenesh merged 3 commits into
mainfrom
feat/virtual-pen

Conversation

@avifenesh

@avifenesh avifenesh commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

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, drag and scroll with delivery: "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 through zwp_tablet_tool_v2, so the user's mouse stays where it is.

  • Left click is a pen tap, right click the upper barrel button (BTN_STYLUS2), middle the lower one (BTN_STYLUS). GTK and Xwayland map them that way, as xf86-input-wacom does. click_count repeats them.
  • A drag is the pen tip pressed at the start, moved and lifted at the end. Both ends must be on the target window.
  • A scroll is a one-finger touch pan, 60 logical px per wheel notch, split into strokes that stay inside the window and 48 px from the monitor edges (GNOME Shell's edge swipes start there). The finger rests before it lifts, so the app does not fling.
  • Before any input, the server reads GNOME Shell's window stacking through the extension and checks that the point is on the target window and that no window above it covers the point. A covered point is refused with nothing sent.
  • drag takes delivery and window target fields for this. Results report the route as gnome-pen or gnome-touch and say whether the user's keyboard focus moved. doctor reports the route and its limits in capabilities.background_pointer.
  • Without /dev/uinput access 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.GetDeviceMapping where the device maps. If that is not where the point is, it writes the device's own output setting (tablet: empty, so the whole layout; touchscreen: the monitor under the point from DisplayConfig.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

  • Not the default route without 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.
  • GNOME only. KWin 6.2+ gives a tablet its own cursor too, but maps a tablet with no configured output to the active output, which follows the user's pointer, and a touchscreen needs a configured output. Getting it right there means writing kcminputrc, and I could not test it here. sway, Hyprland, niri and COSMIC move their one seat cursor for tablets. X11 and sway already have the agent seat.

Limits (in README and results)

  • A tap or touch focuses the window it lands on, so the user's typing goes there afterwards. The result says when keyboard focus moved.
  • Apps without tablet support never see the pen, and the call cannot tell.
  • A drag stays inside one window. A touch pan scrolls only where the app pans on touch.
  • Hover lasts 8 s after an action.

Tests

  • tests/virtual_pen.rs runs scripts/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.
  • Against origin/main the same fixture fails: the first call returns the notice, later ones move the pointer (it ended at (700, 300)).
  • Unit tests for the pure parts: layout from GetCurrentState, capture-to-device mapping, the stacking check, pan strokes, session classification, and the barrel button frames.
  • fmt, clippy -D warnings, cargo test --no-fail-fast (all pass, the pen fixture included), rustdoc, mcp_safety_check.py, check_plugins.sh and the Pi catalog --check pass on the dev desk.

Note

Medium Risk
Adds privileged input injection (/dev/uinput), temporary GNOME peripheral gsettings, 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, and scroll with delivery: "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.

drag gains delivery and the usual window selectors so background drags can use this path; MCP schemas, README/CHANGELOG/SKILL text, and doctor are updated with capabilities.background_pointer and route/limit reporting. Implementation lives in new src/virtual_pen.rs (uinput devices, Mutter display/mapping via D-Bus/gsettings, idle teardown), wired from server.rs for background pointer actions and virtual_pen::shutdown() on server exit. An opt-in integration fixture scripts/virtual_pen_test.py / tests/virtual_pen.rs exercises real GNOME Shell behavior.

Reviewed by Cursor Bugbot for commit edbec4c. Configure here.

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

@revuto-review revuto-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 drag reports the target as raised, although dispatch_drag ignores the target. A screenshot_after: "window" crop can then show a covering window.
  • pan_strokes stops at 40 strokes without saying so, and the result still reports the full requested distance as sent.
  • The unsafe block in availability() 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.

Comment thread src/virtual_pen.rs
Comment on lines +355 to +363
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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 hidden and 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 returns Ok.

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.

Comment thread src/server.rs Outdated
}
}
};
let raised = background_target_raised(true, report.as_ref());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/virtual_pen.rs
let backward = distance < 0.0;
let mut remaining = distance.abs();
let mut strokes = Vec::new();
while remaining > 0.5 && strokes.len() < MAX_STROKES {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/virtual_pen.rs
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread src/virtual_pen.rs
strokes.push((point(begin), point(end)));
remaining -= length;
}
Ok(strokes)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

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.
@avifenesh

Copy link
Copy Markdown
Collaborator Author

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:

  • Target on a workspace the user does not see: the check now requires a focused window and the target on its workspace. No focused window (the overview hides focus) and a focused window on every workspace are refused. The screen being locked is refused through org.gnome.ScreenSaver.
  • Pan strokes: a pan always starts at the point (no more moving the start to the far edge or clamping it in), every stroke end goes through the same stacking check, and a pan needing more than 40 strokes is refused instead of cut short. The result reports the distance sent.
  • Rotated monitors: mutter's matrix for a device mapped to one monitor carries that monitor's transform. Touch scrolling on a rotated or flipped monitor is refused; the pen is always kept on the whole layout, where the matrix is plain.
  • The output setting is reset before a device exists, not after, so a leftover value from a crash cannot map a new device.
  • Several servers share one settings path: a lock file in XDG_RUNTIME_DIR is held across a gesture and around device removal.
  • A mutter without InputMapping is now a missing route (notice, then focused input) instead of a failed call.
  • Background drag reports its target as not raised, so screenshot_after: "window" keeps the focus check.
  • SAFETY comments on both FFI calls; docs say a touch focuses too, and that GNOME Shell's own UI (a dialog, a banner, an open menu) is not part of the check.

Re-run on the dev desk: fmt, clippy -D warnings, cargo test --no-fail-fast with the GNOME Shell fixture (all checks pass, hover 8.3 s), rustdoc, MCP safety, plugins and the Pi catalog check.

@revuto-review revuto-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an auto review done by revuto.


Re-review of 83c6897. All four earlier findings are resolved:

  • Inactive workspace: check_point_on_target now refuses unless a focused window shares the target's workspace, and the extension clears focused while the overview is open.
  • Drag fallback: drag passes TargetRaised::No, so the post-action crop guard applies again.
  • MAX_STROKES: pan_strokes refuses instead of cutting short, and the reported distance is summed from the strokes.
  • SAFETY comment: added.

Two new issues in the follow-up commit, both inline. Reviewed by reading the diff and tracing callers; nothing was built or run.

Comment thread src/virtual_pen.rs Outdated
return Ok(ProcessLock { _file: file });
}
if Instant::now() >= deadline {
return Err(PenError::NoRoute(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, click clears params.delivery and sends a focused click (server.rs:1650-1656), and drag calls dispatch_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.

Comment thread src/server.rs Outdated
Ok(window) => window.clone(),
Err(error) => return fail(format!("Nothing was sent: {error:#}")),
};
if pen::screen_locked().await {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@avifenesh

Copy link
Copy Markdown
Collaborator Author

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.

@revuto-review revuto-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an auto review done by revuto.


Revuto completed the review and found no evidence-backed concerns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant