Skip to content

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

feat: add relief settings for dialogs and taskbar chips

Petar Margetić7c6dfead50e6
diff --git a/docs/wiki/Theme.md b/docs/wiki/Theme.md
index 855cfde..20994b7 100644
--- a/docs/wiki/Theme.md
+++ b/docs/wiki/Theme.md
@@ -437,6 +437,10 @@ as before. Raised shadows reach `relief_depth + relief_softness` past a box: use
| `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 |
+| `dialog_frame_relief` | `"flat"` | Dialog card relief; raised shadows lie outside the card |
+| `settings_card_relief` | `"flat"` | Cards around Settings entries. The page scrolls in a clipped container, so a raised card's shadow is cut at its edge: prefer `inset` |
+| `taskbar_chip_relief` | `"flat"` | Taskbar window chip, idle. Shaded inside the edge (the chip raster has no margin): `inset` is a groove, `raised` swaps the lights. Main theme only; `[taskbar_theme]` does not carry it |
+| `taskbar_chip_active_relief` | `"flat"` | The focused taskbar chip; same rules |
| `select_relief` | `"flat"` | Resting select/dropdown control relief |
| `select_popup_relief` | `"flat"` | Select/dropdown popup container relief |
| `checkbox_relief` | `"flat"` | Checkbox frame relief |
diff --git a/src/control_center/panel.zig b/src/control_center/panel.zig
index 0a77348..73d27dd 100644
--- a/src/control_center/panel.zig
+++ b/src/control_center/panel.zig
@@ -146,7 +146,7 @@ pub fn outOfMemory() Widget {
pub fn card(children: []Widget) Widget {
return .{
- .kind = .{ .rect = .{ .color = theme.global.app_item, .radius = theme.global.settings_card_radius, .border_width = 1, .border_color = theme.global.app_item_border } },
+ .kind = .{ .rect = .{ .color = theme.global.app_item, .radius = theme.global.settings_card_radius, .border_width = 1, .border_color = theme.global.app_item_border, .relief = theme.global.settings_card_relief } },
.direction = .column,
.padding = layout.Edges.all(14),
.gap = 10,
diff --git a/src/control_center/sections/bluetooth.zig b/src/control_center/sections/bluetooth.zig
index 2ddb089..31f8d2b 100644
--- a/src/control_center/sections/bluetooth.zig
+++ b/src/control_center/sections/bluetooth.zig
@@ -64,7 +64,7 @@ fn group(a: A, dir: ui.layout.Direction, items: []const W) !W {
fn card(a: A, items: []const W) !W {
var w = try group(a, .column, items);
const t = panel.palette();
- w.kind = .{ .rect = .{ .color = t.app_item, .radius = t.settings_card_radius, .border_width = 1, .border_color = t.app_item_border } };
+ w.kind = .{ .rect = .{ .color = t.app_item, .radius = t.settings_card_radius, .border_width = 1, .border_color = t.app_item_border, .relief = t.settings_card_relief } };
w.padding = ui.layout.Edges.all(14);
w.gap = 14;
return w;
diff --git a/src/control_center/sections/desktop.zig b/src/control_center/sections/desktop.zig
index d78d536..1765b09 100644
--- a/src/control_center/sections/desktop.zig
+++ b/src/control_center/sections/desktop.zig
@@ -43,7 +43,7 @@ fn container(a: std.mem.Allocator, direction: ui.layout.Direction, items: []cons
fn card(a: std.mem.Allocator, items: []const W) !W {
var w = try container(a, .column, items);
- w.kind = .{ .rect = .{ .color = panel.palette().settings_card_bg, .radius = panel.palette().settings_card_radius, .border_width = 1, .border_color = panel.palette().border_soft } };
+ w.kind = .{ .rect = .{ .color = panel.palette().settings_card_bg, .radius = panel.palette().settings_card_radius, .border_width = 1, .border_color = panel.palette().border_soft, .relief = panel.palette().settings_card_relief } };
w.padding = ui.layout.Edges.all(14);
return w;
}
diff --git a/src/control_center/sections/network.zig b/src/control_center/sections/network.zig
index 26e537a..a9cbb5a 100644
--- a/src/control_center/sections/network.zig
+++ b/src/control_center/sections/network.zig
@@ -71,7 +71,7 @@ fn group(a: Allocator, direction: ui.layout.Direction, items: []const W) !W {
fn card(a: Allocator, items: []const W) !W {
var w = try group(a, .column, items);
const t = panel.palette();
- w.kind = .{ .rect = .{ .color = t.app_item, .radius = 9, .border_width = 1, .border_color = t.app_item_border } };
+ w.kind = .{ .rect = .{ .color = t.app_item, .radius = 9, .border_width = 1, .border_color = t.app_item_border, .relief = t.settings_card_relief } };
w.padding = ui.layout.Edges.all(16);
w.gap = 14;
return w;
diff --git a/src/control_center/sections/printers.zig b/src/control_center/sections/printers.zig
index eeada1b..7d6a8c4 100644
--- a/src/control_center/sections/printers.zig
+++ b/src/control_center/sections/printers.zig
@@ -153,7 +153,7 @@ pub fn group(a: A, items: []const W) !W {
pub fn card(a: A, items: []const W) !W {
var result = try group(a, items);
const t = panel.palette();
- result.kind = .{ .rect = .{ .color = t.app_item, .radius = t.settings_card_radius, .border_width = 1, .border_color = t.app_item_border } };
+ result.kind = .{ .rect = .{ .color = t.app_item, .radius = t.settings_card_radius, .border_width = 1, .border_color = t.app_item_border, .relief = t.settings_card_relief } };
result.padding = ui.layout.Edges.all(14);
return result;
}
diff --git a/src/control_center/sections/region.zig b/src/control_center/sections/region.zig
index 4c71bf9..bc783b4 100644
--- a/src/control_center/sections/region.zig
+++ b/src/control_center/sections/region.zig
@@ -211,7 +211,7 @@ fn container(a: std.mem.Allocator, direction: ui.layout.Direction, items: []cons
fn card(a: std.mem.Allocator, items: []const W) !W {
var result = try container(a, .column, items);
const t = panel.palette();
- result.kind = .{ .rect = .{ .color = t.settings_card_bg, .radius = t.settings_card_radius, .border_width = 1, .border_color = t.border_soft } };
+ result.kind = .{ .rect = .{ .color = t.settings_card_bg, .radius = t.settings_card_radius, .border_width = 1, .border_color = t.border_soft, .relief = t.settings_card_relief } };
result.padding = ui.layout.Edges.all(16);
return result;
}
diff --git a/src/control_center/sections/services.zig b/src/control_center/sections/services.zig
index 5ba7764..093167b 100644
--- a/src/control_center/sections/services.zig
+++ b/src/control_center/sections/services.zig
@@ -166,7 +166,7 @@ fn tree(s: *Section, cc: *panel.ControlCenter, client: *systemd.Client, a: std.m
}, false);
actions.width = .auto;
var banner = try group(a, &.{ summary, actions }, narrow);
- banner.kind = .{ .rect = .{ .color = ui.theme.global.app_item, .radius = 8, .border_width = 1, .border_color = ui.theme.global.app_item_border } };
+ banner.kind = .{ .rect = .{ .color = ui.theme.global.app_item, .radius = 8, .border_width = 1, .border_color = ui.theme.global.app_item_border, .relief = ui.theme.global.settings_card_relief } };
banner.padding = ui.layout.Edges.all(12);
try tryAppend(&content, a, banner);
const field = try a.create(W);
diff --git a/src/control_center/sections/shortcuts.zig b/src/control_center/sections/shortcuts.zig
index 52c5491..f41dd91 100644
--- a/src/control_center/sections/shortcuts.zig
+++ b/src/control_center/sections/shortcuts.zig
@@ -195,7 +195,7 @@ fn buildGroups(s: *Section, cc: *panel.ControlCenter, a: std.mem.Allocator) !voi
try rows.append(a, .{ .kind = .{ .rect = .{ .color = t.window_divider } }, .height = .{ .fixed = 1 }, .width = .{ .percent = 1 } });
try rows.append(a, .{ .kind = .container, .direction = .row, .height = .{ .fixed = 60 }, .width = .{ .percent = 1 }, .padding = ui.layout.Edges.xy(12, 0), .gap = 8, .@"align" = .center, .children = controls.items });
};
- card.* = .{ .name = "shortcuts", .kind = .{ .rect = .{ .color = t.settings_card_bg, .radius = t.settings_card_radius, .border_width = 1, .border_color = t.window_divider } }, .direction = .column, .width = .{ .percent = 1 }, .children = rows.items };
+ card.* = .{ .name = "shortcuts", .kind = .{ .rect = .{ .color = t.settings_card_bg, .radius = t.settings_card_radius, .border_width = 1, .border_color = t.window_divider, .relief = t.settings_card_relief } }, .direction = .column, .width = .{ .percent = 1 }, .children = rows.items };
}
}
fn owner(p: ?*anyopaque) *panel.ControlCenter {
diff --git a/src/control_center/sections/users.zig b/src/control_center/sections/users.zig
index 621cb90..c0a1d6f 100644
--- a/src/control_center/sections/users.zig
+++ b/src/control_center/sections/users.zig
@@ -60,7 +60,7 @@ fn text(value: []const u8, size: f32, dim: bool) W {
fn buildCard(a: std.mem.Allocator, children: []const W) !W {
const t = panel.palette();
- return .{ .kind = .{ .rect = .{ .color = t.app_item, .radius = t.settings_card_radius, .border_width = 1, .border_color = t.app_item_border } }, .direction = .column, .padding = ui.layout.Edges.all(14), .gap = 9, .width = .{ .percent = 1 }, .children = try a.dupe(W, children) };
+ return .{ .kind = .{ .rect = .{ .color = t.app_item, .radius = t.settings_card_radius, .border_width = 1, .border_color = t.app_item_border, .relief = t.settings_card_relief } }, .direction = .column, .padding = ui.layout.Edges.all(14), .gap = 9, .width = .{ .percent = 1 }, .children = try a.dupe(W, children) };
}
pub fn build(s: *Section, cc: *panel.ControlCenter) void {
diff --git a/src/control_center/welcome.zig b/src/control_center/welcome.zig
index 368d794..bda5a87 100644
--- a/src/control_center/welcome.zig
+++ b/src/control_center/welcome.zig
@@ -82,7 +82,7 @@ fn choice(cc: *panel.ControlCenter, a: A, tiling: bool) !W {
.id = @intFromBool(tiling),
.on_click = layoutClicked,
.selected = selected,
- .background = .{ .color = t.app_item, .radius = t.settings_card_radius, .border_width = if (selected) 2 else 1, .border_color = if (selected) t.accent else t.app_item_border },
+ .background = .{ .color = t.app_item, .radius = t.settings_card_radius, .border_width = if (selected) 2 else 1, .border_color = if (selected) t.accent else t.app_item_border, .relief = t.settings_card_relief },
.hover_background = .{ .color = t.app_nav_selected, .radius = t.settings_card_radius, .border_width = 2, .border_color = t.accent },
} };
result.padding = ui.layout.Edges.all(if (compact(cc)) 12 else 18);
diff --git a/src/editor/app_paint.zig b/src/editor/app_paint.zig
index 08c0878..8871022 100644
--- a/src/editor/app_paint.zig
+++ b/src/editor/app_paint.zig
@@ -157,7 +157,7 @@ pub fn paintButton(self: *App, cr: *c.cairo_t, r: field.Rect, label: []const u8,
var layer = ui.Layer.begin(cr, r) orelse return;
defer layer.finish();
layer.renderer.palette = theme.shellPalette();
- button.paint(&layer.renderer, layer.local(), .{ .label = label, .variant = .ghost, .size = .sm }, .{ .selected = selected, .pointer = if (self.px >= r.x and self.px < r.x + r.w and self.py >= r.y and self.py < r.y + r.h) .hover else .idle });
+ button.paint(&layer.renderer, layer.local(), .{ .label = label, .variant = .secondary, .size = .sm }, .{ .selected = selected, .pointer = if (self.px >= r.x and self.px < r.x + r.w and self.py >= r.y and self.py < r.y + r.h) .hover else .idle });
}
pub fn render(self: *App, cr: *c.cairo_t) void {
diff --git a/src/taskbar/paint.zig b/src/taskbar/paint.zig
index 0bc23e2..2fe36c9 100644
--- a/src/taskbar/paint.zig
+++ b/src/taskbar/paint.zig
@@ -11,6 +11,7 @@ const start_button = @import("../taskbar/start_button.zig");
const shape = @import("../taskbar/shape.zig");
const window_shape = @import("ui").window_shape;
const ui_theme = @import("ui").theme;
+const ui_relief = @import("ui").relief;
const stats = @import("../ipc/stats.zig");
const log = std.log.scoped(.taskbar);
const bar_height = Taskbar.bar_height;
@@ -323,6 +324,22 @@ pub fn chipPixelArgb(paint: *const ChipPaint, px: f32, py: f32, scale: f32) u32
return paintChipPixel(paint, px, py, scale).argb();
}
+/// Relief shading inside a chip's edge, over its body. A raster is only a few
+/// px wider than its chip, so there is no room for outside shadows: `inset`
+/// is the groove, `raised` the same shading with the two lights swapped.
+fn chipRelief(body: Color, kind: ui_theme.Relief, x: f32, y: f32, w: f32, h: f32, px: f32, py: f32, scale: f32) Color {
+ const spec = ui_relief.Spec.from(ui_theme.global, scale);
+ if (!spec.enabled()) return body;
+ const shape_box: ui_relief.Shape = .{ .x = x * scale, .y = y * scale, .w = w * scale, .h = h * scale, .radius = ui_theme.global.radius * scale };
+ const pair = ui_relief.inset(spec, shape_box, px * scale, py * scale);
+ const shade_dark = if (kind == .inset) spec.dark else spec.light;
+ const shade_light = if (kind == .inset) spec.light else spec.dark;
+ var color = body;
+ color = (Color{ .r = shade_dark[0], .g = shade_dark[1], .b = shade_dark[2], .a = shade_dark[3] * pair.dark }).over(color);
+ color = (Color{ .r = shade_light[0], .g = shade_light[1], .b = shade_light[2], .a = shade_light[3] * pair.light }).over(color);
+ return color;
+}
+
pub fn paintChipPixel(paint: *const ChipPaint, px: f32, py: f32, scale: f32) Color {
const chip = paint.chip;
const cx = paint.x;
@@ -330,6 +347,7 @@ pub fn paintChipPixel(paint: *const ChipPaint, px: f32, py: f32, scale: f32) Col
const lx = px;
const ly = py;
var color = @import("../taskbar/chip_style.zig").pixel(Color, lx, ly, cx, chip_y, chip.width, @floatFromInt(chipSize()), ui_theme.global.radius, scale, paint.fill, paint.border);
+ if (paint.relief != .flat) color = chipRelief(color, paint.relief, cx, chip_y, chip.width, @floatFromInt(chipSize()), lx, ly, scale);
const tile_x = cx + @as(f32, @floatFromInt(chipPad()));
const tile_y = chip_y + @as(f32, @floatFromInt(chipPad()));
const tile_cov = edgeCoverage(chrome.sdRoundedBox(lx, ly, tile_x, tile_y, @floatFromInt(tileSize()), @floatFromInt(tileSize()), tile_radius), scale);
diff --git a/src/taskbar/types.zig b/src/taskbar/types.zig
index aad696c..b9cc0ba 100644
--- a/src/taskbar/types.zig
+++ b/src/taskbar/types.zig
@@ -97,6 +97,10 @@ pub const ChipMemo = struct {
title_size: f32,
font: []const u8,
colors: [6][4]f32,
+ // Inside-edge relief: kind plus the theme values `relief.Spec` reads.
+ relief: ui_theme.Relief,
+ relief_look: [3]f32,
+ relief_colors: [2][4]f32,
pub fn capture(bar: *Taskbar, chip: *const ChipState, now_ms: i64) ChipMemo {
const t = ui_theme.global;
@@ -118,6 +122,9 @@ pub const ChipMemo = struct {
.title_size = t.taskbar_title_size,
.font = t.font,
.colors = .{ ui_theme.taskbar(.taskbar_surface), ui_theme.taskbar(.taskbar_hover), ui_theme.taskbar(.surface_hover), ui_theme.taskbar(.taskbar_border), ui_theme.taskbar(.border_soft), ui_theme.taskbar(.window_fg) },
+ .relief = if (chip.toplevel == bar.server.world.toplevels.first()) t.taskbar_chip_active_relief else t.taskbar_chip_relief,
+ .relief_look = .{ t.relief_depth, t.relief_softness, t.relief_light_angle },
+ .relief_colors = .{ t.relief_dark, t.relief_light },
};
}
};
@@ -313,6 +320,7 @@ pub const ChipPaint = struct {
fill: Color,
border: Color,
bar_height: i32,
+ relief: ui_theme.Relief = .flat,
flat: ChipFlat = .{},
pub fn init(bar: *Taskbar, now_ms: i64, chip: *const ChipState) ChipPaint {
@@ -326,6 +334,7 @@ pub const ChipPaint = struct {
.fill = style.fill,
.border = style.border,
.bar_height = bar.box.height,
+ .relief = if (active) ui_theme.global.taskbar_chip_active_relief else ui_theme.global.taskbar_chip_relief,
};
paint.flat = .init(&paint, bar.wlr_output.scale);
return paint;
@@ -370,7 +379,7 @@ pub const ChipFlat = struct {
const tile: f32 = @floatFromInt(tileSize());
const clear: Color = .{ .r = 0, .g = 0, .b = 0, .a = 0 };
return .{
- .enabled = scale >= 0.75,
+ .enabled = scale >= 0.75 and paint.relief == .flat,
.outer = .{ .x0 = x - 1, .y0 = y - 1, .x1 = x + w + 1, .y1 = y + h + 1 },
.band_h = .{ .x0 = x + 1 + corner, .y0 = y + 2, .x1 = x + 1 + iw - corner, .y1 = y + ih },
.band_v = .{ .x0 = x + 2, .y0 = y + 1 + corner, .x1 = x + iw, .y1 = y + 1 + ih - corner },
diff --git a/src/ui/mod.zig b/src/ui/mod.zig
index f10103b..f041d01 100644
--- a/src/ui/mod.zig
+++ b/src/ui/mod.zig
@@ -37,6 +37,7 @@ pub const font_fallback = @import("font_fallback.zig");
pub const fold = @import("fold.zig");
pub const hover_glide = @import("hover_glide.zig");
pub const key_repeat = @import("key_repeat.zig");
+pub const relief = @import("relief.zig");
pub const sdf = @import("sdf.zig");
pub const shell_icons = @import("shell_icons.zig");
pub const text = @import("text.zig");
diff --git a/src/ui/theme.zig b/src/ui/theme.zig
index 23919dc..b3582e7 100644
--- a/src/ui/theme.zig
+++ b/src/ui/theme.zig
@@ -235,6 +235,18 @@ pub const Theme = struct {
button_pressed_relief: Relief = .flat,
field_relief: Relief = .flat,
dialog_inset_relief: Relief = .flat,
+ /// The dialog card itself (`widgets/dialog.zig`). Raised shadows lie outside
+ /// it, so keep them within the host's backdrop margin.
+ dialog_frame_relief: Relief = .flat,
+ /// The cards around Settings entries. The page scrolls in a clipped
+ /// container, so a raised card's shadow is cut at its edge: prefer `inset`.
+ settings_card_relief: Relief = .flat,
+ /// Taskbar window chips, idle and active (focused). The chip raster ends a
+ /// few px past the chip, so both shade inside the edge: `inset` is a
+ /// groove, `raised` the same shading with light and dark swapped. Main
+ /// theme only; `[taskbar_theme]` does not carry them.
+ taskbar_chip_relief: Relief = .flat,
+ taskbar_chip_active_relief: Relief = .flat,
select_relief: Relief = .flat,
select_popup_relief: Relief = .flat,
checkbox_relief: Relief = .flat,
diff --git a/src/ui/theme_tests.zig b/src/ui/theme_tests.zig
index 02c3877..b2ef3c2 100644
--- a/src/ui/theme_tests.zig
+++ b/src/ui/theme_tests.zig
@@ -352,7 +352,7 @@ test "component relief theme serialization round-trips and omits defaults" {
test "relief keys of the remaining widgets parse, default to flat and round-trip" {
const Relief = theme.Relief;
- const keys = [_][]const u8{ "segmented_relief", "segmented_selected_relief", "stepper_relief", "swatch_relief", "pill_relief", "row_hover_relief", "row_selected_relief" };
+ const keys = [_][]const u8{ "segmented_relief", "segmented_selected_relief", "stepper_relief", "swatch_relief", "pill_relief", "row_hover_relief", "row_selected_relief", "settings_card_relief", "dialog_frame_relief", "taskbar_chip_relief", "taskbar_chip_active_relief" };
for (keys) |key| try std.testing.expect(theme_file.knownKey(key));
const defaults: Theme = .{};
@@ -386,4 +386,6 @@ test "relief keys of the remaining widgets parse, default to flat and round-trip
try std.testing.expectEqual(t.segmented_selected_relief, reloaded.segmented_selected_relief);
try std.testing.expectEqual(t.row_selected_relief, reloaded.row_selected_relief);
try std.testing.expectEqual(t.stepper_relief, reloaded.stepper_relief);
+ try std.testing.expectEqual(Relief.flat, defaults.settings_card_relief);
+ try std.testing.expectEqual(Relief.flat, defaults.taskbar_chip_active_relief);
}
diff --git a/src/ui/widgets/button.zig b/src/ui/widgets/button.zig
index 0342dca..9350966 100644
--- a/src/ui/widgets/button.zig
+++ b/src/ui/widgets/button.zig
@@ -132,8 +132,9 @@ pub fn paintBackground(r: *Renderer, box: Rect, opts: Options, state: State) voi
if (disabled) bg[3] *= t.button_disabled_alpha;
const ring = state.focused and !disabled;
const border_w: f32 = if (ring) 2 else if (opts.variant == .secondary) 1 else 0;
+ const relief: layout.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;
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,
+ .relief = 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,
@@ -142,7 +143,7 @@ pub fn paintBackground(r: *Renderer, box: Rect, opts: Options, state: State) voi
// Directional lighting gives quiet graphite buttons a subtle raised feel.
// Preserve selected, disabled, primary, ghost, and chrome treatments.
- if (opts.variant == .secondary and !state.selected and !disabled and !state.focused and box.w > 0 and box.h >= 6) {
+ if (opts.variant == .secondary and !state.selected and !disabled and !state.focused and !r.reliefActive(relief) and box.w > 0 and box.h >= 6) {
const inset = @min(m.radius, @min(box.w, box.h) / 3);
const strip_w = box.w - inset * 2;
if (strip_w > 0) {
diff --git a/src/ui/widgets/dialog.zig b/src/ui/widgets/dialog.zig
index 008fa42..5dec5a1 100644
--- a/src/ui/widgets/dialog.zig
+++ b/src/ui/widgets/dialog.zig
@@ -76,7 +76,7 @@ pub fn paintFrame(r: *Renderer, box: Rect) void {
/// App dialogs can share the host's menu background without the shell tint.
pub fn paintFrameWithBackground(r: *Renderer, box: Rect, bg: [4]f32) void {
const t = r.palette orelse theme.global;
- r.fillRect(box.x, box.y, box.w, box.h, .{ .color = bg, .radius = t.radius_lg, .border_width = 1, .border_color = t.window_border });
+ r.fillRect(box.x, box.y, box.w, box.h, .{ .color = bg, .radius = t.radius_lg, .border_width = 1, .border_color = t.window_border, .relief = t.dialog_frame_relief });
}
/// An embedded window header: identical height, tint and radius to chrome.