summaryrefslogtreecommitdiff
path: root/src/macos.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/macos.zig')
-rw-r--r--src/macos.zig263
1 files changed, 37 insertions, 226 deletions
diff --git a/src/macos.zig b/src/macos.zig
index d550e2bd..c0d1c69c 100644
--- a/src/macos.zig
+++ b/src/macos.zig
@@ -12,7 +12,6 @@ const colors = @import("colors.zig");
const look = @import("look.zig");
const message = pardes.Messages.Message;
const layout = @import("layout.zig");
-const animation = @import("animation.zig");
const file_watch = @import("file_watch.zig");
const host_io = @import("host_io.zig");
const fonts = @import("fonts.zig"); // the shared fallback preference order
@@ -76,8 +75,10 @@ pub const Scene = extern struct {
frame: u32 = 0,
};
-pub const PanelBox = animation.Box;
-pub const PanelTrack = animation.Track;
+/// pardes.h's pane transition, which the core no longer makes (its motion
+/// is the frontends' since animation.zig went): the list stays, empty.
+pub const PanelBox = extern struct { x: f32, y: f32, w: f32, h: f32 };
+pub const PanelTrack = extern struct { serial: u32, pane: u8, phase: u8, effect: u8, motion: u8, frame: u16, frame_count: u16, from: PanelBox, to: PanelBox, launch: f32 };
pub const Image = extern struct {
serial: u32,
@@ -114,12 +115,8 @@ const color_indexed: u32 = 0x02000000;
const cell_flag_default: u8 = 1;
const cell_flag_tagline: u8 = 2;
const cell_flag_hover: u8 = 4;
-const scene_flag_crt: u32 = 1 << 0;
-const scene_frame_hz: u32 = 60;
-const scene_wrap_ns: u64 = 4096 * std.time.ns_per_s;
-
-const max_tick_catch_up_ns: u64 = 4 * pardes.animation.frame_ns;
+const max_tick_catch_up_ns: u64 = 4 * pardes.frame_ns;
const theme_watch_pane: u8 = @intCast(pardes.MAX_PANES);
const watch_slot_count = pardes.MAX_PANES + 1;
@@ -257,16 +254,11 @@ const State = struct {
tag_cells: [pardes.MAX_TAG_LAYERS][]Cell = @splat(&.{}),
layer_cells: [pardes.MAX_PANES][]Cell = @splat(&.{}),
cells: []Cell = &.{},
- previous_cells: []Cell = &.{},
- changed_cells: []u8 = &.{},
- panel_diff_len: usize = 0,
frame_len: usize = 0,
frame_cols: u16 = 0,
frame_rows: u16 = 0,
images: []Image = &.{},
images_len: usize = 0,
- panel_tracks: [pardes.MAX_PANES * 2]PanelTrack = undefined,
- panel_tracks_len: usize = 0,
ptys: [pardes.MAX_PANES]?Pty = @splat(null),
inbox: Inbox = undefined,
/// A wakeup is on its way to the runtime: the next ones are not sent.
@@ -289,7 +281,6 @@ const State = struct {
rotate_velocity: f32 = 0,
rotate_last_ns: i128 = 0,
rotate_coasting: bool = false,
- scene_ns: u64 = 0,
last_tick_ns: u64 = 0,
tick_bank_ns: u64 = 0,
cwd_stale: [pardes.MAX_PANES]bool = @splat(false),
@@ -439,8 +430,6 @@ export fn pardes_deinit() void {
if (st.cells.len > 0) st.gpa.free(st.cells);
for (st.layer_cells) |cells| st.gpa.free(cells);
for (st.tag_cells) |cells| st.gpa.free(cells);
- if (st.previous_cells.len > 0) st.gpa.free(st.previous_cells);
- if (st.changed_cells.len > 0) st.gpa.free(st.changed_cells);
if (st.images.len > 0) st.gpa.free(st.images);
st.core.deinit();
pardes.TerminalImages.stop();
@@ -465,33 +454,17 @@ export fn pardes_should_quit() bool {
return st.core.quit;
}
-// The Metal shell keeps its own CRT kernel: the GUI's bundled post pass, as
-// a flag.
-fn encodeSceneEffects(post: *const pardes.config.Runtime.Post) u32 {
- var flags: u32 = 0;
- if (post.has(.crt)) flags |= scene_flag_crt;
- return flags;
-}
-
-fn currentSceneFlags(st: *const State) u32 {
- return encodeSceneEffects(&st.core.settings.post);
-}
-
-fn advanceSceneClock(st: *State, elapsed_ns: u64) void {
- st.scene_ns = (st.scene_ns +| elapsed_ns) % scene_wrap_ns;
-}
-
const TickSpend = struct { elapsed_ns: u64, steps: u32, bank_ns: u64 };
fn spendTickTime(previous_ns: u64, now_ns: u64, bank_ns: u64) TickSpend {
const measured = if (previous_ns == 0 or now_ns <= previous_ns)
- pardes.animation.frame_ns
+ pardes.frame_ns
else
now_ns - previous_ns;
const elapsed = @min(measured, max_tick_catch_up_ns);
var bank = bank_ns +| elapsed;
var steps: u32 = 0;
- while (bank >= pardes.animation.frame_ns) : (steps += 1) bank -= pardes.animation.frame_ns;
+ while (bank >= pardes.frame_ns) : (steps += 1) bank -= pardes.frame_ns;
return .{ .elapsed_ns = elapsed, .steps = steps, .bank_ns = bank };
}
@@ -554,7 +527,7 @@ export fn pardes_tagline_origin_col(col: u16, row: u16) f32 {
pardes.turn.wake();
defer pardes.turn.rest();
const st = &(state orelse return @floatFromInt(col));
- return pardes.taglineOriginColForFrame(st.core, col, row);
+ return pardes.taglineOriginCol(st.core, col, row);
}
export fn pardes_grid_col_at(x: f32, row: u16, body_w: f32, tagline_w: f32) u16 {
@@ -603,34 +576,15 @@ export fn pardes_fallback_font_name(index: u32, len: *u32) ?[*]const u8 {
return name.ptr;
}
+// The core has no post pass (CRT) and no pane transitions since the
+// rewrite: the scene is always still and these three say so to the shell.
export fn pardes_scene() Scene {
- pardes.turn.wake();
- defer pardes.turn.rest();
- const st = &(state orelse return .{});
- const seconds = @as(f64, @floatFromInt(st.scene_ns)) / @as(f64, std.time.ns_per_s);
- return .{
- .flags = currentSceneFlags(st),
- .time_seconds = @floatCast(seconds),
- .frame = @intFromFloat(seconds * @as(f64, @floatFromInt(scene_frame_hz))),
- };
+ return .{};
}
-export fn pardes_postprocessor_unavailable() void {
- pardes.turn.wake();
- defer pardes.turn.rest();
- const st = &(state orelse return);
- st.core.disableSceneEffects();
- st.core.settings.panel_transition = .off;
- st.core.abandonPanelAnimations();
- st.scene_ns = 0;
-}
+export fn pardes_postprocessor_unavailable() void {}
-export fn pardes_panel_animation_failed() void {
- pardes.turn.wake();
- defer pardes.turn.rest();
- const st = &(state orelse return);
- st.core.abandonPanelAnimations();
-}
+export fn pardes_panel_animation_failed() void {}
fn refreshCwds(ctx: ?*anyopaque) void {
const st = hostState(ctx);
@@ -684,7 +638,7 @@ fn setFileWatch(st: *State, pane: u8, path: []const u8, mode: pardes.WatchMode)
_ = reloadWatchedFile(st, pane, false);
}
-fn setThemeFileWatch(st: *State, request_generation: u32, on: bool, animate: bool) void {
+fn setThemeFileWatch(st: *State, request_generation: u32, on: bool) void {
const stopped = st.file_watches.stop(st.gpa, theme_watch_pane);
hostWatchFile(theme_watch_pane, stopped, null, 0);
if (!on) return;
@@ -694,7 +648,7 @@ fn setThemeFileWatch(st: *State, request_generation: u32, on: bool, animate: boo
return;
};
defer st.gpa.free(bytes);
- if (!colors.loadThemeFile(st.core, request_generation, bytes, animate)) return;
+ if (!colors.loadThemeFile(st.core, request_generation, bytes)) return;
const callback_generation = st.file_watches.replace(
st.gpa,
theme_watch_pane,
@@ -721,7 +675,7 @@ fn reloadWatchedTheme(st: *State, announce: bool) bool {
.text => |accepted| if (accepted == hash) return false,
.kind => unreachable,
}
- if (!colors.loadThemeFile(st.core, watched.serial, bytes, true)) return false;
+ if (!colors.loadThemeFile(st.core, watched.serial, bytes)) return false;
const live = if (st.file_watches.entries[theme_watch_pane]) |*entry| entry else return false;
if (live.serial != watched.serial) return false;
live.generation_on_disk = .{ .text = hash };
@@ -960,7 +914,6 @@ fn restoreCore(st: *State) bool {
st.rotate_velocity = 0;
st.rotate_last_ns = 0;
st.rotate_coasting = false;
- st.scene_ns = 0;
st.last_tick_ns = 0;
st.tick_bank_ns = 0;
return true;
@@ -977,10 +930,6 @@ export fn pardes_animation_tick() bool {
st.tick_bank_ns = spend.bank_ns;
var changed = false;
- if (currentSceneFlags(st) != 0) {
- advanceSceneClock(st, spend.elapsed_ns);
- changed = true;
- }
for (0..spend.steps) |_| {
if (st.core.animationActive()) {
@@ -1062,19 +1011,20 @@ export fn pardes_mouse_pixel(button_arg: c_int, kind_arg: c_int, col: u16, row:
pardes.turn.wake();
defer pardes.turn.rest();
const st = &(state orelse return);
- const source = st.core.presentation.pointerFractional(st.core.view().screen_w, st.core.view().screen_h, x / @max(1, bw), y / @max(1, bh));
+ // The layers are asked only over the grid, as the gui's onGrid.
+ const v = st.core.view();
+ const on_grid = std.math.isFinite(x) and std.math.isFinite(y) and x >= 0 and y >= 0 and
+ x < @as(f32, @floatFromInt(v.screen_w)) * @max(1, bw) and y < @as(f32, @floatFromInt(v.screen_h)) * @max(1, bh);
var hit: ?pardes.Mouse.BodyHit = null;
- for (&st.core.surface.body_layers) |*layer| {
- const point = source orelse break;
- hit = layer.bodyHit(point.x * bw, point.y * bh, bw, bh, tw, th);
+ if (on_grid) for (&st.core.surface.body_layers) |*layer| {
+ hit = layer.bodyHit(x, y, bw, bh, tw, th);
if (hit != null) break;
- }
+ };
var tag_hit: ?pardes.TagHit = null;
- for (&st.core.surface.tag_layers) |*layer| {
- const point = source orelse break;
- tag_hit = layer.tagHit(point.x * bw, point.y * bh, bw, bh, tw, th);
+ if (on_grid) for (&st.core.surface.tag_layers) |*layer| {
+ tag_hit = layer.tagHit(x, y, bw, bh, tw, th);
if (tag_hit != null) break;
- }
+ };
mouseWithHit(button_arg, kind_arg, col, row, mods, hit, tag_hit);
}
@@ -1278,8 +1228,6 @@ fn clearFrame(st: *State) void {
st.frame_cols = 0;
st.frame_rows = 0;
st.images_len = 0;
- st.panel_tracks_len = 0;
- st.panel_diff_len = 0;
}
fn blankTagCells(cells: []Cell, cols: u16, rows: u16, source: []const pardes.Cell, layers: []const pardes.Layer) void {
@@ -1330,44 +1278,7 @@ fn presentFrame(ctx: ?*anyopaque, surface: *const pardes.Surface) void {
for (surface.cells, st.cells[0..count]) |cell, *out| out.* = encodeCell(cell);
}
blankTagCells(st.cells[0..count], surface.cols, surface.rows, surface.cells, &surface.tag_layers);
- collectPanelDiff(st, surface, count);
collectImages(st, surface);
- collectPanelTracks(st, surface);
-}
-
-fn collectPanelTracks(st: *State, surface: *const pardes.Surface) void {
- const source = surface.panelTracks();
- const len = @min(source.len, st.panel_tracks.len);
- @memcpy(st.panel_tracks[0..len], source[0..len]);
- st.panel_tracks_len = len;
-}
-
-fn collectPanelDiff(st: *State, surface: *const pardes.Surface, count: usize) void {
- if (!surface.hasPanelDiff() or count == 0) return;
- if (st.previous_cells.len != count) {
- const resized = if (st.previous_cells.len == 0)
- st.gpa.alloc(Cell, count)
- else
- st.gpa.realloc(st.previous_cells, count);
- st.previous_cells = resized catch return;
- }
- if (st.changed_cells.len != count) {
- const resized = if (st.changed_cells.len == 0)
- st.gpa.alloc(u8, count)
- else
- st.gpa.realloc(st.changed_cells, count);
- st.changed_cells = resized catch return;
- }
- for (surface.previous_cells, st.previous_cells[0..count]) |cell, *out|
- out.* = encodeCell(cell);
- blankTagCells(st.previous_cells[0..count], surface.cols, surface.rows, surface.previous_cells, surface.previous_tag_layers);
- for (surface.cell_diffs, st.changed_cells[0..count]) |diff, *out|
- out.* = encodeChanged(diff);
- st.panel_diff_len = count;
-}
-
-fn encodeChanged(diff: pardes.PanelCellDiff) u8 {
- return if (diff.changed()) 255 else 0;
}
fn collectImages(st: *State, surface: *const pardes.Surface) void {
@@ -1434,30 +1345,18 @@ export fn pardes_frame_image_list() ?[*]const Image {
return if (st.images_len == 0) null else st.images.ptr;
}
+// No pane transitions: no tracks, no previous frame to blend from, and a
+// presented frame starts no clock.
export fn pardes_frame_panel_tracks() u32 {
- pardes.turn.wake();
- defer pardes.turn.rest();
- const st = &(state orelse return 0);
- return @intCast(st.panel_tracks_len);
+ return 0;
}
export fn pardes_frame_panel_track_list() ?[*]const PanelTrack {
- pardes.turn.wake();
- defer pardes.turn.rest();
- const st = &(state orelse return null);
- return if (st.panel_tracks_len == 0) null else st.panel_tracks[0..].ptr;
+ return null;
}
-export fn pardes_frame_presented(animated_panels: bool) bool {
- pardes.turn.wake();
- defer pardes.turn.rest();
- const st = &(state orelse return false);
- const was_animating = st.core.animationActive();
- if (animated_panels)
- st.core.acknowledgePanelPresentation(st.panel_tracks[0..st.panel_tracks_len])
- else
- st.core.acknowledgePanelPresentation(&.{});
- return !was_animating and st.core.animationActive();
+export fn pardes_frame_presented(_: bool) bool {
+ return false;
}
export fn pardes_frame_cells() ?[*]const Cell {
@@ -1468,23 +1367,11 @@ export fn pardes_frame_cells() ?[*]const Cell {
}
export fn pardes_frame_previous_cells() ?[*]const Cell {
- pardes.turn.wake();
- defer pardes.turn.rest();
- const st = &(state orelse return null);
- return if (st.panel_diff_len != st.frame_len or st.panel_diff_len == 0)
- null
- else
- st.previous_cells.ptr;
+ return null;
}
export fn pardes_frame_changed_cells() ?[*]const u8 {
- pardes.turn.wake();
- defer pardes.turn.rest();
- const st = &(state orelse return null);
- return if (st.panel_diff_len != st.frame_len or st.panel_diff_len == 0)
- null
- else
- st.changed_cells.ptr;
+ return null;
}
export fn pardes_frame_cols() u16 {
@@ -1843,7 +1730,7 @@ fn watchFile(ctx: ?*anyopaque, pane: u8, path: []const u8, on: bool, mode: parde
fn watchTheme(ctx: ?*anyopaque, generation: u32, on: bool) void {
const st = hostState(ctx);
- setThemeFileWatch(st, generation, on, st.started);
+ setThemeFileWatch(st, generation, on);
}
fn dumpThemes(ctx: ?*anyopaque, pane: u8) void {
@@ -2259,7 +2146,7 @@ test "mac host watcher covers file and directory vnode events, debounce, and gen
}
test "the animation clock spends real time, not callbacks" {
- const frame = pardes.animation.frame_ns;
+ const frame = pardes.frame_ns;
const expectEqual = std.testing.expectEqual;
const first = spendTickTime(0, 999 * std.time.ns_per_s, 0);
@@ -2571,22 +2458,6 @@ test "pardes.h matches the Zig boundary" {
try expectEqual(@as(u8, c.PARDES_CELL_TAGLINE), cell_flag_tagline);
try expectEqual(@as(u8, c.PARDES_CELL_HOVER), cell_flag_hover);
try expectEqual(@as(u16, c.PARDES_TOPBAR_H), pardes.TOPBAR_H);
- try expectEqual(@as(u32, c.PARDES_SCENE_CRT), scene_flag_crt);
- try expectEqual(@as(u8, c.PARDES_PANEL_OPENING), @backingInt(animation.Phase.opening));
- try expectEqual(@as(u8, c.PARDES_PANEL_MOVING), @backingInt(animation.Phase.moving));
- try expectEqual(@as(u8, c.PARDES_PANEL_CLOSING), @backingInt(animation.Phase.closing));
- try expectEqual(@as(u8, c.PARDES_PANEL_OFF), @backingInt(animation.Transition.off));
- try expectEqual(@as(u8, c.PARDES_PANEL_SLIDE), @backingInt(animation.Transition.slide));
- try expectEqual(@as(u8, c.PARDES_PANEL_ZOOM), @backingInt(animation.Transition.zoom));
- try expectEqual(@as(u8, c.PARDES_PANEL_DISSOLVE), @backingInt(animation.Transition.dissolve));
- try expectEqual(@as(u8, c.PARDES_PANEL_ASCII), @backingInt(animation.Transition.ascii));
- try expectEqual(@as(u8, c.PARDES_PANEL_VERTICAL), @backingInt(animation.Transition.vertical));
- try expectEqual(@as(u8, c.PARDES_PANEL_EDGES), @backingInt(animation.Transition.edges));
- try expectEqual(@as(u8, c.PARDES_PANEL_FALL), @backingInt(animation.Transition.fall));
- try expectEqual(@as(u8, c.PARDES_PANEL_WAVE), @backingInt(animation.Transition.wave));
- try expectEqual(@as(u8, c.PARDES_PANEL_CURTAIN), @backingInt(animation.Transition.curtain));
- try expectEqual(@as(u8, c.PARDES_PANEL_SCRAMBLE), @backingInt(animation.Transition.scramble));
- try expectEqual(@as(u8, c.PARDES_PANEL_TYPEWRITER), @backingInt(animation.Transition.typewriter));
try expectEqual(@as(u21, c.PARDES_KEY_ENTER), pardes.Key.enter);
try expectEqual(@as(u21, c.PARDES_KEY_ESCAPE), pardes.Key.escape);
@@ -2640,47 +2511,6 @@ test "pardes.h matches the Zig boundary" {
try expectEqual(pardes.config.gui_tagline_font_percent, pardes_gui_tagline_font_percent());
}
-test "scene effect flags and display clock are compact and independent" {
- const expectEqual = std.testing.expectEqual;
- var post: pardes.config.Runtime.Post = .{};
- try expectEqual(@as(u32, 0), encodeSceneEffects(&post));
- _ = post.set(.crt, "", true);
- try expectEqual(scene_flag_crt, encodeSceneEffects(&post));
-
- var st: State = undefined;
- st.scene_ns = scene_wrap_ns - (std.time.ns_per_ms * 5);
- advanceSceneClock(&st, std.time.ns_per_ms * 5);
- try expectEqual(@as(u64, 0), st.scene_ns);
- advanceSceneClock(&st, std.time.ns_per_ms * 7);
- try expectEqual(@as(u64, std.time.ns_per_ms * 7), st.scene_ns);
-}
-
-test "the mac panel ABI hands the shader the core's order verbatim" {
- const source = [_]PanelTrack{
- .{ .serial = 12, .pane = 1, .phase = .moving, .effect = .zoom },
- .{ .serial = 15, .pane = 2, .phase = .moving, .effect = .dissolve },
- .{ .serial = 11, .pane = 3, .phase = .opening, .effect = .slide },
- .{ .serial = 16, .pane = 2, .phase = .closing, .effect = .vertical },
- };
- var st: State = undefined;
- st.panel_tracks = undefined;
- st.panel_tracks_len = 0;
- var surface: pardes.Surface = std.mem.zeroes(pardes.Surface);
- @memcpy(surface.panel_tracks[0..source.len], &source);
- surface.npanel_tracks = source.len;
-
- collectPanelTracks(&st, &surface);
- try std.testing.expectEqual(source.len, st.panel_tracks_len);
- for (source, st.panel_tracks[0..st.panel_tracks_len]) |want, got|
- try std.testing.expectEqual(want.serial, got.serial);
-}
-
-test "mac panel mask is a literal normalized grayscale texture" {
- try std.testing.expectEqual(@as(u8, 0), encodeChanged(.unchanged));
- try std.testing.expectEqual(@as(u8, 255), encodeChanged(.visual));
- try std.testing.expectEqual(@as(u8, 255), encodeChanged(.{ .ascii = .{ .from = 'a', .to = 'z' } }));
-}
-
test "mac panel ABI has the documented compact byte layout" {
try std.testing.expectEqual(@as(usize, 16), @sizeOf(PanelBox));
try std.testing.expectEqual(@as(usize, 48), @sizeOf(PanelTrack));
@@ -2764,7 +2594,7 @@ test "the dial flings in proportion to the release, and not at all when placed"
try std.testing.expect(travel(100_000) / rotation_notch_degrees > 8);
}
-test "a live session renders on the draw and animates only on the display clock" {
+test "a live session renders on the draw" {
try std.testing.expectEqual(@as(c_int, 0), pardes_init(null, 80, 24));
defer pardes_deinit();
const st = &state.?;
@@ -2779,25 +2609,6 @@ test "a live session renders on the draw and animates only on the display clock"
try std.testing.expectEqual(@as(u16, 80), pardes_frame_cols());
try std.testing.expectEqual(@as(u16, 24), pardes_frame_rows());
try std.testing.expect(pardes_frame_cells() != null);
-
- for ([_][]const u8{ "Theme dark", "Theme acme" }) |command| {
- pardes_command(command.ptr, command.len);
- _ = pardes_tick();
- _ = pardes_frame();
- }
- try std.testing.expect(pardes_animating());
- const step = st.core.chrome_animation.step;
- _ = pardes_tick();
- _ = pardes_frame();
- _ = pardes_tick();
- _ = pardes_frame();
- try std.testing.expectEqual(step, st.core.chrome_animation.step);
- try std.testing.expectEqual(@as(usize, 0), st.core.in_len);
- try std.testing.expect(pardes_animation_tick());
- try std.testing.expectEqual(step + 1, st.core.chrome_animation.step);
- _ = pardes_tick();
- _ = pardes_frame();
- try std.testing.expectEqual(step + 1, st.core.chrome_animation.step);
}
test "mac row metrics ABI preserves PDF cell dimensions and the unrendered grid" {