RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
gtk theme button fix
oxydizerc7b88234c66e
diff --git a/assets/mockups/polkit-dialog.html b/assets/mockups/polkit-dialog.htmldeleted file mode 100644index 4afa18b..0000000--- a/assets/mockups/polkit-dialog.html+++ /dev/null@@ -1,86 +0,0 @@-<!doctype html>-<html lang="en">-<meta charset="utf-8">-<meta name="viewport" content="width=device-width, initial-scale=1">-<title>RediWM · Authentication dialog preview</title>-<style>- * { box-sizing: border-box; }- :root { color-scheme: dark; font-family: Inter, "Noto Sans", sans-serif; color: #f2f4f8; }- body { margin: 0; min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; background: radial-gradient(ellipse at 25% 85%, #36202a, transparent 55%), #101216; }- main { width: min(100%, 540px); }- .dialog { background: #1b1d20; border: 1px solid #ffffff14; border-radius: 18px; padding: 28px; box-shadow: 0 24px 90px #0008; }- header { display: flex; gap: 22px; align-items: center; margin-bottom: 28px; }- .badge { width: 72px; height: 72px; flex: none; display: grid; place-items: center; background: #3d1f26; color: #ff7183; border: 1px solid #ff71831a; border-radius: 20px; }- svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }- .lock-icon { width: 18px; height: 18px; flex: none; filter: invert(63%) sepia(45%) saturate(1400%) hue-rotate(308deg) brightness(105%); }- .badge .lock-icon { width: 32px; height: 32px; }- h1 { font-size: 25px; line-height: 1.25; letter-spacing: -.6px; margin: 0 0 8px; font-weight: 650; }- p { margin: 0; font-size: 14px; line-height: 1.55; color: #a8b0ba; }- .request { display: flex; align-items: center; gap: 14px; padding-bottom: 22px; border-bottom: 1px solid #ffffff0d; }- .app-icon { display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid #ffffff14; border-radius: 10px; background: linear-gradient(#35383f, #24262b); color: #d0d4da; }- strong { display: block; font-size: 15px; font-weight: 600; margin-bottom: 3px; }- .action { font-size: 12px; overflow-wrap: anywhere; user-select: text; }- .identity { display: flex; gap: 13px; align-items: center; margin: 20px 0; padding: 13px 15px; border-radius: 12px; background: #1f2125; border: 1px solid #ffffff0b; }- .avatar { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: #34373d; color: #c9cdd4; }- .identity p { font-size: 12px; }- label { display: block; font-size: 13px; color: #bbc1ca; margin: 0 0 8px; }- .field { display: flex; align-items: center; gap: 12px; height: 52px; padding: 0 15px; border-radius: 11px; border: 1px solid #d85a6b; box-shadow: 0 0 0 2px #ba243814; color: #d67b87; background: #17191c; }- .field span { color: #f2f4f8; letter-spacing: 5px; font-size: 19px; }- .hint { margin-top: 13px; min-height: 43px; font-size: 12px; }- .hint.error { color: #ff8f9e; }- footer { display: flex; gap: 12px; margin-top: 17px; }- button { font: inherit; cursor: pointer; }- footer button { flex: 1; min-height: 44px; border: 1px solid #ffffff12; border-radius: 11px; color: #f2f4f8; background: #2b2e33; font-size: 14px; }- footer .primary { background: #ba2438; font-weight: 600; border-color: #ed65764d; }- button:hover { filter: brightness(1.12); }- button:focus-visible { outline: 2px solid #f2b2bb; outline-offset: 3px; }- button:disabled { opacity: .65; cursor: wait; }- .preview { margin-top: 24px; text-align: center; }- .preview p { font-size: 11px; color: #8e929b; }- .states { display: flex; justify-content: center; gap: 6px; margin-top: 12px; }- .states button { border: 1px solid #ffffff14; border-radius: 6px; background: #ffffff06; color: #b9bdc5; font-size: 11px; padding: 6px 12px; }- .states button[aria-pressed="true"] { background: #ffffff12; color: white; }- @media (max-width: 420px) { .dialog { padding: 22px; } header { gap: 15px; } .badge { width: 56px; height: 56px; border-radius: 16px; } h1 { font-size: 22px; } }-</style>-<main>- <section class="dialog" role="dialog" aria-labelledby="title" aria-describedby="description">- <header>- <div class="badge"><img class="lock-icon" src="../icons/lock.svg" alt=""></div>- <div><h1 id="title">Authentication required</h1><p id="description">Enter your password to continue.</p></div>- </header>- <div class="request">- <div class="app-icon"><svg aria-hidden="true" viewBox="0 0 24 24"><path d="m5 6 6 6-6 6m9 0h5"/></svg></div>- <div><strong>Run a command as administrator</strong><p class="action">org.freedesktop.policykit.exec</p></div>- </div>- <div class="identity">- <div class="avatar"><svg aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="8" r="4" fill="currentColor" stroke="none"/><path d="M4 21v-2a8 8 0 0 1 16 0v2" fill="currentColor" stroke="none"/></svg></div>- <div><strong>Alex</strong><p>alex · Administrator account</p></div>- </div>- <label id="password-label">Password</label>- <div class="field" role="img" aria-labelledby="password-label" aria-label="Password field preview, example masked characters">- <img class="lock-icon" src="../icons/lock.svg" alt=""><span aria-hidden="true">••••••••</span>- </div>- <p class="hint" id="status" aria-live="polite">Administrator privileges are required to continue.</p>- <footer><button id="cancel">Cancel</button><button class="primary" id="authenticate">Authenticate</button></footer>- </section>- <aside class="preview" aria-label="Preview controls">- <p>UI preview · example characters only · no password entry</p>- <div class="states"><button data-state="ready" aria-pressed="true">Ready</button><button data-state="retry" aria-pressed="false">Retry</button><button data-state="working" aria-pressed="false">Authenticating</button></div>- </aside>-</main>-<script>- const status = document.querySelector('#status');- const authenticate = document.querySelector('#authenticate');- function show(state) {- status.classList.toggle('error', state === 'retry');- status.textContent = {ready: 'Administrator privileges are required to continue.', retry: 'Authentication failed. Try again. 2 attempts remaining.', working: 'Verifying your password…', cancelled: 'Request cancelled. Select Ready to preview again.'}[state];- authenticate.disabled = state === 'working' || state === 'cancelled';- authenticate.textContent = state === 'working' ? 'Authenticating…' : 'Authenticate';- document.querySelectorAll('[data-state]').forEach(button => button.setAttribute('aria-pressed', String(button.dataset.state === state)));- }- document.querySelectorAll('[data-state]').forEach(button => button.addEventListener('click', () => show(button.dataset.state)));- authenticate.addEventListener('click', () => show('working'));- document.querySelector('#cancel').addEventListener('click', () => show('cancelled'));- document.addEventListener('keydown', event => { if (event.key === 'Escape') show('cancelled'); });-</script>-</html>diff --git a/build.zig b/build.zigindex f2c3ff0..73614e3 100644--- a/build.zig+++ b/build.zig@@ -85,6 +85,7 @@ pub fn build(b: *std.Build) void {ui_mod.addAnonymousImport("theme-rediwm-dark", .{ .root_source_file = b.path("assets/themes/rediwm-dark.toml") });ui_mod.addAnonymousImport("theme-rediwm-light", .{ .root_source_file = b.path("assets/themes/rediwm-light.toml") });ui_mod.addAnonymousImport("theme-redi-blue", .{ .root_source_file = b.path("assets/themes/redi-blue.toml") });+ ui_mod.addAnonymousImport("theme-redi-mocha", .{ .root_source_file = b.path("assets/themes/redi-mocha.toml") });const dbus_mod = b.createModule(.{ .root_source_file = b.path("src/dbus/mod.zig"), .target = target, .optimize = optimize, .link_libc = true });dbus_mod.addImport("wayland", wayland);dbus_mod.linkSystemLibrary("wayland-server", .{});diff --git a/docs/themes.md b/docs/themes.mdindex a43eb3c..d91b985 100644--- a/docs/themes.md+++ b/docs/themes.md@@ -74,8 +74,11 @@ watched and no additional polling is introduced.Discovery uses the first occurrence of an ID: `$XDG_DATA_HOME/rediwm/themes`,legacy config presets, the binary's `../share/rediwm/themes`,-`$XDG_DATA_DIRS/rediwm/themes`, then the embedded RediWM Dark, RediWM Light-and Redi Blue packs. Without `XDG_DATA_HOME`, use `~/.local/share`.+`$XDG_DATA_DIRS/rediwm/themes`, then the embedded RediWM Dark, RediWM Light,+Redi Blue and Redi-Mocha packs. Without `XDG_DATA_HOME`, use `~/.local/share`.++Redi-Mocha uses the [Catppuccin Mocha palette](https://catppuccin.com/palette/#mocha)+with mauve accents and the bundled `wallpaper-mocha.png` Auckland skyline.The helper is also available from a terminal:diff --git a/docs/wiki/Theme.md b/docs/wiki/Theme.mdindex 4b9f06e..9127093 100644--- a/docs/wiki/Theme.md+++ b/docs/wiki/Theme.md@@ -4,9 +4,11 @@ Put these keys in `[theme]` in `$XDG_CONFIG_HOME/rediwm/config.toml`.`REDIWM_CONFIG` selects another config file; `REDIWM_THEME` overlays anotherfile's `[theme]` section. Omitted keys use the built-in defaults below.Appearance saves custom tokens along with its sliders and selectors.-The bundled picker includes RediWM Dark, RediWM Light and Redi Blue. Redi Blue-uses navy surfaces, cyan accents, 98% chrome opacity and a 30% selection tint.+The bundled picker includes RediWM Dark, RediWM Light, Redi Blue and Redi-Mocha.+Redi Blue uses navy surfaces, cyan accents, 98% chrome opacity and a 30% selection tint.RediWM Light uses 75% window chrome opacity and teal selection accents.+Redi-Mocha uses the [Catppuccin Mocha palette](https://catppuccin.com/palette/#mocha),+mauve accents and the bundled `wallpaper-mocha.png` Auckland skyline.`start_button_logo_color` optionally tints the bundled R logo; Light uses adark tint for contrast. Custom start-button icons retain their own colours.@@ -49,7 +51,10 @@ their own configuration.The first existing user configuration is backed up beside its original as`<filename>.rediwm-backup`; later applications keep that first backup.-Managed symlinks are left alone and reported in Settings. To undo GTK colors,+A `gtk.css` (or Qt config) that is a symlink, for example one generated by+another theming tool, is replaced by a regular file holding its current+contents plus the RediWM block; the link target is not modified. A config+*folder* that is a symlink is refused and reported in Settings. To undo GTK colors,remove the marked RediWM import blocks from both `gtk.css` files (or restoretheir backups). To undo Qt colors, restore the qt5ct/qt6ct configurationbackups (or delete configurations created by the export if no backup exists),diff --git a/src/config/app_theme.zig b/src/config/app_theme.zigindex 7b02a67..9a353db 100644--- a/src/config/app_theme.zig+++ b/src/config/app_theme.zig@@ -1,5 +1,7 @@//! Explicit palette exports. User styles and toolkit preferences are merged;-//! the first originals are kept beside them as .rediwm-backup files.+//! the first originals are kept beside them as .rediwm-backup files. A file+//! that is a symlink (another tool's generated output) is replaced by a regular+//! file holding its current contents; a rollback puts the link back.const std = @import("std");const theme = @import("ui").theme;const Allocator = std.mem.Allocator;@@ -255,16 +257,16 @@ pub fn patchCss(a: Allocator, content: []const u8) ![]u8 {}fn readOptional(a: Allocator, io: Io, path: []const u8) !?[]u8 {- const stat = Io.Dir.cwd().statFile(io, path, .{ .follow_symlinks = false }) catch |err| switch (err) {+ // Follows a file symlink: the link target's content is what gets merged.+ const stat = Io.Dir.cwd().statFile(io, path, .{}) catch |err| switch (err) {error.FileNotFound => return null,else => return err,};- if (stat.kind == .sym_link) return error.ManagedSymlink;if (stat.kind != .file) return error.InvalidFile;return try Io.Dir.cwd().readFileAlloc(io, path, a, .limited(1 << 20));}-const Change = struct { path: []const u8, data: []const u8, original: ?[]const u8, temp: []const u8, permissions: Io.File.Permissions };+const Change = struct { path: []const u8, data: []const u8, original: ?[]const u8, link: ?[]const u8, temp: []const u8, permissions: Io.File.Permissions };const Transaction = struct {a: Allocator,io: Io,@@ -280,16 +282,21 @@ const Transaction = struct {};if (stat.kind == .sym_link) return error.ManagedSymlink;}+ var link_buf: [std.Io.Dir.max_path_bytes]u8 = undefined;+ const link: ?[]const u8 = if (Io.Dir.cwd().readLink(self.io, path, &link_buf)) |n| try self.a.dupe(u8, link_buf[0..n]) else |err| switch (err) {+ error.NotLink, error.FileNotFound => null,+ else => return err,+ };const original = try readOptional(self.a, self.io, path);if (original) |old| {- if (std.mem.eql(u8, old, data)) return;+ if (link == null and std.mem.eql(u8, old, data)) return;if (backup) {const saved = try std.fmt.allocPrint(self.a, "{s}.rediwm-backup", .{path});if (try readOptional(self.a, self.io, saved) == null) try self.add(saved, old, false);}}const permissions = if (original != null) (try Io.Dir.cwd().statFile(self.io, path, .{})).permissions else Io.File.Permissions.fromMode(0o600);- try self.changes.append(self.a, .{ .path = path, .data = data, .original = original, .temp = try std.fmt.allocPrint(self.a, "{s}.rediwm-tmp", .{path}), .permissions = permissions });+ try self.changes.append(self.a, .{ .path = path, .data = data, .original = original, .link = link, .temp = try std.fmt.allocPrint(self.a, "{s}.rediwm-tmp", .{path}), .permissions = permissions });}fn commit(self: *Transaction) !void {@@ -309,7 +316,15 @@ const Transaction = struct {errdefer {var rollback_failed = false;for (self.changes.items[0..published]) |change| {- if (change.original) |original| {+ if (change.link) |target| {+ Io.Dir.cwd().symLink(self.io, target, change.temp, .{}) catch {+ rollback_failed = true;+ continue;+ };+ Io.Dir.rename(.cwd(), change.temp, .cwd(), change.path, self.io) catch {+ rollback_failed = true;+ };+ } else if (change.original) |original| {const file = Io.Dir.cwd().createFile(self.io, change.temp, .{ .exclusive = true, .permissions = change.permissions }) catch {rollback_failed = true;continue;@@ -436,7 +451,7 @@ test "app colors publishes both GTK versions and keeps the first backup" {try std.testing.expectError(error.FileNotFound, tmp.dir.access(io, "qt5ct/qt5ct.conf", .{}));}-test "app colors rejects symlinks and staging failures before publishing" {+test "app colors replaces a file symlink, and rejects linked directories and staging failures" {const a = std.testing.allocator;const io = std.testing.io;var tmp = std.testing.tmpDir(.{});@@ -447,8 +462,20 @@ test "app colors rejects symlinks and staging failures before publishing" {try tmp.dir.writeFile(io, .{ .sub_path = "user.css", .data = "/* owned elsewhere */\n" });try tmp.dir.symLink(io, "../user.css", "gtk-4.0/gtk.css", .{});const p = Palette.fromTheme(.{});- try std.testing.expectError(error.ManagedSymlink, apply(a, io, home, .gtk, p, .{ .qt5 = false, .qt6 = false }));- try std.testing.expectError(error.FileNotFound, tmp.dir.access(io, "gtk-3.0/gtk.css", .{}));+ try apply(a, io, home, .gtk, p, .{ .qt5 = false, .qt6 = false });+ var buf: [64]u8 = undefined;+ try std.testing.expectError(error.NotLink, tmp.dir.readLink(io, "gtk-4.0/gtk.css", &buf));+ const merged = try tmp.dir.readFileAlloc(io, "gtk-4.0/gtk.css", a, .limited(4096));+ defer a.free(merged);+ try std.testing.expect(std.mem.startsWith(u8, merged, css_begin));+ try std.testing.expect(std.mem.endsWith(u8, merged, "/* owned elsewhere */\n"));+ const target = try tmp.dir.readFileAlloc(io, "user.css", a, .limited(64));+ defer a.free(target);+ try std.testing.expectEqualStrings("/* owned elsewhere */\n", target);+ const saved = try tmp.dir.readFileAlloc(io, "gtk-4.0/gtk.css.rediwm-backup", a, .limited(64));+ defer a.free(saved);+ try std.testing.expectEqualStrings("/* owned elsewhere */\n", saved);+ try tmp.dir.deleteTree(io, "gtk-3.0");try tmp.dir.deleteFile(io, "gtk-4.0/gtk.css");try tmp.dir.writeFile(io, .{ .sub_path = "gtk-4.0/gtk.css.rediwm-tmp", .data = "busy" });try std.testing.expectError(error.PathAlreadyExists, apply(a, io, home, .gtk, p, .{ .qt5 = false, .qt6 = false }));diff --git a/src/control_center/sections/appearance.zig b/src/control_center/sections/appearance.zigindex ca1d696..35620b8 100644--- a/src/control_center/sections/appearance.zig+++ b/src/control_center/sections/appearance.zig@@ -861,7 +861,7 @@ fn onApplyAppColors(owner: ?*anyopaque, id: usize) void {fn appColorsFailure(s: *Section, err: anyerror) void {s.app_colors_message = switch (err) {error.QtToolsMissing => "Install qt5ct for Qt 5 apps or qt6ct for Qt 6 apps, then apply again.",- error.ManagedSymlink => "A toolkit file is managed by a symlink. Update its source configuration before applying colors.",+ error.ManagedSymlink => "A toolkit config folder is a symlink. Apply the colors in its real location, or make it a regular folder.",error.InvalidManagedCss => "The RediWM block in gtk.css is incomplete. Repair it before applying colors.",else => std.fmt.bufPrint(&s.app_colors_message_buf, "Could not apply app colors: {s}. Check your configuration files and permissions.", .{@errorName(err)}) catch "Could not apply app colors. Check your configuration files and permissions.",};diff --git a/src/ui/theme_presets.zig b/src/ui/theme_presets.zigindex 3fc87b9..967b6e3 100644--- a/src/ui/theme_presets.zig+++ b/src/ui/theme_presets.zig@@ -11,4 +11,5 @@ pub const bundled = [_]Preset{.{ .id = "rediwm-dark", .name = "RediWM Dark", .bytes = @embedFile("theme-rediwm-dark") },.{ .id = "rediwm-light", .name = "RediWM Light", .bytes = @embedFile("theme-rediwm-light") },.{ .id = "redi-blue", .name = "Redi Blue", .bytes = @embedFile("theme-redi-blue") },+ .{ .id = "redi-mocha", .name = "Redi-Mocha", .bytes = @embedFile("theme-redi-mocha") },};diff --git a/tests/appearance_settings.py b/tests/appearance_settings.pyindex d3a01db..e5e4f3f 100644--- a/tests/appearance_settings.py+++ b/tests/appearance_settings.py@@ -449,11 +449,15 @@ def test_appearance_settings():ipc.wait_for_panel_settled("control_center")assert ui.scroll_into_view("theme")["selected_index"] == 1# Redi Blue applies every supplied token and survives reload.+ blue_index = next(i for i, pack in enumerate(ipc.query("theme.list")["packs"])+ if pack["id"] == "redi-blue")click_widget(ui.scroll_into_view("theme"))- ipc.key_press("End")+ ipc.key_press("Home")+ for _ in range(blue_index):+ ipc.key_press("Down")ipc.key_press("Return")ipc.wait_for_panel_settled("control_center")- assert ui.scroll_into_view("theme")["selected_index"] == 2+ assert ui.scroll_into_view("theme")["selected_index"] == blue_indexblue_theme = tomllib.loads((Path(__file__).resolve().parents[1] /"assets/themes/redi-blue.toml").read_text())["theme"]@@ -478,7 +482,7 @@ def test_appearance_settings():ipc.wait_for("control_center_closed", timeout_ms=5000)ipc.action("open_appearance")ipc.wait_for_panel_settled("control_center")- assert ui.scroll_into_view("theme")["selected_index"] == 2+ assert ui.scroll_into_view("theme")["selected_index"] == blue_indexcheck_blue()click_widget(ui.scroll_into_view("theme"))ipc.key_press("Home")@@ -634,16 +638,16 @@ Path(sys.argv[1]).write_text(json.dumps({k: os.environ[k] for k in keys if k inif "qt6_accent" in colors:assert colors["qt6_accent"] == "#abcdef", colors- # A managed symlink must fail without touching either toolkit.+ # A symlinked gtk.css becomes a regular file with its content merged.gtk4_css = config / "gtk-4.0/gtk.css"gtk4_css.unlink()external = tmp / "external.css"external.write_text("/* external */\n")gtk4_css.symlink_to(external)- before = (config / "gtk-3.0/rediwm-colors.css").read_bytes()- apply("apply_gtk_colors", "managed by a symlink")+ apply("apply_gtk_colors", "GTK colors applied")+ wait_for(lambda: not gtk4_css.is_symlink(), "gtk.css replaced")+ assert "/* external */" in gtk4_css.read_text() and "rediwm-colors.css" in gtk4_css.read_text()assert external.read_text() == "/* external */\n"- assert before == (config / "gtk-3.0/rediwm-colors.css").read_bytes()gtk4_css.unlink()(config / "qt6ct/qt6ct.conf").unlink()(config / "qt6ct/qt6ct.conf").mkdir()diff --git a/tests/theme_packs.py b/tests/theme_packs.pyindex 701634c..6d11683 100644--- a/tests/theme_packs.py+++ b/tests/theme_packs.py@@ -105,7 +105,18 @@ def run():try:with IPCClient(tmp, timeout=30) as ipc:before = ipc.query("theme.list")- assert {p["id"] for p in before["packs"]} >= {"rediwm-dark", "rediwm-light", "redi-blue"}+ assert {p["id"] for p in before["packs"]} >= {"rediwm-dark", "rediwm-light", "redi-blue", "redi-mocha"}+ mocha = next(p for p in before["packs"] if p["id"] == "redi-mocha")+ assert mocha["name"] == "Redi-Mocha" and not mocha["user_installed"], mocha+ ipc.action("theme.apply", {"id": "redi-mocha"})+ look = ipc.action("get_theme")+ assert look["dark_mode"]+ manifest = tomllib.loads((ROOT / "assets/themes/redi-mocha.toml").read_text())+ for key in ("app_bg", "window_fg", "shell_accent", "desktop_selection_border", "switcher_selected_border"):+ expected = tuple(int(manifest["theme"][key][i:i+2], 16) / 255 for i in (1, 3, 5)) + (1,)+ assert all(abs(a - b) < .001 for a, b in zip(look["tokens"][key], expected)), key+ wait_for(lambda: (ipc.query("get_wallpaper")["displayed_path"] or "").endswith("/wallpaper-mocha.png"), "Mocha wallpaper was not presented")+ assert tomllib.loads((tmp / "rediwm-config.toml").read_text())["theme"] == {"base": "redi-mocha"}installed = ipc.action("theme.install", {"path": str(archive)})assert installed["id"] == "test-pack", installedtry: