S046: smoke harness in a hidden nested niri, real selftest input, local media in the sandbox
- tools/nested-session.sh (Xvfb -> nested niri, own display/runtime dir, xresize for SMOKE_SIZE); smoke.sh and hidden.sh run in it; wl-input moved to tools/wl-input (own crate) - selftest: click/rclick/pagescroll via wl-input, pagetype via wtype, resize via the nested niri - WebKit sandbox: XDG user dirs (+ test pages in scripted runs) read-only so file:// media plays (D-043) - SMOKE_VISIBLE needs the user's niri window rule, never moves focus (D-044) - launch, basics, input, keys, chrome green hidden Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
parent
4eeb72a25a
commit
b7d1dbcc2f
16 changed files with 764 additions and 72 deletions
|
|
@ -54,7 +54,7 @@ Never modify: `~/Documents/Apps/Nacre` (the original Python Nacre, reference onl
|
|||
|
||||
- **Builds**: `nice cargo build --release -j 2` only. The first build takes hours (Servo, SpiderMonkey, WebRender). Never run `cargo test` at the same time as a release build, and never run two cargo commands on the same `target/`.
|
||||
- Servo needs clang. Start from Servo's own lock versions to avoid pre-release drift (rsa/pkcs1).
|
||||
- Run apps offscreen or in a hidden nested session (`kwin_wayland --virtual`) unless the user asked to watch. VMs have no real GPU: use software rendering there.
|
||||
- Run apps in the hidden nested session (`tools/nested-session.sh`: Xvfb → nested niri, software GL; `kwin_wayland` isn't installed) unless the user asked to watch. Xvfb has no DRI3, so clients there use `LIBGL_ALWAYS_SOFTWARE=1 WEBKIT_DMABUF_RENDERER_FORCE_SHM=1 GSK_RENDERER=gl` (the session's `env` file sets them). VMs have no real GPU: use software rendering there.
|
||||
- Never connect to Tor or proxies in tests; `NACRE_NO_BRIDGE=1` disables the bridge for debugging.
|
||||
- Servo 0.7 can't add request headers, block third-party cookies, do per-WebView private mode, EME/DRM, printing: don't try, see DESIGN.md.
|
||||
- Several painters on one GL context (one per tab) is unproven; the fallback is in DESIGN.md.
|
||||
|
|
@ -67,7 +67,7 @@ Never modify: `~/Documents/Apps/Nacre` (the original Python Nacre, reference onl
|
|||
| `nice cargo build --release -j 2` | compile check, produces `target/release/nacre` | now |
|
||||
| `nice cargo test --release -j 2` | unit tests (44, ~16 s test-profile build then <1 s run; shares the S001 build) (util, settings, history, bookmarks, permissions, vault, dns, bridge loopback, download, adblock, keys, scripts, updates, inject, hub, theme, ui::widgets input, ui::paint, ui::pages::newtab) | first successful build; not alongside a build |
|
||||
| `src/selftest.rs` | in-app self test: `NACRE_SCRIPT=<file>` runs script commands (listed at its top) | now |
|
||||
| `tools/smoke.sh <script> [outdir]` | smoke run on a hidden Xvfb display with a throwaway home and software GL; outdir (default `target/smoke/<name>-<time>`) gets `nacre.log`, `selftest.log`, `<shot>.png`, `<status>.json`, `home/`; exits non-zero on crash, panic, no `status done` or a failed `assert <js>`. Scripts in `tests/smoke/` (`launch.txt` offline, `https.txt` needs internet, `restore.txt` with `SMOKE_HOME=<launch outdir>/home`, `chrome.txt` chrome and every flyout dark and light, offline; `colours.txt` colours after welcome and site colour vs internal pages, hidden `SMOKE_SIZE=1280x1100`; `input.txt` real clicks, typing, right click, wheel on a web page, offline; `basics.txt` tabs, navigation, find, zoom, full screen, pop-ups, offline; `heavy-web.txt` DuckDuckGo, Wikipedia, YouTube, needs internet, `SMOKE_TIMEOUT=900`; `keys.txt` every shortcut action, offline; `privacy-net.txt` DNT/GPC/Save-Data headers and third-party cookies on a loopback server, offline, start `python3 tests/smoke/net/server.py &` first; `site-doctor.txt` Google sign-in, captchas, Reddit, GitHub, needs internet; `cache.txt` HTTP cache, offline, start `python3 tests/smoke/cache/server.py &` first; selftest `launch <args>` checks single instance; `cookies.txt` → `cookies-restart.txt` → `cookies-cleared.txt` encrypted cookies across restarts with `SMOKE_KEYRING=1` (own throwaway GNOME Keyring + bus) and `SMOKE_HOME`, `cookies-nokeyring.txt` without, server.py first; `crash-adblock.txt` R5-01 regression, ~1300 blocked loads with reloads/navigations mid-load plus 3200 timers under GC pressure, offline, server.py first); header documents env vars and commands. `SMOKE_VISIBLE=1` shows the run on the user's screen (DP-1, real GPU, niri tiles the window so shots are narrower); use it whenever the user is watching (D-009). Read the PNGs | now (S003) |
|
||||
| `tools/smoke.sh <script> [outdir]` | smoke run in a hidden nested Wayland session (`tools/nested-session.sh start\|stop <dir> [WxH]`: Xvfb → nested niri, software GL, own runtime dir and bus; `SMOKE_SIZE` = nested output size, window at 0,0) with a throwaway home; selftest `click`/`rclick`/`pagescroll`/`pagetype` are real compositor input there (`tools/wl-input`, own crate, built on first use; `wtype`), `resize` goes through the nested niri; outdir (default `target/smoke/<name>-<time>`, use a fresh one: `home/` persists) gets `nacre.log`, `selftest.log`, `<shot>.png`, `<status>.json`, `home/`, `session/`; exits non-zero on crash, panic, no `status done` or a failed `assert <js>`. Scripts in `tests/smoke/` (`launch.txt` offline, `https.txt` needs internet, `restore.txt` with `SMOKE_HOME=<launch outdir>/home`, `chrome.txt` chrome and every flyout dark and light, offline; `colours.txt` colours after welcome and site colour vs internal pages, hidden `SMOKE_SIZE=1280x1100`; `input.txt` real clicks, typing, right click, wheel on a web page, offline; `basics.txt` tabs, navigation, find, zoom, full screen, pop-ups, offline; `heavy-web.txt` DuckDuckGo, Wikipedia, YouTube, needs internet, `SMOKE_TIMEOUT=900`; `keys.txt` every shortcut action, offline; `privacy-net.txt` DNT/GPC/Save-Data headers and third-party cookies on a loopback server, offline, start `python3 tests/smoke/net/server.py &` first; `site-doctor.txt` Google sign-in, captchas, Reddit, GitHub, needs internet; `cache.txt` HTTP cache, offline, start `python3 tests/smoke/cache/server.py &` first; selftest `launch <args>` checks single instance; `cookies.txt` → `cookies-restart.txt` → `cookies-cleared.txt` encrypted cookies across restarts with `SMOKE_KEYRING=1` (own throwaway GNOME Keyring + bus) and `SMOKE_HOME`, `cookies-nokeyring.txt` without, server.py first; `crash-adblock.txt` R5-01 regression, ~1300 blocked loads with reloads/navigations mid-load plus 3200 timers under GC pressure, offline, server.py first); header documents env vars and commands. `SMOKE_VISIBLE=1` shows the run on the user's screen (real GPU; page input synthesized in the page, no `rclick`/`resize`); it refuses to start unless the user's niri config has the `dev.nacre.Nacre` window rule from the smoke.sh header (DP-1, no focus), so it never moves the user's focus or workspace (D-044). WebKit state (S046): launch, basics, input, keys, chrome ported; other scripts not yet; loopback-server smokes need `NACRE_NO_BRIDGE=1` until S050. Read the PNGs | now (S003, S046) |
|
||||
| `nacre://gallery` + `SMOKE_SIZE=1400x2800 tools/smoke.sh tests/smoke/gallery.txt` | every design token and widget, dark and light (+ new tab and settings shots); read the PNGs | now (S015) |
|
||||
| `SMOKE_SIZE=1400x1200 tools/smoke.sh tests/smoke/newtab.txt` | new tab page dark/light, nothing playing and a video playing, weather failed state, tall/narrow/phone widths (offline); `tests/smoke/newtab-weather.txt` shoots the real weather card (needs internet); read the PNGs | now (S017) |
|
||||
| `SMOKE_SIZE=1400x900 tools/smoke.sh tests/smoke/backgrounds.txt` | every new tab background with the pointer, Customize panel dark/light, image + blur, GIF frames; `perf-*-a/b.json` `frames` (median/max draw ms, `drawn` count) per background at Lots/Fast, hidden tab, still, Motion off. Selftest `pointer x y`, `customize`; `@PAGESDIR@` = path of tests/smoke/pages | now (S018) |
|
||||
|
|
@ -79,7 +79,7 @@ Never modify: `~/Documents/Apps/Nacre` (the original Python Nacre, reference onl
|
|||
| `tools/smoke.sh tests/smoke/privacy-mode.txt` (+ `SMOKE_ARGS=--incognito … privacy-incognito.txt`) | privacy mode: `pages/fingerprint.html` read off/on, `fp-off.json`/`fp-on.json` + shots (offline); `privacy-net.txt` (needs `tests/smoke/net/server.py`) frame cookies, per-site pause, Accept-Language; `SMOKE_TIMEOUT=700 … coveryourtracks.txt` EFF's test off/on (internet, direct). Selftest `save <name> <js>` writes a JS string result to `<name>.json`; `SMOKE_ARGS` passes browser arguments | now (S024) |
|
||||
| `python tools/icons.py` | rebuilds the icon font subset and `src/ui/icons.rs` from `tools/icons.txt` (needs fontTools and Arch's ttf-material-symbols-variable) | now (S015) |
|
||||
| `tools/engine-test/run.sh servo\|chromium\|webkit` + `analyze.py` | engine comparison: one browser visible on DP-1, throwaway profile, sites from `sites.txt`, per-second RAM (PSS), CPU, GPU of the whole process tree into `docs/engine/runs/<engine>/samples.csv`; `webkit_shell.py` is the WebKitGTK 6.0 shell (needs `webkitgtk-6.0`); report `docs/engine/engine-comparison.md`. Never run two at once or alongside cargo | now |
|
||||
| `tools/hidden.sh <script> [outdir] [-- driver.sh]` | WebKit build hidden: Xvfb → nested niri (`spikes/webkit-egui/run/nested.sh`), throwaway home, software GL, `NACRE_SCRIPT`; the driver gets `click`/`scroll` (wl-input), `grab` (grim), `key`/`type` (wtype). Scripts in `tests/hidden/` (`basic.txt` offline; `web.txt` + `web-driver.sh` needs internet). Read the PNGs | now (S045) |
|
||||
| `tools/hidden.sh <script> [outdir] [-- driver.sh]` | WebKit build hidden with a driver script: Xvfb → nested niri (`tools/nested-session.sh`), throwaway home, software GL, `NACRE_SCRIPT`; the driver gets `click`/`scroll` (`tools/wl-input`), `grab` (grim), `key`/`type` (wtype). Scripts in `tests/hidden/` (`basic.txt` offline; `web.txt` + `web-driver.sh` needs internet). Read the PNGs | now (S045) |
|
||||
| appimagetool, wine + Inno Setup, VM "Windows 10" | packaging and Windows checks | see the user's global CLAUDE.md "Building" |
|
||||
|
||||
Don't assume a tool exists: check first. When your plan creates a tool, add its row here.
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@ basic scripts green.
|
|||
- `tools/smoke.sh` (whole), `src/selftest.rs` header + command dispatcher, `spikes/webkit-egui/run/{nested.sh,spike.sh}`, `docs/engine/webkit-spike.md` "How it was run".
|
||||
|
||||
## Steps
|
||||
- [ ] `tools/nested-session.sh start|stop` (Xvfb + niri, config from the spike, throwaway runtime dir, env file) and `smoke.sh` using it instead of a bare Xvfb; keep throwaway HOME/XDG, keyring, fake Discord, `SMOKE_HOME`, `SMOKE_ARGS`, `SMOKE_SIZE` (niri output size via config `mode`), `SMOKE_TIMEOUT`.
|
||||
- [ ] Move `wl-input` into the main crate as `src/bin/wl-input.rs` (wayland-client deps in `[dev-dependencies]`/bin-only) or keep it a tiny separate crate under `tools/`; document it.
|
||||
- [ ] selftest: `shot` via `grim` on the nested output (or a GTK snapshot of the window); `click`/`rclick`/`pagetype`/`pagescroll` via real input (wl-input/wtype) when available, else GTK synthesized events; `js`/`assert`/`save` over `evaluate_javascript` → `serde_json`.
|
||||
- [ ] Make `launch.txt`, `basics.txt`, `input.txt`, `keys.txt`, `chrome.txt` green hidden (fix the app where they fail, script only where the check is Servo-specific).
|
||||
- [ ] `SMOKE_VISIBLE=1` path documented and syntax-checked (not run while the user sleeps, D-034).
|
||||
- [ ] CLAUDE.md §5 smoke row rewritten (nested niri, software GL, env); §4 pitfalls: drop Xvfb-only notes.
|
||||
- [ ] PROGRESS entry, INDEX line, tracker, commit `S046: …`, push.
|
||||
- [x] `tools/nested-session.sh start|stop` (Xvfb + niri, config from the spike, throwaway runtime dir, env file) and `smoke.sh` using it instead of a bare Xvfb; keep throwaway HOME/XDG, keyring, fake Discord, `SMOKE_HOME`, `SMOKE_ARGS`, `SMOKE_SIZE` (niri output size via config `mode`), `SMOKE_TIMEOUT`.
|
||||
- [x] Move `wl-input` into the main crate as `src/bin/wl-input.rs` (wayland-client deps in `[dev-dependencies]`/bin-only) or keep it a tiny separate crate under `tools/`; document it.
|
||||
- [x] selftest: `shot` via `grim` on the nested output (or a GTK snapshot of the window); `click`/`rclick`/`pagetype`/`pagescroll` via real input (wl-input/wtype) when available, else GTK synthesized events; `js`/`assert`/`save` over `evaluate_javascript` → `serde_json`.
|
||||
- [x] Make `launch.txt`, `basics.txt`, `input.txt`, `keys.txt`, `chrome.txt` green hidden (fix the app where they fail, script only where the check is Servo-specific).
|
||||
- [x] `SMOKE_VISIBLE=1` path documented and syntax-checked (not run while the user sleeps, D-034).
|
||||
- [x] CLAUDE.md §5 smoke row rewritten (nested niri, software GL, env); §4 pitfalls: drop Xvfb-only notes.
|
||||
- [x] PROGRESS entry, INDEX line, tracker, commit `S046: …`, push.
|
||||
|
||||
## End criteria
|
||||
- `tools/smoke.sh tests/smoke/launch.txt` (and basics, input, keys, chrome) exit 0 hidden; shots Read.
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ download manager stubs, HTTP cache on disk.
|
|||
- [ ] TLS errors → Nacre's certificate warning page; "continue" allows the cert for the host for the run.
|
||||
- [ ] Error pages from Nacre's look (port `assets/servo/neterror.html`/`badcert.html` style into `nacre://` pages).
|
||||
- [ ] `CookieManager` accept policy (third-party), `set_preferred_languages`, privacy mode Accept-Language, per-view UA quirk.
|
||||
- [ ] Loopback/127.0.0.1 and localhost bypass the bridge (today a loopback page ends in "Message was restarted too many times" with the URL rewritten to the bridge port; found in S046); regression smoke.
|
||||
- [ ] Smoke (start `python3 tests/smoke/net/server.py &` / `cache/server.py &`): `net-privacy.txt`, `net-downloads.txt`, `privacy-net.txt`, `privacy-mode.txt`, `cache.txt` + `cache-restart.txt` green hidden.
|
||||
- [ ] PROGRESS entry, INDEX line, tracker, commit `S050: …`, push.
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ Engine switch to WebKit (D-032): new category `08 WebKit engine` comes first; Se
|
|||
## 08 WebKit engine
|
||||
- [x] [S044 — Engine seam: pure logic out of the Servo files](08%20WebKit%20engine/S044-engine-seam.md) · Opus medium
|
||||
- [x] [S045 — GTK 4 host with the egui overlay; WebKitGTK views; Servo out of the build](08%20WebKit%20engine/S045-gtk-host.md) · Opus high
|
||||
- [ ] [S046 — Smoke harness and selftest on the GTK host (hidden nested niri)](08%20WebKit%20engine/S046-smoke-harness.md) · Opus medium
|
||||
- [x] [S046 — Smoke harness and selftest on the GTK host (hidden nested niri)](08%20WebKit%20engine/S046-smoke-harness.md) · Opus medium
|
||||
- [ ] [S047 — Page scripts, page messages, find and JS on WebKit](08%20WebKit%20engine/S047-page-channel.md) · Opus medium
|
||||
- [ ] [S048 — WebKit UI callbacks: pop-ups, dialogs, menus, permissions, full screen, inspector, PiP](08%20WebKit%20engine/S048-ui-callbacks.md) · Opus high
|
||||
- [ ] [S049 — Ad blocker on WebKit: content filters + web process extension](08%20WebKit%20engine/S049-adblock-webext.md) · Opus high
|
||||
|
|
|
|||
|
|
@ -46,3 +46,5 @@
|
|||
- D-040 — 2026-11-13 — WebKit tuning defaults (D-032 data, `docs/engine/tune/`): page cache off, memory pressure limit 500 MB per web process, cache model `DocumentViewer`, hardware acceleration policy default (on demand; `never` broke JS checks), related views only for pop-ups. Env overrides for tests (`NACRE_WK_PAGE_CACHE`, `NACRE_WK_MEM_LIMIT`, `NACRE_WK_CACHE_MODEL`, `NACRE_WK_HW`). — lowest PSS/VRAM in the tune runs without failed sites — S052
|
||||
- D-041 — 2026-11-13 — S044 boxes 3–5 (Nacre `ViewId`, engine-neutral `Event` payload types, selftest on them) move to S045 and are defined directly on WebKit; S044 closes with the privacy/policy move. — converting 56 Servo payload uses and 14 `WebViewId` sites now would only add Servo adapters that S045/S048 delete — orchestrator, 2026-11-13 — S044, S045
|
||||
- D-042 — 2026-11-13 — S045 GTK host: the WebKit build ports page controls instead of stubbing them (script dialogs, `<select>`, colour, file, HTTP auth, permissions, context menu from WebKit's hit test, notifications); Bluetooth chooser and protocol-handler prompts are removed (WebKit has neither); picture in picture shows "isn't available yet" until S047; one `UserContentManager` per view so page messages carry their `ViewId` (bridge posts to `window.webkit.messageHandlers.nacre`); cookies stay in WebKit's memory until S051 (`Keeping::RunOnly`); downloads come from the response policy (non-displayable main-frame MIME) plus `looks_like_download`, the Servo download probe is gone; WebKit data/cache under `<profile data>/webkit` and `<cache>/webkit`; views sit in a `Gtk.Overlay` placed by margins (a `Gtk.Fixed` size request grew the window); prefers-color-scheme follows GTK's dark preference set by Nacre (its own changes ignored by the system-scheme watcher); with no desktop font DPI (`gtk-xft-dpi` -1) Nacre sets 96 dpi, else WebKit gives every view after the first a NaN zoom (blank page).
|
||||
- D-043 — 2026-11-13 — Local media and WebKit's sandbox: the web process sandbox (bwrap) has no /home, so GStreamer can't read file:// media. Nacre adds the XDG user folders that exist (Downloads, Videos, Music, Pictures, Desktop, Documents; never the home folder itself) read-only with `WebContext::add_path_to_sandbox` before the first web process, plus `tests/smoke/pages` read-only only when `NACRE_SCRIPT` is set (`engine::host::media_dirs`). file:// media elsewhere doesn't play. — Chromium plays local files; all of $HOME would let a web process read ~/.ssh — orchestrator (option A), 2026-11-13 — S050/S051 media and downloads, any sandbox change
|
||||
- D-044 — 2026-11-13 — Supersedes D-034 while the user allows it: visible test runs on the user's niri session (DP-1) are allowed ("you can run real tests on my niri session"), for what hidden runs can't prove (GPU/dmabuf path, 60 fps, video playback); everything else stays hidden. A visible run never switches the user's workspace, maximizes or steals focus; if the window can't open that way it stays hidden. `tools/smoke.sh` no longer focuses a monitor and starts `SMOKE_VISIBLE=1` only when the user's niri config has the window rule `match app-id="^dev\.nacre\.Nacre$"; open-on-output "DP-1"; open-focused false` (added by the user, not by a session). — user via orchestrator, 2026-11-13 — every plan with visible checks
|
||||
|
|
|
|||
|
|
@ -365,7 +365,17 @@ Later: S010 list: user checks the Discord icon with their own client (the Discor
|
|||
- Stubbed for S047/S048: picture in picture (toast), selftest `rclick`/`pagescroll`/`pagetype` via page JS, request policy `net::policy::decide` and ad-block request blocking not wired (cosmetic/page scripts only), cookie persistence (S051), `Shortcut` per-app window class, console messages.
|
||||
- Later: Wikipedia stays light with Nacre dark: prefers-color-scheme does follow Nacre (checked), Wikipedia's own Appearance shows "Light" (its default); system dark detection may still be polluted by Nacre's own prefer-dark. `navigation_action().frame_name()` is the target name, not "subframe" — check iframe navigations don't reach `on_navigation` as main-frame (S047/S048).
|
||||
|
||||
## S046 — Smoke harness and selftest on the GTK host (2026-11-13)
|
||||
- Done: `tools/nested-session.sh start|stop <dir> [WxH]` (Xvfb → nested niri, own X display/runtime dir/env, several at once; `tools/lib/xresize.py` sizes niri's winit window since it ignores `mode`); `tools/smoke.sh` runs in it with its own bus always (keyring still opt-in); `tools/wl-input/` own crate (built on first use); `tools/hidden.sh` on the same pieces.
|
||||
- Selftest: hidden runs send `click`/`rclick`/`pagescroll` through wl-input and `pagetype` through wtype (script waits for each helper); `resize` asks the nested niri; shots stay GTK snapshots.
|
||||
- Fixed: local video didn't play (web process sandbox has no /home): XDG user dirs + test pages read-only (D-043, `media_dirs` test); `input.html` form cancels its submit (a real Enter navigated and lost the counter).
|
||||
- Verified hidden, fresh outdirs: launch, basics, input, keys, chrome exit 0, shots read; `hidden.sh basic.txt` green; `cargo test` 74; no `dev.nacre.Nacre` window on the user's niri in 152 samples.
|
||||
- Not done: no visible run. The user's niri config has no window rule for `dev.nacre.Nacre`, so a window would take focus; smoke.sh now refuses visible runs without the rule (D-044). Other smoke scripts not ported (each moves with its feature's plan).
|
||||
- Found: loopback http goes through the bridge and fails ("restarted too many times") → S050 box; use `NACRE_NO_BRIDGE=1` for loopback smokes until then.
|
||||
|
||||
## Later
|
||||
- file:// media outside the XDG user folders doesn't play (WebKit sandbox, D-043).
|
||||
- Visible runs need the user to add the niri window rule for `dev.nacre.Nacre` (tools/smoke.sh header, D-044).
|
||||
- Turnstile widget paints as a black half-disc (Servo painting of its iframe/shadow DOM, S006 site doctor).
|
||||
- Google sign-in past the email step: press Next with a real account, by the user (S006).
|
||||
- Bookmark flyout stays open after switching tabs and shows the old page's bookmark (S006 keys.txt shot).
|
||||
|
|
|
|||
|
|
@ -71,6 +71,10 @@ impl Engine {
|
|||
Some(p) => webkit::WebContext::builder().memory_pressure_settings(p).build(),
|
||||
None => webkit::WebContext::new(),
|
||||
};
|
||||
// The web process sandbox has no /home: GStreamer there can't read a file:// video or song (D-043).
|
||||
for dir in media_dirs(std::env::var_os("NACRE_SCRIPT").is_some()) {
|
||||
context.add_path_to_sandbox(&dir, true);
|
||||
}
|
||||
context.set_cache_model(match env("NACRE_WK_CACHE_MODEL").as_deref() {
|
||||
Some("browser") => webkit::CacheModel::WebBrowser,
|
||||
Some("docbrowser") => webkit::CacheModel::DocumentBrowser,
|
||||
|
|
@ -400,3 +404,33 @@ impl Engine {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Folders the web process may read (read only), so local media in them plays: the XDG user folders that exist (never
|
||||
/// the home folder itself), plus the smoke test pages in scripted runs (D-043).
|
||||
fn media_dirs(selftest: bool) -> Vec<std::path::PathBuf> {
|
||||
let home = dirs::home_dir();
|
||||
let mut found: Vec<std::path::PathBuf> = [dirs::download_dir(), dirs::video_dir(), dirs::audio_dir(), dirs::picture_dir(), dirs::desktop_dir(), dirs::document_dir()]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter(|d| d.is_dir() && Some(d) != home.as_ref() && d.parent().is_some())
|
||||
.collect();
|
||||
if selftest {
|
||||
found.push(std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/smoke/pages"));
|
||||
}
|
||||
found.dedup();
|
||||
found
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::media_dirs;
|
||||
|
||||
#[test]
|
||||
fn media_dirs_never_home() {
|
||||
let home = dirs::home_dir();
|
||||
let dirs = media_dirs(true);
|
||||
assert!(dirs.iter().all(|d| Some(d) != home.as_ref() && d.as_os_str() != "/"));
|
||||
assert!(dirs.iter().any(|d| d.ends_with("tests/smoke/pages")));
|
||||
assert!(!media_dirs(false).iter().any(|d| d.ends_with("tests/smoke/pages")));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
108
src/selftest.rs
108
src/selftest.rs
|
|
@ -7,7 +7,7 @@
|
|||
//! open <url> load in the current tab newtab <url> open in a new tab
|
||||
//! page <nacre://...> show an internal page
|
||||
//! shot <name> [pip] save the window (or the picture-in-picture window) as <name>.png
|
||||
//! resize <w> <h> resize the window (logical pixels)
|
||||
//! resize <w> <h> resize the window (logical pixels; in the hidden session through niri)
|
||||
//! status <name> save tabs, downloads, VPN, ad blocker and so on as <name>.json
|
||||
//! set <json pointer> <json> change a setting, e.g. `set /privacy/https_only true`
|
||||
//! perm <host> <kind> allow|block|default store a site's answer for a permission (kinds: store::permissions::Kind keys)
|
||||
|
|
@ -32,8 +32,10 @@
|
|||
//! assert <js expression> the expression must give true, else `ASSERT FAILED` in the log fails the smoke run
|
||||
//! expect <pointer> <json> a value of the `status` JSON must equal json (e.g. `expect /tabs/1/pinned true`;
|
||||
//! `/active/...` is the active tab, `/tab_count` the number of tabs; `> n` a number above n)
|
||||
//! click <x> <y> click in the page at CSS-ish pixel x,y (from the page's top left), through the
|
||||
//! window's input path; `rclick` the same with the right button (context menu)
|
||||
//! click <x> <y> click in the page at CSS pixel x,y (from the page's top left); `rclick` the same with
|
||||
//! the right button (context menu). With NACRE_WL_INPUT (tools/wl-input, hidden runs of
|
||||
//! tools/smoke.sh) `click`, `rclick`, `pagescroll` and `pagetype` are real compositor input
|
||||
//! (wl-input pointer, wtype keyboard); without it they are synthesized in the page (no rclick)
|
||||
//! locate <css selector> find the first visible matching element, scroll it into view; `click @` / `rclick @` then click its centre
|
||||
//! pagescroll <x> <y> <dy> turn the wheel over the page at x,y (as `click`) by dy pixels (positive: down)
|
||||
//! pagetype <text> type text into the page, if it has keyboard focus (after a `click` in a field);
|
||||
|
|
@ -66,6 +68,9 @@ use crate::tabs::Page;
|
|||
use crate::ui::Flyout;
|
||||
use crate::window::Kind;
|
||||
|
||||
/// tools/wl-input, set by tools/smoke.sh in hidden runs: page input goes through the compositor then.
|
||||
static WL_INPUT: std::sync::LazyLock<Option<String>> = std::sync::LazyLock::new(|| std::env::var("NACRE_WL_INPUT").ok().filter(|p| !p.is_empty()));
|
||||
|
||||
pub struct SelfTest {
|
||||
lines: Vec<String>,
|
||||
next: usize,
|
||||
|
|
@ -84,6 +89,8 @@ pub struct SelfTest {
|
|||
wait_js: Option<(String, Instant)>,
|
||||
/// (an evaluation is in flight, the last one gave true)
|
||||
js_poll: std::sync::Arc<std::sync::Mutex<(bool, bool)>>,
|
||||
/// A real input helper (wl-input, wtype) still sending; the script goes on once it exits.
|
||||
input: Option<std::process::Child>,
|
||||
}
|
||||
|
||||
impl SelfTest {
|
||||
|
|
@ -92,7 +99,7 @@ impl SelfTest {
|
|||
let text = std::fs::read_to_string(&path).ok()?;
|
||||
let dir = path.parent().map(|p| p.to_owned()).unwrap_or_else(|| PathBuf::from("."));
|
||||
let lines = text.lines().map(|l| l.trim().to_owned()).filter(|l| !l.is_empty() && !l.starts_with('#')).collect();
|
||||
Some(SelfTest { lines, next: 0, wait_until: None, wait_load_until: None, dir, pending_shot: false, pending_release: None, held: None, located: Default::default(), wait_js: None, js_poll: Default::default() })
|
||||
Some(SelfTest { lines, next: 0, wait_until: None, wait_load_until: None, dir, pending_shot: false, pending_release: None, held: None, located: Default::default(), wait_js: None, js_poll: Default::default(), input: None })
|
||||
}
|
||||
|
||||
fn log(&self, text: &str) {
|
||||
|
|
@ -115,6 +122,18 @@ impl App {
|
|||
}
|
||||
test.wait_until = None;
|
||||
}
|
||||
if let Some(child) = test.input.as_mut() {
|
||||
match child.try_wait() {
|
||||
Ok(None) => return,
|
||||
Ok(Some(status)) if !status.success() => test.log(&format!("ASSERT FAILED: input helper exited with {status}")),
|
||||
Ok(Some(_)) => {},
|
||||
Err(error) => test.log(&format!("ASSERT FAILED: input helper: {error}")),
|
||||
}
|
||||
test.input = None;
|
||||
// Let the page handle what the compositor delivered.
|
||||
test.wait_until = Some(Instant::now() + Duration::from_millis(100));
|
||||
continue;
|
||||
}
|
||||
if let Some(pos) = test.pending_release.take() {
|
||||
test.wait_until = Some(Instant::now() + Duration::from_millis(150));
|
||||
if let Some(win) = self.windows.get_mut(&window) {
|
||||
|
|
@ -236,6 +255,16 @@ impl App {
|
|||
let mut size = rest.split_whitespace().filter_map(|v| v.parse::<u32>().ok());
|
||||
if let (Some(w), Some(h), Some(win)) = (size.next(), size.next(), self.windows.get(&window)) {
|
||||
win.window.set_default_size(w as i32, h as i32);
|
||||
// The hidden session's niri tiles the window and picks its size: ask it (NIRI_SOCKET is the
|
||||
// nested niri's, set by tools/smoke.sh).
|
||||
if std::env::var_os("NIRI_SOCKET").is_some() {
|
||||
for (action, value) in [("set-column-width", w), ("set-window-height", h)] {
|
||||
let status = std::process::Command::new("niri").args(["msg", "action", action, &value.to_string()]).status();
|
||||
if !status.is_ok_and(|s| s.success()) {
|
||||
self.selftest_log(&format!("resize: niri msg action {action} failed"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"status" => {
|
||||
|
|
@ -466,9 +495,12 @@ impl App {
|
|||
// Turn the wheel over the page at x,y (page pixels, as `click`) by dy pixels (scripted through the page).
|
||||
let mut parts = rest.split_whitespace().filter_map(|p| p.parse::<f64>().ok());
|
||||
let (x, y, dy) = (parts.next().unwrap_or(0.0), parts.next().unwrap_or(0.0), parts.next().unwrap_or(0.0));
|
||||
// WebKit takes the page's input straight from GTK; scripted runs scroll through the page itself
|
||||
// (real pointer input comes from the hidden harness's wl-input).
|
||||
let _ = (x, y);
|
||||
// Hidden runs turn the compositor's wheel (wl-input, about 100 px a notch); elsewhere the page scrolls itself.
|
||||
if WL_INPUT.is_some() && let Some((ox, oy)) = self.selftest_output_point(window, x, y) {
|
||||
let notches = (dy / 100.0).round().abs().max(1.0).copysign(dy) as i32;
|
||||
self.selftest_wl_input(&["scroll".into(), ox.to_string(), oy.to_string(), notches.to_string()]);
|
||||
return;
|
||||
}
|
||||
match self.windows.get(&window).and_then(|w| w.active_webview()) {
|
||||
Some(web) => web.evaluate_javascript(format!("window.scrollBy(0, {dy})"), |_| {}),
|
||||
None => self.selftest_log("pagescroll: no web page in this tab"),
|
||||
|
|
@ -511,8 +543,13 @@ impl App {
|
|||
}
|
||||
let mut parts = rest.split_whitespace().filter_map(|p| p.parse::<f64>().ok());
|
||||
let (x, y) = located.unwrap_or((parts.next().unwrap_or(0.0), parts.next().unwrap_or(0.0)));
|
||||
// WebKit takes the page's input straight from GTK; scripted runs click through the page's DOM
|
||||
// (real pointer input comes from the hidden harness's wl-input). No page menu from here yet.
|
||||
// Hidden runs click with the compositor's pointer (wl-input), so the page gets real GTK input; elsewhere
|
||||
// (SMOKE_VISIBLE, never the user's pointer) the click is synthesized in the page's DOM.
|
||||
if WL_INPUT.is_some() && let Some((ox, oy)) = self.selftest_output_point(window, x, y) {
|
||||
let button = if verb == "rclick" { "right" } else { "left" };
|
||||
self.selftest_wl_input(&["click".into(), ox.to_string(), oy.to_string(), button.into()]);
|
||||
return;
|
||||
}
|
||||
match self.windows.get(&window).and_then(|w| w.active_webview()) {
|
||||
Some(web) if verb == "click" => {
|
||||
let script = format!("(() => {{ const e = document.elementFromPoint({x}, {y}); if (!e) return false; if (e.focus) e.focus(); for (const t of ['pointerdown', 'mousedown', 'pointerup', 'mouseup']) e.dispatchEvent(new MouseEvent(t, {{bubbles: true, cancelable: true, clientX: {x}, clientY: {y}}})); e.click(); return true; }})()");
|
||||
|
|
@ -521,7 +558,7 @@ impl App {
|
|||
win.focus_page();
|
||||
}
|
||||
},
|
||||
Some(_) => self.selftest_log("rclick: not available with WebKit yet (S047)"),
|
||||
Some(_) => self.selftest_log("rclick: needs real input (a hidden run)"),
|
||||
None => self.selftest_log("click: no web page in this tab"),
|
||||
}
|
||||
},
|
||||
|
|
@ -529,6 +566,27 @@ impl App {
|
|||
// Type text into the focused web page.
|
||||
// Typed into the focused element through the DOM (as `click`); `{enter}` submits its form.
|
||||
match self.windows.get(&window).filter(|w| w.page_focused && !w.tab().is_some_and(|t| t.dialog.is_some())).and_then(|w| w.active_webview()) {
|
||||
// Hidden runs type with the compositor's keyboard (wtype).
|
||||
Some(_) if WL_INPUT.is_some() => {
|
||||
let mut args = Vec::new();
|
||||
for (i, part) in rest.split('{').enumerate() {
|
||||
let (key, text) = match part.split_once('}') {
|
||||
Some((key, text)) if i > 0 => (Some(key), text),
|
||||
_ => (None, part),
|
||||
};
|
||||
match key {
|
||||
Some("enter") => args.extend(["-k".to_owned(), "Return".to_owned()]),
|
||||
Some("escape") => args.extend(["-k".to_owned(), "Escape".to_owned()]),
|
||||
Some(other) => args.push(format!("{{{other}}}")),
|
||||
None => {},
|
||||
}
|
||||
// (wtype reads text starting with '-' as an option)
|
||||
if !text.is_empty() {
|
||||
args.push(text.to_owned());
|
||||
}
|
||||
}
|
||||
self.selftest_spawn("wtype", &args);
|
||||
},
|
||||
Some(web) => {
|
||||
let enter = rest.contains("{enter}");
|
||||
let text = rest.replace("{enter}", "").replace("{escape}", "");
|
||||
|
|
@ -697,6 +755,36 @@ impl App {
|
|||
}
|
||||
}
|
||||
|
||||
/// A page point (CSS px from the page's top left, as `click`) on the nested output: the window fills the output
|
||||
/// from its top left corner in the hidden session (niri, no gaps).
|
||||
fn selftest_output_point(&self, window: WindowId, x: f64, y: f64) -> Option<(i32, i32)> {
|
||||
let win = self.windows.get(&window)?;
|
||||
let zoom = win.tab().map_or(1.0, |t| t.zoom);
|
||||
let point = gtk::graphene::Point::new(x as f32 * zoom, y as f32 * zoom);
|
||||
let at = win.active_webview()?.widget().compute_point(&win.window, &point)?;
|
||||
Some((at.x().round() as i32, at.y().round() as i32))
|
||||
}
|
||||
|
||||
fn selftest_wl_input(&mut self, args: &[String]) {
|
||||
let Some(program) = WL_INPUT.as_ref() else { return };
|
||||
let output = std::env::var("NACRE_WL_OUTPUT").unwrap_or_else(|_| "-".to_owned());
|
||||
let args: Vec<String> = std::iter::once(output).chain(args.iter().cloned()).collect();
|
||||
self.selftest_spawn(program, &args);
|
||||
}
|
||||
|
||||
/// Run an input helper; the script waits for it to exit.
|
||||
fn selftest_spawn(&mut self, program: &str, args: &[String]) {
|
||||
self.selftest_log(&format!("input: {program} {}", args.join(" ")));
|
||||
match std::process::Command::new(program).args(args).stdin(std::process::Stdio::null()).spawn() {
|
||||
Ok(child) => {
|
||||
if let Some(t) = self.selftest.as_mut() {
|
||||
t.input = Some(child);
|
||||
}
|
||||
},
|
||||
Err(error) => self.selftest_log(&format!("ASSERT FAILED: {program}: {error}")),
|
||||
}
|
||||
}
|
||||
|
||||
fn selftest_log(&self, text: &str) {
|
||||
if let Some(t) = self.selftest.as_ref() {
|
||||
t.log(text);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,6 @@
|
|||
<a id="link" href="#clicked" onclick="window.clicks = (window.clicks || 0) + 1">Click me</a>
|
||||
<input id="field" type="text">
|
||||
<div id="menu" style="width: 300px; height: 60px; background: #ccd" oncontextmenu="window.menus = (window.menus || 0) + 1">Right-click here</div>
|
||||
<form id="form" action="#submitted" onsubmit="window.submits = (window.submits || 0) + 1"><input id="query" name="q" type="text"></form>
|
||||
<form id="form" action="#submitted" onsubmit="window.submits = (window.submits || 0) + 1; return false"><input id="query" name="q" type="text"></form>
|
||||
<textarea id="area" onkeydown="window.keys = (window.keys || []).concat([event.key + ':' + event.keyCode + ':' + event.code])"></textarea>
|
||||
<div style="height: 3000px"></div>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#!/bin/bash
|
||||
# Hidden run of the WebKit Nacre (S045): Xvfb -> nested niri (spikes/webkit-egui/run/nested.sh) -> target/release/nacre
|
||||
# Hidden run of the WebKit Nacre (S045): Xvfb -> nested niri (tools/nested-session.sh) -> target/release/nacre
|
||||
# with a throwaway home, software GL, and a NACRE_SCRIPT selftest script (see src/selftest.rs).
|
||||
#
|
||||
# tools/hidden.sh <script> [outdir] [-- driver.sh]
|
||||
|
|
@ -17,21 +17,21 @@ name=$(basename "$script" .txt)
|
|||
out=${1:-$root/target/hidden/$name-$(date +%Y%m%d-%H%M%S)}; [ $# -gt 0 ] && shift
|
||||
driver=""; [ "${1:-}" = "--" ] && driver=$2
|
||||
mkdir -p "$out"; out=$(cd "$out" && pwd)
|
||||
export SPIKE_RUN=$out/session
|
||||
mkdir -p "$SPIKE_RUN"
|
||||
session=$out/session
|
||||
sed -e "s|@PAGES@|file://$root/tests/smoke/pages|g" -e "s|@PAGESDIR@|$root/tests/smoke/pages|g" "$script" >"$out/script.txt"
|
||||
"$root/spikes/webkit-egui/run/nested.sh" start >"$out/nested.log" 2>&1
|
||||
trap '"$root/spikes/webkit-egui/run/nested.sh" stop' EXIT
|
||||
source "$SPIKE_RUN/env"
|
||||
ln -sfn "$HOME" "$out/home"
|
||||
export LIBGL_ALWAYS_SOFTWARE=1 WEBKIT_DMABUF_RENDERER_FORCE_SHM=1 GSK_RENDERER=gl GTK_A11Y=none NO_AT_BRIDGE=1 GDK_DEBUG=no-portals
|
||||
"$root/tools/nested-session.sh" start "$session" >"$out/nested.log" 2>&1 || { cat "$out/nested.log"; exit 1; }
|
||||
trap '"$root/tools/nested-session.sh" stop "$session"' EXIT
|
||||
source "$session/env"
|
||||
export HOME=$out/home XDG_CONFIG_HOME=$out/home/.config XDG_CACHE_HOME=$out/home/.cache XDG_DATA_HOME=$out/home/.local/share
|
||||
mkdir -p "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME" "$XDG_DATA_HOME"
|
||||
W=$root/tools/wl-input/target/release/wl-input
|
||||
[ -x "$W" ] || nice cargo build --release -q --manifest-path "$root/tools/wl-input/Cargo.toml"
|
||||
export RUST_BACKTRACE=1 NACRE_SCRIPT=$out/script.txt
|
||||
dbus-run-session -- "$root/target/release/nacre" >"$out/nacre.log" 2>&1 &
|
||||
pid=$!
|
||||
if [ -n "$driver" ]; then
|
||||
(
|
||||
export OUT=$out WL_INPUT_FLIP_Y=1
|
||||
W=$root/spikes/webkit-egui/target/release/wl-input
|
||||
export OUT=$out
|
||||
click() { "$W" winit click "$@"; }
|
||||
scroll() { "$W" winit scroll "$@"; }
|
||||
grab() { grim "$OUT/$1.png"; }
|
||||
|
|
|
|||
29
tools/lib/xresize.py
Normal file
29
tools/lib/xresize.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
"""Resize every mapped top-level window of an X display (Xvfb has no window manager): xresize.py :N W H.
|
||||
|
||||
tools/nested-session.sh uses it to give niri's winit output the requested size. Plain ctypes over libX11.
|
||||
"""
|
||||
import ctypes
|
||||
import sys
|
||||
|
||||
x = ctypes.CDLL("libX11.so.6")
|
||||
x.XOpenDisplay.restype = ctypes.c_void_p
|
||||
x.XOpenDisplay.argtypes = [ctypes.c_char_p]
|
||||
x.XDefaultRootWindow.restype = ctypes.c_ulong
|
||||
x.XDefaultRootWindow.argtypes = [ctypes.c_void_p]
|
||||
x.XQueryTree.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.POINTER(ctypes.c_ulong), ctypes.POINTER(ctypes.c_ulong),
|
||||
ctypes.POINTER(ctypes.POINTER(ctypes.c_ulong)), ctypes.POINTER(ctypes.c_uint)]
|
||||
x.XResizeWindow.argtypes = [ctypes.c_void_p, ctypes.c_ulong, ctypes.c_uint, ctypes.c_uint]
|
||||
x.XSync.argtypes = [ctypes.c_void_p, ctypes.c_int]
|
||||
x.XCloseDisplay.argtypes = [ctypes.c_void_p]
|
||||
|
||||
display, w, h = sys.argv[1], int(sys.argv[2]), int(sys.argv[3])
|
||||
d = x.XOpenDisplay(display.encode())
|
||||
if not d:
|
||||
sys.exit(f"xresize: can't open {display}")
|
||||
root, parent, children, n = ctypes.c_ulong(), ctypes.c_ulong(), ctypes.POINTER(ctypes.c_ulong)(), ctypes.c_uint()
|
||||
x.XQueryTree(d, x.XDefaultRootWindow(d), ctypes.byref(root), ctypes.byref(parent), ctypes.byref(children), ctypes.byref(n))
|
||||
for i in range(n.value):
|
||||
x.XResizeWindow(d, children[i], w, h)
|
||||
x.XSync(d, 0)
|
||||
x.XCloseDisplay(d)
|
||||
print(f"xresize: {n.value} window(s) to {w}x{h}")
|
||||
97
tools/nested-session.sh
Executable file
97
tools/nested-session.sh
Executable file
|
|
@ -0,0 +1,97 @@
|
|||
#!/bin/bash
|
||||
# Hidden nested Wayland session for tests (D-034/D-035): Xvfb -> niri (winit backend, an X11 client of Xvfb) -> a
|
||||
# private Wayland socket with the protocols the user's niri has (wlr virtual pointer, virtual keyboard for wtype,
|
||||
# input-method-v2, screencopy for grim). Nothing appears on the user's screen; everything renders with llvmpipe.
|
||||
#
|
||||
# tools/nested-session.sh start <dir> [WxH] start; writes <dir>/env (source it in clients), logs, pid files
|
||||
# tools/nested-session.sh stop <dir> stop it and remove its runtime dir
|
||||
#
|
||||
# WxH (default 1280x800) is the nested output's size (scale 1). Several sessions can run at once (own X display, own runtime
|
||||
# dir). <dir>/env exports WAYLAND_DISPLAY, XDG_RUNTIME_DIR, NIRI_SOCKET (so `niri msg` talks to the nested niri,
|
||||
# never the user's) and the software-GL variables clients need: Xvfb has no DRI3, so the nested niri can't import
|
||||
# GPU dmabufs and clients must render with software GL / shared memory too.
|
||||
set -u
|
||||
cmd=${1:?usage: nested-session.sh start|stop <dir> [WxH]}
|
||||
dir=${2:?usage: nested-session.sh start|stop <dir> [WxH]}
|
||||
mkdir -p "$dir"; dir=$(cd "$dir" && pwd)
|
||||
case $cmd in
|
||||
start)
|
||||
size=${3:-1280x800}
|
||||
w=${size%x*} h=${size#*x}
|
||||
# The socket path must stay short (SUN_LEN), so the runtime dir lives in /run/user/<uid>.
|
||||
rt=$(mktemp -d "/run/user/$(id -u)/ns-XXXXXX") || exit 1
|
||||
chmod 700 "$rt"
|
||||
echo "$rt" >"$dir/runtime"
|
||||
# niri's winit window opens at 1280x800 and ignores an output `mode`; xresize.py resizes it (Xvfb has no
|
||||
# window manager to refuse), so the X screen is made a bit larger than the output.
|
||||
exec 3<>"$dir/display"
|
||||
Xvfb -displayfd 3 -screen 0 "$((w + 64))x$((h + 64))x24" -nolisten tcp -noreset >"$dir/xvfb.log" 2>&1 &
|
||||
echo $! >"$dir/xvfb.pid"
|
||||
display=
|
||||
for _ in $(seq 50); do display=$(head -n1 "$dir/display" 2>/dev/null); [ -n "$display" ] && break; sleep 0.1; done
|
||||
exec 3>&-
|
||||
[ -n "$display" ] || { echo "nested-session: Xvfb did not start (see $dir/xvfb.log)" >&2; exit 1; }
|
||||
cat >"$dir/niri.kdl" <<KDL
|
||||
input {
|
||||
keyboard {
|
||||
xkb {
|
||||
layout "us"
|
||||
}
|
||||
}
|
||||
}
|
||||
prefer-no-csd
|
||||
hotkey-overlay {
|
||||
skip-at-startup
|
||||
}
|
||||
screenshot-path null
|
||||
animations {
|
||||
off
|
||||
}
|
||||
layout {
|
||||
gaps 0
|
||||
border {
|
||||
off
|
||||
}
|
||||
focus-ring {
|
||||
off
|
||||
}
|
||||
default-column-width {
|
||||
proportion 1.0
|
||||
}
|
||||
}
|
||||
KDL
|
||||
env -i PATH="$PATH" HOME="$dir" XDG_RUNTIME_DIR="$rt" DISPLAY=":$display" LIBGL_ALWAYS_SOFTWARE=1 RUST_LOG=warn \
|
||||
niri -c "$dir/niri.kdl" >"$dir/niri.log" 2>&1 &
|
||||
echo $! >"$dir/niri.pid"
|
||||
wl=
|
||||
for _ in $(seq 75); do wl=$(ls "$rt" 2>/dev/null | grep -m1 '^wayland-[0-9]*$'); [ -n "$wl" ] && break; sleep 0.2; done
|
||||
[ -n "$wl" ] || { echo "nested-session: niri did not start (see $dir/niri.log)" >&2; "$0" stop "$dir"; exit 1; }
|
||||
sock=$(ls -d "$rt"/niri*.sock 2>/dev/null | head -n1)
|
||||
if [ "$size" != 1280x800 ]; then
|
||||
python3 -I "$(dirname "$0")/lib/xresize.py" ":$display" "$w" "$h" >>"$dir/niri.log" 2>&1
|
||||
for _ in $(seq 50); do
|
||||
env XDG_RUNTIME_DIR="$rt" NIRI_SOCKET="$sock" niri msg outputs 2>/dev/null | grep -q "Logical size: ${w}x${h}" && break
|
||||
sleep 0.1
|
||||
done
|
||||
fi
|
||||
cat >"$dir/env" <<ENV
|
||||
export XDG_RUNTIME_DIR=$rt WAYLAND_DISPLAY=$wl NIRI_SOCKET=$sock GDK_BACKEND=wayland XDG_SESSION_TYPE=wayland
|
||||
export LIBGL_ALWAYS_SOFTWARE=1 WEBKIT_DMABUF_RENDERER_FORCE_SHM=1 GSK_RENDERER=gl GTK_A11Y=none NO_AT_BRIDGE=1 GDK_DEBUG=no-portals
|
||||
export WL_INPUT_FLIP_Y=1
|
||||
unset DISPLAY SWAYSOCK
|
||||
ENV
|
||||
echo "nested-session: :$display wayland=$wl runtime=$rt";;
|
||||
stop)
|
||||
for p in niri xvfb; do
|
||||
[ -f "$dir/$p.pid" ] && kill "$(cat "$dir/$p.pid")" 2>/dev/null
|
||||
done
|
||||
for p in niri xvfb; do
|
||||
[ -f "$dir/$p.pid" ] && tail --pid="$(cat "$dir/$p.pid")" -f /dev/null 2>/dev/null &
|
||||
done
|
||||
wait
|
||||
rm -f "$dir/niri.pid" "$dir/xvfb.pid"
|
||||
rt=$(cat "$dir/runtime" 2>/dev/null)
|
||||
case $rt in /run/user/*/ns-*) rm -rf "$rt";; esac
|
||||
rm -f "$dir/runtime";;
|
||||
*) echo "usage: nested-session.sh start|stop <dir> [WxH]" >&2; exit 2;;
|
||||
esac
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
# Smoke run: start Nacre on a hidden X display (Xvfb) with a throwaway profile, play a NACRE_SCRIPT, collect results.
|
||||
# Smoke run: start Nacre in a hidden nested Wayland session (tools/nested-session.sh: Xvfb -> niri, software GL) with a
|
||||
# throwaway profile, play a NACRE_SCRIPT, collect results. Nothing appears on the user's screen.
|
||||
#
|
||||
# Usage: tools/smoke.sh <script.txt> [outdir]
|
||||
# outdir defaults to target/smoke/<script name>-<time>. It gets:
|
||||
|
|
@ -7,28 +8,37 @@
|
|||
# selftest.log every script line run, plus js results and warnings
|
||||
# <name>.png `shot <name>` screenshots; <name>.json `status <name>` files
|
||||
# home/ the throwaway HOME / XDG_* folders (profile, history, session)
|
||||
# session/ the nested session's logs (niri.log, xvfb.log) and env
|
||||
# Exit 0 only if the browser exited by itself with status 0, no "panicked" is in nacre.log and the script
|
||||
# wrote `status done` (so every script must end with `status done` then `quit`) and no `assert` failed.
|
||||
#
|
||||
# Environment:
|
||||
# SMOKE_HOME=dir reuse this throwaway home (e.g. a previous run's outdir/home) to test session restore
|
||||
# SMOKE_TIMEOUT=s kill the browser after s seconds (default 180)
|
||||
# SMOKE_SIZE=WxH screen size (default 1280x800)
|
||||
# SMOKE_SIZE=WxH nested output size (default 1280x800); the window fills it (niri, no gaps, at 0,0)
|
||||
# SMOKE_BIN=path browser binary (default target/release/nacre)
|
||||
# SMOKE_ARGS="..." extra command-line arguments for the browser (e.g. --incognito)
|
||||
# NACRE_NO_BRIDGE=1 passed through: no network bridge
|
||||
# SMOKE_FAKE_DISCORD=1 start tests/smoke/net/fake-discord.py on $XDG_RUNTIME_DIR/discord-ipc-0; it logs every frame
|
||||
# it gets to outdir/discord.log (one JSON line each)
|
||||
# SMOKE_KEYRING=1 give the run its own session bus with a throwaway GNOME Keyring (password "smoke", unlocked)
|
||||
# kept in home/, so the OS keyring path is used (cookie key, S025); SMOKE_HOME reruns find the
|
||||
# same key. Without it the run has no session bus, hence no keyring.
|
||||
# SMOKE_VISIBLE=1 show the window on the user's screen (their Wayland display, niri monitor
|
||||
# SMOKE_MONITOR, default DP-1) with the real GPU instead of hidden Xvfb + software GL;
|
||||
# only the Wayland socket is shared, profile/runtime dir/bus stay throwaway
|
||||
# SMOKE_KEYRING=1 put a throwaway GNOME Keyring (password "smoke", unlocked) kept in home/ on the run's own
|
||||
# session bus, so the OS keyring path is used (cookie key, S025); SMOKE_HOME reruns find the same
|
||||
# key. Without it the run's bus (always private, no service activation) has no keyring.
|
||||
# SMOKE_VISIBLE=1 show the window on the user's screen (their Wayland display) with the real GPU instead of the
|
||||
# hidden nested session. Needs this rule in the user's niri config (added by the user), so the
|
||||
# window opens on DP-1 without focus and nothing moves their workspace; without it the run stops:
|
||||
# window-rule { match app-id="^dev\.nacre\.Nacre$"; open-on-output "DP-1"; open-focused false; }
|
||||
# only the Wayland socket is shared, profile/runtime dir/bus stay throwaway. Selftest page input
|
||||
# (click, rclick, pagescroll, pagetype) is then synthesized in the page, never the user's pointer.
|
||||
#
|
||||
# Hidden runs give the selftest real compositor input: NACRE_WL_INPUT (tools/wl-input, built here when missing) for
|
||||
# pointer clicks and wheel, wtype for keys, on the nested output "winit" (WL_INPUT_FLIP_Y=1), and the nested niri's
|
||||
# NIRI_SOCKET for `resize`.
|
||||
#
|
||||
# Script commands (src/selftest.rs has the full list): wait <s>, waitload [s], open <url>, newtab <url>,
|
||||
# page <nacre://...>, shot <name>, status <name>, set <json pointer> <json>, flyout <name>, do <action>,
|
||||
# cmd <name> [arg], js <script>, assert <js>, click|rclick <x> <y>, pagetype <text>, log <text>, quit. Lines starting with # are notes.
|
||||
# cmd <name> [arg], js <script>, assert <js>, click|rclick <x> <y>, pagescroll <x> <y> <dy>, pagetype <text>,
|
||||
# log <text>, quit. Lines starting with # are notes.
|
||||
# In the script, @PAGES@ is replaced by the file:// URL of tests/smoke/pages, @PAGESDIR@ by its path, @HOME@ by the
|
||||
# throwaway home.
|
||||
#
|
||||
|
|
@ -46,7 +56,13 @@ if [ -n "$visible" ]; then
|
|||
[ -n "${WAYLAND_DISPLAY:-}" ] && [ -S "${XDG_RUNTIME_DIR:-}/$WAYLAND_DISPLAY" ] \
|
||||
|| { echo "smoke: SMOKE_VISIBLE needs the user's Wayland session" >&2; exit 2; }
|
||||
else
|
||||
command -v Xvfb >/dev/null || { echo "smoke: Xvfb is missing (pacman -S xorg-server-xvfb)" >&2; exit 2; }
|
||||
for tool in Xvfb niri wtype; do
|
||||
command -v $tool >/dev/null || { echo "smoke: $tool is missing" >&2; exit 2; }
|
||||
done
|
||||
wl_input=$root/tools/wl-input/target/release/wl-input
|
||||
if [ ! -x "$wl_input" ]; then
|
||||
nice cargo build --release -q --manifest-path "$root/tools/wl-input/Cargo.toml" || { echo "smoke: wl-input did not build" >&2; exit 2; }
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p "$out"
|
||||
|
|
@ -57,35 +73,37 @@ home=$(cd "$home" && pwd)
|
|||
rm -f "$out"/*.png "$out"/*.json "$out/selftest.log" "$out/nacre.log"
|
||||
sed -e "s|@PAGES@|file://$root/tests/smoke/pages|g" -e "s|@PAGESDIR@|$root/tests/smoke/pages|g" -e "s|@HOME@|$home|g" "$script" >"$out/script.txt"
|
||||
|
||||
runtime=$(mktemp -d /tmp/nacre-smoke-XXXXXX)
|
||||
chmod 700 "$runtime"
|
||||
xvfb_pid=
|
||||
session=
|
||||
cleanup() {
|
||||
[ -n "$xvfb_pid" ] && kill "$xvfb_pid" 2>/dev/null
|
||||
[ -n "${discord_pid:-}" ] && kill "$discord_pid" 2>/dev/null
|
||||
[ -n "${keyring_pid:-}" ] && kill "$keyring_pid" 2>/dev/null
|
||||
[ -n "${bus_pid:-}" ] && kill "$bus_pid" 2>/dev/null
|
||||
rm -rf "$runtime"
|
||||
if [ -n "$session" ]; then
|
||||
"$root/tools/nested-session.sh" stop "$session"
|
||||
else
|
||||
rm -rf "$runtime"
|
||||
fi
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
if [ -n "$visible" ]; then
|
||||
# Share only the compositor socket; open the window on the chosen monitor.
|
||||
runtime=$(mktemp -d /tmp/nacre-smoke-XXXXXX)
|
||||
chmod 700 "$runtime"
|
||||
# Share only the compositor socket. Never move the user's focus or workspace: where the window opens and that it
|
||||
# doesn't take focus comes from the user's niri window rule (header), which this run checks for.
|
||||
ln -s "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" "$runtime/wayland-0"
|
||||
command -v niri >/dev/null && niri msg action focus-monitor "${SMOKE_MONITOR:-DP-1}" >/dev/null 2>&1
|
||||
dispvars=(WAYLAND_DISPLAY=wayland-0 XDG_SESSION_TYPE=wayland)
|
||||
grep -rqs 'dev\\.nacre\\.Nacre' "${XDG_CONFIG_HOME:-$HOME/.config}/niri" \
|
||||
|| { echo "smoke: SMOKE_VISIBLE needs the niri window rule for dev.nacre.Nacre (see the header); staying hidden is the fallback" >&2; exit 2; }
|
||||
dispvars=(WAYLAND_DISPLAY=wayland-0 XDG_SESSION_TYPE=wayland GDK_BACKEND=wayland)
|
||||
else
|
||||
# Xvfb picks a free display number and writes it to fd 3.
|
||||
exec 3<>"$runtime/display"
|
||||
Xvfb -displayfd 3 -screen 0 "${SMOKE_SIZE:-1280x800}x24" -nolisten tcp -noreset >"$out/xvfb.log" 2>&1 &
|
||||
xvfb_pid=$!
|
||||
for _ in $(seq 50); do
|
||||
display=$(head -n1 "$runtime/display" 2>/dev/null)
|
||||
[ -n "$display" ] && break
|
||||
sleep 0.1
|
||||
done
|
||||
[ -n "${display:-}" ] || { echo "smoke: Xvfb did not start (see $out/xvfb.log)" >&2; exit 1; }
|
||||
dispvars=(DISPLAY=":$display" XDG_SESSION_TYPE=x11 LIBGL_ALWAYS_SOFTWARE=1)
|
||||
session=$out/session
|
||||
"$root/tools/nested-session.sh" start "$session" "${SMOKE_SIZE:-1280x800}" >"$out/nested.log" 2>&1 \
|
||||
|| { session=; echo "smoke: the nested session did not start (see $out/nested.log)" >&2; exit 1; }
|
||||
# The nested session's runtime dir (its Wayland socket) is the run's XDG_RUNTIME_DIR.
|
||||
runtime=$(cat "$session/runtime")
|
||||
dispvars=($(source "$session/env"; for v in WAYLAND_DISPLAY XDG_SESSION_TYPE GDK_BACKEND LIBGL_ALWAYS_SOFTWARE \
|
||||
WEBKIT_DMABUF_RENDERER_FORCE_SHM GSK_RENDERER GTK_A11Y NO_AT_BRIDGE GDK_DEBUG WL_INPUT_FLIP_Y NIRI_SOCKET; do echo "$v=${!v}"; done)
|
||||
NACRE_WL_INPUT="$wl_input" NACRE_WL_OUTPUT=winit)
|
||||
fi
|
||||
|
||||
if [ -n "${SMOKE_FAKE_DISCORD:-}" ]; then
|
||||
|
|
@ -95,20 +113,20 @@ if [ -n "${SMOKE_FAKE_DISCORD:-}" ]; then
|
|||
for _ in $(seq 50); do [ -S "$runtime/discord-ipc-0" ] && break; sleep 0.1; done
|
||||
fi
|
||||
|
||||
busvars=()
|
||||
if [ -n "${SMOKE_KEYRING:-}" ]; then
|
||||
mkdir -p "$home/.local/share"
|
||||
# A bus without service activation: only the keyring on it (no gvfs mounts, portals or the user's services).
|
||||
cat >"$runtime/bus.conf" <<CONF
|
||||
# The run's own session bus (GTK registers the app on it), without service activation: no gvfs mounts, portals or
|
||||
# the user's services; only the keyring with SMOKE_KEYRING.
|
||||
cat >"$runtime/bus.conf" <<CONF
|
||||
<!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-Bus Bus Configuration 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
||||
<busconfig><type>session</type><listen>unix:path=$runtime/bus</listen>
|
||||
<policy context="default"><allow send_destination="*" eavesdrop="true"/><allow eavesdrop="true"/><allow own="*"/></policy></busconfig>
|
||||
CONF
|
||||
env -i PATH="$PATH" HOME="$home" XDG_RUNTIME_DIR="$runtime" \
|
||||
dbus-daemon --config-file="$runtime/bus.conf" --nofork --nopidfile >"$out/bus.log" 2>&1 &
|
||||
bus_pid=$!
|
||||
for _ in $(seq 50); do [ -S "$runtime/bus" ] && break; sleep 0.1; done
|
||||
busvars=(DBUS_SESSION_BUS_ADDRESS="unix:path=$runtime/bus")
|
||||
env -i PATH="$PATH" HOME="$home" XDG_RUNTIME_DIR="$runtime" \
|
||||
dbus-daemon --config-file="$runtime/bus.conf" --nofork --nopidfile >"$out/bus.log" 2>&1 &
|
||||
bus_pid=$!
|
||||
for _ in $(seq 50); do [ -S "$runtime/bus" ] && break; sleep 0.1; done
|
||||
busvars=(DBUS_SESSION_BUS_ADDRESS="unix:path=$runtime/bus")
|
||||
if [ -n "${SMOKE_KEYRING:-}" ]; then
|
||||
mkdir -p "$home/.local/share"
|
||||
# The login keyring's password is "smoke" (an empty one leaves no default collection).
|
||||
printf 'smoke' | env -i PATH="$PATH" HOME="$home" XDG_DATA_HOME="$home/.local/share" XDG_RUNTIME_DIR="$runtime" \
|
||||
"${busvars[@]}" gnome-keyring-daemon --foreground --unlock --components=secrets >"$out/keyring.log" 2>&1 &
|
||||
|
|
@ -120,7 +138,7 @@ CONF
|
|||
done
|
||||
fi
|
||||
|
||||
env -u WAYLAND_DISPLAY -u DISPLAY -u DBUS_SESSION_BUS_ADDRESS -u NACRE_HOME \
|
||||
env -u WAYLAND_DISPLAY -u DISPLAY -u DBUS_SESSION_BUS_ADDRESS -u NACRE_HOME -u NIRI_SOCKET -u SWAYSOCK \
|
||||
-u http_proxy -u https_proxy -u all_proxy -u HTTP_PROXY -u HTTPS_PROXY -u ALL_PROXY \
|
||||
"${dispvars[@]}" "${busvars[@]}" \
|
||||
HOME="$home" XDG_CONFIG_HOME="$home/.config" XDG_DATA_HOME="$home/.local/share" \
|
||||
|
|
|
|||
230
tools/wl-input/Cargo.lock
generated
Normal file
230
tools/wl-input/Cargo.lock
generated
Normal file
|
|
@ -0,0 +1,230 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.13.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ff2a8126fff0f8c839080d619675a585e61720bb12d2baceae45769fd66f155"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "downcast-rs"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e35d6e78f4cebb90e51d543db8fe41528851d6deeef6ef21ebd4bfdc1e784776"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.191"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-xml"
|
||||
version = "0.41.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e660451e55124f798a69a5af3f49ccfbefbd41910eefd25caf2393e1f3473ec1"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "1.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.16.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "149309498a5f7334b12ddae0cad8aba81ce785fe91755068867e017cf98fee46"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
||||
|
||||
[[package]]
|
||||
name = "wayland-backend"
|
||||
version = "0.3.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38a91b4eaddff87b1cd1074985e3713da4af2c49742d1b356b2c01670a67a078"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"downcast-rs",
|
||||
"rustix",
|
||||
"smallvec",
|
||||
"wayland-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-client"
|
||||
version = "0.31.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3c36a0f861ad76d0901f2800b46321410d9f73f2ea88aac0650d86c32688073"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"rustix",
|
||||
"wayland-backend",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols"
|
||||
version = "0.32.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23d0c813de3daa2ed6520af85a3bd49b0e722a3078506899aa9686fea58dc4b6"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-misc"
|
||||
version = "0.3.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e9567599ef23e09b8dad6e429e5738d4509dfc46b3b21f32841a304d16b29c8"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-wlr"
|
||||
version = "0.3.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb04e52f7836d7c7976c78ca0250d61e33873c34156a2a1fc9474828ec268234"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-scanner"
|
||||
version = "0.31.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "338e30461b3a2b67d70eb30a6d89f8e0c93a833e07d2ae89085cd070c4a00ac0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quick-xml",
|
||||
"quote",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-sys"
|
||||
version = "0.31.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8eab23fefc9e41f8e841df4a9c707e8a8c4ed26e944ef69297184de2785e3be"
|
||||
dependencies = [
|
||||
"pkg-config",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.61.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wl-input"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"wayland-client",
|
||||
"wayland-protocols-misc",
|
||||
"wayland-protocols-wlr",
|
||||
]
|
||||
14
tools/wl-input/Cargo.toml
Normal file
14
tools/wl-input/Cargo.toml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
[package]
|
||||
name = "wl-input"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
publish = false
|
||||
description = "Test helper: real compositor input (wlr virtual pointer, input-method-v2) for Nacre's hidden smoke runs"
|
||||
|
||||
# Own workspace and own target/ (tools/wl-input/target), never the main crate's target/.
|
||||
[workspace]
|
||||
|
||||
[dependencies]
|
||||
wayland-client = "=0.31.15"
|
||||
wayland-protocols-wlr = { version = "=0.3.12", features = ["client"] }
|
||||
wayland-protocols-misc = { version = "=0.3.12", features = ["client"] }
|
||||
169
tools/wl-input/src/main.rs
Normal file
169
tools/wl-input/src/main.rs
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
//! Real compositor input for Nacre's hidden smoke runs (tools/nested-session.sh): a wlr virtual pointer and a test
|
||||
//! input method (input-method-v2). Keys and text go through `wtype` instead.
|
||||
//!
|
||||
//! Usage: wl-input OUTPUT move X Y | click X Y [left|right|middle] | scroll X Y NOTCHES | ime TEXT [PREEDIT_SECS]
|
||||
//! X/Y are pixels on OUTPUT (e.g. winit, DP-1; `-` is the first output); WL_INPUT_FLIP_Y=1 for a nested niri (winit
|
||||
//! output), which mirrors Y. NOTCHES are wheel steps, positive down. `ime` waits for a focused text field
|
||||
//! (text-input-v3 enabled), shows TEXT as preedit for PREEDIT_SECS (default 2), then commits it.
|
||||
//! Build: `cargo build --release --manifest-path tools/wl-input/Cargo.toml` (tools/smoke.sh does it when missing).
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use wayland_client::protocol::{wl_output, wl_registry, wl_seat};
|
||||
use wayland_client::{Connection, Dispatch, QueueHandle, delegate_noop};
|
||||
use wayland_protocols_misc::zwp_input_method_v2::client::{zwp_input_method_manager_v2 as imm, zwp_input_method_v2 as im};
|
||||
use wayland_protocols_wlr::virtual_pointer::v1::client::{
|
||||
zwlr_virtual_pointer_manager_v1 as vpm, zwlr_virtual_pointer_v1 as vp,
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
struct State {
|
||||
seat: Option<wl_seat::WlSeat>,
|
||||
outputs: Vec<(wl_output::WlOutput, String, (i32, i32))>,
|
||||
vpm: Option<vpm::ZwlrVirtualPointerManagerV1>,
|
||||
imm: Option<imm::ZwpInputMethodManagerV2>,
|
||||
active: bool,
|
||||
done: u32,
|
||||
unavailable: bool,
|
||||
}
|
||||
|
||||
impl Dispatch<wl_registry::WlRegistry, ()> for State {
|
||||
fn event(s: &mut Self, r: &wl_registry::WlRegistry, e: wl_registry::Event, _: &(), _: &Connection, qh: &QueueHandle<Self>) {
|
||||
if let wl_registry::Event::Global { name, interface, version } = e {
|
||||
match interface.as_str() {
|
||||
"wl_seat" if s.seat.is_none() => s.seat = Some(r.bind(name, version.min(7), qh, ())),
|
||||
"wl_output" => {
|
||||
let i = s.outputs.len();
|
||||
s.outputs.push((r.bind(name, version.min(4), qh, i), String::new(), (0, 0)));
|
||||
}
|
||||
"zwlr_virtual_pointer_manager_v1" => s.vpm = Some(r.bind(name, version.min(2), qh, ())),
|
||||
"zwp_input_method_manager_v2" => s.imm = Some(r.bind(name, 1, qh, ())),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<wl_output::WlOutput, usize> for State {
|
||||
fn event(s: &mut Self, _: &wl_output::WlOutput, e: wl_output::Event, i: &usize, _: &Connection, _: &QueueHandle<Self>) {
|
||||
match e {
|
||||
wl_output::Event::Name { name } => s.outputs[*i].1 = name,
|
||||
wl_output::Event::Mode { width, height, flags, .. }
|
||||
if flags.into_result().is_ok_and(|f| f.contains(wl_output::Mode::Current)) =>
|
||||
{
|
||||
s.outputs[*i].2 = (width, height)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<im::ZwpInputMethodV2, ()> for State {
|
||||
fn event(s: &mut Self, _: &im::ZwpInputMethodV2, e: im::Event, _: &(), _: &Connection, _: &QueueHandle<Self>) {
|
||||
match e {
|
||||
im::Event::Activate => s.active = true,
|
||||
im::Event::Deactivate => s.active = false,
|
||||
im::Event::Done => s.done += 1,
|
||||
im::Event::Unavailable => s.unavailable = true,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delegate_noop!(State: ignore wl_seat::WlSeat);
|
||||
delegate_noop!(State: vpm::ZwlrVirtualPointerManagerV1);
|
||||
delegate_noop!(State: vp::ZwlrVirtualPointerV1);
|
||||
delegate_noop!(State: imm::ZwpInputMethodManagerV2);
|
||||
|
||||
fn now_ms(t0: Instant) -> u32 {
|
||||
t0.elapsed().as_millis() as u32
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = std::env::args().skip(1).collect();
|
||||
let usage = "usage: wl-input OUTPUT move X Y | click X Y [left|right|middle] | scroll X Y DY | ime TEXT [SECS]";
|
||||
let (output_name, cmd) = (args.first().expect(usage), args.get(1).expect(usage).as_str());
|
||||
let conn = Connection::connect_to_env().expect("wayland");
|
||||
let mut q = conn.new_event_queue();
|
||||
let qh = q.handle();
|
||||
conn.display().get_registry(&qh, ());
|
||||
let mut s = State::default();
|
||||
q.roundtrip(&mut s).unwrap();
|
||||
q.roundtrip(&mut s).unwrap();
|
||||
let seat = s.seat.clone().expect("seat");
|
||||
let t0 = Instant::now();
|
||||
let num = |i: usize| -> f64 { args.get(i).and_then(|a| a.parse().ok()).expect(usage) };
|
||||
|
||||
if cmd == "ime" {
|
||||
let text = args.get(2).expect(usage).clone();
|
||||
let secs: f64 = args.get(3).and_then(|a| a.parse().ok()).unwrap_or(2.0);
|
||||
let m = s.imm.clone().expect("compositor has no input-method-v2").get_input_method(&seat, &qh, ());
|
||||
let deadline = Instant::now() + Duration::from_secs(5);
|
||||
while !(s.active && s.done > 0) {
|
||||
q.roundtrip(&mut s).unwrap();
|
||||
assert!(!s.unavailable, "another input method is running");
|
||||
assert!(Instant::now() < deadline, "no focused text field enabled text-input within 5 s");
|
||||
std::thread::sleep(Duration::from_millis(50));
|
||||
}
|
||||
m.set_preedit_string(text.clone(), 0, text.len() as i32);
|
||||
m.commit(s.done);
|
||||
q.roundtrip(&mut s).unwrap();
|
||||
println!("preedit {text}");
|
||||
std::thread::sleep(Duration::from_secs_f64(secs));
|
||||
q.roundtrip(&mut s).unwrap();
|
||||
m.commit_string(text.clone());
|
||||
m.commit(s.done);
|
||||
q.roundtrip(&mut s).unwrap();
|
||||
println!("commit {text}");
|
||||
m.destroy();
|
||||
q.roundtrip(&mut s).unwrap();
|
||||
return;
|
||||
}
|
||||
|
||||
let (out, _, (w, h)) = s.outputs.iter().find(|o| output_name == "-" || &o.1 == output_name).cloned().expect("no such output");
|
||||
let p = s.vpm.clone().expect("compositor has no wlr virtual pointer").create_virtual_pointer_with_output(
|
||||
Some(&seat),
|
||||
Some(&out),
|
||||
&qh,
|
||||
(),
|
||||
);
|
||||
let (x, mut y) = (num(2), num(3));
|
||||
// nested niri (winit backend) mirrors absolute motion vertically
|
||||
if std::env::var("WL_INPUT_FLIP_Y").is_ok_and(|v| v == "1") {
|
||||
y = h as f64 - y;
|
||||
}
|
||||
p.motion_absolute(now_ms(t0), x as u32, y as u32, w as u32, h as u32);
|
||||
p.frame();
|
||||
q.roundtrip(&mut s).unwrap();
|
||||
std::thread::sleep(Duration::from_millis(60));
|
||||
match cmd {
|
||||
"move" => {}
|
||||
"click" => {
|
||||
let button = match args.get(4).map(String::as_str) {
|
||||
Some("right") => 0x111,
|
||||
Some("middle") => 0x112,
|
||||
_ => 0x110,
|
||||
};
|
||||
for state in [wayland_client::protocol::wl_pointer::ButtonState::Pressed, wayland_client::protocol::wl_pointer::ButtonState::Released] {
|
||||
p.button(now_ms(t0), button, state);
|
||||
p.frame();
|
||||
q.roundtrip(&mut s).unwrap();
|
||||
std::thread::sleep(Duration::from_millis(40));
|
||||
}
|
||||
}
|
||||
"scroll" => {
|
||||
let dy = num(4);
|
||||
let steps = dy.abs().round().max(1.0) as i32;
|
||||
for _ in 0..steps {
|
||||
use wayland_client::protocol::wl_pointer::{Axis, AxisSource};
|
||||
p.axis_source(AxisSource::Wheel);
|
||||
p.axis_discrete(now_ms(t0), Axis::VerticalScroll, 15.0 * dy.signum(), dy.signum() as i32);
|
||||
p.frame();
|
||||
q.roundtrip(&mut s).unwrap();
|
||||
std::thread::sleep(Duration::from_millis(30));
|
||||
}
|
||||
}
|
||||
_ => panic!("{usage}"),
|
||||
}
|
||||
p.destroy();
|
||||
q.roundtrip(&mut s).unwrap();
|
||||
}
|
||||
Loading…
Reference in a new issue