Merge fix/reserve-panel-work-area: reserve the taskbar strip and lay application windows out in the work area (#21)

This commit is contained in:
Marco Allegretti 2026-10-10 09:24:31 +02:00 committed by GitHub
commit c557b24dce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 340 additions and 101 deletions

View file

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

View file

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

View file

@ -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(),
@ -52,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() {
@ -97,6 +106,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 +122,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 +133,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
@ -576,7 +577,11 @@ impl Dispatch<ZweftShellManagerV1, ()> 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);
}
}
}
@ -585,7 +590,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,
@ -605,14 +610,64 @@ impl Dispatch<ZweftShellWindowV1, WeftShellWindowData> 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
.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",
),
}
}
}
}
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 and its window slot; applications take the
// 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);
}
state.layout_app_windows();
}
}
}

View file

@ -1,16 +1,22 @@
//! 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; 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.
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;
@ -20,7 +26,10 @@ 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| {
self.weft_shell_state
.panels()
.filter(|p| p.is_alive())
.any(|panel| {
panel
.data::<WeftShellWindowData>()
.and_then(|data| data.surface.as_ref())
@ -34,19 +43,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.send_pending_configures();
if let (Some(keyboard), Some(surface)) = (self.seat.get_keyboard(), window.wl_surface()) {
keyboard.set_focus(
@ -75,51 +76,71 @@ 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);
// 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
/// 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>) {
// 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 panels: Vec<Window> = self
.space
.elements()
.filter(|window| self.is_panel(window))
.cloned()
.collect();
if panels.is_empty() {
return;
.and_then(|output| self.space.output_geometry(output));
let area = self.work_area();
let mut order: Vec<Window> = self.space.elements().cloned().collect();
if lower_panels {
let (panels, apps): (Vec<Window>, Vec<Window>) =
order.into_iter().partition(|window| self.is_panel(window));
order = panels.into_iter().chain(apps).collect();
}
for panel in &panels {
if let Some(toplevel) = panel.toplevel() {
if let Some(window) = below_top
&& let Some(position) = order.iter().position(|w| w == window)
&& position + 1 == order.len()
&& order.len() > 1
{
order.swap(position, position - 1);
}
for window in &order {
let panel = self.is_panel(window);
let 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);
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);
}
// Raising every other window, in its current order, leaves the
// panels at the bottom.
let others: Vec<Window> = self
.space
.elements()
.filter(|window| !self.is_panel(window))
.cloned()
.collect();
for window in &others {
self.space.raise_element(window, false);
// 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);
}
}
@ -146,7 +167,12 @@ impl WeftCompositorState {
if self.is_panel(&window) {
self.fit_panels();
} else if first {
self.layout_app_windows();
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));
}
}
@ -187,6 +213,67 @@ 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().filter(|p| p.is_alive()) {
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),
}
}
// 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))
}
/// Lays the windows out again after the work area changed, keeping the
/// stacking order.
pub fn layout_app_windows(&mut self) {
self.place_windows(false, None);
}
/// 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 starts beneath application windows, and clicking it brings it to the front as the shell's home, with its launcher, until an application is activated or opens its first window; layout changes keep the stacking order, and a window that maps without taking focus goes beneath the window in front; a session's first window, a clicked window and an activated one are raised, marked activated and given keyboard focus, and when the focused window closes the topmost remaining application window gets focus. A session's later windows are shown without taking focus. The panel reserves a strip along an output edge for the taskbar with `set_exclusive_zone` (weft-servo-shell reserves 48 logical pixels at the bottom), and the compositor lays every application window out to fill the remaining work area. weft-appd's `ACTIVATE_APP` request, which the taskbar sends, asks the compositor to activate a running session's window. Supports DRM/KMS and winit (software/dev) backends.
### weft-servo-shell

View file

@ -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
python3 tests/frame/check_update.py # updates leave running sessions on their revision; failed updates, rollback and uninstall
```

View file

@ -42,7 +42,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; 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)

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

@ -6,10 +6,14 @@ 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;
- 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.
@ -35,6 +39,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 +103,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 +138,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 ""
@ -175,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)

View file

@ -52,8 +52,18 @@ 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. 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
def png():
@ -177,10 +187,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():
@ -94,6 +96,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},
@ -132,7 +139,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")
@ -147,7 +154,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.
@ -158,7 +165,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: