RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
feat: add themed relief and refine widget painting
Petar Margetić5b3d8f9a3b5d
diff --git a/docs/wiki/Theme.md b/docs/wiki/Theme.mdindex 269126e..2b51266 100644--- a/docs/wiki/Theme.md+++ b/docs/wiki/Theme.md@@ -218,6 +218,8 @@ geometry retain their content or structural dimensions.| `shadow` | `"rgba(0,0,0,0.35)"` || `border_glow_enabled` | `true` || `border_glow` | `"rgba(237,27,46,0.6)"` (alpha 0 turns the highlight off) |+| `relief_dark` | `"rgba(0,0,0,0.35)"` (neumorphic shadow cast away from the light) |+| `relief_light` | `"rgba(255,255,255,0.1)"` (neumorphic shadow cast toward the light) || `start_menu_bg` | `"rgba(29,34,41,0.98)"` || `start_menu_border` | `"rgba(255,255,255,0.12)"` || `start_menu_search_bg` | `"rgba(21,26,31,1)"` |@@ -339,6 +341,10 @@ Numeric tokens accept 0–4096 unless constrained below. Fractions ending in| `field_radius` | `8.0` || `shadow_size` | `24.0` || `shadow_offset_y` | `8.0` |+| `relief_depth` | `0.0` (off). Neumorphic relief: buttons and fields cast a dark and a light shadow this many px from their edge |+| `relief_softness` | `0.0` (1.5 x `relief_depth`), fade-out length of those shadows |+| `relief_light_angle` | `135.0`, degrees counter-clockwise from the right (135 is the upper left) |+| `border_glow_length` | `72.0` || `border_glow_reach` | `56.0` || `border_glow_depth` | `3.0` |@@ -409,6 +415,28 @@ Numeric tokens accept 0–4096 unless constrained below. Fractions ending in| `button_selected_alpha` | `0.6` || `button_selected_hover_alpha` | `0.7` |+### Component relief++When `relief_depth` is greater than zero, individual controls can opt into+`"flat"`, `"raised"`, or `"inset"` relief. Flat is the default for components+that did not previously use explicit relief. The standard slider progress fill+overlays the start of the track, so an inset `slider_track_relief` can have its+left-side groove shadow covered by that fill. The shaded slider and toggle paths+use their existing procedural lighting instead of these settings.++| Key | Built-in default | Description |+| --- | --- | --- |+| `button_relief` | `"flat"` | Resting primary/secondary button relief |+| `button_pressed_relief` | `"flat"` | Pressed or selected button relief |+| `field_relief` | `"flat"` | Text field frame relief |+| `dialog_inset_relief` | `"flat"` | Dialog recessed content panel relief |+| `select_relief` | `"flat"` | Resting select/dropdown control relief |+| `select_popup_relief` | `"flat"` | Select/dropdown popup container relief |+| `checkbox_relief` | `"flat"` | Checkbox frame relief |+| `toggle_track_relief` | `"flat"` | Standard toggle track relief |+| `toggle_thumb_relief` | `"flat"` | Standard toggle thumb relief |+| `slider_track_relief` | `"flat"` | Standard slider track relief |+| `slider_thumb_relief` | `"flat"` | Standard slider thumb relief || Additional constraint | Range || --- | --- || `chrome_height` | 28–84 |diff --git a/src/config/loader_tests.zig b/src/config/loader_tests.zigindex 568b866..941f933 100644--- a/src/config/loader_tests.zig+++ b/src/config/loader_tests.zig@@ -256,6 +256,7 @@ test "input and theme reload detect every field and compare strings by content"[]const u8 => "another theme",[4]f32 => .{ 0.1, 0.2, 0.3, 0.4 },?[4]f32 => .{ 0.1, 0.2, 0.3, 0.4 },+ theme_mod.Relief => if (@field(original_theme, field_name) == .flat) .raised else .flat,else => @compileError("add a theme change fixture for " ++ field_name),};try std.testing.expect(!themeEql(original_theme, changed));diff --git a/src/ipc/settings.zig b/src/ipc/settings.zigindex c2d8983..721576d 100644--- a/src/ipc/settings.zig+++ b/src/ipc/settings.zig@@ -84,7 +84,7 @@ pub fn getTheme(server: *Server, a: std.mem.Allocator) !protocol.Response {entries[i] = .{ .name = name };const value = @field(theme.global, name);const T = @FieldType(theme.Theme, name);- if (T == [4]f32 or T == ?[4]f32) entries[i].color = value else if (T == []const u8) entries[i].text = value else if (T == bool) entries[i].boolean = value else if (@typeInfo(T) == .float) entries[i].number = value else @compileError("unhandled theme token " ++ name);+ if (T == [4]f32 or T == ?[4]f32) entries[i].color = value else if (T == []const u8) entries[i].text = value else if (T == bool) entries[i].boolean = value else if (@typeInfo(T) == .float) entries[i].number = value else if (T == theme.Relief) entries[i].text = @tagName(value) else @compileError("unhandled theme token " ++ name);}return .{ .ok = .{ .theme = .{ .tokens = .{ .entries = entries }, .path = server.theme_path, .dark_mode = server.config.compositor.dark_mode } } };}diff --git a/src/ui/cairo.zig b/src/ui/cairo.zigindex a139289..1f1f937 100644--- a/src/ui/cairo.zig+++ b/src/ui/cairo.zig@@ -157,6 +157,42 @@ pub fn drawSplitter(cr_any: *anyopaque, geometry: splitter.Geometry, engaged: bo/// `scrollbar.paint` for the widget tree.pub fn drawScrollbar(cr_any: *anyopaque, look: scrollbar.Look) void {const cr: *c.cairo_t = @ptrCast(cr_any);++ // Paint the groove on the original context so it is not clipped to the+ // thumb-sized layer used for animated shine.+ const tx: f64 = look.track.x;+ const ty: f64 = look.track.y;+ const tw: f64 = look.track.w;+ const th: f64 = look.track.h;+ if (tw > 0 and th > 0) {+ const tr: f64 = @min(look.track_radius, @min(tw, th) / 2);+ setSource(cr, look.track_color);+ c.cairo_new_sub_path(cr);+ c.cairo_arc(cr, tx + tw - tr, ty + tr, tr, -std.math.pi / 2.0, 0);+ c.cairo_arc(cr, tx + tw - tr, ty + th - tr, tr, 0, std.math.pi / 2.0);+ c.cairo_arc(cr, tx + tr, ty + th - tr, tr, std.math.pi / 2.0, std.math.pi);+ c.cairo_arc(cr, tx + tr, ty + tr, tr, std.math.pi, 3 * std.math.pi / 2.0);+ c.cairo_close_path(cr);+ c.cairo_fill(cr);++ // Contrasting edges make the channel read as a recessed groove.+ if (look.axis == .vertical) {+ setSource(cr, look.track_light);+ c.cairo_rectangle(cr, tx, ty, 1, th);+ c.cairo_fill(cr);+ setSource(cr, look.track_dark);+ c.cairo_rectangle(cr, tx + tw - 1, ty, 1, th);+ c.cairo_fill(cr);+ } else {+ setSource(cr, look.track_light);+ c.cairo_rectangle(cr, tx, ty, tw, 1);+ c.cairo_fill(cr);+ setSource(cr, look.track_dark);+ c.cairo_rectangle(cr, tx, ty + th - 1, tw, 1);+ c.cairo_fill(cr);+ }+ }+if (look.shine > 0) {// Preserve the thumb's fractional placement within the device-aligned// layer, including a Cairo translation, as its animated width changes.diff --git a/src/ui/layout.zig b/src/ui/layout.zigindex a9b6c4b..dbc10cf 100644--- a/src/ui/layout.zig+++ b/src/ui/layout.zig@@ -157,6 +157,11 @@ pub const ButtonState = enum { idle, hover, press, disabled };// bold Manrope face bundled to switch to.pub const TextFamily = enum { sans, mono };+/// Neumorphic relief of a filled rect (`relief.zig`, theme `relief_*`): raised+/// casts its shadows on the surface around it, inset inside its own edge. It+/// draws nothing while the theme's `relief_depth` is 0.+pub const Relief = enum { flat, raised, inset };+pub const RectStyle = struct {color: [4]f32,/// Replace the covered background, preserving this fill's alpha. Rounded@@ -165,6 +170,7 @@ pub const RectStyle = struct {radius: f32 = 0,border_width: f32 = 0,border_color: [4]f32 = .{ 0, 0, 0, 0 },+ relief: Relief = .flat,};/// Padding of a value pill (`TextStyle.pill`) around its text.diff --git a/src/ui/paint.zig b/src/ui/paint.zigindex 066c8e3..5c09161 100644--- a/src/ui/paint.zig+++ b/src/ui/paint.zig@@ -17,6 +17,7 @@ const IconStyle = layout.IconStyle;const paint_icons = @import("paint_icons.zig");const paint_image = @import("paint_image.zig");const paint_widgets = @import("paint_widgets.zig");+const relief = @import("relief.zig");pub const iconDistance = paint_icons.iconDistance;pub const sdSegment = paint_icons.sdSegment;pub const sdCircle = paint_icons.sdCircle;@@ -179,7 +180,62 @@ pub const Renderer = struct {return out;}+ /// A rounded fill, with the theme's neumorphic relief when the style asks+ /// for it and `relief_depth` is set (`relief.zig`). A raised fill's shadows+ /// go under it, around its edge; an inset fill's go over it, inside.pub fn fillRect(r: *Renderer, x: f32, y: f32, w: f32, h: f32, style: RectStyle) void {+ if (style.relief == .flat or w <= 0 or h <= 0) return r.fillRectPlain(x, y, w, h, style);+ const spec = relief.Spec.from(r.palette orelse theme.global, r.scale);+ if (!spec.enabled()) return r.fillRectPlain(x, y, w, h, style);+ if (style.relief == .raised) r.paintRelief(x, y, w, h, style, spec);+ r.fillRectPlain(x, y, w, h, style);+ if (style.relief == .inset) r.paintRelief(x, y, w, h, style, spec);+ }++ /// The shadow pair of `style.relief` over the pixels it can touch: the+ /// fill's box grown by the shadows' reach when raised, the box itself when+ /// inset. Honors the clip, so a scroll container cuts a raised control's+ /// shadows at its edge.+ fn paintRelief(r: *Renderer, x: f32, y: f32, w: f32, h: f32, style: RectStyle, spec: relief.Spec) void {+ const s = r.scale;+ const raised = style.relief == .raised;+ const grow: f32 = if (raised) spec.reach() else 0;+ var dx0 = x * s - grow;+ var dy0 = y * s - grow;+ var dx1 = (x + w) * s + grow;+ var dy1 = (y + h) * s + grow;+ if (r.effectiveClip()) |c| {+ dx0 = @max(dx0, c.x * s);+ dy0 = @max(dy0, c.y * s);+ dx1 = @min(dx1, (c.x + c.w) * s);+ dy1 = @min(dy1, (c.y + c.h) * s);+ }+ const x0: i32 = @intFromFloat(@floor(@max(0, dx0)));+ const y0: i32 = @intFromFloat(@floor(@max(0, dy0)));+ const x1: i32 = @intFromFloat(@ceil(@min(@as(f32, @floatFromInt(r.width)), dx1)));+ const y1: i32 = @intFromFloat(@ceil(@min(@as(f32, @floatFromInt(r.height)), dy1)));+ if (x0 >= x1 or y0 >= y1) return;++ r.clean = false;+ const shape: relief.Shape = .{ .x = x * s, .y = y * s, .w = w * s, .h = h * s, .radius = style.radius * s };+ const dark = toColor(spec.dark);+ const light = toColor(spec.light);+ var py = y0;+ while (py < y1) : (py += 1) {+ const sy = @as(f32, @floatFromInt(py)) + 0.5;+ const row: usize = @intCast(py * r.width);+ var px = x0;+ while (px < x1) : (px += 1) {+ const sx = @as(f32, @floatFromInt(px)) + 0.5;+ const pair = if (raised) relief.raised(spec, shape, sx, sy) else relief.inset(spec, shape, sx, sy);+ const index = row + @as(usize, @intCast(px));+ if (pair.dark > 0) blendPixel(&r.pixels[index], dark, pair.dark);+ if (pair.light > 0) blendPixel(&r.pixels[index], light, pair.light);+ }+ }+ }++ fn fillRectPlain(r: *Renderer, x: f32, y: f32, w: f32, h: f32, style: RectStyle) void {if (w <= 0 or h <= 0) return;const s = r.scale;var dx0 = x * s;diff --git a/src/ui/paint_tests.zig b/src/ui/paint_tests.zigindex 13dbe75..780f72d 100644--- a/src/ui/paint_tests.zig+++ b/src/ui/paint_tests.zig@@ -395,3 +395,52 @@ test "smooth image sampling is exact at one to one, blends between pixels and shtry std.testing.expectEqual(white, pixels[2 * 4 + 1]);try std.testing.expectEqual(black, pixels[2 * 4 + 2]);}++/// A theme with relief on: depth 4, softness 6, light at the upper left, and+/// opaque shadows so the pixel checks below are unambiguous.+fn reliefTheme() theme.Theme {+ var t: theme.Theme = .{};+ t.relief_depth = 4;+ t.relief_softness = 6;+ t.relief_light_angle = 135;+ t.relief_dark = .{ 0, 0, 0, 1 };+ t.relief_light = .{ 1, 1, 1, 1 };+ return t;+}++test "relief draws nothing while the theme's relief_depth is zero" {+ var with_relief = @as([40 * 40]u32, @splat(0xff808080));+ var without = with_relief;+ var a = Renderer.init(&with_relief, 40, 40, 1);+ a.palette = .{};+ a.fillRect(10, 10, 20, 20, .{ .color = .{ 1, 0, 0, 1 }, .radius = 4, .relief = .raised });+ var b = Renderer.init(&without, 40, 40, 1);+ b.fillRect(10, 10, 20, 20, .{ .color = .{ 1, 0, 0, 1 }, .radius = 4 });+ try std.testing.expectEqualSlices(u32, &without, &with_relief);+}++test "a raised fill casts its dark shadow away from the light and a light one toward it" {+ var pixels = @as([60 * 60]u32, @splat(0xff808080));+ var r = Renderer.init(&pixels, 60, 60, 1);+ r.palette = reliefTheme();+ r.fillRect(20, 20, 20, 20, .{ .color = .{ 0.5, 0.5, 0.5, 1 }, .radius = 4, .relief = .raised });+ // Light from the upper left: shadow below and right of the box, glow above and left.+ try std.testing.expect((pixels[41 * 60 + 41] & 0xff) < 0x80);+ try std.testing.expect((pixels[18 * 60 + 18] & 0xff) > 0x80);+ // The fill and the surface far from it are untouched.+ try std.testing.expectEqual(@as(u32, 0xff808080), pixels[30 * 60 + 30]);+ try std.testing.expectEqual(@as(u32, 0xff808080), pixels[2 * 60 + 2]);+}++test "an inset fill shades the edge facing the light and lights the opposite one" {+ var pixels = @as([60 * 60]u32, @splat(0xff808080));+ var r = Renderer.init(&pixels, 60, 60, 1);+ r.palette = reliefTheme();+ r.fillRect(20, 20, 20, 20, .{ .color = .{ 0.5, 0.5, 0.5, 1 }, .radius = 4, .relief = .inset });+ // Just inside the top edge it is dark, just inside the bottom edge light.+ try std.testing.expect((pixels[22 * 60 + 30] & 0xff) < 0x80);+ try std.testing.expect((pixels[37 * 60 + 30] & 0xff) > 0x80);+ // Neither the middle nor the surface outside the box is touched.+ try std.testing.expectEqual(@as(u32, 0xff808080), pixels[30 * 60 + 30]);+ try std.testing.expectEqual(@as(u32, 0xff808080), pixels[30 * 60 + 15]);+}diff --git a/src/ui/paint_widgets.zig b/src/ui/paint_widgets.zigindex 34c26ef..d18acfe 100644--- a/src/ui/paint_widgets.zig+++ b/src/ui/paint_widgets.zig@@ -244,7 +244,7 @@ pub fn paintSlider(widget: *const Widget, data: SliderData, renderer: *Renderer)// faint hold after a change (`widgets/slider.zig`).const tint = data.feel.accent;const track_color = lerp4(t.slider_track, .{ t.accent[0], t.accent[1], t.accent[2], t.slider_track_tint_alpha * t.accent[3] }, tint);- renderer.fillRect(widget.computed_x, track_y, w, track_h, .{ .color = track_color, .radius = track_h / 2 });+ renderer.fillRect(widget.computed_x, track_y, w, track_h, .{ .relief = t.slider_track_relief, .color = track_color, .radius = track_h / 2 });const frac = if (data.max > data.min) std.math.clamp((data.value - data.min) / (data.max - data.min), 0, 1) else 0;const fill_w = frac * w;@@ -253,7 +253,7 @@ pub fn paintSlider(widget: *const Widget, data: SliderData, renderer: *Renderer)if (fill_w > 0) renderer.fillRect(widget.computed_x, track_y, fill_w, track_h, .{ .color = fill_color, .radius = track_h / 2 });const thumb_x = widget.computed_x + fill_w - thumb_w / 2;- renderer.fillRect(thumb_x, cy - thumb_h / 2, thumb_w, thumb_h, .{ .color = t.control_thumb, .radius = if (settings) t.slider_thumb_radius else t.slider_thumb_size / 2 });+ renderer.fillRect(thumb_x, cy - thumb_h / 2, thumb_w, thumb_h, .{ .relief = t.slider_thumb_relief, .color = t.control_thumb, .radius = if (settings) t.slider_thumb_radius else t.slider_thumb_size / 2 });}/// A slider's value readout: the text centred in a rounded label that fades@@ -406,7 +406,7 @@ pub fn paintSelect(widget: *const Widget, data: layout.SelectData, r: *Renderer)const y = widget.computed_y;const w = widget.computed_width;const h = widget.computed_height;- r.fillRect(x, y, w, h, .{ .color = if (hovered and !data.disabled) t.surface_hover else t.surface, .radius = t.radius, .border_width = 1, .border_color = if (focused or data.open) t.accent else if (hovered and !data.disabled) t.border_hover else t.border });+ r.fillRect(x, y, w, h, .{ .relief = if (data.disabled) .flat else if (data.open) t.button_pressed_relief else t.select_relief, .color = if (hovered and !data.disabled) t.surface_hover else t.surface, .radius = t.radius, .border_width = 1, .border_color = if (focused or data.open) t.accent else if (hovered and !data.disabled) t.border_hover else t.border });const valid = if (data.selected) |i| i < data.labels.len else false;const icon_width: f32 = if (valid and data.selected.? < data.icons.len) 24 else 0;if (icon_width > 0) r.drawIcon(x + 12, y + (h - 16) / 2, 16, 16, .{ .id = data.icons[data.selected.?], .color = if (data.disabled) t.faint else t.dim });@@ -423,7 +423,7 @@ pub fn paintOverlays(widget: *const Widget, r: *Renderer) void {const t = r.palette orelse theme.global;var bg = t.bg;bg[3] = 1;- r.fillRect(b.x, b.y, b.w, b.h, .{ .color = bg, .radius = t.radius, .border_width = 1, .border_color = t.border_hover });+ r.fillRect(b.x, b.y, b.w, b.h, .{ .relief = t.select_popup_relief, .color = bg, .radius = t.radius, .border_width = 1, .border_color = t.border_hover });const row_h = select.rowHeight();const visible = select.visibleCount(widget);const end = @min(d.labels.len, d.first_visible + visible);diff --git a/src/ui/relief.zig b/src/ui/relief.zignew file mode 100644index 0000000..db0c3e7--- /dev/null+++ b/src/ui/relief.zig@@ -0,0 +1,104 @@+//! Neumorphic relief: the pair of soft shadows, one dark and one light, that+//! makes a rounded control look pressed out of (raised) or into (inset) the+//! surface it sits on. Pure geometry on the same signed-distance field as the+//! rest of the rasterizer, so `Renderer.fillRect` and any hand-rolled control+//! shade identically. Everything is in device pixels; `Spec.from` is where the+//! theme's logical values are scaled.+//!+//! The light sits `light_x, light_y` away from the shape (y down). A raised+//! shape casts its dark shadow away from the light and its light one toward+//! it. An inset shape is the same pair seen from inside: the edge facing the+//! light is in shadow and the opposite edge catches the light.+const std = @import("std");+const sdf = @import("sdf.zig");+const theme = @import("theme.zig");++/// The look of one theme, resolved to device pixels.+pub const Spec = struct {+ /// How far each shadow is shifted from the shape. 0 turns relief off.+ depth: f32,+ /// How far a shadow takes to fade out past its own edge (at least 1).+ softness: f32,+ /// Unit vector from the shape toward the light, y down.+ light_x: f32,+ light_y: f32,+ /// Straight RGBA; the alpha is the strength at the shadow's edge.+ dark: [4]f32,+ light: [4]f32,++ pub fn from(t: theme.Theme, scale: f32) Spec {+ // The angle reads like a protractor (counter-clockwise from +x, y up):+ // 135 is the upper left, the usual neumorphic light.+ const radians = t.relief_light_angle * (std.math.pi / 180.0);+ const soft = if (t.relief_softness > 0) t.relief_softness else t.relief_depth * 1.5;+ return .{+ .depth = @max(t.relief_depth, 0) * scale,+ .softness = @max(soft * scale, 1),+ .light_x = @cos(radians),+ .light_y = -@sin(radians),+ .dark = t.relief_dark,+ .light = t.relief_light,+ };+ }++ pub fn enabled(spec: Spec) bool {+ return spec.depth > 0 and (spec.dark[3] > 0 or spec.light[3] > 0);+ }++ /// How far outside its box a raised shape's shadows can reach. Damage for a+ /// control whose relief changes must cover this much more than its box.+ pub fn reach(spec: Spec) f32 {+ return spec.depth + spec.softness;+ }+};++/// A rounded box in device pixels.+pub const Shape = struct { x: f32, y: f32, w: f32, h: f32, radius: f32 };++/// Strength of the two shadows at one pixel, 0 to 1 each.+pub const Pair = struct { dark: f32, light: f32 };++const none: Pair = .{ .dark = 0, .light = 0 };++/// Signed distance from (`px`, `py`) to `shape` moved by (`dx`, `dy`).+inline fn shifted(shape: Shape, px: f32, py: f32, dx: f32, dy: f32) f32 {+ return sdf.sdRoundedBox(px - dx, py - dy, shape.x, shape.y, shape.w, shape.h, shape.radius);+}++/// Full strength on and inside an edge, none `softness` outside it, a+/// smoothstep between: the ramp of the compositor's window shadow, so a+/// control and a window frame fall off the same way.+pub inline fn falloff(distance: f32, softness: f32) f32 {+ const s = std.math.clamp(1 - distance / softness, 0, 1);+ return s * s * (3 - 2 * s);+}++/// The shadows a raised `shape` casts on the surface around it. They are kept+/// out of the shape itself, so a translucent fill does not show them.+pub fn raised(spec: Spec, shape: Shape, px: f32, py: f32) Pair {+ const d = shifted(shape, px, py, 0, 0);+ if (d >= spec.reach()) return none;+ const outside = 1 - sdf.coverage(d);+ if (outside <= 0) return none;+ const ox = spec.light_x * spec.depth;+ const oy = spec.light_y * spec.depth;+ return .{+ .dark = falloff(shifted(shape, px, py, -ox, -oy), spec.softness) * outside,+ .light = falloff(shifted(shape, px, py, ox, oy), spec.softness) * outside,+ };+}++/// The shadows inside an inset `shape`: what the shape, moved by the offset,+/// no longer covers, softened inward.+pub fn inset(spec: Spec, shape: Shape, px: f32, py: f32) Pair {+ const d = shifted(shape, px, py, 0, 0);+ if (d < -spec.reach()) return none;+ const inside = sdf.coverage(d);+ if (inside <= 0) return none;+ const ox = spec.light_x * spec.depth;+ const oy = spec.light_y * spec.depth;+ return .{+ .dark = falloff(-shifted(shape, px, py, -ox, -oy), spec.softness) * inside,+ .light = falloff(-shifted(shape, px, py, ox, oy), spec.softness) * inside,+ };+}diff --git a/src/ui/theme.zig b/src/ui/theme.zigindex fe9718d..53cac7e 100644--- a/src/ui/theme.zig+++ b/src/ui/theme.zig@@ -10,6 +10,8 @@const std = @import("std");const Allocator = std.mem.Allocator;const Io = std.Io;+const layout = @import("layout.zig");+pub const Relief = layout.Relief;const log = std.log.scoped(.theme);@@ -214,6 +216,31 @@ pub const Theme = struct {border_glow_depth: f32 = 3.0, // how far it bleeds inward past the 1 px ringshadow_size: f32 = 24.0, // blur/softness radius, logical pxshadow_offset_y: f32 = 8.0, // vertical offset, logical px+ /// Neumorphic relief of buttons, fields and inset panels (`ui/relief.zig`):+ /// each casts a dark and a light shadow shifted `relief_depth` logical px+ /// from its edge, away from and toward the light. 0 turns relief off.+ relief_depth: f32 = 0,+ /// Fade-out length of those shadows, logical px; 0 follows 1.5 x the depth.+ relief_softness: f32 = 0,+ /// Where the light sits, in degrees counter-clockwise from the right (135+ /// is the upper left).+ relief_light_angle: f32 = 135,+ relief_dark: [4]f32 = .{ 0, 0, 0, 0.35 },+ relief_light: [4]f32 = .{ 1, 1, 1, 0.10 },++ // Component-level relief styles. Flat defaults preserve existing rendering+ // for controls that did not previously request relief.+ button_relief: Relief = .flat,+ button_pressed_relief: Relief = .flat,+ field_relief: Relief = .flat,+ dialog_inset_relief: Relief = .flat,+ select_relief: Relief = .flat,+ select_popup_relief: Relief = .flat,+ checkbox_relief: Relief = .flat,+ toggle_track_relief: Relief = .flat,+ toggle_thumb_relief: Relief = .flat,+ slider_track_relief: Relief = .flat,+ slider_thumb_relief: Relief = .flat,// 0 sizes the menu to the output (`start_menu/size.zig`); set either to pin it.start_menu_width: f32 = 0,start_menu_max_height: f32 = 0,diff --git a/src/ui/theme_file.zig b/src/ui/theme_file.zigindex 6ae0779..d29c3d1 100644--- a/src/ui/theme_file.zig+++ b/src/ui/theme_file.zig@@ -7,6 +7,7 @@ const log = std.log.scoped(.theme);const theme = @import("theme.zig");const window_shape = @import("window_shape.zig");const Theme = theme.Theme;+pub const Relief = theme.Relief;const TaskbarToken = theme.TaskbarToken;/// `REDIWM_THEME`, matching this project's existing env-var config@@ -62,6 +63,11 @@ pub const boolean_keys = keysOf(bool);pub const optional_color_keys = keysOf(?[4]f32);pub const string_keys = keysOf([]const u8);+pub const relief_keys = keysOf(Relief);++pub fn parseRelief(s: []const u8) ?Relief {+ return std.meta.stringToEnum(Relief, s);+}/// Parses theme file bytes. String fields (`font`, `mono_font`) are duped/// with `allocator` and, like `icon_theme.resolveConfig`'s paths, meant to@@ -117,6 +123,13 @@ pub fn applyKey(allocator: Allocator, t: *Theme, name_in: []const u8, value: []creturn;}}+ inline for (relief_keys) |name| {+ if (std.mem.eql(u8, key, name)) {+ const text = try unquote(value);+ @field(t, name) = parseRelief(text) orelse return error.InvalidRelief;+ return;+ }+ }inline for (string_keys) |name| {if (std.mem.eql(u8, key, name)) {const text = try unquote(value);@@ -255,6 +268,11 @@ pub fn writeDiff(allocator: Allocator, buf: *std.ArrayList(u8), t: Theme, defaulinline for (boolean_keys) |name| {if (@field(t, name) != @field(defaults, name)) try appendLine(allocator, buf, "{s} = {}\n", .{ name, @field(t, name) });}+ inline for (relief_keys) |name| {+ if (@field(t, name) != @field(defaults, name)) {+ try appendLine(allocator, buf, "{s} = \"{s}\"\n", .{ name, @tagName(@field(t, name)) });+ }+ }inline for (string_keys) |name| {if (!std.mem.eql(u8, @field(t, name), @field(defaults, name))) {try buf.appendSlice(allocator, name ++ " = \"");diff --git a/src/ui/theme_tests.zig b/src/ui/theme_tests.zigindex 03eca60..575f0cb 100644--- a/src/ui/theme_tests.zig+++ b/src/ui/theme_tests.zig@@ -1,4 +1,5 @@const std = @import("std");+const theme_file = @import("theme_file.zig");const theme = @import("theme.zig");const Theme = theme.Theme;const taskbarTokensEql = theme.taskbarTokensEql;@@ -283,3 +284,68 @@ test "chrome geometry validates and survives theme serialization" {try std.testing.expectEqual(@as(f32, 0), restored.chrome_control_gap);try std.testing.expect(restored.chrome_round_buttons);}+++test "component relief theme keys parse, inherit, and reject invalid values" {+ const Relief = theme.Relief;+ try std.testing.expect(theme_file.knownKey("button_relief"));+ try std.testing.expect(theme_file.knownKey("button_pressed_relief"));+ try std.testing.expect(theme_file.knownKey("field_relief"));+ try std.testing.expect(theme_file.knownKey("dialog_inset_relief"));+ try std.testing.expect(theme_file.knownKey("select_relief"));+ try std.testing.expect(theme_file.knownKey("select_popup_relief"));+ try std.testing.expect(theme_file.knownKey("checkbox_relief"));+ try std.testing.expect(theme_file.knownKey("toggle_track_relief"));+ try std.testing.expect(theme_file.knownKey("toggle_thumb_relief"));+ try std.testing.expect(theme_file.knownKey("slider_track_relief"));+ try std.testing.expect(theme_file.knownKey("slider_thumb_relief"));+ try std.testing.expect(!theme_file.knownKey("fake_relief_key"));++ const toml =+ \\[theme]+ \\button_relief = "flat"+ \\button_pressed_relief = "raised"+ \\checkbox_relief = "inset"+ ;+ var t: Theme = .{};+ try theme_file.overlay(std.testing.allocator, &t, toml);+ try std.testing.expectEqual(Relief.flat, t.button_relief);+ try std.testing.expectEqual(Relief.raised, t.button_pressed_relief);+ try std.testing.expectEqual(Relief.inset, t.checkbox_relief);+ try std.testing.expectEqual(Relief.flat, t.field_relief);+ try std.testing.expectEqual(Relief.flat, t.toggle_track_relief);++ var bad_t: Theme = .{};+ const invalid_relief =+ \\[theme]+ \\button_relief = "concave"+ ;+ try std.testing.expectError(error.InvalidRelief, theme_file.overlay(std.testing.allocator, &bad_t, invalid_relief));+ const unquoted_relief =+ \\[theme]+ \\button_relief = flat+ ;+ try std.testing.expectError(error.ExpectedQuotedString, theme_file.overlay(std.testing.allocator, &bad_t, unquoted_relief));+}++test "component relief theme serialization round-trips and omits defaults" {+ var buf: std.ArrayList(u8) = .empty;+ defer buf.deinit(std.testing.allocator);++ var original: Theme = .{};+ const defaults: Theme = .{};+ original.button_relief = .raised;+ original.toggle_track_relief = .inset;+ original.field_relief = .inset;++ try theme_file.writeDiff(std.testing.allocator, &buf, original, defaults, "", false);+ try std.testing.expect(std.mem.indexOf(u8, buf.items, "button_relief = \"raised\"") != null);+ try std.testing.expect(std.mem.indexOf(u8, buf.items, "toggle_track_relief = \"inset\"") != null);+ try std.testing.expect(std.mem.indexOf(u8, buf.items, "field_relief = \"inset\"") != null);++ var reloaded: Theme = .{};+ try theme_file.overlay(std.testing.allocator, &reloaded, buf.items);+ try std.testing.expectEqual(original.button_relief, reloaded.button_relief);+ try std.testing.expectEqual(original.toggle_track_relief, reloaded.toggle_track_relief);+ try std.testing.expectEqual(original.field_relief, reloaded.field_relief);+}diff --git a/src/ui/widgets/button.zig b/src/ui/widgets/button.zigindex 95f208e..0342dca 100644--- a/src/ui/widgets/button.zig+++ b/src/ui/widgets/button.zig@@ -133,6 +133,7 @@ pub fn paintBackground(r: *Renderer, box: Rect, opts: Options, state: State) voiconst ring = state.focused and !disabled;const border_w: f32 = if (ring) 2 else if (opts.variant == .secondary) 1 else 0;if (bg[3] > 0 or border_w > 0) r.fillRect(box.x, box.y, box.w, box.h, .{+ .relief = if (disabled or (opts.variant != .primary and opts.variant != .secondary)) .flat else if (state.pointer == .press or state.selected) t.button_pressed_relief else t.button_relief,.color = bg,.radius = opts.radius orelse if (opts.variant == .chrome) chrome.cornerRadius(t.chrome_round_buttons, box.w, box.h, chrome.control_radius) else m.radius,.border_width = border_w,diff --git a/src/ui/widgets/checkbox.zig b/src/ui/widgets/checkbox.zigindex 03caa18..19fc7a9 100644--- a/src/ui/widgets/checkbox.zig+++ b/src/ui/widgets/checkbox.zig@@ -30,6 +30,7 @@ pub fn paint(r: *Renderer, box: Rect, label: []const u8, state: State) void {.radius = t.checkbox_radius,.border_width = if (ring) 2 else 1,.border_color = if (ring) t.controlFocusColor() else if (state.checked) t.accent else t.border_hover,+ .relief = if (state.disabled) .flat else t.checkbox_relief,});if (state.checked) r.drawIcon(box.x, y, box_size, box_size, .{ .id = .checkmark, .color = t.on_accent });var left = box.x + box_size + gap;diff --git a/src/ui/widgets/dialog.zig b/src/ui/widgets/dialog.zigindex 7f7800b..008fa42 100644--- a/src/ui/widgets/dialog.zig+++ b/src/ui/widgets/dialog.zig@@ -150,7 +150,7 @@ pub fn paintHeader(r: *Renderer, x: f32, y: f32, w: f32, header: Header) void {/// The panel holding what the dialog is about (an account, a file).pub fn paintInset(r: *Renderer, box: Rect) void {const t = r.palette orelse theme.global;- r.fillRect(box.x, box.y, box.w, box.h, .{ .color = t.surface, .radius = t.dialog_inset_radius });+ r.fillRect(box.x, box.y, box.w, box.h, .{ .color = t.surface, .radius = t.dialog_inset_radius, .relief = t.dialog_inset_relief });}test "header badge takes an accent tint and the frame opaque app colours" {diff --git a/src/ui/widgets/field.zig b/src/ui/widgets/field.zigindex f22338f..bfca3c0 100644--- a/src/ui/widgets/field.zig+++ b/src/ui/widgets/field.zig@@ -116,7 +116,7 @@ pub fn paintFrame(r: *Renderer, box: Rect, opts: Options, state: State) Layout {t.fieldFocusColor()elset.field_border;- r.fillRect(box.x, box.y, box.w, box.h, .{ .color = bg, .radius = m.radius, .border_width = 1, .border_color = border });+ r.fillRect(box.x, box.y, box.w, box.h, .{ .color = bg, .radius = m.radius, .border_width = 1, .border_color = border, .relief = if (state.disabled) .flat else t.field_relief });if (out.icon) |icon| r.drawIcon(icon.x, icon.y, icon.w, icon.h, .{.id = opts.leading_icon.?,.color = if (state.disabled) t.faint else opts.leading_icon_color orelse t.dim,diff --git a/src/ui/widgets/scrollbar.zig b/src/ui/widgets/scrollbar.zigindex e0db593..62ab801 100644--- a/src/ui/widgets/scrollbar.zig+++ b/src/ui/widgets/scrollbar.zig@@ -139,6 +139,11 @@ pub const Drag = struct {/// What to draw: the thumb's rounded box, colour and illuminated edge.pub const Look = struct {+ track: Rect,+ track_radius: f32,+ track_color: [4]f32,+ track_light: [4]f32,+ track_dark: [4]f32,rect: Rect,radius: f32,color: [4]f32,@@ -167,12 +172,41 @@ pub fn look(g: Geometry, state: Appearance, configured: f32, palette: theme.Themvar highlight = palette.border_glow;// A pale reflection of the frame's glow reads as light on every palette.for (highlight[0..3]) |*channel| channel.* += (1 - channel.*) * 0.55;- return .{ .rect = rect, .radius = cornerRadius(thickness), .color = color, .axis = g.axis, .highlight = highlight, .shine = state.shine, .glow = @max(palette.scrollbar_glow, 0) };+ // A narrow, inset-looking groove remains visible even when the thumb is idle.+ // Use the theme surface as its base, with a restrained darkening for contrast.+ var track_color = palette.surface;+ for (track_color[0..3]) |*channel| channel.* *= 0.48;+ track_color[3] = @max(track_color[3], 0.22);+ var track_light = palette.border_glow;+ track_light[3] = @max(track_light[3], 0.5);+ var track_dark = palette.shadow;+ track_dark[3] = @max(track_dark[3], 0.35);+ const track_thickness: f32 = @min(6.0, gutter_thickness);+ var track_rect = g.track;+ if (g.axis == .vertical) {+ track_rect.x += (track_rect.w - track_thickness) / 2;+ track_rect.w = track_thickness;+ } else {+ track_rect.y += (track_rect.h - track_thickness) / 2;+ track_rect.h = track_thickness;+ }+ return .{ .track = track_rect, .track_radius = track_thickness / 2, .track_color = track_color, .track_light = track_light, .track_dark = track_dark, .rect = rect, .radius = cornerRadius(thickness), .color = color, .axis = g.axis, .highlight = highlight, .shine = state.shine, .glow = @max(palette.scrollbar_glow, 0) };}/// The light stays inside the thumb, so ordinary scrollbar damage erases it./// Cairo clients use this same painter through `ui/cairo.zig`'s `drawScrollbar`.pub fn paint(r: *@import("../paint.zig").Renderer, l: Look) void {+ r.fillRect(l.track.x, l.track.y, l.track.w, l.track.h, .{+ .color = l.track_color,+ .radius = l.track_radius,+ });+ if (l.axis == .vertical) {+ r.fillRect(l.track.x, l.track.y, 1, l.track.h, .{ .color = l.track_light });+ r.fillRect(l.track.x + l.track.w - 1, l.track.y, 1, l.track.h, .{ .color = l.track_dark });+ } else {+ r.fillRect(l.track.x, l.track.y, l.track.w, 1, .{ .color = l.track_light });+ r.fillRect(l.track.x, l.track.y + l.track.h - 1, l.track.w, 1, .{ .color = l.track_dark });+ }if (l.shine <= 0) {r.fillRect(l.rect.x, l.rect.y, l.rect.w, l.rect.h, .{ .color = l.color, .radius = l.radius });return;@@ -392,6 +426,11 @@ test "the thumb is centred in its gutter, widens and tints with feedback" {try std.testing.expectEqual(@as(f32, 86 + 4), rest.rect.x);try std.testing.expectEqual(palette.scrollbar_thumb, rest.color);try std.testing.expectEqual(cornerRadius(6), rest.radius);+ try std.testing.expectEqual(@as(f32, 6), rest.track.w);+ try std.testing.expectEqual(@as(f32, 90), rest.track.x);+ try std.testing.expect(rest.track_color[3] > 0);+ try std.testing.expect(rest.track_light[3] >= 0.5);+ try std.testing.expect(rest.track_dark[3] >= 0.35);state.wide = 1;state.accent = 1;const hot = look(g, state, 8, palette);diff --git a/src/ui/widgets/toggle.zig b/src/ui/widgets/toggle.zigindex c35059d..824e84d 100644--- a/src/ui/widgets/toggle.zig+++ b/src/ui/widgets/toggle.zig@@ -41,6 +41,7 @@ pub fn paint(r: *Renderer, box: Rect, opts: Options) void {thumb[3] *= 0.5;}r.fillRect(box.x, box.y, box.w, box.h, .{+ .relief = if (opts.disabled) .flat else t.toggle_track_relief,.color = track,.radius = radius,.border_width = if (opts.focused and !opts.disabled) 2 else 0,@@ -49,7 +50,7 @@ pub fn paint(r: *Renderer, box: Rect, opts: Options) void {const inset: f32 = 2;const side = @max(0, box.h - inset * 2);const x = box.x + inset + (box.w - 2 * inset - side) * restPosition(opts);- r.fillRect(x, box.y + inset, side, side, .{ .color = thumb, .radius = if (opts.style == .settings) t.toggle_thumb_radius else side / 2 });+ r.fillRect(x, box.y + inset, side, side, .{ .relief = if (opts.disabled) .flat else t.toggle_thumb_relief, .color = thumb, .radius = if (opts.style == .settings) t.toggle_thumb_radius else side / 2 });}/// Recessed track and raised knob, contained in the control's damage bounds.