mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-11-22 08:13:59 +00:00
Merge fix/keyboard-system-navigation: reach and operate the system UI from the keyboard (#33)
This commit is contained in:
commit
3f4545ae66
12 changed files with 616 additions and 105 deletions
|
|
@ -57,7 +57,8 @@ fn named_key(n: NamedKey) -> servo::NamedKey {
|
|||
NamedKey::Control => S::Control,
|
||||
NamedKey::Fn => S::Fn,
|
||||
NamedKey::FnLock => S::FnLock,
|
||||
NamedKey::Meta => S::Meta,
|
||||
// winit names the Super keys Super; the DOM names them Meta.
|
||||
NamedKey::Meta | NamedKey::Super => S::Meta,
|
||||
NamedKey::NumLock => S::NumLock,
|
||||
NamedKey::ScrollLock => S::ScrollLock,
|
||||
NamedKey::Shift => S::Shift,
|
||||
|
|
|
|||
|
|
@ -808,6 +808,9 @@ fn scan_installed_apps() -> Vec<AppInfo> {
|
|||
}
|
||||
}
|
||||
}
|
||||
// A stable order, so the launcher's keyboard order does not follow the
|
||||
// directory listing.
|
||||
apps.sort_by_cached_key(|app| (app.name.to_lowercase(), app.app_id.clone()));
|
||||
apps
|
||||
}
|
||||
|
||||
|
|
@ -1332,23 +1335,42 @@ mod tests {
|
|||
|
||||
let _env = env_lock().blocking_lock();
|
||||
let store = std::env::temp_dir().join(format!("weft_appd_scan_{}", std::process::id()));
|
||||
let app_dir = store.join("com.example.scanner");
|
||||
fs::create_dir_all(&app_dir).unwrap();
|
||||
fs::write(
|
||||
app_dir.join("wapp.toml"),
|
||||
"[package]\nid = \"com.example.scanner\"\nname = \"Scanner\"\nversion = \"1.0.0\"\n\
|
||||
[runtime]\nmodule = \"app.wasm\"\n[ui]\nentry = \"ui/index.html\"\n",
|
||||
)
|
||||
.unwrap();
|
||||
// Listed by name, ignoring case, then by ID, whatever the directory
|
||||
// order.
|
||||
for (id, name) in [
|
||||
("com.example.scanner", "Scanner"),
|
||||
("com.example.zeta", "alpha"),
|
||||
("com.example.second", "Alpha"),
|
||||
("com.example.first", "Alpha"),
|
||||
] {
|
||||
let app_dir = store.join(id);
|
||||
fs::create_dir_all(&app_dir).unwrap();
|
||||
fs::write(
|
||||
app_dir.join("wapp.toml"),
|
||||
format!(
|
||||
"[package]\nid = \"{id}\"\nname = \"{name}\"\nversion = \"1.0.0\"\n\
|
||||
[runtime]\nmodule = \"app.wasm\"\n[ui]\nentry = \"ui/index.html\"\n"
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let prior = std::env::var("WEFT_APP_STORE").ok();
|
||||
unsafe { std::env::set_var("WEFT_APP_STORE", &store) };
|
||||
|
||||
let apps = scan_installed_apps();
|
||||
assert_eq!(apps.len(), 1);
|
||||
assert_eq!(apps[0].app_id, "com.example.scanner");
|
||||
assert_eq!(apps[0].name, "Scanner");
|
||||
assert_eq!(apps[0].version, "1.0.0");
|
||||
let ids: Vec<&str> = apps.iter().map(|a| a.app_id.as_str()).collect();
|
||||
assert_eq!(
|
||||
ids,
|
||||
[
|
||||
"com.example.first",
|
||||
"com.example.second",
|
||||
"com.example.zeta",
|
||||
"com.example.scanner"
|
||||
]
|
||||
);
|
||||
assert_eq!(apps[3].name, "Scanner");
|
||||
assert_eq!(apps[3].version, "1.0.0");
|
||||
|
||||
unsafe {
|
||||
match prior {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use smithay::{
|
|||
TouchEvent,
|
||||
},
|
||||
input::{
|
||||
keyboard::FilterResult,
|
||||
keyboard::{FilterResult, KeyboardTarget},
|
||||
pointer::{AxisFrame, ButtonEvent, MotionEvent},
|
||||
},
|
||||
utils::{Logical, Point, SERIAL_COUNTER},
|
||||
|
|
@ -42,41 +42,97 @@ pub fn process_input_event<B: InputBackend>(state: &mut WeftCompositorState, eve
|
|||
}
|
||||
}
|
||||
|
||||
/// What the compositor does with a key instead of forwarding it.
|
||||
enum Shortcut {
|
||||
/// Alt+F4: close the focused application window.
|
||||
Close,
|
||||
/// A Super key tap: show the shell.
|
||||
Shell,
|
||||
/// Nothing: a suppressed key.
|
||||
None,
|
||||
}
|
||||
|
||||
fn handle_keyboard<B: InputBackend>(state: &mut WeftCompositorState, event: B::KeyboardKeyEvent) {
|
||||
use smithay::backend::input::KeyState;
|
||||
use smithay::input::keyboard::keysyms;
|
||||
|
||||
let serial = SERIAL_COUNTER.next_serial();
|
||||
let time = event.time_msec();
|
||||
let key_state = event.state();
|
||||
let Some(keyboard) = state.seat.get_keyboard() else {
|
||||
return;
|
||||
};
|
||||
|
||||
if let Some(keyboard) = state.seat.get_keyboard() {
|
||||
// Alt+F4 belongs to the compositor: it asks the focused application
|
||||
// window to close, and the key never reaches a client.
|
||||
let close = keyboard.input::<bool, _>(
|
||||
state,
|
||||
event.key_code(),
|
||||
key_state,
|
||||
serial,
|
||||
time,
|
||||
|state, mods, keysym| {
|
||||
// A release is taken only when its press was, so no client
|
||||
// sees half of a key.
|
||||
let code = keysym.raw_code().raw();
|
||||
if key_state == smithay::backend::input::KeyState::Pressed {
|
||||
if mods.alt
|
||||
&& keysym.modified_sym() == smithay::input::keyboard::keysyms::KEY_F4.into()
|
||||
{
|
||||
state.suppressed_keys.push(code);
|
||||
return FilterResult::Intercept(true);
|
||||
}
|
||||
} else if let Some(i) = state.suppressed_keys.iter().position(|&k| k == code) {
|
||||
state.suppressed_keys.remove(i);
|
||||
return FilterResult::Intercept(false);
|
||||
// Alt+F4 and the Super keys belong to the compositor. Alt+F4 asks the
|
||||
// focused application window to close. Super's key events are never
|
||||
// delivered to an application: tapped alone, without another key or a
|
||||
// button, it brings the shell's panel to the front with keyboard focus
|
||||
// and is then delivered to the shell, which opens or closes its
|
||||
// launcher. Held, it still sets the Super modifier for other keys.
|
||||
let (filtered, mods_changed) = keyboard.input_intercept::<_, _>(
|
||||
state,
|
||||
event.key_code(),
|
||||
key_state,
|
||||
|state, mods, keysym| {
|
||||
// A release is taken only when its press was, so no client
|
||||
// sees half of a key.
|
||||
let code = keysym.raw_code().raw();
|
||||
let sym = keysym.modified_sym();
|
||||
if key_state == KeyState::Pressed {
|
||||
if mods.alt && sym == keysyms::KEY_F4.into() {
|
||||
state.super_tap = None;
|
||||
state.suppressed_keys.push(code);
|
||||
return FilterResult::Intercept(Shortcut::Close);
|
||||
}
|
||||
FilterResult::Forward
|
||||
},
|
||||
);
|
||||
if close == Some(true) {
|
||||
state.close_focused_window();
|
||||
if sym == keysyms::KEY_Super_L.into() || sym == keysyms::KEY_Super_R.into() {
|
||||
state.super_tap = (!mods.ctrl && !mods.alt && !mods.shift).then_some(code);
|
||||
state.suppressed_keys.push(code);
|
||||
return FilterResult::Intercept(Shortcut::None);
|
||||
}
|
||||
state.super_tap = None;
|
||||
} else if let Some(i) = state.suppressed_keys.iter().position(|&k| k == code) {
|
||||
state.suppressed_keys.remove(i);
|
||||
if state.super_tap.take() == Some(code) {
|
||||
return FilterResult::Intercept(Shortcut::Shell);
|
||||
}
|
||||
return FilterResult::Intercept(Shortcut::None);
|
||||
}
|
||||
FilterResult::Forward
|
||||
},
|
||||
);
|
||||
let shortcut = match filtered {
|
||||
FilterResult::Forward => {
|
||||
keyboard.input_forward(
|
||||
state,
|
||||
event.key_code(),
|
||||
key_state,
|
||||
serial,
|
||||
time,
|
||||
mods_changed,
|
||||
);
|
||||
return;
|
||||
}
|
||||
FilterResult::Intercept(shortcut) => shortcut,
|
||||
};
|
||||
// The focused client follows the modifiers even when the key that
|
||||
// changed them is taken, so none stays held there.
|
||||
if mods_changed && let Some(focus) = keyboard.current_focus() {
|
||||
let seat = state.seat.clone();
|
||||
focus.modifiers(&seat, state, keyboard.modifier_state(), serial);
|
||||
}
|
||||
match shortcut {
|
||||
Shortcut::Close => state.close_focused_window(),
|
||||
Shortcut::Shell => {
|
||||
if state.activate_panel() {
|
||||
// The tap itself, for the shell; the keyboard's own state
|
||||
// already saw it.
|
||||
let code = event.key_code();
|
||||
keyboard.input_forward(state, code, KeyState::Pressed, serial, time, false);
|
||||
let release = SERIAL_COUNTER.next_serial();
|
||||
keyboard.input_forward(state, code, KeyState::Released, release, time, false);
|
||||
}
|
||||
}
|
||||
Shortcut::None => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -144,8 +200,10 @@ fn handle_pointer_button<B: InputBackend>(
|
|||
let button_state = event.state();
|
||||
|
||||
// On press: activate the window under the pointer, which raises an
|
||||
// application window and focuses it.
|
||||
// application window and focuses it. A held Super key is then no
|
||||
// longer a tap.
|
||||
if button_state == ButtonState::Pressed {
|
||||
state.super_tap = None;
|
||||
let pointer_location = state.pointer_location;
|
||||
let window = state
|
||||
.space
|
||||
|
|
@ -221,6 +279,7 @@ fn handle_pointer_axis<B: InputBackend>(
|
|||
}
|
||||
|
||||
fn handle_touch_down<B: InputBackend>(state: &mut WeftCompositorState, event: B::TouchDownEvent) {
|
||||
state.super_tap = None;
|
||||
let serial = SERIAL_COUNTER.next_serial();
|
||||
let output = state.space.outputs().next().cloned();
|
||||
if let Some(output) = output {
|
||||
|
|
|
|||
|
|
@ -101,6 +101,9 @@ pub struct WeftCompositorState {
|
|||
/// Keycodes whose press a compositor shortcut took, so their release is
|
||||
/// taken as well and no client sees half of a key.
|
||||
pub suppressed_keys: Vec<u32>,
|
||||
/// The Super key held down while no other key was pressed since; its
|
||||
/// release is a tap that opens the shell.
|
||||
pub super_tap: Option<u32>,
|
||||
|
||||
pub compositor_state: CompositorState,
|
||||
pub xdg_shell_state: XdgShellState,
|
||||
|
|
@ -200,6 +203,7 @@ impl WeftCompositorState {
|
|||
running: true,
|
||||
gesture_state: GestureState::default(),
|
||||
suppressed_keys: Vec::new(),
|
||||
super_tap: None,
|
||||
#[cfg(unix)]
|
||||
appd_ipc: None,
|
||||
#[cfg(target_os = "linux")]
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@
|
|||
//! 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.
|
||||
//! included, which then shows the shell's home over the applications), one
|
||||
//! appd asks to activate and the panel when a Super key is tapped are
|
||||
//! 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;
|
||||
|
|
@ -58,6 +58,31 @@ impl WeftCompositorState {
|
|||
}
|
||||
}
|
||||
|
||||
/// Activates the shell's panel; returns whether one is registered. With
|
||||
/// several, the first registered is the shell's.
|
||||
pub fn activate_panel(&mut self) -> bool {
|
||||
let panel = self
|
||||
.weft_shell_state
|
||||
.panels()
|
||||
.filter(|p| p.is_alive())
|
||||
.find_map(|panel| {
|
||||
let surface = panel
|
||||
.data::<WeftShellWindowData>()
|
||||
.and_then(|data| data.surface.clone())?;
|
||||
self.space
|
||||
.elements()
|
||||
.find(|window| window.wl_surface().is_some_and(|s| *s == surface))
|
||||
.cloned()
|
||||
});
|
||||
match panel {
|
||||
Some(panel) => {
|
||||
self.activate_window(&panel);
|
||||
true
|
||||
}
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Asks the focused application window to close. Its client decides
|
||||
/// how to end; for an app shell that ends the session. The panel is not
|
||||
/// closed this way.
|
||||
|
|
|
|||
|
|
@ -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<ServoWake> 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);
|
||||
|
|
|
|||
|
|
@ -57,7 +57,8 @@ fn named_key(n: NamedKey) -> servo::NamedKey {
|
|||
NamedKey::Control => S::Control,
|
||||
NamedKey::Fn => S::Fn,
|
||||
NamedKey::FnLock => S::FnLock,
|
||||
NamedKey::Meta => S::Meta,
|
||||
// winit names the Super keys Super; the DOM names them Meta.
|
||||
NamedKey::Meta | NamedKey::Super => S::Meta,
|
||||
NamedKey::NumLock => S::NumLock,
|
||||
NamedKey::ScrollLock => S::ScrollLock,
|
||||
NamedKey::Shift => S::Shift,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
python3 tests/frame/check_update.py # updates leave running sessions on their revision; failed updates, rollback and uninstall
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -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; 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.
|
||||
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. Such a client registered as a panel would also be raised and focused by a Super tap; the compositor picks the first panel registered.
|
||||
|
||||
## JavaScript Engine (SpiderMonkey)
|
||||
|
||||
|
|
|
|||
|
|
@ -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 @@
|
|||
<weft-desktop>
|
||||
<weft-wallpaper></weft-wallpaper>
|
||||
<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"
|
||||
xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
||||
<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"
|
||||
fill="rgba(255,255,255,0.7)" />
|
||||
</svg>
|
||||
</weft-taskbar-launcher>
|
||||
</button>
|
||||
<weft-taskbar-clock id="clock"></weft-taskbar-clock>
|
||||
</weft-taskbar>
|
||||
</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-launcher>
|
||||
<weft-notification-center id="notifications"></weft-notification-center>
|
||||
<weft-notification-center id="notifications" role="status" aria-live="polite"></weft-notification-center>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
|
|
@ -222,27 +240,76 @@
|
|||
updateClock();
|
||||
setInterval(updateClock, 10000);
|
||||
|
||||
document.getElementById('launcher-btn').addEventListener('click', function () {
|
||||
var launcher = document.getElementById('launcher');
|
||||
if (launcher.hasAttribute('hidden')) {
|
||||
launcher.removeAttribute('hidden');
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({ type: 'QUERY_INSTALLED_APPS' }));
|
||||
}
|
||||
} else {
|
||||
launcher.setAttribute('hidden', '');
|
||||
var launcher = document.getElementById('launcher');
|
||||
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');
|
||||
launcherBtn.setAttribute('aria-expanded', 'true');
|
||||
focusInLauncher(null);
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({ type: 'QUERY_INSTALLED_APPS' }));
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
if (e.key === 'Escape') {
|
||||
document.getElementById('launcher').setAttribute('hidden', '');
|
||||
// The compositor brings the shell to the front when a Super key is
|
||||
// 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) {
|
||||
this.setAttribute('hidden', '');
|
||||
closeLauncher();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -285,7 +352,7 @@
|
|||
if (ws !== socket) return;
|
||||
wsReconnectDelay = 1000;
|
||||
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_INSTALLED_APPS' }));
|
||||
});
|
||||
|
|
@ -347,17 +414,25 @@
|
|||
}
|
||||
|
||||
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 = '';
|
||||
if (apps.length === 0) {
|
||||
var empty = document.createElement('p');
|
||||
empty.textContent = 'No apps installed';
|
||||
empty.style.cssText = 'color:var(--text-secondary);font-size:13px;';
|
||||
grid.appendChild(empty);
|
||||
if (refocus) focusInLauncher(null);
|
||||
return;
|
||||
}
|
||||
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.title = app.app_id + (app.version ? ' v' + app.version : '');
|
||||
// Names come from package manifests; they are set as text, never markup.
|
||||
|
|
@ -369,14 +444,16 @@
|
|||
'</text></svg><span></span>';
|
||||
icon.querySelector('text').textContent = app.name ? app.name.charAt(0).toUpperCase() : '?';
|
||||
icon.querySelector('span').textContent = app.name || app.app_id;
|
||||
icon.setAttribute('aria-label', 'Open ' + (app.name || app.app_id));
|
||||
icon.addEventListener('click', function () {
|
||||
if (ws && ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(JSON.stringify({ type: 'LAUNCH_APP', app_id: app.app_id, surface_id: 0 }));
|
||||
}
|
||||
document.getElementById('launcher').setAttribute('hidden', '');
|
||||
closeLauncher();
|
||||
});
|
||||
grid.appendChild(icon);
|
||||
});
|
||||
if (refocus) focusInLauncher(focused);
|
||||
}
|
||||
|
||||
// Longer than weft-appd's close timeout, so an app that neither closes
|
||||
|
|
@ -392,13 +469,20 @@
|
|||
el.id = id;
|
||||
el.dataset.sessionId = sessionId;
|
||||
if (appId) { el.dataset.appId = appId; }
|
||||
el.setAttribute('role', 'group');
|
||||
el.setAttribute('aria-label', label);
|
||||
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;
|
||||
var close = document.createElement('span');
|
||||
span.setAttribute('aria-label', 'Show ' + label);
|
||||
var close = document.createElement('button');
|
||||
close.type = 'button';
|
||||
close.className = 'task-close';
|
||||
close.textContent = '×';
|
||||
close.title = 'Close';
|
||||
close.setAttribute('aria-label', 'Close ' + label);
|
||||
// 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
|
||||
// answer can then be force quit, losing what it has not saved.
|
||||
|
|
@ -415,7 +499,9 @@
|
|||
close.dataset.force = '1';
|
||||
close.textContent = 'Force quit';
|
||||
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
|
||||
// keep working is closed normally next time.
|
||||
closeTimer = setTimeout(resetClose, FORCE_QUIT_OFFER);
|
||||
|
|
@ -428,7 +514,8 @@
|
|||
delete close.dataset.force;
|
||||
close.textContent = '×';
|
||||
close.title = 'Close';
|
||||
close.style.color = '';
|
||||
close.setAttribute('aria-label', 'Close ' + label);
|
||||
close.classList.remove('force');
|
||||
}
|
||||
el.appendChild(span);
|
||||
el.appendChild(close);
|
||||
|
|
@ -452,13 +539,26 @@
|
|||
el.dataset.closing = '1';
|
||||
el.style.opacity = '0.5';
|
||||
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');
|
||||
if (close) { close.style.display = 'none'; }
|
||||
if (close) {
|
||||
if (document.activeElement === close) { activate.focus(); }
|
||||
close.style.display = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
function removeTaskbarEntry(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) {
|
||||
|
|
|
|||
281
tests/frame/check_system_ui.py
Normal file
281
tests/frame/check_system_ui.py
Normal 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())
|
||||
Loading…
Reference in a new issue