Skip to content

fix(cua-driver/linux): get_desktop_state screen size on pure Wayland#2047

Merged
f-trycua merged 1 commit into
mainfrom
fix/linux-desktop-state-wayland-screensize
Jun 26, 2026
Merged

fix(cua-driver/linux): get_desktop_state screen size on pure Wayland#2047
f-trycua merged 1 commit into
mainfrom
fix/linux-desktop-state-wayland-screensize

Conversation

@f-trycua

@f-trycua f-trycua commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Problem

On a pure-Wayland session (Sway, no Xwayland), get_desktop_state fails with Capture error: … $DISPLAY variable not set … — surfaced on the Sway test VM during the overnight harness sweep.

Root cause

The full-display capture already routes correctly through the wlroots zwlr_screencopy cascade on Wayland. The bug is the line right after it:

let (screen_w, screen_h) = x11_screen_size()?;   // unconditional X11 connect

x11_screen_size() opens an X11 connection to read the root-window geometry. With no DISPLAY, x11rb returns "$DISPLAY variable not set" and the ? aborts the whole tool — even though the screenshot already succeeded via screencopy.

Fix

On Wayland the screencopy full-display buffer is the entire output at native physical pixels, so reuse the already-decoded PNG dimensions for the screen size; fall back to x11_screen_size() only off Wayland. X11 / XWayland path unchanged (gated by crate::wayland::is_wayland(), which requires CUA_DRIVER_RS_ENABLE_WAYLAND=1 + WAYLAND_DISPLAY set + DISPLAY unset).

One-line behavioral change + a comment; no new deps, no schema change.

Verification

  • Linux compile via CI on this PR.
  • Behavior on the Sway VM: get_desktop_state with CUA_DRIVER_RS_ENABLE_WAYLAND=1 (DISPLAY unset) returns a PNG + non-zero screen_width/height instead of the $DISPLAY error. (Verifying now.)
  • Regression: off Wayland (X11/XWayland, DISPLAY=:0) still reports X11 root geometry unchanged.

Follow-up (not in this PR)

get_screen_size has the same unconditional x11_screen_size() call and will fail identically on pure Wayland — but it has no prior capture to borrow dims from, so it needs a real Wayland output-dimensions source. Tracked for a separate change.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved desktop screenshot size detection on Linux, especially in Wayland sessions.
    • Screenshots now report the correct screen dimensions even when X11 display information is unavailable.
    • Existing behavior remains unchanged on non-Wayland setups.

get_desktop_state's full-display capture already routes through the wlroots
zwlr_screencopy cascade on Wayland, but the line right after it queried the
screen size via x11_screen_size() unconditionally — which opens an X11
connection and fails with "$DISPLAY variable not set" on a pure-Wayland
session (no Xwayland), aborting the whole tool even though the screenshot
already succeeded. Surfaced on the Sway test VM during the overnight harness sweep.

On Wayland the screencopy full-display buffer IS the whole output at native
physical pixels, so reuse the already-decoded PNG dimensions for screen size;
fall back to x11_screen_size() only off Wayland — X11/XWayland path unchanged.

(Note: get_screen_size has the same latent unconditional x11_screen_size() call;
left for a follow-up since it has no prior capture to borrow dims from.)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Jun 26, 2026 6:15pm

Request Review

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d3af8a42-9148-4af1-b43a-71419ae08fa2

📥 Commits

Reviewing files that changed from the base of the PR and between f2e7ceb and 7494d13.

📒 Files selected for processing (1)
  • libs/cua-driver/rust/crates/platform-linux/src/tools/impl_.rs

📝 Walkthrough

Walkthrough

GetDesktopStateTool now derives screen dimensions from the captured screenshot on Wayland and keeps the existing X11-based size lookup on other platforms.

Changes

Wayland desktop size handling

Layer / File(s) Summary
Wayland and X11 size selection
libs/cua-driver/rust/crates/platform-linux/src/tools/impl_.rs
GetDesktopStateTool::invoke uses the screenshot PNG width and height as the screen size on Wayland, and continues to call x11_screen_size() otherwise.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • trycua/cua#1935: Also changes Wayland/X11 behavior in platform-linux, affecting the same branching logic used by desktop-state sizing.

Poem

Hoppity hop, I leapt so bright,
On Wayland, pixels guide my sight.
X11 still hums its old refrain,
A neat screen size without the pain.
🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: get_desktop_state screen sizing for pure Wayland on Linux.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/linux-desktop-state-wayland-screensize

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@f-trycua f-trycua merged commit 6b2b262 into main Jun 26, 2026
69 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Linux visual regression artifacts

Matrix jobs now run independently. Download visual artifacts from this workflow run.
Each background-GUI job uploads a .gif of the interaction plus two annotated PNGs (<app>.png raw, <app>-atspi.png with AT-SPI element boxes); the cua-driver-linux-som-overlays artifact adds <app>-som.png cua Set-of-Marks overlays:

  • cua-driver-linux-cursor-click-gif
  • cua-driver-linux-background-terminal-gif
  • cua-driver-linux-parallel-drag-xserver
  • cua-driver-linux-background-gui-chromium
  • cua-driver-linux-background-gui-tk
  • cua-driver-linux-background-gui-gtk3-gedit
  • cua-driver-linux-background-gui-gtk3-mousepad
  • cua-driver-linux-background-gui-gtk3-scite
  • cua-driver-linux-background-gui-gtk4-characters
  • cua-driver-linux-background-gui-qt5-manuskript
  • cua-driver-linux-background-gui-qt5-klog
  • cua-driver-linux-background-gui-qt5-openambit
  • cua-driver-linux-background-gui-qt6-kate
  • cua-driver-linux-background-gui-qt6-kcalc
  • cua-driver-linux-background-gui-qt6-okular
  • cua-driver-linux-background-gui-qt6-qownnotes
  • cua-driver-linux-background-gui-electron-zettlr
  • cua-driver-linux-background-gui-electron-joplin
  • cua-driver-linux-background-gui-electron-logseq
  • cua-driver-linux-som-overlays

Open workflow run and download artifacts

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