RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Integrate sidebar accordion hit testing
Mel7f1d27c6b7e5
diff --git a/src/files/app.zig b/src/files/app.zigindex b8c98f5..968c71f 100644--- a/src/files/app.zig+++ b/src/files/app.zig@@ -796,6 +796,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 sidebarBodyY = app_sidebar_paint.sidebarBodyY;pub const renderPinDrop = app_sidebar_paint.renderPinDrop;pub const fileOpsSidebarHeight = app_sidebar_paint.fileOpsSidebarHeight;pub const fileOpsSidebarHit = app_sidebar_paint.fileOpsSidebarHit;diff --git a/src/files/app_hover.zig b/src/files/app_hover.zigindex eaa452d..0e42117 100644--- a/src/files/app_hover.zig+++ b/src/files/app_hover.zig@@ -228,13 +228,26 @@ pub fn updateSidebarSurface(self: *App) void {_ = self.sidebar_surface.pointerMotion(null);return;};+ const is_places = index < self.deviceBase();+ const body_y = self.sidebarBodyY(+ if (is_places) .places else .disks,+ self.mouse_x,+ self.mouse_y,+ ) orelse {+ _ = self.sidebar_surface.pointerMotion(null);+ return;+ };const eject = self.ejectAt(self.mouse_x, self.mouse_y);const key: usize = if (eject) |k| 700 + k else switch (self.rowKind(index)) {.builtin => |b| 300 + b,.pin => |j| 800 + j,.device => |k| 600 + k,};- const bounds = if (eject != null) self.ejectRect(index) else self.placeRect(index);+ var bounds = if (eject != null) self.ejectRect(index) else self.placeRect(index);+ bounds.y += self.mouse_y - body_y;+ const layout = self.sidebarLayout();+ const card = layout.cards[if (is_places) 0 else 1];+ const body_top = card.y + card.header_height;_ = self.sidebar_surface.pointerMotion(.{.id = @intCast(key),@@ -245,10 +258,10 @@ pub fn updateSidebarSurface(self: *App) void {.h = @floatCast(bounds.h),},.clip = .{- .x = 0,- .y = @floatFromInt(self.contentTop()),- .w = @floatFromInt(self.sidebarWidth()),- .h = @floatFromInt(self.h - self.contentTop() - self.sidebarFooter()),+ .x = 8,+ .y = @floatFromInt(body_top),+ .w = @floatFromInt(@max(0, self.sidebarWidth() - self.scrollbarGutter() - 16)),+ .h = @floatFromInt(card.body_height),},.role = .interactive,});diff --git a/src/files/app_hover_tests.zig b/src/files/app_hover_tests.zigindex 2d2d7af..97e60df 100644--- a/src/files/app_hover_tests.zig+++ b/src/files/app_hover_tests.zig@@ -198,15 +198,18 @@ test "sidebar hover glides between places and leaves the current one to its owndefer app.deinit();app.loading = false;app.dirty = false;+ const places_card = app.sidebarLayout().cards[@intFromEnum(@import("app_model.zig").SidebarSection.places)];+ const places_source_top = app.contentTop() - app.sidebar_scroll;+ const places_screen_offset: f64 = @floatFromInt(places_card.y + places_card.header_height - places_source_top);// Home is the current place (history starts at home_dir).- app.handleMotion(70, @as(f64, @floatFromInt(app.placeY(0))) + 10);+ app.handleMotion(70, @as(f64, @floatFromInt(app.placeY(0))) + 10 + places_screen_offset);app.dirty = false;app.stepHover(1000);app.stepHover(4000);try std.testing.expectEqual(@as(f32, 0), app.nav_hover.frame.alpha);try std.testing.expect(!app.dirty and !app.hover_active);- app.handleMotion(70, @as(f64, @floatFromInt(app.placeY(1))) + 10);+ app.handleMotion(70, @as(f64, @floatFromInt(app.placeY(1))) + 10 + places_screen_offset);app.stepHover(5000);app.stepHover(5050);try std.testing.expect(app.dirty and app.paint_damage != null);@@ -225,7 +228,7 @@ test "sidebar hover glides between places and leaves the current one to its owntry std.testing.expectEqual(first.y + first.h, next.y);var y = first.y;while (y < next.y + next.h) : (y += 1) {- app.mouse_y = y;+ app.mouse_y = y + places_screen_offset;app.updateSidebarSurface();try std.testing.expect(app.hoveredPlace() != null);}@@ -233,7 +236,7 @@ test "sidebar hover glides between places and leaves the current one to its ownapp.h = original_height;// Three places down: partway, the highlight sits between the two rows.- app.handleMotion(70, @as(f64, @floatFromInt(app.placeY(4))) + 10);+ app.handleMotion(70, @as(f64, @floatFromInt(app.placeY(4))) + 10 + places_screen_offset);app.stepHover(8100);app.stepHover(8150);const mid = app.nav_hover.frame;@@ -256,13 +259,16 @@ test "sidebar surface owns place hover and clears modal and departed targets" {defer app.deinit();app.loading = false;- app.handleMotion(70, @as(f64, @floatFromInt(app.placeY(1))) + 10);+ const places_card = app.sidebarLayout().cards[@intFromEnum(@import("app_model.zig").SidebarSection.places)];+ const places_source_top = app.contentTop() - app.sidebar_scroll;+ const places_screen_offset: f64 = @floatFromInt(places_card.y + places_card.header_height - places_source_top);+ app.handleMotion(70, @as(f64, @floatFromInt(app.placeY(1))) + 10 + places_screen_offset);try std.testing.expectEqual(@as(u64, 301), app.sidebar_surface.hovered.?.id);try std.testing.expectEqual(@as(?usize, 1), app.hoveredPlace());// The current place keeps its identity for pointer damage, but paints// its own selected fill instead of receiving the hover glide.- app.handleMotion(70, @as(f64, @floatFromInt(app.placeY(0))) + 10);+ app.handleMotion(70, @as(f64, @floatFromInt(app.placeY(0))) + 10 + places_screen_offset);try std.testing.expectEqual(@as(u64, 300), app.sidebar_surface.hovered.?.id);try std.testing.expectEqual(@as(?usize, null), app.hoveredPlace());diff --git a/src/files/app_places.zig b/src/files/app_places.zigindex 620c111..0d09675 100644--- a/src/files/app_places.zig+++ b/src/files/app_places.zig@@ -154,10 +154,19 @@ pub fn placeAt(self: *App, x: f64, y: f64) ?usize {if (self.sidebarScrollbar()) |bar| {if (bar.overTrack(@floatCast(x), @floatCast(y))) return null;}- for (0..self.rowCount()) |i| {- if (!self.placeVisible(i)) continue;- const row = self.placeRect(i);- if (y >= row.y and y < row.y + row.h) return i;+ if (self.sidebarBodyY(.places, x, y)) |body_y| {+ for (0..self.deviceBase()) |i| {+ if (!self.placeVisible(i)) continue;+ const row = self.placeRect(i);+ if (body_y >= row.y and body_y < row.y + row.h) return i;+ }+ }+ if (self.sidebarBodyY(.disks, x, y)) |body_y| {+ for (self.deviceBase()..self.rowCount()) |i| {+ if (!self.placeVisible(i)) continue;+ const row = self.placeRect(i);+ if (body_y >= row.y and body_y < row.y + row.h) return i;+ }}return null;}@@ -200,7 +209,8 @@ pub fn ejectRect(self: *App, index: usize) header.Rect {pub fn ejectAt(self: *App, x: f64, y: f64) ?usize {const index = self.placeAt(x, y) orelse return null;const volume = self.deviceAt(index) orelse return null;- if (volume.mount == null or !self.ejectRect(index).contains(x, y)) return null;+ const body_y = self.sidebarBodyY(.disks, x, y) orelse return null;+ if (volume.mount == null or !self.ejectRect(index).contains(x, body_y)) return null;return index - self.deviceBase();}@@ -219,11 +229,12 @@ pub fn pinSlotAt(self: *App, x: f64, y: f64) ?usize {if (self.sidebarScrollbar()) |bar| {if (x >= @as(f64, bar.track.x)) return null;}+ const body_y = self.sidebarBodyY(.places, x, y) orelse return null;const step: f64 = @floatFromInt(self.placeStep());const count = self.pins.items.items.len;const top: f64 = @floatFromInt(self.placeY(places_start) - 30);- if (y < top or y >= self.pinBoundary(count) + 16) return null;- const nearest = @round((y - self.pinBoundary(0)) / step);+ if (body_y < top or body_y >= self.pinBoundary(count) + 16) return null;+ const nearest = @round((body_y - self.pinBoundary(0)) / step);return @intFromFloat(std.math.clamp(nearest, 0, @as(f64, @floatFromInt(count))));}diff --git a/src/files/app_sidebar_paint.zig b/src/files/app_sidebar_paint.zigindex 76d1df5..ae400e5 100644--- a/src/files/app_sidebar_paint.zig+++ b/src/files/app_sidebar_paint.zig@@ -65,7 +65,7 @@ pub fn sidebarLayout(self: *App) app_model.SidebarLayout {const top = self.contentTop() - self.sidebar_scroll;const pin_bottom = self.pinRowY(self.pins.items.items.len);const old_places_top = self.contentTop() - self.sidebar_scroll;- const places_body = @max(0, pin_bottom + 16 - old_places_top - app_model.SidebarLayout.header_height);+ const places_body = @max(0, pin_bottom + 16 - old_places_top);const disks_body = @max(0, self.deviceBlock() - app_model.SidebarLayout.header_height);const git_body: i32 = if (self.repository() != null)@intFromFloat(self.gitCardHeight())@@ -100,6 +100,30 @@ pub fn sidebarHeaderAt(self: *App, x: f64, y: f64) ?app_model.SidebarSection {return null;}+/// Maps a pointer position in an expanded card body back to the coordinate+/// space used by that section's existing content. Sections already rendered+/// in accordion coordinates (Git and Transfers) pass through unchanged.+pub fn sidebarBodyY(self: *App, section: app_model.SidebarSection, x: f64, y: f64) ?f64 {+ const layout = self.sidebarLayout();+ const card = layout.cards[@intFromEnum(section)];+ if (!card.visible or !card.expanded or card.body_height <= 0) return null;++ const left: f64 = 8;+ const right = @as(f64, @floatFromInt(self.sidebarWidth() - self.scrollbarGutter() - 8));+ if (x < left or x >= right) return null;++ const body_top: f64 = @floatFromInt(card.y + card.header_height);+ const body_bottom = body_top + @as(f64, @floatFromInt(card.body_height));+ if (y < body_top or y >= body_bottom) return null;++ const source_top: i32 = switch (section) {+ .places => self.contentTop() - self.sidebar_scroll,+ .disks => self.pinRowY(self.pins.items.items.len) + 24,+ .git, .transfers => card.y + card.header_height,+ };+ return y - body_top + @as(f64, @floatFromInt(source_top));+}+/// DEVICES: a heading and one row per volume, dimmed while unmounted, with/// an eject button on the mounted ones.pub fn renderDevices(self: *App, cr: *c.cairo_t, content_width: f64) void {diff --git a/src/files/app_sidebar_tests.zig b/src/files/app_sidebar_tests.zigindex de03da9..6117453 100644--- a/src/files/app_sidebar_tests.zig+++ b/src/files/app_sidebar_tests.zig@@ -66,6 +66,8 @@ test "sidebar layout uses shared headers and only expanded visible body" {test "sidebar header clicks select sections without collapsing the active card" {var app = try testApp();defer app.deinit();+ app.w = 800;+ app.h = 1000;try std.testing.expectEqual(app_model.SidebarSection.places, app.sidebar_section);try std.testing.expect(!app.sidebar_section_selected);@@ -98,6 +100,31 @@ test "sidebar header clicks select sections without collapsing the active card"try std.testing.expectEqual(@as(?app_model.SidebarSection, null), app.sidebarHeaderAt(-1, selected_y));}+test "sidebar body geometry rejects hidden areas and translates legacy section coordinates" {+ var app = try testApp();+ defer app.deinit();++ const places = app.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.places)];+ const places_y = @as(f64, @floatFromInt(places.y + places.header_height)) + 5;+ const places_source_top = app.contentTop() - app.sidebar_scroll;+ try std.testing.expectEqual(@as(?f64, @as(f64, @floatFromInt(places_source_top)) + 5), app.sidebarBodyY(.places, 70, places_y));+ try std.testing.expectEqual(@as(?f64, null), app.sidebarBodyY(.places, 7, places_y));+ try std.testing.expectEqual(@as(?f64, @floatFromInt(places_source_top)), app.sidebarBodyY(.places, 70, @floatFromInt(places.y + places.header_height)));+ try std.testing.expectEqual(@as(?f64, null), app.sidebarBodyY(.places, 70, @as(f64, @floatFromInt(places.y + places.header_height + places.body_height))));++ // The compact Disks header is not an interactive body while Places owns+ // the accordion, even if a stale legacy device row would overlap it.+ try std.testing.expectEqual(@as(?f64, null), app.sidebarBodyY(.disks, 70, places_y));++ app.sidebar_section = .disks;+ const disks = app.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.disks)];+ const disks_y = @as(f64, @floatFromInt(disks.y + disks.header_height)) + 5;+ const disks_source_top = app.pinRowY(app.pins.items.items.len) + 24;+ try std.testing.expect(disks.expanded);+ try std.testing.expectEqual(@as(?f64, @as(f64, @floatFromInt(disks_source_top)) + 5), app.sidebarBodyY(.disks, 70, disks_y));+ try std.testing.expectEqual(@as(?f64, null), app.sidebarBodyY(.places, 70, disks_y));+}+test "list column resize pushes following columns and scrolls in Files and chooser" {for ([_]bool{ false, true }) |chooser| {var app = try testApp();@@ -167,7 +194,12 @@ test "sidebar menus unpin only Places and close gaps without changing selection"app.items.items[0].selected = true;const y = app.placeY(App.places_start);const last_place_y = app.placeY(App.pin_base - 1);- app.handleMotion(70, @floatFromInt(y + 10));+ const places_card = app.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.places)];+ const places_body_top = places_card.y + places_card.header_height;+ const places_source_top = app.contentTop() - app.sidebar_scroll;+ const screen_row_y = @as(f64, @floatFromInt(places_body_top)) ++ @as(f64, @floatFromInt(y - places_source_top));+ app.handleMotion(70, screen_row_y + 10);app.handleButton(0x111, true);try std.testing.expectEqual(MenuKind.sidebar, app.menu.?);try std.testing.expectEqualStrings("Open in New Window", app.menuLabels()[1]);@@ -176,11 +208,11 @@ test "sidebar menus unpin only Places and close gaps without changing selection"app.runMenu(3); // Properties must not alter pinned places.app.closeDialog();try std.testing.expect(app.placeVisible(App.places_start));- app.openMenu(.sidebar, 70, @floatFromInt(y));+ app.openMenu(.sidebar, 70, screen_row_y);app.runMenu(2);try std.testing.expect(!app.placeVisible(App.places_start));try std.testing.expectEqual(y, app.placeY(App.places_start + 1));- try std.testing.expectEqual(@as(?usize, App.places_start + 1), app.placeAt(70, @floatFromInt(y + 10)));+ try std.testing.expectEqual(@as(?usize, App.places_start + 1), app.placeAt(70, screen_row_y + 10));try std.testing.expectEqual(last_place_y - app.placeStep(), app.placeY(App.pin_base - 1));try std.testing.expect(app.items.items[0].selected);for ([_]usize{ 0, 1 }) |index| {@@ -250,20 +282,26 @@ test "pins sit after Projects, take drops by gap and keep the rows in drawn ordeapp.device_list.items = &volumes;try std.testing.expectEqual(App.pin_base + 2, app.deviceBase());try std.testing.expectEqual(app.placeY(App.pin_base + 1) + 44 + step, app.placeY(app.deviceBase()));- try std.testing.expectEqual(@as(?usize, App.pin_base + 1), app.placeAt(70, @floatFromInt(app.placeY(App.pin_base + 1) + 10)));- app.handleMotion(70, @floatFromInt(app.placeY(App.pin_base + 1) + 10));+ const places_card = app.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.places)];+ const places_body_top = places_card.y + places_card.header_height;+ const places_source_top = app.contentTop() - app.sidebar_scroll;+ const places_screen_offset: f64 = @floatFromInt(places_body_top - places_source_top);+ const pin_screen_y = @as(f64, @floatFromInt(places_body_top)) ++ @as(f64, @floatFromInt(app.placeY(App.pin_base + 1) + 10 - places_source_top));+ try std.testing.expectEqual(@as(?usize, App.pin_base + 1), app.placeAt(70, pin_screen_y));+ app.handleMotion(70, pin_screen_y);try std.testing.expectEqual(@as(usize, 801), app.hoverKey());app.device_list.items = &.{};// A drag snaps to the nearest gap from anywhere on PLACES, and only there.- const desktop: f64 = @floatFromInt(app.placeY(App.places_start) + 10);- const first_gap = app.pinBoundary(0);+ const desktop: f64 = @as(f64, @floatFromInt(app.placeY(App.places_start) + 10)) + places_screen_offset;+ const first_gap = app.pinBoundary(0) + places_screen_offset;try std.testing.expectEqual(@as(?usize, 0), app.pinSlotAt(70, desktop));try std.testing.expectEqual(@as(?usize, 0), app.pinSlotAt(70, first_gap + 4));- try std.testing.expectEqual(@as(?usize, 1), app.pinSlotAt(70, app.pinBoundary(1) - 4));- try std.testing.expectEqual(@as(?usize, 2), app.pinSlotAt(70, app.pinBoundary(2) + 10));- try std.testing.expectEqual(@as(?usize, null), app.pinSlotAt(70, @floatFromInt(app.placeY(0) + 10)));- try std.testing.expectEqual(@as(?usize, null), app.pinSlotAt(70, app.pinBoundary(2) + 40));+ try std.testing.expectEqual(@as(?usize, 1), app.pinSlotAt(70, app.pinBoundary(1) - 4 + places_screen_offset));+ try std.testing.expectEqual(@as(?usize, 2), app.pinSlotAt(70, app.pinBoundary(2) + 10 + places_screen_offset));+ try std.testing.expectEqual(@as(?usize, null), app.pinSlotAt(70, @as(f64, @floatFromInt(app.placeY(0) + 10)) + places_screen_offset));+ try std.testing.expectEqual(@as(?usize, null), app.pinSlotAt(70, app.pinBoundary(2) + 40 + places_screen_offset));try std.testing.expectEqual(@as(?usize, null), app.pinSlotAt(400, desktop));try std.testing.expect(app.dropMotion(70, first_gap + 4));try std.testing.expectEqual(@as(?usize, 0), app.pin_drop);@@ -273,9 +311,13 @@ test "pins sit after Projects, take drops by gap and keep the rows in drawn ordetry std.testing.expect(!app.dropMotion(400, desktop));// The Trash row is a drop target of its own, above the pins' gaps.- const trash_row: f64 = @floatFromInt(app.placeY(App.trash_place) + 10);+ const trash_row: f64 = @as(f64, @floatFromInt(app.placeY(App.trash_place) + 10)) ++ places_screen_offset;try std.testing.expect(app.trashDropAt(70, trash_row));- try std.testing.expect(!app.trashDropAt(70, @floatFromInt(app.placeY(0) + 10)));+ try std.testing.expect(!app.trashDropAt(+ 70,+ @as(f64, @floatFromInt(app.placeY(0) + 10)) + places_screen_offset,+ ));try std.testing.expect(!app.trashDropAt(70, desktop));try std.testing.expectEqual(@as(?usize, null), app.pinSlotAt(70, trash_row));app.dirty = false;@@ -337,18 +379,30 @@ test "Sidebar separates Disks from Places; only mounted volumes eject" {// compact height when volumes are added.try std.testing.expectEqual(extent, app.sidebarExtent());- const row_y: f64 = @floatFromInt(app.placeY(mounted) + 10);+ const collapsed_disks = app.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.disks)];+ const collapsed_body_y: f64 = @floatFromInt(collapsed_disks.y + collapsed_disks.header_height + 1);+ try std.testing.expectEqual(@as(?usize, null), app.placeAt(70, collapsed_body_y));+ try std.testing.expectEqual(@as(?usize, null), app.pinSlotAt(70, collapsed_body_y));++ app.sidebar_section = .disks;+ const disks = app.sidebarLayout().cards[@intFromEnum(app_model.SidebarSection.disks)];+ const screen_body_top = disks.y + disks.header_height;+ const source_body_top = app.pinRowY(app.pins.items.items.len) + 24;+ const disks_screen_offset: f64 = @floatFromInt(screen_body_top - source_body_top);+ const row_y: f64 = @as(f64, @floatFromInt(app.placeY(mounted) + 10)) + disks_screen_offset;try std.testing.expectEqual(@as(?usize, mounted), app.placeAt(70, row_y));const button = app.ejectRect(mounted);- try std.testing.expectEqual(@as(?usize, 0), app.ejectAt(button.x + 5, button.y + 5));+ const button_y = button.y + screen_body_top - source_body_top;+ try std.testing.expectEqual(@as(?usize, 0), app.ejectAt(button.x + 5, button_y + 5));try std.testing.expectEqual(@as(?usize, null), app.ejectAt(70, row_y));const other = app.ejectRect(unmounted);- try std.testing.expectEqual(@as(?usize, null), app.ejectAt(other.x + 5, other.y + 5));- app.handleMotion(button.x + 5, button.y + 5);+ const other_y = other.y + screen_body_top - source_body_top;+ try std.testing.expectEqual(@as(?usize, null), app.ejectAt(other.x + 5, other_y + 5));+ app.handleMotion(button.x + 5, button_y + 5);try std.testing.expectEqual(@as(usize, 700), app.hoverKey());app.handleMotion(70, row_y);try std.testing.expectEqual(@as(usize, 600), app.hoverKey());- app.handleMotion(70, @floatFromInt(app.placeY(unmounted) + 10));+ app.handleMotion(70, @as(f64, @floatFromInt(app.placeY(unmounted) + 10)) + disks_screen_offset);try std.testing.expectEqual(@as(usize, 601), app.hoverKey());app.menu = .device;