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.
This commit is contained in:
Marco Allegretti 2026-10-09 16:00:38 +00:00
parent 16af8d2a8c
commit 5253eaf251
No known key found for this signature in database
13 changed files with 188 additions and 34 deletions

View file

@ -33,6 +33,8 @@ pub struct WeftShellWindowData {
pub role: String,
pub surface: Option<wayland_server::protocol::wl_surface::WlSurface>,
pub closed: std::sync::atomic::AtomicBool,
/// The edge strip a panel reserved with set_exclusive_zone.
pub exclusive_zone: std::sync::Mutex<Option<(server::zweft_shell_window_v1::Edge, i32)>>,
}
impl WeftShellState {
@ -41,7 +43,7 @@ impl WeftShellState {
D: GlobalDispatch<ZweftShellManagerV1, ()>,
D: 'static,
{
let global = display.create_global::<D, ZweftShellManagerV1, ()>(2, ());
let global = display.create_global::<D, ZweftShellManagerV1, ()>(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]

View file

@ -542,6 +542,7 @@ impl Dispatch<ZweftShellManagerV1, ()> 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<ZweftShellManagerV1, ()> for WeftCompositorState {
impl Dispatch<ZweftShellWindowV1, WeftShellWindowData> 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<ZweftShellWindowV1, WeftShellWindowData> 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",
),
}
}
}
}
}

View file

@ -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,10 +146,13 @@ impl WeftCompositorState {
self.space.map_element(window.clone(), (0, 0), false);
if self.is_panel(&window) {
self.fit_panels();
} else if first {
} else {
self.layout_app_windows();
if first {
self.activate_window(&window);
}
}
}
/// Unmaps a closed toplevel and, if it had keyboard focus, gives focus
/// to the topmost remaining application window, or the panel.
@ -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<Rectangle<i32, Logical>> {
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::<WeftShellWindowData>() 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<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);
}
}
/// Sends the configure for every toplevel whose pending state changed,
/// such as its activated state.
fn send_pending_configures(&self) {

View file

@ -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<wl_registry::WlRegistry, ()> for AppData {
} = event
&& interface == "zweft_shell_manager_v1"
{
let mgr = registry.bind::<ZweftShellManagerV1, _, _>(name, version.min(2), qh, ());
let mgr = registry.bind::<ZweftShellManagerV1, _, _>(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

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 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

View file

@ -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)

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.
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)

View file

@ -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);

View file

@ -43,7 +43,7 @@
<!-- ───────────────────────────── Manager ───────────────────────────── -->
<interface name="zweft_shell_manager_v1" version="2">
<interface name="zweft_shell_manager_v1" version="3">
<description summary="shell session manager">
Bound once by weft-servo-shell. The manager owns the shell session.
@ -95,7 +95,7 @@
<!-- ───────────────────────────── Window ────────────────────────────── -->
<interface name="zweft_shell_window_v1" version="2">
<interface name="zweft_shell_window_v1" version="3">
<description summary="a compositor-managed window slot">
Represents one visual window. The compositor controls the effective
@ -121,6 +121,16 @@
summary="request sent after window_closed was received"/>
<entry name="role_not_permitted" value="1"
summary="an application session requested a shell-only role"/>
<entry name="invalid_exclusive_zone" value="2"
summary="set_exclusive_zone on a window that is not a panel, or with a negative size"/>
</enum>
<enum name="edge">
<description summary="output edge"/>
<entry name="top" value="1"/>
<entry name="bottom" value="2"/>
<entry name="left" value="3"/>
<entry name="right" value="4"/>
</enum>
<request name="destroy" type="destructor">
@ -155,6 +165,19 @@
<arg name="height" type="int" summary="requested height"/>
</request>
<request name="set_exclusive_zone" since="3">
<description summary="reserve an edge of the output for the panel">
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.
</description>
<arg name="edge" type="uint" enum="edge" summary="edge to reserve"/>
<arg name="size" type="int" summary="thickness of the strip"/>
</request>
<event name="configure">
<description summary="compositor sets effective geometry and state">
Sent by the compositor when the effective geometry or state

View file

@ -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 = ('<!DOCTYPE html><html><body style="margin:0;background:rgb(0,160,0);'
'width:100vw;height:100vh"></body></html>')
@ -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 ""

View file

@ -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

View file

@ -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)

View file

@ -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/<name>.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: