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