RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
taskbar updates
oxydizerf42438bf9732
diff --git a/TESTING.md b/TESTING.mdindex 58a83fe..7016a68 100644--- a/TESTING.md+++ b/TESTING.md@@ -401,4 +401,6 @@ Keyring unlock and browser/OBS sharing remain unverified. Seefailures, and [screen sharing](docs/screen-sharing.md#remaining-qualification)for the remaining capture acceptance checks.+`python3 tests/taskbar_shape.py` covers the floating taskbar: the Appearance sliders for gap from the edge, length and corner radius, the same geometry from the theme file on both edges, the strip a maximized window leaves, and the pixels of the rounded ends.+`python3 tests/theme_packs.py` covers theme ZIP installation, refusal of unsafe paths/links/special files/bombs, pack discovery, base plus overrides, live wallpaper and folder icons, reset, cursors and removal in isolated data/config/state directories.diff --git a/docs/themes.md b/docs/themes.mdindex 50fb037..4f7e538 100644--- a/docs/themes.md+++ b/docs/themes.md@@ -51,7 +51,10 @@ icon_theme = "Adwaita" # optional installed theme, behind icons/cursor_theme = "pack" # cursors/, or an installed cursor-theme name```-`[taskbar_theme]` optionally supplies the taskbar's own colours. Unknown+`[taskbar_theme]` optionally supplies the taskbar's own colours. A pack can+also float the bar with `[theme]` tokens `taskbar_edge_gap`, `taskbar_length`,+`taskbar_radius` and `taskbar_outline_width`, and colour its outline with+`taskbar_outline` (see `docs/wiki/Theme.md`). Unknown`[theme]` tokens are logged and skipped. Relative asset paths stay inside thepack; absolute paths, `..` and symlinks are refused. The only symlink exceptionis a cursor alias in `cursors/cursors/` whose target is a regular cursor file@@ -104,6 +107,9 @@ Packs may include this optional section:```toml[layout]taskbar_position = "top" # top or bottom+# Section (left, center, right), order and visibility of each taskbar item, as+# in [compositor]; prefix an entry with - to hide it. All seven items are listed.+taskbar_items = ["left:start", "left:clock", "center:windows", "right:tray", "right:battery", "right:network", "right:volume"]dock_enabled = truedock_position = "bottom" # top, bottom, left or rightdock_height = 76 # thickness; 48–96 logical pixels@@ -112,8 +118,9 @@ dock_hover_zoom = 1.05 # 1.0–1.5; 1.0 disables hover enlargementOnly these appearance settings are accepted here. Resolution is compositordefaults → pack layout → explicit `[compositor]` settings. Choosing a theme-or **Reset to theme** clears these personal overrides; a pack without-layout values returns to the ordinary bottom taskbar and disabled dock.+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.Hidden dock entries and application preferences are preserved. **Save look…**includes the current layout.diff --git a/docs/wiki/Configuration.md b/docs/wiki/Configuration.mdindex 448f60e..31e9009 100644--- a/docs/wiki/Configuration.md+++ b/docs/wiki/Configuration.md@@ -82,6 +82,10 @@ For example, `taskbar_items = ["left:start", "center:windows", "right:tray","right:battery", "right:network", "right:volume", "right:clock"]` is the default.Use `"-right:clock"` to hide the clock. Existing four-item status lists stillload, preserving their order and visibility alongside Start and the window list.+A theme pack can set the same list in its `[layout]` section+(see `docs/themes.md`); a `taskbar_items` of your own here takes precedence over+the theme's until you choose a theme again. The bar's gap from the screen edge,+length, corner radius and outline are `[theme]` tokens (`docs/wiki/Theme.md`).| Key | Default | Notes || --- | --- | --- |diff --git a/docs/wiki/Theme.md b/docs/wiki/Theme.mdindex 8ac7f23..12361bd 100644--- a/docs/wiki/Theme.md+++ b/docs/wiki/Theme.md@@ -16,7 +16,7 @@ Appearance also has a **Taskbar theme** picker under Theme, with the samepresets plus "Same as theme". It gives the taskbar the preset's colours andleaves every other surface on the theme above. It is saved as a`[taskbar_theme]` section holding only these keys: `taskbar_bg`,-`taskbar_surface`, `taskbar_hover`, `taskbar_border`, `border_soft`,+`taskbar_surface`, `taskbar_hover`, `taskbar_border`, `taskbar_outline`, `border_soft`,`surface_hover`, `window_fg`, `window_dim`, `danger`, `window_close_hover`,`start_button_hover`, `start_button_indicator`, `start_button_logo_color` andthe `battery_*` colours. Unlisted keys are ignored, so a whole theme file's@@ -166,6 +166,7 @@ geometry retain their content or structural dimensions.| `taskbar_surface` | `"rgba(255,255,255,0.025)"` || `taskbar_hover` | `"rgba(255,255,255,0.05)"` || `taskbar_border` | `"rgba(255,255,255,0.07)"` |+| `taskbar_outline` | `unset` || `on_accent` | `"rgba(8,33,28,1)"` || `border_focus` | `"rgba(94,234,212,0.4)"` || `caret` | `unset` |@@ -278,6 +279,10 @@ Numeric tokens accept 0–4096 unless constrained below. Fractions ending in| `chrome_control_gap` | `4.0` || `taskbar_title_size` | `12.5` || `taskbar_size` | `48.0` |+| `taskbar_edge_gap` | `0.0` |+| `taskbar_length` | `100.0` |+| `taskbar_radius` | `0.0` |+| `taskbar_outline_width` | `1.0` || `chip_gap` | `4.0` || `chip_width` | `220.0` || `start_button_gap` | `4.0` |@@ -362,11 +367,24 @@ Numeric tokens accept 0–4096 unless constrained below. Fractions ending in| `chrome_height` | 28–84 || `chrome_control_gap` | 0–24 || `chip_width` | 64–400 |+| `taskbar_length` | 20–100 (percent) |+| `taskbar_outline_width` | 0–8 || `scrollbar_width` | 4–24 || `scrollbar_rest_width`, `scrollbar_active_width` | 0.25–1.125 times the configured width || `image_checker_size` | 1–128 |-`taskbar_height` is an alias for `taskbar_size`. Layouts cap some dimensions to+`taskbar_height` is an alias for `taskbar_size`. The taskbar is a flush,+full-width, square bar by default. `taskbar_edge_gap` (0–64 logical px, in+Appearance as **Taskbar gap from edge**) floats it off the screen edge it sits+on, `taskbar_length` (a percentage of that edge, centred; never narrower than+its items need, 420 px) shortens it, and `taskbar_radius` (px; a pill at half+the bar's height) rounds its corners. Windows and panels treat the bar and its+gap as reserved space. `taskbar_outline_width` is the thickness of the bar's own+outline and the optional colour `taskbar_outline` its colour (unset: `border_soft`,+which drew the bar's single hairline before). A flush bar draws the outline on the+side facing the windows only; a floating or rounded one draws it all round.+`taskbar_border` stays the colour of the window buttons' and battery's outlines.+The Radius presets (Sharp, Default, Round) leave `taskbar_radius` alone. Layouts cap some dimensions tofit their available space. The scrollbar reserves room for its maximum width;`slider_*` keys control slider geometry while sharing the scrollbar feedback.diff --git a/src/Output.zig b/src/Output.zigindex 728a440..2bfaef2 100644--- a/src/Output.zig+++ b/src/Output.zig@@ -695,7 +695,8 @@ pub fn atLayout(server: *Server, lx: f64, ly: f64) ?*Output {}// The output's usable area for compositor-driven placement (currently just-// maximize), excluding the taskbar's reserved strip.+// maximize), excluding the taskbar's reserved strip: the bar and its gap. A+// short bar leaves the strip beside it whole.pub fn usableBox(output: *Output) wlr.Box {var box: wlr.Box = if (output.idle_blanked) output.cached_box else blk: {var b: wlr.Box = undefined;@@ -703,8 +704,8 @@ pub fn usableBox(output: *Output) wlr.Box {break :blk b;};if (output.taskbar) |bar| {- if (output.server.config.compositor.taskbar_position == .top) box.y += bar.box.height;- box.height = @max(1, box.height - bar.box.height);+ if (output.server.config.compositor.taskbar_position == .top) box.y += bar.reserved;+ box.height = @max(1, box.height - bar.reserved);}return box;}diff --git a/src/Server.zig b/src/Server.zigindex 7f6df72..a777dff 100644--- a/src/Server.zig+++ b/src/Server.zig@@ -1179,15 +1179,17 @@ pub fn refreshTaskbars(server: *Server) void {server.taskbar_hold_pending = true;return;}- const desired_h = Taskbar.barHeight();+ var strip_moved = false;var it = server.outputs.iterator(.forward);while (it.next()) |output| {output.dock.invalidate();if (output.taskbar) |bar| {- if (bar.box.height != desired_h) {- var box: wlr.Box = undefined;- server.output_layout.getBox(output.wlr_output, &box);+ var box: wlr.Box = undefined;+ server.output_layout.getBox(output.wlr_output, &box);+ if (box.width > 0 and box.height > 0 and !bar.isPlaced(box)) {+ const strip = bar.reserved;bar.relayout(box);+ strip_moved = strip_moved or bar.reserved != strip;if (server.input.open_start_menu) |sm| {if (sm.wlr_output == output.wlr_output) sm.relayout();}@@ -1197,6 +1199,7 @@ pub fn refreshTaskbars(server: *Server) void {}server.taskbar_tree.node.placeBelow(&server.overlay_tree.node);server.updateTaskbarFullscreenVisibility();+ if (strip_moved) server.applyTaskbarPosition();}// Coalesces taskbar refreshes until the matching `releaseTaskbars`, which@@ -1224,13 +1227,16 @@ pub fn releaseTaskbars(server: *Server) void {// hot-reload), not the frequent per-window-event ones, so the extra full// raster pass here is rare and not a hot-path concern.pub fn refreshTaskbarsGeometry(server: *Server) void {+ var strip_moved = false;var it = server.outputs.iterator(.forward);while (it.next()) |output| {output.dock.invalidate();if (output.taskbar) |bar| {var box: wlr.Box = undefined;server.output_layout.getBox(output.wlr_output, &box);+ const strip = bar.reserved;bar.relayout(box);+ strip_moved = strip_moved or bar.reserved != strip;if (server.input.open_start_menu) |sm| {if (sm.wlr_output == output.wlr_output) sm.relayout();}@@ -1238,9 +1244,11 @@ pub fn refreshTaskbarsGeometry(server: *Server) void {}server.taskbar_tree.node.placeBelow(&server.overlay_tree.node);server.updateTaskbarFullscreenVisibility();+ if (strip_moved) server.applyTaskbarPosition();}-/// Apply a changed taskbar edge to panels, reserved space and fixed layouts.+/// Apply a changed taskbar edge, or a changed strip (size or gap), to panels,+/// reserved space and fixed layouts.pub fn applyTaskbarPosition(server: *Server) void {Output.syncLayout(server);var it = server.world.toplevels.iterator(.forward);@@ -1257,7 +1265,7 @@ pub fn applyTaskbarPosition(server: *Server) void {const usable = output.usableBox();const position = server.world.toLayout(@floatFromInt(toplevel.x), @floatFromInt(toplevel.y));const top: f64 = @floatFromInt(usable.y);- const bar_height: f64 = if (output.taskbar) |bar| @floatFromInt(bar.box.height) else 0;+ const bar_height: f64 = if (output.taskbar) |bar| @floatFromInt(bar.reserved) else 0;if (position.y >= top - bar_height and position.y < top) {const target = server.world.toWorld(position.x, top);toplevel.finishMoveAnimation();diff --git a/src/Taskbar.zig b/src/Taskbar.zigindex b9c97ea..dffe091 100644--- a/src/Taskbar.zig+++ b/src/Taskbar.zig@@ -30,6 +30,7 @@ const taskbar_items = @import("config").taskbar_items;const battery_highlight = @import("taskbar/battery_highlight.zig");const battery_badge = @import("ui").widgets.battery;const start_button = @import("taskbar/start_button.zig");+const shape = @import("taskbar/shape.zig");const text = @import("ui").text;const ui_theme = @import("ui").theme;const stats = @import("ipc/stats.zig");@@ -50,6 +51,19 @@ pub const bar_height: i32 = default_bar_height;pub fn barHeight() i32 {return @intFromFloat(@round(ui_theme.global.taskbar_size));}+/// Logical px between the bar and the output edge it sits on, kept small+/// enough that a bad theme can't push the bar off the screen.+const max_edge_gap: f32 = 64;+fn edgeGap() i32 {+ return @intFromFloat(@round(std.math.clamp(ui_theme.global.taskbar_edge_gap, 0, max_edge_gap)));+}+/// What the bar claims from its output edge: its height and its gap.+pub fn reservedHeight() i32 {+ return barHeight() + edgeGap();+}+fn barRadius() f32 {+ return shape.effectiveRadius(ui_theme.global.taskbar_radius, barHeight());+}const edge_pad: i32 = 20;// Anchor sizes at the original 54px bar / 8px item gap (a// 42px-tall chip with a 23px icon tile). Every other taskbar-item size below@@ -113,7 +127,14 @@ pub fn startButtonGap() i32 {return @intFromFloat(@round(ui_theme.global.start_button_gap));}pub fn startButtonLeft() i32 {- return startButtonGap();+ return startButtonGap() + endInset();+}+// Items keep clear of the curve at either end of a rounded bar.+fn endInset() i32 {+ return shape.cornerInset(barRadius(), chipVerticalMargin());+}+fn rightPad() i32 {+ return @max(edge_pad, endInset() + startButtonGap());}pub fn startButtonBox(bar: *Taskbar) wlr.Box {const size = buttonSize();@@ -167,6 +188,12 @@ battery_shimmer: battery_highlight.Highlight = .{},node_data: scene_data.SceneData = undefined,timer: *wl.EventSource,box: wlr.Box = .{ .x = 0, .y = 0, .width = 0, .height = default_bar_height },+// The strip it claims from the output edge, as last laid out: `box.height`+// plus the gap. Beside a short bar the strip stays whole.+reserved: i32 = default_bar_height,+// The original look: edge to edge, on the output's edge, square.+flush: bool = true,+glass_effect: ?*glass.Effect = null,item_layout: taskbar_items.Layout = .{},dirty: bool = true,paint_causes: u8 = 0,@@ -386,7 +413,7 @@ pub fn create(server: *Server, wlr_output: *wlr.Output) !*Taskbar {// Preserve glyph coverage when fractional-scale destination rounding// makes the scene box differ from the raster by a device pixel.buffer_node.setFilterMode(.bilinear);- _ = glass.Engine.attach(server.glass_engine, buffer_node, &buffer_node.node, .taskbar);+ const glass_effect = glass.Engine.attach(server.glass_engine, buffer_node, &buffer_node.node, .taskbar);bar.* = .{.server = server,@@ -399,6 +426,7 @@ pub fn create(server: *Server, wlr_output: *wlr.Output) !*Taskbar {.app_tray_node = app_tray_node,.capture_node = capture_node,.battery_node = battery_node,+ .glass_effect = glass_effect,.battery_state = battery.read(server.io, gpa),.network_offline = if (server.network) |network| network.offline() else false,.clock_minute = @divFloor(c_time.time(null), 60),@@ -635,18 +663,33 @@ fn updateClockStrings(bar: *Taskbar) bool {return true;}+/// Where the bar belongs on `output_box` under the current theme and edge.+pub fn placement(bar: *Taskbar, output_box: wlr.Box) shape.Placement {+ return shape.place(output_box, .{+ .height = barHeight(),+ .edge_gap = edgeGap(),+ .length = ui_theme.global.taskbar_length,+ .radius = barRadius(),+ .top = bar.server.config.compositor.taskbar_position == .top,+ });+}++/// Whether the bar already sits where `placement` puts it.+pub fn isPlaced(bar: *Taskbar, output_box: wlr.Box) bool {+ const wanted = bar.placement(output_box);+ return std.meta.eql(bar.box, wanted.box) and bar.reserved == wanted.reserved;+}+// Repositions the strip along the configured output edge.pub fn relayout(bar: *Taskbar, output_box: wlr.Box) void {if (bar.server.input.window_menu.bar == bar) bar.server.input.window_menu.close();if (bar.server.tray) |tray_mgr| tray_mgr.closeMenu();bar.refreshStartLogo();- const h = barHeight();- bar.box = .{- .x = output_box.x,- .y = if (bar.server.config.compositor.taskbar_position == .top) output_box.y else output_box.y + output_box.height - h,- .width = output_box.width,- .height = h,- };+ const placed = bar.placement(output_box);+ bar.box = placed.box;+ bar.reserved = placed.reserved;+ bar.flush = shape.flush(output_box, bar.box, barRadius());+ glass.Effect.configure(bar.glass_effect, barRadius(), 1);bar.tree.node.setPosition(bar.box.x, bar.box.y);const now_ms = nowMs();bar.pointerLeave();@@ -766,7 +809,7 @@ fn calculateLayout(bar: *Taskbar, window_count: usize) taskbar_items.Layout {if (bar.capturing()) items.visible[@intFromEnum(taskbar_items.Item.tray)] = true;const windows_width = if (window_count == 0) 0 else @as(f32, @floatFromInt(window_count)) * @max(@as(f32, @floatFromInt(chipSize())), ui_theme.global.chip_width) +@as(f32, @floatFromInt(window_count - 1)) * @as(f32, @floatFromInt(chipGap()));- return taskbar_items.arrange(items, @floatFromInt(startButtonLeft()), @floatFromInt(bar.box.width - edge_pad), @as(f32, @floatFromInt(bar.box.width)) / 2, .{ if (bar.battery_state.percent != null) battery_width else 0, @floatFromInt(trayHit()), @floatFromInt(trayHit()), bar.clockColumnWidth(), @floatFromInt(buttonSize()), windows_width, app_width + capture_width }, tray_gap, clock_gap);+ return taskbar_items.arrange(items, @floatFromInt(startButtonLeft()), @floatFromInt(bar.box.width - rightPad()), @as(f32, @floatFromInt(bar.box.width)) / 2, .{ if (bar.battery_state.percent != null) battery_width else 0, @floatFromInt(trayHit()), @floatFromInt(trayHit()), bar.clockColumnWidth(), @floatFromInt(buttonSize()), windows_width, app_width + capture_width }, tray_gap, clock_gap);}pub fn itemBox(bar: *Taskbar, item: taskbar_items.Item) ?wlr.Box {@@ -1366,6 +1409,10 @@ const Color = struct {fn hairline() Color {return fromRgba(ui_theme.taskbar(.border_soft));}+ // The bar's own outline; unset it is the hairline `border_soft` always drew.+ fn outline() Color {+ return fromRgba(ui_theme.taskbar(.taskbar_outline) orelse ui_theme.taskbar(.border_soft));+ }fn chip_idle() Color {return fromRgba(ui_theme.taskbar(.taskbar_surface));}@@ -1727,11 +1774,14 @@ fn renderPart(bar: *Taskbar, now_ms: i64, part: Part, origin_x: i32, origin_y: ifn paintPartPixel(bar: *Taskbar, sampled_start: start_button.Paint, hover: f32, press: f32, part_x: f32, part_width: f32, part: Part, px: f32, py: f32, scale: f32) Color {switch (part) {- .background => {- var color = Color.bar_fill();- if (py < 1) color = Color.hairline().over(color);- return color;- },+ .background => return shape.background(Color, .{+ .width = @floatFromInt(bar.box.width),+ .height = @floatFromInt(bar.box.height),+ .radius = barRadius(),+ .outline = ui_theme.global.taskbar_outline_width,+ .flush = bar.flush,+ .top = bar.server.config.compositor.taskbar_position == .top,+ }, px, py, scale, Color.bar_fill(), Color.outline()),.start => {const btn_size = buttonSize();var color = Color{ .r = 0, .g = 0, .b = 0, .a = 0 };@@ -2285,7 +2335,7 @@ test "battery artwork remains centered as taskbar height and item gap change" {pub fn appTrayCount(bar: *Taskbar) usize {if (!bar.itemShown(.tray)) return 0;const mgr = bar.server.tray orelse return 0;- var fixed: f32 = @floatFromInt(edge_pad + startButtonLeft() + 80 + 5 * clock_gap);+ var fixed: f32 = @floatFromInt(rightPad() + startButtonLeft() + 80 + 5 * clock_gap);if (bar.itemShown(.start)) fixed += @floatFromInt(buttonSize());if (bar.itemShown(.battery)) fixed += battery_width;if (bar.itemShown(.network)) fixed += @floatFromInt(trayHit());diff --git a/src/battery_popup.zig b/src/battery_popup.zigindex 0fd6406..3313da5 100644--- a/src/battery_popup.zig+++ b/src/battery_popup.zig@@ -77,7 +77,7 @@ pub const Popup = struct {const anchor = bar.itemBox(.battery) orelse return;var box: wlr.Box = undefined;self.output.server.output_layout.getBox(self.output.wlr_output, &box);- const available_h = @max(1, box.height - @import("Taskbar.zig").barHeight() - 24);+ const available_h = @max(1, box.height - @import("Taskbar.zig").reservedHeight() - 24);self.factor = @min(1, @min(@as(f32, @floatFromInt(@max(1, box.width - 24))) / 368, @as(f32, @floatFromInt(available_h)) / 496));const width: i32 = @max(1, @as(i32, @intFromFloat(@round(368 * self.factor))));const height: i32 = @max(1, @as(i32, @intFromFloat(@round(496 * self.factor))));diff --git a/src/calendar.zig b/src/calendar.zigindex ec90ca5..70d4a71 100644--- a/src/calendar.zig+++ b/src/calendar.zig@@ -83,7 +83,7 @@ pub const Calendar = struct {const rows = @max(5, @divTrunc(first + days + 6, 7));const body_height: f32 = @floatFromInt(204 + rows * 38);const full_height = body_height + 16;- const available_h = @max(1, box.height - @import("Taskbar.zig").barHeight() - 24);+ const available_h = @max(1, box.height - @import("Taskbar.zig").reservedHeight() - 24);self.factor = @min(1, @min(@as(f32, @floatFromInt(@max(1, box.width - 24))) / 368, @as(f32, @floatFromInt(available_h)) / full_height));const width: i32 = @intFromFloat(@round(368 * self.factor));const height: i32 = @intFromFloat(@round(full_height * self.factor));diff --git a/src/config/default.zig b/src/config/default.zigindex 5b3dba2..bf7a742 100644--- a/src/config/default.zig+++ b/src/config/default.zig@@ -32,6 +32,11 @@ pub const source =\\scrollbar_width = 8.0 # every scrollbar, 4–24 logical px\\selection_alpha = 0.35 # highlight opacity when it follows the accent\\taskbar_size = 44.0 # taskbar height in pixels (36.0 to 84.0)+ \\# taskbar_edge_gap = 0 # floating taskbar: px between it and the screen edge (0–64)+ \\# taskbar_length = 100 # percent of the screen edge it spans, centred (20–100)+ \\# taskbar_radius = 0 # corner radius in px; a pill at half the taskbar size+ \\# taskbar_outline_width = 1 # the bar's outline, px (0–8); colour: taskbar_outline+ \\# taskbar_outline = "rgba(255,255,255,0.06)" # unset follows border_soft\\chip_width = 220.0 # preferred window item width, 64–400px; shrinks to fit\\chip_gap = 4.0 # gap between taskbar window-item pills; also sets\\ # each pill's top/bottom margin in the bar (capped)diff --git a/src/config/theme_pack.zig b/src/config/theme_pack.zigindex f004ec9..63e9820 100644--- a/src/config/theme_pack.zig+++ b/src/config/theme_pack.zig@@ -5,17 +5,21 @@ const theme = @import("ui").theme;const presets = @import("ui").theme_presets;const A = std.mem.Allocator;const Io = std.Io;+const TaskbarItems = @import("taskbar_items.zig").Config;/// Only appearance-related layout defaults belong to packs. User overrides/// remain in [compositor]; packs cannot inject other compositor settings.pub const Layout = struct {taskbar_position: ?@import("types.zig").TaskbarPosition = null,+ /// Which section (left, centre or right) each taskbar item sits in, in+ /// what order and whether it shows: the `[compositor]` list's own syntax.+ taskbar_items: ?TaskbarItems = null,dock_enabled: ?bool = null,dock_position: ?@import("types.zig").DockPosition = null,dock_height: ?u32 = null,dock_hover_zoom: ?f32 = null,- pub const keys = .{ "taskbar_position", "dock_enabled", "dock_position", "dock_height", "dock_hover_zoom" };+ pub const keys = .{ "taskbar_position", "taskbar_items", "dock_enabled", "dock_position", "dock_height", "dock_hover_zoom" };pub fn apply(self: Layout, compositor: anytype) void {inline for (keys) |key| if (@field(self, key)) |value| {@@ -26,6 +30,8 @@ pub const Layout = struct {fn parseKey(self: *Layout, key: []const u8, value: []const u8) !void {if (std.mem.eql(u8, key, "taskbar_position")) {self.taskbar_position = std.meta.stringToEnum(@import("types.zig").TaskbarPosition, try theme.unquote(value)) orelse return error.InvalidLayout;+ } else if (std.mem.eql(u8, key, "taskbar_items")) {+ self.taskbar_items = TaskbarItems.parse(value) catch return error.InvalidLayout;} else if (std.mem.eql(u8, key, "dock_enabled")) {self.dock_enabled = if (std.mem.eql(u8, value, "true")) true else if (std.mem.eql(u8, value, "false")) false else return error.InvalidLayout;} else if (std.mem.eql(u8, key, "dock_position")) {@@ -42,8 +48,10 @@ pub const Layout = struct {}pub fn write(a: A, bytes: *std.ArrayList(u8), compositor: anytype) !void {- const text = try std.fmt.allocPrint(a, "[layout]\ntaskbar_position = \"{s}\"\ndock_enabled = {}\ndock_position = \"{s}\"\ndock_height = {d}\ndock_hover_zoom = {d}\n", .{- @tagName(compositor.taskbar_position), compositor.dock_enabled, @tagName(compositor.dock_position), compositor.dock_height, compositor.dock_hover_zoom,+ const items = try compositor.taskbar_items.serialize(a);+ defer a.free(items);+ const text = try std.fmt.allocPrint(a, "[layout]\ntaskbar_position = \"{s}\"\ntaskbar_items = {s}\ndock_enabled = {}\ndock_position = \"{s}\"\ndock_height = {d}\ndock_hover_zoom = {d}\n", .{+ @tagName(compositor.taskbar_position), items, compositor.dock_enabled, @tagName(compositor.dock_position), compositor.dock_height, compositor.dock_hover_zoom,});defer a.free(text);try bytes.appendSlice(a, text);@@ -255,6 +263,27 @@ test "pack metadata, future tokens and unsafe paths" {const exported = try parse(a, bytes.items, "test", "");try std.testing.expectEqual(pack.layout.dock_position, exported.layout.dock_position);}+ {+ // A pack arranges the taskbar's items, and an export carries them.+ const pack = try parse(a, "[layout]\ntaskbar_items = [\"left:start\", \"left:windows\", \"-center:tray\", \"right:battery\", \"right:network\", \"right:volume\", \"center:clock\"]\n", "test", "");+ const arranged = pack.layout.taskbar_items.?;+ try std.testing.expectEqual(@import("taskbar_items.zig").Section.left, arranged.section(.windows));+ try std.testing.expectEqual(@import("taskbar_items.zig").Section.center, arranged.section(.clock));+ try std.testing.expect(!arranged.shown(.tray));+ var compositor = @import("loader.zig").CompositorConfig{};+ pack.layout.apply(&compositor);+ try std.testing.expectEqualDeep(arranged, compositor.taskbar_items);+ var bytes: std.ArrayList(u8) = .empty;+ try Layout.write(a, &bytes, compositor);+ const exported = try parse(a, bytes.items, "test", "");+ try std.testing.expectEqualDeep(arranged, exported.layout.taskbar_items.?);+ // No list leaves the user's own arrangement alone.+ try std.testing.expectEqual(@as(?TaskbarItems, null), (try parse(a, "[layout]\ntaskbar_position = \"top\"\n", "test", "")).layout.taskbar_items);+ }+ for ([_][]const u8{ "taskbar_items = []", "taskbar_items = [\"left:start\"]", "taskbar_items = [\"middle:start\", \"windows\", \"tray\", \"battery\", \"network\", \"volume\", \"clock\"]", "taskbar_items = \"left:start\"" }) |line| {+ const bytes = try std.fmt.allocPrint(a, "[layout]\n{s}\n", .{line});+ try std.testing.expectError(error.InvalidLayout, parse(a, bytes, "test", ""));+ }for ([_][]const u8{ "dock_height = 47", "dock_height = 97", "dock_hover_zoom = 0.99", "dock_hover_zoom = 1.51", "dock_hover_zoom = nan", "dock_enabled = 1", "dock_position = \"center\"", "taskbar_position = \"left\"", "xwayland = true" }) |line| {const bytes = try std.fmt.allocPrint(a, "[layout]\n{s}\n", .{line});try std.testing.expectError(error.InvalidLayout, parse(a, bytes, "test", ""));diff --git a/src/control_center/sections/appearance.zig b/src/control_center/sections/appearance.zigindex afced54..c9544b3 100644--- a/src/control_center/sections/appearance.zig+++ b/src/control_center/sections/appearance.zig@@ -90,6 +90,9 @@ const px_menu_width = 13;const px_menu_height = 14;const px_dock_height = 15;const px_dock_hover_zoom = 16;+const px_taskbar_edge_gap = 17;+const px_taskbar_length = 18;+const px_taskbar_radius = 19;pub const Section = struct {cc: *panel.ControlCenter = undefined,@@ -171,8 +174,8 @@ pub const Section = struct {inactive_opacity_header_children: [2]Widget = undefined,inactive_opacity_group_children: [2]Widget = undefined,inactive_opacity_value_buf: [16]u8 = undefined,- px: [17]PxControl = undefined,- taskbar_section_children: [8]Widget = undefined,+ px: [20]PxControl = undefined,+ taskbar_section_children: [11]Widget = undefined,taskbar_position_children: [2]Widget = undefined,items_children: [5]Widget = undefined,items_section_children: [3][2]Widget = undefined,@@ -290,7 +293,12 @@ fn sectionLabel(content: []const u8) Widget {/// Builds one "label ... value / slider" pixel-value row and formats its/// initial value into `out.px[idx].value_buf`.fn pxGroup(out: *Section, idx: usize, label_text: []const u8, value: f32, min: f32, max: f32, step: f32, on_change: *const fn (?*anyopaque, usize, f32) void) Widget {- const formatted = std.fmt.bufPrint(&out.px[idx].value_buf, "{d}px", .{@as(i32, @intFromFloat(@round(value)))}) catch "?";+ return unitGroup(out, idx, label_text, value, min, max, step, on_change, "px");+}++/// `pxGroup` for a value that isn't in pixels, such as a percentage.+fn unitGroup(out: *Section, idx: usize, label_text: []const u8, value: f32, min: f32, max: f32, step: f32, on_change: *const fn (?*anyopaque, usize, f32) void, unit: []const u8) Widget {+ const formatted = std.fmt.bufPrint(&out.px[idx].value_buf, "{d}{s}", .{ @as(i32, @intFromFloat(@round(value))), unit }) catch "?";out.px[idx].header_children = .{ labelWidget(label_text), pillWidget(formatted) };const header: Widget = .{ .kind = .container, .direction = .row, .justify = .space_between, .children = &out.px[idx].header_children };const slider: Widget = .{ .kind = .{ .slider = .{ .value = value, .min = min, .max = max, .step = step, .owner = out, .on_change = on_change } } };@@ -309,11 +317,15 @@ fn pxGroup(out: *Section, idx: usize, label_text: []const u8, value: f32, min: f/// thing the cheap height-guarded refresh notices; the start-menu-popup/// padding fields don't touch taskbar geometry at all.fn PxHandler(comptime idx: usize, comptime field: []const u8, comptime taskbar_geometry: bool) type {+ return UnitHandler(idx, field, taskbar_geometry, "px");+}++fn UnitHandler(comptime idx: usize, comptime field: []const u8, comptime taskbar_geometry: bool, comptime unit: []const u8) type {return struct {fn changed(owner: ?*anyopaque, _: usize, value: f32) void {const s = section(owner);@field(theme.global, field) = value;- const formatted = std.fmt.bufPrint(&s.px[idx].value_buf, "{d}px", .{@as(i32, @intFromFloat(@round(value)))}) catch "?";+ const formatted = std.fmt.bufPrint(&s.px[idx].value_buf, "{d}" ++ unit, .{@as(i32, @intFromFloat(@round(value)))}) catch "?";s.px[idx].header_children[1].kind.text.content = formatted;s.px[idx].header_children[1].markDirty();applyThemeChangeImpl(section(owner), taskbar_geometry);@@ -652,6 +664,14 @@ pub fn build(out: *Section, cc: *panel.ControlCenter) void {const position_row: Widget = .{ .kind = .container, .direction = .row, .justify = .space_between, .@"align" = .center, .children = &out.taskbar_position_children };const taskbar_min: f32 = @floatFromInt(Taskbar.min_bar_height);const taskbar_row = pxGroup(out, px_taskbar_size, "Taskbar size", std.math.clamp(t.taskbar_size, taskbar_min, 84.0), taskbar_min, 84, 2, &PxHandler(px_taskbar_size, "taskbar_size", true).changed);+ // A floating bar: its gap from the edge, its length and its corners. At+ // 0 px, 100 % and 0 px it is the original flush, full-width, square bar.+ const edge_gap_row = pxGroup(out, px_taskbar_edge_gap, "Taskbar gap from edge", std.math.clamp(t.taskbar_edge_gap, 0.0, 48.0), 0, 48, 2, &PxHandler(px_taskbar_edge_gap, "taskbar_edge_gap", true).changed);+ out.px[px_taskbar_edge_gap].group_children[1].name = "taskbar_edge_gap";+ const length_row = unitGroup(out, px_taskbar_length, "Taskbar length", std.math.clamp(t.taskbar_length, 30.0, 100.0), 30, 100, 2, &UnitHandler(px_taskbar_length, "taskbar_length", true, "%").changed, "%");+ out.px[px_taskbar_length].group_children[1].name = "taskbar_length";+ const radius_row = pxGroup(out, px_taskbar_radius, "Taskbar corner radius", std.math.clamp(t.taskbar_radius, 0.0, 42.0), 0, 42, 1, &PxHandler(px_taskbar_radius, "taskbar_radius", true).changed);+ out.px[px_taskbar_radius].group_children[1].name = "taskbar_radius";// Also sets each pill's top/bottom margin within the bar (capped) —// see Taskbar.chipVerticalMargin — so this one slider spaces chips on// every side at once instead of only widening the horizontal gap.@@ -688,7 +708,7 @@ pub fn build(out: *Section, cc: *panel.ControlCenter) void {.{ .kind = .container, .direction = .column, .gap = 8, .children = &out.items_section_children[2] },};const items_group: Widget = .{ .kind = .container, .direction = .column, .gap = 8, .children = &out.items_children };- out.taskbar_section_children = .{ sectionLabel("TASKBAR"), position_row, taskbar_row, chip_width_row, chip_gap_row, start_gap_row, start_icon_row, items_group };+ out.taskbar_section_children = .{ sectionLabel("TASKBAR"), position_row, taskbar_row, edge_gap_row, length_row, radius_row, chip_width_row, chip_gap_row, start_gap_row, start_icon_row, items_group };const taskbar_section: Widget = .{ .kind = .container, .direction = .column, .gap = 12, .children = &out.taskbar_section_children };var output_box: wlr.Box = undefined;diff --git a/src/start_menu/panel.zig b/src/start_menu/panel.zigindex a0a6f58..98840b1 100644--- a/src/start_menu/panel.zig+++ b/src/start_menu/panel.zig@@ -963,7 +963,7 @@ pub const StartMenu = struct {ui.arrange.arrange(&menu.root, 0, 0, target_width, target_height);menu.restoreScrollOffset(scroll_offset);- const bottom_offset: f32 = @as(f32, @floatFromInt(Taskbar.barHeight())) + theme.global.start_menu_bottom_pad;+ const bottom_offset: f32 = @as(f32, @floatFromInt(Taskbar.reservedHeight())) + theme.global.start_menu_bottom_pad;const start_offset: f32 = if (Output.fromWlr(menu.wlr_output)) |output| if (output.taskbar) |bar| @floatFromInt(bar.startButtonBox().x - output_box.x - Taskbar.startButtonLeft()) else 0 else 0;const panel_left = std.math.clamp(theme.global.start_menu_left_pad + start_offset, 0, @max(0, @as(f32, @floatFromInt(output_box.width)) - target_width));diff --git a/src/taskbar/shape.zig b/src/taskbar/shape.zignew file mode 100644index 0000000..55882ed--- /dev/null+++ b/src/taskbar/shape.zig@@ -0,0 +1,197 @@+//! The bar as a shape: where it sits on its output, how far its items keep+//! from rounded ends, and the pixels of its background. Pure arithmetic, so+//! every floating variant is checked without a compositor.+const std = @import("std");+const wlr = @import("wlroots");+const sdf = @import("ui").sdf;++/// The narrowest a bar is drawn however short it is asked to be: the start+/// button, a few icons and the clock still have to fit.+pub const min_width: i32 = 420;++pub const Spec = struct {+ height: i32,+ /// Logical px between the bar and the output edge it sits on.+ edge_gap: i32 = 0,+ /// Percent of the output's width; the bar is centred.+ length: f32 = 100,+ radius: f32 = 0,+ top: bool = false,+};++pub const Placement = struct {+ box: wlr.Box,+ /// What the bar claims from the output edge: its height and its gap.+ reserved: i32,+};++pub fn place(output: wlr.Box, spec: Spec) Placement {+ const percent = std.math.clamp(spec.length, 20, 100);+ const wanted: i32 = @intFromFloat(@round(@as(f32, @floatFromInt(output.width)) * percent / 100));+ const width = std.math.clamp(wanted, @min(output.width, min_width), output.width);+ const gap = std.math.clamp(spec.edge_gap, 0, @max(0, output.height - spec.height));+ return .{+ .box = .{+ .x = output.x + @divTrunc(output.width - width, 2),+ .y = if (spec.top) output.y + gap else output.y + output.height - spec.height - gap,+ .width = width,+ .height = spec.height,+ },+ .reserved = spec.height + gap,+ };+}++/// Flush means the original bar: edge to edge, on the output's edge, square.+/// It keeps its single hairline on the side facing the windows.+pub fn flush(output: wlr.Box, placed: wlr.Box, radius: f32) bool {+ return radius <= 0 and placed.width >= output.width and placed.x == output.x and+ (placed.y == output.y or placed.y + placed.height == output.y + output.height);+}++/// A corner can't be rounder than a pill.+pub fn effectiveRadius(radius: f32, height: i32) f32 {+ return @max(0, @min(radius, @as(f32, @floatFromInt(height)) / 2));+}++/// How far from an end of the bar an item has to start to stay inside the+/// curve, when its near edge is `margin` from the bar's top or bottom.+pub fn cornerInset(radius: f32, margin: f32) i32 {+ const rise = radius - margin;+ if (radius <= 0 or rise <= 0) return 0;+ return @intFromFloat(@ceil(radius - @sqrt(radius * radius - rise * rise)));+}++pub const Look = struct {+ /// Logical size of the raster the pixel is sampled in.+ width: f32,+ height: f32,+ radius: f32,+ outline: f32,+ flush: bool,+ top: bool,+};++/// One pixel of the bar's background at logical `px`, `py` of its raster.+/// `C` is a straight-alpha colour with `over` and `scaled`. The outline is+/// composited over the fill, never replacing it: both are translucent.+pub fn background(comptime C: type, look: Look, px: f32, py: f32, scale: f32, fill: C, outline: C) C {+ if (look.flush) {+ const edge = if (look.top) py >= look.height - look.outline else py < look.outline;+ return if (edge) outline.over(fill) else fill;+ }+ const covered = coverage(sdf.sdRoundedBox(px, py, 0, 0, look.width, look.height, look.radius), scale);+ if (covered <= 0) return fill.scaled(0);+ const o = look.outline;+ const inside = if (o <= 0) 1 else coverage(sdf.sdRoundedBox(px, py, o, o, look.width - 2 * o, look.height - 2 * o, @max(0, look.radius - o)), scale);+ return outline.scaled(1 - inside).over(fill).scaled(covered);+}++fn coverage(distance: f32, scale: f32) f32 {+ return std.math.clamp(0.5 - distance * scale, 0, 1);+}++const TestColor = struct {+ r: f32 = 0,+ g: f32 = 0,+ b: f32 = 0,+ a: f32 = 0,++ fn over(source: TestColor, destination: TestColor) TestColor {+ const alpha = source.a + destination.a * (1 - source.a);+ if (alpha == 0) return .{};+ return .{+ .r = (source.r * source.a + destination.r * destination.a * (1 - source.a)) / alpha,+ .g = (source.g * source.a + destination.g * destination.a * (1 - source.a)) / alpha,+ .b = (source.b * source.a + destination.b * destination.a * (1 - source.a)) / alpha,+ .a = alpha,+ };+ }+ fn scaled(color: TestColor, alpha: f32) TestColor {+ return .{ .r = color.r, .g = color.g, .b = color.b, .a = std.math.clamp(color.a * alpha, 0, 1) };+ }+};++test "the bar is centred, keeps its gap on the edge it sits on and never gets too short" {+ const output: wlr.Box = .{ .x = 100, .y = 50, .width = 1920, .height = 1080 };+ const flat = place(output, .{ .height = 44 });+ try std.testing.expectEqual(wlr.Box{ .x = 100, .y = 50 + 1080 - 44, .width = 1920, .height = 44 }, flat.box);+ try std.testing.expectEqual(@as(i32, 44), flat.reserved);++ const floating = place(output, .{ .height = 44, .edge_gap = 12, .length = 60 });+ try std.testing.expectEqual(wlr.Box{ .x = 100 + 384, .y = 50 + 1080 - 44 - 12, .width = 1152, .height = 44 }, floating.box);+ try std.testing.expectEqual(@as(i32, 56), floating.reserved);++ const top = place(output, .{ .height = 44, .edge_gap = 12, .length = 60, .top = true });+ try std.testing.expectEqual(@as(i32, 50 + 12), top.box.y);+ try std.testing.expectEqual(@as(i32, 56), top.reserved);++ // Shorter than the items need, or than the output is wide.+ try std.testing.expectEqual(min_width, place(output, .{ .height = 44, .length = 20 }).box.width);+ const narrow: wlr.Box = .{ .x = 0, .y = 0, .width = 300, .height = 600 };+ try std.testing.expectEqual(@as(i32, 300), place(narrow, .{ .height = 44, .length = 50 }).box.width);+ // Out-of-range asks fall back into range instead of leaving the output.+ try std.testing.expectEqual(@as(i32, 1920), place(output, .{ .height = 44, .length = 400 }).box.width);+ try std.testing.expectEqual(@as(i32, 1080), place(output, .{ .height = 44, .edge_gap = 5000 }).reserved);+}++test "only the original bar is flush" {+ const output: wlr.Box = .{ .x = 0, .y = 0, .width = 1920, .height = 1080 };+ const bottom = place(output, .{ .height = 44 }).box;+ try std.testing.expect(flush(output, bottom, 0));+ try std.testing.expect(flush(output, place(output, .{ .height = 44, .top = true }).box, 0));+ try std.testing.expect(!flush(output, bottom, 8));+ try std.testing.expect(!flush(output, place(output, .{ .height = 44, .edge_gap = 6 }).box, 0));+ try std.testing.expect(!flush(output, place(output, .{ .height = 44, .length = 80 }).box, 0));+}++test "items clear a rounded end by exactly what the curve takes" {+ try std.testing.expectEqual(@as(i32, 0), cornerInset(0, 4));+ // Margin as tall as the radius: the item's corner is past the curve.+ try std.testing.expectEqual(@as(i32, 0), cornerInset(6, 6));+ // A pill 44 high: an item 4 from the top starts about 9.4 px in.+ try std.testing.expectEqual(@as(i32, 10), cornerInset(22, 4));+ try std.testing.expectEqual(@as(f32, 22), effectiveRadius(80, 44));+ try std.testing.expectEqual(@as(f32, 0), effectiveRadius(-3, 44));+ // The reported inset really does put the item corner inside the arc.+ const r: f32 = 22;+ const inset: f32 = @floatFromInt(cornerInset(r, 4));+ try std.testing.expect((r - inset) * (r - inset) + (r - 4) * (r - 4) <= r * r);+}++test "the flush background is the original fill and hairline, on the side facing the windows" {+ const fill: TestColor = .{ .r = 0.1, .g = 0.1, .b = 0.1, .a = 0.96 };+ const line: TestColor = .{ .r = 1, .g = 1, .b = 1, .a = 0.06 };+ const bottom: Look = .{ .width = 400, .height = 44, .radius = 0, .outline = 1, .flush = true, .top = false };+ try std.testing.expectEqualDeep(line.over(fill), background(TestColor, bottom, 100, 0.5, 1, fill, line));+ try std.testing.expectEqualDeep(fill, background(TestColor, bottom, 100, 1.5, 1, fill, line));+ var top = bottom;+ top.top = true;+ try std.testing.expectEqualDeep(fill, background(TestColor, top, 100, 0.5, 1, fill, line));+ try std.testing.expectEqualDeep(line.over(fill), background(TestColor, top, 100, 43.5, 1, fill, line));+ var bare = bottom;+ bare.outline = 0;+ try std.testing.expectEqualDeep(fill, background(TestColor, bare, 100, 0.5, 1, fill, line));+}++fn expectColor(expected: TestColor, actual: TestColor) !void {+ inline for (.{ "r", "g", "b", "a" }) |channel| try std.testing.expectApproxEqAbs(@field(expected, channel), @field(actual, channel), 1e-5);+}++test "a floating background rounds its corners and wears its outline all round" {+ const fill: TestColor = .{ .r = 0.1, .g = 0.1, .b = 0.1, .a = 0.9 };+ const line: TestColor = .{ .r = 1, .g = 0, .b = 0, .a = 0.5 };+ const look: Look = .{ .width = 400, .height = 44, .radius = 22, .outline = 2, .flush = false, .top = false };+ // The corner is cut away, the middle is plain fill, the rim carries the outline.+ try std.testing.expectEqual(@as(f32, 0), background(TestColor, look, 0.5, 0.5, 1, fill, line).a);+ try expectColor(fill, background(TestColor, look, 200, 22, 1, fill, line));+ try expectColor(line.over(fill), background(TestColor, look, 200, 0.5, 1, fill, line));+ try expectColor(line.over(fill), background(TestColor, look, 200, 43.5, 1, fill, line));+ try expectColor(line.over(fill), background(TestColor, look, 0.5, 22, 1, fill, line));+ // Square but floating (only a gap or a length): the corners stay filled.+ var square = look;+ square.radius = 0;+ try std.testing.expect(background(TestColor, square, 1, 1, 1, fill, line).a > 0.9);+ // The ramp is antialiased across the curve.+ const edge = background(TestColor, look, 6.4, 6.4, 1, fill, line).a;+ try std.testing.expect(edge > 0 and edge < 1);+}diff --git a/src/ui/theme.zig b/src/ui/theme.zigindex 6133fe6..122bd12 100644--- a/src/ui/theme.zig+++ b/src/ui/theme.zig@@ -108,6 +108,16 @@ pub const Theme = struct {scrollbar_thumb_active: ?[4]f32 = null,taskbar_title_size: f32 = 12.5,taskbar_size: f32 = 44.0,+ // A floating bar: distance from the output edge it sits on (logical px),+ // its length as a percentage of that edge (centred), and its corner+ // radius. The defaults are the flush, full-width, square bar. The strip+ // the bar claims is its height plus the gap (`Taskbar.reservedHeight`).+ taskbar_edge_gap: f32 = 0,+ taskbar_length: f32 = 100,+ taskbar_radius: f32 = 0,+ // Thickness of the bar's own outline (colour: `taskbar_outline`). With a+ // flush, full-width, square bar only the edge facing the windows is drawn.+ taskbar_outline_width: f32 = 1,// Gap between adjacent taskbar window-item pills, logical px. Also// drives each pill's top/bottom margin within the bar (capped — see// Taskbar.chipVerticalMargin), so one slider spaces pills on every side@@ -141,6 +151,10 @@ pub const Theme = struct {taskbar_surface: [4]f32 = .{ 1, 1, 1, 0.025 },taskbar_hover: [4]f32 = .{ 1, 1, 1, 0.05 },taskbar_border: [4]f32 = .{ 1, 1, 1, 0.07 },+ /// The bar's own outline; unset follows `border_soft`, which drew the+ /// bar's hairline before this token existed. `taskbar_border` stays the+ /// window buttons' and battery's.+ taskbar_outline: ?[4]f32 = null,on_accent: [4]f32 = .{ 8.0 / 255.0, 33.0 / 255.0, 28.0 / 255.0, 1 },border_focus: [4]f32 = .{ 94.0 / 255.0, 234.0 / 255.0, 212.0 / 255.0, 0.40 }, // rgba(94,234,212,0.40)// Text insertion caret (paint.zig's `paintTextInput`), not the mouse@@ -416,6 +430,7 @@ pub const TaskbarToken = enum {taskbar_surface,taskbar_hover,taskbar_border,+ taskbar_outline,border_soft,surface_hover,window_fg,@@ -488,10 +503,20 @@ pub fn applyTaskbarKey(allocator: Allocator, t: *Theme, key: []const u8, value:/// radii remain the source of truth and repeated picks never compound.pub const RadiusPreset = enum { sharp, default, round };+/// Whether a token is one the Sharp/Default/Round presets rescale. The+/// taskbar's corner radius is a shape of its own (its square default has+/// nothing to scale), so a preset must neither reset nor be undone by it.+fn presetRadius(comptime field: std.builtin.Type.StructField) bool {+ if (field.type != f32) return false;+ if (!std.mem.startsWith(u8, field.name, "radius") and !std.mem.endsWith(u8, field.name, "_radius")) return false;+ return !std.mem.eql(u8, field.name, "taskbar_radius");+}+pub fn applyRadiusPreset(t: *Theme, preset: RadiusPreset) void {+ @setEvalBranchQuota(10000);const defaults: Theme = .{};inline for (std.meta.fields(Theme)) |field| {- if (comptime field.type == f32 and (std.mem.startsWith(u8, field.name, "radius") or std.mem.endsWith(u8, field.name, "_radius"))) {+ if (comptime presetRadius(field)) {const base = @field(defaults, field.name);@field(t, field.name) = switch (preset) {.sharp => @min(base, 4),@@ -505,12 +530,13 @@ pub fn applyRadiusPreset(t: *Theme, preset: RadiusPreset) void {/// Custom numeric radii need not match any preset: show no selected segment/// so choosing Default can restore every radius, even when `radius` is still 5.pub fn radiusPreset(t: Theme) ?RadiusPreset {+ @setEvalBranchQuota(10000);for ([_]RadiusPreset{ .sharp, .default, .round }) |preset| {var candidate: Theme = .{};applyRadiusPreset(&candidate, preset);var matches = true;inline for (std.meta.fields(Theme)) |field| {- if (comptime field.type == f32 and (std.mem.startsWith(u8, field.name, "radius") or std.mem.endsWith(u8, field.name, "_radius"))) {+ if (comptime presetRadius(field)) {if (@abs(@field(t, field.name) - @field(candidate, field.name)) > 0.001) matches = false;}}@@ -685,6 +711,12 @@ pub fn applyKey(allocator: Allocator, t: *Theme, key: []const u8, value: []constif (comptime std.mem.eql(u8, name, "chrome_control_gap")) {if (number > 24) return error.InvalidSize;}+ if (comptime std.mem.eql(u8, name, "taskbar_length")) {+ if (number < 20 or number > 100) return error.InvalidSize;+ }+ if (comptime std.mem.eql(u8, name, "taskbar_outline_width")) {+ if (number > 8) return error.InvalidSize;+ }if (comptime std.mem.endsWith(u8, name, "_alpha") or std.mem.endsWith(u8, name, "_opacity") or std.mem.eql(u8, name, "dialog_glyph_lift")) {if (number > 1) return error.InvalidSize;}@@ -972,6 +1004,31 @@ test "theme sizes reject non-finite and unsafe geometry" {}}+test "floating taskbar tokens check their ranges and sit outside the radius presets" {+ var t: Theme = .{};+ try applyKey(std.testing.allocator, &t, "taskbar_edge_gap", "12");+ try applyKey(std.testing.allocator, &t, "taskbar_length", "60");+ try applyKey(std.testing.allocator, &t, "taskbar_radius", "22");+ try applyKey(std.testing.allocator, &t, "taskbar_outline_width", "2");+ try applyKey(std.testing.allocator, &t, "taskbar_outline", "\"#ff0000\"");+ try std.testing.expectEqual(@as(f32, 60), t.taskbar_length);+ try std.testing.expectEqual(@as(f32, 2), t.taskbar_outline_width);+ try std.testing.expect(t.taskbar_outline != null);+ for ([_][2][]const u8{ .{ "taskbar_length", "19" }, .{ "taskbar_length", "101" }, .{ "taskbar_outline_width", "9" }, .{ "taskbar_edge_gap", "-1" } }) |bad| {+ try std.testing.expectError(error.InvalidSize, applyKey(std.testing.allocator, &t, bad[0], bad[1]));+ }+ // A preset rescales window radii; the taskbar's own corner is neither+ // reset by it nor stops the preset from being recognised.+ applyRadiusPreset(&t, .round);+ try std.testing.expectEqual(@as(f32, 22), t.taskbar_radius);+ try std.testing.expectEqual(RadiusPreset.round, radiusPreset(t).?);+ // The default look is the flush, full-width, square bar.+ const flush: Theme = .{};+ try std.testing.expectEqual(@as(f32, 0), flush.taskbar_edge_gap);+ try std.testing.expectEqual(@as(f32, 100), flush.taskbar_length);+ try std.testing.expectEqual(@as(f32, 0), flush.taskbar_radius);+}+test "caret colour follows the accent in effect until the file sets one" {var t: Theme = .{};// Panels remap `accent` for their own palette; an unset caret has todiff --git a/src/ui_tests.zig b/src/ui_tests.zigindex 90fbcad..31636a1 100644--- a/src/ui_tests.zig+++ b/src/ui_tests.zig@@ -36,6 +36,7 @@ test {_ = @import("ui").widgets.arrangement;_ = @import("ui").anim;_ = @import("taskbar/battery.zig");+ _ = @import("taskbar/shape.zig");_ = @import("config").taskbar_items;_ = @import("tray.zig");_ = @import("taskbar/battery_highlight.zig");diff --git a/tests/fixtures/theme-pack/theme.toml b/tests/fixtures/theme-pack/theme.tomlindex f211bdc..6381c9d 100644--- a/tests/fixtures/theme-pack/theme.toml+++ b/tests/fixtures/theme-pack/theme.toml@@ -9,6 +9,8 @@ license = "CC0-1.0"accent = "#f42ca0"window_bg = "#142850"start_button_icon = "logo.svg"+[layout]+taskbar_items = ["left:start", "left:clock", "center:windows", "right:tray", "right:battery", "right:network", "right:volume"][assets]wallpaper = "test.png"color_scheme = "dark"diff --git a/tests/taskbar_shape.py b/tests/taskbar_shape.pynew file mode 100644index 0000000..a294135--- /dev/null+++ b/tests/taskbar_shape.py@@ -0,0 +1,141 @@+#!/usr/bin/env python3+"""Floating taskbar: gap from the edge, length and corner radius from Appearance,+the theme file and the strip a maximized window leaves."""+import os+from pathlib import Path+import subprocess+import tempfile+import tomllib++from PIL import Image+from desktop_zoom import build_client, wait_for+from ipc_client import IPCClient, spawn_compositor, stop_process+from ui_driver import UIDriver++BAR = 44+++def expected_box(output, gap, length, top=False):+ width = max(min(420, output["w"]), min(output["w"], round(output["w"] * length / 100)))+ return {"x": (output["w"] - width) // 2, "y": gap if top else output["h"] - BAR - gap,+ "width": width, "height": BAR}+++def run():+ with tempfile.TemporaryDirectory(prefix="rediwm-taskbar-shape-") as directory:+ tmp = Path(directory)+ build_client(tmp)+ config_path = tmp / "rediwm-config.toml"+ config = ('[compositor]\nxwayland = false\nfocus_zoom = "keep"\n[desktop]\nenabled = false\n'+ '[animations]\nenabled = false\n[theme]\nshadow = "#00000000"\n')+ env_extra = {"DBUS_SESSION_BUS_ADDRESS": "", "XDG_DATA_HOME": str(tmp / "data"), "REDIWM_NO_GLASS": "1"}+ process, log = spawn_compositor(tmp, config_content=config, env_extra=env_extra)+ client = None+ try:+ with IPCClient(tmp, timeout=15) as ipc:+ ui = UIDriver(ipc)+ info = ipc.get_outputs()[0]+ output = {"w": info["logical_width"], "h": info["logical_height"]}++ def bar_box():+ return ipc.get_shell_state()["taskbars"][0]["box"]++ def shot(name):+ ipc.close_panel("control_center")+ ipc.wait_for_frame()+ path = tmp / f"{name}.png"+ path.unlink(missing_ok=True)+ ipc.screenshot(str(path))+ return Image.open(path).convert("RGB")++ # The default is the original bar: flush, full width, square.+ assert bar_box() == expected_box(output, 0, 100), bar_box()++ display = wait_for(lambda: next((p.name for p in tmp.glob("wayland-*")+ if not p.name.endswith(".lock")), None), "display")+ with (tmp / "client.log").open("w") as client_log:+ client = subprocess.Popen(+ [str(tmp / "client"), "--app-id", "shape", "--title", "Shape"],+ env=dict(os.environ, XDG_RUNTIME_DIR=str(tmp), WAYLAND_DISPLAY=display,+ REDIWM_TEST_DECORATION="server", REDIWM_TEST_RESIZE="1"),+ stdout=client_log, stderr=client_log)+ win = wait_for(lambda: next((w for w in ipc.get_windows() if w["app_id"] == "shape"), None), "client map")+ win_id = win["id"]+ ipc.maximize(win_id)+ wait_for(lambda: next(w for w in ipc.get_windows() if w["id"] == win_id).get("is_maximized") is True, "maximize")+ ipc.wait_for("window_geometry_settled", window_id=win_id)+ full = ipc.get_window_debug(win_id)["chrome_box"]+ assert full["y"] + full["height"] == output["h"] - BAR, full++ def slider(name, fraction):+ widget = ui.scroll_into_view(name)+ box = widget["global_box"]+ ipc.click_at(round(box["x"] + min(box["width"] - 1, box["width"] * fraction)),+ round(box["y"] + box["height"] / 2))+ ipc.wait_for_panel_settled("control_center")+ return tomllib.loads(config_path.read_text())["theme"][name]++ ipc.action("open_appearance")+ ipc.wait_for_panel_settled("control_center")+ gap = slider("taskbar_edge_gap", .25)+ length = slider("taskbar_length", .5)+ radius = slider("taskbar_radius", .5)+ assert (gap, radius) == (12, 21) and 60 <= length <= 70, (gap, length, radius)+ expected = expected_box(output, gap, length)+ wait_for(lambda: bar_box() == expected, f"bar did not float: {bar_box()} != {expected}")++ # A maximized window gives up the gap along with the bar.+ ipc.wait_for("window_geometry_settled", window_id=win_id)+ floating = ipc.get_window_debug(win_id)["chrome_box"]+ assert floating["y"] == full["y"] and floating["height"] == full["height"] - gap, (full, floating)++ # Rounded ends: the corner shows what is behind the bar, the body keeps its fill.+ pill = shot("pill")+ left, top = expected["x"], expected["y"]+ body = pill.getpixel((left + 150, top + 6))+ assert all(abs(a - b) <= 8 for a, b in zip(body, (24, 28, 34))), body++ def apart(first, second):+ return sum(abs(a - b) for a, b in zip(pill.getpixel(first), pill.getpixel(second)))++ assert apart((left, top), (left + 150, top + 6)) > 10, "corner of the bar is not cut away"+ assert apart((left - 8, top + BAR // 2), (left + 150, top + 6)) > 10, "bar spills past its length"+ assert apart((left + 150, top + BAR + 4), (left + 150, top + 6)) > 10, "bar fills its gap"++ # The same geometry from the theme file, on the other edge.+ config_path.write_text(config_path.read_text().replace(+ "[compositor]", '[compositor]\ntaskbar_position = "top"', 1))+ saved = config_path.read_text()+ for key in ("taskbar_edge_gap", "taskbar_length", "taskbar_radius"):+ saved = "\n".join(line for line in saved.splitlines() if not line.startswith(key + " "))+ config_path.write_text(saved + "\ntaskbar_edge_gap = 20\ntaskbar_length = 50\ntaskbar_radius = 10\n")+ ipc.reload_config()+ expected = expected_box(output, 20, 50, top=True)+ wait_for(lambda: bar_box() == expected, f"theme geometry on top: {bar_box()} != {expected}")+ wait_for(lambda: (lambda b: b["y"] == BAR + 20 and b["y"] + b["height"] == output["h"])(+ ipc.get_window_debug(win_id)["chrome_box"]), f"maximized window under the top bar: {ipc.get_window_debug(win_id)['chrome_box']}")++ # Too short a bar keeps room for its items; a bad value is refused.+ config_path.write_text(config_path.read_text().replace("taskbar_length = 50", "taskbar_length = 20"))+ ipc.reload_config()+ wait_for(lambda: bar_box()["width"] == 420, f"bar kept narrower than its items: {bar_box()}")+ config_path.write_text(config_path.read_text().replace("taskbar_length = 20", "taskbar_length = 5"))+ ipc.reload_config()+ assert bar_box()["width"] == 420+ stop_process(process)+ assert process.returncode == 0, (tmp / "compositor.log").read_text()+ except Exception:+ print((tmp / "compositor.log").read_text())+ raise+ finally:+ if client is not None:+ stop_process(client)+ if process.poll() is None:+ stop_process(process)+ log.close()+ print("PASS: floating taskbar gap, length, radius, strip and edges")+++if __name__ == "__main__":+ os.environ.pop("REDIWM_THEME", None)+ run()diff --git a/tests/theme_packs.py b/tests/theme_packs.pyindex 3f1d948..ea3b335 100644--- a/tests/theme_packs.py+++ b/tests/theme_packs.py@@ -168,6 +168,19 @@ 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.+ 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"]+ wait_for(lambda: clock_x() < 300, "pack did not move the clock to the left section")+ config_file = tmp / "rediwm-config.toml"+ default_items = '["left:start", "center:windows", "right:tray", "right:battery", "right:network", "right:volume", "right:clock"]'+ 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"})+ 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"]assert cfg["input"]["pointer_speed"] == .4