Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion apps/desktop/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down
12 changes: 11 additions & 1 deletion apps/desktop/src/lib/transparency.test.ts
Original file line number Diff line number Diff line change
@@ -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 };

Expand All @@ -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)`);
});
31 changes: 30 additions & 1 deletion apps/desktop/src/lib/transparency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,40 @@ 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 <html> (index.css), kept to the slider's range. */
export function paintTransparency(percent: number) {
if (typeof document === "undefined") return;
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);
}
2 changes: 2 additions & 0 deletions apps/desktop/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { quietNativeChrome } from "./lib/quietNative";
import { applyCachedTheme } from "./lib/themes";
import {
installReduceTransparency,
paintBlurAfterAppStylesheet,
paintTransparency,
setSystemReduceTransparency,
setUserReduceTransparency,
Expand All @@ -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);
Expand Down
13 changes: 11 additions & 2 deletions apps/desktop/src/state/appState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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. */
Expand Down
5 changes: 5 additions & 0 deletions apps/desktop/src/state/settingsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/state/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
store,
stored,
storedFlag,
storedGlassBlur,
storedJson,
storedThreadLimit,
storedTransparency,
Expand Down Expand Up @@ -486,6 +487,7 @@ export const useApp = create<AppState>((_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<unknown>(STORAGE.headerButtons, null)),
Expand Down
26 changes: 25 additions & 1 deletion apps/desktop/src/ui/SettingsAppearance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ 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,
SETTINGS_DEFAULTS,
setActiveTheme,
setAnimateStreaming,
setFont,
setGlassBlur,
setReduceTransparency,
setTextSize,
setTheme,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -292,6 +294,28 @@ export function AppearancePage() {
/>
</Row>
)}
{paintsBlur() && (
<Row
title="Blur"
reset={
glassBlur !== SETTINGS_DEFAULTS.glassBlur
? () => 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}
>
<Slider
label="Blur"
value={glassBlur}
min={BLUR_MIN}
max={BLUR_MAX}
step={1}
unit="px"
onChange={setGlassBlur}
/>
</Row>
)}
<SidebarDensitySetting />
<SidebarToolbarSetting />
<SettleAfterSetting />
Expand Down
10 changes: 10 additions & 0 deletions apps/desktop/src/ui/settingsIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down