Skip to content

feat(recording): record Wayland pointer clicks for automatic zoom - #4493

Open
kyzer1023 wants to merge 3 commits into
CapSoftware:mainfrom
kyzer1023:feat/wayland-click-events
Open

kyzer1023 wants to merge 3 commits into
CapSoftware:mainfrom
kyzer1023:feat/wayland-click-events

Conversation

@kyzer1023

@kyzer1023 kyzer1023 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Why

On Wayland, PipeWire cursor metadata carries cursor position and appearance, not mouse button presses. As a result, Wayland recordings had empty clicks in cursor.json, so automatic zoom never generated zoom segments for Wayland takes.

What changed

  • Added crates/recording/src/wayland_pointer.rs to open readable pointer /dev/input/event* nodes on Wayland and emit press/release click events (BTN_LEFT / BTN_RIGHT / BTN_MIDDLE), degrading cleanly when /dev/input is not readable by the current user.
  • Wired Wayland click events through crates/recording/src/sources/screen_capture/linux.rs, crates/recording/src/cursor.rs, and crates/recording/src/studio_recording.rs so clicks land in cursor.json in the same format automatic zoom already consumes.
  • Added unit tests in crates/recording/src/wayland_pointer.rs and crates/recording/src/sources/screen_capture/linux/wayland_portal_tests.rs. X11 cursor capture is unchanged.

Verification

Verified on a real Sway 1.9 Wayland session (xdg-desktop-portal-wlr, Linux Mint 22.3, Intel UHD 620 / NVIDIA MX150, cap-gpui running as unprivileged user kyzer):

  • Click source & permissions: cap.log reported Wayland click source opened pointers=1. Because kyzer is not in the input group on this host, the test used a synthetic uinput pointer (/dev/input/event21) with read ACL user:kyzer:r-- (production users need read access to /dev/input/event* via the input group or udev ACL; otherwise click capture degrades cleanly without failing the recording).
  • Recording output: Studio screen recording (Display 1) completed with recording-meta.json status: "Complete". ffprobe on content/segments/segment-0/display.mp4 confirmed playable H.264 yuv420p 1024×768 video, duration 31.358700s, 27 frames (sparse delivery on nested X11-backed Sway X11-1; xdg-desktop-portal-wlr refused cursor metadata mode 4 and retried with embedded cursor, so cursor.json moves is empty while clicks still arrive from evdev).
  • Recorded clicks: cursor.json contained 8 click entries (4 primary press/release pairs, cursor_num: 1) at 20.073s, 21.820s, 23.560s, and 25.319s.
  • Automatic zoom: Opening the .cap in the editor ran auto-zoom-on-open, cleared autoZoomPending, and wrote timeline.zoomSegments:
    • start: 19.772, end: 27.819, amount: 2.0, mode: "auto" (covering all four clicks).

On Ubuntu 22.04.5 x86-64 with headless Sway 1.7 and PipeWire 1.2.7, a synthetic pointer emitted eight press and release pairs while strace confirmed EACCES on its device node. At 7d4c66842, the recording finalized as Complete, all 235 H.264 frames decoded, and cursor.json recorded zero clicks.

Confidence Score: 5/5 · The PR appears safe to merge; all three previous findings are addressed.RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; all three previous findings are addressed.

Summary

Adds Wayland mouse clicks to cursor.json so recordings can generate automatic zoom.

  • Wayland recordings save button clicks for automatic zoom.
  • Wayland screen capture shares cursor positions and shapes with the recorder.

All three previous findings are addressed. No new findings were accepted.

Reviews (6) · Last reviewed commit: "chore: retrigger CI after Windows late-m..." · Reviewed by Greptile

PipeWire cursor metadata carries position and appearance, not buttons.
Read pointer buttons from the session input nodes and store the clicks
with the cursor events auto zoom already reads.
@kyzer1023

Copy link
Copy Markdown
Contributor Author

@greptileai

@vercel

vercel Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@kyzer1023 is attempting to deploy a commit to the Cap Software Inc Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread crates/recording/src/cursor.rs Outdated
Comment on lines +754 to +756
match stop_wakeup_rx.recv_timeout(Duration::from_millis(16)) {
Ok(()) | Err(RecvTimeoutError::Disconnected) => break,
Err(RecvTimeoutError::Timeout) => continue,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Recordings lose the pointer

If /dev/input is unreadable, every timeout runs continue, so the recorder never reads the PipeWire cursor feed. With custom cursor capture enabled, the portal now supplies video without an embedded pointer. These recordings therefore lose the pointer entirely, not just clicks. After waiting, use an empty click list and still process cursor metadata.

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/recording/src/cursor.rs
Line: 754-756

Comment:
**Recordings lose the pointer**

If `/dev/input` is unreadable, every timeout runs `continue`, so the recorder never reads the PipeWire cursor feed. With custom cursor capture enabled, the portal now supplies video without an embedded pointer. These recordings therefore lose the pointer entirely, not just clicks. After waiting, use an empty click list and still process cursor metadata.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a33db884. When the click source is empty, the tick no longer skips the PipeWire cursor sample after waiting—it records the cursor position with an empty click list. Covered by pipewire_cursor_moves_are_written_without_a_click_source.

Comment thread crates/recording/src/wayland_pointer.rs Outdated
self.kept.extend_from_slice(changes);
None
}
PointerPlace::Hidden | PointerPlace::Outside => None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Pointer stays after leaving

Dropping Hidden and Outside without writing a move leaves playback at the last visible position. After the pointer leaves a recorded area, the editor keeps drawing it inside that area until another move arrives. Save a visibility change or an off-screen position, and restore the pointer when it returns.

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/recording/src/wayland_pointer.rs
Line: 283

Comment:
**Pointer stays after leaving**

Dropping `Hidden` and `Outside` without writing a move leaves playback at the last visible position. After the pointer leaves a recorded area, the editor keeps drawing it inside that area until another move arrives. Save a visibility change or an off-screen position, and restore the pointer when it returns.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a33db884. Hidden and Outside pointer states now write one off-frame move ((-1, -1) when hidden without coordinates, or the actual out-of-bounds normalized coordinates when outside) and emit the next visible move even if it matches the previous visible point, while continuing to suppress clicks and duplicate hidden/outside moves. Covered by the_pointer_leaves_the_card_and_comes_back.

Comment thread crates/recording/src/wayland_pointer.rs Outdated
Comment on lines +316 to +325
if let Ok(entries) = std::fs::read_dir("/dev/input") {
for entry in entries.flatten() {
let name = entry.file_name();
let Some(name) = name.to_str() else {
continue;
};
if is_event_node(name) {
nodes.push(entry.path());
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Reconnected mouse clicks vanish

ClickSource scans input devices only at startup. A mouse connected or reconnected during recording is never added, although disconnected readers are removed. This silently loses clicks for the rest of the segment, so later clicks cannot trigger automatic zoom. Watch for new devices or periodically reopen eligible input nodes.

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/recording/src/wayland_pointer.rs
Line: 316-325

Comment:
**Reconnected mouse clicks vanish**

`ClickSource` scans input devices only at startup. A mouse connected or reconnected during recording is never added, although disconnected readers are removed. This silently loses clicks for the rest of the segment, so later clicks cannot trigger automatic zoom. Watch for new devices or periodically reopen eligible input nodes.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a33db884. ClickSource now watches /dev/input via inotify and rescans at most once per second (and immediately after a node disconnects), skipping already-open paths and allowing disconnected paths to be re-adopted. Covered by a_reconnected_pointer_is_adopted_once.

An empty /dev/input wait used to skip the PipeWire cursor sample, so a
recording with custom cursor capture lost the pointer as well as the
clicks. Process that sample every tick. A hidden or out-of-frame pointer
now writes one off-frame move, the same kind of coordinate the X11 window
recorder stores, and the next visible position brings it back. Pointer
nodes that appear after the recording starts are opened on inotify or on
a one-second rescan, without reopening nodes that are already held.
@kyzer1023

Copy link
Copy Markdown
Contributor Author

@greptileai

kyzer1023 added a commit to kyzer1023/Cap that referenced this pull request Nov 23, 2026

This branch has not been deployed

No deployments
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