Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
Add spike S1: Qt Quick + Rust proof of the desktop stack
Bee8580eb3b91d1
diff --git a/.cargo/config.toml b/.cargo/config.tomlnew file mode 100644index 0000000..5dabd77--- /dev/null+++ b/.cargo/config.toml@@ -0,0 +1,6 @@+# Read all C++ sources as UTF-8 on Windows. Without this, MSVC uses the+# system codepage and non-ASCII text in generated QML code (e.g. "·", or any+# translated string) is garbled.+[env]+CXXFLAGS_x86_64_pc_windows_msvc = "/utf-8"+CXXFLAGS_aarch64_pc_windows_msvc = "/utf-8"diff --git a/Cargo.lock b/Cargo.lockindex 350e98e..a3f05c1 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -267,6 +267,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "f74872d07caf508b30a21f6836e7d7016a2eaf7d9ff4f48deaa58cd8a0407630"dependencies = ["find-msvc-tools",+ "jobserver",+ "libc","shlex",]@@ -348,6 +350,15 @@ dependencies = ["inout",]+[[package]]+name = "clang-format"+version = "0.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "696283b40e1a39d208ee614b92e5f6521d16962edeb47c48372585ec92419943"+dependencies = [+ "thiserror 1.0.69",+]+[[package]]name = "clap"version = "4.6.7"@@ -403,6 +414,27 @@ dependencies = ["thiserror 2.0.21",]+[[package]]+name = "codespan-reporting"+version = "0.11.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e"+dependencies = [+ "termcolor",+ "unicode-width 0.1.14",+]++[[package]]+name = "codespan-reporting"+version = "0.13.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "af491d569909a7e4dee0ad7db7f5341fef5c614d5b8ec8cf765732aba3cff681"+dependencies = [+ "serde",+ "termcolor",+ "unicode-width 0.2.2",+]+[[package]]name = "colorchoice"version = "1.0.5"@@ -431,6 +463,15 @@ version = "0.4.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "3d52eff69cd5e647efe296129160853a42795992097e8af39800e1060caeea9b"+[[package]]+name = "convert_case"+version = "0.6.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca"+dependencies = [+ "unicode-segmentation",+]+[[package]]name = "convert_case"version = "0.10.0"@@ -563,6 +604,151 @@ dependencies = ["syn 2.0.119",]+[[package]]+name = "cxx"+version = "1.0.202"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "13f6de320895f42e6e081abb5c7983bedcf0b6d0ff9323de0d33f620c8ac1199"+dependencies = [+ "cc",+ "cxx-build",+ "cxxbridge-cmd",+ "cxxbridge-flags",+ "cxxbridge-macro",+ "foldhash",+ "link-cplusplus",+]++[[package]]+name = "cxx-build"+version = "1.0.202"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4fde53ca86b9704a943fef0f1e1d836239a6aedca5de3c65fa9f97ec0bd46d39"+dependencies = [+ "cc",+ "codespan-reporting 0.13.1",+ "indexmap",+ "proc-macro2",+ "quote",+ "scratch",+ "syn 3.0.6",+]++[[package]]+name = "cxx-gen"+version = "0.7.202"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5010d4044b4ac8b18aca2341f3a6227aaf332ec8f5e38fcb93cba53451f2dc92"+dependencies = [+ "codespan-reporting 0.13.1",+ "indexmap",+ "proc-macro2",+ "quote",+ "syn 3.0.6",+]++[[package]]+name = "cxx-qt"+version = "0.10.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "af6a52cbe33f8a23c6cc7dafb628819b89af6536102c3976f5efc33a038d4a82"+dependencies = [+ "cxx",+ "cxx-qt-build",+ "cxx-qt-macro",+ "qt-build-utils",+ "static_assertions",+ "thiserror 1.0.69",+]++[[package]]+name = "cxx-qt-build"+version = "0.10.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7bb2bb9e19b427e79ec5db1d88cde2f44f2d4190e5a0177e2d599ceb9277b670"+dependencies = [+ "cc",+ "codespan-reporting 0.11.1",+ "cxx-gen",+ "cxx-qt-gen",+ "proc-macro2",+ "qt-build-utils",+ "quote",+ "serde",+ "serde_json",+]++[[package]]+name = "cxx-qt-gen"+version = "0.10.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a6de19cacc58672a9fb70fad66e3d62b6aeb4b2f323b6251aeb99b50c6b6aa0c"+dependencies = [+ "clang-format",+ "convert_case 0.6.0",+ "cxx-gen",+ "indoc",+ "proc-macro2",+ "quote",+ "syn 2.0.119",+]++[[package]]+name = "cxx-qt-lib"+version = "0.10.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1e3c9fea8106d4bbe438d15c1242acd38f4869ca4f6d2a0b19e1f0dbbf23a50e"+dependencies = [+ "cxx",+ "cxx-qt",+ "cxx-qt-build",+ "qt-build-utils",+]++[[package]]+name = "cxx-qt-macro"+version = "0.10.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "cb794f10a4d27bfbd810eb8bf7fd7d9a0b0b5cefcd86a4c7b13ae3f8d4fa0169"+dependencies = [+ "cxx-qt-gen",+ "proc-macro2",+ "quote",+ "syn 2.0.119",+]++[[package]]+name = "cxxbridge-cmd"+version = "1.0.202"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "07bae89236c811fd4d08ed3441759ac4ac98d752cbfd3de341315ba16ad20ec3"+dependencies = [+ "clap",+ "codespan-reporting 0.13.1",+ "indexmap",+ "proc-macro2",+ "quote",+ "syn 3.0.6",+]++[[package]]+name = "cxxbridge-flags"+version = "1.0.202"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "49045042e5fced01b80742aba5508de82aa4f13677ed3fa2b4cda709c40c5918"++[[package]]+name = "cxxbridge-macro"+version = "1.0.202"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b181252e2e3d3b5d183afbdc033a3958b445eb3e1a0ae65fc3d4f5259f5da6fd"+dependencies = [+ "indexmap",+ "proc-macro2",+ "quote",+ "syn 3.0.6",+]+[[package]]name = "data-encoding"version = "2.11.1"@@ -621,7 +807,7 @@ version = "2.1.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb"dependencies = [- "convert_case",+ "convert_case 0.10.0","proc-macro2","quote","rustc_version",@@ -1387,6 +1573,15 @@ dependencies = ["hashbrown 0.17.1",]+[[package]]+name = "indoc"+version = "2.0.7"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706"+dependencies = [+ "rustversion",+]+[[package]]name = "inout"version = "0.1.4"@@ -1684,6 +1879,16 @@ dependencies = ["syn 2.0.119",]+[[package]]+name = "jobserver"+version = "0.1.35"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3"+dependencies = [+ "getrandom 0.4.3",+ "libc",+]+[[package]]name = "js-sys"version = "0.3.106"@@ -1727,6 +1932,15 @@ dependencies = ["vcpkg",]+[[package]]+name = "link-cplusplus"+version = "1.0.12"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7f78c730aaa7d0b9336a299029ea49f9ee53b0ed06e9202e8cb7db9bae7b8c82"+dependencies = [+ "cc",+]+[[package]]name = "linux-raw-sys"version = "0.12.1"@@ -2586,6 +2800,20 @@ version = "0.14.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "d68782463e408eb1e668cf6152704bd856c78c5b6417adaee3203d8f4c1fc9ec"+[[package]]+name = "qt-build-utils"+version = "0.10.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7c97911f105c362cbc035f631be7b43e44d9bca3a3aed2434260ba896f23d6b4"+dependencies = [+ "anyhow",+ "cc",+ "semver",+ "serde",+ "thiserror 1.0.69",+ "which",+]+[[package]]name = "quick-xml"version = "0.42.0"@@ -2863,6 +3091,17 @@ version = "1.0.23"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"+[[package]]+name = "s1-qt-rust"+version = "0.0.0"+dependencies = [+ "cxx",+ "cxx-qt",+ "cxx-qt-build",+ "cxx-qt-lib",+ "windows",+]+[[package]]name = "same-file"version = "1.0.6"@@ -2893,6 +3132,12 @@ version = "1.2.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"+[[package]]+name = "scratch"+version = "1.0.9"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d68f2ec51b097e4c1a75b681a8bec621909b5e91f15bb7b840c4f2f7b01148b2"+[[package]]name = "security-framework"version = "3.7.0"@@ -2974,6 +3219,19 @@ dependencies = ["syn 3.0.6",]+[[package]]+name = "serde_json"+version = "1.0.151"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14"+dependencies = [+ "itoa",+ "memchr",+ "serde",+ "serde_core",+ "zmij",+]+[[package]]name = "serdect"version = "0.4.3"@@ -3139,6 +3397,12 @@ version = "1.2.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"+[[package]]+name = "static_assertions"+version = "1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"+[[package]]name = "strsim"version = "0.11.1"@@ -3263,6 +3527,15 @@ dependencies = ["windows-sys 0.61.2",]+[[package]]+name = "termcolor"+version = "1.4.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755"+dependencies = [+ "winapi-util",+]+[[package]]name = "thiserror"version = "1.0.69"@@ -3607,6 +3880,18 @@ version = "1.13.3"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8"+[[package]]+name = "unicode-width"+version = "0.1.14"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"++[[package]]+name = "unicode-width"+version = "0.2.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254"+[[package]]name = "unicode-xid"version = "0.2.6"@@ -3804,6 +4089,15 @@ dependencies = ["rustls-pki-types",]+[[package]]+name = "which"+version = "8.0.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "bae2f2b2b816647a1cab1acc91f5bd20812d53cb344382635ec2181940c8034f"+dependencies = [+ "libc",+]+[[package]]name = "widestring"version = "1.2.1"@@ -4290,3 +4584,9 @@ dependencies = ["quote","syn 3.0.6",]++[[package]]+name = "zmij"+version = "1.0.23"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"diff --git a/Cargo.toml b/Cargo.tomlindex 90cf90a..c79d80e 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -4,6 +4,7 @@ members = ["core/nectarlink-protocol","core/nectarlink-core","core/nectarlink-cli",+ "spikes/s1-qt-rust",][workspace.package]diff --git a/docs/PLAN.md b/docs/PLAN.mdindex 7444fdb..eb32ba4 100644--- a/docs/PLAN.md+++ b/docs/PLAN.md@@ -464,7 +464,7 @@ What we optimize for, in order:| Issue | Rule / mitigation ||---|---|| Three languages in the UI layer (QML, Rust, a little C++) | **QML is presentation only**: screens, layout and animation. No business logic in QML/JavaScript. C++ is limited to the video item and a few window tweaks |-| cxx-qt is pre-1.0 (0.9.x, KDAB) | Pin the version, upgrade on purpose. **One bridge crate (`nectarlink-qt`)** is the only place Rust touches Qt |+| cxx-qt is pre-1.0 (0.10.x, KDAB) | Pin the version, upgrade on purpose. **One bridge crate (`nectarlink-qt`)** is the only place Rust touches Qt || Heavier build (Qt install, C++ glue, separate ARM64 build) | Install Qt via aqtinstall, cached in CI. Windows ARM64 is a supported Qt platform (MSVC 2022). Scripts make it one command locally || Two threading worlds (Rust async runtime vs Qt's screen thread) | **One pattern everywhere** for handing core events to the screen thread (cxx-qt's thread queue). No ad-hoc cross-thread calls || Bigger installer (+30–50 MB) | Ship only the Qt modules we use. `windeployqt` with an explicit module list |diff --git a/spikes/s1-qt-rust/Cargo.toml b/spikes/s1-qt-rust/Cargo.tomlnew file mode 100644index 0000000..c794348--- /dev/null+++ b/spikes/s1-qt-rust/Cargo.toml@@ -0,0 +1,25 @@+[package]+name = "s1-qt-rust"+description = "Spike S1: Qt Quick + Rust proof (throwaway, see README.md)"+version = "0.0.0"+edition = "2024"+publish = false+license = "GPL-3.0-or-later"++[dependencies]+cxx = "1"+cxx-qt = "0.10"+cxx-qt-lib = { version = "0.10", features = ["qt_full"] }++[target.'cfg(windows)'.dependencies]+windows = { workspace = true, features = [+ "Win32_Foundation",+ "Win32_System_ProcessStatus",+ "Win32_System_Threading",+ "Win32_Graphics_Dwm",+ "Win32_UI_WindowsAndMessaging",+ "Win32_UI_Controls",+] }++[build-dependencies]+cxx-qt-build = { version = "0.10", features = ["link_qt_object_files"] }diff --git a/spikes/s1-qt-rust/README.md b/spikes/s1-qt-rust/README.mdnew file mode 100644index 0000000..a62bbbd--- /dev/null+++ b/spikes/s1-qt-rust/README.md@@ -0,0 +1,38 @@+# Spike S1: Qt Quick + Rust proof++Throwaway code. What we keep is the knowledge below.++Run (needs Qt 6.12 on PATH and `QMAKE` set):+`cargo run --release -p s1-qt-rust` · `-- --autotest` (self-driving measurement) · `-- --mica`++## Results (2026-10-05, this machine, 144 Hz display, release build)++| Criterion | Budget | Result | |+|---|---|---|---|+| First frame | < 500 ms | ~400 ms | ✅ |+| RAM, main window open | < 120 MB | ~88 MB idle, ~104 MB under 10k events/s | ✅ |+| Smoothness under load | 120 fps | 144 fps avg, 143 min (display max) at 10,000 core events/s + hero transition | ✅ |+| Core→UI events | 10k/s without stutter | ✅ with coalescing (see below) | ✅ |+| Bloom design fidelity | matches mockups | Home, notification cards, Deck, shared-element conversation transition, real blur (MultiEffect) | ✅ |+| Mica | works | ⏳ DWM calls succeed and window alpha works, but the backdrop shows white: needs Qt-side presentation work | follow-up |+| Video in scene graph (zero copy) | works | ⏳ not started | follow-up (with S2) |+| ARM64 build | CI builds | ⏳ not tried | follow-up |+| Tray-only RAM < 60 MB | | ⏳ not measured (no tray mode yet) | follow-up |++## Lessons (apply to the real `nectarlink-qt`)++1. **Never queue one closure per core event.** It ballooned to 5.7 GB at 10k/s.+ Use a coalescing pump: latest state in a shared slot, at most one queued+ flush, non-mergeable events batched and bounded (`UiPump` in `src/bridge.rs`).+2. **MSVC needs `/utf-8`** or non-ASCII text in qmlcachegen output is garbled+ (set repo-wide in `.cargo/config.toml`).+3. **`#[auto_cxx_name]`** on `extern "RustQt"` blocks gives QML camelCase names.+4. **QML can't have properties named `onX`**: Material token `onSurface` becomes+ `surfaceContent` in QML (token generator must map this).+5. `font.pixelSize` must be an integer.+6. Windows sends Qt logs to the debugger; set `QT_FORCE_STDERR_LOGGING=1` when diagnosing.++## Verdict++**Gate passed for the UI stack** (looks, smoothness, memory, startup, event throughput).+Mica, the zero-copy video item, ARM64 and tray-mode memory remain to verify.diff --git a/spikes/s1-qt-rust/build.rs b/spikes/s1-qt-rust/build.rsnew file mode 100644index 0000000..219b69b--- /dev/null+++ b/spikes/s1-qt-rust/build.rs@@ -0,0 +1,19 @@+// SPDX-License-Identifier: GPL-3.0-or-later+use cxx_qt_build::{CxxQtBuilder, QmlFile, QmlModule};++fn main() {+ CxxQtBuilder::new_qml_module(QmlModule::new("app.nectarlink.spike").qml_files([+ QmlFile::from("qml/Main.qml"),+ QmlFile::from("qml/Theme.qml").singleton(true),+ QmlFile::from("qml/Icon.qml"),+ QmlFile::from("qml/QuickAction.qml"),+ QmlFile::from("qml/NotificationCard.qml"),+ QmlFile::from("qml/DeckKey.qml"),+ QmlFile::from("qml/StatsPanel.qml"),+ ]))+ .qt_module("Quick")+ .include_dir("cpp")+ .cpp_file("cpp/window_helpers.cpp")+ .files(["src/bridge.rs", "src/native.rs"])+ .build();+}diff --git a/spikes/s1-qt-rust/cpp/window_helpers.cpp b/spikes/s1-qt-rust/cpp/window_helpers.cppnew file mode 100644index 0000000..0591059--- /dev/null+++ b/spikes/s1-qt-rust/cpp/window_helpers.cpp@@ -0,0 +1,11 @@+// SPDX-License-Identifier: GPL-3.0-or-later+#include "window_helpers.h"++#include <QtQuick/QQuickWindow>++void enable_window_alpha()+{+ // Gives Qt Quick windows an alpha channel so the Windows 11 Mica+ // backdrop can show through transparent areas.+ QQuickWindow::setDefaultAlphaBuffer(true);+}diff --git a/spikes/s1-qt-rust/cpp/window_helpers.h b/spikes/s1-qt-rust/cpp/window_helpers.hnew file mode 100644index 0000000..c2df720--- /dev/null+++ b/spikes/s1-qt-rust/cpp/window_helpers.h@@ -0,0 +1,5 @@+// SPDX-License-Identifier: GPL-3.0-or-later+#pragma once++// Must be called before any QQuickWindow is created.+void enable_window_alpha();diff --git a/spikes/s1-qt-rust/qml/DeckKey.qml b/spikes/s1-qt-rust/qml/DeckKey.qmlnew file mode 100644index 0000000..3201ac0--- /dev/null+++ b/spikes/s1-qt-rust/qml/DeckKey.qml@@ -0,0 +1,27 @@+import QtQuick++Rectangle {+ id: key+ property string label+ property string detail+ property string iconPath+ property bool active: false++ radius: Theme.radiusLg+ color: active ? Theme.primary : Theme.surfaceContainer+ scale: tap.pressed ? 0.94 : 1.0+ Behavior on scale { SpringAnimation { spring: 6.2; damping: 0.34 } }+ Behavior on color { ColorAnimation { duration: 180 } }++ Rectangle {+ x: 11; y: 11; width: 30; height: 30; radius: Theme.radiusSm+ color: key.active ? Qt.rgba(1, 1, 1, 0.18) : Theme.surfaceContainerHighest+ Icon { anchors.centerIn: parent; path: key.iconPath; width: 18; height: 18; color: key.active ? Theme.primaryContent : Theme.surfaceContent }+ }+ Column {+ anchors { left: parent.left; bottom: parent.bottom; margins: 11 }+ Text { text: key.label; font.family: Theme.font; font.pixelSize: 12; font.weight: Font.DemiBold; color: key.active ? Theme.primaryContent : Theme.surfaceContent }+ Text { text: key.detail; font.family: Theme.font; font.pixelSize: 10; opacity: 0.75; color: key.active ? Theme.primaryContent : Theme.surfaceContent }+ }+ TapHandler { id: tap; onTapped: key.active = !key.active }+}diff --git a/spikes/s1-qt-rust/qml/Icon.qml b/spikes/s1-qt-rust/qml/Icon.qmlnew file mode 100644index 0000000..ec08d90--- /dev/null+++ b/spikes/s1-qt-rust/qml/Icon.qml@@ -0,0 +1,28 @@+import QtQuick+import QtQuick.Shapes++// Stroke icon from an SVG path on a 24x24 grid (same paths as the design mockups).+Item {+ id: icon+ property string path+ property color color: Theme.surfaceContent+ property real stroke: 1.8+ implicitWidth: 20+ implicitHeight: 20++ Shape {+ anchors.centerIn: parent+ width: 24+ height: 24+ scale: icon.width / 24+ preferredRendererType: Shape.CurveRenderer+ ShapePath {+ strokeColor: icon.color+ strokeWidth: icon.stroke+ fillColor: "transparent"+ capStyle: ShapePath.RoundCap+ joinStyle: ShapePath.RoundJoin+ PathSvg { path: icon.path }+ }+ }+}diff --git a/spikes/s1-qt-rust/qml/Main.qml b/spikes/s1-qt-rust/qml/Main.qmlnew file mode 100644index 0000000..68e02b8--- /dev/null+++ b/spikes/s1-qt-rust/qml/Main.qml@@ -0,0 +1,384 @@+import QtQuick+import QtQuick.Effects+import app.nectarlink.spike++Window {+ id: window+ readonly property bool mica: Qt.application.arguments.indexOf("--mica") >= 0+ width: 1180+ height: 720+ minimumWidth: 980+ minimumHeight: 640+ visible: true+ title: "Nectarlink · S1 proof"+ color: mica ? "transparent" : Theme.surface++ DeviceModel {+ id: device+ onNotification: (app, title, body) => {+ notifications.insert(0, { app: app, title: title, body: body, time: "now" })+ if (notifications.count > 40)+ notifications.remove(notifications.count - 1)+ }+ }++ ListModel {+ id: notifications+ ListElement { app: "Google"; title: "Sign-in code"; body: "Your verification code is 482 913"; time: "now" }+ ListElement { app: "WhatsApp"; title: "Mom"; body: "Dinner at 8? Bring the charger you borrowed."; time: "2m" }+ ListElement { app: "Swiggy"; title: "On the way"; body: "Your order arrives in 12 minutes"; time: "18m" }+ ListElement { app: "Calendar"; title: "Design review"; body: "With Aanya at 4:30 PM"; time: "1h" }+ ListElement { app: "Discord"; title: "#general"; body: "6 new messages"; time: "2h" }+ }++ // --autotest: drives the proof by itself and prints the measurements.+ readonly property bool autotest: Qt.application.arguments.indexOf("--autotest") >= 0+ property real minFps: 1e9+ property real fpsSum: 0+ property int fpsSamples: 0+ Timer {+ running: window.autotest; interval: 1000; repeat: false+ onTriggered: { stats.measuring = true; device.startStress(10000); phase2.start() }+ }+ Timer {+ id: phase2; interval: 2000+ onTriggered: { detail.openFrom(list.itemAtIndex(0), "Mom", "WhatsApp", "Dinner at 8? Bring the charger you borrowed."); phase3.start() }+ }+ Timer {+ id: phase3; interval: 2500+ onTriggered: { detail.close(); phase4.start() }+ }+ Timer {+ id: phase4; interval: 2000+ onTriggered: {+ device.refreshMemory()+ console.log("AUTOTEST fps_avg=" + (window.fpsSum / Math.max(1, window.fpsSamples)).toFixed(1)+ + " fps_min=" + window.minFps.toFixed(1)+ + " events_per_s=" + device.eventsPerSecond+ + " events_total=" + Math.round(device.eventsTotal)+ + " notifications=" + notifications.count+ + " mem_mb=" + device.workingSetMb.toFixed(1)+ + " first_frame_ms=" + device.startupMs.toFixed(0))+ device.stopStress()+ Qt.quit()+ }+ }+ Timer {+ running: window.autotest && stats.measuring; interval: 250; repeat: true+ onTriggered: {+ // Skip the first second while the frame clock settles.+ if (stats.fps > 0 && device.eventsTotal > 10000) {+ window.minFps = Math.min(window.minFps, stats.fps)+ window.fpsSum += stats.fps; window.fpsSamples += 1+ }+ }+ }++ // Report the first rendered frame for the startup measurement.+ Connections {+ target: window+ function onFrameSwapped() { device.firstFrame(); target = null }+ }++ readonly property var icons: ({+ home: "M3 11l9-7 9 7M5 10v10h14V10",+ msg: "M21 12a8 8 0 0 1-11.6 7.1L4 20l1-4.6A8 8 0 1 1 21 12z",+ bell: "M6 8a6 6 0 1 1 12 0c0 7 3 8 3 8H3s3-1 3-8M10 20a2 2 0 0 0 4 0",+ photo: "M6 3h12a3 3 0 0 1 3 3v12a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3V6a3 3 0 0 1 3-3zM21 15l-5-5L5 21",+ apps: "M4 4h6v6H4zM14 4h6v6h-6zM4 14h6v6H4zM14 14h6v6h-6z",+ deck: "M6 5h12a3 3 0 0 1 3 3v8a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3V8a3 3 0 0 1 3-3zM8 14h8",+ gear: "M12 9a3 3 0 1 0 0 6 3 3 0 0 0 0-6zM12 2v3M12 19v3M4.9 4.9l2.1 2.1M17 17l2.1 2.1M2 12h3M19 12h3M4.9 19.1L7 17M17 7l2.1-2.1",+ clip: "M9 3h6v4H9zM16 5h2a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2h2",+ mirror: "M4 4h10a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2zM18.5 8h2a1.5 1.5 0 0 1 1.5 1.5v7a1.5 1.5 0 0 1-1.5 1.5h-2A1.5 1.5 0 0 1 17 16.5v-7A1.5 1.5 0 0 1 18.5 8zM6 18h6",+ send: "M22 2L11 13M22 2l-7 20-4-9-9-4z",+ ring: "M6 8a6 6 0 1 1 12 0c0 7 3 8 3 8H3s3-1 3-8M10 20a2 2 0 0 0 4 0",+ mic: "M12 2a3 3 0 0 1 3 3v6a3 3 0 0 1-6 0V5a3 3 0 0 1 3-3zM5 11a7 7 0 0 0 14 0M12 18v4",+ play: "M8 5l11 7-11 7z",+ lock: "M7 11h10a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2v-6a2 2 0 0 1 2-2zM8 11V8a4 4 0 0 1 8 0v3",+ code: "M8 8l-5 4 5 4M16 8l5 4-5 4",+ moon: "M20 14.5A8 8 0 0 1 9.5 4a8 8 0 1 0 10.5 10.5z",+ hex: "M12 2.5l8.2 4.75v9.5L12 21.5l-8.2-4.75v-9.5zM9 12h6",+ back: "M15 6l-6 6 6 6",+ battery: "M4 7h14a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2zM22 11v2"+ })++ Row {+ anchors.fill: parent++ // ---- Navigation rail ----+ Rectangle {+ id: rail+ width: 80+ height: parent.height+ color: window.mica ? "transparent" : Theme.surfaceLow+ Column {+ anchors.horizontalCenter: parent.horizontalCenter+ topPadding: 16+ spacing: 6+ Rectangle {+ width: 38; height: 38; radius: Theme.radiusSm; color: Theme.primary+ anchors.horizontalCenter: parent.horizontalCenter+ Icon { anchors.centerIn: parent; path: window.icons.hex; color: Theme.primaryContent }+ }+ Item { width: 1; height: 8 }+ Repeater {+ model: [["home", "Home"], ["msg", "Messages"], ["bell", "Alerts"], ["photo", "Photos"], ["apps", "Apps"], ["deck", "Deck"]]+ delegate: Column {+ id: navItem+ required property var modelData+ required property int index+ readonly property bool selected: rail.selected === index+ spacing: 4+ anchors.horizontalCenter: parent.horizontalCenter+ Rectangle {+ width: 52; height: 30; radius: 15+ anchors.horizontalCenter: parent.horizontalCenter+ color: navItem.selected ? Theme.secondaryContainer : (navHover.hovered ? Theme.surfaceContainer : "transparent")+ Behavior on color { ColorAnimation { duration: 160 } }+ Icon { anchors.centerIn: parent; path: window.icons[navItem.modelData[0]]; color: navItem.selected ? Theme.secondaryContainerContent : Theme.surfaceContentVariant }+ HoverHandler { id: navHover; cursorShape: Qt.PointingHandCursor }+ TapHandler { onTapped: rail.selected = navItem.index }+ }+ Text {+ anchors.horizontalCenter: parent.horizontalCenter+ text: navItem.modelData[1]; font.family: Theme.font; font.pixelSize: 11; font.weight: Font.DemiBold+ color: navItem.selected ? Theme.surfaceContent : Theme.surfaceContentVariant+ }+ }+ }+ }+ property int selected: 0+ Rectangle { anchors.right: parent.right; width: 1; height: parent.height; color: Theme.outlineVariant }+ }++ // ---- Main ----+ Rectangle {+ width: parent.width - rail.width+ height: parent.height+ color: window.mica ? Qt.rgba(1, 0.97, 0.95, 0.72) : Theme.surface++ Item {+ id: topBar+ width: parent.width; height: 52+ Row {+ anchors { left: parent.left; leftMargin: 22; verticalCenter: parent.verticalCenter }+ spacing: 12+ Text { text: "Home"; font.family: Theme.displayFont; font.pixelSize: 20; font.weight: Font.DemiBold; color: Theme.surfaceContent }+ Row {+ spacing: 8; anchors.verticalCenter: parent.verticalCenter+ Rectangle { width: 7; height: 7; radius: 4; color: Theme.primary; anchors.verticalCenter: parent.verticalCenter }+ Text { text: device.deviceName + " · Wi-Fi · " + device.rttMs + " ms"; font.family: Theme.font; font.pixelSize: 13; color: Theme.surfaceContentVariant }+ }+ }+ Rectangle { anchors.bottom: parent.bottom; width: parent.width; height: 1; color: Theme.outlineVariant }+ }++ Row {+ anchors { top: topBar.bottom; left: parent.left; right: parent.right; bottom: parent.bottom; margins: 20 }+ spacing: 16++ // Left column+ Column {+ id: leftCol+ width: (parent.width - 16) * 0.58+ spacing: 16++ // Hero: the connected phone, with a real-time blurred glow behind it.+ Item {+ width: parent.width; height: 168+ Rectangle {+ id: heroBg+ anchors.fill: parent+ radius: Theme.radiusXl+ color: Theme.hero+ }+ Rectangle {+ id: glow+ x: 30; y: 26; width: 120; height: 120; radius: 60+ color: Theme.primary; opacity: 0.35+ visible: false+ }+ MultiEffect {+ source: glow; anchors.fill: glow+ blurEnabled: true; blur: 1.0; blurMax: 64+ opacity: 0.55+ }+ Row {+ anchors { fill: parent; margins: 18 }+ spacing: 20+ Rectangle {+ width: 76; height: 132; radius: 18+ border.width: 3; border.color: Theme.surfaceContent+ gradient: Gradient {+ GradientStop { position: 0; color: Theme.primary }+ GradientStop { position: 1; color: Qt.darker(Theme.primary, 2.2) }+ }+ Rectangle { width: 20; height: 5; radius: 3; color: Theme.surfaceContent; anchors.horizontalCenter: parent.horizontalCenter; y: 7 }+ }+ Column {+ spacing: 6+ anchors.verticalCenter: parent.verticalCenter+ Text { text: device.deviceName; font.family: Theme.displayFont; font.pixelSize: 30; font.weight: Font.DemiBold; color: Theme.primaryContainerContent }+ Text { text: "Android 16 · paired since Oct 5"; font.family: Theme.font; font.pixelSize: 13; color: Theme.primaryContainerContent; opacity: 0.78 }+ Row {+ spacing: 8; topPadding: 8+ Repeater {+ model: [device.battery + "%" + (device.charging ? " · charging" : ""), "Home Wi-Fi", "3 unread"]+ delegate: Rectangle {+ required property string modelData+ height: 30; width: pill.implicitWidth + 24; radius: 15+ color: Qt.rgba(0.17, 0.09, 0, 0.09)+ Text { id: pill; anchors.centerIn: parent; text: modelData; font.family: Theme.font; font.pixelSize: 13; font.weight: Font.DemiBold; color: Theme.primaryContainerContent }+ }+ }+ }+ }+ }+ Rectangle {+ anchors { top: parent.top; right: parent.right; margins: 16 }+ width: levelText.implicitWidth + 24; height: 28; radius: 14; color: Theme.surface+ Text { id: levelText; anchors.centerIn: parent; text: "Elevated"; font.family: Theme.font; font.pixelSize: 12; font.weight: Font.DemiBold; color: Theme.surfaceContent }+ }+ }++ Row {+ width: parent.width; spacing: 10+ Repeater {+ model: [["Send clipboard", "Last copied: a link", "clip"], ["Mirror screen", "1080p · 60 fps", "mirror"], ["Send files", "Or drop anywhere", "send"], ["Find phone", "Rings on silent", "ring"]]+ delegate: QuickAction {+ required property var modelData+ width: (leftCol.width - 30) / 4+ title: modelData[0]; subtitle: modelData[1]; iconPath: window.icons[modelData[2]]+ }+ }+ }++ Rectangle {+ width: parent.width; height: deckGrid.implicitHeight + 46+ radius: Theme.radiusLg; color: Theme.surfaceContainer+ Text { x: 16; y: 14; text: "Deck"; font.family: Theme.font; font.pixelSize: 13; font.weight: Font.DemiBold; color: Theme.surfaceContentVariant }+ Grid {+ id: deckGrid+ x: 16; y: 38; columns: 6; spacing: 10+ Repeater {+ model: [["Mic", "Muted", "mic", true], ["Play", "Spotify", "play", false], ["Focus", "Off", "moon", false], ["VS Code", "Launch", "code", false], ["Lock PC", "Win + L", "lock", false], ["Clipboard", "History", "clip", false]]+ delegate: DeckKey {+ required property var modelData+ width: (leftCol.width - 32 - 50) / 6; height: width+ label: modelData[0]; detail: modelData[1]; iconPath: window.icons[modelData[2]]; active: modelData[3]+ }+ }+ }+ }+ }++ // Right column: notifications+ Rectangle {+ id: feed+ width: parent.width - leftCol.width - 16+ height: parent.height+ radius: Theme.radiusLg+ color: Theme.surfaceContainer+ clip: true+ Text { x: 16; y: 14; text: "Notifications"; font.family: Theme.font; font.pixelSize: 13; font.weight: Font.DemiBold; color: Theme.surfaceContentVariant }+ ListView {+ id: list+ anchors { fill: parent; topMargin: 40; leftMargin: 6; rightMargin: 6; bottomMargin: 6 }+ model: notifications+ spacing: 2+ clip: true+ add: Transition {+ ParallelAnimation {+ NumberAnimation { property: "opacity"; from: 0; to: 1; duration: 220 }+ SpringAnimation { property: "y"; spring: Theme.springStandard; damping: Theme.dampingStandard }+ }+ }+ addDisplaced: Transition { SpringAnimation { property: "y"; spring: Theme.springStandard; damping: Theme.dampingStandard } }+ delegate: NotificationCard {+ width: ListView.view.width+ onOpened: (source) => detail.openFrom(source, title, app, body)+ }+ }+ }+ }++ StatsPanel {+ id: stats+ model: device+ anchors { right: parent.right; bottom: parent.bottom; margins: 24 }+ z: 5+ }++ // Shared-element transition: the conversation grows out of the tapped card.+ Rectangle {+ id: detail+ property rect from+ property string who+ property string via+ property string message+ property bool open: false+ visible: open || springX.running+ z: 10+ radius: open ? Theme.radiusXl : Theme.radiusMd+ color: Theme.surface+ border.color: Theme.outlineVariant+ layer.enabled: true+ layer.effect: MultiEffect { shadowEnabled: true; shadowBlur: 0.7; shadowOpacity: 0.18; shadowVerticalOffset: 10 }++ function openFrom(source, title, app, body) {+ const p = source.mapToItem(detail.parent, 0, 0)+ from = Qt.rect(p.x, p.y, source.width, source.height)+ x = from.x; y = from.y; width = from.width; height = from.height+ who = title; via = app; message = body+ open = true+ }+ function close() { open = false }++ states: State {+ when: detail.open+ PropertyChanges { detail.x: feed.x + 20 - 40; detail.y: topBar.height + 20; detail.width: feed.width + 40; detail.height: feed.height }+ }+ transitions: Transition {+ SpringAnimation { id: springX; properties: "x,y,width,height"; spring: Theme.springGentle; damping: 0.32; epsilon: 0.25 }+ }+ Behavior on radius { NumberAnimation { duration: 220 } }++ Column {+ anchors { fill: parent; margins: 20 }+ spacing: 14+ opacity: detail.open ? 1 : 0+ Behavior on opacity { NumberAnimation { duration: 180 } }+ Row {+ spacing: 12+ Rectangle {+ width: 36; height: 36; radius: 18; color: Theme.secondaryContainer+ Icon { anchors.centerIn: parent; path: window.icons.back; color: Theme.secondaryContainerContent }+ TapHandler { onTapped: detail.close() }+ }+ Column {+ Text { text: detail.who; font.family: Theme.displayFont; font.pixelSize: 18; font.weight: Font.DemiBold; color: Theme.surfaceContent }+ Text { text: detail.via + " · via " + device.deviceName; font.family: Theme.font; font.pixelSize: 12; color: Theme.surfaceContentVariant }+ }+ }+ Rectangle {+ width: Math.min(bubble.implicitWidth + 28, parent.width * 0.8); height: bubble.implicitHeight + 20+ radius: 18; color: Theme.surfaceContainerHigh+ Text { id: bubble; anchors.centerIn: parent; width: parent.width - 28; wrapMode: Text.Wrap; text: detail.message; font.family: Theme.font; font.pixelSize: 14; color: Theme.surfaceContent }+ }+ }+ Rectangle {+ anchors { left: parent.left; right: parent.right; bottom: parent.bottom; margins: 20 }+ height: 46; radius: 23; color: Theme.surfaceContainerHigh+ opacity: detail.open ? 1 : 0+ Behavior on opacity { NumberAnimation { duration: 180 } }+ Text { x: 18; anchors.verticalCenter: parent.verticalCenter; text: "Reply to " + detail.who + "…"; font.family: Theme.font; font.pixelSize: 13; color: Theme.surfaceContentVariant }+ Rectangle {+ width: 38; height: 38; radius: 19; color: Theme.primary+ anchors { right: parent.right; rightMargin: 4; verticalCenter: parent.verticalCenter }+ Icon { anchors.centerIn: parent; path: window.icons.send; color: Theme.primaryContent; width: 18; height: 18 }+ }+ }+ }+ }+ }+}diff --git a/spikes/s1-qt-rust/qml/NotificationCard.qml b/spikes/s1-qt-rust/qml/NotificationCard.qmlnew file mode 100644index 0000000..9186fdc--- /dev/null+++ b/spikes/s1-qt-rust/qml/NotificationCard.qml@@ -0,0 +1,57 @@+import QtQuick++Item {+ id: card+ required property string app+ required property string title+ required property string body+ required property string time+ readonly property bool isCode: body.indexOf("code") >= 0+ signal opened(Item source)++ implicitHeight: content.implicitHeight + 22++ Rectangle {+ anchors.fill: parent+ radius: Theme.radiusMd+ color: hover.hovered ? Theme.surfaceContainerHigh : "transparent"+ Behavior on color { ColorAnimation { duration: 140 } }+ }++ Row {+ id: content+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: 11 }+ spacing: 12+ Rectangle {+ width: 34; height: 34; radius: 17+ color: Theme.surfaceContainerHighest+ Text { anchors.centerIn: parent; text: card.app.charAt(0); font.family: Theme.font; font.pixelSize: 13; font.weight: Font.Bold; color: Theme.surfaceContentVariant }+ }+ Column {+ width: parent.width - 46+ spacing: 2+ Row {+ spacing: 8+ Text { text: card.title; font.family: Theme.font; font.pixelSize: 13; font.weight: Font.DemiBold; color: Theme.surfaceContent }+ Text { text: card.app + " · " + card.time; font.family: Theme.font; font.pixelSize: 12; color: Theme.surfaceContentVariant; anchors.baseline: parent.children[0].baseline }+ }+ Text { width: parent.width; text: card.body; elide: Text.ElideRight; font.family: Theme.font; font.pixelSize: 13; color: Theme.surfaceContentVariant }+ Rectangle {+ visible: card.isCode+ height: visible ? 32 : 0; width: codeRow.width + 18+ radius: 16; color: Theme.primaryContainer+ Row {+ id: codeRow+ anchors.centerIn: parent; spacing: 10+ Text { text: "482 913"; font.family: "Cascadia Mono"; font.pixelSize: 13; font.weight: Font.Bold; font.letterSpacing: 1.5; color: Theme.primaryContainerContent; anchors.verticalCenter: parent.verticalCenter }+ Rectangle {+ width: 52; height: 24; radius: 12; color: Theme.primary+ Text { anchors.centerIn: parent; text: "Copy"; font.family: Theme.font; font.pixelSize: 12; font.weight: Font.DemiBold; color: Theme.primaryContent }+ }+ }+ }+ }+ }+ HoverHandler { id: hover; cursorShape: Qt.PointingHandCursor }+ TapHandler { onTapped: card.opened(card) }+}diff --git a/spikes/s1-qt-rust/qml/QuickAction.qml b/spikes/s1-qt-rust/qml/QuickAction.qmlnew file mode 100644index 0000000..1779aad--- /dev/null+++ b/spikes/s1-qt-rust/qml/QuickAction.qml@@ -0,0 +1,36 @@+import QtQuick++Rectangle {+ id: action+ property string title+ property string subtitle+ property string iconPath+ signal clicked++ radius: Theme.radiusLg+ color: hover.hovered ? Qt.darker(Theme.surfaceContainerHigh, 1.03) : Theme.surfaceContainerHigh+ implicitHeight: 104+ scale: tap.pressed ? 0.97 : 1.0+ transform: Translate { y: hover.hovered && !tap.pressed ? -2 : 0; Behavior on y { SpringAnimation { spring: 6; damping: 0.4 } } }++ Behavior on scale { SpringAnimation { spring: 6.2; damping: 0.34 } }+ Behavior on color { ColorAnimation { duration: 160 } }++ Column {+ anchors.fill: parent+ anchors.margins: 14+ spacing: 12+ Rectangle {+ width: 36; height: 36; radius: Theme.radiusMd+ color: Theme.secondaryContainer+ Icon { anchors.centerIn: parent; path: action.iconPath; color: Theme.secondaryContainerContent }+ }+ Column {+ spacing: 2+ Text { text: action.title; font.family: Theme.font; font.pixelSize: 13; font.weight: Font.DemiBold; color: Theme.surfaceContent }+ Text { text: action.subtitle; font.family: Theme.font; font.pixelSize: 12; color: Theme.surfaceContentVariant }+ }+ }+ HoverHandler { id: hover; cursorShape: Qt.PointingHandCursor }+ TapHandler { id: tap; onTapped: action.clicked() }+}diff --git a/spikes/s1-qt-rust/qml/StatsPanel.qml b/spikes/s1-qt-rust/qml/StatsPanel.qmlnew file mode 100644index 0000000..be6c4d0--- /dev/null+++ b/spikes/s1-qt-rust/qml/StatsPanel.qml@@ -0,0 +1,67 @@+import QtQuick+import app.nectarlink.spike++// Live measurements for the S1 gate: frame rate, events per second,+// memory and startup time.+Rectangle {+ id: panel+ required property DeviceModel model+ property real fps: 0+ property bool measuring: false++ width: 262+ height: column.implicitHeight + 24+ radius: Theme.radiusLg+ color: Qt.rgba(0.12, 0.10, 0.08, 0.86)++ FrameAnimation {+ running: panel.measuring+ onTriggered: panel.fps = smoothFrameTime > 0 ? 1.0 / smoothFrameTime : 0+ }+ Timer { interval: 1000; running: true; repeat: true; onTriggered: panel.model.refreshMemory() }++ Column {+ id: column+ anchors { left: parent.left; right: parent.right; top: parent.top; margins: 12 }+ spacing: 6+ Text { text: "S1 · LIVE MEASUREMENTS"; color: "#FFDDB8"; font.family: "Cascadia Mono"; font.pixelSize: 10; font.letterSpacing: 1 }+ Repeater {+ model: [+ ["Frame rate", panel.measuring ? panel.fps.toFixed(0) + " fps" : "idle (no redraws)"],+ ["Core events", panel.model.eventsPerSecond + " / s"],+ ["Events handled", Math.round(panel.model.eventsTotal).toLocaleString(Qt.locale(), "f", 0)],+ ["Memory", panel.model.workingSetMb.toFixed(1) + " MB"],+ ["First frame", panel.model.startupMs > 0 ? panel.model.startupMs.toFixed(0) + " ms" : "…"]+ ]+ delegate: Row {+ required property var modelData+ width: column.width+ Text { width: 116; text: modelData[0]; color: "#C9B9A8"; font.family: "Segoe UI Variable Text"; font.pixelSize: 12 }+ Text { text: modelData[1]; color: "white"; font.family: "Cascadia Mono"; font.pixelSize: 12; font.weight: Font.DemiBold }+ }+ }+ Row {+ spacing: 6+ topPadding: 4+ Repeater {+ model: [["1k/s", 1000], ["10k/s", 10000], ["Stop", 0]]+ delegate: Rectangle {+ required property var modelData+ width: 64; height: 26; radius: 13+ color: tap.pressed ? "#5c4630" : "#3d2f22"+ Text { anchors.centerIn: parent; text: modelData[0]; color: "white"; font.family: "Segoe UI Variable Text"; font.pixelSize: 12; font.weight: Font.DemiBold }+ TapHandler {+ id: tap+ onTapped: modelData[1] > 0 ? panel.model.startStress(modelData[1]) : panel.model.stopStress()+ }+ }+ }+ }+ Rectangle {+ width: 200; height: 26; radius: 13+ color: panel.measuring ? "#8A5100" : "#3d2f22"+ Text { anchors.centerIn: parent; text: panel.measuring ? "Measuring frame rate" : "Measure frame rate"; color: "white"; font.family: "Segoe UI Variable Text"; font.pixelSize: 12; font.weight: Font.DemiBold }+ TapHandler { onTapped: panel.measuring = !panel.measuring }+ }+ }+}diff --git a/spikes/s1-qt-rust/qml/Theme.qml b/spikes/s1-qt-rust/qml/Theme.qmlnew file mode 100644index 0000000..7de1cfb--- /dev/null+++ b/spikes/s1-qt-rust/qml/Theme.qml@@ -0,0 +1,36 @@+pragma Singleton+import QtQuick++// Bloom Light, Honey seed (docs/design/tokens.json). The real app generates+// this from the tokens file and swaps palettes for dark mode and other seeds.+QtObject {+ readonly property color primary: "#8A5100"+ readonly property color primaryContent: "#FFFFFF"+ readonly property color primaryContainer: "#FFDDB8"+ readonly property color primaryContainerContent: "#2C1600"+ readonly property color secondaryContainer: "#F3E0CB"+ readonly property color secondaryContainerContent: "#261A0C"+ readonly property color surface: "#FFF8F3"+ readonly property color surfaceLow: "#FBF2EB"+ readonly property color surfaceContainer: "#F5ECE4"+ readonly property color surfaceContainerHigh: "#EFE6DE"+ readonly property color surfaceContainerHighest: "#E9E1D9"+ readonly property color surfaceContent: "#1F1B16"+ readonly property color surfaceContentVariant: "#51453A"+ readonly property color outline: "#837468"+ readonly property color outlineVariant: "#D5C3B5"+ readonly property color hero: Qt.tint(surface, Qt.rgba(1.0, 0.867, 0.722, 0.62))++ readonly property int radiusXl: 28+ readonly property int radiusLg: 20+ readonly property int radiusMd: 16+ readonly property int radiusSm: 12++ readonly property string font: "Segoe UI Variable Text"+ readonly property string displayFont: "Segoe UI Variable Display"++ // Motion: springs from tokens.json (gentle / standard / snappy).+ readonly property real springGentle: 2.2+ readonly property real springStandard: 3.8+ readonly property real dampingStandard: 0.3+}diff --git a/spikes/s1-qt-rust/src/bridge.rs b/spikes/s1-qt-rust/src/bridge.rsnew file mode 100644index 0000000..0124d72--- /dev/null+++ b/spikes/s1-qt-rust/src/bridge.rs@@ -0,0 +1,275 @@+// SPDX-License-Identifier: GPL-3.0-or-later+//! The Rust side of the proof: a QObject that QML binds to, fed from a+//! background thread the way `nectarlink-core` events will be. All updates+//! cross into Qt through `qt_thread().queue(...)`, the single pattern the+//! real `nectarlink-qt` bridge will use.++use std::{+ pin::Pin,+ sync::{+ Arc, Mutex,+ atomic::{AtomicBool, Ordering},+ },+ thread,+ time::{Duration, Instant},+};++use cxx_qt::{CxxQtThread, CxxQtType, Threading};+use cxx_qt_lib::QString;++#[cxx_qt::bridge]+pub mod qobject {+ unsafe extern "C++" {+ include!("cxx-qt-lib/qstring.h");+ type QString = cxx_qt_lib::QString;+ }++ // Expose snake_case Rust names to QML as camelCase (deviceName, startStress...).+ #[auto_cxx_name]+ extern "RustQt" {+ #[qobject]+ #[qml_element]+ #[qproperty(QString, device_name)]+ #[qproperty(i32, battery)]+ #[qproperty(bool, charging)]+ #[qproperty(i32, rtt_ms)]+ #[qproperty(i32, events_per_second)]+ #[qproperty(f64, events_total)]+ #[qproperty(f64, working_set_mb)]+ #[qproperty(f64, startup_ms)]+ #[qproperty(bool, stress_running)]+ type DeviceModel = super::DeviceModelRust;++ /// Starts simulated core events at `rate` per second.+ #[qinvokable]+ fn start_stress(self: Pin<&mut DeviceModel>, rate: i32);++ #[qinvokable]+ fn stop_stress(self: Pin<&mut DeviceModel>);++ /// Called by QML when the first frame is on screen.+ #[qinvokable]+ fn first_frame(self: Pin<&mut DeviceModel>);++ #[qinvokable]+ fn refresh_memory(self: Pin<&mut DeviceModel>);++ /// A phone notification arrived.+ #[qsignal]+ fn notification(self: Pin<&mut DeviceModel>, app: QString, title: QString, body: QString);+ }++ impl cxx_qt::Threading for DeviceModel {}+}++/// Process start, set in `main` before Qt starts.+pub static STARTED: std::sync::OnceLock<Instant> = std::sync::OnceLock::new();++pub struct DeviceModelRust {+ device_name: QString,+ battery: i32,+ charging: bool,+ rtt_ms: i32,+ events_per_second: i32,+ events_total: f64,+ working_set_mb: f64,+ startup_ms: f64,+ stress_running: bool,+ stop: Option<Arc<AtomicBool>>,+}++impl Default for DeviceModelRust {+ fn default() -> Self {+ Self {+ device_name: QString::from("Pixel 9"),+ battery: 82,+ charging: true,+ rtt_ms: 12,+ events_per_second: 0,+ events_total: 0.0,+ working_set_mb: 0.0,+ startup_ms: 0.0,+ stress_running: false,+ stop: None,+ }+ }+}++const SAMPLE_NOTIFICATIONS: &[(&str, &str, &str)] = &[+ ("WhatsApp", "Mom", "Dinner at 8? Bring the charger you borrowed."),+ ("Google", "Sign-in code", "Your verification code is 482 913"),+ ("Swiggy", "On the way", "Your order arrives in 12 minutes"),+ ("Calendar", "Design review", "With Aanya at 4:30 PM"),+ ("Discord", "#general", "6 new messages"),+ ("Gmail", "Rahul", "Pushed the fix, can you check?"),+];++/// State waiting to be applied on the Qt thread.+#[derive(Default)]+struct PendingUi {+ battery: i32,+ rtt_ms: i32,+ events_total: u64,+ events_per_second: i32,+ /// Events that must not be merged are batched, bounded.+ notifications: Vec<(&'static str, &'static str, &'static str)>,+}++/// Coalesces updates from background threads into at most one queued+/// closure at a time, so a flood of events can never pile up work (or+/// memory) on the Qt thread. The UI always applies the latest state.+struct UiPump {+ qt: CxxQtThread<qobject::DeviceModel>,+ pending: Arc<Mutex<PendingUi>>,+ scheduled: Arc<AtomicBool>,+}++/// Keep at most this many unseen notifications; older ones are dropped+/// from the live view (the app's history keeps them all).+const MAX_PENDING_NOTIFICATIONS: usize = 50;++impl UiPump {+ fn new(qt: CxxQtThread<qobject::DeviceModel>) -> Self {+ Self { qt, pending: Arc::default(), scheduled: Arc::default() }+ }++ /// Applies `f` to the pending state and schedules a flush if none is+ /// queued. Returns false once the QObject has been destroyed.+ fn update(&self, f: impl FnOnce(&mut PendingUi)) -> bool {+ {+ let mut pending = self.pending.lock().unwrap_or_else(|e| e.into_inner());+ f(&mut pending);+ let excess = pending.notifications.len().saturating_sub(MAX_PENDING_NOTIFICATIONS);+ pending.notifications.drain(..excess);+ }+ if self.scheduled.swap(true, Ordering::AcqRel) {+ return true; // a flush is already queued and will see this update+ }+ let pending = self.pending.clone();+ let scheduled = self.scheduled.clone();+ self.qt+ .queue(move |mut model| {+ // Clear first so updates arriving during the flush schedule another.+ scheduled.store(false, Ordering::Release);+ // Scalars are the latest values; only the notification batch is drained.+ let (battery, rtt_ms, events_total, events_per_second, notifications) = {+ let mut state = pending.lock().unwrap_or_else(|e| e.into_inner());+ let batch = std::mem::take(&mut state.notifications);+ (state.battery, state.rtt_ms, state.events_total, state.events_per_second, batch)+ };+ model.as_mut().set_battery(battery);+ model.as_mut().set_rtt_ms(rtt_ms);+ model.as_mut().set_events_total(events_total as f64);+ model.as_mut().set_events_per_second(events_per_second);+ for (app, title, body) in notifications {+ model.as_mut().notification(+ QString::from(app),+ QString::from(title),+ QString::from(body),+ );+ }+ })+ .is_ok()+ }+}++impl qobject::DeviceModel {+ pub fn start_stress(mut self: Pin<&mut Self>, rate: i32) {+ self.as_mut().stop_stress();+ let rate = rate.clamp(1, 100_000) as u64;+ let stop = Arc::new(AtomicBool::new(false));+ self.as_mut().rust_mut().stop = Some(stop.clone());+ self.as_mut().set_stress_running(true);++ let pump = UiPump::new(self.qt_thread());+ thread::spawn(move || {+ let interval = Duration::from_nanos(1_000_000_000 / rate);+ let mut next = Instant::now();+ let mut window_start = Instant::now();+ let mut sent: u64 = 0;+ let mut window_sent: u64 = 0;+ while !stop.load(Ordering::Relaxed) {+ sent += 1;+ window_sent += 1;+ let n = sent;+ let per_second = if window_start.elapsed() >= Duration::from_secs(1) {+ let eps = window_sent as i32;+ window_sent = 0;+ window_start = Instant::now();+ Some(eps)+ } else {+ None+ };+ let alive = pump.update(|state| {+ state.battery = ((n / 50) % 100) as i32;+ state.rtt_ms = 8 + (n % 9) as i32;+ state.events_total = n;+ if let Some(eps) = per_second {+ state.events_per_second = eps;+ }+ if n % 2_500 == 0 {+ let (app, title, body) =+ SAMPLE_NOTIFICATIONS[(n as usize / 2_500) % SAMPLE_NOTIFICATIONS.len()];+ state.notifications.push((app, title, body));+ }+ });+ if !alive {+ return; // the QObject is gone+ }+ next += interval;+ let now = Instant::now();+ if next > now {+ thread::sleep(next - now);+ } else if now - next > Duration::from_millis(250) {+ next = now; // fell behind; don't burst to catch up+ }+ }+ pump.update(|state| state.events_per_second = 0);+ });+ }++ pub fn stop_stress(mut self: Pin<&mut Self>) {+ if let Some(stop) = self.as_mut().rust_mut().stop.take() {+ stop.store(true, Ordering::Relaxed);+ }+ self.set_stress_running(false);+ }++ pub fn first_frame(mut self: Pin<&mut Self>) {+ if self.startup_ms > 0.0 {+ return;+ }+ if let Some(started) = STARTED.get() {+ let ms = started.elapsed().as_secs_f64() * 1000.0;+ println!("first frame after {ms:.0} ms");+ self.as_mut().set_startup_ms(ms);+ }+ self.refresh_memory();+ }++ pub fn refresh_memory(self: Pin<&mut Self>) {+ let mb = working_set_mb();+ self.set_working_set_mb(mb);+ }+}++#[cfg(windows)]+#[allow(unsafe_code)]+fn working_set_mb() -> f64 {+ use windows::Win32::System::{+ ProcessStatus::{GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS},+ Threading::GetCurrentProcess,+ };+ let mut counters = PROCESS_MEMORY_COUNTERS {+ cb: std::mem::size_of::<PROCESS_MEMORY_COUNTERS>() as u32,+ ..Default::default()+ };+ // SAFETY: valid pseudo-handle and a correctly sized, writable struct.+ let ok = unsafe { GetProcessMemoryInfo(GetCurrentProcess(), &mut counters, counters.cb) };+ if ok.is_ok() { counters.WorkingSetSize as f64 / (1024.0 * 1024.0) } else { 0.0 }+}++#[cfg(not(windows))]+fn working_set_mb() -> f64 {+ 0.0+}diff --git a/spikes/s1-qt-rust/src/main.rs b/spikes/s1-qt-rust/src/main.rsnew file mode 100644index 0000000..a27206f--- /dev/null+++ b/spikes/s1-qt-rust/src/main.rs@@ -0,0 +1,32 @@+// SPDX-License-Identifier: GPL-3.0-or-later+//! Spike S1: can Qt Quick + Rust deliver the Nectarlink design within the+//! performance budgets? See README.md for what is measured and the results.++mod bridge;+mod mica;+mod native;++use cxx_qt_lib::{QGuiApplication, QQmlApplicationEngine, QString, QUrl};++fn main() {+ let _ = bridge::STARTED.set(std::time::Instant::now());++ let mica = std::env::args().any(|a| a == "--mica");+ if mica {+ native::ffi::enable_window_alpha();+ }+ let mut app = QGuiApplication::new();+ let mut engine = QQmlApplicationEngine::new();+ if let Some(app) = app.as_mut() {+ app.set_application_name(&QString::from("Nectarlink S1"));+ }+ if let Some(engine) = engine.as_mut() {+ engine.load(&QUrl::from("qrc:/qt/qml/app/nectarlink/spike/qml/Main.qml"));+ }+ if mica {+ mica::apply_to_process_windows();+ }+ if let Some(app) = app.as_mut() {+ std::process::exit(app.exec());+ }+}diff --git a/spikes/s1-qt-rust/src/mica.rs b/spikes/s1-qt-rust/src/mica.rsnew file mode 100644index 0000000..999ad43--- /dev/null+++ b/spikes/s1-qt-rust/src/mica.rs@@ -0,0 +1,47 @@+// SPDX-License-Identifier: GPL-3.0-or-later+//! Applies the Windows 11 Mica backdrop to this thread's top-level windows.+//! The QML root must have a transparent background for Mica to show.++#[cfg(windows)]+#[allow(unsafe_code)]+pub fn apply_to_process_windows() {+ use windows::{+ Win32::{+ Foundation::{HWND, LPARAM},+ Graphics::Dwm::{+ DWM_SYSTEMBACKDROP_TYPE, DWMSBT_MAINWINDOW, DWMWA_SYSTEMBACKDROP_TYPE,+ DwmExtendFrameIntoClientArea, DwmSetWindowAttribute,+ },+ System::Threading::GetCurrentThreadId,+ UI::{Controls::MARGINS, WindowsAndMessaging::EnumThreadWindows},+ },+ core::BOOL,+ };++ unsafe extern "system" fn apply(hwnd: HWND, _: LPARAM) -> BOOL {+ let backdrop: DWM_SYSTEMBACKDROP_TYPE = DWMSBT_MAINWINDOW;+ let margins = MARGINS { cxLeftWidth: -1, cxRightWidth: -1, cyTopHeight: -1, cyBottomHeight: -1 };+ // SAFETY: hwnd comes from EnumThreadWindows; the attribute buffer is a+ // live DWM_SYSTEMBACKDROP_TYPE of the size passed.+ unsafe {+ let extend = DwmExtendFrameIntoClientArea(hwnd, &margins);+ let set = DwmSetWindowAttribute(+ hwnd,+ DWMWA_SYSTEMBACKDROP_TYPE,+ std::ptr::from_ref(&backdrop).cast(),+ std::mem::size_of::<DWM_SYSTEMBACKDROP_TYPE>() as u32,+ );+ let visible = windows::Win32::UI::WindowsAndMessaging::IsWindowVisible(hwnd).as_bool();+ eprintln!("mica: hwnd={hwnd:?} visible={visible} extend={extend:?} backdrop={set:?}");+ }+ BOOL(1)+ }++ // SAFETY: the callback only calls DWM functions on the enumerated handles.+ unsafe {+ let _ = EnumThreadWindows(GetCurrentThreadId(), Some(apply), LPARAM(0));+ }+}++#[cfg(not(windows))]+pub fn apply_to_process_windows() {}diff --git a/spikes/s1-qt-rust/src/native.rs b/spikes/s1-qt-rust/src/native.rsnew file mode 100644index 0000000..2b577d4--- /dev/null+++ b/spikes/s1-qt-rust/src/native.rs@@ -0,0 +1,12 @@+// SPDX-License-Identifier: GPL-3.0-or-later+//! Small C++ helpers for Qt APIs that cxx-qt-lib doesn't wrap.++#[cxx::bridge]+pub mod ffi {+ unsafe extern "C++" {+ include!("window_helpers.h");++ /// Must be called before any QQuickWindow is created.+ fn enable_window_alpha();+ }+}