Fixed Ctrl+Scroll zoom not working with cursor-centered focal point#22
Open
ikabrain wants to merge 3 commits into
Open
Fixed Ctrl+Scroll zoom not working with cursor-centered focal point#22ikabrain wants to merge 3 commits into
ikabrain wants to merge 3 commits into
Conversation
PyGObject returns (bool, float, float) from get_position(), not (float, float)!
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR simplifies Ctrl+scroll zoom focal point handling in the PDF view by removing Graphene/native coordinate transforms and instead tracking pointer position via a motion controller.
Changes:
- Remove Graphene GI dependency and related coordinate translation code.
- Track last pointer coordinates via
Gtk.EventControllerMotion. - Use tracked pointer position as the zoom focal point for Ctrl+scroll, falling back to viewport center.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ctrl+Scroll zoom in Inlinea has been broken since at least GTK 4 was adopted. Holding Ctrl and scrolling over a PDF produced a
ValueError: too many values to unpack (expected 2)on every single event, aborting the handler before the page had a chance to zoom. Because the traceback only surfaces when launching from a terminal rather than the desktop icon, most users would just see "Ctrl+Scroll does nothing" with no indication why.Digging into the crash revealed a second problem underneath: even if the unpack were patched, zoom still would not have been cursor-centered.
GtkEventControllerScrollin GTK 4 carries no pointer coordinates by design:get_position()returnsFalsewith NaN values on every scroll event. The existing surface-to-widget coordinate translation chain inon_scrollwas permanently dead code; the viewport-center fallback fired on every Ctrl+Scroll regardless of where the cursor was!This PR fixes both. The dead translation chain is replaced with a
GtkEventControllerMotionthat tracks the last known cursor position in widget-local coordinates.on_scrollreads from that directly, which gives_zoom_around_focal()the correct focal point on every event. The now-unusedGrapheneimport and itsgi.require_versioncall are removed as well.Changes
GtkEventControllerMotiontoPDFView.__init__, connected to a newon_pointer_motionhandler that stores the last cursor position asself._pointer_posin widget-local coordinates.get_position()/compute_point()translation chain inon_scrollwith a one-liner that readsself._pointer_pos, falling back to the viewport center only when no pointer event has been recorded yet.gi.require_version('Graphene', '1.0')andGraphenefrom thegi.repositoryimport inui/pdf_view.py; the translation chain was the only caller.Tested locally on Arch Linux (
python3 -m inlinea): Ctrl+Scroll zooms correctly and stays anchored to the cursor position. Plain scroll, header-bar zoom buttons, and pinch-to-zoom are all unaffected.