From 5253eaf2518c5f0053e1b6bc79435a47cb39dad6 Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Fri, 9 Oct 2026 16:00:38 +0000 Subject: [PATCH 1/4] fix(compositor): reserve the taskbar strip and lay app windows out in the work area Application windows opened at the client's default size at the origin, so one as large as the output hid the taskbar with no way back. zweft_shell_window_v1 version 3 adds set_exclusive_zone: a panel reserves a strip along an output edge, and other windows get the new invalid_exclusive_zone error. weft-servo-shell reserves its 48-pixel taskbar at the bottom (TASKBAR_HEIGHT, matching --taskbar-height in the system UI). The compositor computes the work area as the output less the reserved strips and configures every application window to fill it, again when the output or a reservation changes. The desktop harness now uses a 1400x900 X screen so the nested compositor's whole 1280x800 output is captured. check_activation.py requires both applications to fill the work area and end at the reserved strip; check_notes.py finds the Discard button from the window's right edge and check_confinement.py samples its probes from the measured page instead of a fixed 800x600 window. --- crates/weft-compositor/src/protocols/mod.rs | 10 ++- crates/weft-compositor/src/state.rs | 24 ++++++- crates/weft-compositor/src/windows.rs | 70 ++++++++++++++++++++- crates/weft-servo-shell/src/shell_client.rs | 12 +++- docs/architecture.md | 2 +- docs/building.md | 2 +- docs/security.md | 2 +- infra/shell/system-ui.html | 1 + protocol/weft-shell-unstable-v1.xml | 27 +++++++- tests/frame/check_activation.py | 21 ++++--- tests/frame/check_confinement.py | 21 +++++-- tests/frame/check_notes.py | 19 ++++-- tests/frame/session.py | 11 ++-- 13 files changed, 188 insertions(+), 34 deletions(-) diff --git a/crates/weft-compositor/src/protocols/mod.rs b/crates/weft-compositor/src/protocols/mod.rs index 18922b4..0993fad 100644 --- a/crates/weft-compositor/src/protocols/mod.rs +++ b/crates/weft-compositor/src/protocols/mod.rs @@ -33,6 +33,8 @@ pub struct WeftShellWindowData { pub role: String, pub surface: Option, pub closed: std::sync::atomic::AtomicBool, + /// The edge strip a panel reserved with set_exclusive_zone. + pub exclusive_zone: std::sync::Mutex>, } impl WeftShellState { @@ -41,7 +43,7 @@ impl WeftShellState { D: GlobalDispatch, D: 'static, { - let global = display.create_global::(2, ()); + let global = display.create_global::(3, ()); Self { _global: global, panels: Vec::new(), @@ -97,6 +99,7 @@ mod tests { role: "normal".into(), surface: None, closed: std::sync::atomic::AtomicBool::new(false), + exclusive_zone: std::sync::Mutex::new(None), }; assert_eq!(d.app_id, "com.example.test"); assert_eq!(d.title, "Test Window"); @@ -112,6 +115,7 @@ mod tests { role: String::new(), surface: None, closed: std::sync::atomic::AtomicBool::new(false), + exclusive_zone: std::sync::Mutex::new(None), }; assert!(!d.closed.load(Ordering::Relaxed)); d.closed.store(true, Ordering::Relaxed); @@ -122,14 +126,14 @@ mod tests { fn manager_interface_name_and_version() { let iface = ZweftShellManagerV1::interface(); assert_eq!(iface.name, "zweft_shell_manager_v1"); - assert_eq!(iface.version, 2); + assert_eq!(iface.version, 3); } #[test] fn window_interface_name_and_version() { let iface = ZweftShellWindowV1::interface(); assert_eq!(iface.name, "zweft_shell_window_v1"); - assert_eq!(iface.version, 2); + assert_eq!(iface.version, 3); } #[test] diff --git a/crates/weft-compositor/src/state.rs b/crates/weft-compositor/src/state.rs index f612358..363783f 100644 --- a/crates/weft-compositor/src/state.rs +++ b/crates/weft-compositor/src/state.rs @@ -542,6 +542,7 @@ impl Dispatch for WeftCompositorState { role, surface, closed: std::sync::atomic::AtomicBool::new(false), + exclusive_zone: std::sync::Mutex::new(None), }, ); if let Some(session) = session @@ -585,7 +586,7 @@ impl Dispatch for WeftCompositorState { impl Dispatch for WeftCompositorState { fn request( - _state: &mut Self, + state: &mut Self, _client: &Client, resource: &ZweftShellWindowV1, request: zweft_shell_window_v1::Request, @@ -613,6 +614,27 @@ impl Dispatch for WeftCompositorState { } => { resource.configure(x, y, width, height, 0); } + zweft_shell_window_v1::Request::SetExclusiveZone { edge, size } => { + let is_panel = state + .weft_shell_state + .panels() + .any(|panel| panel == resource); + let edge = edge.into_result().ok(); + match edge { + Some(edge) if is_panel && size >= 0 => { + let zone = (size > 0).then_some((edge, size)); + *data + .exclusive_zone + .lock() + .unwrap_or_else(|p| p.into_inner()) = zone; + state.layout_app_windows(); + } + _ => resource.post_error( + crate::protocols::server::zweft_shell_window_v1::Error::InvalidExclusiveZone, + "only a panel may reserve an edge, with a size of at least 0", + ), + } + } } } } diff --git a/crates/weft-compositor/src/windows.rs b/crates/weft-compositor/src/windows.rs index df39eb4..c3a3add 100644 --- a/crates/weft-compositor/src/windows.rs +++ b/crates/weft-compositor/src/windows.rs @@ -10,7 +10,7 @@ use smithay::desktop::Window; use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; use smithay::reexports::wayland_server::Resource; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; -use smithay::utils::SERIAL_COUNTER; +use smithay::utils::{Logical, Rectangle, SERIAL_COUNTER}; use smithay::wayland::seat::WaylandFocus; use crate::protocols::WeftShellWindowData; @@ -121,6 +121,7 @@ impl WeftCompositorState { 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 @@ -145,8 +146,11 @@ impl WeftCompositorState { self.space.map_element(window.clone(), (0, 0), false); if self.is_panel(&window) { self.fit_panels(); - } else if first { - self.activate_window(&window); + } else { + self.layout_app_windows(); + if first { + self.activate_window(&window); + } } } @@ -187,6 +191,66 @@ impl WeftCompositorState { } } + /// The part of the output that application windows occupy: the output + /// less the strips the panels reserved. + pub fn work_area(&self) -> Option> { + use crate::protocols::server::zweft_shell_window_v1::Edge; + let output = self.space.outputs().next()?; + let mut area = self.space.output_geometry(output)?; + for panel in self.weft_shell_state.panels() { + let Some(data) = panel.data::() else { + continue; + }; + let zone = *data + .exclusive_zone + .lock() + .unwrap_or_else(|p| p.into_inner()); + let Some((edge, size)) = zone else { + continue; + }; + match edge { + Edge::Top => { + let size = size.min(area.size.h); + area.loc.y += size; + area.size.h -= size; + } + Edge::Bottom => area.size.h -= size.min(area.size.h), + Edge::Left => { + let size = size.min(area.size.w); + area.loc.x += size; + area.size.w -= size; + } + Edge::Right => area.size.w -= size.min(area.size.w), + } + } + Some(area) + } + + /// Places every application window to fill the work area, so none + /// covers the panel's reserved strips. + pub fn layout_app_windows(&mut self) { + let Some(area) = self.work_area() else { + return; + }; + let apps: Vec = 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); + } + } + /// Sends the configure for every toplevel whose pending state changed, /// such as its activated state. fn send_pending_configures(&self) { diff --git a/crates/weft-servo-shell/src/shell_client.rs b/crates/weft-servo-shell/src/shell_client.rs index 7af2270..67b4f2b 100644 --- a/crates/weft-servo-shell/src/shell_client.rs +++ b/crates/weft-servo-shell/src/shell_client.rs @@ -9,6 +9,11 @@ use crate::protocols::{ client::{zweft_shell_manager_v1, zweft_shell_window_v1}, }; +/// Height in logical pixels of the taskbar strip the system UI draws along +/// the bottom of the output; it matches `--taskbar-height` in +/// `infra/shell/system-ui.html`. +pub const TASKBAR_HEIGHT: i32 = 48; + // ── Window state ────────────────────────────────────────────────────────────── pub struct ShellWindowState { @@ -72,7 +77,7 @@ impl Dispatch for AppData { } = event && interface == "zweft_shell_manager_v1" { - let mgr = registry.bind::(name, version.min(2), qh, ()); + let mgr = registry.bind::(name, version.min(3), qh, ()); state.manager = Some(mgr); } } @@ -213,6 +218,11 @@ impl ShellClient { &qh, (), ); + // The taskbar's strip at the bottom of the output is kept free of + // application windows. + if window.version() >= 3 { + window.set_exclusive_zone(zweft_shell_window_v1::Edge::Bottom, TASKBAR_HEIGHT); + } data.window = Some(window); event_queue diff --git a/docs/architecture.md b/docs/architecture.md index dd74a4d..f8abe0e 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -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 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. 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 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. ### weft-servo-shell diff --git a/docs/building.md b/docs/building.md index fc6fed2..d13bbd9 100644 --- a/docs/building.md +++ b/docs/building.md @@ -88,7 +88,7 @@ python3 tests/frame/check_counter.py # Counter round trip through the session python3 tests/frame/check_notes.py # Notes stores exactly what is typed, refuses stale saves python3 tests/frame/check_app_data.py # Notes data from the earlier layout is moved and kept python3 tests/frame/check_confinement.py # an app page reaches only its UI files and its session bridge -python3 tests/frame/check_activation.py # panel beneath two apps; launch and ACTIVATE_APP raise and focus +python3 tests/frame/check_activation.py # apps fill the work area above the taskbar; launch and ACTIVATE_APP raise and focus ``` ## Demo apps (wasm32-wasip2) diff --git a/docs/security.md b/docs/security.md index b18519a..d23d1cb 100644 --- a/docs/security.md +++ b/docs/security.md @@ -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. -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; window placement and close are not yet decided by the compositor per session (all toplevels start at the origin, and no work area is reserved for the taskbar, so an application window as large as the output hides it); 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; 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) diff --git a/infra/shell/system-ui.html b/infra/shell/system-ui.html index 1b98e2f..dd019a6 100644 --- a/infra/shell/system-ui.html +++ b/infra/shell/system-ui.html @@ -9,6 +9,7 @@ color-scheme: dark; --surface-bg: rgba(255, 255, 255, 0.07); --surface-border: rgba(255, 255, 255, 0.12); + /* weft-servo-shell reserves this strip (TASKBAR_HEIGHT); keep them equal. */ --taskbar-height: 48px; --text-primary: rgba(255, 255, 255, 0.92); --text-secondary: rgba(255, 255, 255, 0.55); diff --git a/protocol/weft-shell-unstable-v1.xml b/protocol/weft-shell-unstable-v1.xml index f208b62..8ee68df 100644 --- a/protocol/weft-shell-unstable-v1.xml +++ b/protocol/weft-shell-unstable-v1.xml @@ -43,7 +43,7 @@ - + Bound once by weft-servo-shell. The manager owns the shell session. @@ -95,7 +95,7 @@ - + Represents one visual window. The compositor controls the effective @@ -121,6 +121,16 @@ summary="request sent after window_closed was received"/> + + + + + + + + + @@ -155,6 +165,19 @@ + + + Reserves a strip of the given size, in logical pixels, along an + edge of the output for shell chrome drawn by this panel, such as a + taskbar. The compositor places application windows only in the + work area that remains, so they never cover the strip. A size of 0 + releases the reservation; a later request replaces the earlier one. + Only a panel window may reserve a zone. + + + + + Sent by the compositor when the effective geometry or state diff --git a/tests/frame/check_activation.py b/tests/frame/check_activation.py index 3d46ee4..f5b3e1a 100755 --- a/tests/frame/check_activation.py +++ b/tests/frame/check_activation.py @@ -7,6 +7,8 @@ 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; +- 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; - ACTIVATE_APP, the request the taskbar sends, brings the other session's window back to the front with keyboard focus; @@ -35,6 +37,8 @@ APPS = { "org.weft.test.blue": ((0, 0, 200), (120, 120, 255)), } STARTUP_TIMEOUT = 120.0 +# The strip weft-servo-shell reserves at the bottom (TASKBAR_HEIGHT). +TASKBAR = 48 PANEL_PAGE = ('') @@ -97,10 +101,9 @@ def run(args, desktop, store, home): shot, panel = wait_for_color(desktop, GREEN, 60) if panel is None: raise AssertionError("the panel was not shown") - width, height, _ = parse_ppm(shot) - # The compositor sizes the panel to its whole output, which reaches the - # right and bottom edges of the nested desktop. - if panel[2] != width - 1 or panel[3] < height - 3: + # The compositor sizes the panel to its whole output, larger than a + # toplevel's default size. + if panel[2] - panel[0] + 1 < 1000 or panel[3] - panel[1] + 1 < 700: raise AssertionError(f"the panel does not fill the output: {panel}") t = Path(args.target) @@ -133,9 +136,13 @@ def run(args, desktop, store, home): box, _, _ = area(shot, color) hidden = all(area(shot, c)[0] is None for c in others) if box is not None and hidden: - # The panel stays visible beside the application window. - if area(shot, GREEN)[0] is None: - raise AssertionError("an application covered the panel") + # The application fills the work area: the panel's whole + # width, down to the reserved strip, which stays visible. + if box[0] != panel[0] or box[2] != panel[2] or box[1] != panel[1]: + raise AssertionError(f"{app_id} does not fill the work area: {box}") + if box[3] != panel[3] - TASKBAR: + raise AssertionError( + f"{app_id} does not end at the reserved strip: {box}, panel {panel}") return time.sleep(0.3) state = "pressed " if pressed else "" diff --git a/tests/frame/check_confinement.py b/tests/frame/check_confinement.py index c484905..d1ba9e7 100644 --- a/tests/frame/check_confinement.py +++ b/tests/frame/check_confinement.py @@ -52,8 +52,17 @@ APP_ID = "org.weft.test.confinement" PROBES = ["own-image", "bridge", "outside-image", "other-image", "linked-image", "http-image", "http-fetch", "websocket", "worker-fetch", "srcdoc-internals"] GREEN = (0, 192, 0) -# The app window's page area on the 1024x768 nested desktop. -PAGE_TOP, PAGE_HEIGHT, PAGE_X = 35, 600, 400 +# Where the probe bands are sampled across the app window's page. +PAGE_X = 400 +# The X root behind the nested compositor window. +ROOT_COLOUR = (0, 0, 0) + + +def page_rows(width, height, pixels): + """The first and last rows the app window's page covers at PAGE_X: the + compositor gives the application its whole work area.""" + 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 def png(): @@ -169,10 +178,14 @@ def run(args, desktop, store, other_dir): deadline = time.monotonic() + 15 while True: - width, _, pixels = parse_ppm(desktop.capture()) + width, height, pixels = parse_ppm(desktop.capture()) + rows = page_rows(width, height, pixels) + if rows is None: + raise AssertionError("the test app's page is not on screen") + top, bottom = rows colours = {} for i, name in enumerate(PROBES): - y = PAGE_TOP + int((i + 0.5) * PAGE_HEIGHT / len(PROBES)) + y = top + int((i + 0.5) * (bottom - top + 1) / len(PROBES)) colours[name] = pixel(width, pixels, PAGE_X, y) if all(c == GREEN for c in colours.values()) or time.monotonic() > deadline: break diff --git a/tests/frame/check_notes.py b/tests/frame/check_notes.py index 2d562ee..a769e4a 100644 --- a/tests/frame/check_notes.py +++ b/tests/frame/check_notes.py @@ -35,14 +35,16 @@ from pathlib import Path sys.dont_write_bytecode = True from check_counter import AppdClient, free_port, read_endpoint # noqa: E402 -from session import ROOT, Desktop, SessionError, missing_tools # noqa: E402 +from session import ROOT, Desktop, SessionError, bounding_box, missing_tools, parse_ppm # noqa: E402 APP_ID = "org.weft.demo.notes" SEED = 'path C:\\new\\table "quoted"\tcaf\u00e9 \u2603' -# The Discard button in the 800x600 Notes window at the desktop's origin. -DISCARD = ("663", "68") +PAGE = (15, 15, 15) # The Notes page's background, #0f0f0f. +# The Discard button, right-aligned in the header: its offset from the +# window's right edge, and its height on the desktop. +DISCARD_FROM_RIGHT, DISCARD_Y = 137, 68 def runtime_pid(): @@ -87,6 +89,11 @@ def run(args, desktop, home, xdotool): if reply.get("type") != "APP_READY": raise AssertionError(f"Notes did not start: {reply}") time.sleep(2) + width, height, pixels = parse_ppm(desktop.capture()) + page = bounding_box(width, height, pixels, PAGE) + if page is None: + raise AssertionError("the Notes page is not on screen") + discard = (str(page[2] + 1 - DISCARD_FROM_RIGHT), str(DISCARD_Y)) def act(*arguments): subprocess.run([xdotool, *arguments], env={"DISPLAY": desktop.display}, @@ -125,7 +132,7 @@ def run(args, desktop, home, xdotool): os.kill(runtime, signal.SIGSTOP) try: - act("mousemove", "--sync", *DISCARD) + act("mousemove", "--sync", *discard) act("click", "1") act("mousemove", "--sync", "100", "300") act("click", "1") @@ -140,7 +147,7 @@ def run(args, desktop, home, xdotool): act("key", "ctrl+s") wait_for_file(notes, other + "!") notes.write_bytes(b"\xff not text") - act("mousemove", "--sync", *DISCARD) + act("mousemove", "--sync", *discard) act("click", "1") time.sleep(2) # The editor stays read-only and nothing can be saved over the file. @@ -151,7 +158,7 @@ def run(args, desktop, home, xdotool): time.sleep(2) if notes.read_bytes() != b"\xff not text": raise AssertionError("a failed load changed the stored notes") - act("mousemove", "--sync", *DISCARD) + act("mousemove", "--sync", *discard) notes.write_text("repaired", encoding="utf-8") act("click", "1") time.sleep(2) diff --git a/tests/frame/session.py b/tests/frame/session.py index 0b45837..c87ecf8 100644 --- a/tests/frame/session.py +++ b/tests/frame/session.py @@ -17,7 +17,8 @@ from pathlib import Path ROOT = Path(__file__).resolve().parents[2] -SCREEN = (1024, 768) +# Large enough to show the nested compositor's whole 1280x800 output. +SCREEN = (1400, 900) ANSI_ESCAPE = re.compile(r"\x1b\[[0-9;]*m") REQUIRED_TOOLS = ("Xvfb", "xwd", "convert") @@ -111,9 +112,11 @@ def _stop(process): class Desktop: """Xvfb plus weft-compositor; logs are written to `output/.log`.""" - def __init__(self, compositor, output, outputs=()): - """`outputs` names further files in `output` that this run will write.""" + def __init__(self, compositor, output, outputs=(), screen=SCREEN): + """`outputs` names further files in `output` that this run will write; + `screen` is the X screen size.""" self.compositor = Path(compositor) + self.screen = screen self.output = Path(output) self.own_outputs = ["xvfb.log", "compositor.log", "shell.log", *outputs] self.processes = [] @@ -180,7 +183,7 @@ class Desktop: try: xvfb = subprocess.Popen( ["Xvfb", "-displayfd", str(write_end), "-screen", "0", - f"{SCREEN[0]}x{SCREEN[1]}x24", "-nolisten", "tcp"], + f"{self.screen[0]}x{self.screen[1]}x24", "-nolisten", "tcp"], stdout=log, stderr=subprocess.STDOUT, env=self.env, start_new_session=True, pass_fds=(write_end,)) finally: From 8399914dfab3c508717594a3c9eed4bad53403f7 Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Fri, 9 Oct 2026 16:06:19 +0000 Subject: [PATCH 2/4] 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. --- crates/weft-compositor/src/protocols/mod.rs | 7 +++ crates/weft-compositor/src/state.rs | 44 +++++++++++--- crates/weft-compositor/src/windows.rs | 66 +++++++++++++-------- docs/architecture.md | 2 +- docs/security.md | 2 +- tests/frame/check_activation.py | 21 +++++++ tests/frame/check_confinement.py | 3 +- 7 files changed, 110 insertions(+), 35 deletions(-) diff --git a/crates/weft-compositor/src/protocols/mod.rs b/crates/weft-compositor/src/protocols/mod.rs index 0993fad..7ef486f 100644 --- a/crates/weft-compositor/src/protocols/mod.rs +++ b/crates/weft-compositor/src/protocols/mod.rs @@ -54,6 +54,13 @@ impl WeftShellState { 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) { for panel in &self.panels { if panel.is_alive() { diff --git a/crates/weft-compositor/src/state.rs b/crates/weft-compositor/src/state.rs index 363783f..6372dd0 100644 --- a/crates/weft-compositor/src/state.rs +++ b/crates/weft-compositor/src/state.rs @@ -577,7 +577,11 @@ impl Dispatch for WeftCompositorState { state.weft_shell_state.add_panel(window); state.fit_panels(); } 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 for WeftCompositorState { zweft_shell_window_v1::Request::UpdateMetadata { title, role } => { let _ = (title, role); } - zweft_shell_window_v1::Request::SetGeometry { - x, - y, - width, - height, - } => { - resource.configure(x, y, width, height, 0); + zweft_shell_window_v1::Request::SetGeometry { .. } => { + // The request is advisory: the configure reports the + // geometry the compositor's layout gives the window. + let is_panel = state + .weft_shell_state + .panels() + .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 } => { let is_panel = state @@ -637,4 +652,17 @@ impl Dispatch 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(); + } + } } diff --git a/crates/weft-compositor/src/windows.rs b/crates/weft-compositor/src/windows.rs index c3a3add..35352e4 100644 --- a/crates/weft-compositor/src/windows.rs +++ b/crates/weft-compositor/src/windows.rs @@ -1,10 +1,13 @@ //! Stacking, focus and activation of toplevel windows. //! -//! The compositor decides the order: the trusted shell's panel, which -//! fills the output, stays beneath every application window; a session's -//! first window, a clicked window 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. +//! The compositor decides the order and the geometry. The trusted shell's +//! panel fills the output and starts beneath every application window; +//! application windows fill the work area, the output less the strips the +//! 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. use smithay::desktop::Window; use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; @@ -20,12 +23,15 @@ impl WeftCompositorState { /// Whether `surface` backs a window the trusted shell registered as its /// panel. pub fn is_panel_surface(&self, surface: &WlSurface) -> bool { - self.weft_shell_state.panels().any(|panel| { - panel - .data::() - .and_then(|data| data.surface.as_ref()) - .is_some_and(|s| s == surface) - }) + self.weft_shell_state + .panels() + .filter(|p| p.is_alive()) + .any(|panel| { + panel + .data::() + .and_then(|data| data.surface.as_ref()) + .is_some_and(|s| s == surface) + }) } fn is_panel(&self, window: &Window) -> bool { @@ -34,19 +40,11 @@ impl WeftCompositorState { .is_some_and(|surface| self.is_panel_surface(&surface)) } - /// Raises `window` above the other application windows, marks it - /// activated and gives it keyboard focus. A panel is focused but stays - /// beneath the applications. + /// Raises `window` to the top, marks it activated and gives it keyboard + /// focus. Activating the panel shows the shell's home, with its launcher, + /// over the applications until one is activated again. 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(); if let (Some(keyboard), Some(surface)) = (self.seat.get_keyboard(), window.wl_surface()) { keyboard.set_focus( @@ -197,7 +195,7 @@ impl WeftCompositorState { use crate::protocols::server::zweft_shell_window_v1::Edge; let output = self.space.outputs().next()?; 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::() else { continue; }; @@ -223,9 +221,29 @@ impl WeftCompositorState { 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) } + /// 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 /// covers the panel's reserved strips. pub fn layout_app_windows(&mut self) { diff --git a/docs/architecture.md b/docs/architecture.md index f8abe0e..4289c8e 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -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 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 diff --git a/docs/security.md b/docs/security.md index d23d1cb..d9c2bb3 100644 --- a/docs/security.md +++ b/docs/security.md @@ -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. -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) diff --git a/tests/frame/check_activation.py b/tests/frame/check_activation.py index f5b3e1a..cdd99d8 100755 --- a/tests/frame/check_activation.py +++ b/tests/frame/check_activation.py @@ -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; - ACTIVATE_APP, the request the taskbar sends, brings the other session's 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; - ACTIVATE_APP for a session that is not running is refused. @@ -182,6 +184,25 @@ def run(args, desktop, store, home): activate(blue) 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. appd.send({"type": "TERMINATE_APP", "session_id": sessions[blue]}) shown(red, pressed=True) diff --git a/tests/frame/check_confinement.py b/tests/frame/check_confinement.py index d1ba9e7..4a07c40 100644 --- a/tests/frame/check_confinement.py +++ b/tests/frame/check_confinement.py @@ -60,7 +60,8 @@ ROOT_COLOUR = (0, 0, 0) def page_rows(width, height, pixels): """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] return (rows[0], rows[-1]) if rows else None From cdc4a9e15dd59d5bf40a54a96c7bd9b8b5c5dfae Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Fri, 9 Oct 2026 16:11:20 +0000 Subject: [PATCH 3/4] 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. --- crates/weft-compositor/src/backend/drm.rs | 4 +- crates/weft-compositor/src/backend/winit.rs | 2 +- crates/weft-compositor/src/state.rs | 8 +- crates/weft-compositor/src/windows.rs | 104 +++++++++----------- docs/architecture.md | 2 +- tests/frame/check_activation.py | 2 +- 6 files changed, 57 insertions(+), 65 deletions(-) diff --git a/crates/weft-compositor/src/backend/drm.rs b/crates/weft-compositor/src/backend/drm.rs index 71e93fb..51a56c2 100644 --- a/crates/weft-compositor/src/backend/drm.rs +++ b/crates/weft-compositor/src/backend/drm.rs @@ -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(); } diff --git a/crates/weft-compositor/src/backend/winit.rs b/crates/weft-compositor/src/backend/winit.rs index ede398e..cd11fad 100644 --- a/crates/weft-compositor/src/backend/winit.rs +++ b/crates/weft-compositor/src/backend/winit.rs @@ -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) => { diff --git a/crates/weft-compositor/src/state.rs b/crates/weft-compositor/src/state.rs index 6372dd0..8b2977d 100644 --- a/crates/weft-compositor/src/state.rs +++ b/crates/weft-compositor/src/state.rs @@ -657,11 +657,15 @@ impl Dispatch 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(); } } diff --git a/crates/weft-compositor/src/windows.rs b/crates/weft-compositor/src/windows.rs index 35352e4..ab176e9 100644 --- a/crates/weft-compositor/src/windows.rs +++ b/crates/weft-compositor/src/windows.rs @@ -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 = 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 = self.space.elements().cloned().collect(); + if lower_panels { + let (panels, apps): (Vec, Vec) = + 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 = 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 = 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, diff --git a/docs/architecture.md b/docs/architecture.md index 4289c8e..2d995d3 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -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 diff --git a/tests/frame/check_activation.py b/tests/frame/check_activation.py index cdd99d8..3d69843 100755 --- a/tests/frame/check_activation.py +++ b/tests/frame/check_activation.py @@ -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; From c8bae1cc4d063785f0b6d4fbea56d88e2035492f Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Fri, 9 Oct 2026 16:14:31 +0000 Subject: [PATCH 4/4] fix(compositor): hand focus on when a registering panel is lowered A shell restarted while applications run took keyboard focus before it registered as the panel and kept it after being lowered beneath them; the window in front now gets it. Without an output, windows are still reordered, so a window that maps without taking focus does not cover the one in front. --- crates/weft-compositor/src/state.rs | 3 ++- crates/weft-compositor/src/windows.rs | 39 +++++++++++++++++++-------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/crates/weft-compositor/src/state.rs b/crates/weft-compositor/src/state.rs index 8b2977d..cdd8445 100644 --- a/crates/weft-compositor/src/state.rs +++ b/crates/weft-compositor/src/state.rs @@ -661,7 +661,8 @@ impl Dispatch for WeftCompositorState { ) { // A panel that goes away, by destroy or with its client, releases // its reserved strip and its window slot; applications take the - // space back. + // space back. The surface's window is not mapped again if it + // registers once more. if state.weft_shell_state.remove_panel(resource) { if let Some(surface) = &data.surface { state.window_closed(surface); diff --git a/crates/weft-compositor/src/windows.rs b/crates/weft-compositor/src/windows.rs index ab176e9..4e5f319 100644 --- a/crates/weft-compositor/src/windows.rs +++ b/crates/weft-compositor/src/windows.rs @@ -6,8 +6,9 @@ //! 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; nothing else changes the order, and a window that -//! maps without taking focus goes beneath the window in front. When the +//! given keyboard focus; apart from a panel being lowered when it +//! registers, 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. @@ -79,6 +80,21 @@ impl WeftCompositorState { /// application window; used when a panel registers. pub fn fit_panels(&mut self) { self.place_windows(true, None); + // A shell that took focus before registering as the panel, such as + // one restarted while applications run, hands it to the window that + // is now in front. + let focus_on_panel = self + .seat + .get_keyboard() + .and_then(|keyboard| keyboard.current_focus()) + .is_some_and(|focus| self.is_panel_surface(&focus)); + let front = self.space.elements().last().cloned(); + if focus_on_panel + && let Some(front) = front + && !self.is_panel(&front) + { + self.activate_window(&front); + } } /// Places every window for the current output and reservations: panels @@ -87,17 +103,14 @@ impl WeftCompositorState { /// 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 + // Without an output the order still changes; windows keep their + // size and place until one is mapped. + let output = self .space .outputs() .next() - .and_then(|output| self.space.output_geometry(output)) - else { - return; - }; - let Some(area) = self.work_area() else { - return; - }; + .and_then(|output| self.space.output_geometry(output)); + let area = self.work_area(); let mut order: Vec = self.space.elements().cloned().collect(); if lower_panels { let (panels, apps): (Vec, Vec) = @@ -113,7 +126,11 @@ impl WeftCompositorState { } for window in &order { let panel = self.is_panel(window); - let geometry = if panel { output } else { area }; + let Some(geometry) = (if panel { output } else { area }) else { + let location = self.space.element_location(window).unwrap_or_default(); + self.space.map_element(window.clone(), location, false); + continue; + }; if let Some(toplevel) = window.toplevel() { toplevel.with_pending_state(|state| { state.size = Some(geometry.size);