fix(compositor): show the shell's home on a panel click and release a dead panel's strip

With applications filling the work area, the system UI's launcher, drawn
in the panel beneath them, could not be seen while any application was
open. Clicking the panel now brings it to the front as the shell's home
until an application is activated again.

A panel that is destroyed, or whose client goes away, releases its
reserved strip and the applications are laid out again; dead panels no
longer count toward the work area, so a restarted shell does not reserve
the strip twice. A work area is never configured with a zero size. The
zweft_shell configure for an application window, at creation and in
reply to set_geometry, reports the work area the layout gives it, and a
panel's reports the output.

check_activation.py now clicks the taskbar strip, requires the panel to
cover both applications, and activates one back.
This commit is contained in:
Marco Allegretti 2026-10-09 16:06:19 +00:00
parent 5253eaf251
commit 8399914dfa
No known key found for this signature in database
7 changed files with 110 additions and 35 deletions

View file

@ -54,6 +54,13 @@ impl WeftShellState {
self.panels.push(window); self.panels.push(window);
} }
/// Forgets a panel; returns whether it was one.
pub fn remove_panel(&mut self, window: &ZweftShellWindowV1) -> bool {
let before = self.panels.len();
self.panels.retain(|panel| panel != window);
self.panels.len() != before
}
pub fn reconfigure_panels(&self, x: i32, y: i32, width: i32, height: i32) { pub fn reconfigure_panels(&self, x: i32, y: i32, width: i32, height: i32) {
for panel in &self.panels { for panel in &self.panels {
if panel.is_alive() { if panel.is_alive() {

View file

@ -577,7 +577,11 @@ impl Dispatch<ZweftShellManagerV1, ()> for WeftCompositorState {
state.weft_shell_state.add_panel(window); state.weft_shell_state.add_panel(window);
state.fit_panels(); state.fit_panels();
} else { } else {
window.configure(x, y, width, height, 0); // The compositor decides application geometry: the work
// area, whatever was requested.
let _ = (x, y, width, height);
let (x, y, w, h) = state.app_geometry();
window.configure(x, y, w, h, 0);
} }
} }
} }
@ -606,13 +610,24 @@ impl Dispatch<ZweftShellWindowV1, WeftShellWindowData> for WeftCompositorState {
zweft_shell_window_v1::Request::UpdateMetadata { title, role } => { zweft_shell_window_v1::Request::UpdateMetadata { title, role } => {
let _ = (title, role); let _ = (title, role);
} }
zweft_shell_window_v1::Request::SetGeometry { zweft_shell_window_v1::Request::SetGeometry { .. } => {
x, // The request is advisory: the configure reports the
y, // geometry the compositor's layout gives the window.
width, let is_panel = state
height, .weft_shell_state
} => { .panels()
resource.configure(x, y, width, height, 0); .any(|panel| panel == resource);
let (x, y, w, h) = if is_panel {
state.output_geometry()
} else {
state.app_geometry()
};
let flags = if is_panel {
u32::from(crate::protocols::server::zweft_shell_window_v1::State::Maximized)
} else {
0
};
resource.configure(x, y, w, h, flags);
} }
zweft_shell_window_v1::Request::SetExclusiveZone { edge, size } => { zweft_shell_window_v1::Request::SetExclusiveZone { edge, size } => {
let is_panel = state let is_panel = state
@ -637,4 +652,17 @@ impl Dispatch<ZweftShellWindowV1, WeftShellWindowData> for WeftCompositorState {
} }
} }
} }
fn destroyed(
state: &mut Self,
_client: wayland_server::backend::ClientId,
resource: &ZweftShellWindowV1,
_data: &WeftShellWindowData,
) {
// A panel that goes away, by destroy or with its client, releases
// its reserved strip; applications take the space back.
if state.weft_shell_state.remove_panel(resource) {
state.layout_app_windows();
}
}
} }

View file

@ -1,10 +1,13 @@
//! Stacking, focus and activation of toplevel windows. //! Stacking, focus and activation of toplevel windows.
//! //!
//! The compositor decides the order: the trusted shell's panel, which //! The compositor decides the order and the geometry. The trusted shell's
//! fills the output, stays beneath every application window; a session's //! panel fills the output and starts beneath every application window;
//! first window, a clicked window and one appd asks to activate is raised to //! application windows fill the work area, the output less the strips the
//! the top, marked activated and given keyboard focus. When the focused //! panel reserves. A session's first window, a clicked window (the panel
//! window closes, the topmost remaining application window gets focus. //! 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.
use smithay::desktop::Window; use smithay::desktop::Window;
use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
@ -20,7 +23,10 @@ impl WeftCompositorState {
/// Whether `surface` backs a window the trusted shell registered as its /// Whether `surface` backs a window the trusted shell registered as its
/// panel. /// panel.
pub fn is_panel_surface(&self, surface: &WlSurface) -> bool { pub fn is_panel_surface(&self, surface: &WlSurface) -> bool {
self.weft_shell_state.panels().any(|panel| { self.weft_shell_state
.panels()
.filter(|p| p.is_alive())
.any(|panel| {
panel panel
.data::<WeftShellWindowData>() .data::<WeftShellWindowData>()
.and_then(|data| data.surface.as_ref()) .and_then(|data| data.surface.as_ref())
@ -34,19 +40,11 @@ impl WeftCompositorState {
.is_some_and(|surface| self.is_panel_surface(&surface)) .is_some_and(|surface| self.is_panel_surface(&surface))
} }
/// Raises `window` above the other application windows, marks it /// Raises `window` to the top, marks it activated and gives it keyboard
/// activated and gives it keyboard focus. A panel is focused but stays /// focus. Activating the panel shows the shell's home, with its launcher,
/// beneath the applications. /// over the applications until one is activated again.
pub fn activate_window(&mut self, window: &Window) { pub fn activate_window(&mut self, window: &Window) {
if self.is_panel(window) {
// The panel takes focus without rising; no application window
// stays marked activated.
for other in self.space.elements() {
other.set_activated(false);
}
} else {
self.space.raise_element(window, true); self.space.raise_element(window, true);
}
self.send_pending_configures(); self.send_pending_configures();
if let (Some(keyboard), Some(surface)) = (self.seat.get_keyboard(), window.wl_surface()) { if let (Some(keyboard), Some(surface)) = (self.seat.get_keyboard(), window.wl_surface()) {
keyboard.set_focus( keyboard.set_focus(
@ -197,7 +195,7 @@ impl WeftCompositorState {
use crate::protocols::server::zweft_shell_window_v1::Edge; use crate::protocols::server::zweft_shell_window_v1::Edge;
let output = self.space.outputs().next()?; let output = self.space.outputs().next()?;
let mut area = self.space.output_geometry(output)?; let mut area = self.space.output_geometry(output)?;
for panel in self.weft_shell_state.panels() { for panel in self.weft_shell_state.panels().filter(|p| p.is_alive()) {
let Some(data) = panel.data::<WeftShellWindowData>() else { let Some(data) = panel.data::<WeftShellWindowData>() else {
continue; continue;
}; };
@ -223,9 +221,29 @@ impl WeftCompositorState {
Edge::Right => area.size.w -= size.min(area.size.w), Edge::Right => area.size.w -= size.min(area.size.w),
} }
} }
// A zone covering the output still leaves applications a size the
// client must honour, never 0, which would let it pick its own.
area.size.w = area.size.w.max(1);
area.size.h = area.size.h.max(1);
Some(area) Some(area)
} }
/// The output's geometry as (x, y, width, height).
pub fn output_geometry(&self) -> (i32, i32, i32, i32) {
self.space
.outputs()
.next()
.and_then(|output| self.space.output_geometry(output))
.map_or((0, 0, 0, 0), |g| (g.loc.x, g.loc.y, g.size.w, g.size.h))
}
/// The geometry the layout gives application windows, as
/// (x, y, width, height).
pub fn app_geometry(&self) -> (i32, i32, i32, i32) {
self.work_area()
.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 /// Places every application window to fill the work area, so none
/// covers the panel's reserved strips. /// covers the panel's reserved strips.
pub fn layout_app_windows(&mut self) { pub fn layout_app_windows(&mut self) {

View file

@ -8,7 +8,7 @@ WEFT OS is a Wayland compositor and application runtime where every app is a Web
### weft-compositor ### 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 kept beneath application windows; 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; 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 ### weft-servo-shell

View file

@ -32,7 +32,7 @@ For verified read-only package storage, `weft-pack build-image` produces an EROF
Each app shell is given exactly one Wayland connection, created for its session. weft-appd creates a connected socket pair, gives one end to the app shell as its standard input with `WAYLAND_SOCKET=0` and no `WAYLAND_DISPLAY`, and sends the other end to the compositor over the compositor IPC socket (`SCM_RIGHTS`) with the session ID and app ID. The compositor adds that end as a client bound to the session; the binding comes from appd holding the connection, never from an ID or process ID the client supplies. A session's `zweft_shell` windows carry the session's app ID whatever the client requests, and the shell-only `panel` and `overlay` roles are refused with a protocol error; layer-shell surfaces and the input-method interface are not offered to session clients at all. When the session ends, the compositor closes its client; when the client disconnects, the compositor reports it to appd; when appd's connection ends, the compositor closes every session client appd attached. The compositor accepts one appd connection at a time. A launch is refused (503) while appd is not connected to the compositor, rather than starting an app that could never show a window; if the compositor connection is lost before the session's connection is handed over, the session is stopped before the app shell starts. Frames for appd that its socket cannot take at once are queued and retried; a backlog beyond 4 MiB, from an appd that stopped reading, ends the connection and with it the sessions' clients. Each app shell is given exactly one Wayland connection, created for its session. weft-appd creates a connected socket pair, gives one end to the app shell as its standard input with `WAYLAND_SOCKET=0` and no `WAYLAND_DISPLAY`, and sends the other end to the compositor over the compositor IPC socket (`SCM_RIGHTS`) with the session ID and app ID. The compositor adds that end as a client bound to the session; the binding comes from appd holding the connection, never from an ID or process ID the client supplies. A session's `zweft_shell` windows carry the session's app ID whatever the client requests, and the shell-only `panel` and `overlay` roles are refused with a protocol error; layer-shell surfaces and the input-method interface are not offered to session clients at all. When the session ends, the compositor closes its client; when the client disconnects, the compositor reports it to appd; when appd's connection ends, the compositor closes every session client appd attached. The compositor accepts one appd connection at a time. A launch is refused (503) while appd is not connected to the compositor, rather than starting an app that could never show a window; if the compositor connection is lost before the session's connection is handed over, the session is stopped before the app shell starts. Frames for appd that its socket cannot take at once are queued and retried; a backlog beyond 4 MiB, from an appd that stopped reading, ends the connection and with it the sessions' clients.
Not yet covered: the compositor IPC socket accepts any process of the user while no appd is connected, so the first connection after a restart is trusted as appd; close is not yet decided by the compositor per session; application windows fill the work area the panel leaves, one in front at a time; only the first window a session maps in its lifetime takes keyboard focus when it maps, and a client connected through the display socket takes focus on map only while no other such window is mapped; and the trusted system shell is identified only by connecting through the display socket, which any process of the user, including an app shell, can open. Not yet covered: the compositor IPC socket accepts any process of the user while no appd is connected, so the first connection after a restart is trusted as appd; close is not yet decided by the compositor per session; there is no user placement or resizing, since application windows fill the work area the panel leaves, one in front at a time; only the first window a session maps in its lifetime takes keyboard focus when it maps, and a client connected through the display socket takes focus on map only while no other such window is mapped; and the trusted system shell is identified only by connecting through the display socket, which any process of the user, including an app shell, can open.
## JavaScript Engine (SpiderMonkey) ## JavaScript Engine (SpiderMonkey)

View file

@ -12,6 +12,8 @@ colour and a lighter shade on every key press. In the presented pixels:
- each newly launched application is shown on top and receives keys; - each newly launched application is shown on top and receives keys;
- ACTIVATE_APP, the request the taskbar sends, brings the other session's - ACTIVATE_APP, the request the taskbar sends, brings the other session's
window back to the front with keyboard focus; window back to the front with keyboard focus;
- clicking the taskbar strip brings the panel, the shell's home, over the
applications, and activating an application brings it back;
- when the focused application ends, the remaining one gets keyboard focus; - when the focused application ends, the remaining one gets keyboard focus;
- ACTIVATE_APP for a session that is not running is refused. - ACTIVATE_APP for a session that is not running is refused.
@ -182,6 +184,25 @@ def run(args, desktop, store, home):
activate(blue) activate(blue)
shown(blue, pressed=True) shown(blue, pressed=True)
# A click on the taskbar strip shows the shell's home over the
# applications; activating one brings it back.
x, y = (panel[0] + panel[2]) // 2, panel[3] - TASKBAR // 2
subprocess.run([args.xdotool, "mousemove", "--sync", str(x), str(y)],
env={"DISPLAY": desktop.display}, check=True, timeout=20)
subprocess.run([args.xdotool, "click", "1"], env={"DISPLAY": desktop.display},
check=True, timeout=20)
deadline = time.monotonic() + 20
while True:
shot = desktop.capture()
if area(shot, GREEN)[0] == panel and all(
area(shot, c)[0] is None for cs in APPS.values() for c in cs):
break
if time.monotonic() > deadline:
raise AssertionError("clicking the taskbar did not show the shell over the apps")
time.sleep(0.3)
activate(blue)
shown(blue, pressed=True)
# When the focused application ends, keyboard focus returns to the other. # When the focused application ends, keyboard focus returns to the other.
appd.send({"type": "TERMINATE_APP", "session_id": sessions[blue]}) appd.send({"type": "TERMINATE_APP", "session_id": sessions[blue]})
shown(red, pressed=True) shown(red, pressed=True)

View file

@ -60,7 +60,8 @@ ROOT_COLOUR = (0, 0, 0)
def page_rows(width, height, pixels): def page_rows(width, height, pixels):
"""The first and last rows the app window's page covers at PAGE_X: the """The first and last rows the app window's page covers at PAGE_X: the
compositor gives the application its whole work area.""" compositor gives the application its whole work area. No shell runs in
this check, so every row of the output that is not the X root is page."""
rows = [y for y in range(height) if pixel(width, pixels, PAGE_X, y) != ROOT_COLOUR] rows = [y for y in range(height) if pixel(width, pixels, PAGE_X, y) != ROOT_COLOUR]
return (rows[0], rows[-1]) if rows else None return (rows[0], rows[-1]) if rows else None