diff --git a/docs/engine/webkit-spike.md b/docs/engine/webkit-spike.md new file mode 100644 index 0000000..941c093 --- /dev/null +++ b/docs/engine/webkit-spike.md @@ -0,0 +1,45 @@ +# WebKit embedding spike (D-033, in progress) + +## WIP state (2026-11-13, stopped for the usage limit) + +**Done** +- Read: CLAUDE.md, HANDOFF "Orchestrator resume (2026-11-13)", D-032, `engine-comparison.md`, `docs/engine/tune/` + (check jsons + samples), `tools/engine-test/webkit_shell.py`. Not yet read: `docs/engine/servo-removal.md` (baa3b7f; + 4 open decisions: ad-block interception, cookie encryption, profile dir rename, Media Session/MPRIS). +- Tuning data, all-tabs-idle row (PSS / tree VRAM): base 2989 / 1562 MB; no-page-cache 2414 / 1019; mem500 2377 / 1139; + cache-viewer 2816 / 873; hw-never 2298 / 58 (JS checks fail: "Unsupported result type"); related 2933 / 1380. + Base WebKitGTK plays the YouTube watch page (t=14.8 s, readyState 4) in the tune runs; the blank tabs of the first + comparison run were a shell problem. +- System: `webkitgtk-6.0` 2.54.2, `gtk4` 4.24.1, `libadwaita` 1.10 installed. `wpewebkit` 2.54.2 in extra, **not + installed** (provides libWPEWebKit-2.0, no libwpe/wpebackend-fdo dependency = new WPE Platform API; needs the user's + `sudo pacman -S wpewebkit`, not asked yet). niri exposes `zwlr_virtual_pointer_manager_v1`, + `zwp_input_method_manager_v2`, `zwp_text_input_manager_v3`, `zwp_virtual_keyboard_manager_v1`; `wtype`, `grim` present. +- Crates (pinned in the spike): `gtk4 =0.11.5` (feature v4_20), `webkit6 =0.6.1` (feature v2_52; latest, no v2_54 + feature), `egui`/`egui_glow =0.37.0`, `glow =0.17.0`, `wayland-client =0.31.15`, `wayland-protocols-wlr`/`-misc + =0.3.12`. No usable Rust crate for WPE Platform 2.x (would need gir/bindgen). +- Spike code `spikes/webkit-egui/` (own Cargo workspace and target/), **builds, never run yet**: + - `src/egui_area.rs`: `Gtk.GLArea` subclass painting egui with egui_glow (GL via eglGetProcAddress), transparent + clear; `contains()` takes the pointer only outside egui's page rect or over an egui Area, so GTK's pick falls + through to the WebView for page input; GTK motion/click/scroll/key controllers + `IMMulticontext` → egui events. + - `src/main.rs`: Gtk.Overlay { Gtk.Fixed { Gtk.Stack of WebViews moved/sized to egui's page rect }, EguiArea }; + egui toolbar (tabs, back/forward/reload, URL field, ⋮ flyout over the page), egui context menu from WebKit's + `context-menu` signal, popups via `create` (related view → new tab), Web Inspector, zoom, capture-phase Ctrl+L/T. + D-032 knobs on by default (page cache off, 500 MB memory limit, DOCUMENT_VIEWER); env knobs in the file header. + Driver: `SPIKE_CMD=` command file (open/go/tab/menu/js/shot/stats/pick/state/focus/sleep/mark/quit); + `stats` = GTK frame-clock pacing + egui render ms. + - `src/bin/wl-input.rs`: real compositor input for tests: `wl-input DP-1 move|click|scroll …`, `ime TEXT [secs]` + (test input method: preedit, then commit). + +**Design leaning**: (b) GTK 4 host. WebKitGTK gives input, IME, scroll, dialogs, printing, Web Inspector natively, has +maintained Rust bindings, and egui keeps drawing all chrome through the overlay; winit is replaced by GTK events in +app.rs (egui-winit → own GTK→egui input glue as in egui_area.rs). WPE would need hand-written bindings, our own input +translation and frame import, and has no Inspector UI. Unproven until the spike runs: GLArea transparency over the +WebView, pick fall-through, frame pacing with video under the overlay. + +**Exact next step**: ask the orchestrator/user how to run visibly (the user rejected a run that switched DP-1 to an +empty workspace and maximized the window; options: visible without moving focus, or hidden nested +`kwin_wayland --virtual`). Then run `spikes/webkit-egui/target/release/webkit-egui` with a throwaway HOME and +`SPIKE_CMD`, YouTube watch page: shots (toolbar, ⋮ flyout over playing video, context menu), `pick` toolbar vs page, +`stats` during playback (with and without `SPIKE_EGUI=0`), wl-input click/scroll/right click/IME into URL field and a +page input, popup, two tabs; RAM via `tools/engine-test/sample.py`; Chromium reference shot in the browser pane +(D-031). Then finish this doc + D-033, pull, read servo-removal.md, `plan-generate` → `Plans/08 WebKit engine/` (S044+). diff --git a/spikes/webkit-egui/Cargo.lock b/spikes/webkit-egui/Cargo.lock new file mode 100644 index 0000000..799fc0f --- /dev/null +++ b/spikes/webkit-egui/Cargo.lock @@ -0,0 +1,1536 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "accesskit" +version = "0.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e883d1d28c5fd5568c79ed2d2bd48d9f2fd3945c8974ed0f53690ceddb051be" +dependencies = [ + "uuid", +] + +[[package]] +name = "ahash" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "arrayvec" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56" + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "bytemuck" +version = "1.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95832e849adfb21180ccb6826a99da14e5d266ae5c2e668e1602cf234f153797" +dependencies = [ + "bytemuck_derive", +] + +[[package]] +name = "bytemuck_derive" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a1f896587b6f2c069c73d2f0913e2d590c3990285cd2f0b6aa02b786b4c679c" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "cairo-rs" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df683f1d30b457964673a5541a4603208ef95ab6873d2a55871895cf310f3b56" +dependencies = [ + "bitflags", + "cairo-sys-rs", + "glib", + "libc", +] + +[[package]] +name = "cairo-sys-rs" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee548131103ad8f698c6725669647b9c757b3b66992dd6a026037596417bee21" +dependencies = [ + "glib-sys", + "libc", + "system-deps 9.0.1", +] + +[[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 = "cfg-expr" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ba9e9ec16c447027685b1f897b720e18e9a8afd00bd7332c483537e38086c9f" +dependencies = [ + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "color" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ec7c5eb7a16992b1904d76c517d170ab353b0e0b3d5a0c81a8a0cd1037893cf" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "downcast-rs" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" + +[[package]] +name = "ecolor" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31bcbef0d4263a63eb32c4834e5d711613035ce1333468e107d928923e21e6e2" +dependencies = [ + "bytemuck", + "emath", +] + +[[package]] +name = "egui" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec9144f49b7a28b5f395d3147e325b4fe3e77ba686eac11d1bdf0a7da3f375f" +dependencies = [ + "accesskit", + "ahash", + "bitflags", + "emath", + "epaint", + "itertools", + "log", + "nohash-hasher", + "profiling", + "smallvec", + "unicode-segmentation", +] + +[[package]] +name = "egui_glow" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9275ca5cc35a6b7c94e0e8cedf22542f66cb0cf45ed8ab2657c78ff49fec7268" +dependencies = [ + "bytemuck", + "egui", + "glow", + "log", + "profiling", +] + +[[package]] +name = "either" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be" + +[[package]] +name = "emath" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e73ce90f54750be8672c02be0743fe47530e6f251e066f0ee2869b59eb297af5" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "epaint" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97bac86ae3dde93fc3951e790951caea739ff39a6c89d909cdaf1d9278dbb1bd" +dependencies = [ + "ahash", + "bytemuck", + "ecolor", + "emath", + "epaint_default_fonts", + "font-types", + "harfrust", + "log", + "nohash-hasher", + "parking_lot", + "profiling", + "self_cell", + "skrifa", + "smallvec", + "unicode-general-category", + "unicode-properties", + "unicode-segmentation", + "vello_cpu", +] + +[[package]] +name = "epaint_default_fonts" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfc1cc505827f4c23eedc297975a0fd038268d41293f389dd8ff3b574aefab19" + +[[package]] +name = "equivalent" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" + +[[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 = "euclid" +version = "0.22.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1a05365e3b1c6d1650318537c7460c6923f1abdd272ad6842baa2b509957a06" +dependencies = [ + "num-traits", +] + +[[package]] +name = "fearless_simd" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97b65636e5b9ef369943878ac74335ba1c55c1cb6adbf1e2c293c624248d693" + +[[package]] +name = "field-offset" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38e2275cc4e4fc009b0669731a1e5ab7ebf11f469eaede2bab9309a5b4d6057f" +dependencies = [ + "memoffset", + "rustc_version", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" + +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + +[[package]] +name = "font-types" +version = "0.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "835ae9d781464a79026cde387f9cbc650c9a4909d7cf7e658b127e3c35d2f35d" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-executor" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031b47cf1a3c6cc8bc2fc76cd437f521619387907d469316e7c0bc278f1f5432" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-macro", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "gdk-pixbuf" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25f420376dbee041b2db374ce4573892a36222bb3f6c0c43e24f0d67eae9b646" +dependencies = [ + "gdk-pixbuf-sys", + "gio", + "glib", + "libc", +] + +[[package]] +name = "gdk-pixbuf-sys" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5209294ba3775f9b650bf78bfadeba4332089f2329b3e2f6ce0a4957a45bff" +dependencies = [ + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "system-deps 9.0.1", +] + +[[package]] +name = "gdk4" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e77c579bac9eff8b84c0625d5f533da6d69988c063062fe92c2e955ede8f28eb" +dependencies = [ + "cairo-rs", + "gdk-pixbuf", + "gdk4-sys", + "gio", + "glib", + "libc", + "pango", +] + +[[package]] +name = "gdk4-sys" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eff6238a30c1f198fb3c8d3d445fa7faf211d11d9075af0772e6e0ca32ae001" +dependencies = [ + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "pango-sys", + "pkg-config", + "system-deps 9.0.1", +] + +[[package]] +name = "gio" +version = "0.22.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4620fbafdf19dba814473e19f18e75290cb3338662f6ae35f0402affd3b2b699" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "gio-sys", + "glib", + "libc", + "pin-project-lite", + "smallvec", +] + +[[package]] +name = "gio-sys" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28739f914c15b87a9856000bed9cbd5b3a8afbca5e982d9a299e1601422cb5" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps 9.0.1", + "windows-sys", +] + +[[package]] +name = "glib" +version = "0.22.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4cf9e5bd8713f1990a92c422998826e0fb34824277b46bc59757373483c6694" +dependencies = [ + "bitflags", + "futures-channel", + "futures-core", + "futures-executor", + "futures-task", + "futures-util", + "gio-sys", + "glib-macros", + "glib-sys", + "gobject-sys", + "libc", + "memchr", + "smallvec", +] + +[[package]] +name = "glib-macros" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9597c68fa7bdf4154a3079642cd21c4dccac0b0bdd2897d82861523bf91e7b9" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "glib-sys" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99b38907e67e40dec9b60f858bcada952598719cb512a13eb13d6cdcd16f8295" +dependencies = [ + "libc", + "system-deps 9.0.1", +] + +[[package]] +name = "glifo" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282a26c1e23de04bdab3e34a21b6f877a479b96737792516b9b8b8f69b6661be" +dependencies = [ + "bytemuck", + "foldhash", + "hashbrown", + "log", + "peniko", + "skrifa", + "smallvec", + "vello_common", +] + +[[package]] +name = "glow" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29038e1c483364cc6bb3cf78feee1816002e127c331a1eec55a4d202b9e1adb5" +dependencies = [ + "js-sys", + "slotmap", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "gobject-sys" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07595c9ba696bd9819cb6a8df39f08078f3dd679508fe052dd558492c2053834" +dependencies = [ + "glib-sys", + "libc", + "system-deps 9.0.1", +] + +[[package]] +name = "graphene-rs" +version = "0.22.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb856b9c558971c3f13ab692358926da710b046932a4e087aedcc35b040d7dff" +dependencies = [ + "glib", + "graphene-sys", +] + +[[package]] +name = "graphene-sys" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97842c7543828f98aa5583aa54fcda28aa84fa2b0f8c556142177f7bbb638057" +dependencies = [ + "glib-sys", + "libc", + "system-deps 9.0.1", +] + +[[package]] +name = "gsk4" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eee23d7425c5281ec5a2f40f7b69384aac66c15861d990d248e9d9c9368be464" +dependencies = [ + "cairo-rs", + "gdk4", + "glib", + "graphene-rs", + "gsk4-sys", + "libc", + "pango", +] + +[[package]] +name = "gsk4-sys" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27900c92e47df410bbe43b51818104051e3409da43fb88547a41c0bafddfd39c" +dependencies = [ + "cairo-sys-rs", + "gdk4-sys", + "glib-sys", + "gobject-sys", + "graphene-sys", + "libc", + "pango-sys", + "system-deps 9.0.1", +] + +[[package]] +name = "gtk4" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0f8226c94dd0b65ba2e8fcd8ff402d380e890f6e5a6488e652a0158e827b9bf" +dependencies = [ + "cairo-rs", + "field-offset", + "futures-channel", + "gdk-pixbuf", + "gdk4", + "gio", + "glib", + "graphene-rs", + "gsk4", + "gtk4-macros", + "gtk4-sys", + "libc", + "pango", +] + +[[package]] +name = "gtk4-macros" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb906c98f0b4cc9002594e337e83f40492aa6dca22c97242f13be5b046c5f338" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "gtk4-sys" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd14af0137f269bdecee73404157d2a852f9651af7d68bd1023d3b8b914a14c3" +dependencies = [ + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gdk4-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "graphene-sys", + "gsk4-sys", + "libc", + "pango-sys", + "system-deps 9.0.1", +] + +[[package]] +name = "guillotiere" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b17e70c989c36bad147b27a58d148c0741c51448aa5653436547323e524d0ab" +dependencies = [ + "euclid", +] + +[[package]] +name = "harfrust" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c03d949a14aa089bbb282f7dd76a498a7f684428e4257202efc119ec010376f9" +dependencies = [ + "bitflags", + "bytemuck", + "read-fonts", + "smallvec", +] + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" +dependencies = [ + "foldhash", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "indexmap" +version = "2.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itertools" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b4baf93f58d4425749ca49a51c50ebab072c5df6994d08fed93541c331481dc" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" + +[[package]] +name = "javascriptcore6" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d8d4f64d976c6dc6068723b6ef7838acf954d56b675f376c826f7e773362ddb" +dependencies = [ + "glib", + "javascriptcore6-sys", + "libc", +] + +[[package]] +name = "javascriptcore6-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b9787581c8949a7061c9b8593c4d1faf4b0fe5e5643c6c7793df20dbe39cf6" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps 7.0.8", +] + +[[package]] +name = "js-sys" +version = "0.3.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "kurbo" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b60dfc32f652b926df6192e55525b16d186c69d47876c3ead4da5cc9f8450e2" +dependencies = [ + "arrayvec", + "euclid", + "polycool", + "smallvec", +] + +[[package]] +name = "libc" +version = "0.2.191" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" + +[[package]] +name = "libloading" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" +dependencies = [ + "cfg-if", + "windows-link", +] + +[[package]] +name = "linebender_resource_handle" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4a5ff6bcca6c4867b1c4fd4ef63e4db7436ef363e0ad7531d1558856bae64f4" + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "nohash-hasher" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "pango" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b2022dbbd82e1c42bd950a6f1df9b98c796e725dce5ec275e03cbf9772e4efa" +dependencies = [ + "gio", + "glib", + "pango-sys", +] + +[[package]] +name = "pango-sys" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca02d64761b74d56cdd4b437db6d73dc95e6c0d40f27e1c707952c0f09052948" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps 9.0.1", +] + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "peniko" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "839c8299360d2e998bdb106dc0a6cd71dcc5f4df51df1b620361bf50e283cca6" +dependencies = [ + "bytemuck", + "color", + "kurbo", + "linebender_resource_handle", + "smallvec", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "pkg-config" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" + +[[package]] +name = "polycool" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50596ddc09eb5ad5f75cacd40209568e66df71baf86e1499a0e99c4cff12a5a6" +dependencies = [ + "arrayvec", +] + +[[package]] +name = "proc-macro-crate" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f" +dependencies = [ + "toml_edit", +] + +[[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 = "profiling" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d595e54a326bc53c1c197b32d295e14b169e3cfeaa8dc82b529f947fba6bcf5" + +[[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 = "read-fonts" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "046a7d674daf459825b32f5062056d6882db0d2f5a479fbd76ccfc870ac18709" +dependencies = [ + "bytemuck", + "font-types", + "once_cell", +] + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[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 = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "self_cell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab42ca02749e120097e328d91d415325bdf43b1c72c4c8badf37375fe40a813" + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "serde_json" +version = "1.0.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_spanned" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c187e0a369471c550af028cba56d4f4fa2a489ad28151ae95a4d340a2a8b782" +dependencies = [ + "serde_core", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "skrifa" +version = "0.44.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819ab7d62b1d3e72d9d9dea5650bac30424f9111364bb94928dbf5ecad1baa68" +dependencies = [ + "bytemuck", + "read-fonts", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "slotmap" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdd58c3c93c3d278ca835519292445cb4b0d4dc59ccfdf7ceadaab3f8aeb4038" +dependencies = [ + "version_check", +] + +[[package]] +name = "smallvec" +version = "1.16.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "149309498a5f7334b12ddae0cad8aba81ce785fe91755068867e017cf98fee46" + +[[package]] +name = "soup3" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d38b59ff6d302538efd337e15d04d61c5b909ec223c60ae4061d74605a962a" +dependencies = [ + "futures-channel", + "gio", + "glib", + "libc", + "soup3-sys", +] + +[[package]] +name = "soup3-sys" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79d5d25225bb06f83b78ff8cc35973b56d45fcdd21af6ed6d2bbd67f5a6f9bea" +dependencies = [ + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "system-deps 7.0.8", +] + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "system-deps" +version = "7.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "396a35feb67335377e0251fcbc1092fc85c484bd4e3a7a54319399da127796e7" +dependencies = [ + "cfg-expr", + "heck", + "pkg-config", + "toml", + "version-compare", +] + +[[package]] +name = "system-deps" +version = "9.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db551ad38aac61d5e0343e0eeeb0163be3115c4e23b6a025959570ee0c03c67d" +dependencies = [ + "cfg-expr", + "heck", + "pkg-config", + "toml", + "version-compare", +] + +[[package]] +name = "target-lexicon" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca" + +[[package]] +name = "thiserror" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "toml" +version = "1.2.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5755c51863cdac711f1956baf8eb9588e060755f7d3c4c979e70ea1e1f32cd7" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", +] + +[[package]] +name = "toml_datetime" +version = "1.1.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "173f25c883cd2176a2d8212155638c0a60d484a9d84546d270866f40f56b6e49" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_edit" +version = "0.25.19+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd43688c4858d7264ae1cf9a9f874a67c3feb74a883b1cd7bebd6a4ea8307218" +dependencies = [ + "indexmap", + "toml_datetime", + "toml_parser", + "winnow", +] + +[[package]] +name = "toml_parser" +version = "1.1.5+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baa693a8032d7e1cada7d0041e96126df243179ff061456783ac7f12bda4744c" +dependencies = [ + "winnow", +] + +[[package]] +name = "toml_writer" +version = "1.2.0+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "009dbb7700f11c55ef83aebbe4c0e9cf1f1ac0844bd8d6f00dc38f302026e13a" + +[[package]] +name = "unicode-general-category" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b993bddc193ae5bd0d623b49ec06ac3e9312875fdae725a975c51db1cc1677f" + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "unicode-properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "993ad287eb20e8ba755312801cfe1413e0f25d604075863acaddca10b04c1833" + +[[package]] +name = "unicode-segmentation" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8" + +[[package]] +name = "uuid" +version = "1.29.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bed99139f7dac9b5cfe5f17be4d66dc7079a34dee1d74bcc77217119240e267c" + +[[package]] +name = "vello_common" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb2141a2bca6e6d598e471fd4d1d7eed8e020aad6a28187edda07f091a325dd" +dependencies = [ + "bytemuck", + "fearless_simd", + "guillotiere", + "log", + "peniko", + "smallvec", + "thiserror", +] + +[[package]] +name = "vello_cpu" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace506ca414548966fcf3c283be94eb1cad8254de488791ee698bf438b0890a9" +dependencies = [ + "bytemuck", + "glifo", + "hashbrown", + "vello_common", +] + +[[package]] +name = "version-compare" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c2856837ef78f57382f06b2b8563a2f512f7185d732608fd9176cb3b8edf0e" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasm-bindgen" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c" +dependencies = [ + "cfg-if", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 3.0.10", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e" +dependencies = [ + "unicode-ident", +] + +[[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 = "web-sys" +version = "0.3.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7d179596ff5ec0f6de4db64d54011bde6289cc49603d3a6e4ce3f329207ab88" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webkit-egui" +version = "0.1.0" +dependencies = [ + "egui", + "egui_glow", + "glow", + "gtk4", + "libloading", + "serde_json", + "wayland-client", + "wayland-protocols-misc", + "wayland-protocols-wlr", + "webkit6", +] + +[[package]] +name = "webkit6" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4959dd2a92813d4b2ae134e71345a03030bcff189b4f79cd131e9218aba22b70" +dependencies = [ + "gdk4", + "gio", + "glib", + "gtk4", + "javascriptcore6", + "libc", + "soup3", + "webkit6-sys", +] + +[[package]] +name = "webkit6-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "236078ce03ff041bf87904c8257e6a9b0e9e0f957267c15f9c1756aadcf02581" +dependencies = [ + "gdk4-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "gtk4-sys", + "javascriptcore6-sys", + "libc", + "soup3-sys", + "system-deps 7.0.8", +] + +[[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 = "winnow" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3b93199df0ab874cdf0c6a94f0a0dc3423fe41f1cafb62b8bd7b1deb277aef" +dependencies = [ + "memchr", +] + +[[package]] +name = "zerocopy" +version = "0.8.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5fe1f8f1b06191a00962174c61aa5005e0bb391a6d80d07e24d115c01a92ed8" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "863ad3ac83293fb4d740aedbfdc9240dd8d1a50c1099acd76ce80ce7c7230c7f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/spikes/webkit-egui/Cargo.toml b/spikes/webkit-egui/Cargo.toml new file mode 100644 index 0000000..19b53d4 --- /dev/null +++ b/spikes/webkit-egui/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "webkit-egui" +version = "0.1.0" +edition = "2024" +publish = false +description = "Spike: Nacre's egui chrome hosted in a GTK 4 window next to WebKitGTK 6.0 web views (D-033)" + +# Own workspace and own target/ (never the main crate's target/). +[workspace] + +[dependencies] +gtk = { package = "gtk4", version = "=0.11.5", features = ["v4_20"] } +webkit = { package = "webkit6", version = "=0.6.1", features = ["v2_52"] } +egui = { version = "=0.37.0", default-features = false, features = ["default_fonts"] } +egui_glow = { version = "=0.37.0", default-features = false } +glow = "=0.17.0" +libloading = "0.8" +serde_json = "1" +# wl-input test helper (virtual pointer, test input method) +wayland-client = "=0.31.15" +wayland-protocols-wlr = { version = "=0.3.12", features = ["client"] } +wayland-protocols-misc = { version = "=0.3.12", features = ["client"] } + +[profile.release] +debug = 1 diff --git a/spikes/webkit-egui/src/bin/wl-input.rs b/spikes/webkit-egui/src/bin/wl-input.rs new file mode 100644 index 0000000..61e28eb --- /dev/null +++ b/spikes/webkit-egui/src/bin/wl-input.rs @@ -0,0 +1,162 @@ +//! Real compositor input for spike tests: a wlr virtual pointer and a test input method (input-method-v2). +//! +//! Usage: wl-input OUTPUT move X Y | click X Y [left|right|middle] | scroll X Y DY | ime TEXT [PREEDIT_SECS] +//! X/Y are pixels on OUTPUT (e.g. DP-1). `ime` waits for a focused text field (text-input-v3 enabled), shows +//! TEXT as preedit for PREEDIT_SECS (default 2), then commits it. +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, + outputs: Vec<(wl_output::WlOutput, String, (i32, i32))>, + vpm: Option, + imm: Option, + active: bool, + done: u32, + unavailable: bool, +} + +impl Dispatch for State { + fn event(s: &mut Self, r: &wl_registry::WlRegistry, e: wl_registry::Event, _: &(), _: &Connection, qh: &QueueHandle) { + 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 for State { + fn event(s: &mut Self, _: &wl_output::WlOutput, e: wl_output::Event, i: &usize, _: &Connection, _: &QueueHandle) { + 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 for State { + fn event(s: &mut Self, _: &im::ZwpInputMethodV2, e: im::Event, _: &(), _: &Connection, _: &QueueHandle) { + 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 = 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| &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, y) = (num(2), num(3)); + 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(); +} diff --git a/spikes/webkit-egui/src/egui_area.rs b/spikes/webkit-egui/src/egui_area.rs new file mode 100644 index 0000000..389ded0 --- /dev/null +++ b/spikes/webkit-egui/src/egui_area.rs @@ -0,0 +1,333 @@ +//! egui painted in a transparent `Gtk.GLArea` that lies over the whole window (D-033 design). +//! +//! The area only takes the pointer where egui has something (`contains`): the chrome outside the page rect and any +//! egui `Area` (flyouts, menus, toasts) over the page. Everywhere else GTK's pick falls through to the WebKit view +//! below, so the page gets its own pointer, scroll, right click, drag and IME without any forwarding. +use std::cell::{Cell, RefCell}; +use std::sync::Arc; +use std::time::Instant; + +use gtk::prelude::*; +use gtk::subclass::prelude::*; +use gtk::{gdk, glib}; + +pub type UiFn = Box egui::Rect>; + +mod imp { + use super::*; + + #[derive(Default)] + pub struct EguiArea { + pub ctx: egui::Context, + pub painter: RefCell>, + pub events: RefCell>, + pub ui: RefCell>, + /// The page rect egui left for the web view, in points. + pub page: Cell>, + pub mods: Cell, + pub start: Cell>, + /// CPU time of each render (egui layout + paint), ms. + pub render_ms: RefCell>, + pub repaint_pending: Cell, + pub preedit: Cell, + } + + #[glib::object_subclass] + impl ObjectSubclass for EguiArea { + const NAME: &'static str = "NacreEguiArea"; + type Type = super::EguiArea; + type ParentType = gtk::GLArea; + } + + impl ObjectImpl for EguiArea {} + + impl WidgetImpl for EguiArea { + fn contains(&self, x: f64, y: f64) -> bool { + let pos = egui::pos2(x as f32, y as f32) / self.ppp(); + !self.page.get().is_some_and(|p| p.contains(pos)) || self.ctx.layer_id_at(pos).is_some_and(|l| l.order != egui::Order::Background) + } + + fn realize(&self) { + self.parent_realize(); + let obj = self.obj(); + obj.make_current(); + if let Some(e) = obj.error() { + eprintln!("GLArea error: {e}"); + return; + } + let gl = unsafe { glow::Context::from_loader_function_cstr(super::gl_proc) }; + let painter = egui_glow::Painter::new(Arc::new(gl), "", None, false).expect("egui painter"); + *self.painter.borrow_mut() = Some(painter); + } + + fn unrealize(&self) { + self.obj().make_current(); + if let Some(mut p) = self.painter.borrow_mut().take() { + p.destroy(); + } + self.parent_unrealize(); + } + } + + impl GLAreaImpl for EguiArea { + fn render(&self, _context: &gdk::GLContext) -> glib::Propagation { + let t0 = Instant::now(); + self.repaint_pending.set(false); + let obj = self.obj(); + let ppp = self.ppp(); + let (w, h) = (obj.width() as f32, obj.height() as f32); + let start = *self.start.get().get_or_insert_with(Instant::now); + self.start.set(Some(start)); + let mut input = egui::RawInput { + screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(w, h))), + time: Some(start.elapsed().as_secs_f64()), + events: std::mem::take(&mut *self.events.borrow_mut()), + focused: obj.has_focus(), + ..Default::default() + }; + input.viewports.entry(egui::ViewportId::ROOT).or_default().native_pixels_per_point = Some(ppp); + let mut page = self.page.get().unwrap_or(egui::Rect::NOTHING); + let out = { + let mut ui_fn = self.ui.borrow_mut(); + self.ctx.run_ui(input, |ui| { + if let Some(f) = ui_fn.as_mut() { + page = f(ui); + } + }) + }; + self.page.set(Some(page)); + let prims = self.ctx.tessellate(out.shapes, out.pixels_per_point); + let mut textures = out.textures_delta; + if let Some(p) = self.painter.borrow_mut().as_mut() { + let size = [(w * ppp) as u32, (h * ppp) as u32]; + p.clear(size, [0.0; 4]); + p.paint_and_update_textures(size, out.pixels_per_point, &prims, &mut textures); + } + let delay = out.viewport_output.get(&egui::ViewportId::ROOT).map(|v| v.repaint_delay); + if let Some(d) = delay.filter(|d| *d < std::time::Duration::from_secs(3600)) { + let weak = obj.downgrade(); + glib::timeout_add_local_once(d, move || { + if let Some(a) = weak.upgrade() { + a.repaint(); + } + }); + } + self.render_ms.borrow_mut().push(t0.elapsed().as_secs_f32() * 1000.0); + glib::Propagation::Stop + } + } + + impl EguiArea { + pub fn ppp(&self) -> f32 { + self.obj().scale_factor() as f32 + } + } +} + +glib::wrapper! { + pub struct EguiArea(ObjectSubclass) + @extends gtk::GLArea, gtk::Widget, + @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget; +} + +fn gl_proc(name: &std::ffi::CStr) -> *const std::ffi::c_void { + // GTK 4 uses EGL on Wayland and X11; Mesa's eglGetProcAddress also returns core GL entry points. + static EGL: std::sync::OnceLock<(libloading::Library, unsafe extern "C" fn(*const i8) -> *const std::ffi::c_void)> = + std::sync::OnceLock::new(); + let (_, f) = EGL.get_or_init(|| unsafe { + let lib = libloading::Library::new("libEGL.so.1").expect("libEGL"); + let f = *lib.get(b"eglGetProcAddress\0").expect("eglGetProcAddress"); + (lib, f) + }); + unsafe { f(name.as_ptr()) } +} + +impl EguiArea { + pub fn new(ui: UiFn) -> Self { + let a: Self = glib::Object::builder().build(); + a.set_hexpand(true); + a.set_vexpand(true); + a.set_focusable(true); + a.set_auto_render(false); + // GTK composites the area's texture with alpha: clear to transparent and the web view shows through. + *a.imp().ui.borrow_mut() = Some(ui); + a.imp().ctx.set_visuals(egui::Visuals::dark()); + a.attach_input(); + a + } + + pub fn ctx(&self) -> &egui::Context { + &self.imp().ctx + } + + pub fn page_rect(&self) -> egui::Rect { + self.imp().page.get().unwrap_or(egui::Rect::NOTHING) + } + + pub fn render_ms(&self) -> Vec { + self.imp().render_ms.borrow().clone() + } + + pub fn repaint(&self) { + if !self.imp().repaint_pending.replace(true) { + self.queue_render(); + } + } + + fn push(&self, e: egui::Event) { + self.imp().events.borrow_mut().push(e); + self.repaint(); + } + + fn attach_input(&self) { + let motion = gtk::EventControllerMotion::new(); + let w = self.downgrade(); + motion.connect_motion(move |_, x, y| { + if let Some(a) = w.upgrade() { + a.push(egui::Event::PointerMoved(egui::pos2(x as f32, y as f32) / a.imp().ppp())); + } + }); + let w = self.downgrade(); + motion.connect_leave(move |_| { + if let Some(a) = w.upgrade() { + a.push(egui::Event::PointerGone); + } + }); + self.add_controller(motion); + + let click = gtk::GestureClick::new(); + click.set_button(0); + let w = self.downgrade(); + click.connect_pressed(move |g, _n, x, y| { + if let Some(a) = w.upgrade() { + a.grab_focus(); + a.button(g, x, y, true); + } + }); + let w = self.downgrade(); + click.connect_released(move |g, _n, x, y| { + if let Some(a) = w.upgrade() { + a.button(g, x, y, false); + } + }); + self.add_controller(click); + + let scroll = gtk::EventControllerScroll::new(gtk::EventControllerScrollFlags::BOTH_AXES); + let w = self.downgrade(); + scroll.connect_scroll(move |_, dx, dy| { + if let Some(a) = w.upgrade() { + a.push(egui::Event::MouseWheel { + unit: egui::MouseWheelUnit::Line, + delta: egui::vec2(-dx as f32, -dy as f32), + phase: egui::TouchPhase::Move, + source: egui::MouseWheelSource::Unknown, + modifiers: a.imp().mods.get(), + }); + } + glib::Propagation::Stop + }); + self.add_controller(scroll); + + // Keys go through GTK's input method first (text-input-v3 on Wayland): committed text and preedit arrive + // as egui Text / Ime events; only keys the IM did not consume reach egui as Key events. + let im = gtk::IMMulticontext::new(); + let keys = gtk::EventControllerKey::new(); + keys.set_im_context(Some(&im)); + let w = self.downgrade(); + im.connect_commit(move |_, text| { + if let Some(a) = w.upgrade() { + // plain typing (no composition) is ordinary text; a commit ends a composition + if a.imp().preedit.replace(false) { + a.push(egui::Event::Ime(egui::ImeEvent::Commit(text.to_string()))); + } else { + a.push(egui::Event::Text(text.to_string())); + } + } + }); + let w = self.downgrade(); + im.connect_preedit_changed(move |im| { + if let Some(a) = w.upgrade() { + let (text, _, _) = im.preedit_string(); + a.imp().preedit.set(!text.is_empty()); + a.push(egui::Event::Ime(egui::ImeEvent::Preedit { text: text.to_string(), active_range_chars: None })); + } + }); + let w = self.downgrade(); + let im2 = im.clone(); + self.connect_has_focus_notify(move |_| { + if let Some(a) = w.upgrade() { + if a.has_focus() { + im2.focus_in(); + } else { + im2.focus_out(); + } + } + }); + let w = self.downgrade(); + keys.connect_key_pressed(move |_, key, _, state| { + w.upgrade().map_or(glib::Propagation::Proceed, |a| a.key(key, state, true)) + }); + let w = self.downgrade(); + keys.connect_key_released(move |_, key, _, state| { + if let Some(a) = w.upgrade() { + a.key(key, state, false); + } + }); + self.add_controller(keys); + } + + fn button(&self, g: >k::GestureClick, x: f64, y: f64, pressed: bool) { + let button = match g.current_button() { + 3 => egui::PointerButton::Secondary, + 2 => egui::PointerButton::Middle, + _ => egui::PointerButton::Primary, + }; + let pos = egui::pos2(x as f32, y as f32) / self.imp().ppp(); + self.push(egui::Event::PointerButton { pos, button, pressed, modifiers: self.imp().mods.get() }); + } + + fn key(&self, key: gdk::Key, state: gdk::ModifierType, pressed: bool) -> glib::Propagation { + let mods = egui::Modifiers { + alt: state.contains(gdk::ModifierType::ALT_MASK), + ctrl: state.contains(gdk::ModifierType::CONTROL_MASK), + shift: state.contains(gdk::ModifierType::SHIFT_MASK), + mac_cmd: false, + command: state.contains(gdk::ModifierType::CONTROL_MASK), + }; + self.imp().mods.set(mods); + let Some(k) = egui_key(key) else { return glib::Propagation::Proceed }; + if mods.command && pressed { + match k { + egui::Key::C => self.push(egui::Event::Copy), + egui::Key::X => self.push(egui::Event::Cut), + _ => {} + } + } + self.push(egui::Event::Key { key: k, physical_key: None, pressed, repeat: false, modifiers: mods }); + glib::Propagation::Stop + } +} + +fn egui_key(k: gdk::Key) -> Option { + use egui::Key as E; + Some(match k { + gdk::Key::Return | gdk::Key::KP_Enter => E::Enter, + gdk::Key::BackSpace => E::Backspace, + gdk::Key::Delete => E::Delete, + gdk::Key::Escape => E::Escape, + gdk::Key::Tab => E::Tab, + gdk::Key::Left => E::ArrowLeft, + gdk::Key::Right => E::ArrowRight, + gdk::Key::Up => E::ArrowUp, + gdk::Key::Down => E::ArrowDown, + gdk::Key::Home => E::Home, + gdk::Key::End => E::End, + gdk::Key::a | gdk::Key::A => E::A, + gdk::Key::c | gdk::Key::C => E::C, + gdk::Key::l | gdk::Key::L => E::L, + gdk::Key::t | gdk::Key::T => E::T, + gdk::Key::v | gdk::Key::V => E::V, + gdk::Key::x | gdk::Key::X => E::X, + _ => return None, + }) +} diff --git a/spikes/webkit-egui/src/main.rs b/spikes/webkit-egui/src/main.rs new file mode 100644 index 0000000..d97e673 --- /dev/null +++ b/spikes/webkit-egui/src/main.rs @@ -0,0 +1,615 @@ +//! Spike (D-033): Nacre's egui chrome in a GTK 4 window, WebKitGTK 6.0 web views placed in the page rect egui +//! leaves free, and a transparent egui overlay above them for flyouts and menus. +//! +//! Layout: Gtk.Overlay { child: Gtk.Fixed { Gtk.Stack of WebViews at egui's page rect }, overlay: EguiArea }. +//! +//! Env: SPIKE_CMD= runs commands appended to that file (see `run_cmd`), outputs into SPIKE_OUT (default the +//! file's folder). Tuning (D-032 knobs, all on by default): SPIKE_PAGE_CACHE=1 turns the page cache back on, +//! SPIKE_MEM_LIMIT= (default 500, 0 = off), SPIKE_CACHE_MODEL=viewer|browser|docbrowser (default viewer), +//! SPIKE_HW=always|never, SPIKE_EGUI=0 hides the egui overlay and toolbar (WebKit alone, for comparison), +//! SPIKE_NATIVE_MENU=1 keeps WebKit's own context menu. SPIKE_DATA= keeps cookies/cache there (else ephemeral). +mod egui_area; + +use std::cell::RefCell; +use std::io::{BufRead, Seek}; +use std::rc::Rc; + +use egui_area::EguiArea; +use gtk::prelude::*; +use gtk::{gdk, glib}; +use webkit::prelude::*; + +const TOOLBAR: f32 = 46.0; +const START: &str = "https://www.youtube.com/watch?v=aqz-KE-bpKQ"; + +fn env(name: &str) -> Option { + std::env::var(name).ok().filter(|v| !v.is_empty()) +} + +enum Act { + Go(String), + Back, + Forward, + Reload, + NewTab(String), + Select(usize), + Close(usize), + Inspect, + Zoom(f64), + Js(String), +} + +#[derive(Default)] +struct Chrome { + url: String, + editing: bool, + focus_url: bool, + menu: bool, + ctx_menu: Option<(egui::Pos2, Option)>, + acts: Vec, +} + +struct Browser { + tabs: Vec, + cur: usize, + stack: gtk::Stack, + fixed: gtk::Fixed, + session: webkit::NetworkSession, + context: webkit::WebContext, + settings: webkit::Settings, + area: Option, + page: egui::Rect, + /// GTK frame clock paint times (s) for frame pacing; split by `stats`. + frames: Rc>>, + out: std::path::PathBuf, +} + +type B = Rc>; + +fn main() -> glib::ExitCode { + let app = gtk::Application::builder().application_id("dev.nacre.WebkitEguiSpike").flags(gtk::gio::ApplicationFlags::NON_UNIQUE).build(); + app.connect_activate(activate); + app.run_with_args::<&str>(&[]) +} + +fn activate(app: >k::Application) { + let mem_limit: u32 = env("SPIKE_MEM_LIMIT").and_then(|v| v.parse().ok()).unwrap_or(500); + let mut pressure = None; + if mem_limit > 0 { + let mut p = webkit::MemoryPressureSettings::new(); + p.set_memory_limit(mem_limit); + webkit::NetworkSession::set_memory_pressure_settings(&mut p.clone()); + pressure = Some(p); + } + let session = match env("SPIKE_DATA") { + Some(d) => webkit::NetworkSession::new(Some(&format!("{d}/data")), Some(&format!("{d}/cache"))), + None => webkit::NetworkSession::new_ephemeral(), + }; + let context = match &pressure { + Some(p) => webkit::WebContext::builder().memory_pressure_settings(p).build(), + None => webkit::WebContext::new(), + }; + context.set_cache_model(match env("SPIKE_CACHE_MODEL").as_deref() { + Some("browser") => webkit::CacheModel::WebBrowser, + Some("docbrowser") => webkit::CacheModel::DocumentBrowser, + _ => webkit::CacheModel::DocumentViewer, + }); + let settings = webkit::Settings::new(); + settings.set_enable_developer_extras(true); + settings.set_enable_page_cache(env("SPIKE_PAGE_CACHE").as_deref() == Some("1")); + settings.set_javascript_can_open_windows_automatically(true); + match env("SPIKE_HW").as_deref() { + Some("never") => settings.set_hardware_acceleration_policy(webkit::HardwareAccelerationPolicy::Never), + Some("always") => settings.set_hardware_acceleration_policy(webkit::HardwareAccelerationPolicy::Always), + _ => {} + } + + let win = gtk::ApplicationWindow::builder().application(app).title("Nacre WebKit spike").default_width(1556).default_height(815).build(); + win.set_decorated(false); + let stack = gtk::Stack::new(); + let fixed = gtk::Fixed::new(); + fixed.put(&stack, 0.0, TOOLBAR as f64); + let overlay = gtk::Overlay::new(); + overlay.set_child(Some(&fixed)); + win.set_child(Some(&overlay)); + + let out = env("SPIKE_OUT").map(Into::into).or_else(|| env("SPIKE_CMD").and_then(|c| std::path::Path::new(&c).parent().map(Into::into))).unwrap_or_else(|| ".".into()); + let b: B = Rc::new(RefCell::new(Browser { + tabs: vec![], + cur: 0, + stack, + fixed, + session, + context, + settings, + area: None, + page: egui::Rect::NOTHING, + frames: Rc::default(), + out, + })); + + let chrome = Rc::new(RefCell::new(Chrome::default())); + if env("SPIKE_EGUI").as_deref() != Some("0") { + let ui = { + let (b, chrome) = (b.clone(), chrome.clone()); + Box::new(move |ui: &mut egui::Ui| draw(ui, &b, &chrome)) as egui_area::UiFn + }; + let area = EguiArea::new(ui); + overlay.add_overlay(&area); + b.borrow_mut().area = Some(area); + } else { + // no chrome: the page fills the window + b.borrow().fixed.move_(&b.borrow().stack, 0.0, 0.0); + } + + // shortcuts that must work while the page has focus (Nacre's keys.rs table goes here) + let keys = gtk::EventControllerKey::new(); + keys.set_propagation_phase(gtk::PropagationPhase::Capture); + { + let (b, chrome) = (b.clone(), chrome.clone()); + keys.connect_key_pressed(move |_, key, _, state| { + if !state.contains(gdk::ModifierType::CONTROL_MASK) { + return glib::Propagation::Proceed; + } + match key { + gdk::Key::l => { + if let Some(a) = b.borrow().area.clone() { + a.grab_focus(); + chrome.borrow_mut().focus_url = true; + a.repaint(); + } + } + gdk::Key::t => new_tab(&b, "about:blank"), + _ => return glib::Propagation::Proceed, + } + glib::Propagation::Stop + }); + } + win.add_controller(keys); + + { + let frames = b.borrow().frames.clone(); + win.connect_realize(move |w| { + if let Some(clock) = w.frame_clock() { + let frames = frames.clone(); + clock.connect_after_paint(move |c| frames.borrow_mut().push(c.frame_time() as f64 / 1e6)); + } + }); + } + win.present(); + new_tab(&b, &env("SPIKE_URL").unwrap_or_else(|| START.into())); + if let Some(a) = b.borrow().area.clone() { + a.repaint(); + } + if let Some(cmd) = env("SPIKE_CMD") { + commands(b.clone(), chrome.clone(), app.clone(), cmd); + } + // apply chrome actions outside the egui frame (they may emit signals synchronously) + glib::timeout_add_local(std::time::Duration::from_millis(16), move || { + let acts = std::mem::take(&mut chrome.borrow_mut().acts); + for a in acts { + apply(&b, &chrome, a); + } + place_page(&b); + glib::ControlFlow::Continue + }); +} + +fn current(b: &B) -> Option { + let b = b.borrow(); + b.tabs.get(b.cur).cloned() +} + +fn repaint(b: &B) { + if let Some(a) = b.borrow().area.clone() { + a.repaint(); + } +} + +fn new_view(b: &B, related: Option<&webkit::WebView>) -> webkit::WebView { + let view = { + let bb = b.borrow(); + match related { + // popups share the opener's web process (window.opener works) + Some(r) => webkit::WebView::builder().related_view(r).settings(&bb.settings).build(), + None => webkit::WebView::builder().network_session(&bb.session).web_context(&bb.context).settings(&bb.settings).build(), + } + }; + let weak = Rc::downgrade(b); + let redraw = move |_: &webkit::WebView| { + if let Some(b) = weak.upgrade() { + repaint(&b); + } + }; + view.connect_title_notify(redraw.clone()); + view.connect_uri_notify(redraw.clone()); + view.connect_estimated_load_progress_notify(redraw); + let weak = Rc::downgrade(b); + view.connect_create(move |v, _action| { + let b = weak.upgrade()?; + let popup = new_view(&b, Some(v)); + add_tab(&b, &popup); + eprintln!("popup opened as tab {}", b.borrow().tabs.len() - 1); + Some(popup.upcast()) + }); + let weak = Rc::downgrade(b); + view.connect_close(move |v| { + if let Some(b) = weak.upgrade() { + let i = b.borrow().tabs.iter().position(|t| t == v); + if let Some(i) = i { + close_tab(&b, i); + } + } + }); + if env("SPIKE_NATIVE_MENU").as_deref() != Some("1") { + let weak = Rc::downgrade(b); + view.connect_context_menu(move |_v, menu, hit| { + let Some(b) = weak.upgrade() else { return false }; + // the event is in surface (window) coordinates + let pos = menu.event().and_then(|e| e.position()).map(|(x, y)| egui::pos2(x as f32, y as f32)); + if let Some(c) = CHROME.with(|c| c.borrow().clone()) { + c.borrow_mut().ctx_menu = pos.map(|p| (p, hit.link_uri().map(|s| s.to_string()))); + eprintln!("context menu at {pos:?} link {:?}", hit.link_uri()); + } + repaint(&b); + true + }); + } + view +} + +thread_local! { + static CHROME: RefCell>>> = const { RefCell::new(None) }; +} + +fn add_tab(b: &B, view: &webkit::WebView) { + let mut bb = b.borrow_mut(); + bb.stack.add_child(view); + bb.tabs.push(view.clone()); + bb.cur = bb.tabs.len() - 1; + bb.stack.set_visible_child(view); + drop(bb); + repaint(b); +} + +fn new_tab(b: &B, url: &str) { + let view = new_view(b, None); + add_tab(b, &view); + view.load_uri(url); +} + +fn close_tab(b: &B, i: usize) { + let mut bb = b.borrow_mut(); + if bb.tabs.len() <= 1 || i >= bb.tabs.len() { + return; + } + let v = bb.tabs.remove(i); + v.try_close(); + bb.stack.remove(&v); + bb.cur = bb.cur.min(bb.tabs.len() - 1); + let cur = bb.tabs[bb.cur].clone(); + bb.stack.set_visible_child(&cur); + drop(bb); + repaint(b); +} + +fn apply(b: &B, chrome: &Rc>, a: Act) { + let view = current(b); + match a { + Act::Go(url) => { + let url = if url.contains("://") || url.starts_with("about:") { url } else { format!("https://{url}") }; + if let Some(v) = view { + v.load_uri(&url); + v.grab_focus(); + } + } + Act::Back => view.inspect(|v| v.go_back()).map_or((), |_| ()), + Act::Forward => view.inspect(|v| v.go_forward()).map_or((), |_| ()), + Act::Reload => view.inspect(|v| v.reload()).map_or((), |_| ()), + Act::NewTab(url) => new_tab(b, &url), + Act::Select(i) => { + let mut bb = b.borrow_mut(); + if let Some(v) = bb.tabs.get(i).cloned() { + bb.cur = i; + bb.stack.set_visible_child(&v); + } + chrome.borrow_mut().editing = false; + } + Act::Close(i) => close_tab(b, i), + Act::Inspect => { + if let Some(i) = view.and_then(|v| v.inspector()) { + i.show(); + } + } + Act::Js(code) => { + if let Some(v) = view { + v.evaluate_javascript(&code, None, None, None::<>k::gio::Cancellable>, |_| {}); + } + } + Act::Zoom(f) => { + if let Some(v) = view { + v.set_zoom_level((v.zoom_level() * f).clamp(0.3, 5.0)); + } + } + } + repaint(b); +} + +/// Move/resize the web view stack to the page rect egui left free. +fn place_page(b: &B) { + let mut bb = b.borrow_mut(); + let Some(area) = bb.area.clone() else { return }; + let r = area.page_rect(); + if r == bb.page || !r.is_positive() { + return; + } + bb.page = r; + bb.fixed.move_(&bb.stack, r.min.x as f64, r.min.y as f64); + bb.stack.set_size_request(r.width() as i32, r.height() as i32); +} + +fn draw(ui: &mut egui::Ui, b: &B, chrome: &Rc>) -> egui::Rect { + CHROME.with(|c| *c.borrow_mut() = Some(chrome.clone())); + let mut c = chrome.borrow_mut(); + let (titles, cur, view) = { + let bb = b.borrow(); + let titles: Vec = bb.tabs.iter().map(|t| t.title().map(|s| s.to_string()).filter(|s| !s.is_empty()).unwrap_or_else(|| "New tab".into())).collect(); + (titles, bb.cur, bb.tabs.get(bb.cur).cloned()) + }; + if !c.editing { + c.url = view.as_ref().and_then(|v| v.uri()).map(|s| s.to_string()).unwrap_or_default(); + } + let frame = egui::Frame::new().fill(egui::Color32::from_rgb(0x1d, 0x1b, 0x20)).inner_margin(egui::Margin::symmetric(8, 6)); + egui::Panel::top("toolbar").exact_size(TOOLBAR).frame(frame).show_separator_line(false).show(ui, |ui| { + ui.horizontal_centered(|ui| { + for (i, t) in titles.iter().enumerate() { + let label: String = t.chars().take(18).collect(); + if ui.selectable_label(i == cur, label).clicked() { + c.acts.push(Act::Select(i)); + } + if titles.len() > 1 && ui.small_button("×").clicked() { + c.acts.push(Act::Close(i)); + } + } + if ui.button("+").clicked() { + c.acts.push(Act::NewTab("about:blank".into())); + } + ui.separator(); + if ui.add_enabled(view.as_ref().is_some_and(|v| v.can_go_back()), egui::Button::new("←")).clicked() { + c.acts.push(Act::Back); + } + if ui.add_enabled(view.as_ref().is_some_and(|v| v.can_go_forward()), egui::Button::new("→")).clicked() { + c.acts.push(Act::Forward); + } + if ui.button("⟳").clicked() { + c.acts.push(Act::Reload); + } + let progress = view.as_ref().map_or(1.0, |v| v.estimated_load_progress()); + let url_id = egui::Id::new("url"); + let resp = ui.add(egui::TextEdit::singleline(&mut c.url).id(url_id).desired_width(ui.available_width() - 48.0)); + if c.focus_url { + c.focus_url = false; + resp.request_focus(); + if let Some(mut st) = egui::TextEdit::load_state(ui.ctx(), url_id) { + st.cursor.set_char_range(Some(egui::text::CCursorRange::two(egui::text::CCursor::new(0), egui::text::CCursor::new(c.url.chars().count())))); + st.store(ui.ctx(), url_id); + } + } + if resp.changed() { + c.editing = true; + } + if resp.lost_focus() { + if ui.input(|i| i.key_pressed(egui::Key::Enter)) { + let url = c.url.clone(); + c.acts.push(Act::Go(url)); + } + c.editing = false; + } + if progress < 1.0 { + let r = resp.rect; + let w = r.width() * progress as f32; + ui.painter().rect_filled(egui::Rect::from_min_size(egui::pos2(r.min.x, r.max.y - 2.0), egui::vec2(w, 2.0)), 0.0, egui::Color32::from_rgb(0xd0, 0xbc, 0xff)); + } + if ui.button("⋮").clicked() { + c.menu = !c.menu; + } + }); + }); + let page = ui.available_rect_before_wrap(); + + // a flyout over the web page (proves egui draws over the WebView and takes the pointer only there) + if c.menu { + let pos = egui::pos2(page.max.x - 8.0, page.min.y + 4.0); + let r = egui::Area::new(egui::Id::new("menu")).fixed_pos(pos).pivot(egui::Align2::RIGHT_TOP).order(egui::Order::Foreground).show(ui.ctx(), |ui| { + egui::Frame::popup(ui.style()).show(ui, |ui| { + ui.set_width(260.0); + ui.label(egui::RichText::new("Nacre menu (egui over WebKit)").strong()); + ui.separator(); + for (label, act) in [("New tab", 0), ("Zoom in", 1), ("Zoom out", 2), ("Web Inspector", 3), ("Open popup (window.open)", 4)] { + if ui.button(label).clicked() { + c.acts.push(match act { + 0 => Act::NewTab("about:blank".into()), + 1 => Act::Zoom(1.1), + 2 => Act::Zoom(1.0 / 1.1), + 3 => Act::Inspect, + _ => Act::Js("window.open('https://example.com/','_blank','width=500,height=400'); 0".into()), + }); + c.menu = false; + } + } + }); + }); + if r.response.clicked_elsewhere() && !ui.ctx().input(|i| i.pointer.any_pressed() && i.pointer.interact_pos().is_some_and(|p| p.y < TOOLBAR)) { + c.menu = false; + } + } + // the page's context menu, drawn by egui at the click position (WebKit's own is suppressed) + if let Some((pos, link)) = c.ctx_menu.clone() { + let r = egui::Area::new(egui::Id::new("ctx")).fixed_pos(pos).order(egui::Order::Foreground).constrain(true).show(ui.ctx(), |ui| { + egui::Frame::popup(ui.style()).show(ui, |ui| { + ui.set_width(220.0); + if let Some(l) = &link { + if ui.button("Open link in new tab").clicked() { + c.acts.push(Act::NewTab(l.clone())); + c.ctx_menu = None; + } + } + for (label, a) in [("Back", 0), ("Reload", 1), ("Inspect", 2)] { + if ui.button(label).clicked() { + c.acts.push(match a { + 0 => Act::Back, + 1 => Act::Reload, + _ => Act::Inspect, + }); + c.ctx_menu = None; + } + } + }); + }); + if r.response.clicked_elsewhere() || ui.ctx().input(|i| i.key_pressed(egui::Key::Escape)) { + c.ctx_menu = None; + } + } + page +} + +/// Driver: reads commands appended to `path`, one per line, waiting for each to finish. +/// open URL | go URL | tab I | menu 0|1 | js NAME CODE | shot NAME | stats NAME | pick NAME X Y [X Y ...] +/// | focus web|url | sleep S | mark LABEL | quit +fn commands(b: B, chrome: Rc>, app: gtk::Application, path: String) { + let file = std::fs::File::open(&path).expect("SPIKE_CMD file"); + let reader = Rc::new(RefCell::new(std::io::BufReader::new(file))); + let busy = Rc::new(std::cell::Cell::new(false)); + let last = Rc::new(std::cell::Cell::new(0usize)); + glib::timeout_add_local(std::time::Duration::from_millis(100), move || { + if busy.get() { + return glib::ControlFlow::Continue; + } + let mut line = String::new(); + let mut r = reader.borrow_mut(); + let pos = r.stream_position().unwrap_or(0); + if r.read_line(&mut line).unwrap_or(0) == 0 || !line.ends_with('\n') { + let _ = r.seek(std::io::SeekFrom::Start(pos)); + return glib::ControlFlow::Continue; + } + drop(r); + let line = line.trim().to_string(); + if line.is_empty() || line.starts_with('#') { + return glib::ControlFlow::Continue; + } + eprintln!("cmd: {line}"); + run_cmd(&b, &chrome, &app, &line, &busy, &last); + glib::ControlFlow::Continue + }); +} + +fn write(b: &B, name: &str, text: &str) { + let p = b.borrow().out.join(name); + std::fs::write(&p, text).unwrap_or_else(|e| eprintln!("write {}: {e}", p.display())); +} + +fn run_cmd(b: &B, chrome: &Rc>, app: >k::Application, line: &str, busy: &Rc>, last: &Rc>) { + let mut parts = line.splitn(3, ' '); + let (cmd, a1, rest) = (parts.next().unwrap_or(""), parts.next().unwrap_or(""), parts.next().unwrap_or("")); + match cmd { + "open" => new_tab(b, a1), + "go" => chrome.borrow_mut().acts.push(Act::Go(a1.into())), + "tab" => chrome.borrow_mut().acts.push(Act::Select(a1.parse().unwrap_or(0))), + "menu" => { + chrome.borrow_mut().menu = a1 == "1"; + repaint(b); + } + "mark" => write(b, "mark", a1), + "focus" => match a1 { + "url" => { + if let Some(a) = b.borrow().area.clone() { + a.grab_focus(); + } + chrome.borrow_mut().focus_url = true; + repaint(b); + } + _ => { + if let Some(v) = current(b) { + v.grab_focus(); + } + } + }, + "sleep" => { + busy.set(true); + let busy = busy.clone(); + glib::timeout_add_local_once(std::time::Duration::from_secs_f64(a1.parse().unwrap_or(1.0)), move || busy.set(false)); + } + "js" => { + let Some(v) = current(b) else { return }; + busy.set(true); + let (busy, b2, name) = (busy.clone(), b.clone(), a1.to_string()); + v.evaluate_javascript(rest, None, None, None::<>k::gio::Cancellable>, move |r| { + let text = match r { + Ok(val) => val.to_str().to_string(), + Err(e) => serde_json::json!({ "error": e.to_string() }).to_string(), + }; + eprintln!("js {name}: {}", text.chars().take(300).collect::()); + write(&b2, &format!("{name}.json"), &text); + busy.set(false); + }); + } + "shot" => { + let out = b.borrow().out.join(format!("{a1}.png")); + let output = env("SPIKE_OUTPUT").unwrap_or_else(|| "DP-1".into()); + let _ = std::process::Command::new("grim").args(["-o", &output]).arg(&out).status(); + } + "stats" => { + let bb = b.borrow(); + let frames = bb.frames.borrow(); + let from = last.replace(frames.len()); + let f = &frames[from.min(frames.len())..]; + let mut iv: Vec = f.windows(2).map(|w| (w[1] - w[0]) * 1000.0).collect(); + iv.sort_by(|a, b| a.partial_cmp(b).unwrap()); + let pct = |p: f64| iv.get(((iv.len() as f64 - 1.0) * p) as usize).copied().unwrap_or(0.0); + let secs = f.last().zip(f.first()).map_or(0.0, |(l, f)| l - f); + let render = bb.area.as_ref().map(|a| a.render_ms()).unwrap_or_default(); + let mut rs = render.clone(); + rs.sort_by(|a, b| a.partial_cmp(b).unwrap()); + let rp = |p: f64| rs.get(((rs.len() as f64 - 1.0) * p) as usize).copied().unwrap_or(0.0); + let json = serde_json::json!({ + "window_frames": f.len(), "seconds": secs, "fps": if secs > 0.0 { f.len() as f64 / secs } else { 0.0 }, + "interval_ms": {"p50": pct(0.5), "p95": pct(0.95), "p99": pct(0.99), "max": pct(1.0)}, + "egui_renders_total": render.len(), "egui_render_ms": {"p50": rp(0.5), "p95": rp(0.95), "max": rp(1.0)}, + "tabs": bb.tabs.len(), "page_rect": [bb.page.min.x, bb.page.min.y, bb.page.width(), bb.page.height()], + }); + drop(frames); + drop(bb); + write(b, &format!("{a1}.json"), &json.to_string()); + } + "pick" => { + // which widget gets the pointer at window points X Y (GTK's own hit test, the one real events use) + let Some(win) = b.borrow().stack.root() else { return }; + let nums: Vec = rest.split_whitespace().filter_map(|n| n.parse().ok()).collect(); + let mut res = vec![]; + for p in nums.chunks(2) { + let w = win.pick(p[0], p[1], gtk::PickFlags::DEFAULT); + let mut chain = vec![]; + let mut cur = w; + while let Some(x) = cur { + chain.push(x.type_().name().to_string()); + cur = x.parent(); + } + res.push(serde_json::json!({"x": p[0], "y": p[1], "widget": chain.first(), "chain": chain})); + } + write(b, &format!("{a1}.json"), &serde_json::Value::Array(res).to_string()); + } + "state" => { + let c = chrome.borrow(); + let bb = b.borrow(); + let json = serde_json::json!({ + "url_field": c.url, "editing": c.editing, "menu": c.menu, "ctx_menu": c.ctx_menu.as_ref().map(|(p, l)| serde_json::json!({"x": p.x, "y": p.y, "link": l})), + "tabs": bb.tabs.iter().map(|t| serde_json::json!({"title": t.title().map(|s| s.to_string()), "uri": t.uri().map(|s| s.to_string()), "zoom": t.zoom_level()})).collect::>(), + "cur": bb.cur, "egui_focus": bb.area.as_ref().is_some_and(|a| a.has_focus()), + }); + drop(bb); + write(b, &format!("{a1}.json"), &json.to_string()); + } + "quit" => app.quit(), + _ => eprintln!("unknown command {cmd}"), + } +}