Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
Make Mica work in the S1 spike
Bee22ba45196148
diff --git a/spikes/s1-qt-rust/README.md b/spikes/s1-qt-rust/README.mdindex a62bbbd..c07f838 100644--- a/spikes/s1-qt-rust/README.md+++ b/spikes/s1-qt-rust/README.md@@ -14,7 +14,7 @@ Run (needs Qt 6.12 on PATH and `QMAKE` set):| 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 |+| Mica | works | Works on D3D11 with no cost: 144 fps under load, same memory (see lesson 7) | ✅ || 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 |@@ -31,8 +31,21 @@ Run (needs Qt 6.12 on PATH and `QMAKE` set):`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.+7. **Mica on Qt Quick** needs four things: `QQuickWindow::setDefaultAlphaBuffer(true)`+ and `QT_QPA_DISABLE_REDIRECTION_SURFACE=1` before the app starts (without+ it D3D swap chains don't use DirectComposition and transparent pixels are+ white), a transparent root `Window`, then `DwmExtendFrameIntoClientArea`+ + `DWMWA_SYSTEMBACKDROP_TYPE`. OpenGL also works but costs ~100 MB more;+ stay on D3D11.+8. **Pin `Qt.styleHints.colorScheme` to the app theme.** Qt otherwise follows+ the system, so a light theme on a dark-mode PC gets a dark frame and dark+ Mica tint.+9. **Drop the engine and app before `process::exit`**, or Qt's render and+ vsync threads are torn down mid-flight and log warnings at exit.## 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.+The zero-copy video item, ARM64 and tray-mode memory remain to verify. The+real app also needs a custom title bar so Mica runs edge to edge (the system+caption is drawn in the accent color here).diff --git a/spikes/s1-qt-rust/cpp/window_helpers.cpp b/spikes/s1-qt-rust/cpp/window_helpers.cppindex 0591059..6fc89ea 100644--- a/spikes/s1-qt-rust/cpp/window_helpers.cpp+++ b/spikes/s1-qt-rust/cpp/window_helpers.cpp@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-3.0-or-later#include "window_helpers.h"+#include <QtCore/QtEnvironmentVariables>#include <QtQuick/QQuickWindow>void enable_window_alpha()@@ -8,4 +9,8 @@ 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);+ // Qt's D3D11/D3D12 swap chains only blend with what is behind the window+ // when presented through DirectComposition, which Qt uses when the window+ // has no redirection surface. Without this, transparent pixels are white.+ qputenv("QT_QPA_DISABLE_REDIRECTION_SURFACE", "1");}diff --git a/spikes/s1-qt-rust/cpp/window_helpers.h b/spikes/s1-qt-rust/cpp/window_helpers.hindex c2df720..e09a1a4 100644--- a/spikes/s1-qt-rust/cpp/window_helpers.h+++ b/spikes/s1-qt-rust/cpp/window_helpers.h@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-3.0-or-later#pragma once-// Must be called before any QQuickWindow is created.+// Prepares Qt Quick windows for a DWM system backdrop (Mica). Must be called+// before QGuiApplication and any QQuickWindow are created.void enable_window_alpha();diff --git a/spikes/s1-qt-rust/qml/Main.qml b/spikes/s1-qt-rust/qml/Main.qmlindex 68e02b8..10f18a1 100644--- a/spikes/s1-qt-rust/qml/Main.qml+++ b/spikes/s1-qt-rust/qml/Main.qml@@ -13,6 +13,9 @@ Window {title: "Nectarlink · S1 proof"color: mica ? "transparent" : Theme.surface+ // The frame and the Mica tint follow the app theme, not the system one.+ Component.onCompleted: Qt.styleHints.colorScheme = Theme.dark ? Qt.ColorScheme.Dark : Qt.ColorScheme.Light+DeviceModel {id: deviceonNotification: (app, title, body) => {diff --git a/spikes/s1-qt-rust/qml/Theme.qml b/spikes/s1-qt-rust/qml/Theme.qmlindex 7de1cfb..1280e75 100644--- a/spikes/s1-qt-rust/qml/Theme.qml+++ b/spikes/s1-qt-rust/qml/Theme.qml@@ -4,6 +4,8 @@ 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 bool dark: false+readonly property color primary: "#8A5100"readonly property color primaryContent: "#FFFFFF"readonly property color primaryContainer: "#FFDDB8"diff --git a/spikes/s1-qt-rust/src/bridge.rs b/spikes/s1-qt-rust/src/bridge.rsindex 0124d72..eadfee1 100644--- a/spikes/s1-qt-rust/src/bridge.rs+++ b/spikes/s1-qt-rust/src/bridge.rs@@ -207,7 +207,7 @@ impl qobject::DeviceModel {if let Some(eps) = per_second {state.events_per_second = eps;}- if n % 2_500 == 0 {+ if n.is_multiple_of(2_500) {let (app, title, body) =SAMPLE_NOTIFICATIONS[(n as usize / 2_500) % SAMPLE_NOTIFICATIONS.len()];state.notifications.push((app, title, body));diff --git a/spikes/s1-qt-rust/src/main.rs b/spikes/s1-qt-rust/src/main.rsindex a27206f..a3eb4a7 100644--- a/spikes/s1-qt-rust/src/main.rs+++ b/spikes/s1-qt-rust/src/main.rs@@ -26,7 +26,10 @@ fn main() {if mica {mica::apply_to_process_windows();}- if let Some(app) = app.as_mut() {- std::process::exit(app.exec());- }+ let code = app.as_mut().map_or(1, |app| app.exec());+ // Tear down in order (QML before the application) so Qt's render and+ // vsync threads stop cleanly; `process::exit` would skip destructors.+ drop(engine);+ drop(app);+ std::process::exit(code);}diff --git a/spikes/s1-qt-rust/src/mica.rs b/spikes/s1-qt-rust/src/mica.rsindex 999ad43..cea63bc 100644--- a/spikes/s1-qt-rust/src/mica.rs+++ b/spikes/s1-qt-rust/src/mica.rs@@ -1,6 +1,8 @@// 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.+//! Requires `native::ffi::enable_window_alpha()` before Qt starts and a+//! transparent QML root. Mica's light or dark tint follows the window's+//! color scheme, which QML sets to match the app theme.#[cfg(windows)]#[allow(unsafe_code)]@@ -24,15 +26,14 @@ pub fn apply_to_process_windows() {// 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(+ // Best effort: on failure the window keeps its opaque frame.+ let _ = DwmExtendFrameIntoClientArea(hwnd, &margins);+ let _ = 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)}diff --git a/spikes/s1-qt-rust/src/native.rs b/spikes/s1-qt-rust/src/native.rsindex 2b577d4..b911b41 100644--- a/spikes/s1-qt-rust/src/native.rs+++ b/spikes/s1-qt-rust/src/native.rs@@ -6,7 +6,8 @@ pub mod ffi {unsafe extern "C++" {include!("window_helpers.h");- /// Must be called before any QQuickWindow is created.+ /// Prepares windows for a DWM backdrop. Must be called before+ /// QGuiApplication and any QQuickWindow are created.fn enable_window_alpha();}}