diff --git a/crates/weft-servo-shell/src/embedder.rs b/crates/weft-servo-shell/src/embedder.rs index ffc5ab1..60026fe 100644 --- a/crates/weft-servo-shell/src/embedder.rs +++ b/crates/weft-servo-shell/src/embedder.rs @@ -296,12 +296,25 @@ impl App { self.next_endpoint_check, )); 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; }; - // 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 .url() .is_some_and(|url| same_document(url.as_str(), self.url.as_str())) @@ -313,9 +326,8 @@ impl App { format!( "window === window.top && \ location.href.split('#')[0] === {document} && \ - typeof window.weftAppdEndpoint === 'function' && \ - window.weftAppdEndpoint({}, '{}')", - endpoint.port, endpoint.token + typeof window.{name} === 'function' && \ + {call}" ), |_| {}, ); @@ -494,6 +506,11 @@ impl ApplicationHandler for App { WindowEvent::ModifiersChanged(mods) => { 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, .. } => { if let Some(wv) = &self.webview { let ev = super::keyutils::keyboard_event_from_winit(&event, self.modifiers); diff --git a/docs/architecture.md b/docs/architecture.md index 1207cd4..9aa77f3 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -8,11 +8,11 @@ WEFT OS is a Wayland compositor and application runtime where every app is a Web ### weft-compositor -Smithay-based Wayland compositor. Implements the `zweft-shell-unstable-v1` protocol extension, which allows shell clients (servo-shell, app-shell) to register their surfaces as typed shell slots. Each application session's Wayland connection is handed to the compositor by weft-appd, which binds the client to that session (see `security.md`). The compositor owns stacking and focus: the system shell's panel is sized to the output and starts beneath application windows, and clicking it brings it to the front as the shell's home, with its launcher, until an application is activated 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 -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 diff --git a/docs/building.md b/docs/building.md index 9ca5f22..981c5ee 100644 --- a/docs/building.md +++ b/docs/building.md @@ -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_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_system_ui.py # the system UI's launcher and taskbar work from the keyboard alone, reached with a Super tap ``` ## Demo apps (wasm32-wasip2) diff --git a/infra/shell/system-ui.html b/infra/shell/system-ui.html index 4d0b5eb..2d49b94 100644 --- a/infra/shell/system-ui.html +++ b/infra/shell/system-ui.html @@ -14,6 +14,7 @@ --text-primary: rgba(255, 255, 255, 0.92); --text-secondary: rgba(255, 255, 255, 0.55); --accent: #5b8af5; + --focus-ring: #9db8ff; } *, *::before, *::after { @@ -63,19 +64,30 @@ -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; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 8px; - cursor: pointer; - background: transparent; - transition: background 0.15s; } - weft-taskbar-launcher:hover { + #launcher-btn:hover { background: var(--surface-border); } @@ -111,55 +123,56 @@ margin: 0 auto; } - weft-app-icon { + .app-icon { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 8px; border-radius: 12px; - cursor: pointer; color: var(--text-primary); font-size: 12px; text-align: center; word-break: break-word; - transition: background 0.15s; } - weft-app-icon:hover { + .app-icon:hover { background: var(--surface-border); } - weft-app-icon svg { + .app-icon svg { flex-shrink: 0; } weft-taskbar-app { display: inline-flex; align-items: center; - gap: 4px; + gap: 2px; font-size: 12px; color: var(--text-secondary); - padding: 0 4px 0 6px; - cursor: pointer; border-radius: 6px; - transition: background 0.15s; } weft-taskbar-app:hover { background: var(--surface-border); } + weft-taskbar-app .task-activate { + padding: 4px 2px 4px 6px; + border-radius: 6px; + } + weft-taskbar-app .task-close { opacity: 0; font-size: 11px; line-height: 1; - padding: 1px 3px; + padding: 3px 4px; 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; } @@ -167,6 +180,10 @@ background: rgba(255,80,80,0.3); } + weft-taskbar-app .task-close.force { + color: #ff6b6b; + } + weft-notification-center { position: fixed; top: 8px; @@ -188,7 +205,8 @@ - + -