diff --git a/build.zig b/build.zig index 84d13a9..dc04d54 100755 --- a/build.zig +++ b/build.zig @@ -21,6 +21,11 @@ pub fn build(b: *std.Build) void { defer make_args.deinit(); make_args.append("make") catch unreachable; + + // use as many cores as possible by default (like zig) I dont know how to check for j arg + const cpu_count = std.Thread.getCpuCount() catch 1; + make_args.append(b.fmt("-j{d}", .{cpu_count})) catch unreachable; + make_args.append("-C") catch unreachable; make_args.append("deps/mupdf") catch unreachable; diff --git a/src/Context.zig b/src/Context.zig index c9a321a..1259c27 100644 --- a/src/Context.zig +++ b/src/Context.zig @@ -195,6 +195,7 @@ pub const Context = struct { }, .file_changed => { try self.pdf_handler.reloadDocument(); + // we could remove the current page from the cache here self.reload_page = true; }, } @@ -251,7 +252,6 @@ pub const Context = struct { } pub fn drawCurrentPage(self: *Self, win: vaxis.Window) !void { - self.pdf_handler.commitReload(); if (self.current_page == null or self.reload_page) { const winsize = try vaxis.Tty.getWinsize(self.tty.fd); const pix_per_col = try std.math.divCeil(u16, win.screen.width_pix, win.screen.width); diff --git a/src/PdfHandler.zig b/src/PdfHandler.zig index fe3b2e5..4ea7db5 100644 --- a/src/PdfHandler.zig +++ b/src/PdfHandler.zig @@ -16,7 +16,6 @@ pub const ScrollDirection = enum { Up, Down, Left, Right }; allocator: std.mem.Allocator, ctx: [*c]c.fz_context, doc: [*c]c.fz_document, -temp_doc: ?[*c]c.fz_document, total_pages: u16, current_page_number: u16, path: []const u8, @@ -62,7 +61,6 @@ pub fn init( .allocator = allocator, .ctx = ctx, .doc = doc, - .temp_doc = null, .total_pages = total_pages, .current_page_number = current_page_number, .path = path, @@ -76,36 +74,27 @@ pub fn init( } pub fn deinit(self: *Self) void { - if (self.temp_doc) |doc| c.fz_drop_document(self.ctx, doc); c.fz_drop_document(self.ctx, self.doc); c.fz_drop_context(self.ctx); } pub fn reloadDocument(self: *Self) !void { - if (self.temp_doc) |doc| { + if (self.doc) |doc| { c.fz_drop_document(self.ctx, doc); - self.temp_doc = null; + self.doc = null; } - self.temp_doc = c.fz_open_document(self.ctx, self.path.ptr) orelse { + self.doc = c.fz_open_document(self.ctx, self.path.ptr) orelse { std.debug.print("Failed to reload document\n", .{}); return PdfError.FailedToOpenDocument; }; - self.total_pages = @as(u16, @intCast(c.fz_count_pages(self.ctx, self.temp_doc.?))); + self.total_pages = @as(u16, @intCast(c.fz_count_pages(self.ctx, self.doc.?))); if (self.current_page_number >= self.total_pages) { self.current_page_number = self.total_pages - 1; } } -pub fn commitReload(self: *Self) void { - if (self.temp_doc) |doc| { - c.fz_drop_document(self.ctx, self.doc); - self.doc = doc; - self.temp_doc = null; - } -} - pub fn renderPage( self: *Self, page_number: u16,