Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

save settings fixes

oxydizere6f401961bf1
diff --git a/docs/themes.md b/docs/themes.md
index 8456a0e..04c9196 100644
--- a/docs/themes.md
+++ b/docs/themes.md
@@ -2,10 +2,10 @@
Choose a pack in **Settings → Appearance → Theme**. Changes to colours,
fonts and geometry are stored as overrides of that pack. **Reset to theme**
-clears those overrides; choosing a different pack also resets its wallpaper
-and cursor. Picking a wallpaper afterward pins that choice until the next
-pack switch. **Icon theme** chooses the installed icon theme behind a pack's
-own icons (the pack's `icon_theme`, when specified, takes precedence).
+clears those overrides. Switching packs preserves personal settings, including
+wallpaper, cursor, dark mode and the separate taskbar theme; settings without
+an override follow the new pack. **Icon theme** chooses the installed icon
+theme behind a pack's own icons (the pack's `icon_theme`, when specified, takes precedence).
**Install theme…** accepts a `.rediwm-theme` or `.zip` file. **Remove** is
available for user-installed packs and switches an active pack to RediWM Dark.
@@ -121,10 +121,11 @@ dock_hover_zoom = 1.05 # 1.0–1.5; 1.0 disables hover enlargement
```
Only these appearance settings are accepted here. Resolution is compositor
-defaults → pack layout → explicit `[compositor]` settings. Choosing a theme
-or **Reset to theme** clears these personal overrides (including a taskbar
-item arrangement made in Appearance); a pack without layout values returns to
-the ordinary bottom taskbar, its usual item sections and a disabled dock.
+defaults → pack layout → explicit `[compositor]` settings. Switching themes
+preserves these personal overrides (including a taskbar item arrangement made
+in Appearance). **Reset to theme** clears them; without personal overrides, a
+pack without layout values uses the ordinary bottom taskbar, its usual item
+sections and a disabled dock.
Hidden dock entries and application preferences are preserved. **Save look…**
includes the current layout.
diff --git a/src/config/setting_save.zig b/src/config/setting_save.zig
index 66aad0b..e6aebe1 100644
--- a/src/config/setting_save.zig
+++ b/src/config/setting_save.zig
@@ -15,31 +15,45 @@ pub fn saveCompositor(allocator: std.mem.Allocator, io: Io, path: []const u8, co
} else try save(allocator, io, path, "compositor", key, value);
}
-/// A pack switch/reset clears only layout edits owned by themes. Keep user
-/// launchers, hidden dock entries and unrelated compositor preferences.
-pub fn resetThemeLayout(allocator: std.mem.Allocator, io: Io, path: []const u8) !void {
+/// Switching changes only the base: explicit preferences keep winning over
+/// the new pack. Reset drops appearance overrides so defaults remain inherited,
+/// rather than writing the current pack's defaults as personal preferences.
+pub fn selectTheme(allocator: std.mem.Allocator, io: Io, path: []const u8, id: []const u8, reset: bool) !void {
+ if (!@import("theme_pack.zig").validId(id)) return error.InvalidValue;
const original = try Io.Dir.cwd().readFileAlloc(io, path, allocator, .limited(1 << 20));
defer allocator.free(original);
+ var old = try loader.parse(allocator, original, path);
+ defer old.deinit();
+ const cleared = if (reset) try clearThemeOverrides(allocator, original) else original;
+ defer if (reset) allocator.free(cleared);
+ const result = try patch(allocator, cleared, "theme", "base", id);
+ defer allocator.free(result);
+ try writeValidated(allocator, io, path, result);
+}
+
+fn clearThemeOverrides(allocator: std.mem.Allocator, original: []const u8) ![]u8 {
var result: std.ArrayList(u8) = .empty;
- defer result.deinit(allocator);
- var in_compositor = false;
+ errdefer result.deinit(allocator);
+ var section: []const u8 = "";
var lines = std.mem.splitScalar(u8, original, '\n');
var offset: usize = 0;
while (lines.next()) |raw| {
const end = @min(original.len, offset + raw.len + 1);
const line = theme.stripComment(std.mem.trim(u8, raw, " \t\r"));
- if (std.mem.startsWith(u8, line, "[")) in_compositor = std.mem.eql(u8, line, "[compositor]");
- var remove = false;
- if (in_compositor) if (std.mem.indexOfScalar(u8, line, '=')) |eq| {
+ if (std.mem.startsWith(u8, line, "[")) section = line;
+ var remove = std.mem.eql(u8, section, "[theme]") or std.mem.eql(u8, section, "[taskbar_theme]");
+ if (std.mem.indexOfScalar(u8, line, '=')) |eq| {
const key = std.mem.trim(u8, line[0..eq], " \t\"");
- inline for (@import("theme_pack.zig").Layout.keys) |layout_key| {
- if (std.mem.eql(u8, key, layout_key)) remove = true;
- }
- };
+ if (std.mem.eql(u8, section, "[compositor]")) {
+ inline for (@import("theme_pack.zig").Layout.keys ++ .{ "wallpaper", "dark_mode" }) |appearance_key| {
+ if (std.mem.eql(u8, key, appearance_key)) remove = true;
+ }
+ } else if (std.mem.eql(u8, section, "[input]") and std.mem.eql(u8, key, "cursor_theme")) remove = true;
+ }
if (!remove) try result.appendSlice(allocator, original[offset..end]);
offset = end;
}
- try writeValidated(allocator, io, path, result.items);
+ return result.toOwnedSlice(allocator);
}
pub fn saveRegion(allocator: std.mem.Allocator, io: Io, path: []const u8, comptime key: []const u8, value: @FieldType(loader.RegionConfig, key)) !void {
diff --git a/src/config_runtime/theme_pack.zig b/src/config_runtime/theme_pack.zig
index 4508b4f..0205b38 100644
--- a/src/config_runtime/theme_pack.zig
+++ b/src/config_runtime/theme_pack.zig
@@ -5,21 +5,20 @@ const config = @import("config");
const main = @import("../main.zig");
pub fn apply(server: *Server, id: []const u8) !void {
+ try select(server, id, false);
+}
+
+pub fn reset(server: *Server, id: []const u8) !void {
+ try select(server, id, true);
+}
+
+fn select(server: *Server, id: []const u8, reset_overrides: bool) !void {
if (server.greeter_mode or server.locker != null) return error.SessionLocked;
var arena = std.heap.ArenaAllocator.init(main.gpa);
defer arena.deinit();
- const p = (try config.theme_pack.find(arena.allocator(), server.io, server.environ, server.config.path, id)) orelse return error.ThemeNotFound;
+ _ = (try config.theme_pack.find(arena.allocator(), server.io, server.environ, server.config.path, id)) orelse return error.ThemeNotFound;
if (server.config.path.len == 0) return error.NoConfigPath;
- try config.setting_save.resetThemeLayout(main.gpa, server.io, server.config.path);
- config.loader.replaceThemeOverrides(main.gpa, server.io, server.config.path, p.tokens, p.tokens, id);
- config.loader.replaceTaskbarThemeSection(main.gpa, server.io, server.config.path, p.taskbar);
- // Empty wallpaper means the pack default. Explicit later choices pin it.
- config.setting_save.saveCompositor(main.gpa, server.io, server.config.path, "wallpaper", "") catch return error.SaveFailed;
- if (p.color_scheme) |dark| config.setting_save.saveCompositor(main.gpa, server.io, server.config.path, "dark_mode", dark) catch return error.SaveFailed;
- {
- const name = if (p.cursor_theme.len == 0) "default" else if (std.mem.eql(u8, p.cursor_theme, "pack")) try std.fmt.allocPrint(arena.allocator(), "rediwm-{s}-cursors", .{p.id}) else p.cursor_theme;
- config.setting_save.saveInput(main.gpa, server.io, server.config.path, "cursor_theme", name) catch return error.SaveFailed;
- }
+ try config.setting_save.selectTheme(main.gpa, server.io, server.config.path, id, reset_overrides);
const loaded = try config.loader.load(server.config.path, main.gpa, server.io, server.environ);
if (!std.mem.eql(u8, loaded.theme_base, id)) {
var failed = loaded;
diff --git a/src/control_center/sections/appearance_themes.zig b/src/control_center/sections/appearance_themes.zig
index ff65c4c..265c151 100644
--- a/src/control_center/sections/appearance_themes.zig
+++ b/src/control_center/sections/appearance_themes.zig
@@ -114,11 +114,7 @@ pub fn refreshTheme(server: *@import("../../Server.zig"), taskbar_geometry: bool
if (server.input.open_control_center) |cc| cc.refresh();
}
-/// Replaces every `[theme]` field at once from the picked preset. Reads the
-/// preset bytes before mutating anything, and parses with `main.gpa` rather
-/// than the panel's per-open arena: `theme.global`'s string fields must
-/// outlive this build, and `applyThemeChange` below may trigger a repaint
-/// that resets the arena.
+/// Explicitly discard personal appearance overrides of the current pack.
pub fn onResetTheme(owner: ?*anyopaque, _: usize) void {
const server = section(owner).cc.server;
if (server.config.theme_base.len == 0) {
@@ -126,7 +122,7 @@ pub fn onResetTheme(owner: ?*anyopaque, _: usize) void {
saveThemeChange(server, true);
return;
}
- @import("../../config_runtime/theme_pack.zig").apply(server, server.config.theme_base) catch |err| themeFailure(server, err);
+ @import("../../config_runtime/theme_pack.zig").reset(server, server.config.theme_base) catch |err| themeFailure(server, err);
}
pub fn themeFailure(server: *Server, err: anyerror) void {
if (server.input.open_control_center) |cc| {
diff --git a/src/ipc/commands.zig b/src/ipc/commands.zig
index 211ff2f..cd3c24e 100644
--- a/src/ipc/commands.zig
+++ b/src/ipc/commands.zig
@@ -48,7 +48,7 @@ pub const CommandSpec = struct {
// Canonical v1 names and internal parameter-parser routes.
pub const specs = [_]CommandSpec{
.{ .id = .theme_list, .wire_name = "theme.list", .kind = .query, .description = "List installed and embedded theme packs", .params_schema = "{}", .description_order = 107 },
- .{ .id = .theme_apply, .wire_name = "theme.apply", .kind = .action, .description = "Apply a pack and clear appearance overrides", .params_schema = "{\"id\":string}", .description_order = 108 },
+ .{ .id = .theme_apply, .wire_name = "theme.apply", .kind = .action, .description = "Apply a pack while preserving personal overrides", .params_schema = "{\"id\":string}", .description_order = 108 },
.{ .id = .theme_install, .wire_name = "theme.install", .kind = .action, .description = "Install a theme ZIP or directory using the isolated helper", .params_schema = "{\"path\":string,\"replace\"?:boolean}", .description_order = 109 },
.{ .id = .set_desktop_mode, .kind = .action, .description = "Set Canvas or Workspaces mode", .params_schema = "{\"mode\":\"canvas\" | \"workspaces\", \"persist\"?:boolean}", .description_order = 101 },
.{ .id = .set_workspace_layout, .kind = .action, .description = "Set a workspace to automatic tiling or floating", .params_schema = "{\"workspace\":number, \"automatic\":boolean}", .description_order = 102 },
diff --git a/src/server/wallpaper.zig b/src/server/wallpaper.zig
new file mode 100644
index 0000000..68755ba
--- /dev/null
+++ b/src/server/wallpaper.zig
@@ -0,0 +1,184 @@
+//! Server wallpaper and catalog loading, and icon wake.
+
+const std = @import("std");
+const Server = @import("../Server.zig");
+const wl = @import("wayland").server.wl;
+const ImageBuffer = @import("../ImageBuffer.zig");
+const ui_theme = @import("ui").theme;
+const wallpaper_load = @import("../wallpaper_load.zig");
+const wallpapers = @import("../wallpapers.zig");
+const startup = @import("../startup.zig");
+const png = @import("../png.zig");
+const log = std.log.scoped(.compositor);
+
+/// Runs on the compositor thread, woken by `IconService`'s worker thread
+/// finishing a decode (see `icon_service.zig`'s module comment). Does not
+/// know or care which consumer wanted the icon that just became ready — it
+/// rechecks live consumers. Chrome/taskbar memos and the menu's visible icon
+/// IDs avoid repainting when nothing relevant changed, so touching them is safe and
+/// avoids tracking per-request subscriber pointers into windows/panels that
+/// could be destroyed before their icon arrives.
+pub fn themeColorArgb(color: [4]f32) u32 {
+ const a = std.math.clamp(color[3], 0, 1);
+ const a8: u32 = @intFromFloat(@round(a * 255.0));
+ const r8: u32 = @intFromFloat(@round(std.math.clamp(color[0] * a, 0, 1) * 255.0));
+ const g8: u32 = @intFromFloat(@round(std.math.clamp(color[1] * a, 0, 1) * 255.0));
+ const b8: u32 = @intFromFloat(@round(std.math.clamp(color[2] * a, 0, 1) * 255.0));
+ return (a8 << 24) | (r8 << 16) | (g8 << 8) | b8;
+}
+
+pub fn applyDecodedWallpaper(server: *Server, decoded: png.Image) void {
+ const image = ImageBuffer.createFromDecoded(decoded) catch |err| {
+ log.warn("applyDecodedWallpaper: {}", .{err});
+ decoded.deinit(@import("../main.zig").gpa);
+ startup.markWallpaperFailed();
+ return;
+ };
+ const old = server.wallpaper;
+ server.wallpaper = image;
+ var it = server.outputs.iterator(.forward);
+ while (it.next()) |output| {
+ output.replaceWallpaper(image);
+ }
+ if (old) |prev| prev.base.drop();
+}
+
+pub fn handleCatalogWake(fd: c_int, mask: wl.EventMask, server: *Server) c_int {
+ _ = fd;
+ _ = mask;
+ if (!server.start_menu_catalog.drainCompletions()) return 0;
+ if (server.input.open_control_center) |cc| cc.refresh();
+ var it = server.outputs.iterator(.forward);
+ while (it.next()) |output| {
+ output.dock.invalidate();
+ if (output.start_menu) |sm| sm.refreshCatalog();
+ }
+ server.startup_warmup.onCatalogReady(server);
+ if (server.ipc) |ipc| ipc.wait_mgr.checkAll();
+ return 0;
+}
+
+/// Loads `[compositor] wallpaper` unless it is already shown or loading.
+/// The current wallpaper stays until the new one has decoded.
+pub fn reloadWallpaper(server: *Server) void {
+ server.loadWallpaper(0);
+}
+
+pub fn saveLoginTheme(server: *Server) void {
+ if (server.greeter_mode) return;
+ const dir = server.login_appearance_dir orelse return;
+ @import("../session/login_appearance.zig").saveTheme(@import("../main.zig").gpa, dir, ui_theme.global) catch |err| {
+ log.warn("could not save login appearance: {s}", .{@errorName(err)});
+ };
+}
+
+pub fn loadWallpaper(server: *Server, delay_ns: u64) void {
+ const gpa = @import("../main.zig").gpa;
+ const path = @import("../config_runtime/theme_pack.zig").wallpaperPath(server, gpa) catch |err| {
+ log.warn("wallpaper '{s}': {}", .{ server.config.compositor.wallpaper, err });
+ return;
+ };
+ if (server.wallpaper_source) |current| {
+ if (std.mem.eql(u8, current, path) and !server.wallpaper_failed) {
+ gpa.free(path);
+ return;
+ }
+ gpa.free(current);
+ }
+ server.wallpaper_source = path;
+ server.stopWallpaperLoad();
+
+ // A missing or broken choice falls back to the bundled image.
+ const default = wallpapers.resolve(gpa, server.io, "") catch null;
+ defer if (default) |d| gpa.free(d);
+ var candidates: [2][]const u8 = .{ path, undefined };
+ var count: usize = 1;
+ if (default) |d| {
+ if (!std.mem.eql(u8, d, path)) {
+ candidates[1] = d;
+ count = 2;
+ }
+ }
+ const loader = wallpaper_load.Loader.start(gpa, server.io, candidates[0..count], delay_ns, server.login_appearance_dir) catch |err| {
+ server.wallpaper_failed = true;
+ log.warn("wallpaper decode worker failed: {}", .{err});
+ server.forgetWallpaperSource();
+ return;
+ };
+ server.wallpaper_failed = false;
+ server.wallpaper_loader = loader;
+ startup.markWallpaperDecoding();
+ server.wallpaper_wake_source = server.wl_server.getEventLoop().addFd(*Server, loader.wakeFd(), .{ .readable = true }, handleWallpaperWake, server) catch |err| {
+ server.wallpaper_failed = true;
+ log.warn("could not register wallpaper wake fd: {}", .{err});
+ server.stopWallpaperLoad();
+ server.forgetWallpaperSource();
+ return;
+ };
+}
+
+pub fn stopWallpaperLoad(server: *Server) void {
+ if (server.wallpaper_wake_source) |source| source.remove();
+ server.wallpaper_wake_source = null;
+ if (server.wallpaper_loader) |loader| loader.deinit();
+ server.wallpaper_loader = null;
+}
+
+pub fn forgetWallpaperSource(server: *Server) void {
+ if (server.wallpaper_source) |path| @import("../main.zig").gpa.free(path);
+ server.wallpaper_source = null;
+}
+
+pub fn handleWallpaperWake(fd: c_int, mask: wl.EventMask, server: *Server) c_int {
+ _ = fd;
+ _ = mask;
+ const gpa = @import("../main.zig").gpa;
+ const loader = server.wallpaper_loader orelse return 0;
+ if (loader.take()) |result| {
+ startup.markWallpaperDecoded(loader.decode_ns);
+ if (server.wallpaper_displayed_path) |path| gpa.free(path);
+ server.wallpaper_displayed_path = gpa.dupe(u8, loader.paths[result.path_index]) catch null;
+ server.wallpaper_failed = result.path_index != 0;
+ applyDecodedWallpaper(server, result.image);
+ if (server.wallpaper_thumb) |old| old.deinit(gpa);
+ server.wallpaper_thumb = result.thumb;
+ } else if (loader.takeFailed()) {
+ server.wallpaper_failed = true;
+ // Later failures keep the wallpaper already on screen.
+ if (startup.marks.wallpaper_state != .presented) startup.markWallpaperFailed();
+ server.forgetWallpaperSource();
+ } else return 0;
+ // Removing the source from its own callback is safe; the worker is done.
+ server.stopWallpaperLoad();
+ server.reveal.onWallpaper();
+ if (server.input.open_control_center) |cc| cc.refresh();
+ if (server.ipc) |ipc| ipc.wait_mgr.checkAll();
+ return 0;
+}
+
+pub fn handleIconWake(fd: c_int, mask: wl.EventMask, server: *Server) c_int {
+ _ = fd;
+ _ = mask;
+ const service = server.icon_service orelse return 0;
+ service.drainCompletions();
+
+ const now = @import("../Toplevel.zig").nowMs();
+ var toplevel_it = server.world.toplevels.iterator(.forward);
+ while (toplevel_it.next()) |toplevel| {
+ toplevel.syncChrome(false, now) catch |err| {
+ log.warn("handleIconWake: syncChrome failed: {}", .{err});
+ };
+ }
+
+ var output_it = server.outputs.iterator(.forward);
+ while (output_it.next()) |output| {
+ if (output.taskbar) |bar| bar.notifyToplevelsChanged();
+ output.dock.invalidate();
+ if (output.start_menu) |sm| sm.iconsReady();
+ }
+ if (server.notifications) |mgr| mgr.iconsReady();
+ if (server.input.open_control_center) |cc| @import("../control_center/sections/appearance.zig").iconsReady(&cc.appearance);
+ if (server.tray) |tray| tray.changed();
+ server.scheduleFrames();
+ return 0;
+}
diff --git a/src/theme_main.zig b/src/theme_main.zig
index eb28a7a..4220c13 100644
--- a/src/theme_main.zig
+++ b/src/theme_main.zig
@@ -165,13 +165,7 @@ fn run(init: std.process.Init) !void {
defer cfg.deinit();
if (std.mem.eql(u8, cfg.theme_base, input)) {
changed_config = config_path;
- try @import("config").setting_save.resetThemeLayout(a, io, config_path);
- const dark = try packs.parse(a, @import("ui").theme_presets.bundled[0].bytes, "rediwm-dark", "");
- @import("config").loader.replaceThemeOverrides(a, io, config_path, dark.tokens, dark.tokens, "rediwm-dark");
- @import("config").loader.replaceTaskbarThemeSection(a, io, config_path, null);
- try @import("config").setting_save.saveCompositor(a, io, config_path, "wallpaper", "");
- try @import("config").setting_save.saveInput(a, io, config_path, "cursor_theme", "default");
- try @import("config").setting_save.saveCompositor(a, io, config_path, "dark_mode", true);
+ try @import("config").setting_save.selectTheme(a, io, config_path, "rediwm-dark", false);
}
}
} else |_| {}
diff --git a/tests/appearance_settings.py b/tests/appearance_settings.py
index bfd799e..0cf9186 100644
--- a/tests/appearance_settings.py
+++ b/tests/appearance_settings.py
@@ -371,14 +371,26 @@ def test_appearance_settings():
_ = ui.scroll_into_view("inactive_opacity")
assert any(w.get("label") == "100%" for w in widgets())
- # Bundled themes replace the palette live and persist their
- # optional overrides; returning to Dark clears those overrides.
+ # Picking a theme preserves personal edits, including the
+ # opacity set above. Only Reset discards those overrides.
+ theme_indices = {pack["id"]: i for i, pack in enumerate(ipc.query("theme.list")["packs"])}
+ light_index = theme_indices["rediwm-light"]
+ dark_index = theme_indices["rediwm-dark"]
+ before_switch = read_config()
+ previous_tokens = ipc.action("get_theme")["tokens"]
click_widget(ui.scroll_into_view("theme"))
ipc.key_press("Home")
- ipc.key_press("Down")
+ for _ in range(light_index):
+ ipc.key_press("Down")
ipc.key_press("Return")
ipc.wait_for_panel_settled("control_center")
- assert ui.scroll_into_view("theme")["selected_index"] == 1
+ assert ui.scroll_into_view("theme")["selected_index"] == light_index
+ expected_config = dict(before_switch, theme=dict(before_switch["theme"], base="rediwm-light"))
+ actual_config = read_config()
+ assert actual_config == expected_config, (actual_config, expected_config)
+ assert ipc.action("get_theme")["tokens"]["window_bg"] == previous_tokens["window_bg"]
+ click_widget(ui.scroll_into_view("theme_reset"))
+ ipc.wait_for_panel_settled("control_center")
tokens = ipc.action("get_theme")["tokens"]
for name, expected in {
"window_bg": [246 / 255, 247 / 255, 249 / 255, 0.75],
@@ -440,15 +452,16 @@ def test_appearance_settings():
assert ui.scroll_into_view("taskbar_theme")["selected_index"] == 0
click_widget(ui.scroll_into_view("taskbar_theme"))
ipc.key_press("Home")
- ipc.key_press("Down")
+ for _ in range(dark_index + 1):
+ ipc.key_press("Down")
ipc.key_press("Return")
ipc.wait_for_panel_settled("control_center")
- assert ui.scroll_into_view("taskbar_theme")["selected_index"] == 1
+ assert ui.scroll_into_view("taskbar_theme")["selected_index"] == dark_index + 1
assert max(taskbar_pixel("dark-taskbar.png")) < 90, "taskbar did not take the Dark taskbar theme"
tokens = ipc.action("get_theme")["tokens"]
assert all(abs(a - b) < 0.001 for a, b in zip(tokens["taskbar_bg"], [241 / 255, 244 / 255, 247 / 255, 0.94]))
assert all(abs(a - b) < 0.001 for a, b in zip(tokens["window_fg"], [31 / 255, 36 / 255, 48 / 255, 1]))
- assert ui.scroll_into_view("theme")["selected_index"] == 1
+ assert ui.scroll_into_view("theme")["selected_index"] == light_index
assert read_config()["taskbar_theme"] == {}
assert read_config()["theme"] == {"base": "rediwm-light"}
ipc.reload_config()
@@ -456,7 +469,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("taskbar_theme")["selected_index"] == 1
+ assert ui.scroll_into_view("taskbar_theme")["selected_index"] == dark_index + 1
assert max(taskbar_pixel("dark-taskbar-reloaded.png")) < 90
click_widget(ui.scroll_into_view("taskbar_theme"))
ipc.key_press("Home")
@@ -471,7 +484,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"] == 1
+ assert ui.scroll_into_view("theme")["selected_index"] == light_index
# 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")
@@ -510,9 +523,11 @@ def test_appearance_settings():
check_blue()
click_widget(ui.scroll_into_view("theme"))
ipc.key_press("Home")
+ for _ in range(dark_index):
+ ipc.key_press("Down")
ipc.key_press("Return")
ipc.wait_for_panel_settled("control_center")
- assert ui.scroll_into_view("theme")["selected_index"] == 0
+ assert ui.scroll_into_view("theme")["selected_index"] == dark_index
assert "shell_accent" not in read_config()["theme"]
assert "scrollbar_thumb_active" not in read_config()["theme"]
assert "start_button_logo_color" not in read_config()["theme"]
diff --git a/tests/theme_packs.py b/tests/theme_packs.py
index c2b1fd8..be80523 100644
--- a/tests/theme_packs.py
+++ b/tests/theme_packs.py
@@ -31,6 +31,14 @@ def helper(env, *args, ok=True):
return result
+def reset_theme(ipc):
+ ipc.action("open_appearance")
+ ipc.wait_for_panel_settled("control_center")
+ ui = UIDriver(ipc)
+ ui.click(ui.scroll_into_view("theme_reset"))
+ ipc.action("close_panel", {"panel": "control_center"})
+
+
def hostile_archives(tmp, env):
manifest = (FIXTURE / "theme.toml").read_bytes()
cases = {
@@ -154,7 +162,13 @@ def run():
config_path.write_text(config_path.read_text().replace("[compositor]", '[compositor]\ndock_enabled = false\ndock_position = "left"\ntaskbar_position = "bottom"\ndock_height = 48\ndock_hover_zoom = 1.5', 1))
wait_for(lambda: not UIDriver(ipc).widgets("dock"), "explicit dock override did not win")
assert ipc.get_shell_state()["taskbars"][0]["box"]["y"] > 0
- ipc.action("theme.apply", {"id": "gold"})
+ saved_layout = tomllib.loads(config_path.read_text())["compositor"]
+ for theme_id in ("rediwm-light", "gold"):
+ ipc.action("theme.apply", {"id": theme_id})
+ assert tomllib.loads(config_path.read_text())["compositor"] == saved_layout
+ assert not UIDriver(ipc).widgets("dock"), "switch lost explicit dock preference"
+ assert ipc.get_shell_state()["taskbars"][0]["box"]["y"] > 0
+ reset_theme(ipc)
wait_for(lambda: UIDriver(ipc).widgets("dock"), "reset did not restore Gold layout")
assert not {"dock_enabled", "dock_position", "dock_height", "dock_hover_zoom", "taskbar_position"} & tomllib.loads(config_path.read_text())["compositor"].keys()
# Every other bundled theme restores the standard bar and no dock.
@@ -179,7 +193,7 @@ def run():
assert ipc.query("theme.list")["active"] == "test-pack"
cfg = tomllib.loads((tmp / "rediwm-config.toml").read_text())
assert cfg["theme"] == {"base": "test-pack"}, cfg["theme"]
- # A pack arranges the taskbar's items; an explicit list wins until a theme is chosen again.
+ # A pack arranges the taskbar's items; an explicit list survives theme switches until Reset.
def clock_x():
items = ipc.get_shell_state()["taskbars"][0]["right_items"]
return next(i for i in items if i["name"] == "clock")["box"]["x"]
@@ -189,13 +203,18 @@ def run():
config_file.write_text(config_file.read_text().replace("[compositor]", f"[compositor]\ntaskbar_items = {default_items}", 1))
ipc.reload_config()
wait_for(lambda: clock_x() > 900, "explicit taskbar_items did not win over the pack")
- ipc.action("theme.apply", {"id": "test-pack"})
+ for theme_id in ("gold", "test-pack"):
+ ipc.action("theme.apply", {"id": theme_id})
+ assert tomllib.loads(config_file.read_text())["compositor"]["taskbar_items"] == json.loads(default_items)
+ assert clock_x() > 900
+ reset_theme(ipc)
assert "taskbar_items" not in tomllib.loads(config_file.read_text())["compositor"]
- wait_for(lambda: clock_x() < 300, "choosing the pack did not restore its arrangement")
- assert cfg["compositor"]["wallpaper"] == ""
- assert cfg["compositor"]["dark_mode"]
+ wait_for(lambda: clock_x() < 300, "reset did not restore the pack arrangement")
+ assert "wallpaper" not in cfg["compositor"]
+ assert "dark_mode" not in cfg["compositor"]
+ assert ipc.action("get_theme")["dark_mode"]
assert cfg["input"]["pointer_speed"] == .4
- assert cfg["input"]["cursor_theme"] == "rediwm-test-pack-cursors"
+ assert "cursor_theme" not in cfg["input"]
cursor_link = tmp / "data/icons/rediwm-test-pack-cursors"
assert cursor_link.is_symlink()
wait_for(lambda: ipc.query("get_wallpaper")["displayed_path"] == str(tmp / "data/rediwm/themes/test-pack/wallpapers/test.png"), "pack wallpaper was not presented")
@@ -280,8 +299,23 @@ def run():
assert (tmp / "data/rediwm/themes/exported/icons/folder.svg").read_bytes() == (pack / "icons/folder.svg").read_bytes()
assert (tmp / "data/rediwm/themes/exported/glyphs/wifi.svg").read_bytes() == (pack / "glyphs/wifi.svg").read_bytes()
helper(env, "remove", "exported")
- ipc.action("theme.apply", {"id": "test-pack"})
- assert tomllib.loads((tmp / "rediwm-config.toml").read_text())["theme"] == {"base": "test-pack"}
+ # Personal preferences survive a different pack, reapplying it,
+ # and reload. Unset tokens still come from the selected pack.
+ config_file.write_text(config_file.read_text()
+ .replace("[compositor]", '[compositor]\nwallpaper = "wallpaper-gold.png"\ndark_mode = false', 1)
+ .replace("[input]", '[input]\ncursor_theme = "default"', 1)
+ + '\n[taskbar_theme]\nclock_bold = true\n')
+ ipc.reload_config()
+ saved = tomllib.loads(config_file.read_text())
+ for theme_id in ("gold", "test-pack", "test-pack"):
+ ipc.action("theme.apply", {"id": theme_id})
+ ipc.reload_config()
+ expected = dict(saved, theme=dict(saved["theme"], base=theme_id))
+ assert tomllib.loads(config_file.read_text()) == expected
+ look = ipc.action("get_theme")
+ assert not look["dark_mode"]
+ assert all(abs(a - b) < .001 for a, b in zip(look["tokens"]["accent"], [17/255, 34/255, 51/255, 1]))
+ wait_for(lambda: (ipc.query("get_wallpaper")["displayed_path"] or "").endswith("/wallpaper-gold.png"), "switch lost wallpaper override")
ipc.action("open_appearance")
ui = UIDriver(ipc)
ui.wait_present("theme_reset")
@@ -298,17 +332,29 @@ def run():
fg = tuple(round(c*255) for c in ipc.action("get_theme")["tokens"]["window_fg"][:3])
assert sum(color == fg for color in glyph.getdata()) > 350, "shell glyph override missing"
ui.click("theme_reset")
+ reset_config = tomllib.loads(config_file.read_text())
+ assert reset_config["theme"] == {"base": "test-pack"}
+ assert "taskbar_theme" not in reset_config
+ assert "wallpaper" not in reset_config["compositor"]
+ assert "dark_mode" not in reset_config["compositor"]
+ assert "cursor_theme" not in reset_config["input"]
+ assert reset_config["input"]["pointer_speed"] == .4
+ assert ipc.action("get_theme")["dark_mode"]
+ wait_for(lambda: (ipc.query("get_wallpaper")["displayed_path"] or "").endswith("/test.png"), "reset did not restore pack wallpaper")
assert ipc.query("theme.list")["active"] == "test-pack"
ipc.action("close_panel", {"panel": "control_center"})
ipc.action("theme.apply", {"id": "rediwm-light"})
assert not ipc.action("get_theme")["dark_mode"]
wait_for(lambda: "test-pack" not in (ipc.query("get_wallpaper")["displayed_path"] or ""), "wallpaper did not restore")
ipc.action("theme.apply", {"id": "test-pack"})
+ ipc.action("set_accent_color", {"color": "#112233"})
+ before_remove = tomllib.loads(config_file.read_text())
ipc.action("open_appearance")
ui.click(ui.scroll_into_view("theme_remove"))
wait_for(lambda: all(p["id"] != "test-pack" for p in ipc.query("theme.list")["packs"]), "active pack was not removed")
assert ipc.query("theme.list")["active"] == "rediwm-dark"
ipc.action("close_panel", {"panel": "control_center"})
+ assert tomllib.loads(config_file.read_text()) == dict(before_remove, theme=dict(before_remove["theme"], base="rediwm-dark"))
assert not cursor_link.exists()
assert all(p["id"] != "test-pack" for p in ipc.query("theme.list")["packs"])
# A user pack can shadow a built-in ID; removal restores embedded art.
@@ -318,12 +364,12 @@ def run():
manifest_path.write_text(manifest_path.read_text().replace('id = "test-pack"', 'id = "rediwm-dark"'))
ipc.action("theme.install", {"path": str(shadow)})
ipc.action("theme.apply", {"id": "rediwm-dark"})
- ipc.action("open_appearance")
- ui.click(ui.scroll_into_view("theme_remove"))
+ before_remove = tomllib.loads(config_file.read_text())
+ helper(dict(env, REDIWM_CONFIG=str(config_file)), "remove", "rediwm-dark")
+ assert tomllib.loads(config_file.read_text()) == before_remove
wait_for(lambda: not next(p for p in ipc.query("theme.list")["packs"] if p["id"] == "rediwm-dark")["user_installed"] and ipc.action("get_theme")["tokens"]["start_button_icon"] == "", "embedded pack was not restored")
tokens = ipc.action("get_theme")["tokens"]
assert tokens["start_button_icon"] == "", tokens["start_button_icon"]
- ipc.action("close_panel", {"panel": "control_center"})
# Missing pack falls back; the config remains usable.
config = tmp / "rediwm-config.toml"
config.write_text(config.read_text().replace('base = "rediwm-dark"', 'base = "missing-pack"'))