summaryrefslogtreecommitdiff
path: root/src/pdf_view.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 02:56:53 -0300
committerGabriel Schneider <[email protected]>2026-11-06 04:13:33 -0300
commitd1d5d3cfb18841604bba2057eeb3598f729b4475 (patch)
tree298c29ab8767852bf74eb86ad4d15acc4348f109 /src/pdf_view.zig
parent33037ece5af9ae1c7048819bbbae3fc5e6fc4ade (diff)
downloadpardes-d1d5d3cfb18841604bba2057eeb3598f729b4475.tar.gz
pardes-d1d5d3cfb18841604bba2057eeb3598f729b4475.zip
client #1, the views indexed: a view's share of the session is Pardes.View (the ~42 fields views.fields named: size, cell metrics, columns, rects, focus, jumps, pointer, gestures, prefixes, frontend), one of Pardes.views[4] (null when closed), the live one views[live] through Pardes.view() (index field `view` renamed `live`); going into another view is the index plus the panes' shares, which stay swapped (park and unpark now move only Pane.pv); views.zig loses fields, Part over Pardes, Parked, kept, emptied and the session half of every copy, and a pane closing leaves every view's layout at once (views.gone, at the two places a slot is freed) instead of the serials each parked view kept; drawOne and within put the drawn view's own share back whole; the views are in the digest now (tape's per-field parts name views[k].field), so a fresh view's col_x/col_w default to zeros, not undefined; the dump keeps every open view in the core and the panes' shares of the others under `shares`; an image from before (live view as the core's own fields, the rest under `views`) loads them into views[] once; the ~2,400 references rewritten mechanically from the compiler's errors (p.active is p.view().active, `const v = p.view()` hoisted in 823 places), Kind.zig (4 lines) and addon_test.zig (3) among them, macos.zig by pattern (not compiled here); tape's watched host writes read the live view's frontend and active; perf.zig's accessor lines change its harness hash, the debug baselines re-keyed to it (their numbers the base's); no golden changes; gates: core-test 956/956 both, unit-test 1487/1488 tui and 1530/1531 gui, behaviour-test 248/248 both, pane-test 171/172, snap all 105 ok, process-test 0 of 37 failed tui, replicas ok
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/pdf_view.zig')
-rw-r--r--src/pdf_view.zig53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/pdf_view.zig b/src/pdf_view.zig
index 4da382fd..8edb4902 100644
--- a/src/pdf_view.zig
+++ b/src/pdf_view.zig
@@ -2326,11 +2326,12 @@ fn movePage(
/// A normal-mode command in a PDF pane: the page moves, or the session is
/// asked for what a page cannot do (Last, the leader, the tag, a search).
pub fn applyNormal(core: *pardes.Pardes, pane: *pardes.Pane, a: modal.Normal.Action) void {
+ const v = core.view();
if (comptime !enabled) return;
const state = pane.pdf orelse return;
const gpa = core.pdf_gpa;
- const native = core.frontend.native_images;
- const cells: CellPixels = .{ .w = core.cell_pixels.w, .h = core.cell_pixels.h };
+ const native = v.frontend.native_images;
+ const cells: CellPixels = .{ .w = v.cell_pixels.w, .h = v.cell_pixels.h };
const viewport = paneViewport(core, pane);
const placed = if (native) paneGeometry(core, pane) else null;
const page_changed = switch (a.role) {
@@ -2338,7 +2339,7 @@ pub fn applyNormal(core: *pardes.Pardes, pane: *pardes.Pane, a: modal.Normal.Act
// a pane (text-only, the page shows neither); typed again by a
// macro, Esc is only the page's.
.escape => {
- if ((!state.cancelChrome(gpa) or !native) and core.macro.replaying == 0) exec.runBuiltin(core, .Last, core.active, "", null);
+ if ((!state.cancelChrome(gpa) or !native) and core.macro.replaying == 0) exec.runBuiltin(core, .Last, v.active, "", null);
return;
},
.move_down, .goto_line_down => moveRows(state, gpa, native, viewport, cells, 1, a.count),
@@ -2359,8 +2360,8 @@ pub fn applyNormal(core: *pardes.Pardes, pane: *pardes.Pane, a: modal.Normal.Act
.half_page_down, .page_down => movePage(state, gpa, native, viewport, cells, 1, a.role == .half_page_down, a.count),
.half_page_up, .page_up => movePage(state, gpa, native, viewport, cells, -1, a.role == .half_page_up, a.count),
.leader => {
- core.prefix = .leader;
- core.leader_n = 0;
+ v.prefix = .leader;
+ v.leader_n = 0;
return;
},
.command_line => return tagline.enterTag(core, pane),
@@ -2718,7 +2719,7 @@ fn rearmCleanSections(
pane.search_pane = remembered.pane;
pane.search_row = null;
look.armLookWalk(core, remembered.pane);
- core.active = id;
+ core.view().active = id;
return true;
}
@@ -2759,7 +2760,7 @@ pub fn openSections(core: *pardes.Pardes, id: usize) void {
};
exec.placeNew(core, id, id, free, .doc);
layout.compute(core);
- core.active = id;
+ core.view().active = id;
pane.search_pane = free;
pane.search_row = null;
look.armLookWalk(core, free);
@@ -2824,7 +2825,7 @@ pub fn lookSection(
.external => |uri| if (uri.len <= 256) core.emit(.{ .open_link = .from(uri) }),
.none => unreachable,
}
- core.active = owner.id;
+ core.view().active = owner.id;
return true;
}
@@ -2928,14 +2929,15 @@ pub fn toggleTint(pane: *pardes.Pane) void {
}
pub fn paneViewport(core: *const pardes.Pardes, pane: *const pardes.Pane) ?Viewport {
+ const v = core.view();
if (comptime !enabled) return null;
- const rect = core.rects[panes.paneIdOf(core, pane) orelse return null];
+ const rect = v.rects[panes.paneIdOf(core, pane) orelse return null];
const cols = rect.w -| config.GUTTER;
const rows = rect.h -| pane.tag_rows;
if (cols == 0 or rows == 0) return null;
return .{
- .pixel_w = @as(u32, cols) * @as(u32, core.cell_pixels.w),
- .pixel_h = @as(u32, rows) * @as(u32, core.cell_pixels.h),
+ .pixel_w = @as(u32, cols) * @as(u32, v.cell_pixels.w),
+ .pixel_h = @as(u32, rows) * @as(u32, v.cell_pixels.h),
};
}
@@ -2965,13 +2967,14 @@ pub fn paneGeometry(core: *const pardes.Pardes, pane: *const pardes.Pane) ?image
/// The page under grid row `row`, from the middle of its cell.
pub fn pageAtGridRow(core: *const pardes.Pardes, pane: *const pardes.Pane, row: u16) ?usize {
+ const v = core.view();
if (comptime !enabled) return null;
const state = pane.pdf orelse return null;
- const rect = core.rects[panes.paneIdOf(core, pane) orelse return null];
+ const rect = v.rects[panes.paneIdOf(core, pane) orelse return null];
const body_y = core.bodyTop(pane, rect);
if (!state.layout_valid or row < body_y or row >= body_y + (rect.h -| pane.tag_rows)) return null;
const document_y = state.document_scroll_y + @as(f64, @floatFromInt(
- @as(u32, row - body_y) * core.cell_pixels.h + core.cell_pixels.h / 2,
+ @as(u32, row - body_y) * v.cell_pixels.h + v.cell_pixels.h / 2,
));
const page = pageAtOffset(state, document_y);
const start: f64 = @floatFromInt(state.page_starts[page]);
@@ -2983,7 +2986,7 @@ pub fn pageAtGridRow(core: *const pardes.Pardes, pane: *const pardes.Pane, row:
/// Some page of the pane is placed where it is drawn.
pub fn paneNativeReady(core: *const pardes.Pardes, pane: *const pardes.Pane) bool {
if (comptime !enabled) return false;
- if (!core.frontend.native_images) return false;
+ if (!core.view().frontend.native_images) return false;
const state = if (pane.pdf) |view| view else return false;
const view = paneViewport(core, pane) orelse return false;
for (state.rasters[0..state.rasters_len]) |*raster| {
@@ -2999,7 +3002,7 @@ pub fn nativePageAtGridRow(
row: u16,
) ?usize {
if (comptime !enabled) return null;
- if (!core.frontend.native_images) return null;
+ if (!core.view().frontend.native_images) return null;
const state = if (pane.pdf) |view| view else return null;
const page = pageAtGridRow(core, pane, row) orelse return null;
const view = paneViewport(core, pane) orelse return null;
@@ -3023,11 +3026,11 @@ pub fn panePointAtPage(
const raster = rasterForPageConst(state, page) orelse return null;
if (raster.rgba.len == 0) return null;
const placed = placedGeometry(state, raster, view, page) orelse return null;
- const rect = core.rects[panes.paneIdOf(core, pane) orelse return null];
+ const rect = core.view().rects[panes.paneIdOf(core, pane) orelse return null];
const body_x = @as(i64, rect.x + config.GUTTER);
const body_y = @as(i64, core.bodyTop(pane, rect));
- const px = (@as(i64, col) - body_x) * core.cell_pixels.w + core.cell_pixels.w / 2;
- const py = (@as(i64, row) - body_y) * core.cell_pixels.h + core.cell_pixels.h / 2;
+ const px = (@as(i64, col) - body_x) * core.view().cell_pixels.w + core.view().cell_pixels.w / 2;
+ const py = (@as(i64, row) - body_y) * core.view().cell_pixels.h + core.view().cell_pixels.h / 2;
return pointAtGeometry(placed.geometry, placed.pixel_offset_y, raster.iw, raster.ih, raster.band_y, px, py, clamp_to_page);
}
@@ -3246,7 +3249,7 @@ pub fn highlightInput(
.hover_page = hover_page,
.hover_color = if (link_hover) core.theme().box else selection_color,
.selection_color = selection_color,
- .live = core.frontend.native_image_patches,
+ .live = core.view().frontend.native_image_patches,
};
}
@@ -3279,24 +3282,24 @@ fn stripAt(state: *State, view: Viewport) f64 {
pub fn verticalWheel(core: *pardes.Pardes, pane: *pardes.Pane, direction: i8) void {
if (comptime !enabled) return;
- if (!core.frontend.native_images) {
+ if (!core.view().frontend.native_images) {
// The text layer: a page a notch.
const state = pane.pdf orelse return;
if (stepPage(state, core.pdf_gpa, direction)) resetPageChrome(pane);
return;
}
const rows: u32 = @intCast(@max(1, config.wheel_rows));
- const pixels = scaledStep(core.cell_pixels.h, rows);
+ const pixels = scaledStep(core.view().cell_pixels.h, rows);
_ = scrollPane(core, pane, @as(f64, @floatFromInt(pixels)) * direction, true);
}
pub fn horizontalWheel(core: *pardes.Pardes, pane: *pardes.Pane, direction: i8) void {
if (comptime !enabled) return;
const state = pane.pdf orelse return;
- if (!core.frontend.native_images or state.fit != .height) return;
+ if (!core.view().frontend.native_images or state.fit != .height) return;
const placed = paneGeometry(core, pane) orelse return;
const cols: u32 = @intCast(@max(1, config.wheel_cols));
- _ = panPixels(state, placed, .horizontal, direction, scaledStep(core.cell_pixels.w, cols));
+ _ = panPixels(state, placed, .horizontal, direction, scaledStep(core.view().cell_pixels.w, cols));
}
pub fn draw(
@@ -3310,7 +3313,7 @@ pub fn draw(
rail: *pardes.Region,
) bool {
if (comptime !enabled) return false;
- if (!core.frontend.native_images or rect.h <= pane.tag_rows) return false;
+ if (!core.view().frontend.native_images or rect.h <= pane.tag_rows) return false;
const state = pane.pdf orelse return false;
const view = paneViewport(core, pane) orelse return false;
const key = TintKey{ .mode = state.tint, .colors = tintColors(core) };
@@ -3321,7 +3324,7 @@ pub fn draw(
const shown = stripAt(state, view);
state.document_scroll_y = shown;
defer state.document_scroll_y = state.drawn_y;
- if (pane_id == core.active) core.frames.scroll = @floatCast(shown);
+ if (pane_id == core.view().active) core.frames.scroll = @floatCast(shown);
defer {
core.frames.landed +|= state.landed;
state.landed = 0;