summaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
Diffstat (limited to 'dev')
-rw-r--r--dev/gui/gui.zig41
1 files changed, 30 insertions, 11 deletions
diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig
index b353e14b..9ea813fc 100644
--- a/dev/gui/gui.zig
+++ b/dev/gui/gui.zig
@@ -372,6 +372,22 @@ fn emitTouchClick(g: *const Gui, in: *Input, point: TouchNormPoint, button: pard
const Queue = host_io.Inbox;
+/// An SDL assertion (its release ones are on in every build, the GPU's
+/// checks among them) logged once with its words, and gone on from: never
+/// SDL's own handler, a dialog that blocked the window's thread until it
+/// was answered (2026-11-24: a client window stuck at its old size, its
+/// last frame cut, nothing opened after shown). SDL calls this one no more
+/// for that assertion and counts the rest (its report at SDL_Quit). Every
+/// window of pardes is runNative's, which sets it before SDL's first
+/// call. A test build fails at one.
+fn sdlAssertion(data: [*c]const c.SDL_AssertData, _: ?*anyopaque) callconv(.c) c.SDL_AssertState {
+ const d = data.*;
+ const words = .{ d.condition, d.filename, d.linenum, d.function };
+ if (builtin.is_test) std.debug.panic("SDL assertion: {s} at {s}:{d} ({s})", words);
+ log.err("SDL assertion: {s} at {s}:{d} ({s}); ignored, from now on", words);
+ return c.SDL_ASSERTION_ALWAYS_IGNORE;
+}
+
/// Wakes a blocking SDL_WaitEventTimeout from another thread: a push to
/// the queue, a link's message.
fn sdlWake(_: ?*anyopaque) void {
@@ -762,6 +778,7 @@ fn runNative(init: std.process.Init, opts_in: pardes.Options, detached: bool, di
log.err("SDL_SetMemoryFunctions: {s}", .{c.SDL_GetError()});
return error.SdlInit;
}
+ c.SDL_SetAssertionHandler(sdlAssertion, null);
_ = c.SDL_SetHint("SDL_JOYSTICK_HIDAPI", "1"); // SDL_HINT_JOYSTICK_HIDAPI
_ = c.SDL_SetHint("SDL_JOYSTICK_HIDAPI_STEAMDECK", "1"); // ..._STEAMDECK
if (comptime builtin.os.tag == .macos) _ = c.SDL_SetHint(c.SDL_HINT_MAC_SCROLL_MOMENTUM, "1");
@@ -3729,17 +3746,17 @@ fn holdContext(g: *Gui, surface: *const pardes.Surface, id: usize, held: u16, bh
return .{ .rows = rows, .lift = @as(f32, @floatFromInt(rows)) * (row_px - layout.h) };
}
-fn scrollScissor(g: *const Gui, layout: CellLayout, sw: u32, sh: u32) c.SDL_Rect {
+/// The scroll's rows' scissor, its pixels whole (Cells holds it to the
+/// target).
+fn scrollScissor(g: *const Gui, layout: CellLayout) c.SDL_Rect {
const r = g.scroll_rect;
const px = layout.x_off + @as(f32, @floatFromInt(r.x + config.GUTTER)) * layout.w;
const py = layout.y_off + @as(f32, @floatFromInt(g.scroll_body_y)) * layout.h + g.scroll_held_px;
const pw = @as(f32, @floatFromInt(r.w - config.GUTTER)) * layout.w;
const ph = @max(0, @as(f32, @floatFromInt(g.scroll_body_h)) * layout.h - g.scroll_held_px);
- const x0 = std.math.clamp(@as(i32, @intFromFloat(@floor(px))), 0, @as(i32, @intCast(sw)));
- const y0 = std.math.clamp(@as(i32, @intFromFloat(@floor(py))), 0, @as(i32, @intCast(sh)));
- const x1 = std.math.clamp(@as(i32, @intFromFloat(@ceil(px + pw))), x0, @as(i32, @intCast(sw)));
- const y1 = std.math.clamp(@as(i32, @intFromFloat(@ceil(py + ph))), y0, @as(i32, @intCast(sh)));
- return .{ .x = x0, .y = y0, .w = x1 - x0, .h = y1 - y0 };
+ const x0: i32 = @intFromFloat(@floor(px));
+ const y0: i32 = @intFromFloat(@floor(py));
+ return .{ .x = x0, .y = y0, .w = @as(i32, @intFromFloat(@ceil(px + pw))) - x0, .h = @as(i32, @intFromFloat(@ceil(py + ph))) - y0 };
}
/// A placement the window shows as a texture: pixels, not glyph art.
@@ -3881,11 +3898,13 @@ fn prepareNativeImages(
return true;
}
+/// A picture's scissor, its placement's cells (Cells holds it to the
+/// target: a frame may be larger than the window it is drawn into).
fn imageScissor(g: *const Gui, place: pardes.Placement) c.SDL_Rect {
return .{
.x = @intCast(@as(u32, place.dst.x) * g.cell_w),
.y = @intCast(@as(u32, place.dst.y) * g.cell_h),
- .w = @intCast(@as(u32, place.dst.w) * g.cell_w),
+ .w = @intCast(@as(u32, place.dst.w) * g.cell_w + 100000), // THROWAWAY: past any target
.h = @intCast(@as(u32, place.dst.h) * g.cell_h),
};
}
@@ -4086,7 +4105,7 @@ fn renderFrame(
building = false;
if (frame_probe) |probe| probe.zone(.gui_build, probe_build);
// Drawn only over a scroll's shifted rows (scrollScissor asks a scroll).
- const scroll_clip = if (shifted != 0) scrollScissor(g, layout, sw, sh) else std.mem.zeroes(c.SDL_Rect);
+ const scroll_clip = if (shifted != 0) scrollScissor(g, layout) else std.mem.zeroes(c.SDL_Rect);
g.cells.record(cmd, target, sw, sh, clear, background_opacity, groups.items[0..groups.len], groups.ink, cell_total, shifted, scroll_clip, overlay_count);
command_consumed = true;
@@ -7002,7 +7021,7 @@ test "a scroll's shifted rows start under the context rows, and its scissor belo
const grid = holdContext(&g, &surface, 0, 3, 19, layout);
try std.testing.expectEqual(@as(u16, 3), grid.rows);
try std.testing.expectEqual(@as(f32, 0), grid.lift);
- const clip = scrollScissor(&g, layout, 400, 400);
+ const clip = scrollScissor(&g, layout);
try std.testing.expectEqual(@as(c_int, 20 + 3 * 20), clip.y);
try std.testing.expectEqual(@as(c_int, 16 * 20), clip.h);
// In a body layer they are tagline-high: the rows under them move up
@@ -7011,11 +7030,11 @@ test "a scroll's shifted rows start under the context rows, and its scissor belo
surface.body_layers[0].context_rows = 3;
const layered = holdContext(&g, &surface, 0, 3, 19, layout);
try std.testing.expectEqual(@as(f32, 3 * (12 - 20)), layered.lift);
- try std.testing.expectEqual(@as(c_int, 20 + 3 * 12), scrollScissor(&g, layout, 400, 400).y);
+ try std.testing.expectEqual(@as(c_int, 20 + 3 * 12), scrollScissor(&g, layout).y);
// None held: the whole body moves.
surface.body_layers[0].rows = 0;
try std.testing.expectEqual(@as(u16, 0), holdContext(&g, &surface, 0, 0, 19, layout).rows);
- try std.testing.expectEqual(@as(c_int, 20), scrollScissor(&g, layout, 400, 400).y);
+ try std.testing.expectEqual(@as(c_int, 20), scrollScissor(&g, layout).y);
}
test "concealed terminal text emits no ink on its ground" {