RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
feat: add independent button hover glow setting
Petar Margetić4588dc95509e
diff --git a/src/control_center/sections/appearance.zig b/src/control_center/sections/appearance.zigindex 1e17d04..e8d8c3b 100644--- a/src/control_center/sections/appearance.zig+++ b/src/control_center/sections/appearance.zig@@ -90,6 +90,7 @@ pub const onFontSizeChanged = appearance_chrome.onFontSizeChanged;pub const onRadiusChanged = appearance_chrome.onRadiusChanged;pub const onShadowChanged = appearance_chrome.onShadowChanged;pub const onBorderGlowChanged = appearance_chrome.onBorderGlowChanged;+pub const onButtonHoverGlowChanged = appearance_chrome.onButtonHoverGlowChanged;pub const onChromeOpacityChanged = appearance_chrome.onChromeOpacityChanged;pub const onChromeDarknessChanged = appearance_chrome.onChromeDarknessChanged;pub const onInactiveDimChanged = appearance_chrome.onInactiveDimChanged;@@ -274,6 +275,8 @@ pub const Section = struct {shadow_row_children: [2]Widget = undefined,glow_row_children: [2]Widget = undefined,glow_label_children: [2]Widget = undefined,+ button_hover_glow_row_children: [2]Widget = undefined,+ button_hover_glow_label_children: [2]Widget = undefined,opacity_header_children: [2]Widget = undefined,opacity_group_children: [2]Widget = undefined,opacity_value_buf: [16]u8 = undefined,@@ -517,6 +520,7 @@ pub fn build(out: *Section, cc: *panel.ControlCenter) void {.{ .kind = .container, .direction = .row, .justify = .space_between, .@"align" = .center, .children = &out.radius_row_children },.{ .kind = .container, .direction = .row, .justify = .space_between, .@"align" = .center, .children = &out.shadow_row_children },.{ .kind = .container, .direction = .row, .justify = .space_between, .@"align" = .center, .children = &out.glow_row_children },+ .{ .kind = .container, .direction = .row, .justify = .space_between, .@"align" = .center, .children = &out.button_hover_glow_row_children },chrome_row,buildWindowTabs(out),.{ .kind = .container, .direction = .row, .justify = .space_between, .@"align" = .center, .children = &out.dim_row_children },@@ -589,6 +593,7 @@ pub const Row = enum {radius,shadow,edge_glow,+ button_hover_glow,chrome_opacity,window_tabs,inactive_dim,@@ -606,7 +611,7 @@ pub const groups = [_]struct { title: ?i18n.Message, rows: []const Row }{.{ .title = i18n.msg("Themes & colours"), .rows = &.{ .theme, .taskbar_theme, .theme_pack, .icon_theme, .dark_mode, .app_colors } },.{ .title = i18n.msg("Wallpaper"), .rows = &.{.wallpaper} },.{ .title = i18n.msg("Fonts & cursor"), .rows = &.{ .font_family, .font_size, .cursor } },- .{ .title = i18n.msg("Windows"), .rows = &.{ .radius, .shadow, .edge_glow, .chrome_opacity, .window_tabs, .inactive_dim, .inactive_opacity, .terminal_opacity, .window_gap, .scrollbar_width } },+ .{ .title = i18n.msg("Windows"), .rows = &.{ .radius, .shadow, .edge_glow, .button_hover_glow, .chrome_opacity, .window_tabs, .inactive_dim, .inactive_opacity, .terminal_opacity, .window_gap, .scrollbar_width } },.{ .title = i18n.msg("Motion & feedback"), .rows = &.{ .animations, .animation_speed, .reduced_motion, .focus_zoom, .drag_feedback, .drag_scale, .dodge_file_drags, .launch_splash } },.{ .title = null, .rows = &.{.dock} },.{ .title = null, .rows = &.{.taskbar} },diff --git a/src/control_center/sections/appearance_chrome.zig b/src/control_center/sections/appearance_chrome.zigindex 3647eaa..f9e2583 100644--- a/src/control_center/sections/appearance_chrome.zig+++ b/src/control_center/sections/appearance_chrome.zig@@ -78,6 +78,12 @@ pub fn onBorderGlowChanged(owner: ?*anyopaque, _: usize, on: bool) void {applyThemeChange(section(owner));}+pub fn onButtonHoverGlowChanged(owner: ?*anyopaque, _: usize, on: bool) void {+ if (theme.global.button_hover_glow_enabled == on) return;+ theme.global.button_hover_glow_enabled = on;+ applyThemeChange(section(owner));+}+pub fn onChromeOpacityChanged(owner: ?*anyopaque, _: usize, value: f32) void {const s = section(owner);const clamped = std.math.clamp(value, 0.0, 1.0);diff --git a/src/control_center/sections/appearance_rows.zig b/src/control_center/sections/appearance_rows.zigindex a8bad4d..fb217db 100644--- a/src/control_center/sections/appearance_rows.zig+++ b/src/control_center/sections/appearance_rows.zig@@ -21,6 +21,7 @@ const onFontSizeChanged = appearance_chrome.onFontSizeChanged;const onRadiusChanged = appearance_chrome.onRadiusChanged;const onShadowChanged = appearance_chrome.onShadowChanged;const onBorderGlowChanged = appearance_chrome.onBorderGlowChanged;+const onButtonHoverGlowChanged = appearance_chrome.onButtonHoverGlowChanged;const onChromeOpacityChanged = appearance_chrome.onChromeOpacityChanged;const onChromeDarknessChanged = appearance_chrome.onChromeDarknessChanged;const onInactiveDimChanged = appearance_chrome.onInactiveDimChanged;@@ -232,7 +233,7 @@ pub fn buildBehaviorRows(out: *Section, pal: theme.Theme) void {};}-/// The UI font, cursor theme, font size, radius, shadow and edge glow rows.+/// The UI font, cursor theme, font size, radius, shadow and glow rows.pub fn buildFontRows(out: *Section, arena: std.mem.Allocator, t: theme.Theme, pal: theme.Theme) void {if (out.font_families == null) {out.font_families = @import("ui").font_fallback.listFamilies(out.font_arena.allocator()) catch null;@@ -318,6 +319,15 @@ pub fn buildFontRows(out: *Section, arena: std.mem.Allocator, t: theme.Theme, pa.{ .kind = .container, .direction = .column, .gap = 2, .width = .{ .flex = 1 }, .children = &out.glow_label_children },.{ .name = "border_glow", .kind = .{ .toggle = .{ .on = t.border_glow_enabled, .owner = out, .on_change = &onBorderGlowChanged } } },};++ out.button_hover_glow_label_children = .{+ .{ .kind = .{ .text = .{ .content = i18n.tr("Button hover glow"), .font_size = theme.global.app_text_size, .weight = 600, .color = pal.fg } } },+ .{ .kind = .{ .text = .{ .content = i18n.tr("Light button edges near the pointer"), .font_size = theme.global.settings_description_size, .color = pal.dim } } },+ };+ out.button_hover_glow_row_children = .{+ .{ .kind = .container, .direction = .column, .gap = 2, .width = .{ .flex = 1 }, .children = &out.button_hover_glow_label_children },+ .{ .name = "button_hover_glow", .kind = .{ .toggle = .{ .on = t.button_hover_glow_enabled, .owner = out, .on_change = &onButtonHoverGlowChanged } } },+ };}/// Window chrome height, control gap, opacity and darkness.diff --git a/src/ui/paint_tests.zig b/src/ui/paint_tests.zigindex 92c0186..8dea9dd 100644--- a/src/ui/paint_tests.zig+++ b/src/ui/paint_tests.zig@@ -682,7 +682,7 @@ test "segmented frames, swatches and rows take their own relief keys" {}-test "button proximity glow follows the pointer and stays rounded and clipped" {+test "button hover glow is independent of window edge glow and stays rounded and clipped" {const sample = struct {fn pixel(pixels: []const u32, width: i32, scale: f32, x: f32, y: f32) u32 {const px: usize = @intFromFloat(@floor(x * scale));@@ -705,7 +705,8 @@ test "button proximity glow follows the pointer and stays rounded and clipped" {var renderer = Renderer.init(&pixels, width, height, scale);var palette: theme.Theme = .{};palette.border_glow = .{ 1, 0, 0, 0.60 };- palette.border_glow_enabled = true;+ palette.border_glow_enabled = false;+ palette.button_hover_glow_enabled = true;palette.border_glow_reach = 56;palette.border_glow_length = 72;palette.border_glow_depth = 3;@@ -737,5 +738,19 @@ test "button proximity glow follows the pointer and stays rounded and clipped" {try std.testing.expect((near >> 16) & 0xff > (centre >> 16) & 0xff);try std.testing.expectEqual(@as(u32, 0xff808080), rounded_corner);try std.testing.expectEqual(@as(u32, 0xff808080), outside_clip);++ // Window-edge glow being off must not suppress button glow.+ @memset(&pixels, 0xff808080);+ palette.border_glow_enabled = true;+ palette.button_hover_glow_enabled = false;+ renderer.palette = palette;+ paintButton(&widget, .{+ .variant = .ghost,+ .proximity_distance = 4,+ .proximity_x = 40,+ .proximity_y = -4,+ }, &renderer);+ const button_glow_disabled = sample.pixel(&pixels, width, scale, 60.5, 20.5);+ try std.testing.expectEqual(@as(u32, 0xff808080), button_glow_disabled);}}diff --git a/src/ui/theme.zig b/src/ui/theme.zigindex b3582e7..f489263 100644--- a/src/ui/theme.zig+++ b/src/ui/theme.zig@@ -211,6 +211,9 @@ pub const Theme = struct {/// (`Toplevel.setGlow`). Its alpha is the strength at full proximity; zero/// turns it off.border_glow_enabled: bool = true,+ /// Independent gate for proximity highlights painted inside buttons.+ /// Colour and reach/length/depth are shared with the window-edge glow.+ button_hover_glow_enabled: bool = true,border_glow: [4]f32 = .{ 237.0 / 255.0, 27.0 / 255.0, 46.0 / 255.0, 0.60 },border_glow_length: f32 = 72.0, // along the edge, logical px; fades out smoothlyborder_glow_reach: f32 = 56.0, // pointer distance from the edge where it appearsdiff --git a/src/ui/theme_tests.zig b/src/ui/theme_tests.zigindex b2ef3c2..f54648f 100644--- a/src/ui/theme_tests.zig+++ b/src/ui/theme_tests.zig@@ -350,6 +350,30 @@ test "component relief theme serialization round-trips and omits defaults" {try std.testing.expectEqual(original.field_relief, reloaded.field_relief);}+test "window edge and button hover glow toggles serialize independently and reload" {+ const cases = [_]struct { edge: bool, button: bool }{+ .{ .edge = false, .button = true },+ .{ .edge = true, .button = false },+ .{ .edge = false, .button = false },+ .{ .edge = true, .button = true },+ };++ for (cases) |case| {+ var original: Theme = .{};+ original.border_glow_enabled = case.edge;+ original.button_hover_glow_enabled = case.button;++ var buf: std.ArrayList(u8) = .empty;+ defer buf.deinit(std.testing.allocator);+ try theme_file.writeDiff(std.testing.allocator, &buf, original, .{}, "", false);++ var restored: Theme = .{};+ try theme_file.overlay(std.testing.allocator, &restored, buf.items);+ try std.testing.expectEqual(case.edge, restored.border_glow_enabled);+ try std.testing.expectEqual(case.button, restored.button_hover_glow_enabled);+ }+}+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", "settings_card_relief", "dialog_frame_relief", "taskbar_chip_relief", "taskbar_chip_active_relief" };diff --git a/src/ui/widgets/button.zig b/src/ui/widgets/button.zigindex f4edcf0..683ac71 100644--- a/src/ui/widgets/button.zig+++ b/src/ui/widgets/button.zig@@ -230,7 +230,7 @@ fn paintAdaptiveRelief(/// Both passes stay inside the button's antialiased rounded shape.fn paintProximityGlow(r: *Renderer, box: Rect, radius: f32, state: State) void {const t = r.palette orelse theme.global;- if (!t.border_glow_enabled or state.proximity_distance >= std.math.inf(f32) or+ if (!t.button_hover_glow_enabled or state.proximity_distance >= std.math.inf(f32) ort.border_glow[3] <= 0 or t.border_glow_reach <= 0 ort.border_glow_length <= 0 or t.border_glow_depth <= 0 orbox.w <= 0 or box.h <= 0)