RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Merge pull request #16: feat: add shared UI interaction surfaces and proximity glow
oxydizer0066b06e9170
diff --cc src/files/app_pointer.zigindex 18289e5,a2845b6..0e82566--- a/src/files/app_pointer.zig+++ b/src/files/app_pointer.zig@@@ -24,22 -24,9 +24,10 @@@ pub fn hoverKey(self: *App) usizeconst y = self.mouse_y;if (self.dialog) |dlg| {if (dlg.kind == .properties) return dlg.properties.?.hit(self.w, self.h, x, y);+ if (dlg.kind == .trash_properties) return @intFromEnum(dlg.trash_properties.?.hit(self.w, self.h, x, y));if (dlg.kind == .open_with) return dlg.applications.?.hit(self.w, self.h, x, y);if (dlg.kind == .trash_confirm) return @intFromEnum(dlg.deletion.geometry(self.w, self.h).target(x, y));- const dw: f64 = @min(440, @as(f64, @floatFromInt(self.w)) - 24);- const dx = (@as(f64, @floatFromInt(self.w)) - dw) / 2;- const dy = (@as(f64, @floatFromInt(self.h)) - 130) / 2;- if (y < dy + 84 or y > dy + 112) return 0;- if (dlg.kind == .conflict) {- for (0..3) |i| {- const left = dx + 16 + @as(f64, @floatFromInt(i)) * ((dw - 48) / 3 + 8);- if (x >= left and x <= left + (dw - 48) / 3) return i + 1;- }- } else {- if (x >= dx + dw - 184 and x <= dx + dw - 104) return 1;- if (x >= dx + dw - 96 and x <= dx + dw - 16) return 2;- }+ if (self.dialog_surface.hovered) |target| return @intCast(target.id);return 0;}if (self.menu != null) return 100 + (self.menuHit(x, y) orelse 99);diff --cc src/files/properties_card.zigindex 1381f1f,0000000..1f96d0emode 100644,000000..100644--- a/src/files/properties_card.zig+++ b/src/files/properties_card.zig@@@ -1,63 -1,0 +1,63 @@@+//! The body shared by every Properties window: an identity row (preview tile,+//! name, kind, Open) and the label/value fields under it. File Properties+//! (`properties.zig`) and the Trash's (`trash_properties.zig`, also shown by the+//! desktop) both draw with these, so the two cannot drift apart.+//!+//! `s` is how far the content is scrolled, less the title bar's extra height:+//! a row at `y` is drawn at `y - s`. The renderer's palette is the body's+//! (`fg` for text, `accent` for Open); call these with it set.+const std = @import("std");+const ui = @import("ui");+const theme = ui.theme;+const button = ui.widgets.button;+const Renderer = ui.paint.Renderer;+const Rect = ui.cairo.Rect;++pub const fields_y: f32 = 157;+pub const field_step: f32 = 26;++pub fn openBox(width: f32, s: f32) Rect {+ return .{ .x = width - 48, .y = 67 - s, .w = 28, .h = 28 };+}++/// Where the content ends once it holds `count` fields.+pub fn fieldsBottom(count: usize) f32 {+ return fields_y + @as(f32, @floatFromInt(count)) * field_step;+}++pub const Identity = struct {+ /// Raster of the thing described, drawn 44 px wide in its tile.+ image: ?ui.paint.Image = null,+ /// Vector glyph for when there is no raster.+ glyph: ui.layout.IconId,+ name: []const u8,+ kind: []const u8,+};++pub fn paintIdentity(r: *Renderer, width: f32, s: f32, id: Identity) void {+ const t = r.palette orelse theme.global;+ r.fillRect(24, 66 - s, 64, 64, .{ .color = theme.global.app_toolbar, .radius = 9, .border_width = 1, .border_color = theme.global.app_item_border });+ if (id.image) |im| r.drawImageCover(34, 76 - s, 44, 44, 0, im) else r.drawIcon(34, 76 - s, 44, 44, .{ .id = id.glyph, .color = t.fg });+ r.drawText(108, 68 - s, width - 162, 26, .{ .content = id.name, .font_size = t.font_size, .weight = 600, .color = t.fg });+ r.drawText(108, 99 - s, width - 132, 24, .{ .content = id.kind, .font_size = t.font_size, .color = t.fg });+}++pub fn paintOpen(r: *Renderer, width: f32, s: f32, label: []const u8, focused: bool, hovered: bool) void {+ const body = r.palette orelse theme.global;+ var accent = body;+ accent.fg = body.accent;+ r.palette = accent;- button.paint(r, openBox(width, s), .{ .icon = .open, .variant = .ghost, .label = label }, .{ .focused = focused, .pointer = if (hovered) .hover else .idle });++ button.paint(r, openBox(width, s), .{ .icon = .open, .variant = .secondary, .label = label }, .{ .focused = focused, .pointer = if (hovered) .hover else .idle });+ r.palette = body;+}++/// The rule under the identity row, then one label and value per line.+pub fn paintFields(r: *Renderer, width: f32, s: f32, labels: []const []const u8, values: []const []const u8) void {+ const t = r.palette orelse theme.global;+ r.fillRect(24, 146 - s, width - 48, 1, .{ .color = theme.global.app_divider });+ for (labels, values, 0..) |label, value, i| {+ const y = fields_y + @as(f32, @floatFromInt(i)) * field_step - s;+ r.drawText(24, y, 120, 24, .{ .content = label, .font_size = t.font_size, .color = t.fg });+ r.drawText(162, y, width - 186, 24, .{ .content = value, .font_size = t.font_size, .color = t.fg });+ }+}