RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Align sidebar accordion hit testing and repaint
Mel47ab3425dd44
diff --git a/src/files/app.zig b/src/files/app.zigindex 6009e21..5c02fff 100644--- a/src/files/app.zig+++ b/src/files/app.zig@@ -803,6 +803,7 @@ pub const App = struct {pub const renderSidebar = app_sidebar_paint.renderSidebar;pub const sidebarLayout = app_sidebar_paint.sidebarLayout;pub const sidebarHeaderAt = app_sidebar_paint.sidebarHeaderAt;+ pub const sidebarHeaderBounds = app_sidebar_paint.sidebarHeaderBounds;pub const sidebarBodyY = app_sidebar_paint.sidebarBodyY;pub const renderPinDrop = app_sidebar_paint.renderPinDrop;pub const fileOpsSidebarHeight = app_sidebar_paint.fileOpsSidebarHeight;diff --git a/src/files/app_hover.zig b/src/files/app_hover.zigindex 2e266c0..ca33140 100644--- a/src/files/app_hover.zig+++ b/src/files/app_hover.zig@@ -18,13 +18,7 @@ pub fn hoverBounds(self: *App, key: usize) ?header.Rect {if (key >= 920 and key < 926) return @import("app_audio_bar.zig").rect(self);if (key >= 940 and key < 944) {const card = self.sidebarLayout().cards[key - 940];- if (!card.visible) return null;- return .{- .x = 8,- .y = @floatFromInt(card.y),- .w = @floatFromInt(@max(0, self.sidebarWidth() - self.scrollbarGutter() - 16)),- .h = @floatFromInt(card.header_height),- };+ return self.sidebarHeaderBounds(card);}if (key >= std.math.maxInt(usize) - 4096) return null;if (key >= 900 and key < 904) return .{ .x = 0, .y = 0, .w = @floatFromInt(self.w), .h = @floatFromInt(self.h) };@@ -600,19 +594,19 @@ pub fn damageSidebarProximity(self: *App, old_x: f64, old_y: f64, new_x: f64, ne// Card headers use the same proximity light as their rows.for (layout.cards) |card| {- if (!card.visible) continue;+ const bounds = self.sidebarHeaderBounds(card) orelse continue;const rect: button_widget.Rect = .{.x = 12,- .y = @floatFromInt(card.y + 2),- .w = @floatFromInt(@max(0, self.sidebarWidth() - self.scrollbarGutter() - 24)),+ .y = @floatCast(bounds.y + 2),+ .w = @floatCast(@max(0, bounds.w - 8)),.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),+ .x = @floatCast(bounds.x),+ .y = @floatCast(bounds.y),+ .w = @floatCast(bounds.w),+ .h = @floatCast(bounds.h),};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);@@ -623,9 +617,9 @@ pub fn damageSidebarProximity(self: *App, old_x: f64, old_y: f64, new_x: f64, ne// A clip that cuts those arcs rasterizes the card fill a level// differently from a complete repaint.const header_damage: header.Rect = .{- .x = clip.x,+ .x = bounds.x,.y = rect.y,- .w = clip.w,+ .w = bounds.w,.h = rect.h,};damage = if (damage) |current| unionRect(current, header_damage) else header_damage;diff --git a/src/files/app_hover_tests.zig b/src/files/app_hover_tests.zigindex 86f3221..27c0a0b 100644--- a/src/files/app_hover_tests.zig+++ b/src/files/app_hover_tests.zig@@ -61,6 +61,21 @@ test "retained hover repairs match complete Cairo rasters across isolated transiconst field = header.field(app.w);try points.append(std.testing.allocator, .{ field.x + 12, field.y + 18 });+ // Exercise accordion headers at their painted bounds, including the+ // right edge where the scrollbar gutter and animated clip matter.+ for (app.sidebarLayout().cards) |card| {+ const bounds = app.sidebarHeaderBounds(card) orelse continue;+ const y = bounds.y + bounds.h / 2;+ try points.append(std.testing.allocator, .{+ bounds.x + bounds.w / 2,+ y,+ });+ try points.append(std.testing.allocator, .{+ bounds.x + bounds.w - 0.5,+ y,+ });+ }+// Exercise visible sidebar rows without depending on their hover keys.for (0..app.rowCount()) |index| {if (!app.placeVisible(index)) continue;diff --git a/src/files/app_sidebar_paint.zig b/src/files/app_sidebar_paint.zigindex 0389d41..3f3d6c1 100644--- a/src/files/app_sidebar_paint.zig+++ b/src/files/app_sidebar_paint.zig@@ -10,6 +10,7 @@ const recent = @import("recent.zig");const icons = @import("../icon_cache.zig");const shell_ui = @import("ui").cairo;const ui_theme = @import("ui").theme;+const header = @import("header.zig");const pins_mod = @import("pins.zig");const app_model = @import("app_model.zig");const places = App.places;@@ -64,24 +65,23 @@ fn drawSidebarHeader(fn drawSidebarHeaderProximity(self: *App,cr: *c.cairo_t,- card: app_model.SidebarCardGeometry,- content_width: f64,+ bounds: header.Rect,) void {shell_ui.drawProximityGlow(cr,.{.x = 12,- .y = @floatFromInt(card.y + 2),- .w = @floatCast(@max(@as(f64, 0), content_width - 24)),+ .y = @floatCast(bounds.y + 2),+ .w = @floatCast(@max(@as(f64, 0), bounds.w - 8)),.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),+ .y = @floatCast(bounds.y),+ .w = @floatCast(bounds.w),+ .h = @floatCast(bounds.h),},);}@@ -145,20 +145,43 @@ pub fn sidebarLayout(self: *App) app_model.SidebarLayout {);}+/// The content width used by sidebar painting: the scrollbar track when it+/// exists, otherwise the final target width while the panel is animating.+fn sidebarContentWidth(self: *App) f64 {+ return if (self.sidebarScrollbar()) |bar|+ @as(f64, @floatCast(bar.track.x))+ else+ @as(f64, @floatFromInt(self.sidebarTargetWidth()));+}++/// The visible header bounds after applying the same right edge as painting+/// and the sidebar's current animated clip width.+pub fn sidebarHeaderBounds(self: *App, card: app_model.SidebarCardGeometry) ?header.Rect {+ if (!card.visible or self.sidebarWidth() <= 8) return null;+ const right = @min(+ sidebarContentWidth(self) - 8,+ @as(f64, @floatFromInt(self.sidebarWidth())),+ );+ const width = right - 8;+ if (width <= 0) return null;+ return .{+ .x = 8,+ .y = @floatFromInt(card.y),+ .w = width,+ .h = @floatFromInt(card.header_height),+ };+}+/// Returns the visible accordion header under the pointer. Card bodies are/// deliberately excluded so section selection cannot steal their controls.pub fn sidebarHeaderAt(self: *App, x: f64, y: f64) ?app_model.SidebarSection {- if (self.sidebarWidth() <= 16 or- x < 8 or x >= @as(f64, @floatFromInt(self.sidebarWidth() - 8)) or- y < @as(f64, @floatFromInt(self.contentTop())) or+ if (y < @as(f64, @floatFromInt(self.contentTop())) ory >= @as(f64, @floatFromInt(self.h - self.sidebarFooter()))) return null;const layout = self.sidebarLayout();for (layout.cards, 0..) |card, i| {- if (!card.visible) continue;- const top: f64 = @floatFromInt(card.y);- const bottom = top + @as(f64, @floatFromInt(card.header_height));- if (y >= top and y < bottom) return @enumFromInt(i);+ const bounds = sidebarHeaderBounds(self, card) orelse continue;+ if (bounds.contains(x, y)) return @enumFromInt(i);}return null;}@@ -303,9 +326,8 @@ pub fn drawPackPlaceIcon(self: *App, cr: *c.cairo_t, index: usize, y: f64, alphapub fn renderSidebar(self: *App, cr: *c.cairo_t) void {const width: f64 = @floatFromInt(self.sidebarWidth());if (width == 0) return;- const bar = self.sidebarScrollbar();// Labels keep their final layout while the panel grows or shrinks.- const content_width = if (bar) |b| @as(f64, b.track.x) else @as(f64, @floatFromInt(self.sidebarTargetWidth()));+ const content_width = sidebarContentWidth(self);c.cairo_save(cr);defer c.cairo_restore(cr);c.cairo_rectangle(cr, 0, @floatFromInt(self.contentTop()), width, @floatFromInt(self.h - self.contentTop() - self.sidebarFooter()));@@ -333,7 +355,9 @@ pub fn renderSidebar(self: *App, cr: *c.cairo_t) void {@max(0, content_width - 16),@floatFromInt(height),);- drawSidebarHeaderProximity(self, cr, card, content_width);+ if (sidebarHeaderBounds(self, card)) |bounds| {+ drawSidebarHeaderProximity(self, cr, bounds);+ }drawSidebarHeader(cr, section_names[i], card.y, content_width, card.expanded);}diff --git a/src/files/app_sidebar_tests.zig b/src/files/app_sidebar_tests.zigindex 2451fbe..2e2ea23 100644--- a/src/files/app_sidebar_tests.zig+++ b/src/files/app_sidebar_tests.zig@@ -103,6 +103,73 @@ test "sidebar header clicks independently toggle sections" {try std.testing.expectEqual(@as(?app_model.SidebarSection, null), app.sidebarHeaderAt(-1, selected_y));}+test "sidebar header bounds follow painted width and scrollbar track" {+ var app = try testApp();+ defer app.deinit();+ app.w = 800;+ app.h = 1000;+ app.sidebar_px = 180;++ const places = app.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.places)];+ const bounds = app.sidebarHeaderBounds(places).?;+ try std.testing.expectEqual(@as(f64, 8), bounds.x);+ try std.testing.expectEqual(@as(f64, 172), bounds.w);++ const center_y = bounds.y + bounds.h / 2;+ try std.testing.expectEqual(+ app_model.SidebarSection.places,+ app.sidebarHeaderAt(bounds.x + bounds.w - 0.5, center_y).?,+ );+ try std.testing.expectEqual(+ @as(?app_model.SidebarSection, null),+ app.sidebarHeaderAt(bounds.x + bounds.w, center_y),+ );+ try std.testing.expectEqual(bounds, app.hoverBounds(940).?);++ // A short viewport forces a sidebar scrollbar. Header hit bounds must+ // stop at the same track edge used by the painter.+ app.h = 220;+ app.sidebar_expanded[1] = true;+ if (app.sidebarScrollbar()) |bar| {+ const scrolled_places = app.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.places)];+ const scrolled_bounds = app.sidebarHeaderBounds(scrolled_places).?;+ try std.testing.expectApproxEqAbs(+ @as(f64, @floatCast(bar.track.x - 16)),+ scrolled_bounds.w,+ 0.001,+ );+ try std.testing.expectEqual(+ @as(?app_model.SidebarSection, null),+ app.sidebarHeaderAt(@as(f64, @floatCast(bar.track.x)), scrolled_bounds.y + 10),+ );+ } else {+ return error.TestUnexpectedResult;+ }+}++test "adjacent collapsed sidebar headers invalidate their shared transition area" {+ var app = try testApp();+ defer app.deinit();+ app.w = 800;+ app.h = 1000;+ app.sidebar_expanded[0] = false;++ const first = app.hoverBounds(940).?;+ const second = app.hoverBounds(941).?;+ try std.testing.expect(second.y >= first.y + first.h);++ app.dirty = false;+ app.paint_damage = null;+ app.invalidateHover(940, 941);+ const damage = app.paint_damage.?;+ try std.testing.expect(damage.x <= first.x);+ try std.testing.expect(damage.x + damage.w >= first.x + first.w);+ try std.testing.expect(damage.x <= second.x);+ try std.testing.expect(damage.x + damage.w >= second.x + second.w);+ try std.testing.expect(damage.y <= first.y);+ try std.testing.expect(damage.y + damage.h >= second.y + second.h);+}+test "sidebar body geometry rejects hidden areas and translates legacy section coordinates" {var app = try testApp();defer app.deinit();