Skip to content

fix: pen buttons on GNOME 48+ and touch scrolls after a pen action - #493

Merged
avifenesh merged 4 commits into
mainfrom
fix/pen-followup
Nov 20, 2026
Merged

avifenesh merged 4 commits into
mainfrom
fix/pen-followup

Conversation

@avifenesh

@avifenesh avifenesh commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #489 (refs #480).

What changes

  • Pen buttons on GNOME 48 and later. gsettings-desktop-schemas f25d3e7c (GNOME 48) changed the stylus defaults: button-action (lower button, BTN_STYLUS) became right and secondary-button-action (upper, BTN_STYLUS2) middle. Mutter rewrites a tool's buttons by those actions before a client sees them (meta-seat-impl.c, the tool button map), so on GNOME 48+ the feat: background pointer input on GNOME through a virtual pen #489 mapping (right = upper button) arrived as a middle click. That is why the GNOME Wayland: let Computer Use click without moving my mouse #480 reporter found the lower button gives a right click in Chromium. GNOME 46 and 47 default to default, which passes the code through. Every client agrees on the bare codes: GTK (gdkseat-wayland.c), Xwayland (xwayland-input.c), Chromium ozone (wayland_tablet_tool.cc) and KWin all map BTN_STYLUS to middle and BTN_STYLUS2 to right. So the server now writes both actions (middle, right) for its own pen's tool, at /org/gnome/desktop/peripherals/stylus/default-6375:7065/ (a uinput pen has no serial, so mutter keys it by vendor and product id), before the pen exists, and resets them when the pen goes away. Every GNOME then delivers the code the pen pressed. No per-toolkit mapping is needed.
  • The actions are written before every action, under the process lock, not only when the pen is made: every server's pen shares that settings path, and one server's pen going away resets it.
  • No lingering hover. libinput pairs a tablet with the first touchscreen it sees and, for a pen without tilt, drops every touch while the pen is in proximity (evdev-tablet.c, tablet_toggle_touch_device), and for 90 ms after it leaves (evdev-fallback.c, the arbitration timer). The pen hovered 8 s after each action, so a scroll in that time sent nothing although the call reported it sent. feat: background pointer input on GNOME through a virtual pen #489's fixture passed only because its scroll created the touchscreen while the pen already hovered. Worse, the paired touchscreen can be the user's own, which then ignored touch for 8 s after every background click. The pen now leaves proximity at the end of each action, and a scroll waits out the 90 ms (200 ms from the pen's leave).
  • A new touchscreen settles first. Mutter lists a new touchscreen before it has mapped it. A pan sent at once never reached the window (measured once the hover no longer hid it), so the first touch waits 300 ms.

Tests

scripts/virtual_pen_test.py (opt-in seat0 GNOME Shell 46 fixture, dev desk):

  • The session's schemas carry GNOME 48's stylus defaults (a compiled schema override), so the run shows what GNOME 48+ does, also after a reset.
  • A second server's pen comes and goes between clicks; the first server's right and middle clicks must stay right and middle.
  • The pen must leave proximity right after a click, and a scroll right after a pen click must pan.
  • The Xwayland display comes from mutter's log, not from a scan of /tmp/.X11-unix.
  • With Chromium or Google Chrome installed, a page in it (native Wayland, then Xwayland: mutter now starts Xwayland for X clients) gets a left click, right and middle clicks, a double click, a drag and a scroll; it must see pointerType: "pen" events with the named button (contextmenu for right, auxclick button 1 for middle), a dblclick, pen moves between the drag's ends, and the list must scroll. No mouse button event may reach the page.

Results on the dev desk, Google Chrome 158, GNOME Shell 46:

  • origin/main: 14 checks fail (on the first fixture version). GTK right click arrives as button 2 and middle as 3. Chromium Wayland and X11 get auxclick for right and contextmenu for middle. The second GTK scroll and both Chromium scrolls never pan, and libinput debug-events shows no touch events after the first scroll.
  • the first commit of this branch, against the current fixture: right and middle clicks swap again after the second server's pen goes away, and the pen still hovers.
  • this branch: all checks pass, GTK plus Chromium Wayland and Xwayland.

fmt, clippy -D warnings, cargo test --no-fail-fast, mcp_safety_check.py, check_plugins.sh and the Pi catalog --check pass on the dev desk.

KWin support and the hover question follow in a separate PR.

GNOME 48 changed the stylus button defaults (gsettings-desktop-schemas
f25d3e7c): the lower button became a right click and the upper one a
middle click, and mutter rewrites the pen's buttons by them, so a
background right click arrived as a middle click. The server now sets both
actions for its own pen and resets them with the pen.

libinput pairs a tablet with the first touchscreen it sees and drops every
touch while the pen is in proximity and for 90 ms after it leaves, so a
scroll after a click sent nothing. A scroll now lifts a hovering pen first.

The GNOME seat fixture now runs with GNOME 48's stylus defaults, scrolls
after a pen click, and repeats the clicks, a drag and a scroll on Chromium
under native Wayland and Xwayland.

@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 finding, in the multi-server case this module already guards with process_lock: the stylus button actions are written once per pen but reset by any server whose pen goes away, so a surviving server's pen falls back to the GNOME 48+ defaults and its right and middle clicks swap again. The scroll change (lift a hovering pen, wait 150 ms) reads correctly: it runs under the DEVICES lock, so the reaper cannot race it.

Not verified here: mutter's behaviour itself. This review had no network or mutter sources and ran nothing, so the key-to-button mapping and the settings path rest on the PR's own measurements.

Comment thread src/virtual_pen.rs
if self.wrote_output {
reset_output(Kind::Pen);
}
reset_stylus_actions();

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 reset is shared across servers, but the matching write is not repeated, so one server going away re-swaps the buttons for another server's live pen on GNOME 48+.

Every server uses the same vendor and product id, so they all share the one default-6375:7065 path (the ProcessLock comment says as much). set_stylus_actions() runs only inside if devices.pen.is_none() in run_pen, i.e. once per pen. The sequence that breaks:

  1. Server A makes its pen and writes middle ​/ right.
  2. Server B makes its pen and writes the same.
  3. B exits or idles out after 600 s. Pen::drop resets both keys to the schema defaults.
  4. A's pen is still alive, so A never writes them again. On GNOME 48+ its next button: "right" click arrives as a middle click, and the call still reports used: true.

This depends on mutter re-reading the tool's button map on each proximity-in rather than once per tool. That is my reading of mutter (tool-changed → apply_stylus_settings), not something I could check here. If it holds, every click hits it, because hover(.., true) leaves and re-enters proximity.

The output key does not have this problem: covering_area re-checks the mapping before every gesture and rewrites it when it differs. The button actions have no such re-check.

Two ways to fix it:

  • Call set_stylus_actions() on every run_pen, under the process lock that perform already holds, before the fresh proximity-in.
  • Drop the reset on Drop. The path belongs only to this server's own ids, so a leftover value affects no other device (the fixture's 'stylus' not in dump check would then need to change).

@avifenesh

Copy link
Copy Markdown
Collaborator Author

Fresh-context review: PR #493 at 6f64596

I read the diff and the head versions of src/virtual_pen.rs and scripts/virtual_pen_test.py, and checked the upstream claims against current source: mutter main and gnome-46 (meta-input-settings.c, native/meta-input-settings-native.c, native/meta-seat-impl.c, native/meta-input-device-tool-native.c), libinput main (evdev-tablet.c, evdev-fallback.c), gsettings-desktop-schemas f25d3e7c, GTK gdkseat-wayland.c and Chromium wayland_tablet_tool.cc. I did not build, run or send any input.

High

  1. One server's teardown flips another live server's pen buttons. src/virtual_pen.rs:910 (Pen::drop), :1129 and :1135 (error paths in run_pen), with the set only at :1128 when the pen is first created. Every server's pen has the same vendor and product id, so they all share /org/gnome/desktop/peripherals/stylus/default-6375:7065/. Several servers at once is normal: each Claude Code or Codex session starts its own stdio MCP server. When server A's reaper drops its idle pen (IDLE_LIFETIME), or A shuts down, hits a Partial error, or fails to create a pen, reset_stylus_actions() puts the path back to GNOME 48's defaults (right and middle) while server B's pen is still alive. B never writes the actions again, because devices.pen is still Some. Mutter reads the tool settings again on every proximity in (meta_input_settings_notify_tool_change calls apply_stylus_settings), and for the current tool on every change (current_tool_changed_cb, mutter main). Every click enters proximity fresh (hover(..., true)). So from then on B's button: right arrives as a middle click and middle as a right click on GNOME 48+, which is the exact bug this PR fixes, and nothing reports it. The ProcessLock does not help, because the setting has to hold for the whole life of B's pen, not just while one call runs. The base code already treats the shared output path this way: covering_area checks it on every gesture, and the ProcessLock comment says another server's reset must not land between the check and the events. Fix: write the two actions (or read them and write when they differ) on every pen gesture, under the process lock, before the hover(..., true) that enters proximity. Mutter then applies them when the tool comes in. The reset on drop can stay, since the next user writes them again. The fixture has no two-server case. A second server process whose pen is reaped while the first one right-clicks would show this.

Medium (already there before this PR; the PR's own libinput analysis brings it up)

  1. A hovering virtual pen turns off a real touchscreen, and another server's touchscreen. libinput pairs a tablet with the first touchscreen it sees (evdev-tablet.c tablet_setup_touch_arbitration). It drops every touch while the tool is in proximity when tilt.x == 0 (ARBITRATION_IGNORE_ALL in tablet_toggle_touch_device). On a laptop with a real touchscreen, the virtual pen pairs with the user's own panel, so for HOVER_LIFETIME (8 s) after every background click or drag the user's touchscreen does nothing. That is background input changing what the user can do. Also, server B's pen can pair with server A's virtual touchscreen. B's 8 s hover then silently drops A's background scrolls, because the lift at src/virtual_pen.rs:1240-1245 only lifts this server's own pen, and the scroll still reports it was sent. Possible fixes: end proximity soon after a gesture instead of hovering 8 s, or leave the pen out of proximity whenever the hover is not needed. This could go in the follow-up PR about hovering; it does not block this one.

Low

  1. The arbitration wait is a fixed margin with no check. src/virtual_pen.rs:86 and :1244. The 90 ms timer starts at the proximity-out event's own timestamp (usec_add_millis(time, 90) in fallback_interface_toggle_touch), and touches are dropped until mutter's input thread runs the timer callback (fallback_arbitration_timeout). If that thread stalls by more than about 60 ms, the touch-down can be read before the timer fires and get swallowed, and the call still reports it was sent. 150 ms is a reasonable margin. Nothing to change unless it shows up under load, but the comment could say it is a margin, not a guarantee.

  2. Real GNOME 48+ mutter was not run. The fixture runs GNOME Shell 46 with GNOME 48's schema defaults written into the tool's path. That reproduces the setting, but mutter 48+ has a different remap path: meta-seat-impl.c now switches on the action. Reading mutter main, middle and right still map to BTN_STYLUS and BTN_STYLUS2 (meta-input-settings-native.c sets MIDDLE from button-action and SECONDARY from secondary-button-action), so I expect the fix to work there. But the CHANGELOG and PR text ("every GNOME delivers the code the pen pressed") claim more than was measured. One more thing, in favour of the PR: on mutter main, an absent map entry or default is G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT, which meta-seat-impl.c turns into CLUTTER_BUTTON_PRIMARY (a left click). So writing explicit middle and right is right, and a future change must never "pass through" by writing default. That would be worth a line in the module comment at src/virtual_pen.rs:38-46.

  3. The fixture can pick up another session's X socket. scripts/virtual_pen_test.py:252 and :274 find the Xwayland display by comparing /tmp/.X11-unix before and after. On a shared dev desk, another session's X server starting in that window would be taken instead. Using mutter's own display (for example, reading it from the fixture shell's log or from the auth file's owner) would be safer. This only affects the test.

  4. README wording. The sentence "A scroll first lifts a hovering pen out of proximity..." comes before the sentence that says what a scroll is ("A scroll is a one-finger touch pan..."). Moving it after that sentence reads better.

Checked and correct

  • gsettings-desktop-schemas f25d3e7c changes button-action from default to right and secondary-button-action from default to middle.
  • Mutter's settings path for a tool with serial 0 or 1 is stylus/default-%.4x:%.4x/ (main, integer ids; gnome-46 builds the same lowercase string). {VENDOR:04x}:{PEN_PRODUCT:04x} gives 6375:7065, the same.
  • On GNOME 46, middle maps to BTN_STYLUS and right to BTN_STYLUS2 (action_to_evcode), so the explicit values change nothing there.
  • GTK (gdkseat-wayland.c) and Chromium ozone (wayland_tablet_tool.cc) map BTN_STYLUS to middle and BTN_STYLUS2 to right.
  • libinput: the pairing with the first touchscreen, ignore-all when tilt.x == 0, and the 90 ms timer after proximity out all match the code comments.
  • Safety of the new code paths: the lift in run_touch sends only a proximity out (leave() clears the tip and both buttons) and runs under the device mutex and the process lock. The pan's own window and point checks are unchanged. The settings are written only on the server's own vendor and product path. The fixture's final dconf dump check fails if they are left behind.
  • The tests do prove the single-server change: on main the GTK right and middle checks and the scroll-after-click check fail, and they pass on the branch.

Review findings on the pen follow-up:
- Every server's pen shares one stylus settings path, so one server's
  reset left another's pen on GNOME 48's swapped defaults. The actions are
  now written before every action, under the process lock.
- A hovering pen silences the touchscreen libinput paired it with, which
  can be the user's own. The pen now leaves proximity after each action
  instead of hovering 8 s, and a scroll waits out libinput's 90 ms.
- A new touchscreen's first pan never reached the window: mutter lists it
  before mapping it. The first touch now waits 300 ms.

The fixture runs with GNOME 48's stylus defaults compiled into the
session's schemas, adds a second server whose pen comes and goes, takes
the Xwayland display from mutter's log, and checks that the pen leaves
proximity after a click.
@avifenesh

Copy link
Copy Markdown
Collaborator Author

Addressed the fresh-context review in 75ecebe:

  1. High, shared settings path: the stylus actions are now written before every pen action under the process lock. The fixture adds a second server whose pen comes and goes between clicks. Against the previous commit the first server's right and middle clicks swapped after that; now they hold.
  2. Medium, a hovering pen silences a paired touchscreen (possibly the user's): the pen no longer hovers. It leaves proximity at the end of each action, so arbitration lasts only for the action plus libinput's 90 ms. The fixture checks the pen leaves proximity within 0.5 s of a click.
  3. Low, margin: the scroll now waits 200 ms from the pen's own leave. With no hover, the pen leaves at the end of the previous call, so the wait is almost always already over.
  4. Low, real GNOME 48: GNOME 48's defaults are now compiled into the session's schemas (a schema override), not written per path, so a reset returns to them as it would on GNOME 48. The CHANGELOG says what was measured and what comes from mutter's source, and the module comment says never to write default.
  5. Low, Xwayland display: it now comes from mutter's "Using public X11 display" log line.
  6. README: reordered.

New finding while fixing 2: with the hover gone, a fresh touchscreen's first pan never reached the window, because mutter lists the device before mapping it. The hover had hidden this. The first touch now waits 300 ms; the fixture's first scroll covers it.

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

logind starts a getty on the active terminal when no session holds it, and
one left from the previous run took tty6 back about ten seconds in and hung
up GNOME Shell's session: every second back-to-back run failed, on main too.
The getty is masked with --runtime for the run and unmasked after. Four
back-to-back runs now 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.

@avifenesh

Copy link
Copy Markdown
Collaborator Author

Fresh-context re-review: delta 6f64596...ccb2de6

I reviewed only the delta (75ecebe and ccb2de6), with the same rules as before. I did not build, run anything or send any input. To check the delta's claims I read mutter gnome-46 meta-xwayland.c and the head tree.

The earlier findings

  • High 1 (one server's reset swaps another server's buttons): fixed. run_pen now writes both actions before every action, under the process lock (src/virtual_pen.rs:1127-1134). The fixture's new second server clicks and exits between the left click and the right click (scripts/virtual_pen_test.py:355-361). Server.close closes stdin and waits, so virtual_pen::shutdown runs and resets the path. That check would fail on 6f64596.
  • Medium 2 (a hovering pen silences a paired touchscreen): fixed for this server's own pen. The pen leaves proximity at the end of every action (src/virtual_pen.rs:1213-1215), so the user's touchscreen is off only for the action plus 90 ms. The README, the SKILL.md copies, the doctor note and the server.rs limits no longer say the pen hovers 8 s. The only mention left is the released 0.7.58 CHANGELOG entry, which is correct to keep.
  • Low 3 (fixed wait): now 200 ms counted from this pen's own left_at, and the comment says the timer counts from the event's own time. Fine.
  • Low 4 (claims beyond what was measured): the CHANGELOG now says what was measured and what comes from reading mutter's source. The module comment warns never to write default. Resolved.
  • Low 5 (X socket comparison): now read from mutter's own log line. g_message ("Using public X11 display %s, ...") is at gnome-46 src/wayland/meta-xwayland.c:1098, so the regex matches. Resolved.
  • Nit 6 (README order): resolved.

New findings

Low

  1. The reaper and shutdown() still reset without the lock when they cannot get it (src/virtual_pen.rs:965, :981). let _process = process_lock(Duration::from_secs(2)); keeps the Result. On Err the drop, and with it reset_stylus_actions(), runs anyway. run_pen writes the actions and then can wait up to MAPPING_TIMEOUT (3 s) in covering_area before the pen enters proximity. Another server's reaper or shutdown that gives up after 2 s can reset the path inside that window. That server's pen then enters proximity on GNOME 48's defaults, and a right click becomes a middle click. This mostly happens on a pen's first use, when the mapping wait is longest. Fix: write the actions right before the hover(..., true) that enters proximity, after covering_area. In the reaper, do not drop on Err; try again on the next pass. In shutdown(), wait longer.
  2. Another server's pen can still swallow the first part of a pan (src/virtual_pen.rs:1247-1254). run_touch waits only for this server's own left_at. Pens pair with the first touchscreen libinput sees, so server B's pen can be paired with server A's touchscreen. If B's action ends less than 90 ms before A's scroll gets the process lock, A's first touch frames are dropped, and A still reports the scroll as sent. One fix: store the time a pen last left proximity in the shared lock file, and have every server wait from the latest one.
  3. Two dconf writes on every pen action (src/virtual_pen.rs:848-853 via :1130). gsettings set writes even when the value is already there. Each click and drag rewrites the user's dconf database twice and sends a change signal to every GSettings listener in the session, mutter included. Read the two keys first and write only when they differ. That costs two gsettings get calls and no disk writes.
  4. The fixture's second-server click is not checked (scripts/virtual_pen_test.py:359). The result of other.call('click', ...) is ignored. If that call fails (no route, the lock busy, a refused point), the second pen is never made or reset, and the right and middle checks after it pass without testing anything. Check ok, background.used and route == 'gnome-pen', as background() does.

Nits

  1. TOUCH_SETTLE is a guess with no check (src/virtual_pen.rs:1238-1241). It sleeps 300 ms before covering_area, which already waits for mutter to confirm the mapping. If the first pan was lost because mutter had not finished adding the device yet, 300 ms is a guess. A comment saying what was measured, or a probe, would make it more robust.
  2. The getty mask in the fixture (scripts/virtual_pen_test.py:271-277). systemctl mask --runtime --now stops a getty on that terminal, which would also end a text login there, and its result is ignored. That is acceptable on the headless dev desk, but the docstring could say it. import re inside run could move to the top of the file.

No High or Medium findings in the delta.

- The stylus actions are written right before the pen enters proximity,
  and only the ones that differ, so an unchanged setting sends no signal.
- The idle reaper removes the devices only under the process lock (their
  reset touches settings every server's pen shares); shutdown waits up to
  10 s for it.
- A pen action holds the process lock 200 ms past the pen's leave, so no
  server's scroll starts inside libinput's 90 ms touch arbitration.
- The fixture checks the second server's click went through its pen.
@avifenesh

Copy link
Copy Markdown
Collaborator Author

Re-review findings, addressed in 3a0cd24:

  1. The actions are now written right before the pen enters proximity (after the mapping wait). The idle reaper removes the devices only while it holds the process lock, and retries otherwise. shutdown() waits up to 10 s.
  2. A pen action now holds the process lock 200 ms past its leave, so no server's scroll can start inside another pen's 90 ms arbitration window.
  3. The actions are read first and only differing ones are written.
  4. The fixture checks that the second server's click went through its pen.

Nits: import re moved to the top. TOUCH_SETTLE is measured, not a guess: without it the first pan on a fresh touchscreen never arrived, and with 300 ms it passed in every run since (six back to back). The getty mask runs only in the opt-in fixture, which already refuses to run while a graphical session holds seat0.

Fixture: two back-to-back passes on the dev desk; fmt, clippy, tests, MCP safety, plugins and the Pi catalog pass.

@avifenesh
avifenesh merged commit 3a0cd24 into main Nov 20, 2026
24 of 25 checks passed
@avifenesh
avifenesh deleted the fix/pen-followup branch November 20, 2026 03:37
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