Skip to content

Fix mouse-wheel scroll-up on Tk 9 - #76

Merged
JoshCLWren merged 2 commits into
mainfrom
fix/mouse-wheel-tk9
Oct 18, 2026
Merged

JoshCLWren merged 2 commits into
mainfrom
fix/mouse-wheel-tk9

Conversation

@JoshCLWren

Copy link
Copy Markdown
Owner

Problem

Mouse-wheel scroll up did nothing and every notch scrolled/advanced down, in the packaged builds. Logs from a real run show it:

Mouse wheel delta=120  num=??  ->  Scroll by delta=216   # up, but offset increases
Mouse wheel delta=-120 num=??  ->  Scroll by delta=216

Tk 9 delivers <MouseWheel> on X11 with a +/-120 delta and reports the unused button substitution as the string "??". The old handler was:

if hasattr(event, "num") and event.num:      # "??" is truthy
    direction = -1 if event.num == 4 else 1  # "??" == 4 is False -> always 1 (down)

So every notch decoded as scroll-down; scroll-up was unreachable. Tk 8.6 delivered <Button-4>/<Button-5> with a real int num, which is why source builds worked and packaged (Tk 9) builds did not.

Fix

  • _wheel_direction() reads delta first and only treats num as a button when it is actually 4 or 5.
  • _wheel_step() uses a finer step (1/10 of the canvas height, min 40px) so the wheel is smoother than the arrow-key step.

Testing

  • Regression tests cover the real Tk 9 num="??" for scroll-up, scroll-down, prev-page navigation, plus the ignored-event case.
  • bash scripts/lint.sh clean; xvfb-run pytest: 562 passed, coverage 96.38%.

Tk 9 delivers <MouseWheel> on X11 with a +/-120 delta and reports the unused button substitution as the string "??", which is truthy. The old handler took the button branch for any truthy num, then treated "??" as Button-5, so every notch scrolled down and scrolling up was impossible in the packaged (Tk 9) builds. Decode the delta first and only honour num when it is truly 4 or 5, and use a finer wheel step for smoother scrolling.

Add regression tests covering the Tk 9 "??" num for scroll up, scroll down, prev-page navigation, and the ignored event case.
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 27bed3f1-7b88-46ff-af6e-3b9ea5d9433e
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Drive a genuine <MouseWheel> event through Tk (num resolves to the string "??" under Tk 9) so the scroll direction is exercised the way the packaged app really receives it, not just via a mocked num=0.
@JoshCLWren
JoshCLWren merged commit 66a279b into main Oct 18, 2026
10 checks passed
@JoshCLWren
JoshCLWren deleted the fix/mouse-wheel-tk9 branch October 18, 2026 03:57
@JoshCLWren JoshCLWren mentioned this pull request Oct 18, 2026
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.

1 participant