RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
feat: add proximity glow to Files toolbar
Petar Margetić7465b282f6d2
diff --git a/src/files/app.zig b/src/files/app.zigindex f71aba1..1ad5b29 100644--- a/src/files/app.zig+++ b/src/files/app.zig@@ -442,6 +442,8 @@ pub const App = struct {pub const toolbarButtonVisible = app_hover.toolbarButtonVisible;pub const toolbarButtonEnabled = app_hover.toolbarButtonEnabled;pub const hoveredToolbarButton = app_hover.hoveredToolbarButton;+ pub const toolbarButtonProximity = app_hover.toolbarButtonProximity;+ pub const damageToolbarProximity = app_hover.damageToolbarProximity;pub const stepHover = app_hover.stepHover;pub const damageHighlight = app_hover.damageHighlight;pub const unionRect = app_hover.unionRect;diff --git a/src/files/app_hover.zig b/src/files/app_hover.zigindex 318c74d..431546c 100644--- a/src/files/app_hover.zig+++ b/src/files/app_hover.zig@@ -5,6 +5,8 @@ const App = @import("app.zig").App;const anim = @import("ui").anim;const header = @import("header.zig");const hover_glide = @import("ui").hover_glide;+const button_widget = @import("ui").widgets.button;+const ui_theme = @import("ui").theme;const pins_mod = @import("pins.zig");const HoverLayout = App.HoverLayout;const column_labels = App.column_labels;@@ -165,6 +167,61 @@ pub fn hoveredToolbarButton(self: *App) ?header.Rect {return header.rect(self.w, self.inRepository(), action);}+/// Shared button proximity using Files' existing pointer and header geometry.+pub fn toolbarButtonProximity(+ self: *App,+ action: header.Action,+ x: f64,+ y: f64,+) button_widget.ProximitySample {+ const absent = button_widget.ProximitySample{+ .distance = std.math.inf(f32),+ .x = 0,+ .y = 0,+ };+ if (self.transfer_view.active or self.dialog != null or self.menu != null or+ !self.toolbarButtonVisible(action) or !self.toolbarButtonEnabled(action))+ return absent;++ const r = header.rect(self.w, self.inRepository(), action);+ return button_widget.sampleProximity(+ .{+ .x = @floatCast(r.x),+ .y = @floatCast(r.y),+ .w = @floatCast(r.w),+ .h = @floatCast(r.h),+ },+ @floatCast(x),+ @floatCast(y),+ .{+ .x = 0,+ .y = 0,+ .w = @floatFromInt(self.w),+ .h = @floatFromInt(self.contentTop()),+ },+ );+}++/// Repaint only toolbar buttons whose proximity appearance may have changed.+pub fn damageToolbarProximity(self: *App, old_x: f64, old_y: f64, new_x: f64, new_y: f64) void {+ const reach = ui_theme.global.border_glow_reach;+ if (reach <= 0) return;+ if (!ui_theme.global.button_hover_glow_enabled and ui_theme.global.button_relief == .flat) return;++ var damage: ?header.Rect = null;+ for (std.meta.tags(header.Action)) |action| {+ if (!self.toolbarButtonVisible(action) or !self.toolbarButtonEnabled(action)) continue;++ const before = self.toolbarButtonProximity(action, old_x, old_y);+ const after = self.toolbarButtonProximity(action, new_x, new_y);+ if (@min(before.distance, after.distance) > reach) continue;++ const rect = header.rect(self.w, self.inRepository(), action);+ damage = if (damage) |current| unionRect(current, rect) else rect;+ }+ if (damage) |rect| self.addDamage(rect);+}+/// Samples the hover highlights and queues damage for what moved or/// faded. Once per loop, before painting: the painters draw the sampled/// `frame`, so a partial repaint and a complete one agree.diff --git a/src/files/app_hover_tests.zig b/src/files/app_hover_tests.zigindex 87b0373..29f6b56 100644--- a/src/files/app_hover_tests.zig+++ b/src/files/app_hover_tests.zig@@ -289,3 +289,27 @@ test "hover damage covers this repaint only" {app.addDamage(.{ .x = 10, .y = 10, .w = 5, .h = 5 });try std.testing.expect(app.dirty and app.paint_damage == null);}++test "toolbar proximity uses shared button geometry and damages in-button motion" {+ var app = try testApp();+ defer app.deinit();++ const rect = header.rect(app.w, false, .refresh);+ const x = rect.x + rect.w / 2;+ const y = rect.y + rect.h / 2;++ app.handleMotion(x, y);+ const sample = app.toolbarButtonProximity(.refresh, x, y);+ try std.testing.expectEqual(@as(f32, 0), sample.distance);+ try std.testing.expectEqual(@as(f32, @floatCast(rect.w / 2)), sample.x);+ try std.testing.expectEqual(@as(f32, @floatCast(rect.h / 2)), sample.y);++ // Moving within the same button does not change hoverKey. Proximity+ // still changes and must queue damage for the button.+ app.dirty = false;+ app.paint_damage = null;+ app.handleMotion(x + 1, y);+ try std.testing.expect(app.dirty);+ try std.testing.expect(app.paint_damage != null);+ try std.testing.expect(app.paint_damage.?.contains(x, y));+}diff --git a/src/files/app_paint.zig b/src/files/app_paint.zigindex 2958040..7b51426 100644--- a/src/files/app_paint.zig+++ b/src/files/app_paint.zig@@ -65,7 +65,21 @@ pub fn renderHeader(self: *App, cr: *c.cairo_t) void {else => .{ .variant = .ghost, .icon = header.glyph(action), .icon_scale = 0.56, .label = @tagName(action) },};var layer = shell_ui.Layer.begin(cr, .{ .x = @floatCast(r.x), .y = @floatCast(r.y), .w = @floatCast(r.w), .h = @floatCast(r.h) }) orelse continue;- const state: ui_button.State = .{ .pointer = if (enabled) .idle else .disabled, .selected = active };+ const proximity = self.toolbarButtonProximity(action, self.mouse_x, self.mouse_y);+ const reach = ui_theme.global.border_glow_reach;+ const elevation = if (enabled and reach > 0 and proximity.distance < std.math.inf(f32))+ std.math.clamp(1 - proximity.distance / reach, 0, 1)+ else+ 0;+ const state: ui_button.State = .{+ .pointer = if (enabled) .idle else .disabled,+ .selected = active,+ // Glow is painted separately above the sliding chip.+ .proximity_distance = std.math.inf(f32),+ .proximity_x = proximity.x,+ .proximity_y = proximity.y,+ .hover_elevation = elevation,+ };if (content) ui_button.paintContent(&layer.renderer, layer.local(), opts, state) else ui_button.paintBackground(&layer.renderer, layer.local(), opts, state);layer.finish();}@@ -77,14 +91,37 @@ pub fn renderHeader(self: *App, cr: *c.cairo_t) void {pub fn renderToolbarHover(self: *App, cr: *c.cairo_t) void {const hover = self.toolbar_hover;- if (hover.opacity <= 0) return;- const r = hover.frame;- if (shell_ui.Layer.begin(cr, .{ .x = r[0], .y = r[1], .w = r[2], .h = r[3] })) |value| {- var layer = value;- var palette = layer.renderer.palette.?;- palette.surface_hover[3] *= hover.opacity;- layer.renderer.palette = palette;- ui_button.paintBackground(&layer.renderer, layer.local(), .{ .variant = .ghost }, .{ .pointer = .hover });+ if (hover.opacity > 0) {+ const r = hover.frame;+ if (shell_ui.Layer.begin(cr, .{ .x = r[0], .y = r[1], .w = r[2], .h = r[3] })) |value| {+ var layer = value;+ var palette = layer.renderer.palette.?;+ palette.surface_hover[3] *= hover.opacity;+ layer.renderer.palette = palette;+ ui_button.paintBackground(&layer.renderer, layer.local(), .{ .variant = .ghost }, .{ .pointer = .hover });+ layer.finish();+ }+ }++ // The glow sits above the sliding chip but below the button ink.+ if (!ui_theme.global.button_hover_glow_enabled) return;+ for (std.meta.tags(header.Action)) |action| {+ if (!self.toolbarButtonVisible(action) or !self.toolbarButtonEnabled(action)) continue;+ const r = header.rect(self.w, self.inRepository(), action);+ const sample = self.toolbarButtonProximity(action, self.mouse_x, self.mouse_y);+ if (sample.distance >= std.math.inf(f32)) continue;++ var layer = shell_ui.Layer.begin(cr, .{+ .x = @floatCast(r.x),+ .y = @floatCast(r.y),+ .w = @floatCast(r.w),+ .h = @floatCast(r.h),+ }) orelse continue;+ ui_button.paintBackground(&layer.renderer, layer.local(), .{ .variant = .ghost }, .{+ .proximity_distance = sample.distance,+ .proximity_x = sample.x,+ .proximity_y = sample.y,+ });layer.finish();}}diff --git a/src/files/app_pointer.zig b/src/files/app_pointer.zigindex 5069f2a..f80a7f1 100644--- a/src/files/app_pointer.zig+++ b/src/files/app_pointer.zig@@ -139,9 +139,12 @@ pub fn handleMotion(self: *App, x: f64, y: f64) void {self.last_click_index = null;}}+ const old_x = self.mouse_x;+ const old_y = self.mouse_y;const old_hover = self.hoverKey();self.mouse_x = x;self.mouse_y = y;+ self.damageToolbarProximity(old_x, old_y, x, y);if (self.selection_band != null) self.updateSelectionBand();if (self.text_dragging) {self.placeCaret(x, true);