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
adwaita(default) — exact behavior of current sctk-adwaita. The hardcoded constants move verbatim intobackend/adwaita.rs. Zero-config drop-in: when no config file exists, this backend is selected.static— reads colors from~/.config/sctk-dynamic/colors.toml. Supports[light]and[dark]sections in a single file; flips on the portalcolor-schemesignal. Watches the file via thenotifycrate for live reload.- Later:
gnome(query libadwaita at runtime via a GTK4 helper process),kde(parse~/.local/share/color-schemes/*.colors), etc.
Configuration
~/.config/sctk-dynamic/config.toml— selects the active backend:
Missing file → default tobackend = "adwaita" # or "static"adwaita.~/.config/sctk-dynamic/colors.toml— consumed by thestaticbackend:[light.active] headerbar = "#EBEBEB" button_idle = "#D8D8D8" button_hover = "#CFCFCF" button_icon = "#2A2A2A" border_color = "#DCDCDC" font_color = "#2F2F2F" [light.inactive] headerbar = "#FAFAFA" # ... [dark.active] # ... [dark.inactive] # ...
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:
adwaitabackend: subscribe to the portalSettingChangedsignal oncolor-scheme(not currently done; needs to be added).staticbackend:notify-crate file watch oncolors.toml, plus the same portal subscription to flip[light]vs[dark].gnome/kdebackends (future): portal signal + helper-process re-query, or file watch on KDE color-scheme files.
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:
org.freedesktop.appearance→color-scheme(via the XDG settings portal) — pickslight()vsdark(). Only flips the whole palette; no RGB control. Note: this is the portal’s standardized appearance namespace, notorg.gnome.desktop.interface(which also has acolor-schemegsettings key, but sctk-adwaita goes through the portal).org.gnome.desktop.wm.preferences→button-layout— determines which buttons appear and on which side (config.rs:29-37).org.gnome.desktop.wm.preferences→titlebar-font— via shelling out togsettings get(title/config.rs:8-9).
sctk-dynamic inherits all three. Decide where they live (a shared
system.rs, or duplicated per backend) during implementation.
Concrete first-implementation plan
git clonesctk-adwaita; keeppackage.name = "sctk-adwaita"inCargo.toml(required for[patch.crates-io]); keepAdwaitaFrame<T>as the public type name. The git repo / directory can be calledsctk-dynamic.- Add upstream remote (
https://github.com/rust-windowing/sctk-adwaita) — periodically merge/rebase to pull bugfixes. - Introduce the
Backendtrait in a newbackend/mod.rs. - Move the existing constants into
backend/adwaita.rs(verbatim move oflight()/dark()/auto()). - Implement
backend/static.rs: loadcolors.toml, watch vianotify, callon_changedon edits. - Add
config.tomlloader (backend = "adwaita" | "static"). Defaultadwaitawhen file missing. - Wire the portal
SettingChangedsignal into both backends so they flip light/dark on system theme change.
Where the work actually is
lib.rs:131(buttons: Buttons::new(get_button_layout_config())) — frame construction. Here the chosenBackendis instantiated instead of hardcodingColorTheme::auto().- A new
config.rsfor the TOML loaders. Note: sctk-adwaita already has aconfig.rsfor the gsettings/portal reads. However, those reads (button-layout,titlebar-font,color-scheme) are shared infrastructure needed by every backend, not adwaita-specific. Decide where they live (a sharedsystem.rs, or duplicated per backend). Each backend that needs its own config (e.g.staticreading TOML) can have its own config module.
Everything else (rendering, input, seat integration) is untouched.