From a76764231e84de4f953f757f1971c12c42ae35e9 Mon Sep 17 00:00:00 2001 From: rgxdev Date: Wed, 25 Nov 2026 00:35:40 +0100 Subject: [PATCH 1/4] feat(themes): add Liquid Glass themes that blur the desktop behind the window on macOS Two built-in themes on Tarn's blue palette with a translucent backdrop and sidebar. On macOS the browser and settings windows turn blurred-translucent while one of them is active; every other theme, and any theme not compiled in, keeps an opaque window. Theme text is now also checked over the backdrop's second gradient stop and the black an opaque window clears to, and the built-in glass themes are tested over a white and a black desktop. Signed-off-by: rgxdev --- CHANGELOG.md | 3 ++ crates/app/src/settings.rs | 5 ++- crates/app/src/shared.rs | 6 ++-- crates/app/src/themes.rs | 29 ++++++++++++++-- crates/browser-core/src/theme.rs | 40 ++++++++++++++++++---- crates/browser-core/themes/glass-light.css | 35 +++++++++++++++++++ crates/browser-core/themes/glass.css | 35 +++++++++++++++++++ docs/port-backlog.md | 15 ++++++++ docs/themes.md | 3 ++ 9 files changed, 154 insertions(+), 17 deletions(-) create mode 100644 crates/browser-core/themes/glass-light.css create mode 100644 crates/browser-core/themes/glass.css diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c7a48d8..0ff53876 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ All notable changes to Tarn are documented in this file. The format is based on ### Added +- Liquid Glass themes: pick Liquid Glass or Liquid Glass Light in Settings › Appearance and the + sidebar and window background turn translucent in Tarn's blues, blurring the desktop behind + them, with rounder panels and lighter edges. On macOS. - Agent control: turn on Settings › AI › Let AI agents control Tarn and add Tarn to Claude Code or Codex (`tarn --mcp`), and the agent can browse for you in a window of its own that keeps nothing. You allow the agent (look only, or act), each site it uses and each click on a page holding a diff --git a/crates/app/src/settings.rs b/crates/app/src/settings.rs index c5f791d7..8b06ece0 100644 --- a/crates/app/src/settings.rs +++ b/crates/app/src/settings.rs @@ -2,8 +2,7 @@ use browser_core::library::HistoryRange; use gpui::{ AnyElement, App, AppContext, Bounds, Context, Div, FocusHandle, Focusable, FontWeight, InteractiveElement, IntoElement, KeyDownEvent, MouseButton, MouseMoveEvent, ParentElement, Pixels, PromptLevel, Render, RenderImage, SharedString, Stateful, StatefulInteractiveElement, Styled, Subscription, - TitlebarOptions, WeakEntity, Window, WindowBackgroundAppearance, WindowBounds, WindowHandle, WindowOptions, canvas, div, img, point, - prelude::FluentBuilder, px, rgb, size, + TitlebarOptions, WeakEntity, Window, WindowBounds, WindowHandle, WindowOptions, canvas, div, img, point, prelude::FluentBuilder, px, rgb, size, }; use shield::ShieldLevel; use std::cell::Cell; @@ -338,7 +337,7 @@ impl SettingsWindow { // AppKit only hit-tests the buttons inside its titlebar strip, so they stay within it. traffic_light_position: Some(point(px(18.), px(10.))), }), - window_background: WindowBackgroundAppearance::Opaque, + window_background: crate::themes::window_background(), is_minimizable: false, ..Default::default() }; diff --git a/crates/app/src/shared.rs b/crates/app/src/shared.rs index 96797830..994a35f1 100644 --- a/crates/app/src/shared.rs +++ b/crates/app/src/shared.rs @@ -6,9 +6,7 @@ use browser_core::windows::{Frame, onto_screen}; use engine::Event; use futures::StreamExt; use futures::channel::{mpsc, oneshot}; -use gpui::{ - App, AppContext, Bounds, DisplayId, Global, Pixels, TitlebarOptions, Window, WindowBackgroundAppearance, WindowBounds, WindowOptions, point, px, size, -}; +use gpui::{App, AppContext, Bounds, DisplayId, Global, Pixels, TitlebarOptions, Window, WindowBounds, WindowOptions, point, px, size}; use store::{Id, SavedWindow}; use crate::browser::{Browser, WindowStart, data_dir}; @@ -562,7 +560,7 @@ pub(crate) fn open_window( window_bounds: Some(WindowBounds::Windowed(Bounds::new(point(px(x), px(y)), size(px(width), px(height))))), display_id: display, titlebar: Some(TitlebarOptions { title: Some("Tarn".into()), appears_transparent: true, traffic_light_position: Some(point(px(20.), px(17.))) }), - window_background: WindowBackgroundAppearance::Opaque, + window_background: crate::themes::window_background(), window_min_size: Some(size(px(720.), px(480.))), ..Default::default() }; diff --git a/crates/app/src/themes.rs b/crates/app/src/themes.rs index c7f3a347..7f55edd6 100644 --- a/crates/app/src/themes.rs +++ b/crates/app/src/themes.rs @@ -1,5 +1,7 @@ use browser_core::theme::{Active, Selection}; -use gpui::{App, WindowAppearance}; +use std::sync::atomic::{AtomicBool, Ordering}; + +use gpui::{App, WindowAppearance, WindowBackgroundAppearance}; use ui::theme::Theme; use crate::shared::AppCore; @@ -29,11 +31,32 @@ pub(crate) fn apply(core: &AppCore, system_light: bool) { let active = browser_core::theme_library::current(&core.disk, system_light, state.safe); let p = &active.parsed; Theme::set_tokens(p.tokens, p.meta.scheme, p.font.clone()); + GLASS.store(cfg!(target_os = "macos") && matches!(active.id, browser_core::theme::ThemeRef::BuiltIn(_)) && p.tokens.translucent(), Ordering::Relaxed); crate::prefs::apply_accent(&core.disk); Theme::set_search_effect(browser_core::theme_library::search_effect(&core.disk, &active)); state.active = Some(active); } +static GLASS: AtomicBool = AtomicBool::new(false); + +/// Only built-in themes see through the window: their text is tested over any desktop. Windows +/// keeps an opaque window until acrylic is tried over CEF views. +pub(crate) fn window_background() -> WindowBackgroundAppearance { + if GLASS.load(Ordering::Relaxed) { WindowBackgroundAppearance::Blurred } else { WindowBackgroundAppearance::Opaque } +} + +/// Deferred, as the caller may be inside the update of one of these windows. +fn refresh(cx: &mut App) { + cx.defer(|cx| { + let shells = + cx.windows().into_iter().filter(|w| w.downcast::().is_some() || w.downcast::().is_some()); + for handle in shells.collect::>() { + handle.update(cx, |_, window, _| window.set_background_appearance(window_background())).ok(); + } + cx.refresh_windows(); + }); +} + /// Applies the stored theme choice after it or a theme changed, and redraws every window. Pages /// get changed website styles as they load; Chromium views, which keep the script they were made /// with, are made again (macOS; on Windows `set_site_styles` restyles open pages and is @@ -43,7 +66,7 @@ pub(crate) fn changed(cx: &mut App) { if !moved.is_empty() { crate::shared::each(cx, |b, window, cx| b.restart_views_of(&moved, true, window, cx)); } - cx.refresh_windows(); + refresh(cx); } /// Loads the theme and hands every open profile its sheets; returns the profiles whose sheets @@ -77,7 +100,7 @@ pub(crate) fn enter_safe_mode(core: &AppCore, cx: &mut App) { if !moved.is_empty() { crate::shared::each(cx, |b, window, cx| b.restart_views_of(&moved, false, window, cx)); } - cx.refresh_windows(); + refresh(cx); } /// Called when macOS switches between light and dark: only a "Match system" choice follows it. diff --git a/crates/browser-core/src/theme.rs b/crates/browser-core/src/theme.rs index d296ddf5..5b212645 100644 --- a/crates/browser-core/src/theme.rs +++ b/crates/browser-core/src/theme.rs @@ -963,13 +963,24 @@ fn readable(fg: u32, backgrounds: &[u32], floor: f32) -> Option { } impl Tokens { - /// Every background text sits on, opaque over the backdrop. + /// Every background text sits on, over each end of the backdrop drawn opaque and over the + /// black an opaque window clears to. fn text_backgrounds(&self) -> Vec { - let base = self.backdrop.from | 0xff; - [self.page, self.panel, self.panel_nav, self.panel_row, self.surface, self.sidebar.from, self.sidebar.to, self.backdrop.from, self.backdrop.to] - .iter() - .map(|bg| over(*bg, base)) - .collect() + self.text_backgrounds_over(&[0x000000ff]) + } + + fn text_backgrounds_over(&self, desktops: &[u32]) -> Vec { + let layers = + [self.page, self.panel, self.panel_nav, self.panel_row, self.surface, self.sidebar.from, self.sidebar.to, self.backdrop.from, self.backdrop.to]; + let ends = [self.backdrop.from, self.backdrop.to]; + let mut bases: Vec = ends.iter().map(|e| e | 0xff).chain(ends.iter().flat_map(|e| desktops.iter().map(move |d| over(*e, *d)))).collect(); + bases.sort_unstable(); + bases.dedup(); + bases.into_iter().flat_map(|base| layers.map(|bg| over(bg, base))).collect() + } + + pub fn translucent(&self) -> bool { + self.backdrop.from & 0xff < 0xff || self.backdrop.to & 0xff < 0xff } /// The accent where it is text or a focus ring: the accent itself while it keeps @@ -1070,12 +1081,14 @@ fn tokens_css(meta: &Meta, tokens: &Tokens, font: Option<&str>) -> String { /// Themes compiled into the app: id, CSS. The first is the default dark theme, the second the /// default light one. -pub const BUILT_IN: [(&str, &str); 5] = [ +pub const BUILT_IN: [(&str, &str); 7] = [ ("tarn", include_str!("../themes/tarn.css")), ("tarn-light", include_str!("../themes/tarn-light.css")), ("graphite", include_str!("../themes/graphite.css")), ("high-contrast", include_str!("../themes/high-contrast.css")), ("ember", include_str!("../themes/ember.css")), + ("glass", include_str!("../themes/glass.css")), + ("glass-light", include_str!("../themes/glass-light.css")), ]; pub const DARK_SETTING: &str = "theme.dark"; @@ -1397,6 +1410,19 @@ mod tests { assert_eq!(parse(BUILT_IN[0].1, Source::BuiltIn).unwrap().tokens, Tokens::DARK); let light = parse(BUILT_IN[1].1, Source::BuiltIn).unwrap(); assert_eq!((light.tokens, light.meta.scheme), (Tokens::LIGHT, Scheme::Light)); + assert!(!Tokens::DARK.translucent() && !Tokens::LIGHT.translucent()); + for id in ["glass", "glass-light"] { + let css = BUILT_IN.iter().find(|(b, _)| *b == id).unwrap().1; + let mut t = parse(css, Source::BuiltIn).unwrap().tokens; + assert!(t.translucent(), "{id}"); + let backgrounds = t.text_backgrounds_over(&[0xffffffff, 0x000000ff]); + for (name, floor) in FLOORS { + let text = *text_slot(&mut t, name); + for bg in &backgrounds { + assert!(contrast(text, *bg) >= floor, "{id} {name} on {bg:08x} over any desktop"); + } + } + } } #[test] diff --git a/crates/browser-core/themes/glass-light.css b/crates/browser-core/themes/glass-light.css new file mode 100644 index 00000000..b2cb38f6 --- /dev/null +++ b/crates/browser-core/themes/glass-light.css @@ -0,0 +1,35 @@ +@tarn-theme { name: "Liquid Glass Light"; author: "Tarn"; version: "1"; scheme: light; } + +:root { + --tarn-backdrop: linear-gradient(160deg, #eef3f8e6, #dde8f3e0); + --tarn-sidebar: linear-gradient(180deg, #f7fbffb3, #e4eef899); + --tarn-sidebar-edge: #ffffffd9; + --tarn-space-label: #1567a3; + --tarn-surface: #ffffffeb; + --tarn-surface-edge: #1567a32e; + --tarn-page: #f7fafc; + --tarn-panel: #f1f5f9f0; + --tarn-panel-nav: #ffffff80; + --tarn-panel-row: #ffffffc7; + --tarn-separator: #1567a31f; + --tarn-control: #ffffffa6; + --tarn-raised: #ffffffc7; + --tarn-group: #ffffff73; + --tarn-hover: #1567a314; + --tarn-pressed: #1567a329; + --tarn-hairline: #1567a31f; + --tarn-text: #0f2236; + --tarn-muted: #1b3550c7; + --tarn-faint: #1b3550b8; + --tarn-accent: #1f75b0; + --tarn-fog-1: #d6e4f1; + --tarn-fog-2: #aac7e1; + --tarn-fog-3: #4f7fa8; + --tarn-fog-4: #1f75b0; + --tarn-radius-row: 10px; + --tarn-radius-group: 14px; + --tarn-radius-tile: 18px; + --tarn-radius-panel: 20px; + --tarn-radius-card: 24px; + --tarn-shadow: 0.7; +} diff --git a/crates/browser-core/themes/glass.css b/crates/browser-core/themes/glass.css new file mode 100644 index 00000000..2d36ed2a --- /dev/null +++ b/crates/browser-core/themes/glass.css @@ -0,0 +1,35 @@ +@tarn-theme { name: "Liquid Glass"; author: "Tarn"; version: "1"; scheme: dark; } + +:root { + --tarn-backdrop: linear-gradient(160deg, #10243ae0, #0a1a2be6); + --tarn-sidebar: linear-gradient(180deg, #1f4a7059, #1440634d); + --tarn-sidebar-edge: #8ed1f747; + --tarn-space-label: #8ed1f7; + --tarn-surface: #173350e6; + --tarn-surface-edge: #8ed1f740; + --tarn-page: #0e2134; + --tarn-panel: #10243af0; + --tarn-panel-nav: #8ed1f712; + --tarn-panel-row: #8ed1f71c; + --tarn-separator: #8ed1f724; + --tarn-control: #8ed1f71f; + --tarn-raised: #8ed1f71c; + --tarn-group: #8ed1f714; + --tarn-hover: #8ed1f71f; + --tarn-pressed: #8ed1f740; + --tarn-hairline: #8ed1f72e; + --tarn-text: #f4f9fd; + --tarn-muted: #d9ecfad1; + --tarn-faint: #d9ecfab8; + --tarn-accent: #1f75b0; + --tarn-fog-1: #2a5478; + --tarn-fog-2: #4f8bb8; + --tarn-fog-3: #e3f3fd; + --tarn-fog-4: #8ed1f7; + --tarn-radius-row: 10px; + --tarn-radius-group: 14px; + --tarn-radius-tile: 18px; + --tarn-radius-panel: 20px; + --tarn-radius-card: 24px; + --tarn-shadow: 1.1; +} diff --git a/docs/port-backlog.md b/docs/port-backlog.md index 42f775f4..e7840f4f 100644 --- a/docs/port-backlog.md +++ b/docs/port-backlog.md @@ -21,6 +21,21 @@ Reference: . ## Open +### Translucent window for glass themes (2026-11-25) + +What it does: the built-in Liquid Glass themes, whose backdrop is translucent, blur what is behind +the window instead of drawing on an opaque one. The other clients list both themes already and +paint the translucent backdrop over whatever their window clears to; nobody has checked how that +looks there. +Shared API: `browser_core::theme::Tokens::translucent`. +Reference: `crates/app/src/themes.rs` (`window_background`). + +- [ ] Windows — the same code asks GPUI for acrylic; not yet seen running over CEF views. +- [ ] Linux — `linux/` draws the backdrop on an opaque window; needs an ARGB window and a + compositor blur where one exists, else the backdrop composited opaque. +- [ ] iOS — `mobile/app` shell background; a system material behind the chrome. +- [ ] Android — `mobile/app` shell background; a window blur behind the chrome (API 31+). + ### Agent control in the user's profile or tabs (2026-11-24) What it does: two more opt-in settings in Settings › AI let the user approve an agent to open its diff --git a/docs/themes.md b/docs/themes.md index 794e3746..a63b7d50 100644 --- a/docs/themes.md +++ b/docs/themes.md @@ -35,6 +35,9 @@ Tokens (defaults are Tarn's dark theme; a missing or invalid one keeps its defau | `--tarn-search-color` | a colour for the effect (its alpha is ignored); unset means the accent | | `--tarn-font` | an installed font family | +A translucent `--tarn-backdrop` blurs the desktop through the window only for the built-in Liquid +Glass themes, whose text is checked over a white and a black desktop; any other theme draws on an +opaque window. `--tarn-danger`, `--tarn-warning` and `--tarn-success` are fixed for security and ignored. Website styles: `@media`, `@supports` and `@keyframes` (not in `*`); selectors with `:not`, `:is`, `:where`, `:has` (not nested, own and official themes only), `:nth-*`, `:lang`, `:dir`; values From dc47b224dc1170e043664998023b6948e93aa352 Mon Sep 17 00:00:00 2001 From: rgxdev Date: Wed, 25 Nov 2026 06:39:53 +0100 Subject: [PATCH 2/4] feat(appearance): add a Glass design that any theme can use, with Classic as the default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Settings › Appearance › Design switches between Classic and Glass on every client, also from View › Glass Design and the command palette. Glass gives rounder, softer panels and, on macOS, a translucent window over the blurred desktop with adjustable transparency, blur and corners. The core holds transparency back until every text colour stays readable on a light and a dark desktop. Linux turns the window translucent where the desktop composites windows; Windows, iOS and Android get the rounder panels only, with the reasons in the port backlog and plan docs. Replaces the two Liquid Glass themes. Signed-off-by: rgxdev --- CHANGELOG.md | 10 +- crates/app/src/lib.rs | 10 +- crates/app/src/menubar.rs | 2 + crates/app/src/settings.rs | 4 +- crates/app/src/settings/appearance.rs | 70 +++++++ crates/app/src/themes.rs | 23 ++- crates/browser-core/src/command.rs | 2 + crates/browser-core/src/palette.rs | 4 +- crates/browser-core/src/theme.rs | 222 +++++++++++++++++++-- crates/browser-core/src/theme_library.rs | 118 ++++++++++- crates/browser-core/themes/glass-light.css | 35 ---- crates/browser-core/themes/glass.css | 35 ---- docs/mobile-plan.md | 5 + docs/nsh-plan.md | 7 + docs/port-backlog.md | 26 ++- docs/themes.md | 7 +- linux/src/browser/feature_tests.rs | 13 ++ linux/src/browser/themes.rs | 21 +- linux/src/ui.rs | 16 +- linux/src/ui/appearance.rs | 3 + linux/src/ui/tools.rs | 6 + mobile/app/src/themes.rs | 11 +- mobile/app/src/ui/mac/toolbar.rs | 7 +- nsh-shared/src/appearance.rs | 60 +++++- nsh-shared/src/panes.rs | 4 +- 25 files changed, 585 insertions(+), 136 deletions(-) delete mode 100644 crates/browser-core/themes/glass-light.css delete mode 100644 crates/browser-core/themes/glass.css diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ff53876..4b29f5eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,13 @@ All notable changes to Tarn are documented in this file. The format is based on ### Added -- Liquid Glass themes: pick Liquid Glass or Liquid Glass Light in Settings › Appearance and the - sidebar and window background turn translucent in Tarn's blues, blurring the desktop behind - them, with rounder panels and lighter edges. On macOS. +- Glass design: Settings › Appearance › Design (or View › Glass Design, or the command palette) + switches from Classic to Glass, which works with any theme: the window turns translucent over + your desktop with rounder, softer panels. Transparency, blur behind the window and corner + roundness are adjustable; transparency is held back as far as needed to keep text readable on a + light and a dark desktop. Classic stays the default. Translucent with blur on macOS, translucent on + Linux where the desktop composites windows; rounder, softer panels only on Windows, iOS and + Android. - Agent control: turn on Settings › AI › Let AI agents control Tarn and add Tarn to Claude Code or Codex (`tarn --mcp`), and the agent can browse for you in a window of its own that keeps nothing. You allow the agent (look only, or act), each site it uses and each click on a page holding a diff --git a/crates/app/src/lib.rs b/crates/app/src/lib.rs index 25525f98..a81144f0 100644 --- a/crates/app/src/lib.rs +++ b/crates/app/src/lib.rs @@ -100,7 +100,7 @@ actions!( ] ); -actions!(tarn, [ReopenClosedTab, CloseAllTabs, DuplicateTab, CopyLink, CopyCleanLink, ToggleCompactToolbar, OpenAppMenu]); +actions!(tarn, [ReopenClosedTab, CloseAllTabs, DuplicateTab, CopyLink, CopyCleanLink, ToggleCompactToolbar, ToggleGlassDesign, OpenAppMenu]); actions!(tarn, [AboutTarn, CheckForUpdates, RestartToUpdate, HideTarn, HideOthers, ShowAll, ToggleFullScreen, NewChromiumWindow, NewWindow]); actions!(tarn, [NewGroup, ToggleLibrary, BookmarkTab, BookmarkAllTabs, ToggleAutoHideSidebar, ToggleDownloads]); actions!(tarn, [Tab1, Tab2, Tab3, Tab4, Tab5, Tab6, Tab7, Tab8, LastTab, NextTab, PreviousTab, BurnerTab]); @@ -126,6 +126,7 @@ pub(crate) fn command_action(command: browser_core::palette::Command) -> Option< C::TabsOnTop => &ToggleTabsOnTop, C::AutoHideSidebar => &ToggleAutoHideSidebar, C::CompactToolbar => &ToggleCompactToolbar, + C::GlassDesign => &ToggleGlassDesign, C::CloseAllTabs => &CloseAllTabs, C::ShowLibrary => &ToggleLibrary, C::SaveSnapshot => &library::SaveSnapshot, @@ -444,6 +445,13 @@ impl Browser { })) }) .on_action(cx.listener(|b, _: &ToggleCompactToolbar, _, cx| b.set_pref(prefs::Pref::CompactToolbar, !b.pref(prefs::Pref::CompactToolbar), cx))) + .on_action(cx.listener(|b, _: &ToggleGlassDesign, _, cx| { + let on = b.core.themes.borrow().glass; + if let Err(e) = browser_core::theme_library::set_glass_on(&b.core.disk, !on) { + b.show_toast_as(browser_core::toast::Tone::Warning, e, None, cx); + } + cx.defer(themes::changed); + })) .on_action(cx.listener(|b, _: &OpenAppMenu, window, cx| b.open_app_menu(window, cx))) .on_action(cx.listener(|b, _: &FocusNextRegion, w, cx| b.cycle_focus(false, w, cx))) .on_action(cx.listener(|b, _: &FocusPreviousRegion, w, cx| b.cycle_focus(true, w, cx))) diff --git a/crates/app/src/menubar.rs b/crates/app/src/menubar.rs index d5f60057..b03575db 100644 --- a/crates/app/src/menubar.rs +++ b/crates/app/src/menubar.rs @@ -217,6 +217,7 @@ impl Browser { self.model.active.and_then(|k| self.pinned_drift(k)).map(|u| u.host_str().map(str::to_owned)).hash(&mut hash); (self.model.active.is_some_and(|a| self.splits.contains(a)), self.site().is_some(), self.reader_shown()).hash(&mut hash); (self.sidebar_open, self.tab_placement, self.pref(crate::prefs::Pref::CompactToolbar), self.pref(crate::prefs::Pref::AutoHideSidebar)).hash(&mut hash); + self.core.themes.borrow().glass.hash(&mut hash); let signature = hash.finish(); if self.menu.signature != signature { self.menu.signature = signature; @@ -388,6 +389,7 @@ impl Browser { view.item("Tabs on Top", Box::new(crate::ToggleTabsOnTop), None, self.tab_placement == browser_core::layout::TabPlacement::Top), view.item("Compact Toolbar", Box::new(crate::ToggleCompactToolbar), None, compact), view.item("Auto-Hide Sidebar", Box::new(crate::ToggleAutoHideSidebar), None, auto_hide), + view.item("Glass Design", Box::new(crate::ToggleGlassDesign), None, self.core.themes.borrow().glass), MenuItem::separator(), view.action("Reload", crate::Reload), view.action("Reload Without Cache", crate::ReloadFromOrigin), diff --git a/crates/app/src/settings.rs b/crates/app/src/settings.rs index 8b06ece0..081567ba 100644 --- a/crates/app/src/settings.rs +++ b/crates/app/src/settings.rs @@ -80,7 +80,7 @@ const PANES: [(SettingsPane, Icon, &str, &str, &str); 14] = [ Icon::Palette, "Appearance", "Theme, accent colour, motion and layout.", - "theme dark light match system accent colour color motion reduce toolbar compact density sidebar search bar effect tips", + "theme dark light match system accent colour color motion reduce toolbar compact density sidebar search bar effect tips design glass liquid transparency translucent blur corners round", ), ( SettingsPane::Tabs, @@ -1017,6 +1017,8 @@ impl SettingsWindow { .child(section("Theme")) .child(group().children(self.theme_rows(cx)).child(row(false).child(text_block("Accent", "Buttons, selection and focus.")).child(accents))) .child(self.theme_sections(window, cx)) + .child(section("Design")) + .child(group().children(self.design_rows(cx))) .child(section("Motion")) .child(group().child(reduce_motion).child(self.search_effect_row(false, cx))) .child(section("Tips")) diff --git a/crates/app/src/settings/appearance.rs b/crates/app/src/settings/appearance.rs index abc9f88e..98570980 100644 --- a/crates/app/src/settings/appearance.rs +++ b/crates/app/src/settings/appearance.rs @@ -493,6 +493,76 @@ impl SettingsWindow { self.report(saved, "Appearance reset to Tarn.", cx); } + pub(super) fn design_rows(&self, cx: &mut Context) -> Vec { + let core = crate::shared::core(cx); + let on = library::glass_on(&core.disk); + let glass = library::glass_settings(&core.disk); + let (reached, safe) = (core.themes.borrow().reached, core.themes.borrow().safe); + let mut rows = vec![ + wide_row( + true, + text_block( + "Design", + if cfg!(target_os = "macos") { + "Glass makes the window translucent over your desktop, with rounder, softer panels." + } else { + "Glass gives rounder, softer panels." + }, + ), + Self::picks("design", on, [("Classic", false), ("Glass", true)], library::set_glass_on, cx), + ) + .into_any_element(), + ]; + if !on { + return rows; + } + let corners = browser_core::theme::Corners::ALL.map(|c| (c.label(), c)); + let corners = + wide_row(false, text_block("Corners", "How round panels and cards are."), Self::picks("corners", glass.corners, corners, library::set_corners, cx)) + .into_any_element(); + if !cfg!(target_os = "macos") { + rows.push(corners); + return rows; + } + let steps = library::TRANSPARENCY_STEPS.map(|v| (format!("{v} %"), v)); + rows.push( + wide_row( + false, + text_block("Transparency", library::transparency_note(glass.transparency, reached, safe)), + Self::picks("transparency", glass.transparency, steps, library::set_transparency, cx), + ) + .into_any_element(), + ); + let blur = glass.blur; + rows.push( + switch_row("glass-blur", false, text_block("Blur behind the window", "Off shows the desktop sharp behind the window."), blur) + .on_click(cx.listener(move |this, _, _, cx| { + let saved = library::set_blur(&crate::shared::core(cx).disk, !blur); + this.report(saved, "", cx); + this.appearance.message = this.appearance.message.take().filter(|(error, _)| *error); + })) + .into_any_element(), + ); + rows.push(corners); + rows + } + + fn picks( + key: &'static str, + current: T, + choices: [(impl Into, T); N], + set: fn(&store::Store, T) -> Result<(), String>, + cx: &mut Context, + ) -> gpui::Div { + segmented().children(choices.into_iter().enumerate().map(|(ix, (label, value))| { + tab_stop(segment((key, ix), label, value == current)).on_click(cx.listener(move |this, _, _, cx| { + let saved = set(&crate::shared::core(cx).disk, value); + this.report(saved, "", cx); + this.appearance.message = this.appearance.message.take().filter(|(error, _)| *error); + })) + })) + } + pub(super) fn search_effect_row(&self, first: bool, cx: &mut Context) -> gpui::Div { use browser_core::effects::Effect; let stored = library::chosen_effect(&crate::shared::core(cx).disk); diff --git a/crates/app/src/themes.rs b/crates/app/src/themes.rs index 7f55edd6..a85c2f39 100644 --- a/crates/app/src/themes.rs +++ b/crates/app/src/themes.rs @@ -1,5 +1,5 @@ use browser_core::theme::{Active, Selection}; -use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::atomic::{AtomicU8, Ordering}; use gpui::{App, WindowAppearance, WindowBackgroundAppearance}; use ui::theme::Theme; @@ -13,6 +13,9 @@ pub(crate) struct State { /// Shift was held at launch: the built-in theme shows, without page styles, until quit. pub safe: bool, pub system_light: bool, + /// The Glass design's transparency after the readability limit. + pub reached: u8, + pub glass: bool, } pub(crate) fn merge_revocations(core: &AppCore, list: &shield::revocations::Revocations) -> bool { @@ -30,19 +33,25 @@ pub(crate) fn apply(core: &AppCore, system_light: bool) { state.system_light = system_light; let active = browser_core::theme_library::current(&core.disk, system_light, state.safe); let p = &active.parsed; - Theme::set_tokens(p.tokens, p.meta.scheme, p.font.clone()); - GLASS.store(cfg!(target_os = "macos") && matches!(active.id, browser_core::theme::ThemeRef::BuiltIn(_)) && p.tokens.translucent(), Ordering::Relaxed); + let can = if cfg!(target_os = "macos") { browser_core::theme::Backing::Blurred } else { browser_core::theme::Backing::Opaque }; + let look = browser_core::theme_library::look(&core.disk, &active, state.safe, can); + Theme::set_tokens(look.tokens, p.meta.scheme, p.font.clone()); + BACKING.store(look.window as u8, Ordering::Relaxed); + state.reached = look.transparency; + state.glass = browser_core::theme_library::glass_on(&core.disk); crate::prefs::apply_accent(&core.disk); Theme::set_search_effect(browser_core::theme_library::search_effect(&core.disk, &active)); state.active = Some(active); } -static GLASS: AtomicBool = AtomicBool::new(false); +static BACKING: AtomicU8 = AtomicU8::new(0); -/// Only built-in themes see through the window: their text is tested over any desktop. Windows -/// keeps an opaque window until acrylic is tried over CEF views. pub(crate) fn window_background() -> WindowBackgroundAppearance { - if GLASS.load(Ordering::Relaxed) { WindowBackgroundAppearance::Blurred } else { WindowBackgroundAppearance::Opaque } + match BACKING.load(Ordering::Relaxed) { + 1 => WindowBackgroundAppearance::Transparent, + 2 => WindowBackgroundAppearance::Blurred, + _ => WindowBackgroundAppearance::Opaque, + } } /// Deferred, as the caller may be inside the update of one of these windows. diff --git a/crates/browser-core/src/command.rs b/crates/browser-core/src/command.rs index b38cf5b5..96297ed6 100644 --- a/crates/browser-core/src/command.rs +++ b/crates/browser-core/src/command.rs @@ -235,6 +235,7 @@ pub const GLYPHS: &[(&str, &str)] = &[ ("Toggle Sidebar", "sidebar"), ("Auto-Hide Sidebar", "sidebar"), ("Compact Toolbar", "app-window"), + ("Glass Design", "sparkles"), ("Close All Tabs", "close"), ("Close Duplicate Tabs", "copy"), ("Close Split View", "close"), @@ -783,6 +784,7 @@ mod tests { "Show Tabs in Sidebar", "Classic Toolbar", "Compact Toolbar", + "Glass Design", "Site Settings…", ]; for label in labels { diff --git a/crates/browser-core/src/palette.rs b/crates/browser-core/src/palette.rs index c22ddbf2..387b2ac4 100644 --- a/crates/browser-core/src/palette.rs +++ b/crates/browser-core/src/palette.rs @@ -66,6 +66,7 @@ pub enum Command { TabsOnTop, AutoHideSidebar, CompactToolbar, + GlassDesign, CloseAllTabs, ShowLibrary, SaveSnapshot, @@ -123,7 +124,7 @@ pub enum Command { AskPage, } -pub const COMMANDS: [(&str, &str, Command); 73] = [ +pub const COMMANDS: [(&str, &str, Command); 74] = [ ("Settings", "preferences options", Command::Settings), ("Open File\u{2026}", "local disk html pdf image text document view", Command::OpenFile), ("New Tab Group", "group", Command::NewGroup), @@ -142,6 +143,7 @@ pub const COMMANDS: [(&str, &str, Command); 73] = [ ("Tabs on Top", "layout strip horizontal sidebar", Command::TabsOnTop), ("Auto-Hide Sidebar", "floating", Command::AutoHideSidebar), ("Compact Toolbar", "toggle address", Command::CompactToolbar), + ("Glass Design", "liquid classic translucent transparent blur appearance look", Command::GlassDesign), ("Close All Tabs", "clear", Command::CloseAllTabs), ("Show Library", "bookmarks history", Command::ShowLibrary), ("Save Space as Snapshot", "session tabs save", Command::SaveSnapshot), diff --git a/crates/browser-core/src/theme.rs b/crates/browser-core/src/theme.rs index 5b212645..21c303ac 100644 --- a/crates/browser-core/src/theme.rs +++ b/crates/browser-core/src/theme.rs @@ -76,6 +76,8 @@ pub struct Tokens { /// accent. pub search_effect: Effect, pub search_color: Option, + /// Set by `glass` only: the backgrounds above are translucent and sit over the desktop. + pub see_through: bool, } impl Tokens { @@ -107,6 +109,7 @@ impl Tokens { fog_mode: Fog::On, search_effect: Effect::None, search_color: None, + see_through: false, }; pub const LIGHT: Tokens = Tokens { @@ -137,6 +140,7 @@ impl Tokens { fog_mode: Fog::On, search_effect: Effect::None, search_color: None, + see_through: false, }; /// The search effect's colour: the theme's, else the accent. @@ -966,7 +970,7 @@ impl Tokens { /// Every background text sits on, over each end of the backdrop drawn opaque and over the /// black an opaque window clears to. fn text_backgrounds(&self) -> Vec { - self.text_backgrounds_over(&[0x000000ff]) + self.text_backgrounds_over(if self.see_through { &[0xffffffff, 0x000000ff] } else { &[0x000000ff] }) } fn text_backgrounds_over(&self, desktops: &[u32]) -> Vec { @@ -979,10 +983,6 @@ impl Tokens { bases.into_iter().flat_map(|base| layers.map(|bg| over(bg, base))).collect() } - pub fn translucent(&self) -> bool { - self.backdrop.from & 0xff < 0xff || self.backdrop.to & 0xff < 0xff - } - /// The accent where it is text or a focus ring: the accent itself while it keeps /// `ACCENT_TEXT_FLOOR` on every background, otherwise lightened or darkened until it does. pub fn accent_text(&self) -> u32 { @@ -990,6 +990,118 @@ impl Tokens { } } +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] +pub enum Corners { + Theme, + #[default] + Round, + Rounder, +} + +impl Corners { + pub const ALL: [Corners; 3] = [Corners::Theme, Corners::Round, Corners::Rounder]; + + pub fn label(self) -> &'static str { + match self { + Corners::Theme => "Theme", + Corners::Round => "Round", + Corners::Rounder => "Rounder", + } + } + + pub fn name(self) -> &'static str { + match self { + Corners::Theme => "theme", + Corners::Round => "round", + Corners::Rounder => "rounder", + } + } + + pub fn parse(s: &str) -> Option { + Corners::ALL.into_iter().find(|c| c.name() == s) + } + + fn radii(self) -> Option<[f32; 6]> { + match self { + Corners::Theme => None, + Corners::Round => Some([8., 11., 14., 18., 20., 24.]), + Corners::Rounder => Some([10., 13., 16., 20., 22., 24.]), + } + } +} + +/// The Glass design's settings: how see-through the window is (0 to 100), whether the desktop +/// behind it is blurred, and how round its corners are. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct Glass { + pub transparency: u8, + pub blur: bool, + pub corners: Corners, +} + +impl Default for Glass { + fn default() -> Self { + Glass { transparency: 60, blur: true, corners: Corners::default() } + } +} + +/// What a window can be drawn over: nothing (opaque), the desktop, or the blurred desktop. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum Backing { + Opaque, + Clear, + Blurred, +} + +fn fade(c: u32, alpha: f32) -> u32 { + (over(c, 0x000000ff) & !0xff) | (alpha * 255.).round() as u32 +} + +fn soften(c: u32) -> u32 { + (c & !0xff) | ((c & 0xff) as f32 * 0.6).round() as u32 +} + +/// `tokens` in the Glass design: rounder corners, softer edges and, where `can` allows, a window +/// that shows the desktop. Returns the tokens, how the window is backed and the transparency +/// reached, which is the requested one unless text could not stay readable on a light and a dark +/// desktop at once, when it steps down until it can. +pub fn glass(tokens: &Tokens, glass: Glass, can: Backing) -> (Tokens, Backing, u8) { + let mut t = *tokens; + if let Some(table) = glass.corners.radii() { + t.radius = std::array::from_fn(|i| t.radius[i].max(table[i]).min(24.)); + } + for edge in [&mut t.sidebar_edge, &mut t.surface_edge, &mut t.hairline, &mut t.separator] { + *edge = soften(*edge); + } + t.shadow = (t.shadow * 1.15).min(1.5); + if can == Backing::Opaque { + return (t, Backing::Opaque, 0); + } + let mut percent = glass.transparency.min(100); + while percent > 0 { + let f = percent as f32 / 100.; + let mut c = t; + c.see_through = true; + let (backdrop, sidebar, layer) = (1. - 0.70 * f, 1. - 0.75 * f, 1. - 0.14 * f); + c.backdrop = Gradient { from: fade(t.backdrop.from, backdrop), to: fade(t.backdrop.to, backdrop), ..t.backdrop }; + c.sidebar = Gradient { from: fade(t.sidebar.from, sidebar), to: fade(t.sidebar.to, sidebar), ..t.sidebar }; + for slot in [&mut c.panel, &mut c.surface] { + *slot = fade(*slot, layer); + } + let backgrounds = c.text_backgrounds(); + let readable_text = FLOORS.iter().try_for_each(|(name, floor)| { + let slot = text_slot(&mut c, name); + readable(*slot, &backgrounds, *floor).map(|r| *slot = r) + }); + if readable_text.is_some() && readable(c.accent | 0xff, &backgrounds, ACCENT_TEXT_FLOOR).is_some() { + let backing = if glass.blur && can == Backing::Blurred { Backing::Blurred } else { Backing::Clear }; + return (c, backing, percent); + } + percent = percent.saturating_sub(5); + } + (t, Backing::Opaque, 0) +} + /// Moves each text colour towards white or black until it reaches its floor on every background /// it sits on. When no colour can (light and dark backgrounds mixed), the text and background /// colours go back to the scheme's defaults. Returns what it changed. @@ -1081,14 +1193,12 @@ fn tokens_css(meta: &Meta, tokens: &Tokens, font: Option<&str>) -> String { /// Themes compiled into the app: id, CSS. The first is the default dark theme, the second the /// default light one. -pub const BUILT_IN: [(&str, &str); 7] = [ +pub const BUILT_IN: [(&str, &str); 5] = [ ("tarn", include_str!("../themes/tarn.css")), ("tarn-light", include_str!("../themes/tarn-light.css")), ("graphite", include_str!("../themes/graphite.css")), ("high-contrast", include_str!("../themes/high-contrast.css")), ("ember", include_str!("../themes/ember.css")), - ("glass", include_str!("../themes/glass.css")), - ("glass-light", include_str!("../themes/glass-light.css")), ]; pub const DARK_SETTING: &str = "theme.dark"; @@ -1410,21 +1520,97 @@ mod tests { assert_eq!(parse(BUILT_IN[0].1, Source::BuiltIn).unwrap().tokens, Tokens::DARK); let light = parse(BUILT_IN[1].1, Source::BuiltIn).unwrap(); assert_eq!((light.tokens, light.meta.scheme), (Tokens::LIGHT, Scheme::Light)); - assert!(!Tokens::DARK.translucent() && !Tokens::LIGHT.translucent()); - for id in ["glass", "glass-light"] { - let css = BUILT_IN.iter().find(|(b, _)| *b == id).unwrap().1; - let mut t = parse(css, Source::BuiltIn).unwrap().tokens; - assert!(t.translucent(), "{id}"); - let backgrounds = t.text_backgrounds_over(&[0xffffffff, 0x000000ff]); - for (name, floor) in FLOORS { - let text = *text_slot(&mut t, name); - for bg in &backgrounds { - assert!(contrast(text, *bg) >= floor, "{id} {name} on {bg:08x} over any desktop"); + } + + fn built_in_tokens(id: &str) -> Tokens { + parse(BUILT_IN.iter().find(|(b, _)| *b == id).unwrap().1, Source::BuiltIn).unwrap().tokens + } + + #[test] + fn glass_keeps_text_readable_over_any_desktop_at_every_transparency() { + for (id, _) in BUILT_IN { + let classic = built_in_tokens(id); + for transparency in [0, 50, 100] { + for blur in [false, true] { + for can in [Backing::Clear, Backing::Blurred] { + let (mut t, backing, effective) = glass(&classic, Glass { transparency, blur, corners: Corners::Round }, can); + assert!(effective <= transparency, "{id}"); + if effective == 0 { + assert!(backing == Backing::Opaque && !t.see_through, "{id}"); + assert_eq!((t.text, t.backdrop, t.panel), (classic.text, classic.backdrop, classic.panel), "{id}"); + continue; + } + assert!(t.see_through, "{id}"); + assert_eq!(backing, if blur && can == Backing::Blurred { Backing::Blurred } else { Backing::Clear }); + let backgrounds = t.text_backgrounds(); + for (name, floor) in FLOORS { + let text = *text_slot(&mut t, name); + for bg in &backgrounds { + assert!(contrast(text, *bg) >= floor, "{id} {name} on {bg:08x} at {effective}"); + } + } + for bg in &backgrounds { + assert!(contrast(t.accent_text(), *bg) >= ACCENT_TEXT_FLOOR, "{id} accent on {bg:08x}"); + } + } } } } } + #[test] + fn an_opaque_window_gets_corners_and_soft_edges_only() { + let classic = Tokens::DARK; + let (t, backing, effective) = glass(&classic, Glass { transparency: 100, blur: true, corners: Corners::Rounder }, Backing::Opaque); + assert_eq!((backing, effective, t.see_through), (Backing::Opaque, 0, false)); + assert_eq!((t.backdrop, t.text, t.panel), (classic.backdrop, classic.text, classic.panel)); + assert_eq!(t.radius, [10., 13., 16., 20., 22., 24.]); + assert_eq!(t.hairline & 0xff, (0x1f as f32 * 0.6).round() as u32); + assert_eq!(t.shadow, 1.15); + let (theme_corners, ..) = glass(&classic, Glass { corners: Corners::Theme, ..Glass::default() }, Backing::Opaque); + assert_eq!(theme_corners.radius, classic.radius); + } + + #[test] + fn corners_never_shrink_a_themes_radii_and_stop_at_24() { + let hostile = Tokens { radius: [0., 40., 12., 14., 12., 16.], shadow: 1.5, ..Tokens::DARK }; + let (t, ..) = glass(&hostile, Glass::default(), Backing::Opaque); + assert_eq!(t.radius, [8., 24., 14., 18., 20., 24.]); + assert_eq!(t.shadow, 1.5); + } + + #[test] + fn tarn_dark_stays_see_through_at_full_transparency() { + let (_, backing, effective) = glass(&Tokens::DARK, Glass { transparency: 100, blur: true, corners: Corners::Round }, Backing::Blurred); + assert_eq!(backing, Backing::Blurred); + assert!(effective >= 40, "{effective}"); + } + + #[test] + fn a_hostile_theme_falls_back_to_opaque_rather_than_unreadable() { + let mixed = Tokens { + backdrop: Gradient { angle: 0., from: 0xffffffff, to: 0x000000ff }, + sidebar: Gradient { angle: 0., from: 0xffffffff, to: 0x000000ff }, + ..Tokens::DARK + }; + let (t, backing, effective) = glass(&mixed, Glass { transparency: 100, blur: true, corners: Corners::Round }, Backing::Blurred); + if backing == Backing::Opaque { + assert_eq!((effective, t.see_through), (0, false)); + } else { + let backgrounds = t.text_backgrounds(); + assert!(backgrounds.iter().all(|bg| contrast(t.text, *bg) >= 4.5)); + } + } + + #[test] + fn parsing_never_makes_a_theme_see_through() { + for (id, _) in BUILT_IN { + assert!(!built_in_tokens(id).see_through, "{id}"); + } + let p = parse("@tarn-theme { scheme: dark; } :root { --tarn-backdrop: #00000000; --tarn-see-through: true }", Source::Yours).unwrap(); + assert!(!p.tokens.see_through); + } + #[test] fn accent_text_is_readable_on_every_background_with_any_accent() { for (id, css) in BUILT_IN { diff --git a/crates/browser-core/src/theme_library.rs b/crates/browser-core/src/theme_library.rs index 1e46ff24..f2c48338 100644 --- a/crates/browser-core/src/theme_library.rs +++ b/crates/browser-core/src/theme_library.rs @@ -5,11 +5,16 @@ use std::path::Path; use store::{Id, Store}; use crate::effects::{Effect, chosen}; -use crate::theme::{self, Active, Origin, Scheme, Selection, Source, ThemeRef}; +use crate::prefs::Switch; +use crate::theme::{self, Active, Backing, Corners, Glass, Origin, Scheme, Selection, Source, ThemeRef, Tokens}; pub const REVOKED_SETTING: &str = "theme.revoked"; pub const REVOKED_REPOS_SETTING: &str = "theme.revoked_repos"; pub const SEARCH_EFFECT_SETTING: &str = "search_effect"; +pub const DESIGN_SETTING: &str = "design"; +pub const TRANSPARENCY_SETTING: &str = "design.transparency"; +pub const CORNERS_SETTING: &str = "design.corners"; +pub const GLASS_BLUR: Switch = Switch { key: "design.blur", default: true }; pub fn revoked(store: &Store) -> String { store.setting(REVOKED_SETTING).ok().flatten().unwrap_or_default() @@ -74,6 +79,65 @@ pub fn set_effect(store: &Store, effect: Option) -> Result<(), String> { store.set_setting(SEARCH_EFFECT_SETTING, effect.map_or("theme", Effect::name)).map_err(|e| e.to_string()) } +/// How the shell is drawn: the theme's tokens, how the window is backed and the transparency reached. +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct Look { + pub tokens: Tokens, + pub window: Backing, + pub transparency: u8, +} + +pub fn glass_on(store: &Store) -> bool { + store.setting(DESIGN_SETTING).ok().flatten().as_deref() == Some("glass") +} + +pub fn set_glass_on(store: &Store, on: bool) -> Result<(), String> { + store.set_setting(DESIGN_SETTING, if on { "glass" } else { "classic" }).map_err(|e| e.to_string()) +} + +pub fn glass_settings(store: &Store) -> Glass { + let default = Glass::default(); + Glass { + transparency: store.setting(TRANSPARENCY_SETTING).ok().flatten().and_then(|v| v.parse::().ok()).map_or(default.transparency, |v| v.min(100)), + blur: GLASS_BLUR.on(store), + corners: store.setting(CORNERS_SETTING).ok().flatten().and_then(|v| Corners::parse(&v)).unwrap_or(default.corners), + } +} + +/// The transparency choices offered in settings. +pub const TRANSPARENCY_STEPS: [u8; 5] = [20, 40, 60, 80, 100]; + +/// What settings say under the transparency choices once `reached` is known. +pub fn transparency_note(requested: u8, reached: u8, safe: bool) -> String { + match reached { + _ if safe => "Safe mode keeps the window opaque until Tarn restarts.".to_owned(), + 0 => "This theme's text cannot stay readable over the desktop, so the window stays opaque.".to_owned(), + r if r < requested => format!("Held at {r} % so text stays readable on light and dark desktops."), + _ => "How much of the desktop shows through.".to_owned(), + } +} + +pub fn set_transparency(store: &Store, percent: u8) -> Result<(), String> { + store.set_setting(TRANSPARENCY_SETTING, &percent.min(100).to_string()).map_err(|e| e.to_string()) +} + +pub fn set_blur(store: &Store, on: bool) -> Result<(), String> { + if GLASS_BLUR.set(store, on) { Ok(()) } else { Err("The setting could not be saved.".to_owned()) } +} + +pub fn set_corners(store: &Store, corners: Corners) -> Result<(), String> { + store.set_setting(CORNERS_SETTING, corners.name()).map_err(|e| e.to_string()) +} + +pub fn look(store: &Store, active: &Active, safe: bool, can: Backing) -> Look { + let tokens = active.parsed.tokens; + if safe || !glass_on(store) { + return Look { tokens, window: Backing::Opaque, transparency: 0 }; + } + let (tokens, window, transparency) = theme::glass(&tokens, glass_settings(store), can); + Look { tokens, window, transparency } +} + pub fn pages_on(store: &Store, profile_id: Id) -> bool { store.setting(&theme::pages_setting(profile_id)).ok().flatten().as_deref() != Some("off") } @@ -210,6 +274,9 @@ pub fn set_page_css(store: &Store, id: Id, on: bool) -> Result<(), String> { } pub fn reset(store: &Store) -> Result<(), String> { + for key in [DESIGN_SETTING, TRANSPARENCY_SETTING, CORNERS_SETTING, GLASS_BLUR.key] { + store.delete_setting(key).map_err(|e| e.to_string())?; + } Selection { dark: ThemeRef::DARK, light: ThemeRef::LIGHT, match_system: false }.save(store).map_err(|e| e.to_string()) } @@ -363,6 +430,55 @@ mod tests { assert_eq!(badge("official:x"), "Official"); } + #[test] + fn the_design_defaults_round_trip_and_ignore_garbage() { + let (_d, s) = store(); + assert_eq!((glass_on(&s), glass_settings(&s)), (false, Glass { transparency: 60, blur: true, corners: Corners::Round })); + set_glass_on(&s, true).unwrap(); + set_transparency(&s, 250).unwrap(); + set_blur(&s, false).unwrap(); + set_corners(&s, Corners::Rounder).unwrap(); + assert_eq!((glass_on(&s), glass_settings(&s)), (true, Glass { transparency: 100, blur: false, corners: Corners::Rounder })); + s.set_setting(TRANSPARENCY_SETTING, "300").unwrap(); + assert_eq!(glass_settings(&s).transparency, 60); + s.set_setting(TRANSPARENCY_SETTING, "x").unwrap(); + s.set_setting(CORNERS_SETTING, "square").unwrap(); + s.set_setting(DESIGN_SETTING, "other").unwrap(); + assert_eq!((glass_on(&s), glass_settings(&s).transparency, glass_settings(&s).corners), (false, 60, Corners::Round)); + } + + #[test] + fn look_is_classic_unless_glass_is_on_and_safe_mode_is_not() { + let (_d, s) = store(); + let active = current(&s, false, false); + let classic = Look { tokens: active.parsed.tokens, window: Backing::Opaque, transparency: 0 }; + assert_eq!(look(&s, &active, false, Backing::Blurred), classic); + set_glass_on(&s, true).unwrap(); + assert_eq!(look(&s, &active, true, Backing::Blurred), classic); + let glassy = look(&s, &active, false, Backing::Blurred); + assert!(glassy.tokens.see_through && glassy.window == Backing::Blurred && glassy.transparency > 0); + assert_eq!(look(&s, &active, false, Backing::Opaque).window, Backing::Opaque); + } + + #[test] + fn the_transparency_note_names_why_it_was_held() { + assert!(transparency_note(60, 0, true).starts_with("Safe mode")); + assert!(transparency_note(60, 0, false).contains("stays opaque")); + assert!(transparency_note(80, 40, false).starts_with("Held at 40 %")); + assert_eq!(transparency_note(60, 60, false), "How much of the desktop shows through."); + } + + #[test] + fn reset_clears_the_design() { + let (_d, s) = store(); + set_glass_on(&s, true).unwrap(); + set_transparency(&s, 10).unwrap(); + set_blur(&s, false).unwrap(); + set_corners(&s, Corners::Theme).unwrap(); + reset(&s).unwrap(); + assert_eq!((glass_on(&s), glass_settings(&s)), (false, Glass::default())); + } + #[test] fn the_engines_take_as_much_theme_css_as_a_profile_gets() { assert_eq!(engine::page_scripts::MAX_THEME_SHEETS, store::MAX_SITE_CSS); diff --git a/crates/browser-core/themes/glass-light.css b/crates/browser-core/themes/glass-light.css deleted file mode 100644 index b2cb38f6..00000000 --- a/crates/browser-core/themes/glass-light.css +++ /dev/null @@ -1,35 +0,0 @@ -@tarn-theme { name: "Liquid Glass Light"; author: "Tarn"; version: "1"; scheme: light; } - -:root { - --tarn-backdrop: linear-gradient(160deg, #eef3f8e6, #dde8f3e0); - --tarn-sidebar: linear-gradient(180deg, #f7fbffb3, #e4eef899); - --tarn-sidebar-edge: #ffffffd9; - --tarn-space-label: #1567a3; - --tarn-surface: #ffffffeb; - --tarn-surface-edge: #1567a32e; - --tarn-page: #f7fafc; - --tarn-panel: #f1f5f9f0; - --tarn-panel-nav: #ffffff80; - --tarn-panel-row: #ffffffc7; - --tarn-separator: #1567a31f; - --tarn-control: #ffffffa6; - --tarn-raised: #ffffffc7; - --tarn-group: #ffffff73; - --tarn-hover: #1567a314; - --tarn-pressed: #1567a329; - --tarn-hairline: #1567a31f; - --tarn-text: #0f2236; - --tarn-muted: #1b3550c7; - --tarn-faint: #1b3550b8; - --tarn-accent: #1f75b0; - --tarn-fog-1: #d6e4f1; - --tarn-fog-2: #aac7e1; - --tarn-fog-3: #4f7fa8; - --tarn-fog-4: #1f75b0; - --tarn-radius-row: 10px; - --tarn-radius-group: 14px; - --tarn-radius-tile: 18px; - --tarn-radius-panel: 20px; - --tarn-radius-card: 24px; - --tarn-shadow: 0.7; -} diff --git a/crates/browser-core/themes/glass.css b/crates/browser-core/themes/glass.css deleted file mode 100644 index 2d36ed2a..00000000 --- a/crates/browser-core/themes/glass.css +++ /dev/null @@ -1,35 +0,0 @@ -@tarn-theme { name: "Liquid Glass"; author: "Tarn"; version: "1"; scheme: dark; } - -:root { - --tarn-backdrop: linear-gradient(160deg, #10243ae0, #0a1a2be6); - --tarn-sidebar: linear-gradient(180deg, #1f4a7059, #1440634d); - --tarn-sidebar-edge: #8ed1f747; - --tarn-space-label: #8ed1f7; - --tarn-surface: #173350e6; - --tarn-surface-edge: #8ed1f740; - --tarn-page: #0e2134; - --tarn-panel: #10243af0; - --tarn-panel-nav: #8ed1f712; - --tarn-panel-row: #8ed1f71c; - --tarn-separator: #8ed1f724; - --tarn-control: #8ed1f71f; - --tarn-raised: #8ed1f71c; - --tarn-group: #8ed1f714; - --tarn-hover: #8ed1f71f; - --tarn-pressed: #8ed1f740; - --tarn-hairline: #8ed1f72e; - --tarn-text: #f4f9fd; - --tarn-muted: #d9ecfad1; - --tarn-faint: #d9ecfab8; - --tarn-accent: #1f75b0; - --tarn-fog-1: #2a5478; - --tarn-fog-2: #4f8bb8; - --tarn-fog-3: #e3f3fd; - --tarn-fog-4: #8ed1f7; - --tarn-radius-row: 10px; - --tarn-radius-group: 14px; - --tarn-radius-tile: 18px; - --tarn-radius-panel: 20px; - --tarn-radius-card: 24px; - --tarn-shadow: 1.1; -} diff --git a/docs/mobile-plan.md b/docs/mobile-plan.md index 7baa1b53..bdc5ab4f 100644 --- a/docs/mobile-plan.md +++ b/docs/mobile-plan.md @@ -838,6 +838,11 @@ loopback HTTPS server through a loopback proxy (an app built with `TARN_TEST_PRO the simulator's keychain; evidence in `mobile/evidence/themes-github/`. Android carries theme sheets in the page world, as it does site CSS (S28/S29). +The Glass design (Settings › Appearance › Design; Glass Design in the command bar of the tablet's +Mac layout) gives rounder corners and softer edges only: the core is asked for `Backing::Opaque`, so +Settings offers Corners but no Transparency or Blur. Gap on iOS: a full-screen app has nothing of the +home screen behind it, and the web views draw above the NSH views, so there is nothing to see through. +Android could show the wallpaper instead (port backlog). ### Install script and portable build diff --git a/docs/nsh-plan.md b/docs/nsh-plan.md index ba92dc2e..5b9721ee 100644 --- a/docs/nsh-plan.md +++ b/docs/nsh-plan.md @@ -441,6 +441,13 @@ These figures were measured with particles drawn as solid dots; since 2026-11-21 glow (a radial gradient here, a blurred shadow on macOS and Windows), and Glow runs at 24 fps with a light running around the card instead of a ring pulsing at 8 fps; not yet measured again. +The Glass design (Settings › Appearance › Design, or Glass Design in the command bar) asks the core for +`Backing::Clear` while GDK reports a composited display and `Backing::Opaque` otherwise; with Clear the +windows get NSH's `transparent` attribute and the theme's backdrop lets the desktop through, at the +transparency the core keeps readable. Without a compositor only the rounder corners and softer edges +apply, and Settings offers no Transparency. Gap: no blur behind the window, because GTK 4 and NSH have no +API to ask for one; a compositor set to blur translucent windows on its own may still do it. + ### Agent control on Linux `linux/src/ui/agent.rs` runs `browser_core::agent::control` over `engine::agent_socket::Server` (threat diff --git a/docs/port-backlog.md b/docs/port-backlog.md index e7840f4f..73f38878 100644 --- a/docs/port-backlog.md +++ b/docs/port-backlog.md @@ -21,20 +21,18 @@ Reference: . ## Open -### Translucent window for glass themes (2026-11-25) - -What it does: the built-in Liquid Glass themes, whose backdrop is translucent, blur what is behind -the window instead of drawing on an opaque one. The other clients list both themes already and -paint the translucent backdrop over whatever their window clears to; nobody has checked how that -looks there. -Shared API: `browser_core::theme::Tokens::translucent`. -Reference: `crates/app/src/themes.rs` (`window_background`). - -- [ ] Windows — the same code asks GPUI for acrylic; not yet seen running over CEF views. -- [ ] Linux — `linux/` draws the backdrop on an opaque window; needs an ARGB window and a - compositor blur where one exists, else the backdrop composited opaque. -- [ ] iOS — `mobile/app` shell background; a system material behind the chrome. -- [ ] Android — `mobile/app` shell background; a window blur behind the chrome (API 31+). +### See-through window for the Glass design (2026-11-25) + +What it does: with Settings › Appearance › Design on Glass, the window lets the desktop show +through behind the sidebar and toolbar, as far as text stays readable. +Shared API: `browser_core::theme_library::look` with the `Backing` the window can have. +Reference: `crates/app/src/themes.rs` (`window_background`), `linux/src/browser/themes.rs`. + +- [ ] Windows — `crates/app/src/themes.rs` asks for `Backing::Opaque` off macOS; GPUI can give + acrylic (`Blurred`), which needs trying over CEF views before the transparency rows show there. +- [ ] Android — `mobile/app/src/themes.rs` asks for `Backing::Opaque`; the activity could show the + wallpaper behind the chrome (`FLAG_SHOW_WALLPAPER`, blurred with `setBackgroundBlurRadius` on + API 31+), with `mobile/android` passing `Backing::Clear` or `Blurred` up. ### Agent control in the user's profile or tabs (2026-11-24) diff --git a/docs/themes.md b/docs/themes.md index a63b7d50..be8920d2 100644 --- a/docs/themes.md +++ b/docs/themes.md @@ -35,9 +35,10 @@ Tokens (defaults are Tarn's dark theme; a missing or invalid one keeps its defau | `--tarn-search-color` | a colour for the effect (its alpha is ignored); unset means the accent | | `--tarn-font` | an installed font family | -A translucent `--tarn-backdrop` blurs the desktop through the window only for the built-in Liquid -Glass themes, whose text is checked over a white and a black desktop; any other theme draws on an -opaque window. +No theme token makes the window see-through. The Glass design (Settings › Appearance › Design) +does that for any theme, in `browser_core::theme::glass`, holding transparency back until every +text colour stays readable over a white and a black desktop. + `--tarn-danger`, `--tarn-warning` and `--tarn-success` are fixed for security and ignored. Website styles: `@media`, `@supports` and `@keyframes` (not in `*`); selectors with `:not`, `:is`, `:where`, `:has` (not nested, own and official themes only), `:nth-*`, `:lang`, `:dir`; values diff --git a/linux/src/browser/feature_tests.rs b/linux/src/browser/feature_tests.rs index 9c8d1a5b..c3075c7b 100644 --- a/linux/src/browser/feature_tests.rs +++ b/linux/src/browser/feature_tests.rs @@ -1306,6 +1306,19 @@ fn a_peek_reloads_at_a_stricter_level_and_closes_with_its_tab() { assert_eq!(b.model.active, Some(other)); } +#[test] +fn the_glass_design_is_off_until_turned_on_and_stays_on() { + let (dir, mut b) = browser(); + assert!(!browser_core::theme_library::glass_on(&b.core.disk)); + b.toggle_glass_design(); + b.apply_theme(); + assert_eq!(b.core.disk.setting(browser_core::theme_library::DESIGN_SETTING).unwrap().as_deref(), Some("glass"), "the key the macOS client reads"); + assert_eq!(b.themes.window, browser_core::theme::Backing::Opaque, "no display, so nothing to see through"); + drop(b); + let b = Browser::open(dir.path()); + assert!(browser_core::theme_library::glass_on(&b.core.disk)); +} + #[test] fn compact_toolbar_and_auto_hide_sidebar_are_off_until_turned_on() { let (_dir, mut b) = browser(); diff --git a/linux/src/browser/themes.rs b/linux/src/browser/themes.rs index ae841bc9..adfd2c3c 100644 --- a/linux/src/browser/themes.rs +++ b/linux/src/browser/themes.rs @@ -1,6 +1,6 @@ use browser_core::prefs; use browser_core::tabs::TabKey; -use browser_core::theme::Active; +use browser_core::theme::{Active, Backing}; use browser_core::theme_library as library; use serde_json::{Value, json}; use tarn_nsh_shared::theme::Theme; @@ -12,6 +12,7 @@ pub struct Themes { pub active: Active, pub safe: bool, pub light: bool, + pub window: Backing, } pub fn catalog_dir() -> std::path::PathBuf { @@ -22,20 +23,34 @@ impl Themes { pub fn open(store: &store::Store, filters: &std::path::Path) -> Themes { library::merge_cached_bundle(store, filters); browser_core::theme_fetch::merge_cached_catalog(store, &catalog_dir()); - Themes { active: library::current(store, false, false), safe: false, light: false } + Themes { active: library::current(store, false, false), safe: false, light: false, window: Backing::Opaque } } } +/// GTK 4 has no blur behind a window, so the most a composited display offers is a clear one. +pub fn desktop_backing() -> Backing { + use webkit6::prelude::*; + if webkit6::gdk::Display::default().is_some_and(|d| d.is_composited()) { Backing::Clear } else { Backing::Opaque } +} + impl Browser { pub fn apply_theme(&mut self) { let store = &self.core.disk; let active = library::current(store, self.themes.light, self.themes.safe); + let look = library::look(store, &active, self.themes.safe, desktop_backing()); let p = &active.parsed; - Theme::set_tokens(prefs::accented(p.tokens, store), p.meta.scheme, p.font.clone()); + Theme::set_tokens(prefs::accented(look.tokens, store), p.meta.scheme, p.font.clone()); Theme::set_search_effect(library::search_effect(store, &active)); tarn_nsh_shared::motion::set_reduced(prefs::REDUCE_MOTION.on(store)); Theme::set_compact(prefs::COMPACT.on(store)); self.themes.active = active; + self.themes.window = look.window; + } + + pub fn toggle_glass_design(&mut self) { + if let Err(e) = library::set_glass_on(&self.core.disk, !library::glass_on(&self.core.disk)) { + self.show_toast_as(browser_core::toast::Tone::Warning, e, None); + } } pub fn follow_appearance(&mut self, light: bool) { diff --git a/linux/src/ui.rs b/linux/src/ui.rs index 11bbb70c..81b6f717 100644 --- a/linux/src/ui.rs +++ b/linux/src/ui.rs @@ -2767,12 +2767,22 @@ pub fn refresh_panels() { pub fn themes_changed() { for ui in WINDOWS.with_borrow(Vec::clone) { act(ui, Browser::apply_theme); + match_backing(ui); } if let Some(ui) = WINDOWS.with_borrow(|w| w.first().copied()) { apply_color_scheme(ui, Theme::is_light()); } } +fn match_backing(ui: Ui) { + let clear = read(ui, |b| b.themes.window != browser_core::theme::Backing::Opaque).unwrap_or_default(); + if let Some(here) = WINDOW_REFS.with_borrow(|refs| refs.get(&ui.window).cloned()) { + let mut attributes = WindowAttributes::default(); + attributes.transparent = Some(clear); + here.set(attributes); + } +} + /// Gives every page the app theme's colour scheme, or the system's while the theme follows it. fn apply_color_scheme(ui: Ui, light: bool) { let follows = read(ui, |b| browser_core::theme::Selection::load(&b.core.disk).match_system).unwrap_or(true); @@ -3088,6 +3098,7 @@ fn browser_window(ui: Ui) -> AnyElement { let here = current_window(); keep_placement(ui, here.clone()); WINDOW_REFS.with_borrow_mut(|refs| refs.insert(ui.window, here.clone())); + match_backing(ui); here.on_focus_change(move |focused| { if focused { FOCUSED.with(|f| f.set(ui.window)); @@ -3138,7 +3149,10 @@ fn browser_window(ui: Ui) -> AnyElement { } effect(move || { let light = !dark(); - untracked(|| act(ui, |b| b.follow_appearance(light))); + untracked(|| { + act(ui, |b| b.follow_appearance(light)); + match_backing(ui); + }); }); effect(move || { let light = Theme::is_light(); diff --git a/linux/src/ui/appearance.rs b/linux/src/ui/appearance.rs index 5760d0aa..fb16e398 100644 --- a/linux/src/ui/appearance.rs +++ b/linux/src/ui/appearance.rs @@ -52,6 +52,9 @@ impl Host for Looks { fn accent_and_motion(self) -> bool { true } + fn backing(self) -> browser_core::theme::Backing { + crate::browser::themes::desktop_backing() + } } pub(super) fn pane(ui: Ui) -> AnyElement { diff --git a/linux/src/ui/tools.rs b/linux/src/ui/tools.rs index ef3e311d..f29ebdf9 100644 --- a/linux/src/ui/tools.rs +++ b/linux/src/ui/tools.rs @@ -67,6 +67,7 @@ pub enum Command { SetPinnedUrl, SleepOthers, StopLoading, + GlassDesign, ToastAction, Ask, AskPage, @@ -134,6 +135,7 @@ fn command_for(command: palette::Command) -> Option { C::NewWindow => Command::NewWindow, C::FullScreen => Command::FullScreen, C::StopLoading => Command::StopLoading, + C::GlassDesign => Command::GlassDesign, C::ReloadFromOrigin => Command::Key(Action::ReloadFromOrigin), C::CloseWindow => Command::Key(Action::CloseWindow), C::KeyboardShortcuts => Command::Key(Action::ToggleShortcuts), @@ -287,6 +289,10 @@ pub fn run(ui: Ui, command: Command) { Command::NewWindow => super::new_window(ui), Command::FullScreen => act(ui, Browser::toggle_full_screen), Command::StopLoading => act(ui, Browser::stop), + Command::GlassDesign => { + act(ui, Browser::toggle_glass_design); + super::themes_changed(); + } Command::ToastAction => take_toast_action(ui), Command::Ask => super::assistant::open(ui, false), Command::AskPage => super::assistant::open(ui, true), diff --git a/mobile/app/src/themes.rs b/mobile/app/src/themes.rs index fda04d8e..a9f7a4f4 100644 --- a/mobile/app/src/themes.rs +++ b/mobile/app/src/themes.rs @@ -1,6 +1,6 @@ use std::path::{Path, PathBuf}; -use browser_core::theme::Active; +use browser_core::theme::{Active, Backing}; use browser_core::theme_library as library; use store::Store; use tarn_nsh_shared::theme::Theme; @@ -27,12 +27,19 @@ impl Shell { let store = &self.core.disk; let active = library::current(store, self.themes.light, false); let p = &active.parsed; - Theme::set_tokens(p.tokens, p.meta.scheme, p.font.clone()); + Theme::set_tokens(library::look(store, &active, false, Backing::Opaque).tokens, p.meta.scheme, p.font.clone()); Theme::set_search_effect(library::search_effect(store, &active)); Theme::set_compact(browser_core::prefs::COMPACT.on(store)); self.themes.active = active; } + pub fn toggle_glass_design(&mut self) { + if let Err(e) = library::set_glass_on(&self.core.disk, !library::glass_on(&self.core.disk)) { + self.toast_as(browser_core::toast::Tone::Warning, e); + } + self.apply_theme(); + } + pub fn follow_appearance(&mut self, light: bool) { if self.themes.light != light { self.themes.light = light; diff --git a/mobile/app/src/ui/mac/toolbar.rs b/mobile/app/src/ui/mac/toolbar.rs index f78878d8..09158d6a 100644 --- a/mobile/app/src/ui/mac/toolbar.rs +++ b/mobile/app/src/ui/mac/toolbar.rs @@ -21,7 +21,7 @@ use url::Url; use super::super::{Screen, Ui, bars}; use crate::theme::{TEXT_TITLE, TOOLBAR_HEIGHT, Theme, themed}; -const OFFERED: [Command; 29] = [ +const OFFERED: [Command; 30] = [ Command::OpenFile, Command::ReopenClosedTab, Command::TogglePin, @@ -46,6 +46,7 @@ const OFFERED: [Command; 29] = [ Command::RemoveFromSplitView, Command::CloseSplit, Command::TabsOnTop, + Command::GlassDesign, Command::Ask, Command::AskPage, Command::ShowHistory, @@ -501,6 +502,10 @@ fn run(ui: Ui, command: Command) { s.toggle_tabs_on_top(); Vec::new() }), + Command::GlassDesign => ui.act(|s| { + s.toggle_glass_design(); + Vec::new() + }), Command::Ask => super::super::assistant::open(ui, false), Command::AskPage => super::super::assistant::open(ui, true), _ => {} diff --git a/nsh-shared/src/appearance.rs b/nsh-shared/src/appearance.rs index 59382ba4..258f6f43 100644 --- a/nsh-shared/src/appearance.rs +++ b/nsh-shared/src/appearance.rs @@ -4,7 +4,7 @@ use std::time::{Duration, SystemTime}; use browser_core::effects::Effect; use browser_core::github::Hop; use browser_core::prefs::{self, ACCENTS, COMPACT, FEATURE_HINTS, REDUCE_MOTION, THEME_ACCENT}; -use browser_core::theme::{self, Origin, Scheme, Selection, Source, ThemeRef}; +use browser_core::theme::{self, Backing, Corners, Origin, Scheme, Selection, Source, ThemeRef}; use browser_core::theme_fetch::{self as fetch, Pending, Release}; use browser_core::theme_library::{self as library, Card}; use nsh_base::input; @@ -31,6 +31,9 @@ pub trait Host: Copy + 'static { fn accent_and_motion(self) -> bool { false } + fn backing(self) -> Backing { + Backing::Opaque + } } #[derive(Clone, Default)] @@ -482,14 +485,52 @@ fn effect_row(pane: Pane) -> View { (name.to_owned(), Box::new(move || effect == stored), Box::new(move || pane.quietly(pane.host.with_store(|s| library::set_effect(s, effect))))) }) .collect(); - view() - .flex_col() - .gap_2() - .px_3() - .py_2() - .child(label("Search bar effect")) - .child(small("Around the search field on the start page.")) - .child(segmented(choices)) + choice_row("Search bar effect", "Around the search field on the start page.", segmented(choices)) +} + +fn choice_row(title: &'static str, about: impl Into, choices: View) -> View { + view().flex_col().gap_2().px_3().py_2().child(label(title)).child(small(about)).child(choices) +} + +fn picks(pane: Pane, current: T, choices: &[(&str, T)], set: fn(&Store, T) -> Result<(), String>) -> View { + segmented( + choices + .iter() + .map(|&(name, value)| -> Segment { + (name.to_owned(), Box::new(move || value == current), Box::new(move || pane.quietly(pane.host.with_store(|s| set(s, value))))) + }) + .collect(), + ) +} + +fn design_group(pane: Pane) -> View { + let host = pane.host; + let backing = host.backing(); + let (on, glass, reached) = host.with_store(|s| { + let active = library::current(s, host.system_light(), host.safe()); + (library::glass_on(s), library::glass_settings(s), library::look(s, &active, host.safe(), backing).transparency) + }); + let about = if backing == Backing::Opaque { + "Glass gives rounder, softer panels." + } else { + "Glass makes the window translucent over your desktop, with rounder, softer panels." + }; + let mut rows = group().child(choice_row("Design", about, picks(pane, on, &[("Classic", false), ("Glass", true)], library::set_glass_on))); + if !on { + return rows; + } + if backing != Backing::Opaque { + let labels = library::TRANSPARENCY_STEPS.map(|v| format!("{v} %")); + let steps: Vec<(&str, u8)> = labels.iter().map(String::as_str).zip(library::TRANSPARENCY_STEPS).collect(); + let note = library::transparency_note(glass.transparency, reached, host.safe()); + rows = rows.child(choice_row("Transparency", note, picks(pane, glass.transparency, &steps, library::set_transparency))); + } + if backing == Backing::Blurred { + let blur = glass.blur; + rows = rows.child(switch_row("Blur behind the window", move || blur, move || pane.quietly(host.with_store(|s| library::set_blur(s, !blur))))); + } + let corners = Corners::ALL.map(|c| (c.label(), c)); + rows.child(choice_row("Corners", "How round panels and cards are.", picks(pane, glass.corners, &corners, library::set_corners))) } fn pending_card(pane: Pane) -> Option { @@ -598,6 +639,7 @@ fn body(pane: Pane) -> View { } else { "Choose a theme to use it." }))); + page = page.child(view().pt_4().pb_2().child(caps_label("Design"))).child(design_group(pane)); if host.accent_and_motion() { page = page.child(view().pt_3().child(group().child(accent_row(pane)))); } diff --git a/nsh-shared/src/panes.rs b/nsh-shared/src/panes.rs index 9a61e73b..a705c6af 100644 --- a/nsh-shared/src/panes.rs +++ b/nsh-shared/src/panes.rs @@ -60,7 +60,9 @@ pub fn words(pane: Pane) -> &'static str { match pane { Pane::Profile => "shield level standard strict lockdown card filter lists site overrides connections default browser", Pane::General => "downloads folders import about version licence source privacy imprint", - Pane::Appearance => "theme dark light match system accent colour color motion reduce toolbar compact density sidebar search bar effect tips", + Pane::Appearance => { + "theme dark light match system accent colour color motion reduce toolbar compact density sidebar search bar effect tips design glass liquid transparency translucent blur corners round" + } Pane::Tabs => "awake sleep memory new tab start page close archive gestures swipe drag tear off temporary full window", Pane::Search => "search engine suggestions history text shortcuts bangs", Pane::Privacy => { From 2cb416c926fb35ccaf15e757c2c013c48982e50c Mon Sep 17 00:00:00 2001 From: rgxdev Date: Wed, 25 Nov 2026 07:10:05 +0100 Subject: [PATCH 3/4] fix(appearance): keep pop-up cards opaque and Classic contrast unchanged in the Glass design Only the window backdrop and the docked sidebar turn translucent; the floating sidebar and pop-up cards, which sit over the page, keep Classic's colours on every client. Classic themes are checked for contrast exactly as before, Glass is checked over a white and a black desktop including the opaque sidebar card, and 300 generated themes are tested through it. Signed-off-by: rgxdev --- crates/app/src/lib.rs | 2 +- crates/app/src/sidebar.rs | 9 +- crates/app/src/themes.rs | 17 +++- crates/browser-core/src/theme.rs | 113 +++++++++++++++-------- crates/browser-core/src/theme_library.rs | 6 +- crates/ui/src/theme.rs | 8 +- linux/src/ui.rs | 6 +- linux/src/ui/peek.rs | 2 +- nsh-shared/src/appearance.rs | 9 +- nsh-shared/src/theme.rs | 7 ++ 10 files changed, 116 insertions(+), 63 deletions(-) diff --git a/crates/app/src/lib.rs b/crates/app/src/lib.rs index a81144f0..9304822a 100644 --- a/crates/app/src/lib.rs +++ b/crates/app/src/lib.rs @@ -446,7 +446,7 @@ impl Browser { }) .on_action(cx.listener(|b, _: &ToggleCompactToolbar, _, cx| b.set_pref(prefs::Pref::CompactToolbar, !b.pref(prefs::Pref::CompactToolbar), cx))) .on_action(cx.listener(|b, _: &ToggleGlassDesign, _, cx| { - let on = b.core.themes.borrow().glass; + let on = browser_core::theme_library::glass_on(&b.core.disk); if let Err(e) = browser_core::theme_library::set_glass_on(&b.core.disk, !on) { b.show_toast_as(browser_core::toast::Tone::Warning, e, None, cx); } diff --git a/crates/app/src/sidebar.rs b/crates/app/src/sidebar.rs index 9e5d8d2c..91ffbc7f 100644 --- a/crates/app/src/sidebar.rs +++ b/crates/app/src/sidebar.rs @@ -214,10 +214,11 @@ fn mix(from: Option, to: Option, t: f32) -> Option { Some(Rgba { r: lerp(a.r, b.r), g: lerp(a.g, b.g), b: lerp(a.b, b.b), a: lerp(a.a, b.a) }) } -fn background(b: &Browser) -> Background { +fn background(b: &Browser, card: bool) -> Background { let tint = |ix: usize| b.model.spaces.get(ix).and_then(space_tint); let (other, shown) = b.slide_other().map_or((None, 0.), |(ix, _, shown)| (tint(ix), shown)); - mix(tint(b.model.space_ix), other, shown).map_or_else(Theme::sidebar, Theme::sidebar_tinted) + mix(tint(b.model.space_ix), other, shown) + .map_or_else(|| if card { Theme::sidebar_solid() } else { Theme::sidebar() }, |tint| Theme::sidebar_tinted(tint, card)) } pub fn group_color(g: &Group) -> Rgba { @@ -363,7 +364,7 @@ pub fn render(b: &mut Browser, cx: &mut Context) -> AnyElement { if !cx.has_active_drag() { b.split_drop = None; } - let bg = background(b); + let bg = background(b, false); content(b, NOTCH_WIDTH + 10., cx) .relative() .w(px(b.sidebar_width)) @@ -411,7 +412,7 @@ fn resize_handle(cx: &mut Context) -> impl IntoElement { /// visible above it. It slides in from the window's left edge and fully back out, fading as it goes. pub fn floating(b: &mut Browser, height: Pixels, closing: bool, cx: &mut Context) -> AnyElement { let width = b.sidebar_width; - let bg = background(b); + let bg = background(b, true); let card = content(b, TILE_GAP + 4., cx) .absolute() .top_0() diff --git a/crates/app/src/themes.rs b/crates/app/src/themes.rs index a85c2f39..117b7487 100644 --- a/crates/app/src/themes.rs +++ b/crates/app/src/themes.rs @@ -13,7 +13,6 @@ pub(crate) struct State { /// Shift was held at launch: the built-in theme shows, without page styles, until quit. pub safe: bool, pub system_light: bool, - /// The Glass design's transparency after the readability limit. pub reached: u8, pub glass: bool, } @@ -36,7 +35,12 @@ pub(crate) fn apply(core: &AppCore, system_light: bool) { let can = if cfg!(target_os = "macos") { browser_core::theme::Backing::Blurred } else { browser_core::theme::Backing::Opaque }; let look = browser_core::theme_library::look(&core.disk, &active, state.safe, can); Theme::set_tokens(look.tokens, p.meta.scheme, p.font.clone()); - BACKING.store(look.window as u8, Ordering::Relaxed); + let backing = match look.window { + browser_core::theme::Backing::Opaque => OPAQUE, + browser_core::theme::Backing::Clear => CLEAR, + browser_core::theme::Backing::Blurred => BLURRED, + }; + BACKING.store(backing, Ordering::Relaxed); state.reached = look.transparency; state.glass = browser_core::theme_library::glass_on(&core.disk); crate::prefs::apply_accent(&core.disk); @@ -44,12 +48,15 @@ pub(crate) fn apply(core: &AppCore, system_light: bool) { state.active = Some(active); } -static BACKING: AtomicU8 = AtomicU8::new(0); +static BACKING: AtomicU8 = AtomicU8::new(OPAQUE); +const OPAQUE: u8 = 0; +const CLEAR: u8 = 1; +const BLURRED: u8 = 2; pub(crate) fn window_background() -> WindowBackgroundAppearance { match BACKING.load(Ordering::Relaxed) { - 1 => WindowBackgroundAppearance::Transparent, - 2 => WindowBackgroundAppearance::Blurred, + CLEAR => WindowBackgroundAppearance::Transparent, + BLURRED => WindowBackgroundAppearance::Blurred, _ => WindowBackgroundAppearance::Opaque, } } diff --git a/crates/browser-core/src/theme.rs b/crates/browser-core/src/theme.rs index 21c303ac..686f99d9 100644 --- a/crates/browser-core/src/theme.rs +++ b/crates/browser-core/src/theme.rs @@ -967,20 +967,37 @@ fn readable(fg: u32, backgrounds: &[u32], floor: f32) -> Option { } impl Tokens { - /// Every background text sits on, over each end of the backdrop drawn opaque and over the - /// black an opaque window clears to. + /// Every background text sits on: opaque over the backdrop, or, in the Glass design, over the + /// backdrop over a white and a black desktop. fn text_backgrounds(&self) -> Vec { - self.text_backgrounds_over(if self.see_through { &[0xffffffff, 0x000000ff] } else { &[0x000000ff] }) + if self.see_through { + return self.text_backgrounds_over_desktops(); + } + let base = self.backdrop.from | 0xff; + self.layers().iter().map(|bg| over(*bg, base)).collect() + } + + /// The sidebar as Classic draws it, for a card over the page, where nothing may show through. + pub fn sidebar_card(&self) -> Gradient { + let s = self.sidebar; + if self.see_through { Gradient { from: s.from | 0xff, to: s.to | 0xff, ..s } } else { s } + } + + fn layers(&self) -> [u32; 9] { + [self.page, self.panel, self.panel_nav, self.panel_row, self.surface, self.sidebar.from, self.sidebar.to, self.backdrop.from, self.backdrop.to] } - fn text_backgrounds_over(&self, desktops: &[u32]) -> Vec { - let layers = - [self.page, self.panel, self.panel_nav, self.panel_row, self.surface, self.sidebar.from, self.sidebar.to, self.backdrop.from, self.backdrop.to]; + /// Over a desktop, plus the opaque sidebar a card over the page paints. + fn text_backgrounds_over_desktops(&self) -> Vec { + let desktops = [0xffffffff, 0x000000ff]; + let layers = self.layers(); let ends = [self.backdrop.from, self.backdrop.to]; let mut bases: Vec = ends.iter().map(|e| e | 0xff).chain(ends.iter().flat_map(|e| desktops.iter().map(move |d| over(*e, *d)))).collect(); bases.sort_unstable(); bases.dedup(); - bases.into_iter().flat_map(|base| layers.map(|bg| over(bg, base))).collect() + let card = self.sidebar_card(); + let cards = [card.from, card.to]; + bases.into_iter().flat_map(|base| layers.map(|bg| over(bg, base))).chain(cards).collect() } /// The accent where it is text or a focus ring: the accent itself while it keeps @@ -1053,8 +1070,9 @@ pub enum Backing { Blurred, } -fn fade(c: u32, alpha: f32) -> u32 { - (over(c, 0x000000ff) & !0xff) | (alpha * 255.).round() as u32 +/// `c` as Classic draws it over `under`, made `alpha` opaque. +fn fade(c: u32, under: u32, alpha: f32) -> u32 { + (over(c, under) & !0xff) | (alpha * 255.).round() as u32 } fn soften(c: u32) -> u32 { @@ -1082,12 +1100,10 @@ pub fn glass(tokens: &Tokens, glass: Glass, can: Backing) -> (Tokens, Backing, u let f = percent as f32 / 100.; let mut c = t; c.see_through = true; - let (backdrop, sidebar, layer) = (1. - 0.70 * f, 1. - 0.75 * f, 1. - 0.14 * f); - c.backdrop = Gradient { from: fade(t.backdrop.from, backdrop), to: fade(t.backdrop.to, backdrop), ..t.backdrop }; - c.sidebar = Gradient { from: fade(t.sidebar.from, sidebar), to: fade(t.sidebar.to, sidebar), ..t.sidebar }; - for slot in [&mut c.panel, &mut c.surface] { - *slot = fade(*slot, layer); - } + let (backdrop, sidebar) = (1. - 0.70 * f, 1. - 0.75 * f); + let (from, to) = (over(t.backdrop.from, 0x000000ff), over(t.backdrop.to, 0x000000ff)); + c.backdrop = Gradient { from: fade(from, from, backdrop), to: fade(to, to, backdrop), ..t.backdrop }; + c.sidebar = Gradient { from: fade(t.sidebar.from, from, sidebar), to: fade(t.sidebar.to, to, sidebar), ..t.sidebar }; let backgrounds = c.text_backgrounds(); let readable_text = FLOORS.iter().try_for_each(|(name, floor)| { let slot = text_slot(&mut c, name); @@ -1529,30 +1545,55 @@ mod tests { #[test] fn glass_keeps_text_readable_over_any_desktop_at_every_transparency() { for (id, _) in BUILT_IN { - let classic = built_in_tokens(id); - for transparency in [0, 50, 100] { - for blur in [false, true] { - for can in [Backing::Clear, Backing::Blurred] { - let (mut t, backing, effective) = glass(&classic, Glass { transparency, blur, corners: Corners::Round }, can); - assert!(effective <= transparency, "{id}"); - if effective == 0 { - assert!(backing == Backing::Opaque && !t.see_through, "{id}"); - assert_eq!((t.text, t.backdrop, t.panel), (classic.text, classic.backdrop, classic.panel), "{id}"); - continue; - } - assert!(t.see_through, "{id}"); - assert_eq!(backing, if blur && can == Backing::Blurred { Backing::Blurred } else { Backing::Clear }); - let backgrounds = t.text_backgrounds(); - for (name, floor) in FLOORS { - let text = *text_slot(&mut t, name); - for bg in &backgrounds { - assert!(contrast(text, *bg) >= floor, "{id} {name} on {bg:08x} at {effective}"); - } - } + assert_glass_readable(&built_in_tokens(id), id); + } + } + + #[test] + fn glass_keeps_text_readable_for_generated_themes() { + let mut seed = 0x9e3779b97f4a7c15u64; + let mut next = || { + seed ^= seed << 13; + seed ^= seed >> 7; + seed ^= seed << 17; + (seed as u32) | 0xff + }; + for ix in 0..300 { + let mut t = if ix % 2 == 0 { Tokens::DARK } else { Tokens::LIGHT }; + for slot in [&mut t.text, &mut t.muted, &mut t.faint, &mut t.space_label, &mut t.accent, &mut t.page, &mut t.panel, &mut t.surface] { + *slot = next(); + } + t.backdrop = Gradient { from: next(), to: next() & 0xffffff80 | 0x40, ..t.backdrop }; + t.sidebar = Gradient { from: next() & 0xffffff00 | 0x90, to: next(), ..t.sidebar }; + enforce_contrast(&mut t, if ix % 2 == 0 { Scheme::Dark } else { Scheme::Light }); + assert_glass_readable(&t, &format!("generated {ix}")); + } + } + + fn assert_glass_readable(classic: &Tokens, id: &str) { + for transparency in [0, 50, 100] { + for blur in [false, true] { + for can in [Backing::Clear, Backing::Blurred] { + let (mut t, backing, effective) = glass(classic, Glass { transparency, blur, corners: Corners::Round }, can); + assert!(effective <= transparency, "{id}"); + assert_eq!((t.panel, t.surface), (classic.panel, classic.surface), "{id}: pop-up cards stay as Classic draws them"); + if effective == 0 { + assert!(backing == Backing::Opaque && !t.see_through, "{id}"); + assert_eq!((t.text, t.backdrop), (classic.text, classic.backdrop), "{id}"); + continue; + } + assert!(t.see_through, "{id}"); + assert_eq!(backing, if blur && can == Backing::Blurred { Backing::Blurred } else { Backing::Clear }); + let backgrounds = t.text_backgrounds(); + for (name, floor) in FLOORS { + let text = *text_slot(&mut t, name); for bg in &backgrounds { - assert!(contrast(t.accent_text(), *bg) >= ACCENT_TEXT_FLOOR, "{id} accent on {bg:08x}"); + assert!(contrast(text, *bg) >= floor, "{id} {name} on {bg:08x} at {effective}"); } } + for bg in &backgrounds { + assert!(contrast(t.accent_text(), *bg) >= ACCENT_TEXT_FLOOR, "{id} accent on {bg:08x}"); + } } } } diff --git a/crates/browser-core/src/theme_library.rs b/crates/browser-core/src/theme_library.rs index f2c48338..8473dcae 100644 --- a/crates/browser-core/src/theme_library.rs +++ b/crates/browser-core/src/theme_library.rs @@ -79,7 +79,6 @@ pub fn set_effect(store: &Store, effect: Option) -> Result<(), String> { store.set_setting(SEARCH_EFFECT_SETTING, effect.map_or("theme", Effect::name)).map_err(|e| e.to_string()) } -/// How the shell is drawn: the theme's tokens, how the window is backed and the transparency reached. #[derive(Clone, Copy, Debug, PartialEq)] pub struct Look { pub tokens: Tokens, @@ -104,14 +103,12 @@ pub fn glass_settings(store: &Store) -> Glass { } } -/// The transparency choices offered in settings. pub const TRANSPARENCY_STEPS: [u8; 5] = [20, 40, 60, 80, 100]; -/// What settings say under the transparency choices once `reached` is known. pub fn transparency_note(requested: u8, reached: u8, safe: bool) -> String { match reached { _ if safe => "Safe mode keeps the window opaque until Tarn restarts.".to_owned(), - 0 => "This theme's text cannot stay readable over the desktop, so the window stays opaque.".to_owned(), + 0 if requested > 0 => "This theme's text cannot stay readable over the desktop, so the window stays opaque.".to_owned(), r if r < requested => format!("Held at {r} % so text stays readable on light and dark desktops."), _ => "How much of the desktop shows through.".to_owned(), } @@ -464,6 +461,7 @@ mod tests { fn the_transparency_note_names_why_it_was_held() { assert!(transparency_note(60, 0, true).starts_with("Safe mode")); assert!(transparency_note(60, 0, false).contains("stays opaque")); + assert_eq!(transparency_note(0, 0, false), "How much of the desktop shows through."); assert!(transparency_note(80, 40, false).starts_with("Held at 40 %")); assert_eq!(transparency_note(60, 60, false), "How much of the desktop shows through."); } diff --git a/crates/ui/src/theme.rs b/crates/ui/src/theme.rs index 0dd743a3..792559c8 100644 --- a/crates/ui/src/theme.rs +++ b/crates/ui/src/theme.rs @@ -100,14 +100,18 @@ impl Theme { pub fn sidebar() -> Background { get(|t| gradient(t.sidebar)) } + /// The sidebar as Classic draws it, for a card over the page, where nothing may show through. + pub fn sidebar_solid() -> Background { + get(|t| gradient(t.sidebar_card())) + } /// The sidebar gradient washed with a space's colour, kept close to the theme so text keeps /// its contrast; the tint's alpha scales the wash. - pub fn sidebar_tinted(tint: Rgba) -> Background { + pub fn sidebar_tinted(tint: Rgba, solid_card: bool) -> Background { let mix = |base: u32, t: f32| { let (base, t) = (rgba(base), t * tint.a); Rgba { r: base.r + (tint.r - base.r) * t, g: base.g + (tint.g - base.g) * t, b: base.b + (tint.b - base.b) * t, a: base.a } }; - let g = get(|t| t.sidebar); + let g = get(|t| if solid_card { t.sidebar_card() } else { t.sidebar }); linear_gradient(g.angle, linear_color_stop(mix(g.from, 0.12), 0.), linear_color_stop(mix(g.to, 0.2), 1.)) } pub fn sidebar_edge() -> Rgba { diff --git a/linux/src/ui.rs b/linux/src/ui.rs index 81b6f717..f86be66c 100644 --- a/linux/src/ui.rs +++ b/linux/src/ui.rs @@ -1096,7 +1096,7 @@ fn new_tab_row(ui: Ui) -> View { view().flex_row().items_center().mb_1().child(new).child(icon_button(icons::ELLIPSIS, browser_core::sidebar::ORGANIZE, move || show(ui, Panel::Organize))) } -fn sidebar(ui: Ui) -> View { +fn sidebar(ui: Ui, card: bool) -> View { let settings = icon_button(icons::GEAR, "Settings", move || show(ui, Panel::Settings)); let header = view().flex_row().items_center().gap_1().h(px(TOOLBAR_HEIGHT - 8.)).pl_1().child(space_switcher(ui)).child(downloads_button(ui)).child(settings); @@ -1115,7 +1115,7 @@ fn sidebar(ui: Ui) -> View { .w(px(SIDEBAR_WIDTH)) .p_1() .rounded(px(Theme::radius_tile())) - .paint(Theme::sidebar()) + .paint(if card { Theme::sidebar_solid() } else { Theme::sidebar() }) .border_1() .border_color(Theme::sidebar_edge()) .shadow(Theme::elevation(10., 30.)) @@ -3174,7 +3174,7 @@ fn browser_window(ui: Ui) -> AnyElement { } peek::window_height(ui, b.size.height.0); }) - .child(when(move || ui.sidebar.get() && !full.get(), move || themed(move || sidebar(ui)))) + .child(when(move || ui.sidebar.get() && !full.get(), move || themed(move || sidebar(ui, false)))) .child( view() .flex_col() diff --git a/linux/src/ui/peek.rs b/linux/src/ui/peek.rs index ffe9553f..e718656b 100644 --- a/linux/src/ui/peek.rs +++ b/linux/src/ui/peek.rs @@ -133,7 +133,7 @@ pub(super) fn floating(ui: Ui) -> AnyElement { .flex_col() .on_mouse_enter(move |_: &MouseEvent| card_hovered(ui, true)) .on_mouse_leave(move |_: &MouseEvent| card_hovered(ui, false)) - .child(themed(move || sidebar(ui).flex_1())) + .child(themed(move || sidebar(ui, true).flex_1())) }) }) } diff --git a/nsh-shared/src/appearance.rs b/nsh-shared/src/appearance.rs index 258f6f43..9b147861 100644 --- a/nsh-shared/src/appearance.rs +++ b/nsh-shared/src/appearance.rs @@ -479,13 +479,8 @@ const MOTION_NOTE: &str = "Pop-ups, cards, tabs and the sidebar appear without a fn effect_row(pane: Pane) -> View { let stored = pane.host.with_store(library::chosen_effect); - let choices: Vec = std::iter::once((None, "Theme")) - .chain(Effect::ALL.map(|e| (Some(e), e.label()))) - .map(|(effect, name)| -> Segment { - (name.to_owned(), Box::new(move || effect == stored), Box::new(move || pane.quietly(pane.host.with_store(|s| library::set_effect(s, effect))))) - }) - .collect(); - choice_row("Search bar effect", "Around the search field on the start page.", segmented(choices)) + let choices: Vec<(&str, Option)> = std::iter::once(("Theme", None)).chain(Effect::ALL.map(|e| (e.label(), Some(e)))).collect(); + choice_row("Search bar effect", "Around the search field on the start page.", picks(pane, stored, &choices, library::set_effect)) } fn choice_row(title: &'static str, about: impl Into, choices: View) -> View { diff --git a/nsh-shared/src/theme.rs b/nsh-shared/src/theme.rs index 9c9c92c3..29de928d 100644 --- a/nsh-shared/src/theme.rs +++ b/nsh-shared/src/theme.rs @@ -133,6 +133,13 @@ impl Theme { pub fn sidebar() -> Gradient { get(|t| gradient(t.sidebar.angle, t.sidebar.from, t.sidebar.to)) } + /// The sidebar as Classic draws it, for a card over the page, where nothing may show through. + pub fn sidebar_solid() -> Gradient { + get(|t| { + let card = t.sidebar_card(); + gradient(card.angle, card.from, card.to) + }) + } pub fn sidebar_tinted(tint: Rgba) -> Gradient { let mix = |base: u32, t: f32| { let (base, t) = (rgba(base), t * tint.a); From 314038846375abc58fe2b6d2b7e9ccbb40feb1c8 Mon Sep 17 00:00:00 2001 From: rgxdev Date: Wed, 25 Nov 2026 07:24:57 +0100 Subject: [PATCH 4/4] fix(appearance): check Glass text against the bare backdrop over the desktop Text such as the toolbar's sits straight on the window backdrop, so each backdrop over a white and a black desktop is now a checked background itself, not only the layers drawn over it. Transparency is held back further where that needs it; Tarn's dark theme now stops at 20 %. Signed-off-by: rgxdev --- crates/browser-core/src/theme.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/browser-core/src/theme.rs b/crates/browser-core/src/theme.rs index 686f99d9..38760a71 100644 --- a/crates/browser-core/src/theme.rs +++ b/crates/browser-core/src/theme.rs @@ -997,7 +997,7 @@ impl Tokens { bases.dedup(); let card = self.sidebar_card(); let cards = [card.from, card.to]; - bases.into_iter().flat_map(|base| layers.map(|bg| over(bg, base))).chain(cards).collect() + bases.iter().copied().chain(bases.iter().flat_map(|base| layers.map(|bg| over(bg, *base)))).chain(cards).collect() } /// The accent where it is text or a focus ring: the accent itself while it keeps @@ -1570,6 +1570,15 @@ mod tests { } } + #[test] + fn glass_checks_text_on_the_bare_backdrop_over_a_light_desktop() { + let black = Gradient { from: 0x000000ff, to: 0x000000ff, ..Tokens::DARK.backdrop }; + let classic = Tokens { backdrop: black, sidebar: black, text: 0xffffffff, ..Tokens::DARK }; + let (t, _, effective) = glass(&classic, Glass { transparency: 100, ..Glass::default() }, Backing::Blurred); + assert!(effective > 0); + assert!(contrast(t.text, over(t.backdrop.from, 0xffffffff)) >= 4.5, "white text on the backdrop over a white desktop at {effective}"); + } + fn assert_glass_readable(classic: &Tokens, id: &str) { for transparency in [0, 50, 100] { for blur in [false, true] { @@ -1624,7 +1633,7 @@ mod tests { fn tarn_dark_stays_see_through_at_full_transparency() { let (_, backing, effective) = glass(&Tokens::DARK, Glass { transparency: 100, blur: true, corners: Corners::Round }, Backing::Blurred); assert_eq!(backing, Backing::Blurred); - assert!(effective >= 40, "{effective}"); + assert!(effective >= 20, "{effective}"); } #[test]