From: Mark Levedahl Date: Fri, 6 Jun 2025 01:45:22 +0000 (-0400) Subject: gitk: mousewheel scrolling functions for Tk 8.6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=429bbf449c4ce43330e16422070080c314f8b8c4;p=thirdparty%2Fgit.git gitk: mousewheel scrolling functions for Tk 8.6 gitk supports scrolling of 5 windows, but does this differently on the aqua, x11, and win32 platforms as Tk provides different events on each. TIP 171 removes some differences on win32 while altering the required bindings on x11. TIP 474, which is in Tk 8.7 and later, finally unifies all platforms on using common MouseWheel bindings. Importantly for now, TIP 171 causes delivery of MouseWheel events to the widget under the mouse cursor on win32, eliminating the need for completely different bindings on win32. Let's make some common functions to unify as much as we can in Tk 8.6. Examining the platforms shows that the default platform scrolling is overridden differently on the 3 platforms, and the nominal amount of motion achieved per mouse wheel "click" is different. win32 nominally makes everything move 5 lines per click, aqua 1 line per click, and x11 is a mixture. Part of this is due to win32 overriding all scroll events, while x11 and aqua override smaller sets. Also, note that the text widgets (the lower two panes) always scroll by 2-3 lines when given a smaller scroll amount, while the upper three canvas objects follow the requested scrolling value more accurately. First, let's have a common routine to calculate the scroll value to give to a widget in an event. This accounts for the user preference, the scale of the %D (delta) value given by the event (120 on win32, 1 on aqua, assumed 1 on x11), and must always be integer. Include negation as by convention the screen moves opposite to the MouseWheel delta. Allow setting an offset value to account for the larger minimum scrolling of text widgets. Second, let's have a common declaration of MouseWheel event bindings, as those are shared by all in Tcl9, and by aqua/win32 earlier. Bind all five display windows here. Note that the Patch/Tree widget (cflist) cannot scroll horizontally. Signed-off-by: Mark Levedahl --- diff --git a/gitk b/gitk index 0596e4382a..56eb1ec4e6 100755 --- a/gitk +++ b/gitk @@ -2259,6 +2259,21 @@ proc makedroplist {w varname args} { return $gm } +proc scrollval {D {koff 0}} { + global kscroll scroll_D0 + return [expr int(-($D / $scroll_D0) * max(1, $kscroll-$koff))] +} + +proc bind_mousewheel {} { + global canv cflist ctext + bindall {allcanvs yview scroll [scrollval %D] units} + bindall break + bind $ctext {$ctext yview scroll [scrollval %D] units} + bind $ctext {$ctext xview scroll [scrollval %D] units} + bind $cflist {$cflist yview scroll [scrollval %D] units} + bind $cflist break +} + proc makewindow {} { global canv canv2 canv3 linespc charspc ctext cflist cscroll global tabstop