diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 23:19:57 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:40:08 -0300 |
| commit | 27d8941a177a4ec2c3b0990d4b81f529b93c6f0a (patch) | |
| tree | 218061ef9cb9b7cc7a69c450c47f111f6aa11321 /src/gui | |
| parent | 684dd340da01a60525d45e5a4f4c64f9fb79be1d (diff) | |
| download | pardes-27d8941a177a4ec2c3b0990d4b81f529b93c6f0a.tar.gz pardes-27d8941a177a4ec2c3b0990d4b81f529b93c6f0a.zip | |
gui: the touch debug overlay goes (circles, trails, hex labels in their own 3x5 font, the click flash, and the ink runs the labels drew in), the two-finger scroll and tap stay; the overlay draws the pet and the cursor's glide in one call, and renderFrame no longer takes the Debug flag only that overlay read
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/gui')
| -rw-r--r-- | src/gui/gui.zig | 259 |
1 files changed, 14 insertions, 245 deletions
diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 96c7254e..880e41ee 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -251,10 +251,6 @@ const LoadedFallback = struct { }; const max_touch_points: usize = 16; -const max_touch_trail_points: usize = 8; -const overlay_circle_vertices: usize = 16 * 3; -const touch_click_flash_max_frames: u8 = 14; -const touch_click_flash_vertices: usize = 1400; const touch_scroll_tick: f32 = 0.02; test "a new panel's frame zero is presented before it advances" { @@ -289,9 +285,9 @@ test "a new panel's frame zero is presented before it advances" { for (second.panelTracks()) |track| try std.testing.expectEqual(@as(u16, 1), track.frame); } -// The triangle overlay holds only the pet and the touch view: the chrome is -// decor. -const max_overlay_vertices: usize = pet.max_vertices + touch_click_flash_vertices + max_touch_points * (1100 + max_touch_trail_points * overlay_circle_vertices); +// The triangle overlay holds only the pet and the cursor's glide quad: the +// chrome is decor. +const max_overlay_vertices: usize = pet.max_vertices + 6; const font_px_step: f32 = 2.0; const font_px_min: f32 = 8.0; @@ -512,8 +508,6 @@ const OverlayVertex = extern struct { g: f32, b: f32, a: f32, - // CPU draw grouping metadata; not a shader attribute. - ink: u32 = 0, }; const OverlayColor = struct { r: f32, g: f32, b: f32, a: f32 }; @@ -698,22 +692,16 @@ fn resizeOf(core: anytype, cols: u16, rows: u16, cell_w: u32, cell_h: u32, tag_w return .{ .resize = .{ .cols = cols, .rows = rows, .row_metrics = metrics } }; } -const TouchSample = struct { x: f32 = 0, y: f32 = 0, pressure: f32 = 1 }; - const TouchPoint = struct { active: bool = false, id: u64 = 0, x: f32 = 0, y: f32 = 0, - pressure: f32 = 1, - trail: [max_touch_trail_points]TouchSample = @splat(.{}), - trail_len: usize = 0, - trail_next: usize = 0, }; const TouchNormPoint = struct { x: f32 = 0, y: f32 = 0 }; -const Finger = struct { kind: enum { down, motion, up, cancel }, id: u64, x: f32, y: f32, pressure: f32 }; +const Finger = struct { kind: enum { down, motion, up, cancel }, id: u64, x: f32, y: f32 }; const Touch = struct { points: [max_touch_points]TouchPoint = @splat(.{}), @@ -724,9 +712,6 @@ const Touch = struct { scrolled: bool = false, last_center: TouchNormPoint = .{}, } = .{}, - click_count: u32 = 0, - click_button: pardes.Mouse.Button = .middle, - click_flash_frames: u8 = 0, fn findSlot(t: *const Touch, id: u64) ?usize { for (&t.points, 0..) |*tp, i| if (tp.active and tp.id == id) return i; @@ -747,10 +732,6 @@ const Touch = struct { if (!tp.active or tp.id != f.id) tp.* = .{ .active = true, .id = f.id }; tp.x = f.x; tp.y = f.y; - tp.pressure = f.pressure; - tp.trail[tp.trail_next] = .{ .x = f.x, .y = f.y, .pressure = f.pressure }; - tp.trail_next = (tp.trail_next + 1) % max_touch_trail_points; - if (tp.trail_len < max_touch_trail_points) tp.trail_len += 1; }, } } @@ -851,7 +832,7 @@ fn handlePairFinger(t: *Touch, in: *Input, f: Finger, win_w: f32, win_h: f32, ce const tap_center = t.finishPair(f); t.updatePoint(f); t.syncPair(); - if (tap_center) |center| emitTouchClick(t, in, center, .middle, win_w, win_h, cell_w, cell_h, tagline_w); + if (tap_center) |center| emitTouchClick(in, center, .middle, win_w, win_h, cell_w, cell_h, tagline_w); }, } } @@ -865,10 +846,7 @@ fn emitTouchScroll(in: *Input, center: TouchNormPoint, ticks: i32, delta_y: f32, in.post(.{ .touch_scroll = delta_y }); } -fn emitTouchClick(t: *Touch, in: *Input, point: TouchNormPoint, button: pardes.Mouse.Button, win_w: f32, win_h: f32, cell_w: f32, cell_h: f32, tagline_w: f32) void { - t.click_count +%= 1; - t.click_button = button; - t.click_flash_frames = touch_click_flash_max_frames; +fn emitTouchClick(in: *Input, point: TouchNormPoint, button: pardes.Mouse.Button, win_w: f32, win_h: f32, cell_w: f32, cell_h: f32, tagline_w: f32) void { const cell = gridCellAtDimensions(in.core, point.x * win_w, point.y * win_h, cell_w, cell_h, tagline_w); in.post(.{ .mouse = .{ .button = button, .kind = .press, .col = cell.col, .row = cell.row, .tag_hit = cell.tag_hit, .body_hit = cell.body_hit } }); in.post(.{ .mouse = .{ .button = button, .kind = .release, .col = cell.col, .row = cell.row, .tag_hit = cell.tag_hit, .body_hit = cell.body_hit } }); @@ -1770,7 +1748,7 @@ const Group = struct { /// standing still), a group for each track in paint order (tier 2 moving and /// opening, tier 3 closing), tier 4 (floating: the notices, then the guides /// and the debug box, which the core paints over them) and tier 5 (ink: the -/// bar cursors; the pet and the touch overlay draw after it). Tier 1 is the +/// bar cursors; the pet and the cursor's glide draw after it). Tier 1 is the /// focus lift, which does not exist yet. const Groups = struct { items: [pardes.MAX_PANES * 2 + 4]Group = @splat(.{}), @@ -3106,6 +3084,7 @@ fn parseFinger(payload: []const u8) ?Finger { const y_s = parts.next() orelse return null; const pressure_s = parts.next() orelse return null; if (parts.next() != null) return null; + _ = std.fmt.parseFloat(f32, pressure_s) catch return null; const kind: @FieldType(Finger, "kind") = if (std.mem.eql(u8, type_name, "SDL_EVENT_FINGER_DOWN") or std.mem.eql(u8, type_name, "down")) .down else if (std.mem.eql(u8, type_name, "SDL_EVENT_FINGER_MOTION") or std.mem.eql(u8, type_name, "motion")) @@ -3121,7 +3100,6 @@ fn parseFinger(payload: []const u8) ?Finger { .id = std.fmt.parseInt(u64, id_s, 10) catch return null, .x = std.fmt.parseFloat(f32, x_s) catch return null, .y = std.fmt.parseFloat(f32, y_s) catch return null, - .pressure = std.fmt.parseFloat(f32, pressure_s) catch return null, }; } @@ -3428,7 +3406,6 @@ fn dispatch(g: *Gui, in: *Input, sev: *const c.SDL_Event) void { .id = @intCast(f.fingerID), .x = f.x, .y = f.y, - .pressure = f.pressure, }; var pw: c_int = 0; var ph: c_int = 0; @@ -4745,7 +4722,7 @@ fn pollFrame(ctx: ?*anyopaque) void { if (g.blink_due and !core.needs_frame and s.presented) if (s.surface) |frame| { g.blink_due = false; blink_redraws += 1; - s.presented = renderFrame(g, s.gpa, core, frame, core.settings.debug) catch false; + s.presented = renderFrame(g, s.gpa, core, frame) catch false; }; } @@ -4925,13 +4902,7 @@ fn present(ctx: ?*anyopaque, surface: *const pardes.Surface) void { g.frame_arrival_ns = monoNs(); const scene_requested = g.post.ready(); if (!scene_requested) g.scene_failures = 0; - s.presented = renderFrame( - g, - s.gpa, - core, - frame, - core.settings.debug, - ) catch |err| blk: { + s.presented = renderFrame(g, s.gpa, core, frame) catch |err| blk: { log.err("render: {t}", .{err}); break :blk false; }; @@ -6499,7 +6470,6 @@ fn renderFrame( gpa: std.mem.Allocator, core: ?*pardes.Pardes, surface: *const pardes.Surface, - debug_on: bool, ) !bool { if (surface.pointer_shape != g.pointer_shape) { g.pointer_shape = surface.pointer_shape; @@ -6599,7 +6569,7 @@ fn renderFrame( probe.caret = caretRow(g, surface) orelse 0; } const cursors_shown = groups.tracks == 0 and !quad_mode; - var overlay_count = buildOverlay(g, core, surface, sw, sh, debug_on); + var overlay_count = buildOverlay(g, core, surface, sw, sh); if (overlay_count != 0 and !uploadOverlayGpu(g, cmd, overlay_count)) overlay_count = 0; if (!prepareNativeImages(g, gpa, cmd, surface, &groups, sw, sh)) { @@ -10846,7 +10816,7 @@ fn cursorDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, if (box.bar) try addDecor(g, gpa, box.x0, box.y0, box.x1, box.y1, box.rgb, 1, null, win_w, win_h); } -/// The triangle overlay: the workspace pet and the touch debug view, over +/// The triangle overlay: the workspace pet and the cursor's glide, over /// everything. fn buildOverlay( g: *Gui, @@ -10854,13 +10824,11 @@ fn buildOverlay( surface: *const pardes.Surface, sw: u32, sh: u32, - debug_on: bool, ) u32 { if (g.overlay_vertices.len == 0 or sw == 0 or sh == 0) return 0; var builder = OverlayBuilder{ .vertices = g.overlay_vertices, .win_w = @floatFromInt(sw), .win_h = @floatFromInt(sh) }; appendWorkspacePet(g, core, surface, &builder); appendCursorGlide(g, surface, &builder); - appendTouchOverlay(g, &builder, debug_on); return @intCast(builder.len); } @@ -10994,57 +10962,6 @@ fn overlayRgb(rgb: [3]u8) OverlayColor { }; } -fn appendTouchOverlay(g: *Gui, builder: *OverlayBuilder, debug_on: bool) void { - if (!debug_on) { - g.touch.click_flash_frames = 0; - return; - } - const t = &g.touch; - - if (t.click_flash_frames != 0) { - const flash = @as(f32, @floatFromInt(t.click_flash_frames)) / @as(f32, @floatFromInt(touch_click_flash_max_frames)); - const label = touchClickLabel(t.click_count, t.click_button); - const glyph_scale = 3.0; - const char_step = 4.0 * glyph_scale; - const pad = 5.0; - const stripe_w = 4.0; - const label_w = pad * 2.0 + stripe_w + 3.0 + @as(f32, @floatFromInt(label.len)) * char_step - glyph_scale; - const label_h = pad * 2.0 + 5.0 * glyph_scale; - builder.addRect(0.0, 0.0, builder.win_w, builder.win_h, .{ .r = 1.0, .g = 0.78, .b = 0.18, .a = 0.055 * flash }); - builder.addRect(8.0, 8.0, 8.0 + label_w, 8.0 + label_h, .{ .r = 0.0, .g = 0.0, .b = 0.0, .a = 0.54 + 0.22 * flash }); - builder.addRect(8.0 + pad, 8.0 + pad, 8.0 + pad + stripe_w, 8.0 + label_h - pad, .{ .r = 1.0, .g = 0.78, .b = 0.18, .a = 0.96 }); - builder.addMiniText(label[0..], 8.0 + pad + stripe_w + 3.0, 8.0 + pad, glyph_scale, .{ .r = 1.0, .g = 1.0, .b = 1.0, .a = 0.96 }); - t.click_flash_frames -= 1; - } - - for (&t.points) |*tp| { - if (!tp.active) continue; - const cx = std.math.clamp(tp.x, 0.0, 1.0) * builder.win_w; - const cy = std.math.clamp(tp.y, 0.0, 1.0) * builder.win_h; - const radius = (12.0 + std.math.clamp(tp.pressure, 0.0, 1.0) * 4.0) * 4.0; - const color = touchColor(tp.id); - - if (tp.trail_len > 1) { - const first = if (tp.trail_len == max_touch_trail_points) tp.trail_next else 0; - for (0..tp.trail_len - 1) |trail_i| { - const sample = tp.trail[(first + trail_i) % max_touch_trail_points]; - const fade = @as(f32, @floatFromInt(trail_i + 1)) / @as(f32, @floatFromInt(tp.trail_len)); - var trail_color = color; - trail_color.a *= 0.42 * fade; - const tx = std.math.clamp(sample.x, 0.0, 1.0) * builder.win_w; - const ty = std.math.clamp(sample.y, 0.0, 1.0) * builder.win_h; - const trail_radius = (12.0 + std.math.clamp(sample.pressure, 0.0, 1.0) * 4.0) * 2.8; - builder.addCircle(tx, ty, trail_radius, trail_color); - } - } - - builder.addCircle(cx, cy, radius + 4.0, .{ .r = 0.0, .g = 0.0, .b = 0.0, .a = 0.62 }); - builder.addCircle(cx, cy, radius, color); - builder.addCircle(cx, cy, 2.4, .{ .r = 1.0, .g = 1.0, .b = 1.0, .a = 0.92 }); - builder.addIdTag(tp.id, cx, cy, color); - } -} - fn uploadOverlayGpu(g: *Gui, cmd: *c.SDL_GPUCommandBuffer, vertex_count: u32) bool { const byte_len: u32 = vertex_count * @sizeOf(OverlayVertex); const ptr = c.SDL_MapGPUTransferBuffer(g.device, g.overlay_vxfer, false) orelse return false; @@ -11076,29 +10993,8 @@ fn drawOverlayGpu(g: *Gui, cmd: *c.SDL_GPUCommandBuffer, rp: ?*c.SDL_GPURenderPa c.SDL_BindGPUGraphicsPipeline(pass, g.overlay_pipeline); const binding = c.SDL_GPUBufferBinding{ .buffer = g.overlay_vbuf, .offset = 0 }; c.SDL_BindGPUVertexBuffers(pass, 0, &binding, 1); - var first: u32 = 0; - while (first < vertex_count) { - const ink = g.overlay_vertices[first].ink; - var end = first + 1; - while (end < vertex_count and g.overlay_vertices[end].ink == ink) : (end += 1) {} - pushLayerOpacity(cmd, pass, if (ink != 0) 1 else backgroundOpacity(g.applied_window_opacity)); - c.SDL_DrawGPUPrimitives(pass, end - first, 1, first, 0); - first = end; - } -} - -fn touchColor(id: u64) OverlayColor { - const palette = [_]OverlayColor{ - .{ .r = 0.10, .g = 0.72, .b = 1.00, .a = 0.88 }, - .{ .r = 1.00, .g = 0.32, .b = 0.50, .a = 0.88 }, - .{ .r = 0.35, .g = 0.90, .b = 0.38, .a = 0.88 }, - .{ .r = 1.00, .g = 0.78, .b = 0.18, .a = 0.88 }, - .{ .r = 0.78, .g = 0.52, .b = 1.00, .a = 0.88 }, - .{ .r = 0.10, .g = 0.88, .b = 0.75, .a = 0.88 }, - .{ .r = 1.00, .g = 0.48, .b = 0.18, .a = 0.88 }, - .{ .r = 0.78, .g = 0.90, .b = 1.00, .a = 0.88 }, - }; - return palette[@intCast(id % palette.len)]; + pushLayerOpacity(cmd, pass, backgroundOpacity(g.applied_window_opacity)); + c.SDL_DrawGPUPrimitives(pass, vertex_count, 1, 0, 0); } const OverlayBuilder = struct { @@ -11106,7 +11002,6 @@ const OverlayBuilder = struct { len: usize = 0, win_w: f32, win_h: f32, - ink: bool = false, fn addVertex(b: *OverlayBuilder, px: f32, py: f32, color: OverlayColor) void { if (b.len >= b.vertices.len) return; @@ -11117,7 +11012,6 @@ const OverlayBuilder = struct { .g = color.g, .b = color.b, .a = color.a, - .ink = @intFromBool(b.ink), }; b.len += 1; } @@ -11140,133 +11034,8 @@ const OverlayBuilder = struct { b.addTri(x0, y0, x1, y1, x0, y1, color); } - fn addCircle(b: *OverlayBuilder, cx: f32, cy: f32, radius: f32, color: OverlayColor) void { - var i: usize = 0; - while (i + 1 < circle_points.len) : (i += 1) { - const p0 = circle_points[i]; - const p1 = circle_points[i + 1]; - b.addTri(cx, cy, cx + p0[0] * radius, cy + p0[1] * radius, cx + p1[0] * radius, cy + p1[1] * radius, color); - } - } - - fn addIdTag(b: *OverlayBuilder, id: u64, cx: f32, cy: f32, color: OverlayColor) void { - const label = touchIdLabel(id); - const glyph_scale = 2.0; - const char_step = 4.0 * glyph_scale; - const pad = 4.0; - const stripe_w = 3.0; - const label_w = pad * 2.0 + stripe_w + 3.0 + @as(f32, @floatFromInt(label.len)) * char_step - glyph_scale; - const label_h = pad * 2.0 + 5.0 * glyph_scale; - - var x = cx + 20.0; - if (x + label_w > b.win_w - 2.0) x = cx - label_w - 20.0; - x = std.math.clamp(x, 2.0, @max(2.0, b.win_w - label_w - 2.0)); - var y = cy - label_h - 10.0; - if (y < 2.0) y = cy + 20.0; - y = std.math.clamp(y, 2.0, @max(2.0, b.win_h - label_h - 2.0)); - - b.addRect(x, y, x + label_w, y + label_h, .{ .r = 0.0, .g = 0.0, .b = 0.0, .a = 0.72 }); - b.addRect(x + pad, y + pad, x + pad + stripe_w, y + label_h - pad, color); - b.addMiniText(label[0..], x + pad + stripe_w + 3.0, y + pad, glyph_scale, .{ .r = 1.0, .g = 1.0, .b = 1.0, .a = 0.95 }); - } - - fn addMiniText(b: *OverlayBuilder, text: []const u8, x: f32, y: f32, scale: f32, color: OverlayColor) void { - const previous_ink = b.ink; - b.ink = true; - defer b.ink = previous_ink; - var cx = x; - for (text) |ch| { - const rows = miniGlyph(ch); - const masks = [_]u8{ 0b100, 0b010, 0b001 }; - for (rows, 0..) |bits, row| { - for (masks, 0..) |mask, colidx| { - if ((bits & mask) == 0) continue; - const x0 = cx + @as(f32, @floatFromInt(colidx)) * scale; - const y0 = y + @as(f32, @floatFromInt(row)) * scale; - b.addRect(x0, y0, x0 + scale, y0 + scale, color); - } - } - cx += 4.0 * scale; - } - } -}; - -test "overlay labels preserve ink without exempting surrounding chrome" { - var vertices: [192]OverlayVertex = undefined; - var builder: OverlayBuilder = .{ .vertices = &vertices, .win_w = 100, .win_h = 100 }; - const color: OverlayColor = .{ .r = 1, .g = 1, .b = 1, .a = 1 }; - builder.addRect(0, 0, 10, 10, color); - const text_start = builder.len; - builder.addMiniText("1", 0, 0, 1, color); - const text_end = builder.len; - try std.testing.expect(text_end > text_start); - builder.addRect(20, 20, 30, 30, color); - for (vertices[0..builder.len], 0..) |vertex, i| - try std.testing.expectEqual(@as(u32, @intFromBool(i >= text_start and i < text_end)), vertex.ink); - try std.testing.expect(!builder.ink); -} - -const circle_points = [_][2]f32{ - .{ 1.0000000, 0.0000000 }, .{ 0.9238795, 0.3826834 }, .{ 0.7071068, 0.7071068 }, .{ 0.3826834, 0.9238795 }, - .{ 0.0000000, 1.0000000 }, .{ -0.3826834, 0.9238795 }, .{ -0.7071068, 0.7071068 }, .{ -0.9238795, 0.3826834 }, - .{ -1.0000000, 0.0000000 }, .{ -0.9238795, -0.3826834 }, .{ -0.7071068, -0.7071068 }, .{ -0.3826834, -0.9238795 }, - .{ 0.0000000, -1.0000000 }, .{ 0.3826834, -0.9238795 }, .{ 0.7071068, -0.7071068 }, .{ 0.9238795, -0.3826834 }, - .{ 1.0000000, 0.0000000 }, }; -fn touchIdLabel(id: u64) [9]u8 { - var out: [9]u8 = undefined; - out[0] = '#'; - const low: u32 = @truncate(id); - for (0..8) |i| { - const shift: u5 = @intCast((7 - i) * 4); - out[i + 1] = hexDigit((low >> shift) & 0xf); - } - return out; -} - -fn touchClickLabel(count: u32, button: pardes.Mouse.Button) [14]u8 { - var out: [14]u8 = undefined; - @memcpy(out[0..6], if (button == .right) "LOOK #" else "MID #"); - for (0..8) |i| { - const shift: u5 = @intCast((7 - i) * 4); - out[i + 6] = hexDigit((count >> shift) & 0xf); - } - return out; -} - -fn hexDigit(n: u32) u8 { - return if (n < 10) @intCast('0' + n) else @intCast('A' + (n - 10)); -} - -fn miniGlyph(ch: u8) [5]u8 { - return switch (ch) { - '#' => .{ 0b101, 0b111, 0b101, 0b111, 0b101 }, - '0' => .{ 0b111, 0b101, 0b101, 0b101, 0b111 }, - '1' => .{ 0b010, 0b110, 0b010, 0b010, 0b111 }, - '2' => .{ 0b111, 0b001, 0b111, 0b100, 0b111 }, - '3' => .{ 0b111, 0b001, 0b111, 0b001, 0b111 }, - '4' => .{ 0b101, 0b101, 0b111, 0b001, 0b001 }, - '5' => .{ 0b111, 0b100, 0b111, 0b001, 0b111 }, - '6' => .{ 0b111, 0b100, 0b111, 0b101, 0b111 }, - '7' => .{ 0b111, 0b001, 0b010, 0b010, 0b010 }, - '8' => .{ 0b111, 0b101, 0b111, 0b101, 0b111 }, - '9' => .{ 0b111, 0b101, 0b111, 0b001, 0b111 }, - 'A' => .{ 0b111, 0b101, 0b111, 0b101, 0b101 }, - 'B' => .{ 0b110, 0b101, 0b110, 0b101, 0b110 }, - 'C' => .{ 0b111, 0b100, 0b100, 0b100, 0b111 }, - 'D' => .{ 0b110, 0b101, 0b101, 0b101, 0b110 }, - 'E' => .{ 0b111, 0b100, 0b111, 0b100, 0b111 }, - 'F' => .{ 0b111, 0b100, 0b111, 0b100, 0b100 }, - 'I' => .{ 0b111, 0b010, 0b010, 0b010, 0b111 }, - 'K' => .{ 0b101, 0b101, 0b110, 0b101, 0b101 }, - 'L' => .{ 0b100, 0b100, 0b100, 0b100, 0b111 }, - 'M' => .{ 0b101, 0b111, 0b111, 0b101, 0b101 }, - 'O' => .{ 0b111, 0b101, 0b101, 0b101, 0b111 }, - else => .{ 0, 0, 0, 0, 0 }, - }; -} - fn envU16(env: *std.process.Environ.Map, name: []const u8) ?u16 { const raw = env.get(name) orelse return null; return std.fmt.parseInt(u16, raw, 10) catch null; |
