Skip to content

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

Add proximity lighting to Files sidebar headers

Melfaa3aabccde9
diff --git a/src/files/app_hover.zig b/src/files/app_hover.zig
index 6a9dcd2..c8b9596 100644
--- a/src/files/app_hover.zig
+++ b/src/files/app_hover.zig
@@ -547,6 +547,35 @@ pub fn damageSidebarProximity(self: *App, old_x: f64, old_y: f64, new_x: f64, ne
};
damage = if (damage) |current| unionRect(current, row_damage) else row_damage;
}
+
+ // Card headers use the same proximity light as their rows.
+ for (layout.cards) |card| {
+ if (!card.visible) continue;
+
+ const rect: button_widget.Rect = .{
+ .x = 12,
+ .y = @floatFromInt(card.y + 2),
+ .w = @floatFromInt(@max(0, self.sidebarWidth() - self.scrollbarGutter() - 40)),
+ .h = 28,
+ };
+ const clip: button_widget.Rect = .{
+ .x = 8,
+ .y = @floatFromInt(card.y),
+ .w = @floatFromInt(@max(0, self.sidebarWidth() - self.scrollbarGutter() - 16)),
+ .h = @floatFromInt(card.header_height),
+ };
+ const before = button_widget.sampleProximity(rect, @floatCast(old_x), @floatCast(old_y), clip);
+ const after = button_widget.sampleProximity(rect, @floatCast(new_x), @floatCast(new_y), clip);
+ if (@min(before.distance, after.distance) > reach) continue;
+
+ const header_damage: header.Rect = .{
+ .x = rect.x,
+ .y = rect.y,
+ .w = rect.w,
+ .h = rect.h,
+ };
+ damage = if (damage) |current| unionRect(current, header_damage) else header_damage;
+ }
if (damage) |rect| self.addDamage(rect);
}
diff --git a/src/files/app_sidebar_paint.zig b/src/files/app_sidebar_paint.zig
index d11cff8..348f084 100644
--- a/src/files/app_sidebar_paint.zig
+++ b/src/files/app_sidebar_paint.zig
@@ -41,16 +41,7 @@ fn drawSidebarHeader(
y: i32,
content_width: f64,
expanded: bool,
- hovered: bool,
) void {
- if (hovered) {
- shell_ui.drawSidebarHover(cr, .{
- .x = 12,
- .y = @floatFromInt(y + 2),
- .w = @floatCast(@max(0, content_width - 24)),
- .h = 28,
- }, 0.8);
- }
setSource(cr, ui_theme.global.sidebarForeground());
drawText(cr, label, 24, @as(f64, @floatFromInt(y)) + 21, shell_ui.headingSize(), true);
if (shell_ui.Layer.begin(cr, .{
@@ -68,6 +59,32 @@ fn drawSidebarHeader(
}
}
+/// Draws the same theme-configured edge light used by sidebar rows.
+fn drawSidebarHeaderProximity(
+ self: *App,
+ cr: *c.cairo_t,
+ card: app_model.SidebarCardGeometry,
+ content_width: f64,
+) void {
+ shell_ui.drawProximityGlow(
+ cr,
+ .{
+ .x = 12,
+ .y = @floatFromInt(card.y + 2),
+ .w = @floatCast(@max(@as(f64, 0), content_width - 24)),
+ .h = 28,
+ },
+ ui_theme.global.app_sidebar_item_radius,
+ .{ .x = self.mouse_x, .y = self.mouse_y },
+ .{
+ .x = 8,
+ .y = @floatFromInt(card.y),
+ .w = @floatCast(@max(@as(f64, 0), content_width - 16)),
+ .h = @floatFromInt(card.header_height),
+ },
+ );
+}
+
/// Draws the theme-configured edge light in the section's legacy row
/// coordinate space. The pointer is translated to match the Cairo context.
fn drawSidebarRowProximity(
@@ -313,8 +330,8 @@ pub fn renderSidebar(self: *App, cr: *c.cairo_t) void {
@max(0, content_width - 16),
@floatFromInt(height),
);
- const hovered = self.hoverKey() == 940 + i;
- drawSidebarHeader(cr, section_names[i], card.y, content_width, card.expanded, hovered);
+ drawSidebarHeaderProximity(self, cr, card, content_width);
+ drawSidebarHeader(cr, section_names[i], card.y, content_width, card.expanded);
}
const places_card = layout.cards[@intFromEnum(app_model.SidebarSection.places)];