SCTK-Dynamic plan

Published (last updated )

A fork of sctk-adwaita that makes the client-side decoration colors used by winit-based Wayland apps (Alacritty, Neovide, etc.) configurable, instead of hardcoded to Adwaita’s palette.

Motivation

On at least GNOME Wayland, mutter does not draw decorations for native Wayland windows. Apps using the winit crate, render their own CSD via the sctk-adwaita crate, which is statically linked into the app binary, effectively making colors compile-time constants. There is no runtime configuration, and GTK CSS (~/.config/gtk-4.0/gtk.css) has no effect on these apps.

The hardcoded values (light variant):

Part Focused (active) Unfocused (inactive)
headerbar #EBEBEB #FAFAFA
button idle #D8D8D8 #F0F0F0
button hover #CFCFCF #D8D8D8
button icon #2A2A2A #949494
border color #DCDCDC #DCDCDC
font color #2F2F2F #969696

Design

Forking sctk-adwaita

We will fork sctk-adwaita. Besides the hardcoded colors mentioned above, it contains a CSD renderer (tiny_skia drawing of headerbar/buttons/shadow, pointer hit-testing, seat integration, the Frame trait impl that winit depends on). Re-implementing that from scratch is wasted effort and a source of bugs. The colors are ~40 lines out of a ~2000-line codebase.

The existing structure makes the refactor clean: ColorTheme is already the indirection point. Rendering code in parts.rs / buttons.rs / title.rs / shadow.rs / pointer.rs only consumes ColorMap — that interface stays unchanged. The change is basically swapping one function: ColorTheme::light() / dark() / auto() → Backend::color_theme().

Backend abstraction

Introduce a Backend trait:

pub trait Backend {
    fn color_theme(&self) -> ColorTheme;
    fn subscribe(&self, on_changed: Box<dyn Fn()>);
}

Each backend owns its own update mechanics (portal signal, file watch, none). Adding a new backend later is one new impl, no churn elsewhere.

Backends

  1. adwaita (default) — exact behavior of current sctk-adwaita. The hardcoded constants move verbatim into backend/adwaita.rs. Zero-config drop-in: when no config file exists, this backend is selected.
  2. static — reads colors from ~/.config/sctk-dynamic/colors.toml. Supports [light] and [dark] sections in a single file; flips on the portal color-scheme signal. Watches the file via the notify crate for live reload.
  3. Later: gnome (query libadwaita at runtime via a GTK4 helper process), kde (parse ~/.local/share/color-schemes/*.colors), etc.

Configuration

Color parsing

For now, only #RRGGBB and #RRGGBBAA hex literals.

Public API compatibility

Keep AdwaitaFrame<T> as the public type name (a type alias for whatever the internal frame struct becomes). This means winit’s #[cfg(feature = "sctk-adwaita")] code at winit-wayland/src/window/state.rs:49-50 keeps compiling unchanged.

Important: to swap sctk-adwaita for sctk-dynamic via [patch.crates-io] in Alacritty’s or Neovide’s Cargo.toml, the package.name in Cargo.toml must stay sctk-adwaita — the patch mechanism requires the replacement crate to have the same package name as the original. The git repo / directory can be called sctk-dynamic, but the crate name cannot change without also patching winit itself.

Live reload

winit’s set_theme() (winit-wayland/src/window/state.rs:876) calls frame.set_config(...), which is the entry point for pushing new colors into an existing frame. However, nothing in winit automatically invokes set_theme() on portal color-scheme changes today — sctk-adwaita calls prefer_dark() exactly once at frame construction (inside ColorTheme::auto()), with no portal subscription. Live portal-driven reload needs to be built.

The subscribe mechanism on the Backend trait is the way to do this:

When a backend’s subscribe callback fires, it triggers a set_config() call on the frame, which re-renders with the new colors.

What sctk-adwaita reads from the system today

Already wired and reusable. These three reads are shared infrastructure needed by every backend (they all render buttons and titlebar text, and flip light/dark), not owned by the adwaita backend specifically:

sctk-dynamic inherits all three. Decide where they live (a shared system.rs, or duplicated per backend) during implementation.

Concrete first-implementation plan

  1. git clone sctk-adwaita; keep package.name = "sctk-adwaita" in Cargo.toml (required for [patch.crates-io]); keep AdwaitaFrame<T> as the public type name. The git repo / directory can be called sctk-dynamic.
  2. Add upstream remote (https://github.com/rust-windowing/sctk-adwaita) — periodically merge/rebase to pull bugfixes.
  3. Introduce the Backend trait in a new backend/mod.rs.
  4. Move the existing constants into backend/adwaita.rs (verbatim move of light() / dark() / auto()).
  5. Implement backend/static.rs: load colors.toml, watch via notify, call on_changed on edits.
  6. Add config.toml loader (backend = "adwaita" | "static"). Default adwaita when file missing.
  7. Wire the portal SettingChanged signal into both backends so they flip light/dark on system theme change.

Where the work actually is

Everything else (rendering, input, seat integration) is untouched.