Skip to content

fix(wayland): explicitly restack XWayland surfaces in WaylandState::restack#247

Merged
paperbenni merged 2 commits intomainfrom
fix-xwayland-restack-monocle-17793732228212661052
Mar 23, 2026
Merged

fix(wayland): explicitly restack XWayland surfaces in WaylandState::restack#247
paperbenni merged 2 commits intomainfrom
fix-xwayland-restack-monocle-17793732228212661052

Conversation

@paperbenni
Copy link
Copy Markdown
Member

@paperbenni paperbenni commented Mar 22, 2026

This commit fixes an issue where switching focus (e.g. super j/super k) in a monocle layout under Wayland would sometimes fail to visually raise the focused window. The problem was caused by a missing explicit X11 restack call for XWayland surfaces inside WaylandState::restack, which allowed the embedded X server to keep compositing windows with an outdated stacking order.


PR created automatically by Jules for task 17793732228212661052 started by @paperbenni

Summary by Sourcery

Bug Fixes:

  • Fix XWayland windows sometimes not visually raising when focus changes in monocle layouts under Wayland.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling and logging for window management operations, providing better visibility into issues when they occur.
    • Enhanced window compatibility by ensuring X11 windows are properly synchronized with Wayland window stacking operations.

Added `xwm.raise_window(surface)` inside `WaylandState::restack` to ensure that XWayland windows visually update their Z-order when focus changes occur in layouts like monocle. Without this, Smithay would internally reorder the surfaces but X11 clients would continue compositing their buffers based on stale X11 stacking orders.

Co-authored-by: paperbenni <15818888+paperbenni@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Mar 22, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds an explicit XWayland/X11 restack when raising elements in WaylandState::restack so that XWayland windows visually reflect focus changes, particularly in monocle layouts.

Sequence diagram for WaylandState restack with explicit XWayland restack

sequenceDiagram
    actor User
    participant Compositor
    participant WaylandState
    participant Space
    participant Element
    participant Xwm

    User->>Compositor: request_focus_change(target_window)
    Compositor->>WaylandState: restack()

    loop for_each_element_in_new_stack
        WaylandState->>Space: raise_element(element, false)
        activate Element
        WaylandState->>Element: x11_surface()
        alt element_has_x11_surface_and_xwm_present
            Element-->>WaylandState: X11Surface
            WaylandState->>Xwm: raise_window(X11Surface)
            Xwm-->>WaylandState: result
        else
            Element-->>WaylandState: None
        end
        deactivate Element
    end

    WaylandState->>Xwm: raise_unmanaged_x11_windows()
    Xwm-->>WaylandState: done
    WaylandState-->>Compositor: restack_complete
    Compositor-->>User: focused_window_visually_raised
Loading

Class diagram for updated WaylandState restack XWayland integration

classDiagram
    class WaylandState {
        +Space space
        +Option_Xwm xwm
        +restack()
        +raise_unmanaged_x11_windows()
    }

    class Space {
        +raise_element(element, activate)
    }

    class Element {
        +x11_surface() Option_X11Surface
    }

    class Xwm {
        +raise_window(surface)
        +raise_unmanaged_x11_windows()
    }

    class Option_Xwm
    class Option_X11Surface
    class X11Surface

    WaylandState --> Space : has
    WaylandState --> Option_Xwm : has
    Space --> Element : manages
    Element --> Option_X11Surface : may_expose
    Option_X11Surface --> X11Surface : wraps
    Option_Xwm --> Xwm : wraps
    WaylandState ..> Xwm : uses_raise_window
    WaylandState ..> Element : iterates_in_restack
    WaylandState ..> X11Surface : passes_to_raise_window
Loading

File-Level Changes

Change Details Files
Ensure XWayland (X11) windows are explicitly restacked when a Wayland element is raised so their visual stacking matches focus changes.
  • Extend WaylandState::restack to, after raising a window element in the space, check whether the element has an associated X11 surface and the compositor has an active XWayland window manager.
  • Invoke the XWayland window manager’s raise_window on the X11 surface, ignoring any error result, to synchronize X11 stacking with Wayland stacking.
  • Keep the existing call to raise_unmanaged_x11_windows so unmanaged X11 windows are still handled after managed ones are restacked.
src/backend/wayland/compositor/window/management.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 22, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cd05f6df-83ad-46d1-8e58-78a97b22295e

📥 Commits

Reviewing files that changed from the base of the PR and between 96b88c8 and d4d79b6.

📒 Files selected for processing (1)
  • src/backend/wayland/compositor/window/management.rs

📝 Walkthrough

Walkthrough

The pull request enhances error handling in Wayland window management functions. WaylandState::raise_window now logs warnings when xwm.raise_window(surface) fails, and WaylandState::restack explicitly restacks associated XWayland/X11 surfaces after raising Wayland elements, with similar error logging added.

Changes

Cohort / File(s) Summary
Error Handling & XWayland Surface Management
src/backend/wayland/compositor/window/management.rs
Modified raise_window and restack methods to handle and log errors from XWayland surface operations; restack now explicitly calls xwm.raise_window(surface) for associated X11 surfaces with error reporting.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through windows wide,
Now errors caught, no more they hide!
With XWayland surfaces in place,
Management flows with gentle grace! ✨

✨ 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-xwayland-restack-monocle-17793732228212661052

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 and usage tips.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Right now the result of xwm.raise_window(surface) is silently ignored; consider at least logging failures so unexpected XWayland restack errors can be diagnosed if the visual stacking issue reappears.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Right now the result of `xwm.raise_window(surface)` is silently ignored; consider at least logging failures so unexpected XWayland restack errors can be diagnosed if the visual stacking issue reappears.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@paperbenni
Copy link
Copy Markdown
Member Author

@jules
Please address the comments from this code review:

Overall Comments

  • Right now the result of xwm.raise_window(surface) is silently ignored; consider at least logging failures so unexpected XWayland restack errors can be diagnosed if the visual stacking issue reappears.

@google-labs-jules
Copy link
Copy Markdown
Contributor

@jules
Please address the comments from this code review:

Overall Comments

  • Right now the result of xwm.raise_window(surface) is silently ignored; consider at least logging failures so unexpected XWayland restack errors can be diagnosed if the visual stacking issue reappears.

Good point. I have updated the restack method to properly log any errors returned by xwm.raise_window(surface). This will ensure unexpected failures are visible for debugging. Submitting the updated code now.

Updated `WaylandState::restack` to explicitly restack X11 surfaces via `xwm.raise_window(surface)`. Also added error logging when this restack request fails, which will assist with diagnosing any future XWayland depth/stacking-related visual bugs in overlapping or monocle layouts.

Co-authored-by: paperbenni <15818888+paperbenni@users.noreply.github.com>
@paperbenni paperbenni merged commit 037990c into main Mar 23, 2026
2 of 5 checks passed
@paperbenni paperbenni deleted the fix-xwayland-restack-monocle-17793732228212661052 branch March 23, 2026 12:39
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