RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
feat: complete app button proximity glow migrations
Mel341ea3a0b9735a
diff --git a/src/editor/app.zig b/src/editor/app.zigindex 8846efb..ec1f5ca 100644--- a/src/editor/app.zig+++ b/src/editor/app.zig@@ -195,6 +195,8 @@ pub const App = struct {pub const newButtonBox = app_controls.newButtonBox;pub const menuButtonBox = app_controls.menuButtonBox;pub const hoverTarget = app_controls.hoverTarget;+ pub const buttonProximity = app_controls.buttonProximity;+ pub const proximityChanged = app_controls.proximityChanged;pub const render = app_paint.render;pub const paintLine = app_paint.paintLine;pub const paintClose = app_paint.paintClose;diff --git a/src/editor/app_controls.zig b/src/editor/app_controls.zigindex 996ce7d..b15ce41 100644--- a/src/editor/app_controls.zig+++ b/src/editor/app_controls.zig@@ -7,6 +7,88 @@ const Rect = @import("ui").context_menu.Rect;const app = @import("app.zig");const App = app.App;const SearchControl = @import("app_search.zig").Control;+const ui_theme = @import("ui").theme;++pub fn buttonProximity(self: *const App, box: Rect) button.ProximitySample {+ return button.sampleProximity(+ .{ .x = @floatCast(box.x), .y = @floatCast(box.y), .w = @floatCast(box.w), .h = @floatCast(box.h) },+ @floatCast(self.px),+ @floatCast(self.py),+ .{ .x = 0, .y = 0, .w = @floatFromInt(self.w), .h = @floatFromInt(self.h) },+ );+}++fn nearestButton(self: *const App, x: f64, y: f64) f32 {+ if (self.menu_open) return std.math.inf(f32);+ var nearest = std.math.inf(f32);+ if (self.close_tab != null) {+ if (self.operation == null) {+ const dx = (@as(f64, @floatFromInt(self.w)) - 420) / 2;+ const dy = (@as(f64, @floatFromInt(self.h)) - 170) / 2;+ for ([_]Rect{+ .{ .x = dx + 20, .y = dy + 112, .w = 115, .h = 38 },+ .{ .x = dx + 145, .y = dy + 112, .w = 125, .h = 38 },+ .{ .x = dx + 280, .y = dy + 112, .w = 120, .h = 38 },+ }) |box| {+ const sample = button.sampleProximity(+ .{ .x = @floatCast(box.x), .y = @floatCast(box.y), .w = @floatCast(box.w), .h = @floatCast(box.h) },+ @floatCast(x), @floatCast(y),+ .{ .x = 0, .y = 0, .w = @floatFromInt(self.w), .h = @floatFromInt(self.h) },+ );+ nearest = @min(nearest, sample.distance);+ }+ }+ return nearest;+ }+ for (self.first_tab..self.tabs.items.len) |i| {+ const index = i - self.first_tab;+ if (@as(f64, @floatFromInt(index + 1)) * app.tab_w > self.tabRight()) break;+ const box = self.tabCloseBox(index);+ const sample = button.sampleProximity(+ .{ .x = @floatCast(box.x), .y = @floatCast(box.y), .w = @floatCast(box.w), .h = @floatCast(box.h) },+ @floatCast(x), @floatCast(y),+ .{ .x = 0, .y = 0, .w = @floatFromInt(self.w), .h = @floatFromInt(self.h) },+ );+ nearest = @min(nearest, sample.distance);+ }+ for ([_]Rect{ self.newButtonBox() }) |box| {+ const sample = button.sampleProximity(+ .{ .x = @floatCast(box.x), .y = @floatCast(box.y), .w = @floatCast(box.w), .h = @floatCast(box.h) },+ @floatCast(x), @floatCast(y),+ .{ .x = 0, .y = 0, .w = @floatFromInt(self.w), .h = @floatFromInt(self.h) },+ );+ nearest = @min(nearest, sample.distance);+ }+ if (!self.has_titlebar) {+ const box = self.menuButtonBox();+ const sample = button.sampleProximity(+ .{ .x = @floatCast(box.x), .y = @floatCast(box.y), .w = @floatCast(box.w), .h = @floatCast(box.h) },+ @floatCast(x), @floatCast(y),+ .{ .x = 0, .y = 0, .w = @floatFromInt(self.w), .h = @floatFromInt(self.h) },+ );+ nearest = @min(nearest, sample.distance);+ }+ if (self.find_open) {+ const controls = [_]SearchControl{ .next, .toggle, .close, .replace, .replace_all };+ for (controls) |control| {+ if (!self.replace_open and (control == .replace or control == .replace_all)) continue;+ const box = self.searchBox(control);+ const sample = button.sampleProximity(+ .{ .x = @floatCast(box.x), .y = @floatCast(box.y), .w = @floatCast(box.w), .h = @floatCast(box.h) },+ @floatCast(x), @floatCast(y),+ .{ .x = 0, .y = 0, .w = @floatFromInt(self.w), .h = @floatFromInt(self.h) },+ );+ nearest = @min(nearest, sample.distance);+ }+ }+ return nearest;+}++pub fn proximityChanged(self: *const App, old_x: f64, old_y: f64, new_x: f64, new_y: f64) bool {+ const reach = ui_theme.global.border_glow_reach;+ if (!ui_theme.global.button_hover_glow_enabled or reach <= 0) return false;+ return @min(nearestButton(self, old_x, old_y), nearestButton(self, new_x, new_y)) <= reach;+}pub fn tabCloseBox(_: *const App, index: usize) Rect {return .{ .x = @as(f64, @floatFromInt(index)) * app.tab_w + app.tab_w - 36, .y = 2, .w = 34, .h = 34 };@@ -49,8 +131,13 @@ pub fn paintIcon(self: *App, cr: *c.cairo_t, box: Rect, icon: @import("ui").layovar layer = ui.Layer.begin(cr, .{ .x = @floatCast(box.x), .y = @floatCast(box.y), .w = @floatCast(box.w), .h = @floatCast(box.h) }) orelse return;defer layer.finish();layer.renderer.palette = theme.shellPalette();+ const active = !self.menu_open and self.close_tab == null;+ const proximity = if (active) self.buttonProximity(box) else .{ .distance = std.math.inf(f32), .x = 0, .y = 0 };button.paint(&layer.renderer, layer.local(), .{ .label = label, .icon = icon, .variant = .ghost, .size = .sm }, .{.selected = selected,- .pointer = if (!self.menu_open and self.close_tab == null and box.contains(self.px, self.py)) .hover else .idle,+ .pointer = if (active and box.contains(self.px, self.py)) .hover else .idle,+ .proximity_distance = proximity.distance,+ .proximity_x = proximity.x,+ .proximity_y = proximity.y,});}diff --git a/src/editor/app_input.zig b/src/editor/app_input.zigindex 2a6c9c8..5a26e3f 100644--- a/src/editor/app_input.zig+++ b/src/editor/app_input.zig@@ -22,8 +22,11 @@ pub fn indexAt(self: *App, x: f64, y: f64) usize {pub fn handleMotion(self: *App, x: f64, y: f64) void {const previous_hover = self.hoverTarget();+ const old_x = self.px;+ const old_y = self.py;self.px = x;self.py = y;+ if (self.proximityChanged(old_x, old_y, x, y)) self.dirty = true;if (self.menu_open) {const hovered = self.menuHit(x, y);if (hovered != self.menu_selected) {diff --git a/src/editor/app_paint.zig b/src/editor/app_paint.zigindex 8871022..b739768 100644--- a/src/editor/app_paint.zig+++ b/src/editor/app_paint.zig@@ -157,7 +157,14 @@ pub fn paintButton(self: *App, cr: *c.cairo_t, r: field.Rect, label: []const u8,var layer = ui.Layer.begin(cr, r) orelse return;defer layer.finish();layer.renderer.palette = theme.shellPalette();- button.paint(&layer.renderer, layer.local(), .{ .label = label, .variant = .secondary, .size = .sm }, .{ .selected = selected, .pointer = if (self.px >= r.x and self.px < r.x + r.w and self.py >= r.y and self.py < r.y + r.h) .hover else .idle });+ const proximity = self.buttonProximity(r);+ button.paint(&layer.renderer, layer.local(), .{ .label = label, .variant = .secondary, .size = .sm }, .{+ .selected = selected,+ .pointer = if (r.contains(self.px, self.py)) .hover else .idle,+ .proximity_distance = proximity.distance,+ .proximity_x = proximity.x,+ .proximity_y = proximity.y,+ });}pub fn render(self: *App, cr: *c.cairo_t) void {diff --git a/src/editor/app_search.zig b/src/editor/app_search.zigindex 8635141..04c1185 100644--- a/src/editor/app_search.zig+++ b/src/editor/app_search.zig@@ -218,6 +218,7 @@ pub fn paintSearch(self: *App, cr: *c.cairo_t) void {var layer = ui.Layer.begin(cr, .{ .x = @floatCast(box.x), .y = @floatCast(box.y), .w = @floatCast(box.w), .h = @floatCast(box.h) }) orelse continue;const disabled = (control == .next or control == .replace or control == .replace_all) and (self.query.text.items.len == 0 or (control != .next and self.document().locked));layer.renderer.palette = theme.shellPalette();+ const proximity = if (self.close_tab == null and !self.menu_open) self.buttonProximity(box) else .{ .distance = std.math.inf(f32), .x = 0, .y = 0 };button.paint(&layer.renderer, layer.local(), .{.label = switch (control) {.next => tr("Next"),@@ -234,6 +235,9 @@ pub fn paintSearch(self: *App, cr: *c.cairo_t) void {.selected = control == .toggle and self.replace_open,.focused = self.search_focus == control,.pointer = if (disabled) .disabled else if (self.close_tab == null and !self.menu_open and box.contains(self.px, self.py)) .hover else .idle,+ .proximity_distance = proximity.distance,+ .proximity_x = proximity.x,+ .proximity_y = proximity.y,});layer.finish();}diff --git a/src/share_picker/client.zig b/src/share_picker/client.zigindex 24cb972..627ddc5 100644--- a/src/share_picker/client.zig+++ b/src/share_picker/client.zig@@ -261,9 +261,61 @@ const Client = struct {}}+ fn rowRect(self: *const Client, index: usize) ui_button.Rect {+ const y = header_h + @as(i32, @intCast(index)) * row_h + 4;+ return .{+ .x = @floatFromInt(pad - 4),+ .y = @floatFromInt(y),+ .w = @floatFromInt(self.w - pad * 2 + 8),+ .h = @floatFromInt(row_h - 8),+ };+ }++ fn rowProximity(self: *const Client, index: usize, x: f64, y: f64) ui_button.ProximitySample {+ return ui_button.sampleProximity(+ self.rowRect(index),+ @floatCast(x),+ @floatCast(y - @as(f64, @floatFromInt(self.titlebarHeight()))),+ .{+ .x = 0,+ .y = @floatFromInt(header_h),+ .w = @floatFromInt(self.w),+ .h = @floatFromInt(@max(0, self.h - header_h)),+ },+ );+ }++ fn closeRect(self: *const Client) ui_button.Rect {+ const h: f64 = @floatFromInt(self.titlebarHeight());+ const w: f64 = @floatFromInt(self.w);+ const close_w = @min(h, 32);+ return .{ .x = @floatCast(w - close_w), .y = 0, .w = @floatCast(close_w), .h = @floatCast(h) };+ }++ fn proximityChanged(self: *const Client, old_x: f64, old_y: f64, x: f64, y: f64) bool {+ const reach = ui_theme.global.border_glow_reach;+ if (!ui_theme.global.button_hover_glow_enabled or reach <= 0) return false;+ var before = std.math.inf(f32);+ var after = std.math.inf(f32);+ if (self.titlebarHeight() > 0) {+ const box = self.closeRect();+ const clip: ui_button.Rect = .{ .x = 0, .y = 0, .w = @floatFromInt(self.w), .h = @floatFromInt(self.titlebarHeight()) };+ before = @min(before, ui_button.sampleProximity(box, @floatCast(old_x), @floatCast(old_y), clip).distance);+ after = @min(after, ui_button.sampleProximity(box, @floatCast(x), @floatCast(y), clip).distance);+ }+ for (self.labels, 0..) |_, index| {+ before = @min(before, self.rowProximity(index, old_x, old_y).distance);+ after = @min(after, self.rowProximity(index, x, y).distance);+ }+ return @min(before, after) <= reach;+ }+fn handleMotion(self: *Client, x: f64, y: f64) void {+ const old_x = self.pointer_x;+ const old_y = self.pointer_y;self.pointer_x = x;self.pointer_y = y;+ if (self.proximityChanged(old_x, old_y, x, y)) self.dirty = true;const content_y = y - @as(f64, @floatFromInt(self.titlebarHeight()));const row = rowAt(content_y);const next: ?usize = if (row) |r| (if (r < self.labels.len) r else null) else null;@@ -385,8 +437,15 @@ const Client = struct {drawText(cr, i18n.tr("Share screen"), 16, h_f / 2.0 + 4, 13, true);const close_w: f64 = @min(h_f, 32);const hovered = self.inside and self.pointer_y < h_f and self.pointer_x >= w_f - close_w;+ const box = self.closeRect();+ const proximity = ui_button.sampleProximity(box, @floatCast(self.pointer_x), @floatCast(self.pointer_y), .{ .x = 0, .y = 0, .w = @floatFromInt(w), .h = @floatFromInt(h) });var layer = shell_ui.Layer.begin(cr, .{ .x = @floatCast(w_f - close_w), .y = 0, .w = @floatCast(close_w), .h = @floatCast(h_f) }) orelse return;- ui_button.paint(&layer.renderer, layer.local(), .{ .variant = .chrome, .icon = .close, .label = i18n.tr("Close") }, .{ .pointer = if (hovered) .hover else .idle });+ ui_button.paint(&layer.renderer, layer.local(), .{ .variant = .chrome, .icon = .close, .label = i18n.tr("Close") }, .{+ .pointer = if (hovered) .hover else .idle,+ .proximity_distance = proximity.distance,+ .proximity_x = proximity.x,+ .proximity_y = proximity.y,+ });layer.finish();}@@ -410,15 +469,22 @@ const Client = struct {}for (self.labels, 0..) |label, i| {- const y: f64 = @floatFromInt(header_h + @as(i32, @intCast(i)) * row_h);- if (self.hover == i or self.selected == i) {- // The shared selected-item tint (a toggled-on button's).- setSource(cr, .{ t.accent[0], t.accent[1], t.accent[2], t.accent[3] * 0.22 });- roundedRect(cr, pad - 4, y + 4, w_f - @as(f64, @floatFromInt(pad * 2)) + 8, @as(f64, @floatFromInt(row_h)) - 8, t.radius);- c.cairo_fill(cr);- }- setSource(cr, t.fg);- drawText(cr, label, pad, y + 28, 13, false);+ const row = self.rowRect(i);+ const proximity = self.rowProximity(i, self.pointer_x, self.pointer_y);+ var layer = shell_ui.Layer.begin(cr, row) orelse continue;+ ui_button.paint(&layer.renderer, layer.local(), .{+ .variant = .secondary,+ .size = .md,+ .alignment = .left,+ .label = label,+ }, .{+ .selected = self.hover == i or self.selected == i,+ .pointer = if (self.inside and self.hover == i) .hover else .idle,+ .proximity_distance = proximity.distance,+ .proximity_x = proximity.x,+ .proximity_y = proximity.y,+ });+ layer.finish();}}};@@ -431,15 +497,6 @@ fn setSource(cr: *c.cairo_t, color: [4]f32) void {c.cairo_set_source_rgba(cr, color[0], color[1], color[2], color[3]);}-fn roundedRect(cr: *c.cairo_t, x: f64, y: f64, w: f64, h: f64, r: f64) void {- c.cairo_new_sub_path(cr);- c.cairo_arc(cr, x + w - r, y + r, r, -std.math.pi / 2.0, 0);- c.cairo_arc(cr, x + w - r, y + h - r, r, 0, std.math.pi / 2.0);- c.cairo_arc(cr, x + r, y + h - r, r, std.math.pi / 2.0, std.math.pi);- c.cairo_arc(cr, x + r, y + r, r, std.math.pi, std.math.pi * 1.5);- c.cairo_close_path(cr);-}-const Buffer = struct {client: *Client,wl_buffer: *wl.Buffer,