fix(shell): make the system UI operable from the keyboard

The launcher button, app icons and taskbar entries were custom elements
with click handlers only: none could be focused, named or activated from
the keyboard, and the launcher overlay neither took nor returned focus.

They are now buttons with accessible names and a visible focus ring. The
launcher is a modal dialog that a Super tap or the Apps button opens
with focus on its first app; Tab moves between apps, Enter opens one and
Escape or another Super tap closes it, returning focus to the Apps
button. Each taskbar entry has an activate and a close button reachable
with Tab, and focus moves to a remaining control when an entry closes or
goes away. Notifications, including the offer to force quit, are
announced as status.

Servo does not tell the document when its window loses keyboard focus,
so weft-servo-shell calls window.weftShellBlurred() then and the launcher
closes; the next Super tap opens it again. Servo does not evaluate
prefers-reduced-motion either, so the page has no transitions.

tests/frame/check_system_ui.py drives the real page on the nested
desktop with keys: opening apps from the launcher, reaching the shell
with a Super tap from an application, a Super chord that stays with the
app and leaves no Super modifier held there, activating and closing apps
from the taskbar, the launcher closing when the shell loses focus, and
toggling it. It fails without the compositor's Super handling or the
focus-loss call.
This commit is contained in:
Marco Allegretti 2026-10-09 20:21:26 +00:00
parent e83c3f6df0
commit fda9a7c22f
No known key found for this signature in database
5 changed files with 452 additions and 53 deletions

View file

@ -296,12 +296,25 @@ impl App {
self.next_endpoint_check, self.next_endpoint_check,
)); ));
self.endpoint = appd_endpoint(self.ws_port); self.endpoint = appd_endpoint(self.ws_port);
let (Some(endpoint), Some(webview)) = (&self.endpoint, &self.webview) else { let Some(endpoint) = &self.endpoint else {
return;
};
// The credential goes only to the system UI document.
let call = format!(
"window.weftAppdEndpoint({}, '{}')",
endpoint.port, endpoint.token
);
self.call_system_ui("weftAppdEndpoint", &call);
}
/// Runs `call` in the system UI document if it defines the function
/// `name`. Navigation away from the document is denied; the script
/// checks the document again because a load can still be under way when
/// it runs.
fn call_system_ui(&self, name: &str, call: &str) {
let Some(webview) = &self.webview else {
return; return;
}; };
// The credential goes only to the system UI document. Navigation away
// from it is denied; the script checks the document again because a
// load can still be under way when it runs.
if !webview if !webview
.url() .url()
.is_some_and(|url| same_document(url.as_str(), self.url.as_str())) .is_some_and(|url| same_document(url.as_str(), self.url.as_str()))
@ -313,9 +326,8 @@ impl App {
format!( format!(
"window === window.top && \ "window === window.top && \
location.href.split('#')[0] === {document} && \ location.href.split('#')[0] === {document} && \
typeof window.weftAppdEndpoint === 'function' && \ typeof window.{name} === 'function' && \
window.weftAppdEndpoint({}, '{}')", {call}"
endpoint.port, endpoint.token
), ),
|_| {}, |_| {},
); );
@ -494,6 +506,11 @@ impl ApplicationHandler<ServoWake> for App {
WindowEvent::ModifiersChanged(mods) => { WindowEvent::ModifiersChanged(mods) => {
self.modifiers = mods.state(); self.modifiers = mods.state();
} }
// Servo does not tell the page when its window loses keyboard
// focus; the system UI closes its launcher then.
WindowEvent::Focused(false) => {
self.call_system_ui("weftShellBlurred", "window.weftShellBlurred()");
}
WindowEvent::KeyboardInput { event, .. } => { WindowEvent::KeyboardInput { event, .. } => {
if let Some(wv) = &self.webview { if let Some(wv) = &self.webview {
let ev = super::keyutils::keyboard_event_from_winit(&event, self.modifiers); let ev = super::keyutils::keyboard_event_from_winit(&event, self.modifiers);

View file

@ -8,11 +8,11 @@ WEFT OS is a Wayland compositor and application runtime where every app is a Web
### weft-compositor ### weft-compositor
Smithay-based Wayland compositor. Implements the `zweft-shell-unstable-v1` protocol extension, which allows shell clients (servo-shell, app-shell) to register their surfaces as typed shell slots. Each application session's Wayland connection is handed to the compositor by weft-appd, which binds the client to that session (see `security.md`). The compositor owns stacking and focus: the system shell's panel is sized to the output and 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. Alt+F4 is the compositor's: it asks the focused application window to close (never the panel), and the app shell then exits and its session ends. 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. Alt+F4 is the compositor's: it asks the focused application window to close (never the panel), and the app shell then exits and its session ends. The Super keys are the compositor's too and never reach an application: a Super tap, pressed and released without another key or a pointer button, brings the panel (the first registered) to the front with keyboard focus and then delivers the tap to it, so the shell's launcher is reachable from any application; keys pressed while Super is held reach the focused window with the Super modifier, but Super's own key events do not. A session's later windows are shown without taking focus. The panel reserves a strip along an output edge for the taskbar with `set_exclusive_zone` (weft-servo-shell reserves 48 logical pixels at the bottom), and the compositor lays every application window out to fill the remaining work area. weft-appd's `ACTIVATE_APP` request, which the taskbar sends, asks the compositor to activate a running session's window. Supports DRM/KMS and winit (software/dev) backends.
### weft-servo-shell ### weft-servo-shell
System UI host. Renders one WebView pointing at `system-ui.html` using the embedded Servo engine (feature-gated behind `servo-embed`). Connects to the compositor as window type `panel`. Dispatches the `zweft_shell_manager_v1` event queue each frame. Forwards navigation gestures received from the compositor to `weft-appd` over WebSocket. Reads the appd WebSocket port and system token from `$XDG_RUNTIME_DIR/weft/` and hands both to the page through `window.weftAppdEndpoint(port, token)`; the shell hands the token only to the system UI document and denies top-level navigation away from it, and the launcher shows package names as text, never markup. System UI host. Renders one WebView pointing at `system-ui.html` using the embedded Servo engine (feature-gated behind `servo-embed`). Connects to the compositor as window type `panel`. Dispatches the `zweft_shell_manager_v1` event queue each frame. Forwards navigation gestures received from the compositor to `weft-appd` over WebSocket. Reads the appd WebSocket port and system token from `$XDG_RUNTIME_DIR/weft/` and hands both to the page through `window.weftAppdEndpoint(port, token)`; the shell hands the token only to the system UI document and denies top-level navigation away from it, and the launcher shows package names as text, never markup. The system UI works from the keyboard: a Super tap opens or closes the launcher, which lists installed apps by name and keeps focus while open (Tab moves between apps, Enter opens one, Escape closes it and returns focus to the Apps button, with the shell's home still in front); every taskbar entry and its close button is a button reachable with Tab, and Enter on an entry brings its app back. The shell tells the page through `window.weftShellBlurred()` when it loses keyboard focus, which Servo does not report to the document, and the launcher closes. The page has no transitions or animations, since Servo does not evaluate `prefers-reduced-motion`.
### weft-app-shell ### weft-app-shell

View file

@ -89,6 +89,7 @@ python3 tests/frame/check_notes.py # Notes stores exactly what is typed, ref
python3 tests/frame/check_app_data.py # Notes data from the earlier layout is moved and kept 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_confinement.py # an app page reaches only its UI files and its session bridge
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_activation.py # apps fill the work area above the taskbar; launch and ACTIVATE_APP raise and focus
python3 tests/frame/check_system_ui.py # the system UI's launcher and taskbar work from the keyboard alone, reached with a Super tap
``` ```
## Demo apps (wasm32-wasip2) ## Demo apps (wasm32-wasip2)

View file

@ -14,6 +14,7 @@
--text-primary: rgba(255, 255, 255, 0.92); --text-primary: rgba(255, 255, 255, 0.92);
--text-secondary: rgba(255, 255, 255, 0.55); --text-secondary: rgba(255, 255, 255, 0.55);
--accent: #5b8af5; --accent: #5b8af5;
--focus-ring: #9db8ff;
} }
*, *::before, *::after { *, *::before, *::after {
@ -63,19 +64,30 @@
-webkit-backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
} }
weft-taskbar-launcher { button {
font: inherit;
color: inherit;
border: 0;
margin: 0;
background: transparent;
cursor: pointer;
}
:focus-visible {
outline: 2px solid var(--focus-ring);
outline-offset: 2px;
}
#launcher-btn {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
width: 36px; width: 36px;
height: 36px; height: 36px;
border-radius: 8px; border-radius: 8px;
cursor: pointer;
background: transparent;
transition: background 0.15s;
} }
weft-taskbar-launcher:hover { #launcher-btn:hover {
background: var(--surface-border); background: var(--surface-border);
} }
@ -111,55 +123,56 @@
margin: 0 auto; margin: 0 auto;
} }
weft-app-icon { .app-icon {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
gap: 6px; gap: 6px;
padding: 12px 8px; padding: 12px 8px;
border-radius: 12px; border-radius: 12px;
cursor: pointer;
color: var(--text-primary); color: var(--text-primary);
font-size: 12px; font-size: 12px;
text-align: center; text-align: center;
word-break: break-word; word-break: break-word;
transition: background 0.15s;
} }
weft-app-icon:hover { .app-icon:hover {
background: var(--surface-border); background: var(--surface-border);
} }
weft-app-icon svg { .app-icon svg {
flex-shrink: 0; flex-shrink: 0;
} }
weft-taskbar-app { weft-taskbar-app {
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
gap: 4px; gap: 2px;
font-size: 12px; font-size: 12px;
color: var(--text-secondary); color: var(--text-secondary);
padding: 0 4px 0 6px;
cursor: pointer;
border-radius: 6px; border-radius: 6px;
transition: background 0.15s;
} }
weft-taskbar-app:hover { weft-taskbar-app:hover {
background: var(--surface-border); background: var(--surface-border);
} }
weft-taskbar-app .task-activate {
padding: 4px 2px 4px 6px;
border-radius: 6px;
}
weft-taskbar-app .task-close { weft-taskbar-app .task-close {
opacity: 0; opacity: 0;
font-size: 11px; font-size: 11px;
line-height: 1; line-height: 1;
padding: 1px 3px; padding: 3px 4px;
border-radius: 3px; border-radius: 3px;
transition: opacity 0.1s, background 0.1s;
} }
weft-taskbar-app:hover .task-close { /* Shown on hover and whenever the entry has keyboard focus. */
weft-taskbar-app:hover .task-close,
weft-taskbar-app:focus-within .task-close {
opacity: 1; opacity: 1;
} }
@ -167,6 +180,10 @@
background: rgba(255,80,80,0.3); background: rgba(255,80,80,0.3);
} }
weft-taskbar-app .task-close.force {
color: #ff6b6b;
}
weft-notification-center { weft-notification-center {
position: fixed; position: fixed;
top: 8px; top: 8px;
@ -188,7 +205,8 @@
<weft-desktop> <weft-desktop>
<weft-wallpaper></weft-wallpaper> <weft-wallpaper></weft-wallpaper>
<weft-taskbar> <weft-taskbar>
<weft-taskbar-launcher id="launcher-btn" title="Apps"> <button id="launcher-btn" type="button" title="Apps" aria-label="Apps"
aria-haspopup="dialog" aria-expanded="false" aria-controls="launcher">
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" <svg width="18" height="18" viewBox="0 0 18 18" fill="none"
xmlns="http://www.w3.org/2000/svg" aria-hidden="true"> xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<rect x="1" y="1" width="6" height="6" rx="1.5" <rect x="1" y="1" width="6" height="6" rx="1.5"
@ -200,15 +218,15 @@
<rect x="11" y="11" width="6" height="6" rx="1.5" <rect x="11" y="11" width="6" height="6" rx="1.5"
fill="rgba(255,255,255,0.7)" /> fill="rgba(255,255,255,0.7)" />
</svg> </svg>
</weft-taskbar-launcher> </button>
<weft-taskbar-clock id="clock"></weft-taskbar-clock> <weft-taskbar-clock id="clock"></weft-taskbar-clock>
</weft-taskbar> </weft-taskbar>
</weft-desktop> </weft-desktop>
<weft-launcher hidden id="launcher"> <weft-launcher hidden id="launcher" tabindex="-1" role="dialog" aria-modal="true" aria-label="Apps">
<weft-app-grid id="app-grid"></weft-app-grid> <weft-app-grid id="app-grid"></weft-app-grid>
</weft-launcher> </weft-launcher>
<weft-notification-center id="notifications"></weft-notification-center> <weft-notification-center id="notifications" role="status" aria-live="polite"></weft-notification-center>
<script> <script>
(function () { (function () {
@ -222,27 +240,76 @@
updateClock(); updateClock();
setInterval(updateClock, 10000); setInterval(updateClock, 10000);
document.getElementById('launcher-btn').addEventListener('click', function () {
var launcher = document.getElementById('launcher'); var launcher = document.getElementById('launcher');
if (launcher.hasAttribute('hidden')) { var launcherBtn = document.getElementById('launcher-btn');
var appGrid = document.getElementById('app-grid');
function launcherOpen() {
return !launcher.hasAttribute('hidden');
}
// Opening the launcher moves keyboard focus into it; closing it
// returns focus to the Apps button.
function openLauncher() {
launcher.removeAttribute('hidden'); launcher.removeAttribute('hidden');
launcherBtn.setAttribute('aria-expanded', 'true');
focusInLauncher(null);
if (ws && ws.readyState === WebSocket.OPEN) { if (ws && ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({ type: 'QUERY_INSTALLED_APPS' })); ws.send(JSON.stringify({ type: 'QUERY_INSTALLED_APPS' }));
} }
} else {
launcher.setAttribute('hidden', '');
} }
function closeLauncher() {
if (!launcherOpen()) return;
launcher.setAttribute('hidden', '');
launcherBtn.setAttribute('aria-expanded', 'false');
launcherBtn.focus();
}
// Focuses the icon of `appId`, else the first one, else the dialog.
function focusInLauncher(appId) {
var icons = appGrid.querySelectorAll('.app-icon');
var target = null;
icons.forEach(function (icon) {
if (icon.dataset.appId === appId) target = icon;
});
(target || icons[0] || launcher).focus();
}
launcherBtn.addEventListener('click', function () {
if (launcherOpen()) closeLauncher(); else openLauncher();
}); });
document.addEventListener('keydown', function (e) { document.addEventListener('keydown', function (e) {
if (e.key === 'Escape') { // The compositor brings the shell to the front when a Super key is
document.getElementById('launcher').setAttribute('hidden', ''); // tapped, then delivers the tap here; it opens or closes the
// launcher.
if (e.key === 'Meta' && !e.repeat && !e.altKey && !e.ctrlKey && !e.shiftKey) {
e.preventDefault();
if (launcherOpen()) closeLauncher(); else openLauncher();
} else if (e.key === 'Escape' && launcherOpen()) {
e.preventDefault();
closeLauncher();
} else if (e.key === 'Tab' && launcherOpen()) {
// The launcher is modal: Tab cycles through its apps, and Escape
// leaves it.
var icons = Array.prototype.slice.call(appGrid.querySelectorAll('.app-icon'));
e.preventDefault();
if (icons.length === 0) { launcher.focus(); return; }
var at = icons.indexOf(document.activeElement);
var next = at === -1 ? 0 : (at + (e.shiftKey ? icons.length - 1 : 1)) % icons.length;
icons[next].focus();
} }
}); });
document.getElementById('launcher').addEventListener('click', function (e) { // weft-servo-shell calls this when the shell loses keyboard focus, as
// when an application window is clicked; the launcher closes, so the
// next Super tap opens it.
window.weftShellBlurred = closeLauncher;
launcher.addEventListener('click', function (e) {
if (e.target === this) { if (e.target === this) {
this.setAttribute('hidden', ''); closeLauncher();
} }
}); });
@ -285,7 +352,7 @@
if (ws !== socket) return; if (ws !== socket) return;
wsReconnectDelay = 1000; wsReconnectDelay = 1000;
socket.send(JSON.stringify({ type: 'HELLO', role: 'system', token: endpoint.token })); socket.send(JSON.stringify({ type: 'HELLO', role: 'system', token: endpoint.token }));
document.querySelectorAll('weft-taskbar-app').forEach(function (el) { el.remove(); }); document.querySelectorAll('weft-taskbar-app').forEach(removeEntryElement);
socket.send(JSON.stringify({ type: 'QUERY_RUNNING' })); socket.send(JSON.stringify({ type: 'QUERY_RUNNING' }));
socket.send(JSON.stringify({ type: 'QUERY_INSTALLED_APPS' })); socket.send(JSON.stringify({ type: 'QUERY_INSTALLED_APPS' }));
}); });
@ -347,17 +414,25 @@
} }
function renderLauncher(apps) { function renderLauncher(apps) {
var grid = document.getElementById('app-grid'); var grid = appGrid;
// Replacing the icons would drop keyboard focus; it returns to the
// same app's new icon.
var focused = grid.contains(document.activeElement) ? document.activeElement.dataset.appId : null;
var active = document.activeElement;
var refocus = launcherOpen() && (!active || active === document.body || launcher.contains(active));
grid.innerHTML = ''; grid.innerHTML = '';
if (apps.length === 0) { if (apps.length === 0) {
var empty = document.createElement('p'); var empty = document.createElement('p');
empty.textContent = 'No apps installed'; empty.textContent = 'No apps installed';
empty.style.cssText = 'color:var(--text-secondary);font-size:13px;'; empty.style.cssText = 'color:var(--text-secondary);font-size:13px;';
grid.appendChild(empty); grid.appendChild(empty);
if (refocus) focusInLauncher(null);
return; return;
} }
apps.forEach(function (app) { apps.forEach(function (app) {
var icon = document.createElement('weft-app-icon'); var icon = document.createElement('button');
icon.type = 'button';
icon.className = 'app-icon';
icon.dataset.appId = app.app_id; icon.dataset.appId = app.app_id;
icon.title = app.app_id + (app.version ? ' v' + app.version : ''); icon.title = app.app_id + (app.version ? ' v' + app.version : '');
// Names come from package manifests; they are set as text, never markup. // Names come from package manifests; they are set as text, never markup.
@ -369,14 +444,16 @@
'</text></svg><span></span>'; '</text></svg><span></span>';
icon.querySelector('text').textContent = app.name ? app.name.charAt(0).toUpperCase() : '?'; icon.querySelector('text').textContent = app.name ? app.name.charAt(0).toUpperCase() : '?';
icon.querySelector('span').textContent = app.name || app.app_id; icon.querySelector('span').textContent = app.name || app.app_id;
icon.setAttribute('aria-label', 'Open ' + (app.name || app.app_id));
icon.addEventListener('click', function () { icon.addEventListener('click', function () {
if (ws && ws.readyState === WebSocket.OPEN) { if (ws && ws.readyState === WebSocket.OPEN) {
ws.send(JSON.stringify({ type: 'LAUNCH_APP', app_id: app.app_id, surface_id: 0 })); ws.send(JSON.stringify({ type: 'LAUNCH_APP', app_id: app.app_id, surface_id: 0 }));
} }
document.getElementById('launcher').setAttribute('hidden', ''); closeLauncher();
}); });
grid.appendChild(icon); grid.appendChild(icon);
}); });
if (refocus) focusInLauncher(focused);
} }
// Longer than weft-appd's close timeout, so an app that neither closes // Longer than weft-appd's close timeout, so an app that neither closes
@ -392,13 +469,20 @@
el.id = id; el.id = id;
el.dataset.sessionId = sessionId; el.dataset.sessionId = sessionId;
if (appId) { el.dataset.appId = appId; } if (appId) { el.dataset.appId = appId; }
el.setAttribute('role', 'group');
el.setAttribute('aria-label', label);
el.title = appId ? appId + ' (session ' + sessionId + ')' : 'Session ' + sessionId; el.title = appId ? appId + ' (session ' + sessionId + ')' : 'Session ' + sessionId;
var span = document.createElement('span'); var span = document.createElement('button');
span.type = 'button';
span.className = 'task-activate';
span.textContent = '● ' + label; span.textContent = '● ' + label;
var close = document.createElement('span'); span.setAttribute('aria-label', 'Show ' + label);
var close = document.createElement('button');
close.type = 'button';
close.className = 'task-close'; close.className = 'task-close';
close.textContent = '×'; close.textContent = '×';
close.title = 'Close'; close.title = 'Close';
close.setAttribute('aria-label', 'Close ' + label);
// The first click asks the app to close; it may decline, for example // The first click asks the app to close; it may decline, for example
// to offer saving. An app still running once it has had time to // to offer saving. An app still running once it has had time to
// answer can then be force quit, losing what it has not saved. // answer can then be force quit, losing what it has not saved.
@ -415,7 +499,9 @@
close.dataset.force = '1'; close.dataset.force = '1';
close.textContent = 'Force quit'; close.textContent = 'Force quit';
close.title = 'Force quit: changes the app has not saved are lost'; close.title = 'Force quit: changes the app has not saved are lost';
close.style.color = '#ff6b6b'; close.setAttribute('aria-label', 'Force quit ' + label + '; changes it has not saved are lost');
close.classList.add('force');
showNotification(label + ' did not close; its close button now force quits it');
// Offered only for a while: an app that declined to let the user // Offered only for a while: an app that declined to let the user
// keep working is closed normally next time. // keep working is closed normally next time.
closeTimer = setTimeout(resetClose, FORCE_QUIT_OFFER); closeTimer = setTimeout(resetClose, FORCE_QUIT_OFFER);
@ -428,7 +514,8 @@
delete close.dataset.force; delete close.dataset.force;
close.textContent = '×'; close.textContent = '×';
close.title = 'Close'; close.title = 'Close';
close.style.color = ''; close.setAttribute('aria-label', 'Close ' + label);
close.classList.remove('force');
} }
el.appendChild(span); el.appendChild(span);
el.appendChild(close); el.appendChild(close);
@ -452,13 +539,26 @@
el.dataset.closing = '1'; el.dataset.closing = '1';
el.style.opacity = '0.5'; el.style.opacity = '0.5';
el.title += ' (closing)'; el.title += ' (closing)';
var activate = el.querySelector('.task-activate');
activate.setAttribute('aria-disabled', 'true');
activate.setAttribute('aria-label', activate.getAttribute('aria-label') + ' (closing)');
var close = el.querySelector('.task-close'); var close = el.querySelector('.task-close');
if (close) { close.style.display = 'none'; } if (close) {
if (document.activeElement === close) { activate.focus(); }
close.style.display = 'none';
}
} }
function removeTaskbarEntry(sessionId) { function removeTaskbarEntry(sessionId) {
var el = document.getElementById('task-' + sessionId); var el = document.getElementById('task-' + sessionId);
if (el) { el.remove(); } if (el) { removeEntryElement(el); }
}
// Focus on a removed entry would be lost; it moves to the Apps button.
function removeEntryElement(el) {
var hadFocus = el.contains(document.activeElement);
el.remove();
if (hadFocus) { launcherBtn.focus(); }
} }
function showNotification(text) { function showNotification(text) {

View file

@ -0,0 +1,281 @@
#!/usr/bin/env python3
"""Check that the system UI can be operated with the keyboard alone.
The harness runs weft-servo-shell with the real system UI page
(infra/shell/system-ui.html) and weft-appd with two test applications,
"Blue" and "Red", on a nested desktop (see session.py). Each application
page switches between its colour and a lighter shade on every key press.
Every action below is a key press, apart from one activation request; the
results are observed in weft-appd's lifecycle messages and in the presented
pixels:
- a Super tap brings the shell to the front from an application and opens
the launcher with focus on its first app, in name order; Super pressed
with another key leaves the application in front, and that key reaches it
with the Super modifier, which the application no longer sees once Super
is released;
- Enter opens the focused app, whose window takes keyboard focus; Tab
moves through the launcher's apps;
- Escape closes the launcher and returns focus to the Apps button, from
which Tab reaches each taskbar entry and its close button;
- Enter on a taskbar entry brings its app's window back with keyboard
focus, and Enter on its close button ends its session;
- the launcher closes when the shell loses focus, so the next Super tap
opens it, and a second Super tap closes it, leaving focus on the Apps
button.
The applications are unsigned test packages, recorded as development content
in a private data home, using the Counter demo's component.
"""
import argparse
import shutil
import subprocess
import sys
import tempfile
import time
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
from check_activation import APPS, area # noqa: E402
from check_counter import AppdClient, free_port, read_endpoint # noqa: E402
from session import ROOT, Desktop, SessionError, missing_tools # noqa: E402
BLUE, RED = "org.weft.test.blue", "org.weft.test.red"
NAMES = {BLUE: "Blue", RED: "Red"}
STARTUP_TIMEOUT = 120.0
# The strip weft-servo-shell reserves at the bottom (TASKBAR_HEIGHT).
TASKBAR = 48
def app_page(color, pressed):
"""A page that switches shade on every key press without the Super
(Meta) modifier, so a modifier left held shows as a missed switch."""
return ('<!DOCTYPE html><html><body style="margin:0;width:100vw;height:100vh;'
f'background:rgb{color}"><script>'
'var pressed = false;'
'addEventListener("keydown", function (e) { if (e.metaKey) return;'
'pressed = !pressed;'
f'document.body.style.background = pressed ? "rgb{pressed}" : "rgb{color}"; }});'
'</script></body></html>')
def make_store(store, home):
for app_id, (color, pressed) in APPS.items():
package = store / app_id
(package / "ui").mkdir(parents=True)
(package / "wapp.toml").write_text(
f'[package]\nid = "{app_id}"\nname = "{NAMES[app_id]}"\nversion = "0.1.0"\n'
'[runtime]\nmodule = "app.wasm"\n[ui]\nentry = "ui/index.html"\n')
shutil.copy(ROOT / "examples/org.weft.demo.counter/app.wasm", package / "app.wasm")
(package / "ui/index.html").write_text(app_page(color, pressed))
record = home / "share/weft/owners" / app_id
record.parent.mkdir(parents=True, exist_ok=True)
record.write_text("development\n")
def run(args, desktop, store, home):
t = Path(args.target)
desktop.launch_client("appd", [t / "weft-appd"], {
"WEFT_RUNTIME_BIN": str(t / "weft-runtime"),
"WEFT_APP_SHELL_BIN": str(t / "weft-app-shell"),
"WEFT_APP_STORE": str(store),
"WEFT_DISABLE_CGROUP": "1",
"WEFT_APPD_WS_PORT": str(free_port()),
"HOME": str(home),
"XDG_DATA_HOME": str(home / "share"),
"RUST_LOG": "info,weft_appd::ws=debug",
})
port, token = read_endpoint(desktop.runtime, 30)
appd = AppdClient(port, token)
desktop.launch_client("shell", [args.shell],
{"WEFT_SYSTEM_UI_HTML": str(ROOT / "infra/shell/system-ui.html")})
# This check's client and the system UI page.
deadline = time.monotonic() + 90
while desktop.log_text("appd").count("system client connected") < 2:
if time.monotonic() > deadline:
raise AssertionError("the system UI did not connect to weft-appd")
time.sleep(0.5)
def key(*names):
subprocess.run([args.xdotool, "search", "--class", "weft-compositor",
"windowfocus", "--sync"], env={"DISPLAY": desktop.display},
check=True, timeout=20)
for name in names:
subprocess.run([args.xdotool, "key", name], env={"DISPLAY": desktop.display},
check=True, timeout=20)
time.sleep(0.3)
def colors(shot):
return {c for cs in APPS.values() for c in cs if area(shot, c)[0] is not None}
def shown(app_id, pressed=False):
"""Waits until `app_id` is the visible application, alone on top."""
color = APPS[app_id][1 if pressed else 0]
deadline = time.monotonic() + 20
while time.monotonic() < deadline:
if colors(desktop.capture()) == {color}:
return
time.sleep(0.3)
state = "pressed " if pressed else ""
raise AssertionError(f"{NAMES[app_id]} is not shown {state}on top")
def shell_in_front():
deadline = time.monotonic() + 20
while time.monotonic() < deadline:
if not colors(desktop.capture()):
return
time.sleep(0.3)
raise AssertionError("the shell did not come to the front")
def ready(app_id, timeout=STARTUP_TIMEOUT):
try:
message = appd.wait_for(lambda m: m.get("type") == "APP_READY", timeout)
except TimeoutError:
raise AssertionError(f"{NAMES[app_id]} was not opened")
if message.get("app_id") != app_id:
raise AssertionError(f"expected {NAMES[app_id]} to open, got {message}")
return message["session_id"]
def no_launch(seconds=3):
try:
message = appd.wait_for(lambda m: m.get("type") == "APP_READY", seconds)
except TimeoutError:
return
raise AssertionError(f"an app opened unexpectedly: {message}")
# A Super tap opens the launcher on the first app by name; Enter opens
# it. The page asks for the catalog once connected; until it has
# arrived, Enter finds no app, so the first attempt may be repeated.
for attempt in range(10):
key("Escape", "super", "Return")
try:
appd.wait_for(lambda m: m.get("type") == "LAUNCH_ACK", 5)
break
except TimeoutError:
if attempt == 9:
raise AssertionError("the launcher opened no app")
blue = ready(BLUE)
shown(BLUE)
# The new window has keyboard focus.
key("a")
shown(BLUE, pressed=True)
# Super pressed with another key is not a tap: the key reaches the
# application with the Super modifier, and the shell stays behind it.
key("super+a")
time.sleep(1)
shown(BLUE, pressed=True)
# Once Super is released, the application's keys carry no Super
# modifier, even when another modifier changed while it was held.
xdo = [args.xdotool]
for step in (["keydown", "super"], ["key", "shift"], ["keyup", "super"]):
subprocess.run(xdo + step, env={"DISPLAY": desktop.display}, check=True, timeout=20)
time.sleep(0.3)
shown(BLUE, pressed=True)
key("a")
shown(BLUE)
key("a")
shown(BLUE, pressed=True)
# A Super tap from an application brings the shell and its launcher to
# the front; Tab moves to the next app.
key("super")
shell_in_front()
key("Tab", "Return")
red = ready(RED)
shown(RED)
# Escape closes the launcher, so Tab leaves the Apps button for the
# first taskbar entry rather than an app; Enter activates it.
key("super")
shell_in_front()
key("Escape", "Tab", "Return")
shown(BLUE, pressed=True)
no_launch()
key("a")
shown(BLUE)
# The launcher closes when the shell loses focus, here to an
# activation, so the next Super tap opens it rather than closing it.
key("super")
shell_in_front()
appd.send({"type": "ACTIVATE_APP", "session_id": red})
shown(RED)
key("super")
shell_in_front()
key("Return")
extra = ready(BLUE)
shown(BLUE)
# Tab passes Blue's entry and close button and Red's entry to reach
# Red's close button; Enter ends Red's session.
key("super")
shell_in_front()
key("Escape", "Tab", "Tab", "Tab", "Tab", "Return")
try:
appd.wait_for(lambda m: m.get("type") == "APP_STATE" and m.get("state") == "stopped"
and m.get("session_id") == red, 20)
except TimeoutError:
raise AssertionError("Enter on Red's close button did not end its session")
appd.send({"type": "QUERY_RUNNING"})
running = appd.wait_for(lambda m: m.get("type") == "RUNNING_APPS", 10)
if sorted(s["session_id"] for s in running["sessions"]) != sorted([blue, extra]):
raise AssertionError(f"after closing Red, expected only the Blue sessions: {running}")
# A second Super tap closes the launcher and leaves focus on the Apps
# button: Tab then reaches the first taskbar entry, and Enter shows
# that app instead of opening another.
key("super", "super")
no_launch()
key("Tab", "Return")
shown(BLUE)
no_launch()
def main(argv=None):
parser = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("--compositor", type=Path, default=ROOT / "target/debug/weft-compositor")
parser.add_argument("--shell", type=Path, default=ROOT / "target/debug/weft-servo-shell")
parser.add_argument("--target", type=Path, default=ROOT / "target/debug",
help="directory with weft-appd, weft-runtime and weft-app-shell")
parser.add_argument("--output", type=Path, default=ROOT / "target/system-ui-check")
parser.add_argument("--xdotool", default=shutil.which("xdotool"))
args = parser.parse_args(argv)
if not args.xdotool:
print("missing: xdotool", file=sys.stderr)
return 2
missing = missing_tools() + [str(p) for p in (args.compositor, args.shell,
args.target / "weft-appd",
args.target / "weft-runtime",
args.target / "weft-app-shell")
if not p.is_file()]
if missing:
print("missing: " + ", ".join(missing), file=sys.stderr)
return 2
store = Path(tempfile.mkdtemp(prefix="weft-store-"))
home = Path(tempfile.mkdtemp(prefix="weft-home-"))
try:
make_store(store, home)
with Desktop(args.compositor, args.output,
outputs=["appd.log", "system-ui.ppm"]) as desktop:
try:
run(args, desktop, store, home)
except AssertionError:
(args.output / "system-ui.ppm").write_bytes(desktop.capture())
raise
except (AssertionError, SessionError, TimeoutError) as failure:
print(f"system UI check failed: {failure}", file=sys.stderr)
print(f"logs and capture in {args.output}", file=sys.stderr)
return 1
finally:
shutil.rmtree(store, ignore_errors=True)
shutil.rmtree(home, ignore_errors=True)
print("system UI check passed")
return 0
if __name__ == "__main__":
sys.exit(main())