RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
refactor(files): route toolbar hover through interaction surface
Petar Margetićc47fca3917f5
diff --git a/src/files/app.zig b/src/files/app.zigindex 1ad5b29..2ee45fa 100644--- a/src/files/app.zig+++ b/src/files/app.zig@@ -17,6 +17,7 @@ const theme = @import("../icon_theme.zig");const Allocator = std.mem.Allocator;const header = @import("header.zig");const hover_glide = @import("ui").hover_glide;+const interaction_surface = @import("ui").interaction_surface;const Preferences = @import("preferences.zig").Preferences;const pins_mod = @import("pins.zig");const chooser_mod = @import("chooser.zig");@@ -186,6 +187,7 @@ pub const App = struct {// between cells while visible. `stepHover` samples them once per loop and// damages only what changed; the painters draw `frame`, never the pointer.toolbar_hover: ToolbarHover = .{},+ toolbar_surface: interaction_surface.Surface = .{},nav_hover: hover_glide.Glide = .{},item_hover: hover_glide.Glide = .{},// Each path section fades independently, including when crossing a separator.@@ -441,6 +443,7 @@ pub const App = struct {pub const itemHighlight = app_hover.itemHighlight;pub const toolbarButtonVisible = app_hover.toolbarButtonVisible;pub const toolbarButtonEnabled = app_hover.toolbarButtonEnabled;+ pub const updateToolbarSurface = app_hover.updateToolbarSurface;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 431546c..382cfdb 100644--- a/src/files/app_hover.zig+++ b/src/files/app_hover.zig@@ -159,12 +159,33 @@ pub fn toolbarButtonEnabled(self: *App, action: header.Action) bool {};}+pub fn updateToolbarSurface(self: *App) void {+ const action = if (self.transfer_view.active or self.dialog != null or self.menu != null)+ null+ else+ header.hit(self.w, self.inRepository(), self.mouse_x, self.mouse_y);+ if (action) |value| {+ const r = header.rect(self.w, self.inRepository(), value);+ _ = self.toolbar_surface.pointerMotion(.{+ .id = @intCast(@intFromEnum(value)),+ .rect = .{ .x = @floatCast(r.x), .y = @floatCast(r.y), .w = @floatCast(r.w), .h = @floatCast(r.h) },+ .clip = .{ .x = 0, .y = 0, .w = @floatFromInt(self.w), .h = @floatFromInt(self.contentTop()) },+ .role = .button,+ .enabled = self.toolbarButtonVisible(value) and self.toolbarButtonEnabled(value),+ });+ } else {+ _ = self.toolbar_surface.pointerMotion(null);+ }+}+pub fn hoveredToolbarButton(self: *App) ?header.Rect {- if (self.transfer_view.active) return null;- if (self.dialog != null or self.menu != null) return null;- const action = header.hit(self.w, self.inRepository(), self.mouse_x, self.mouse_y) orelse return null;- if (!self.toolbarButtonVisible(action) or !self.toolbarButtonEnabled(action)) return null;- return header.rect(self.w, self.inRepository(), action);+ const target = self.toolbar_surface.hovered orelse return null;+ return .{+ .x = @floatCast(target.rect.x),+ .y = @floatCast(target.rect.y),+ .w = @floatCast(target.rect.w),+ .h = @floatCast(target.rect.h),+ };}/// Shared button proximity using Files' existing pointer and header geometry.@@ -254,6 +275,7 @@ pub fn stepHover(self: *App, now: i64) void {const view: header.Rect = self.clipToViewport(.{ .x = @floatFromInt(self.sidebarWidth()), .y = 0, .w = @floatFromInt(self.w - self.sidebarWidth()), .h = @floatFromInt(self.h) });self.damageHighlight(view, if (before.alpha > 0) self.itemHighlight(before) else null, if (self.item_hover.frame.alpha > 0) self.itemHighlight(self.item_hover.frame) else null);}+ self.updateToolbarSurface();if (self.toolbar_hover.step(now, self.hoveredToolbarButton(), pixel)) {self.addDamage(.{ .x = 0, .y = 0, .w = @floatFromInt(self.w), .h = @floatFromInt(self.contentTop()) });}diff --git a/src/files/app_hover_tests.zig b/src/files/app_hover_tests.zigindex 29f6b56..9bd97ed 100644--- a/src/files/app_hover_tests.zig+++ b/src/files/app_hover_tests.zig@@ -290,6 +290,25 @@ test "hover damage covers this repaint only" {try std.testing.expect(app.dirty and app.paint_damage == null);}+test "toolbar surface owns enabled hover targets and clears disabled and departed targets" {+ var app = try testApp();+ defer app.deinit();++ const cut = header.rect(app.w, false, .cut);+ try std.testing.expect(!app.toolbarButtonEnabled(.cut));+ app.handleMotion(cut.x + cut.w / 2, cut.y + cut.h / 2);+ try std.testing.expect(app.toolbar_surface.hovered == null);++ const refresh = header.rect(app.w, false, .refresh);+ app.handleMotion(refresh.x + refresh.w / 2, refresh.y + refresh.h / 2);+ try std.testing.expectEqual(@as(u64, @intFromEnum(header.Action.refresh)), app.toolbar_surface.hovered.?.id);+ try std.testing.expectEqual(refresh.x, app.hoveredToolbarButton().?.x);++ app.handleMotion(-1, -1);+ try std.testing.expect(app.toolbar_surface.hovered == null);+ try std.testing.expect(app.hoveredToolbarButton() == null);+}+test "toolbar proximity uses shared button geometry and damages in-button motion" {var app = try testApp();defer app.deinit();diff --git a/src/files/app_pointer.zig b/src/files/app_pointer.zigindex f80a7f1..34212cb 100644--- a/src/files/app_pointer.zig+++ b/src/files/app_pointer.zig@@ -54,7 +54,7 @@ pub fn hoverKey(self: *App) usize {return 500;}}- if (header.hit(self.w, self.inRepository(), x, y)) |action| return 200 + @as(usize, @intFromEnum(action));+ 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;@@ -144,6 +144,7 @@ pub fn handleMotion(self: *App, x: f64, y: f64) void {const old_hover = self.hoverKey();self.mouse_x = x;self.mouse_y = y;+ self.updateToolbarSurface();self.damageToolbarProximity(old_x, old_y, x, y);if (self.selection_band != null) self.updateSelectionBand();if (self.text_dragging) {