gitk: update win32 scrolling for Tk 8.6 / TIP 171

gitk on win32 binds windows_mousewheel_redirector to all MouseWheel events in the main window. This proc determines the widget under the cursor, then determines what scroll command to give, possibly none, and issues scroll commands to the widget. The top panes get only vertical scroll events, as does the lower right Patch/Tree pane. All others get both vertical and horizontal events. These are all hard coded at +/- five lines. We now have common MouseWheel event bindings that follow user preferences for the scrolling amount, bind for only the five main display widgets, and leave the other gui elements untouched. Let's use this instead. With the scrolling preference set at 5, the users should not notice much, if any, difference. Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>

Mark Levedahl committed Jul 6, 2024 at 11:08 UTC 61c74d062bd9fd35c6f9a17b488abce88d560566
1 file changed +8 -24
gitk
+8 -24
@@ -2268,9 +2268,9 @@ proc bind_mousewheel {} {
2268 global canv cflist ctext
2269 bindall <MouseWheel> {allcanvs yview scroll [scrollval %D] units}
2270 bindall <Shift-MouseWheel> break
2271 - bind $ctext <MouseWheel> {$ctext yview scroll [scrollval %D] units}
2272 - bind $ctext <Shift-MouseWheel> {$ctext xview scroll [scrollval %D] units}
2273 - bind $cflist <MouseWheel> {$cflist yview scroll [scrollval %D] units}
2271 + bind $ctext <MouseWheel> {$ctext yview scroll [scrollval %D 2] units}
2272 + bind $ctext <Shift-MouseWheel> {$ctext xview scroll [scrollval %D 2] units}
2273 + bind $cflist <MouseWheel> {$cflist yview scroll [scrollval %D 2] units}
2274 bind $cflist <Shift-MouseWheel> break
2275 }
2276
@@ -2293,6 +2293,7 @@ proc makewindow {} {
2293 global fprogitem fprogcoord lastprogupdate progupdatepending
2294 global rprogitem rprogcoord rownumsel numcommits
2295 global worddiff
2296 + global scroll_D0
2297
2298 # The "mc" arguments here are purely so that xgettext
2299 # sees the following string as needing to be translated
@@ -2709,10 +2710,11 @@ proc makewindow {} {
2710
2711 pack .ctop -fill both -expand 1
2712 bindall <1> {selcanvline %W %x %y}
2712 - #bindall <B1-Motion> {selcanvline %W %x %y}
2713 +
2714 + #Mouse / touchpad scrolling
2715 if {[tk windowingsystem] == "win32"} {
2714 - bind . <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D }
2715 - bind $ctext <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D ; break }
2716 + set scroll_D0 120
2717 + bind_mousewheel
2718 } elseif {[tk windowingsystem] == "x11"} {
2719 bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
2720 bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
@@ -2873,24 +2875,6 @@ proc makewindow {} {
2875 $diff_menu configure -tearoff 0
2876 }
2877
2876 -# Windows sends all mouse wheel events to the current focused window, not
2877 -# the one where the mouse hovers, so bind those events here and redirect
2878 -# to the correct window
2879 -proc windows_mousewheel_redirector {W X Y D} {
2880 - global canv canv2 canv3
2881 - set w [winfo containing -displayof $W $X $Y]
2882 - if {$w ne ""} {
2883 - set u [expr {$D < 0 ? 5 : -5}]
2884 - if {$w == $canv || $w == $canv2 || $w == $canv3} {
2885 - allcanvs yview scroll $u units
2886 - } else {
2887 - catch {
2888 - $w yview scroll $u units
2889 - }
2890 - }
2891 - }
2892 -}
2893 -
2878 # Update row number label when selectedline changes
2879 proc selectedline_change {n1 n2 op} {
2880 global selectedline rownumsel