# Themes

A theme changes how Grabbit looks and keeps everything where it was: the same windows, menus and
buttons in the same places, drawn in other colours, sizes and shapes. Each theme has a light and
a dark side.

## Graphite

Grabbit's look is **Graphite**, its only built-in theme: zinc greys, near-black or white, with
emerald green, rounded corners, one-colour icons and its own typeface, Geist
([Getting started](https://humblef0ol.github.io/grabbit/help/getting-started.html#themes) describes it). A theme file that names a theme
Grabbit doesn't have gets Graphite, and the log says so.

The status bar's light/dark button chooses its light or dark side
([Dark mode](https://humblef0ol.github.io/grabbit/help/getting-started.html#dark-mode)). Theme files of your own build on Graphite: open
**View → Theme** and click one, and the whole window changes at once, nothing to restart.

## Where theme files go

Theme files you make or download go in Grabbit's themes folder. **View → Theme → Open themes folder**
opens it (and makes it the first time). It is in Grabbit's data folder:

| System | Folder |
|---|---|
| Installed or the plain zip | `%APPDATA%\grabbit\themes` |
| [Portable copy](https://humblef0ol.github.io/grabbit/help/portable.html) | `data\themes` beside the program |

Within two seconds a new file shows in **View → Theme**, under Graphite, by the `name`
it gives itself. After you edit a file, pick it again in **View → Theme** to see the change.

A theme can be one file (`harbour.toml`) or a folder of its own (`harbour/theme.toml`) when it
brings icons.

**View → Theme → Add a theme file...** does it for you: pick a file anywhere, and Grabbit copies it into
the themes folder and uses it at once. A file that isn't a theme stays out, and Grabbit says why.

## Base16 and pywal colour schemes

Colour schemes made for other programs are themes too, with nothing to convert:

- **A Base16 scheme**, the `.yaml` file the
  [Base16 and Base24 schemes](https://github.com/tinted-theming/schemes) come in: both the
  classic layout (`scheme:` and `base00` to `base0F` at the top) and the newer one (`name:` and a
  `palette:` block). A Base24 scheme reads as its first 16 colours.
- **pywal's `colors.json`**, or any program's file in pywal's shape (wallust's pywal template).

Add it with **View → Theme → Add a theme file...**, or put it in the themes folder yourself. It
shows in **View → Theme** under the scheme's name (`name:` or `scheme:`; pywal's is named after
the wallpaper).

**pywal itself:** once `wal` has run, **View → Theme** lists **pywal**, read straight from where
pywal writes its colours: `~/.cache/wal/colors.json` (on Windows
`%USERPROFILE%\.cache\wal\colors.json`, where winwal and pywal write it; `$PYWAL_CACHE_DIR` or
`$XDG_CACHE_HOME/wal` when you set them). Pick it and Grabbit follows your wallpaper: each time `wal`
writes new colours, Grabbit takes them within two seconds. It looks only at the file's date and size,
every two seconds, and only while pywal is the theme. A copy added with **Add a theme file...**
keeps the colours it had.

A scheme changes colours only, on Graphite: every window, button and menu stays where it
was. A dark scheme makes Grabbit dark and a light one light, whatever the light/dark button says (the button is greyed while such a scheme is chosen). The
scheme's colours go where they mean the same:

| Grabbit | Base16 | pywal |
|---|---|---|
| The download list, text boxes and menus | `base00` (the background) | `special.background` |
| Windows, dialogs, the toolbar, the menu bar and column headers | `base01` (the lighter background) | the background a step toward the foreground |
| Text | `base05` (the foreground) | `special.foreground` |
| Secondary text (sizes, notes) | `base04` | `color8` |
| Focus, default buttons, check boxes, links, the selection and the progress bar | `base0D` (blue) | `color4` |
| Errors | `base08` (red) | `color1` |
| Warnings | `base0A` (yellow) | `color3` |
| Success, the meters and a torrent's pieces | `base0B` (green) | `color2` |

Borders and the hover and pressed shades are mixed from these, as for a theme file's `[seeds]`.
Text stays readable: text and secondary text at 4.5:1 or more against every background they sit
on (WCAG AA), the accent at 3:1. A scheme short of that has those colours moved a little darker
(lighter on a dark scheme) until they pass; Grabbit's log says which.

To change more than colours, make a theme file that inherits the scheme by its file name and adds
what you like:

```toml
name = "Gruvbox, my way"
inherits = "gruvbox-dark-medium"   # gruvbox-dark-medium.yaml, beside it

[sizes]
radius = 6
```

`inherits = "pywal"` works the same way, and follows `wal` too.

## The file

A theme is one small text file in [TOML](https://toml.io/) (or JSON, `.json`; or a
[colour scheme](#base16-and-pywal-colour-schemes), `.yaml`). It names only what it changes;
everything else comes from the theme it `inherits`:

```toml
name = "Harbour"
inherits = "graphite"

[seeds.light]
background = "#eef3f6"
surface = "#ffffff"
text = "#11202b"
accent = "#0f6c8c"

[seeds.dark]
background = "#14212a"
surface = "#0e171d"
text = "#e8f0f4"
accent = "#5cc3e6"

[sizes]
radius = 6

[controls]
focus = "ring"
```

- **`name`** — what **View → Theme** lists; the file's name when there is none.
- **`inherits`** — the theme yours starts from: `graphite` (the default when it's left out), or
  another theme file in the same folder, by its file name without `.toml`. A file that inherits
  another can be inherited in turn; a theme can't inherit itself.
- **`[seeds]`** — a handful of colours (`background`, `surface`, `header`, `text`, `accent`,
  `selection`, `error`, `warning`, `success`) that Grabbit spreads over every control.
  `[seeds.light]` and `[seeds.dark]` give each side its own.
- **`[colors]`** — single colour roles (such as `window`, `accent` or `"progress.bar"`) on both
  sides; **`[light]`** and **`[dark]`** on one side only. A colour is `#rrggbb`, or `#rrggbbaa`
  with transparency. The roles a file sets win over its seeds.
- **`[sizes]`** — corner radii, border widths, font sizes and row heights, in pixels.
- **`[controls]`** — the shape of text boxes, check boxes, buttons, progress bars, scroll bars,
  the focus mark and the title bar. The layout is Graphite's in every theme (a `chrome` key is
  no longer read). The removed themes' styles `luna`, `aero`, `aqua`, `adwaita`, `breeze` and
  `metro` are gone: a theme file that names one gets Graphite's control. Its parts are drawn with the roles `panel`, `tile`, `text.secondary`,
  `menu.shortcut`, `toolbar.checked`, `button.danger`, `button.danger.text`, `banner.error`,
  `banner.info`, `banner.warning`, `glow`, `button.accent.top` and `progress.bar.end` (`glow`,
  `button.accent.top` and `progress.bar.end` are transparent unless a theme sets them: no glow,
  a flat face). A download window's strip uses `strip.accent` (its track while a file is
  checked or a video joined, and the stripes between the fill while a debrid service downloads
  a torrent first), `strip.error` and `strip.error.hatch`.
- **`font`** — a font Grabbit carries, for every text: `"geist"` (Geist, as the Graphite theme has it).
  Without it, or with a name Grabbit doesn't carry, the windows keep Windows' own fonts.
- **`contrast = "high"`** — strengthens every edge and text colour on top of the rest.

Every colour role, size and control style, with what it sets, is listed on the website's
[Themes page](https://humblef0ol.github.io/grabbit/themes.html#make-your-own) (read from Grabbit's own
code, so it never drifts). Graphite is written the same way:
[read it on GitHub](https://github.com/HUMBLEF0OL/grabbit/tree/main/crates/app/assets/themes).

A key Grabbit doesn't know, or a value it can't read, is skipped and written to Grabbit's log (the `logs`
folder beside the themes folder), so a file made for a newer Grabbit still loads. A file that isn't
valid TOML or JSON doesn't load, and the log says why. A file named like the built-in theme
(`graphite.toml`) is passed over: give yours a name of its own.

### Icons

A theme in a folder of its own (`harbour/theme.toml`) can bring its icons in `icons/16` and
`icons/24` (and, for PNG pictures, `icons/32` and `icons/48`, used on a screen scaled to 150 % and
more), each named for what it shows (`tb-add-url.svg`, `cat-music.png`…). SVG and PNG files keep
their colours; `-symbolic.svg` and `-symbolic.png` ones, as GNOME and KDE name them, take the
theme's text colour. An icon the set lacks is Graphite's. The full list of names is in [themeicons.rs](https://github.com/HUMBLEF0OL/grabbit/blob/main/crates/app/src/themeicons.rs) (`NEEDS`).
Its `EXTRAS` (`gx-link.svg`, `gx-search.svg`…) are the icons of Graphite's menu rows, buttons,
Options pages, banners and tiles.

## Make one

1. **View → Theme → Open themes folder**, and make a new `.toml` file there (any text editor).
2. Start from the example above: change the seeds' colours, then add roles and sizes as you go.
3. Pick it in **View → Theme**, and look at both sides: click the status bar's light/dark button. Check
   that text is readable and the focus mark visible in both.

The website's [Themes page](https://humblef0ol.github.io/grabbit/themes.html#ai-prompt) has a prompt
you can give an AI assistant, with the format, every key and the rules, to write a theme for you
from a description.

## Share it

Made something others would like? Open a
[pull request](https://github.com/HUMBLEF0OL/grabbit/pulls) that adds it to
`crates/app/assets/themes`, with:

- the `.toml` file, and its folder of icons if it has one;
- screenshots of the main window in its light and its dark side;
- a `SOURCES.txt` beside any icons, saying who drew them and under which licence. Icons must be
  your own or under a licence that lets Grabbit share them (GPL-3.0), never copied from another
  program.

Not sure yet? Show it in the
[issues](https://github.com/HUMBLEF0OL/grabbit/issues) first.
[CONTRIBUTING.md](https://humblef0ol.github.io/grabbit/contributing.html) explains how pull requests work here.

## Next steps

- [Getting started →](https://humblef0ol.github.io/grabbit/help/getting-started.html)
- [Options →](https://humblef0ol.github.io/grabbit/help/options.html)
