RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
refactor(files): route column header hover through interaction surface
Petar Margetić3815a81d27a2
diff --git a/src/files/app.zig b/src/files/app.zigindex c9afcf4..c4d85d4 100644--- a/src/files/app.zig+++ b/src/files/app.zig@@ -189,6 +189,7 @@ pub const App = struct {toolbar_hover: ToolbarHover = .{},toolbar_surface: interaction_surface.Surface = .{},sidebar_surface: interaction_surface.Surface = .{},+ column_surface: interaction_surface.Surface = .{},nav_hover: hover_glide.Glide = .{},item_hover: hover_glide.Glide = .{},// Each path section fades independently, including when crossing a separator.@@ -446,6 +447,7 @@ pub const App = struct {pub const toolbarButtonEnabled = app_hover.toolbarButtonEnabled;pub const updateToolbarSurface = app_hover.updateToolbarSurface;pub const updateSidebarSurface = app_hover.updateSidebarSurface;+ pub const updateColumnSurface = app_hover.updateColumnSurface;pub const hoveredToolbarButton = app_hover.hoveredToolbarButton;pub const toolbarButtonProximity = app_hover.toolbarButtonProximity;pub const damageToolbarProximity = app_hover.damageToolbarProximity;diff --git a/src/files/app_hover.zig b/src/files/app_hover.zigindex fd3f6ee..852a5ae 100644--- a/src/files/app_hover.zig+++ b/src/files/app_hover.zig@@ -91,6 +91,46 @@ pub fn clipToViewport(self: *App, rect: header.Rect) header.Rect {return .{ .x = rect.x, .y = y, .w = rect.w, .h = @max(0, bottom - y) };}+/// The pointer's list header column, using Files' existing header geometry.+pub fn updateColumnSurface(self: *App) void {+ if (!self.list_view or self.transfer_view.active or self.dialog != null or self.menu != null) {+ _ = self.column_surface.pointerMotion(null);+ return;+ }++ if (self.mouse_x < @as(f64, @floatFromInt(self.sidebarWidth())) or+ self.mouse_x >= @as(f64, @floatFromInt(self.w - self.scrollbarGutter())))+ {+ _ = self.column_surface.pointerMotion(null);+ return;+ }++ for (0..@min(4, column_labels.len)) |i| {+ const rect = self.listColumn(i);+ if (!rect.contains(self.mouse_x, self.mouse_y)) continue;++ _ = self.column_surface.pointerMotion(.{+ .id = @intCast(400 + i),+ .rect = .{+ .x = @floatCast(rect.x),+ .y = @floatCast(rect.y),+ .w = @floatCast(rect.w),+ .h = @floatCast(rect.h),+ },+ .clip = .{+ .x = @floatFromInt(self.sidebarWidth()),+ .y = @floatFromInt(self.contentTop()),+ .w = @floatFromInt(self.w - self.sidebarWidth() - self.scrollbarGutter()),+ .h = 30,+ },+ .role = .interactive,+ });+ return;+ }++ _ = self.column_surface.pointerMotion(null);+}+/// The pointer's sidebar row, unless that is the current place, which/// paints its own fill.pub fn updateSidebarSurface(self: *App) void {@@ -301,6 +341,7 @@ pub fn stepHover(self: *App, now: i64) void {const pixel = anim.rasterPixelQuantum(@floatFromInt(self.scale));self.updateSidebarSurface();+ self.updateColumnSurface();if (self.sidebarWidth() > 0) {const before = self.nav_hover.frame;self.nav_hover.setTarget(now, if (self.hoveredPlace()) |i| .{ .col = 0, .row = @intCast(i) } else null);diff --git a/src/files/app_hover_tests.zig b/src/files/app_hover_tests.zigindex 2047b1a..dd3611a 100644--- a/src/files/app_hover_tests.zig+++ b/src/files/app_hover_tests.zig@@ -317,6 +317,37 @@ test "hover damage covers this repaint only" {try std.testing.expect(app.dirty and app.paint_damage == null);}+test "column surface owns list header hover and clears modal and departed targets" {+ var app = try testApp();+ defer app.deinit();+ app.loading = false;+ app.list_view = true;+ try testItems(&app, 12);++ const column = app.listColumn(1);+ const x = column.x + column.w / 2;+ const y = column.y + column.h / 2;++ app.handleMotion(x, y);+ try std.testing.expectEqual(@as(u64, 401), app.column_surface.hovered.?.id);+ try std.testing.expectEqual(@as(usize, 401), app.hoverKey());++ app.handleMotion(-1, -1);+ try std.testing.expect(app.column_surface.hovered == null);+ try std.testing.expectEqual(@as(usize, 0), app.hoverKey());++ app.handleMotion(x, y);+ try std.testing.expect(app.column_surface.hovered != null);+ app.menu = .background;+ app.updateColumnSurface();+ try std.testing.expect(app.column_surface.hovered == null);++ app.menu = null;+ app.transfer_view.active = true;+ app.updateColumnSurface();+ try std.testing.expect(app.column_surface.hovered == null);+}+test "toolbar surface owns enabled hover targets and clears disabled and departed targets" {var app = try testApp();defer app.deinit();diff --git a/src/files/app_pointer.zig b/src/files/app_pointer.zigindex 74281fc..d79acd7 100644--- a/src/files/app_pointer.zig+++ b/src/files/app_pointer.zig@@ -56,9 +56,7 @@ pub fn hoverKey(self: *App) usize {}if (self.toolbar_surface.hovered) |target| return 200 + @as(usize, @intCast(target.id));if (self.list_view and x >= @as(f64, @floatFromInt(self.sidebarWidth())) and x < @as(f64, @floatFromInt(self.w - self.scrollbarGutter()))) {- for (self.columnLabels(), 0..) |_, i| {- if (i < 4 and self.listColumn(i).contains(x, y)) return 400 + i;- }+ if (self.column_surface.hovered) |target| return @intCast(target.id);}if (self.sidebar_surface.hovered) |target| return @intCast(target.id);if (self.inlineTorrentHit(x, y)) |hit| return std.math.maxInt(usize) - 3000 - hit.index * 2 - @intFromBool(hit.toggle);@@ -135,6 +133,7 @@ pub fn handleMotion(self: *App, x: f64, y: f64) void {self.mouse_y = y;self.updateToolbarSurface();self.updateSidebarSurface();+ self.updateColumnSurface();self.damageToolbarProximity(old_x, old_y, x, y);if (self.selection_band != null) self.updateSelectionBand();if (self.text_dragging) {