# fluxtheme

One semantic theme model → GTK2, GTK3/4, KDE/Qt configs, edited surgically.

## Status

v0.2 — the v0.1 core (gtk2/3/4 + KDE backends, line-preserving editor,
diff/backup apply) plus Xcursor and neoflux backends, discovery with
nearest-name and cursor-size checks, live X11/XSETTINGS/EWMH session state,
per-run restore, and a clap CLI. 38 unit tests; `show`, `set --apply`, and
`restore` verified against a real Plasma-6-written config set and a live
neoflux session. The unit tests in `ini.rs`, `model.rs`, `apply.rs`, and
`backends/` are the spec.

```
cargo test
cargo run -- help                     # clap-generated; each subcommand has --help
cargo run -- show                    # what each config file says, plus session caveats
cargo run -- discover                # installed themes × toolkits, schemes, fonts, live overrides
cargo run -- set widget=Breeze icons=breeze cursor=breeze_cursors cursor-size=24 font="Noto Sans 10"
cargo run -- set ... --apply          # writes; every file gets a backup tagged with this run's stamp
cargo run -- set ... --apply --force  # even if a selection is not installed for every toolkit
cargo run -- restore                  # dry run: what undoing the newest --apply run would change
cargo run -- restore --apply          # undo it (consumes the backups; repeat to step further back)
cargo run -- restore --list           # runs and files; --run STAMP picks an older one, --keep leaves backups
```

## Layout

| module            | job |
|-------------------|-----|
| `model.rs`        | `Model` (all `Option`), `Font` with GTK/KDE serializers |
| `ini.rs`          | line-preserving INI editor; handles KDE `[A][B]` and `key[$e]`; `Dialect::Xresources` for `key: value` / `!` comments |
| `edit.rs`         | `Edit::SetKey { file, section, key, value }`, `Edit::SetXresource { file, key, value }` |
| `backend.rs`      | `Backend` trait (`detect / read / plan / apply_hint`), `Env` |
| `backends/gtk.rs` | `.gtkrc-2.0`, `gtk-3.0/settings.ini`, `gtk-4.0/settings.ini` |
| `backends/kde.rs` | `kdeglobals`, `kcminputrc` |
| `backends/xcursor.rs` | `~/.Xresources` (`Xcursor.theme/size`), `~/.icons/default/index.theme` (`Inherits=`) |
| `backends/neoflux.rs` | `[titlebar] font` family in whichever of `config.toml` / `theme.toml` (symlink followed) currently decides; sizes are px layout and left alone |
| `apply.rs`        | group edits by file → before/after → unified diff → write + backup; `find_backups`/`plan_restore`/`restore` undo a run (`<file>.fluxtheme-bak-STAMP` copy, or `.fluxtheme-new-STAMP` marker → delete) |
| `discover.rs`     | inventory of installed widget/icon/cursor themes (× toolkit), KDE schemes, fontconfig families; `check()` a model against it |
| `live.rs`         | session caveats: Wayland, Plasma, XSETTINGS manager (live values), xrdb-vs-file drift, `GTK_THEME`/`XCURSOR_*`/`QT_*` env overrides |
| `x11.rs`          | reads `RESOURCE_MANAGER`, `_XSETTINGS_SETTINGS`, and the EWMH WM name from the running server via x11rb; wire-format parsers are unit-tested |

## Design rules

- Backends emit key-level edits, never whole files. Unknown keys and
  comments pass through untouched. Diffs are therefore short.
- `None` in the model means "don't touch". Reading never fails on a missing
  file; it just yields an empty model.
- Preserve what you don't understand: `Font::to_kde` keeps every QFont field
  except family and size, so Qt5 vs Qt6 field counts don't matter.
- Locate files via `Env` (HOME / XDG_CONFIG_HOME), never hardcoded paths, so
  tests can run against a temp dir and nothing assumes neoflux.

## Roadmap

- **Discovery, remaining**: `discover` lists, `set` refuses `--apply` on an
  uninstalled selection and suggests the nearest installed name (or, for a
  widget theme, the ones installed for every toolkit). `show` ends with a
  `[live x11]` block (xrdb `Xcursor.*`, XSETTINGS manager + values, WM name),
  and `show`/`discover` open with a one-line session summary — neoflux is
  recognised by its EWMH name, `DESKTOP_SESSION`, or process, in that order.
- **More backends**: `qt5ct`/`qt6ct`, gsettings
  (`org.gnome.desktop.interface`), fontconfig XML, an env fragment for
  `XCURSOR_THEME` / `QT_QPA_PLATFORMTHEME`. The neoflux backend could also
  learn the dock apps' palette once they read a shared file.
- **Data-driven backends**: once three or four INI backends exist, lift the
  file/section/key mapping into a TOML table so new toolkit versions are a
  table edit, not code.
- `--stage DIR`, CRLF tolerance in `ini.rs`.

## License

CC0 1.0 (public domain) where the code is not protected by copyright, which
is the position for AI-written code in many countries, and most of this was
written by an AI model; GNU GPL 3.0 or later where it is. The exact terms
are in `LICENSE`, with the two licence texts beside it.

The Rust crates built into the program keep their own licences:
`THIRD-PARTY-LICENSES.txt`.
