Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

window: windows follows the preferred appearance

RoversXeb8f73351bc8
diff --git a/window/src/os/windows/connection.rs b/window/src/os/windows/connection.rs
index bc5954b2..16f3b8db 100644
--- a/window/src/os/windows/connection.rs
+++ b/window/src/os/windows/connection.rs
@@ -38,7 +38,10 @@ pub struct Connection {
pub(crate) gl_connection: RefCell<Option<Rc<crate::egl::GlConnection>>>,
}
-pub(crate) fn get_appearance() -> Appearance {
+/// What the system is set to, ignoring any appearance the application was
+/// asked to present. Use [`get_appearance`] unless you specifically want to
+/// know what Windows itself says.
+pub(crate) fn system_appearance() -> Appearance {
let hkcu = RegKey::predef(HKEY_CURRENT_USER);
match hkcu.open_subkey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize") {
Ok(theme) => {
@@ -53,6 +56,13 @@ pub(crate) fn get_appearance() -> Appearance {
}
}
+/// The appearance the application presents: whatever it was asked to present,
+/// else whatever the system is set to. The override short-circuits the
+/// registry read, so a window that is already themed costs nothing to re-check.
+pub(crate) fn get_appearance() -> Appearance {
+ crate::connection::preferred_appearance().unwrap_or_else(system_appearance)
+}
+
/// The monitor the user is working on: the one holding our focused window,
/// falling back to the primary when none of ours has focus.
///
@@ -76,6 +86,10 @@ impl ConnectionOps for Connection {
get_appearance()
}
+ fn reapply_appearance(&self) {
+ super::window::reapply_appearance_to_all_windows();
+ }
+
fn name(&self) -> String {
"Windows".to_string()
}
diff --git a/window/src/os/windows/window.rs b/window/src/os/windows/window.rs
index 3b7e853d..70676b37 100644
--- a/window/src/os/windows/window.rs
+++ b/window/src/os/windows/window.rs
@@ -552,6 +552,25 @@ fn schedule_apply_decoration(hwnd: HWND, decorations: WindowDecorations) {
.detach();
}
+/// Re-theme every window, after the application was asked to present a
+/// different appearance. `apply_theme` reads that appearance for itself, and
+/// its own comparison against the window's last-seen value decides whether an
+/// `AppearanceChanged` is worth dispatching.
+///
+/// The handles are collected before any of them is themed: `apply_theme`
+/// borrows each window's inner state and dispatches from inside that borrow,
+/// which it cannot do while the window map is also borrowed here.
+pub(crate) fn reapply_appearance_to_all_windows() {
+ let conn = match Connection::get() {
+ Some(conn) => conn,
+ None => return,
+ };
+ let hwnds: Vec<HWND> = conn.windows.borrow().keys().map(|window| window.0).collect();
+ for hwnd in hwnds {
+ apply_theme(hwnd);
+ }
+}
+
fn apply_decoration_immediate(hwnd: HWND, decorations: WindowDecorations) {
match rc_from_hwnd(hwnd) {
Some(inner) => {