zen: register the theme sheet at agent level

As a user sheet it sorted below userChrome.css and lost every !important to
the copy parsed at startup. Agent sheets sort above ua.css; @-moz-document
keeps that origin off web pages.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
rope 2026-08-31 20:18:32 +01:00
parent d9604900e3
commit 0e980586d0
2 changed files with 25 additions and 14 deletions

View file

@ -5,17 +5,18 @@ let
# startup — the only scriptable way into chrome, since Gecko has no reload # startup — the only scriptable way into chrome, since Gecko has no reload
# for userChrome.css and Zen exposes no command for one. # for userChrome.css and Zen exposes no command for one.
# #
# So don't use userChrome.css at all for the wallpaper theme. Register # So register <profile>/chrome/zen-theme.css as a style sheet here and
# <profile>/chrome/zen-theme.css as a style-sheet-service USER_SHEET here # re-register it under a cache-busting URI whenever its mtime moves — that is
# and re-register it under a cache-busting URI whenever its mtime moves — # what makes a `theme-apply` switch land in a running Zen (settings/theming.nix
# that is what makes a `theme-apply` switch land in a running Zen # writes that file on every switch).
# (settings/theming.nix writes that file on every switch).
# #
# theming.nix still writes userChrome.css too, so a broken watcher costs the # AGENT_SHEET, not USER_SHEET. theming.nix still writes userChrome.css as the
# live update and nothing else. Whether the watcher can win at all is the # startup floor, and nsIStyleSheetService orders its user sheets BEFORE the
# open question: nsIStyleSheetService documents its user sheets as ordered # profile's userChrome.css — so as a user sheet ours registered fine and then
# BEFORE the profile's userChrome.css, which would let the startup copy # lost every `!important` to the copy parsed at startup, which is precisely a
# outrank every sheet we register. # theme frozen at launch. Agent sheets sort above ua.css, so agent-origin
# !important outranks it. theming.nix wraps this file in @-moz-document to
# keep that agent origin off web pages.
# #
# Everything here goes through Components.classes rather than `Services`, # Everything here goes through Components.classes rather than `Services`,
# which is not a global in this scope. # which is not a global in this scope.
@ -71,11 +72,11 @@ let
// A fresh query string dodges the CSS loader's per-URI cache; without // A fresh query string dodges the CSS loader's per-URI cache; without
// it a re-register would hand back the sheet parsed at startup. // it a re-register would hand back the sheet parsed at startup.
const base = io.newFileURI(file).spec; const base = io.newFileURI(file).spec;
sss.loadAndRegisterSheet(io.newURI(base + "?" + stamp), sss.USER_SHEET); sss.loadAndRegisterSheet(io.newURI(base + "?" + stamp), sss.AGENT_SHEET);
if (live !== null) { if (live !== null) {
const old = io.newURI(base + "?" + live); const old = io.newURI(base + "?" + live);
if (sss.sheetRegistered(old, sss.USER_SHEET)) if (sss.sheetRegistered(old, sss.AGENT_SHEET))
sss.unregisterSheet(old, sss.USER_SHEET); sss.unregisterSheet(old, sss.AGENT_SHEET);
} }
live = stamp; live = stamp;
note("ok " + stamp); note("ok " + stamp);

View file

@ -532,7 +532,17 @@ let
# userChrome.css the result is the old behaviour — themed on next launch — # userChrome.css the result is the old behaviour — themed on next launch —
# never an unthemed browser. # never an unthemed browser.
install -Dm644 "$theme/zen.css" "$HOME/${zenChrome}/userChrome.css" install -Dm644 "$theme/zen.css" "$HOME/${zenChrome}/userChrome.css"
install -Dm644 "$theme/zen.css" "$HOME/${zenChrome}/zen-theme.css" # Same CSS again, at agent level via the watcher in apps/zen.nix, which is
# the copy that actually changes a running window — a user-level sheet is
# ordered below userChrome.css and loses every !important to it. Agent
# origin applies to web pages too, hence the @-moz-document scope; the
# startup copy above stays unwrapped so it survives even if that syntax is
# ever dropped for user sheets.
{
echo '@-moz-document url-prefix(chrome://) {'
cat "$theme/zen.css"
echo '}'
} > "$HOME/${zenChrome}/zen-theme.css"
# Icon theme: replace the directory contents (cheap — the tree is # Icon theme: replace the directory contents (cheap — the tree is
# symlinks into the papirus store path) so GTK's icon-theme monitor sees # symlinks into the papirus store path) so GTK's icon-theme monitor sees