zhengqunkoo avatar

fbpdf

0 subscribers
CRoffMakefile

A small framebuffer pdf, djvu, epub, xps, and cbz viewer

Created Feb 2020

BSD-3-Clause license

Live activities

This commit removes handling for sideways mouse scroll events in fbpdf. It was discovered that 'z-move' events actually report a signed value between -8 and +7, making the previous mapping to discrete sideways movements incorrect. This ensures more accurate mouse input processing.

The jmpmark function has been updated to consistently jump to both the saved page and the preserved vertical scroll position when using marks. Previously, the logic inconsistently toggle-jumped between different mark styles; this change ensures predictable document navigation by honoring the stored offset automatically. You can now reliably return to your exact reading location in the PDF.

Added mouse drag functionality to fbpdf, enabling direct interaction with the document view via mouse events. The implementation correctly processes mouse escape sequences, allowing users to scroll or navigate the viewport more intuitively. This update significantly improves the user experience for those using the PDF viewer with a mouse.

Updated key bindings in fbpdf to align more closely with common PDF viewer conventions, specifically matching Zathura-style controls (e.g., mapping arrow keys and navigation keys to consistent movement actions). This change makes navigation more intuitive for power users familiar with standard document viewer workflows. You'll now find more predictable behavior when using arrow keys and secondary navigation inputs.

Added support for PgUp, PgDn, Home, and End keys to improve document navigation in fbpdf. These keyboard shortcuts mapped to existing internal commands, allowing for a more intuitive reading experience. You can now jump through your documents faster directly from the keyboard.

This patch fixes a rendering bug in fbpdf.c where inverted colors were only applied correctly in the full redraw path, but not consistently when pages were loaded incrementally during multipage navigation. The inversion logic now runs at the point each page buffer is created, covering forward, backward, and initial loads with the same behavior. That keeps the display mode consistent as pages are reused and redrawn, so inverted viewing now works reliably across multipage browsing.

This change teaches fbpdf/fbdjvu to accept mouse events in addition to the existing keyboard controls, using a new dev-input-mice submodule and pthread-based mouse reader. The implementation forks so the parent process can keep reading terminal keyboard input while a mouse thread translates button and wheel events into the same vi-style commands the main loop already understands, then forwards everything through a pipe to the renderer. Build rules were updated to compile and link the mouse input code and pthread support. The practical effect is that navigating documents now works with both keyboard and mouse scrolling, without rewriting the core event loop.

This change updates printinfo() in fbpdf.c to query the current terminal width with ioctl(TIOCGWINSZ) and truncate the filename portion of the status line accordingly. Previously, long filenames could overflow the bottom status bar and push page or zoom information out of view. The result is a cleaner, more stable UI in constrained terminal sizes, especially when opening deeply nested or verbose file paths.

This change makes scrolling through multi-page documents cheaper by tracking how far the current window moved and only freeing, shifting, and rendering the page buffers that actually changed. Previously, loadpage() rebuilt the visible page set from scratch; now it preserves still-visible pages and allocates the page buffer array once during startup, which should reduce redraw work and memory churn. It also adjusts cleanup to free the full allocated buffer range safely. The practical effect is smoother scrolling and less wasted rendering when moving page by page.

This change updates fbpdf’s main loop to compute explicit vertical scroll limits and trigger page loads when the viewport reaches the top or bottom margin. Instead of clamping strictly within the current page, scrolling now attempts to move into the previous or next page using loadpage() and getcount(1), with sensible fallbacks when no adjacent page is available. The result is smoother navigation through PDFs, especially when reading continuously across page boundaries.

This change fixes a small but meaningful edge case in fbpdf.c where the previous zoom value could be zero when recalculating scroll position after a zoom operation. By clamping the old zoom to a new MINZOOM floor before doing the division, the code avoids a potential crash or undefined behavior while preserving the existing zoom bounds. The practical effect is safer, more predictable zoom handling.

This change updates printinfo() in fbpdf.c to position the cursor on the last screen row before rendering the status line, instead of always jumping to the top-left corner. That keeps the file/page/zoom overlay anchored at the bottom where it behaves more like a conventional status bar and is less likely to interfere with page content. The practical effect is a cleaner reading experience with persistent info shown in a less intrusive place.

This change replaces the single-page render buffer with an array of page buffers and updates drawing logic to stitch multiple rendered pages into the viewport. loadpage() now loads up to two consecutive pages, handles end-of-document bounds, and applies inversion across all loaded pages, while margin detection continues to use the primary page. The result is groundwork for smoother multi-page viewing with fewer redraw constraints when navigating near page boundaries.

This change introduces a persistent info/status display flag in fbpdf and redraws the document metadata automatically after each render when it’s enabled. The old i key behavior that printed info on demand has been replaced with Ctrl+N, which toggles the display on and off, and the unconditional startup print was removed. In practice, this makes navigation smoother by keeping status output consistent while still letting users hide it when they want a cleaner view.

This change replaces the previous zoom command handling with direct keybindings for zooming in, zooming out, and resetting to the default zoom level. In fbpdf.c, + and - now increment or decrement the current zoom value before re-rendering the page, while = restores zoom_def, and the older Z, z, and w paths are removed. The result is a simpler and more discoverable zoom workflow with clearer runtime behavior.

This updates the r key handling in fbpdf.c to rotate the current page by a fixed 90 degrees each time, instead of reading an arbitrary count value. The change makes rotation state consistent and removes dependence on numeric input for a common viewing action. In practice, page rotation is now simpler and more predictable for users navigating PDFs.

This change defines handling for the g key in fbpdf.c, setting a mark and loading page 1 through the existing getcount/loadpage path. It mirrors the surrounding navigation behavior, including restoring the previous scroll row if the page load fails. In practice, users now have a quick, predictable shortcut for returning to the start of a document.

This change teaches the input loop to recognize ANSI escape sequences for the arrow keys and map them onto the viewer’s existing vim-style movement commands. Instead of requiring only h/j/k/l navigation, users can now use standard arrow keys without changing the rest of the command handling logic. The practical effect is more intuitive keyboard navigation with minimal code-path disruption.

This change adjusts the Makefile for the fbpdf target to link MuPDF's transitive libraries directly, including zlib, FreeType, HarfBuzz, jbig2dec, OpenJPEG, and JPEG. That usually matters on systems or toolchains that don't automatically pull in dependent libraries, where linking can fail even though MuPDF itself is installed. In practice, this should make PDF support compile more consistently and reduce environment-specific build breakage.

Wrote a comprehensive UNIX man page (fbpdf.1) for the framebuffer PDF and djvu viewer. The documentation covers command-line arguments such as zoom, rotation, and starting page, while significantly documenting the extensive key-binding commands in a dedicated table format. This finally provides users with immediate, offline access to tool usage and keymap references without needing to check the source code.