Skip to content

Wayland: emit Occluded for the xdg-shell suspended state - #4709

Open
crmne wants to merge 1 commit into
rust-windowing:masterfrom
crmne:wayland-suspended-occluded-master
Open

crmne wants to merge 1 commit into
rust-windowing:masterfrom
crmne:wayland-suspended-occluded-master

Conversation

@crmne

@crmne crmne commented Sep 23, 2026 •

Copy link
Copy Markdown

On Wayland, a compositor stops sending frame callbacks to a window it has suspended (xdg-shell v6 suspended), for example when the window is on a hidden workspace or the outputs are off. Applications have no way to know: winit stopped reporting this state as WindowEvent::Occluded in #3441.

This emits Occluded(true) and Occluded(false) again when the suspended state is added or removed. Nothing else changes: every configure, including the suspending one, still asks for a redraw, and winit never commits on the application's behalf. An earlier version of this PR let the app ask winit to commit while it wasn't presenting; that was dropped after review.

The Occluded docs now cover Wayland: what suspended means, that the suspending configure still has to be committed by the app, and that pre_present_notify keeps a suspended window from blocking in a vsync present.

The earlier version was tested on Hyprland 0.56.2 and headless Jay (Occluded(true) on moving the window to a hidden workspace, Occluded(false) on its return); this cut-down version keeps that event path unchanged and passes the Wayland clippy and tests. Sway doesn't send suspended, and compositors older than xdg_wm_base v6 never do, so nothing changes there.

  • Tested on all platforms changed (Wayland)
  • Added an entry to the changelog module if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality

@kchibisov kchibisov left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if you look at the reason why the original patch got reverted you'll see that your patch may not work on some compositors.

@crmne

crmne commented Sep 23, 2026

Copy link
Copy Markdown
Author

Thanks. I read #3441, #3442 and ff73119. If I understand the concern: the configure that adds suspended is only acknowledged by the first commit after the window is shown again. So a compositor that waits for that commit before it sends the configure removing suspended, or before it resumes frame callbacks, would never unsuspend the window. I only tested on Hyprland, which doesn't wait. Is that the failure you mean, and do you know which compositors behave that way?

If so, I can rework this along the lines you proposed in #3442: the application tells winit it has stopped presenting (for example, a window method called after handling Occluded(true)), and winit then acks and commits the pending configure on its behalf. Would that shape work for you?

@mahkoh

mahkoh commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

I only tested on Hyprland, which doesn't wait.

Hyprland doesn't implement transactional configure sequences. It cannot be used to test anything related to configure sequences since it doesn't operate under the same constraints as other compositors.

So a compositor that waits for that commit before it sends the configure removing suspended, or before it resumes frame callbacks, would never unsuspend the window.

Most compositors use a short timeout, say 200 milliseconds. So this would show up as a stutter instead of permanently blocking subsequent configuration sequences.

@crmne

crmne commented Sep 23, 2026

Copy link
Copy Markdown
Author

Thanks, both. I tested this on compositors with transactional configure sequences and on ones that send suspended, all headless:

  • Jay (master, run): sends suspended and uses transactions, but hidden windows are exempt from them. No configure or transaction timeouts with this patch.
  • sway 1.12 (run): uses transactions (200 ms) but never sends suspended, so the patch changes nothing there.
  • cosmic-comp (source): only sends suspended for inactive stack tabs, which its TilingBlocker doesn't wait on.
  • KWin, mutter, Hyprland (source): send suspended but don't wait on clients across windows.

To model the case you describe, I changed Jay to also wait on hidden windows (200 ms timeout). There the patch caused one timeout-long stall, about 200 ms, each time a window was hidden, and no permanent block. Stock winit avoids that stall only because the app keeps drawing once and then freezes on vsync for as long as the window is hidden.

A single empty commit from winit on the configure that leaves the window suspended removed every stall in that setup. sctk already acks each configure, so the commit is the only missing piece. A commit from winit is only safe while the app isn't presenting, though, so I'd follow the shape from #3442: a window method the app calls after handling Occluded(true) to say it has stopped presenting. Winit then commits for the pending and any later suspended configures, and asks for a redraw when the window is unsuspended, as now. I'll push that unless you'd prefer another shape.

@crmne
crmne force-pushed the wayland-suspended-occluded-master branch from 9d2015f to a68ac90 Compare September 25, 2026 08:59
@crmne

crmne commented Sep 25, 2026

Copy link
Copy Markdown
Author

I pushed the shape from my last comment.

  • WindowExtWayland::notify_presentation_paused(): the app calls it once it has stopped presenting after Occluded(true). Winit then commits the surface right away (sctk has already acked the configure), and again after every later configure while the window stays suspended, without asking for a redraw. The configure that removes suspended emits Occluded(false) and asks for a redraw as before. The next suspension needs a new call.
  • An app that never calls it behaves as it does today: every configure, including the suspending one, asks for a redraw. The only difference it sees is the Occluded events.
  • If the integer buffer scale changed after the call, winit doesn't commit, since set_buffer_scale would then apply to the old buffer.
  • The app may keep presenting at a low rate while occluded, as long as the present can't block (swap interval 0 or mailbox) and it doesn't call pre_present_notify for those frames. The docs say so.

Testing used a small softbuffer probe that hides its window three times per run. On headless Jay, I kept hidden windows in transactions as before, with the stock 50 ms timeout:

  • Calls the method: no transaction or configure timeouts. The commit goes out right after the ack, in the same dispatch.
  • Stops presenting without calling it: one timeout per hide.
  • Keeps presenting on every redraw: no timeouts, and the same redraw and paint counts as stock v0.30.x.
  • Calls it and keeps presenting every 400 ms: no timeouts.

On Hyprland 0.56.2 (headless output, window moved to a special workspace and back), the events and commits were as expected. The 0.30 backport (#4710) gave the same results.

@mahkoh, a side note: Jay's headless backend never clears backend_idle, so every window there is suspended from the moment it maps. I patched that locally for these tests.

The name is open. I can also move it to the core Window trait if you'd rather have it there.

crmne added a commit to crmne/zapfast that referenced this pull request Sep 25, 2026
Hyprland stops frame callbacks to a window covered by a fullscreen or
maximized one without marking it suspended, so a vsync swap blocked the
event loop until the compositor called ZapFast unresponsive (#190).

Pin the shared forks: crmne/egui apps-0.36 presents without a blocking
swap on Wayland, paces frames by frame callbacks, and runs only the app
logic when a redraw is 250 ms overdue (emilk/egui#8631); crmne/winit
apps-0.30 reports suspended as Occluded and commits on the app's behalf
(rust-windowing/winit#4709). vsync.rs's compositor check goes: vsync is
requested everywhere and eframe handles Wayland.

Fixes #190
crmne added a commit to crmne/chatwithwork-desktop that referenced this pull request Sep 25, 2026
Hyprland sends no frame callbacks to a window covered by a fullscreen or
maximized one, on a hidden workspace, or with the display off, so a
vsync swap blocked the event loop the tray shares and the compositor
called the app unresponsive.

Pin the forks ZapFast, Spotifast, RekordFlash and TonePush share:
crmne/egui apps-0.36 paces Wayland frames by frame callbacks
(emilk/egui#8631) and crmne/winit apps-0.30 reports suspended as
Occluded (rust-windowing/winit#4709). egui_kittest comes from the same
revision so the tests share one egui.
Comment thread winit-wayland/src/window/state.rs Outdated
return false;
}

self.window.wl_surface().commit();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

winit should never commit on behalf of the user when there's a possibility of user rendering, which there's, so such approach doesn't work.

What works, perhaps, is once you get Suspended, do RequestRedraw and after that request submit Occluded, so the event is kind of delayed with the hope that user redrawn because they got asked to do so, so delivering Occluded would be once we know that user kind-of committed the occluded state.

crmne added a commit to crmne/chatwithwork-desktop that referenced this pull request Sep 25, 2026
Hyprland sends no frame callbacks to a window covered by a fullscreen or
maximized one, on a hidden workspace, or with the display off, so a
vsync swap blocked the event loop the tray shares and the compositor
called the app unresponsive.

Pin the forks ZapFast, Spotifast, RekordFlash and TonePush share:
crmne/egui apps-0.36 paces Wayland frames by frame callbacks
(emilk/egui#8631) and crmne/winit apps-0.30 reports suspended as
Occluded (rust-windowing/winit#4709). egui_kittest comes from the same
revision so the tests share one egui.
crmne added a commit to crmne/chatwithwork-desktop that referenced this pull request Sep 25, 2026
Hyprland sends no frame callbacks to a window covered by a fullscreen or
maximized one, on a hidden workspace, or with the display off, so a
vsync swap blocked the event loop the tray shares and the compositor
called the app unresponsive.

Pin the forks ZapFast, Spotifast, RekordFlash and TonePush share:
crmne/egui apps-0.36 paces Wayland frames by frame callbacks
(emilk/egui#8631) and crmne/winit apps-0.30 reports suspended as
Occluded (rust-windowing/winit#4709). egui_kittest comes from the same
revision so the tests share one egui.
@crmne

crmne commented Sep 26, 2026

Copy link
Copy Markdown
Author

Thanks, understood about not committing on the user's behalf. I tested the redraw-then-Occluded flow for the case I care about, the Hyprland "not responding" dialog, and neither design fixes it. With Mesa EGL and FIFO, an app that doesn't call pre_present_notify blocks in the in-flight present before winit even reads the suspending configure. An app that does call it never blocks, because winit holds RedrawRequested until the frame callback arrives. That hold also stops the post-configure redraw while the window is hidden, so with your flow those apps wouldn't get Occluded(true) until the window was shown again.

So the dialog is the app's job (pre_present_notify, or a non-FIFO present mode), not winit's. If Occluded for suspended is still useful to you, I can cut this down to emitting it immediately, with no commits from winit. Otherwise I'm happy to close it.

lucasmerlin added a commit to emilk/egui that referenced this pull request Oct 6, 2026
* Part of #5136
* Closes #8414

On Wayland a compositor may stop sending frame callbacks to a window it
isn't showing, without telling the client that the window is occluded.
Hyprland does this when another window on the same workspace goes
fullscreen or maximized. With the glow backend, eframe then blocks in a
vsync `eglSwapBuffers` until the window is shown again. Nothing runs,
pings go unanswered, and the compositor reports the app as not
responding. With wgpu, `pre_present_notify` keeps eframe from blocking,
but `RedrawRequested` never arrives, so `App::logic` stops running.

In rust-windowing/winit#4668 the winit maintainers said that winit
should keep holding `RedrawRequested` until the frame callback arrives,
and that a timeout belongs in the toolkit. This PR adds that timeout:

* glow calls `Window::pre_present_notify` before swapping, like
egui-wgpu already does, so winit paces `RedrawRequested` by frame
callbacks.
* On Wayland, glow swaps with interval 0. The frame callbacks already
pace it. With the NVIDIA driver (egl-wayland2), a vsync swap also blocks
forever for a window that starts on a hidden workspace: the compositor
sends a frame callback for the first buffer but never presents it, and
the next swap waits for that buffer.
* If a `RedrawRequested` we asked for hasn't arrived within 250 ms,
eframe runs `App::logic` without an egui pass, the same as for other
hidden windows. Once the compositor sends a frame callback again, the
window paints normally.

`glow_options.vsync` therefore has no effect on Wayland. That's what
vsync means there anyway, and the docs now say so.

## Testing

I tested with a small probe that calls `request_repaint` on every
`App::logic` call and counts `logic` and `ui` calls. It ran on Hyprland
0.56.2 with NVIDIA and a headless output, and I counted pings and pongs
with `WAYLAND_DEBUG=1`. Each phase lasted 10 s:

| Scenario | Before | After |
| --- | --- | --- |
| Visible (glow and wgpu) | 60 fps | 60 fps |
| Covered by a fullscreen window, glow | blocked in `eglSwapBuffers`, 0
pings answered | about 4 `logic`/s, no paints, all pings answered |
| Covered by a maximized window, glow | same (Hyprland stops the
callbacks) | same as above |
| Covered, wgpu | responsive, but 0 `logic` calls | about 4 `logic`/s |
| Window on a hidden workspace | glow blocks | about 4 `logic`/s, all
pings answered |
| Started on a hidden workspace, glow | blocked on the second swap |
about 4 `logic`/s, all pings answered |
| Shown again | resumes | resumes on the next frame callback |
| Idle | 0 CPU | 0 CPU |

X11 and other platforms: I only checked that they compile. Nothing
changes there except that `run_logic` may run if a `RedrawRequested`
takes more than 250 ms to arrive, which only calls `App::logic` one
extra time.

When winit reports `Occluded` on Wayland (rust-windowing/winit#4709),
eframe's existing occluded handling takes over for hidden workspaces.
This timeout still covers windows the compositor hides without
suspending them.

* [x] I have followed the instructions in the PR template

---------

Co-authored-by: Emil Ernerfeldt <[email protected]>
Co-authored-by: Lucas Meurer <[email protected]>
A compositor sends no frame callbacks to a surface it has suspended, for
example on a hidden workspace or while the outputs are off. Winit stopped
reporting this state as `WindowEvent::Occluded` in rust-windowing#3441, together with
the change that made the suspending configure ask for a redraw.

Emit `Occluded(true)` and `Occluded(false)` again when the `suspended`
state is added or removed. Winit still asks for a redraw after every
configure, including the suspending one, and never commits on the
application's behalf, so applications that ignore the event behave as
before.

Refs rust-windowing#3442
@crmne
crmne force-pushed the wayland-suspended-occluded-master branch from a68ac90 to c67526e Compare October 14, 2026 21:55
@crmne

crmne commented Oct 14, 2026

Copy link
Copy Markdown
Author

I cut this down as offered: winit now only emits Occluded(true) and Occluded(false) when the xdg-shell suspended state is added or removed. notify_presentation_paused is gone, winit never commits on the application's behalf, and every configure still asks for a redraw as before.

I emit the event as soon as the configure arrives rather than after the post-configure redraw. Apps that call pre_present_notify don't get that redraw while the window is suspended, because winit holds RedrawRequested until a frame callback that a suspended window never receives, so a delayed Occluded(true) would only reach them once the window was shown again. The Occluded docs note that the suspending configure still needs the app's commit and that compositors may wait for it up to a timeout. #4710 has the same change for 0.30.

GruperTal pushed a commit to GruperTal/egui that referenced this pull request Oct 20, 2026
eframe paints nothing while a window is occluded and only runs
`App::logic`. On Wayland, tell winit so through
`WindowExtWayland::notify_presentation_paused`, so it commits the
suspended window's configures itself instead of asking for a redraw
that would never be presented.

Needs the winit 0.30 backport of rust-windowing/winit#4709, patched in
from crmne/winit apps-0.30.
stergiotis added a commit to stergiotis/boxer that referenced this pull request Nov 8, 2026
zapfast, an MIT-licensed desktop client on the same egui as the imzero2
host, carries fixes found through its users' bug reports. The ADR takes
seven groups of them, records how a port is made (techniques reimplemented,
the failure reproduced in boxer first, notice given once and again where
code is close, egui/winit fixes taken from upstream rather than its forks)
and what stays out.

ADR-0332's O3 and the vendored winit's notes now name the upstream pull
requests (emilk/egui#8631, rust-windowing/winit#4709, #4710) that would let
the copy go.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
caue-r pushed a commit to caue-r/zapfast that referenced this pull request Nov 8, 2026
Hyprland stops frame callbacks to a window covered by a fullscreen or
maximized one without marking it suspended, so a vsync swap blocked the
event loop until the compositor called ZapFast unresponsive (crmne#190).

Pin the shared forks: crmne/egui apps-0.36 presents without a blocking
swap on Wayland, paces frames by frame callbacks, and runs only the app
logic when a redraw is 250 ms overdue (emilk/egui#8631); crmne/winit
apps-0.30 reports suspended as Occluded and commits on the app's behalf
(rust-windowing/winit#4709). vsync.rs's compositor check goes: vsync is
requested everywhere and eframe handles Wayland.

Fixes crmne#190
aleliras added a commit to aleliras/zapfast that referenced this pull request Nov 23, 2026
Hyprland stops frame callbacks to a window covered by a fullscreen or
maximized one without marking it suspended, so a vsync swap blocked the
event loop until the compositor called ZapFast unresponsive (crmne#190).

Pin the shared forks: crmne/egui apps-0.36 presents without a blocking
swap on Wayland, paces frames by frame callbacks, and runs only the app
logic when a redraw is 250 ms overdue (emilk/egui#8631); crmne/winit
apps-0.30 reports suspended as Occluded and commits on the app's behalf
(rust-windowing/winit#4709). vsync.rs's compositor check goes: vsync is
requested everywhere and eframe handles Wayland.

Fixes crmne#190

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

Development

Successfully merging this pull request may close these issues.

3 participants