Skip to content
Open
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
76 changes: 76 additions & 0 deletions firefox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Firefox

Themes the Firefox browser chrome (toolbar, tabs, URL bar, menus, sidebar) and the
built-in `about:` pages with the Noctalia palette, using Firefox's native
`userChrome.css` / `userContent.css` mechanism. No extension required.

> Firefox can also be themed through the Pywalfox extension — see the community
> templates `pywalfox` and `pywalfox-beta4` for that approach. This template is
> a drop-in CSS-only alternative; they can coexist, but you only need one.

## What it themes

- **Browser chrome** (`firefox-userChrome.css`): tab bar, navigation toolbar,
URL bar and its results, bookmarks bar, sidebar, find bar, menus/panels,
context menus, dialogs, autocomplete popups, download panel, select dropdowns.
- **Content pages** (`firefox-userContent.css`): `about:newtab` / `about:home`,
`about:preferences` and its sub-dialogs, `about:addons`, `about:logins`,
`about:protections`, `about:config`, `about:profiles`, and more.

Both dark and light variants are generated, and Firefox switches between them
automatically via `prefers-color-scheme`.

## Setup

When the Noctalia theming script runs, it automatically:

1. Finds Firefox profiles by locating their `prefs.js` files, in:
- `~/.mozilla/firefox` (regular installs)
- `~/.var/app/org.mozilla.firefox/.mozilla/firefox` (Flatpak)
- `~/snap/firefox/common/.mozilla/firefox` (Snap)
2. Creates each profile's `chrome/` directory when necessary.
3. Adds the Noctalia imports to `userChrome.css` and `userContent.css`.
4. Enables the required preferences through the profile's `user.js`:
- `toolkit.legacyUserProfileCustomizations.stylesheets` — load `userChrome.css`
- `svg.context-properties.content.enabled` — colored icons on `about:` pages
- `devtools.chrome.enabled` — browser chrome debugging

No manual changes in `about:config` are required.

## Set website appearance

Open **Settings → Appearance** and set **Website Appearance** to **Auto**.
This lets websites (and the browser) follow the color scheme generated by Noctalia.

## Apply changes

**Restart Firefox** after the initial setup. A restart may also be required
after color changes for the updated theme to appear.

## Troubleshooting

- **Theme not appearing:** make sure the template is enabled in
Noctalia (Settings → Templates), then re-apply your theme and restart Firefox.
- **Some colors look wrong:** extensions that restyle the browser UI (e.g. a
competing theme or a dark-mode forcing add-on) can override template colors.
Disable them, then restart Firefox.
- **Only some profiles are themed:** the hook updates every profile it finds
under the paths above. Profiles stored in a custom location are not touched.
- **Changes not appearing after a palette change:** Firefox may cache `userChrome.css`;
restarting the browser picks up the new render.

## Removing the theme

Disable the template in Noctalia, delete the `@import "…firefox-userChrome.css";` /
`@import "…firefox-userContent.css";` lines from each profile's `userChrome.css` /
`userContent.css`, and remove the preferences added by this template from `user.js`
(or delete those files if you never customized them).

## Files

| File | Purpose |
| --- | --- |
| `template.toml` | Noctalia manifest (renders both CSS files, runs `apply.sh`) |
| `apply.sh` | Finds profiles, wires up imports and preferences (idempotent) |
| `firefox-userChrome.css` | Browser chrome theme |
| `firefox-userContent.css` | `about:` pages theme |
Binary file added firefox/about-preferences-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions firefox/apply.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bash
set -euo pipefail

cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}"
css_chrome="$cache_dir/noctalia/firefox/firefox-userChrome.css"
css_content="$cache_dir/noctalia/firefox/firefox-userContent.css"
line_chrome="@import \"$css_chrome\";"
line_content="@import \"$css_content\";"

write_if_changed() {
local target="$1" tmp="$2"
if ! cmp -s "$target" "$tmp"; then
cat "$tmp" >"$target"
fi
rm -f "$tmp"
}

# Firefox keeps one prefs.js per profile, under one of these roots:
# ~/.mozilla/firefox (regular installs)
# $XDG_CONFIG_HOME/mozilla/firefox (NixOS / MOZILLA_HOME setups)
# ~/.var/app/org.mozilla.firefox/... (Flatpak)
# ~/snap/firefox/common/... (Snap)
roots=()
for root in \
"${HOME}/.mozilla/firefox" \
"${XDG_CONFIG_HOME:-$HOME/.config}/mozilla/firefox" \
"${HOME}/.var/app/org.mozilla.firefox/.mozilla/firefox" \
"${HOME}/snap/firefox/common/.mozilla/firefox"
do
[ -d "$root" ] && roots+=("$root")
done

if [ "${#roots[@]}" -gt 0 ]; then
find "${roots[@]}" -mindepth 2 -maxdepth 2 -type f -name "prefs.js" -print0 2>/dev/null |
while IFS= read -r -d '' prefs_file; do
profile_dir=$(dirname "$prefs_file")
chrome_dir="$profile_dir/chrome"
user_chrome="$chrome_dir/userChrome.css"
user_content="$chrome_dir/userContent.css"
user_js="$profile_dir/user.js"

mkdir -p "$chrome_dir"
touch "$user_chrome" "$user_content" "$user_js"

tmp_chrome="$(mktemp "${user_chrome}.tmp.XXXXXX")"
sed '/noctalia\/firefox\/firefox-userChrome\.css/d' "$user_chrome" >"$tmp_chrome"
if ! grep -Fq "$line_chrome" "$tmp_chrome"; then
[ -s "$tmp_chrome" ] && [ -n "$(tail -c1 "$tmp_chrome")" ] && echo >>"$tmp_chrome"
printf '%s\n' "$line_chrome" >>"$tmp_chrome"
fi
write_if_changed "$user_chrome" "$tmp_chrome"

tmp_content="$(mktemp "${user_content}.tmp.XXXXXX")"
sed '/noctalia\/firefox\/firefox-userContent\.css/d' "$user_content" >"$tmp_content"
if ! grep -Fq "$line_content" "$tmp_content"; then
[ -s "$tmp_content" ] && [ -n "$(tail -c1 "$tmp_content")" ] && echo >>"$tmp_content"
printf '%s\n' "$line_content" >>"$tmp_content"
fi
write_if_changed "$user_content" "$tmp_content"

tmp_js="$(mktemp "${user_js}.tmp.XXXXXX")"
sed \
-e '/toolkit\.legacyUserProfileCustomizations\.stylesheets/d' \
-e '/svg\.context-properties\.content\.enabled/d' \
-e '/devtools\.chrome\.enabled/d' \
"$user_js" >"$tmp_js"
[ -s "$tmp_js" ] && [ -n "$(tail -c1 "$tmp_js")" ] && echo >>"$tmp_js"
printf '%s\n' \
'user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true);' \
'user_pref("svg.context-properties.content.enabled", true);' \
'user_pref("devtools.chrome.enabled", true);' >>"$tmp_js"
write_if_changed "$user_js" "$tmp_js"
done
fi
Loading