Skip to content

Fixed Ctrl+Scroll zoom not working with cursor-centered focal point#22

Open
ikabrain wants to merge 3 commits into
kaurmanjot20:mainfrom
ikabrain:fix/ctrl-scroll-zoom
Open

Fixed Ctrl+Scroll zoom not working with cursor-centered focal point#22
ikabrain wants to merge 3 commits into
kaurmanjot20:mainfrom
ikabrain:fix/ctrl-scroll-zoom

Conversation

@ikabrain

@ikabrain ikabrain commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

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. GtkEventControllerScroll in GTK 4 carries no pointer coordinates by design: get_position() returns False with NaN values on every scroll event. The existing surface-to-widget coordinate translation chain in on_scroll was 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 GtkEventControllerMotion that tracks the last known cursor position in widget-local coordinates. on_scroll reads from that directly, which gives _zoom_around_focal() the correct focal point on every event. The now-unused Graphene import and its gi.require_version call are removed as well.

Changes

  • Added GtkEventControllerMotion to PDFView.__init__, connected to a new on_pointer_motion handler that stores the last cursor position as self._pointer_pos in widget-local coordinates.
  • Replaced the dead get_position() / compute_point() translation chain in on_scroll with a one-liner that reads self._pointer_pos, falling back to the viewport center only when no pointer event has been recorded yet.
  • Removed gi.require_version('Graphene', '1.0') and Graphene from the gi.repository import in ui/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.

Copilot AI review requested due to automatic review settings June 5, 2026 15:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/inlinea/ui/pdf_view.py
Comment thread src/inlinea/ui/pdf_view.py
Comment thread src/inlinea/ui/pdf_view.py
@ikabrain ikabrain requested a review from Copilot June 5, 2026 15:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread src/inlinea/ui/pdf_view.py
Comment thread src/inlinea/ui/pdf_view.py
Comment thread src/inlinea/ui/pdf_view.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants