diff --git a/apps/desktop/src/App.tsx b/apps/desktop/src/App.tsx index af4b07607..709e39b6b 100644 --- a/apps/desktop/src/App.tsx +++ b/apps/desktop/src/App.tsx @@ -13,7 +13,11 @@ import { import { rememberFocus } from "./lib/focusAreas"; import { matchWindowTheme } from "./lib/material"; import { applyTheme, resolveTheme } from "./lib/themes"; -import { paintTransparency, setUserReduceTransparency } from "./lib/transparency"; +import { + paintBlurAfterAppStylesheet, + paintTransparency, + setUserReduceTransparency, +} from "./lib/transparency"; import { restoreZoom } from "./lib/zoom"; import { startDeepLinks } from "./state/deepLinks"; import { sessionsListed } from "./state/engine"; @@ -72,6 +76,7 @@ function useTheme() { document.documentElement.dataset.chatWidth = s.chatWidth; setUserReduceTransparency(s.reduceTransparency); paintTransparency(s.transparency); + paintBlurAfterAppStylesheet(s.glassBlur); }; paint(); media.addEventListener("change", paint); @@ -84,6 +89,7 @@ function useTheme() { s.textSize !== prev.textSize || s.reduceTransparency !== prev.reduceTransparency || s.transparency !== prev.transparency || + s.glassBlur !== prev.glassBlur || s.chatWidth !== prev.chatWidth ) paint(); diff --git a/apps/desktop/src/lib/transparency.test.ts b/apps/desktop/src/lib/transparency.test.ts index 1b7e5d6e6..05b1e4613 100644 --- a/apps/desktop/src/lib/transparency.test.ts +++ b/apps/desktop/src/lib/transparency.test.ts @@ -1,5 +1,5 @@ import { expect, test } from "bun:test"; -import { canBlur, reducesTransparency } from "./transparency"; +import { BLUR_MAX, blurRule, canBlur, reducesTransparency } from "./transparency"; const none = { user: false, system: false, media: false, blur: true }; @@ -23,3 +23,13 @@ test("the glass blurs only where the web view has the filter and composites it", expect(canBlur(false, true)).toBe(false); expect(canBlur(false, false)).toBe(false); }); + +test("the blur rule writes a literal filter for both properties, kept to the slider's range", () => { + const rule = blurRule(14); + expect(rule).toContain("backdrop-filter: saturate(1.15) blur(14px);"); + expect(rule).toContain("-webkit-backdrop-filter: saturate(1.15) blur(14px);"); + expect(rule).not.toContain("var("); + expect(rule).toContain(":not(.reduce-transparency"); + expect(blurRule(-3)).toContain("blur(0px)"); + expect(blurRule(999)).toContain(`blur(${BLUR_MAX}px)`); +}); diff --git a/apps/desktop/src/lib/transparency.ts b/apps/desktop/src/lib/transparency.ts index a46fb1e3d..885eae5dd 100644 --- a/apps/desktop/src/lib/transparency.ts +++ b/apps/desktop/src/lib/transparency.ts @@ -90,7 +90,7 @@ export function installReduceTransparency() { /** Settings › Appearance › Transparency, in percent: how much of the sidebar and the glass shows. */ export const TRANSPARENCY_MIN = 0; -export const TRANSPARENCY_MAX = 60; +export const TRANSPARENCY_MAX = 100; /** Sets `--rc-transparency` on (index.css), kept to the slider's range. */ export function paintTransparency(percent: number) { @@ -98,3 +98,32 @@ export function paintTransparency(percent: number) { const value = Math.min(TRANSPARENCY_MAX, Math.max(TRANSPARENCY_MIN, Math.round(percent))); document.documentElement.style.setProperty("--rc-transparency", `${value}%`); } + +export const BLUR_MIN = 0; +export const BLUR_MAX = 40; + +const GLASS_SURFACES = + ".rc-glass, .rc-glass-faint, .rc-glass-overlay, .rc-composer, .rc-composer-card, .rc-toast, " + + ".rc-composer-footer, .rc-scrim, .rc-lightbox-scrim, .elevated, .glass-filter"; + +export function blurRule(px: number): string { + const value = Math.min(BLUR_MAX, Math.max(BLUR_MIN, Math.round(px))); + const literalFilterForWebKit = `saturate(1.15) blur(${value}px)`; + const rootUnlessSolid = + ':root:not(.reduce-transparency, [data-platform="windows"], [data-platform="linux"])'; + return ( + `${rootUnlessSolid} :is(${GLASS_SURFACES}), ${rootUnlessSolid} .rc-header-glass::before ` + + `{ backdrop-filter: ${literalFilterForWebKit}; -webkit-backdrop-filter: ${literalFilterForWebKit}; }` + ); +} + +export function paintBlurAfterAppStylesheet(px: number) { + if (typeof document === "undefined") return; + let style = document.getElementById("rc-glass-blur"); + if (!style) { + style = document.createElement("style"); + style.id = "rc-glass-blur"; + } + document.head.appendChild(style); + style.textContent = blurRule(px); +} diff --git a/apps/desktop/src/main.tsx b/apps/desktop/src/main.tsx index a444a3882..cb10772af 100644 --- a/apps/desktop/src/main.tsx +++ b/apps/desktop/src/main.tsx @@ -11,6 +11,7 @@ import { quietNativeChrome } from "./lib/quietNative"; import { applyCachedTheme } from "./lib/themes"; import { installReduceTransparency, + paintBlurAfterAppStylesheet, paintTransparency, setSystemReduceTransparency, setUserReduceTransparency, @@ -32,6 +33,7 @@ applyCachedTheme(); installReduceTransparency(); setUserReduceTransparency(store.useApp.getState().reduceTransparency); paintTransparency(store.useApp.getState().transparency); +paintBlurAfterAppStylesheet(store.useApp.getState().glassBlur); // The window's material shows through the sidebar where there is one (macOS; lib/material.ts). applyMaterial(platform); diff --git a/apps/desktop/src/state/appState.ts b/apps/desktop/src/state/appState.ts index 5b87e95db..8a4a4be9e 100644 --- a/apps/desktop/src/state/appState.ts +++ b/apps/desktop/src/state/appState.ts @@ -321,6 +321,8 @@ export interface AppState { reduceTransparency: boolean; /** How much of the sidebar and the glass shows through, in percent (Settings › Appearance). */ transparency: number; + /** How strongly the glass blurs what is behind it, in pixels (Settings › Appearance). */ + glassBlur: number; /** How wide the chat lane grows, transcript and composer alike (Settings › Chat). */ chatWidth: ChatWidth; /** A turn shows its tool calls (Settings › Chat); off, only its "Worked for" line and the reply. */ @@ -485,6 +487,7 @@ export const STORAGE = { animateStreaming: "rustcode.animateStreaming", reduceTransparency: "rustcode.reduceTransparency", transparency: "rustcode.transparency", + glassBlur: "rustcode.glassBlur", chatWidth: "rustcode.chatWidth", showToolCalls: "rustcode.showToolCalls", headerButtons: "rustcode.headerButtons", @@ -530,6 +533,7 @@ export const SETTINGS_DEFAULTS = { animateStreaming: true, reduceTransparency: false, transparency: 28, + glassBlur: 9, chatWidth: CHAT_WIDTH_DEFAULT, showToolCalls: true, headerButtons: DEFAULT_HEADER_BUTTONS, @@ -567,9 +571,14 @@ function storedNumber(key: string, fallback: number, min: number, max: number): return Math.min(max, Math.max(min, n)); } -/** Settings › Appearance › Transparency, kept to the slider's 0..60. */ +/** Settings › Appearance › Transparency, kept to the slider's 0..100. */ export function storedTransparency(): number { - return storedNumber(STORAGE.transparency, SETTINGS_DEFAULTS.transparency, 0, 60); + return storedNumber(STORAGE.transparency, SETTINGS_DEFAULTS.transparency, 0, 100); +} + +/** Settings › Appearance › Blur, kept to the slider's 0..40 pixels. */ +export function storedGlassBlur(): number { + return storedNumber(STORAGE.glassBlur, SETTINGS_DEFAULTS.glassBlur, 0, 40); } /** A thread's own delegate limit, kept to 2..32. */ diff --git a/apps/desktop/src/state/settingsActions.ts b/apps/desktop/src/state/settingsActions.ts index 4f4f89432..5c9759706 100644 --- a/apps/desktop/src/state/settingsActions.ts +++ b/apps/desktop/src/state/settingsActions.ts @@ -166,6 +166,11 @@ export function setTransparency(percent: number) { store(STORAGE.transparency, String(percent)); } +export function setGlassBlur(px: number) { + set({ glassBlur: px }); + store(STORAGE.glassBlur, String(px)); +} + export function setChatWidth(width: ChatWidth) { set({ chatWidth: width }); store(STORAGE.chatWidth, width); diff --git a/apps/desktop/src/state/store.ts b/apps/desktop/src/state/store.ts index 24259bf6f..5019838c4 100644 --- a/apps/desktop/src/state/store.ts +++ b/apps/desktop/src/state/store.ts @@ -25,6 +25,7 @@ import { store, stored, storedFlag, + storedGlassBlur, storedJson, storedThreadLimit, storedTransparency, @@ -486,6 +487,7 @@ export const useApp = create((_set, _get, api) => ({ animateStreaming: storedFlag(STORAGE.animateStreaming, SETTINGS_DEFAULTS.animateStreaming), reduceTransparency: storedFlag(STORAGE.reduceTransparency, SETTINGS_DEFAULTS.reduceTransparency), transparency: storedTransparency(), + glassBlur: storedGlassBlur(), chatWidth: parseChatWidth(stored(STORAGE.chatWidth)), showToolCalls: storedFlag(STORAGE.showToolCalls, SETTINGS_DEFAULTS.showToolCalls), headerButtons: sanitizeHeaderButtons(storedJson(STORAGE.headerButtons, null)), diff --git a/apps/desktop/src/ui/SettingsAppearance.tsx b/apps/desktop/src/ui/SettingsAppearance.tsx index 154390bb8..86ff98ca8 100644 --- a/apps/desktop/src/ui/SettingsAppearance.tsx +++ b/apps/desktop/src/ui/SettingsAppearance.tsx @@ -4,7 +4,7 @@ import { dirname } from "../lib/paths"; import { appPlatform, paintsBlur } from "../lib/platform"; import { hasShell } from "../lib/shell"; import { BUILTIN_THEMES, cssName, type Theme, TOKENS } from "../lib/themes"; -import { TRANSPARENCY_MAX, TRANSPARENCY_MIN } from "../lib/transparency"; +import { BLUR_MAX, BLUR_MIN, TRANSPARENCY_MAX, TRANSPARENCY_MIN } from "../lib/transparency"; import { getZoom, stepZoom, subscribeZoom, ZOOM_DEFAULT, ZOOM_MAX, ZOOM_MIN, zoomLabel } from "../lib/zoom"; import { createTheme, @@ -12,6 +12,7 @@ import { setActiveTheme, setAnimateStreaming, setFont, + setGlassBlur, setReduceTransparency, setTextSize, setTheme, @@ -184,6 +185,7 @@ export function AppearancePage() { const animateStreaming = useApp((s) => s.animateStreaming); const reduceTransparency = useApp((s) => s.reduceTransparency); const transparency = useApp((s) => s.transparency); + const glassBlur = useApp((s) => s.glassBlur); const active = useApp((s) => s.themeActive); const snapshot = useApp((s) => s.themes); const supported = useApp((s) => s.features.themes); @@ -292,6 +294,28 @@ export function AppearancePage() { /> )} + {paintsBlur() && ( + setGlassBlur(SETTINGS_DEFAULTS.glassBlur) + : undefined + } + subtitle="How strongly the composer and menus blur what is behind them." + hint={reduceTransparency ? "Reduce transparency is on, so nothing is blurred." : undefined} + > + + + )} diff --git a/apps/desktop/src/ui/settingsIndex.ts b/apps/desktop/src/ui/settingsIndex.ts index e1f9f72ba..e15a5469e 100644 --- a/apps/desktop/src/ui/settingsIndex.ts +++ b/apps/desktop/src/ui/settingsIndex.ts @@ -382,6 +382,16 @@ export const SETTINGS_INDEX: SettingEntry[] = [ title: "Reduce transparency", keywords: "glass blur frosted translucent solid mica acrylic vibrancy accessibility contrast", }, + { + section: "appearance", + title: "Transparency", + keywords: "opacity see through translucent glass sidebar window alpha", + }, + { + section: "appearance", + title: "Blur", + keywords: "glass frosted backdrop blur radius pixels softness", + }, { section: "appearance", title: "Theme",