fix(compositor): keep the stacking order through layout changes

Laying windows out re-mapped every application window, which smithay
puts on top, so a session mapping another window, an exclusive zone
change or an output resize pushed the shell's home back under the
applications while it kept keyboard focus. Placement now re-maps every
window in its current order. Panels are lowered only when they
register, and a window that maps without taking focus goes beneath the
window in front, so a session cannot cover the shell's home or another
application by creating windows. A panel's zweft window that is
destroyed while its surface lives also removes its window slot.
This commit is contained in:
Marco Allegretti 2026-10-09 16:11:20 +00:00
parent 8399914dfa
commit cdc4a9e15d
No known key found for this signature in database
6 changed files with 57 additions and 65 deletions

View file

@ -550,7 +550,7 @@ fn connector_connected(
tracing::info!(?name, "output connected");
let (pw, ph) = (wl_mode.size.w, wl_mode.size.h);
state.weft_shell_state.reconfigure_panels(0, 0, pw, ph);
state.fit_panels();
state.layout_app_windows();
state.weft_shell_state.retain_alive_panels();
render_output(state, node, crtc);
}
@ -579,7 +579,7 @@ fn connector_disconnected(
.map(|g| (g.size.w, g.size.h))
.unwrap_or((0, 0));
state.weft_shell_state.reconfigure_panels(0, 0, pw, ph);
state.fit_panels();
state.layout_app_windows();
state.weft_shell_state.retain_alive_panels();
}

View file

@ -124,7 +124,7 @@ pub fn run() -> anyhow::Result<()> {
state
.weft_shell_state
.reconfigure_panels(0, 0, size.w, size.h);
state.fit_panels();
state.layout_app_windows();
state.weft_shell_state.retain_alive_panels();
}
WinitEvent::Input(input_event) => {

View file

@ -657,11 +657,15 @@ impl Dispatch<ZweftShellWindowV1, WeftShellWindowData> for WeftCompositorState {
state: &mut Self,
_client: wayland_server::backend::ClientId,
resource: &ZweftShellWindowV1,
_data: &WeftShellWindowData,
data: &WeftShellWindowData,
) {
// A panel that goes away, by destroy or with its client, releases
// its reserved strip; applications take the space back.
// its reserved strip and its window slot; applications take the
// space back.
if state.weft_shell_state.remove_panel(resource) {
if let Some(surface) = &data.surface {
state.window_closed(surface);
}
state.layout_app_windows();
}
}

View file

@ -6,8 +6,10 @@
//! panel reserves. A session's first window, a clicked window (the panel
//! included, which then shows the shell's home over the applications) and
//! one appd asks to activate is raised to the top, marked activated and
//! given keyboard focus. When the focused window closes, the topmost
//! remaining application window gets focus.
//! given keyboard focus; nothing else changes the order, and a window that
//! maps without taking focus goes beneath the window in front. When the
//! focused window closes, the topmost remaining application window gets
//! focus.
use smithay::desktop::Window;
use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
@ -73,10 +75,19 @@ impl WeftCompositorState {
}
}
/// Sizes the panels to the output, places them at its origin and keeps
/// them beneath every application window.
/// Sizes the panels to the output and keeps them beneath every
/// application window; used when a panel registers.
pub fn fit_panels(&mut self) {
let Some(geometry) = self
self.place_windows(true, None);
}
/// Places every window for the current output and reservations: panels
/// fill the output, application windows the work area. The stacking
/// order is kept, except that `lower_panels` moves the panels beneath
/// the applications, and `below_top` slips that window under the
/// window that was on top.
pub fn place_windows(&mut self, lower_panels: bool, below_top: Option<&Window>) {
let Some(output) = self
.space
.outputs()
.next()
@ -84,42 +95,36 @@ impl WeftCompositorState {
else {
return;
};
let panels: Vec<Window> = self
.space
.elements()
.filter(|window| self.is_panel(window))
.cloned()
.collect();
if panels.is_empty() {
let Some(area) = self.work_area() else {
return;
};
let mut order: Vec<Window> = self.space.elements().cloned().collect();
if lower_panels {
let (panels, apps): (Vec<Window>, Vec<Window>) =
order.into_iter().partition(|window| self.is_panel(window));
order = panels.into_iter().chain(apps).collect();
}
for panel in &panels {
if let Some(toplevel) = panel.toplevel() {
if let Some(window) = below_top
&& let Some(position) = order.iter().position(|w| w == window)
&& position + 1 == order.len()
&& order.len() > 1
{
order.swap(position, position - 1);
}
for window in &order {
let panel = self.is_panel(window);
let geometry = if panel { output } else { area };
if let Some(toplevel) = window.toplevel() {
toplevel.with_pending_state(|state| {
state.size = Some(geometry.size);
state.states.set(xdg_toplevel::State::Maximized);
});
toplevel.send_pending_configure();
tracing::debug!(
width = geometry.size.w,
height = geometry.size.h,
"panel fitted to the output"
);
}
self.space.map_element(panel.clone(), geometry.loc, false);
// Mapping puts a window on top; mapping all of them in `order`
// leaves exactly that order.
self.space.map_element(window.clone(), geometry.loc, false);
}
// Raising every other window, in its current order, leaves the
// panels at the bottom.
let others: Vec<Window> = self
.space
.elements()
.filter(|window| !self.is_panel(window))
.cloned()
.collect();
for window in &others {
self.space.raise_element(window, false);
}
self.layout_app_windows();
}
/// Maps a new toplevel. The first window a session maps in its lifetime
@ -144,11 +149,13 @@ impl WeftCompositorState {
self.space.map_element(window.clone(), (0, 0), false);
if self.is_panel(&window) {
self.fit_panels();
} else {
} else if first {
self.layout_app_windows();
if first {
self.activate_window(&window);
}
self.activate_window(&window);
} else {
// A window that does not take focus does not cover the window
// in front either, the shell's home included.
self.place_windows(false, Some(&window));
}
}
@ -244,29 +251,10 @@ impl WeftCompositorState {
.map_or((0, 0, 0, 0), |a| (a.loc.x, a.loc.y, a.size.w, a.size.h))
}
/// Places every application window to fill the work area, so none
/// covers the panel's reserved strips.
/// Lays the windows out again after the work area changed, keeping the
/// stacking order.
pub fn layout_app_windows(&mut self) {
let Some(area) = self.work_area() else {
return;
};
let apps: Vec<Window> = self
.space
.elements()
.filter(|window| !self.is_panel(window))
.cloned()
.collect();
for window in apps {
if let Some(toplevel) = window.toplevel() {
toplevel.with_pending_state(|state| {
state.size = Some(area.size);
state.states.set(xdg_toplevel::State::Maximized);
});
toplevel.send_pending_configure();
}
// Re-mapped in stacking order, so the order is kept.
self.space.map_element(window.clone(), area.loc, false);
}
self.place_windows(false, None);
}
/// Sends the configure for every toplevel whose pending state changed,

View file

@ -8,7 +8,7 @@ WEFT OS is a Wayland compositor and application runtime where every app is a Web
### weft-compositor
Smithay-based Wayland compositor. Implements the `zweft-shell-unstable-v1` protocol extension, which allows shell clients (servo-shell, app-shell) to register their surfaces as typed shell slots. Each application session's Wayland connection is handed to the compositor by weft-appd, which binds the client to that session (see `security.md`). The compositor owns stacking and focus: the system shell's panel is sized to the output and starts beneath application windows, and clicking it brings it to the front as the shell's home, with its launcher, until an application is activated; a session's first window, a clicked window and an activated one are raised, marked activated and given keyboard focus, and when the focused window closes the topmost remaining application window gets focus. A session's later windows are shown without taking focus. The panel reserves a strip along an output edge for the taskbar with `set_exclusive_zone` (weft-servo-shell reserves 48 logical pixels at the bottom), and the compositor lays every application window out to fill the remaining work area. weft-appd's `ACTIVATE_APP` request, which the taskbar sends, asks the compositor to activate a running session's window. Supports DRM/KMS and winit (software/dev) backends.
Smithay-based Wayland compositor. Implements the `zweft-shell-unstable-v1` protocol extension, which allows shell clients (servo-shell, app-shell) to register their surfaces as typed shell slots. Each application session's Wayland connection is handed to the compositor by weft-appd, which binds the client to that session (see `security.md`). The compositor owns stacking and focus: the system shell's panel is sized to the output and starts beneath application windows, and clicking it brings it to the front as the shell's home, with its launcher, until an application is activated or opens its first window; layout changes keep the stacking order, and a window that maps without taking focus goes beneath the window in front; a session's first window, a clicked window and an activated one are raised, marked activated and given keyboard focus, and when the focused window closes the topmost remaining application window gets focus. A session's later windows are shown without taking focus. The panel reserves a strip along an output edge for the taskbar with `set_exclusive_zone` (weft-servo-shell reserves 48 logical pixels at the bottom), and the compositor lays every application window out to fill the remaining work area. weft-appd's `ACTIVATE_APP` request, which the taskbar sends, asks the compositor to activate a running session's window. Supports DRM/KMS and winit (software/dev) backends.
### weft-servo-shell

View file

@ -6,7 +6,7 @@ panel, and weft-appd with two test applications, one red and one blue, on a
nested desktop (see session.py). Each application page switches between its
colour and a lighter shade on every key press. In the presented pixels:
- the panel fills the compositor output and stays beneath the applications;
- the panel fills the compositor output and starts beneath the applications;
- application windows fill the work area: the output less the strip the
shell reserves for its taskbar along the bottom, which stays visible;
- each newly launched application is shown on top and receives keys;