diff options
Diffstat (limited to 'src/macos.zig')
| -rw-r--r-- | src/macos.zig | 68 |
1 files changed, 15 insertions, 53 deletions
diff --git a/src/macos.zig b/src/macos.zig index 5d3dfec4..55f6b3f6 100644 --- a/src/macos.zig +++ b/src/macos.zig @@ -18,7 +18,7 @@ const image = if (pardes.pdf_enabled) @import("image.zig") else struct {}; const host_io = @import("host_io.zig"); const fonts = @import("fonts.zig"); // the shared fallback preference order const tracy = @import("tracy.zig"); // no-op unless -Dtracy names a checkout -const selection_pipe = @import("selection_pipe.zig"); // Job, runJob and Tasks +const selection_pipe = @import("selection_pipe.zig"); // start, Response and Tasks const crash = @import("crash.zig"); pub const panic = std.debug.FullPanic(struct { @@ -830,7 +830,7 @@ export fn pardes_deinit() void { pardes.lsp.setStatusSink(null, null); host_io.setExitWake(null, null); if (st.lsp_task) |*t| { - t.future.cancel(st.io) catch {}; + t.future.cancel(st.io); st.lsp_task = null; } st.pipe_tasks.cancelAll(st.io); @@ -1333,7 +1333,7 @@ fn drainInbox(st: *State) bool { .lsp_done => |d| { st.core.update(.{ .lsp_resp = .{ .id = d.id, .rows = d.rows } }); if (st.lsp_task) |*t| if (t.id == d.id) { - t.future.await(st.io) catch {}; + t.future.await(st.io); st.lsp_task = null; }; }, @@ -1397,7 +1397,7 @@ fn restoreCore(st: *State) bool { return false; }; if (st.lsp_task) |*task| { - task.future.cancel(st.io) catch {}; + task.future.cancel(st.io); st.lsp_task = null; } st.pipe_tasks.cancelAll(st.io); @@ -1592,7 +1592,7 @@ export fn pardes_animation_tick() bool { defer pardes.turn.rest(); const st = &(state orelse return false); - const now: u64 = @intCast(@max(0, monotonicNs())); + const now: u64 = @intCast(std.Io.Clock.awake.now(st.io).nanoseconds); const spend = spendTickTime(st.last_tick_ns, now, st.tick_bank_ns); st.last_tick_ns = now; st.tick_bank_ns = spend.bank_ns; @@ -1766,7 +1766,7 @@ export fn pardes_scroll_begin() void { st.scroll_velocity = 0; st.scroll_velocity_x = 0; st.scroll_coasting = false; - st.scroll_last_ns = monotonicNs(); + st.scroll_last_ns = std.Io.Clock.awake.now(st.io).nanoseconds; } /// Fingers lifted. A swipe that was still moving when it ended becomes a @@ -1786,7 +1786,7 @@ export fn pardes_scroll_end() void { st.scroll_last_ns = 0; st.scroll_coasting = false; // A hand that came to rest before lifting is not throwing anything. - if (last == 0 or monotonicNs() - last > 90 * std.time.ns_per_ms) { + if (last == 0 or std.Io.Clock.awake.now(st.io).nanoseconds - last > 90 * std.time.ns_per_ms) { st.scroll_velocity = 0; st.scroll_velocity_x = 0; return; @@ -1804,7 +1804,7 @@ export fn pardes_rotate(degrees: f32) void { st.rotate_lag = 0; st.rotate_velocity = 0; st.rotate_coasting = false; - st.rotate_last_ns = monotonicNs(); + st.rotate_last_ns = std.Io.Clock.awake.now(st.io).nanoseconds; return; } noteRotationVelocity(st, degrees); @@ -1818,7 +1818,7 @@ export fn pardes_rotate_end() void { const last = st.rotate_last_ns; st.rotate_last_ns = 0; st.rotate_coasting = false; - if (last == 0 or monotonicNs() - last > 90 * std.time.ns_per_ms) { + if (last == 0 or std.Io.Clock.awake.now(st.io).nanoseconds - last > 90 * std.time.ns_per_ms) { st.rotate_velocity = 0; return; } @@ -1826,14 +1826,8 @@ export fn pardes_rotate_end() void { st.rotate_coasting = st.rotate_velocity != 0; } -fn monotonicNs() i128 { - var ts: libc.timespec = undefined; - if (libc.clock_gettime(.MONOTONIC, &ts) != 0) return 0; - return @as(i128, ts.sec) * std.time.ns_per_s + ts.nsec; -} - fn noteRotationVelocity(st: *State, degrees: f32) void { - const now = monotonicNs(); + const now = std.Io.Clock.awake.now(st.io).nanoseconds; const last = st.rotate_last_ns; st.rotate_last_ns = now; st.rotate_coasting = false; @@ -2380,52 +2374,20 @@ fn hostFor(st: *State) pardes.Host { fn lspRequest(ctx: ?*anyopaque, req: host_io.Lsp.Request) void { const st = hostState(ctx); - const job = host_io.Lsp.snapshot(st.gpa, st.core, req) catch |err| { - st.core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } }); - return st.core.reportError(req.pane, "lsp", err); - }; - if (st.lsp_task) |*old| { - old.future.cancel(st.io) catch {}; - st.lsp_task = null; - } - const future = st.io.concurrent(lspWorker, .{ st, job }) catch |err| { - job.free(st.gpa); - st.core.update(.{ .lsp_resp = .{ .id = req.id, .rows = null } }); - return st.core.reportError(req.pane, "lsp", err); - }; - st.lsp_task = .{ .id = req.id, .future = future }; + host_io.Lsp.start(st.io, st.gpa, st.core, &st.lsp_task, req, st, deliverLspRows); } fn pipeRequest(ctx: ?*anyopaque, id: u32) void { const st = hostState(ctx); - if (st.pipe_tasks.full()) { - st.core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } }); - return; - } - const view = st.core.pipe.pipeRequest(id) orelse return; - const job = selection_pipe.Job.copy(st.gpa, view) catch |err| { - st.core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } }); - return st.core.reportError(st.core.active, "pipe", err); - }; - const future = st.io.concurrent(pipeWorker, .{ st, job }) catch |err| { - job.deinit(st.gpa); - st.core.update(.{ .pipe_resp = .{ .id = id, .success = false, .outputs = &.{} } }); - return st.core.reportError(st.core.active, "pipe", err); - }; - std.debug.assert(st.pipe_tasks.add(.{ .id = id, .future = future })); + selection_pipe.start(st.io, st.gpa, st.core, &st.pipe_tasks, id, st, deliverPipe); } -fn pipeWorker(st: *State, job: *selection_pipe.Job) anyerror!void { - defer job.deinit(st.gpa); - const response = selection_pipe.runJob(st.gpa, st.io, job); +fn deliverPipe(ctx: ?*anyopaque, response: selection_pipe.Response) void { + const st: *State = @ptrCast(@alignCast(ctx orelse return)); st.inbox.push(st.gpa, st.io, .{ .pipe = response }); wake(st); } -fn lspWorker(st: *State, job: *host_io.Lsp.Job) anyerror!void { - host_io.Lsp.work(st.io, st.gpa, job, st, deliverLspRows); -} - fn deliverLspRows(ctx: ?*anyopaque, id: u32, rows: ?[]u8) void { const st: *State = @ptrCast(@alignCast(ctx orelse return)); st.inbox.push(st.gpa, st.io, .{ .lsp_done = .{ .id = id, .rows = rows } }); @@ -2662,7 +2624,7 @@ fn encodeCellFlags(default: bool, role: pardes.FontRole, hover: bool) u8 { } fn noteScrollVelocity(st: *State, delta_rows: f32, delta_cols: f32) void { - const now = monotonicNs(); + const now = std.Io.Clock.awake.now(st.io).nanoseconds; const last = st.scroll_last_ns; st.scroll_last_ns = now; // Any real travel ends a coast: that is what lets a host with momentum of |
