]> git.ipfire.org Git - thirdparty/git.git/commitdiff
gitk: update win32 scrolling for Tk 8.6 / TIP 171
authorMark Levedahl <mlevedahl@gmail.com>
Sat, 6 Jul 2024 15:08:32 +0000 (11:08 -0400)
committerMark Levedahl <mlevedahl@gmail.com>
Thu, 17 Jul 2025 03:01:51 +0000 (23:01 -0400)
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>
gitk

diff --git a/gitk b/gitk
index 56eb1ec4e64ef995ff42aacfa133d50e4922e031..124e39c519f5289fdf1562ae68df5e904abaedc3 100755 (executable)
--- a/gitk
+++ b/gitk
@@ -2268,9 +2268,9 @@ proc bind_mousewheel {} {
     global canv cflist ctext
     bindall <MouseWheel> {allcanvs yview scroll [scrollval %D] units}
     bindall <Shift-MouseWheel> break
-    bind $ctext <MouseWheel> {$ctext yview scroll [scrollval %D] units}
-    bind $ctext <Shift-MouseWheel> {$ctext xview scroll [scrollval %D] units}
-    bind $cflist <MouseWheel> {$cflist yview scroll [scrollval %D] units}
+    bind $ctext <MouseWheel> {$ctext yview scroll [scrollval %D 2] units}
+    bind $ctext <Shift-MouseWheel> {$ctext xview scroll [scrollval %D 2] units}
+    bind $cflist <MouseWheel> {$cflist yview scroll [scrollval %D 2] units}
     bind $cflist <Shift-MouseWheel> break
 }
 
@@ -2293,6 +2293,7 @@ proc makewindow {} {
     global fprogitem fprogcoord lastprogupdate progupdatepending
     global rprogitem rprogcoord rownumsel numcommits
     global worddiff
+    global scroll_D0
 
     # The "mc" arguments here are purely so that xgettext
     # sees the following string as needing to be translated
@@ -2709,10 +2710,11 @@ proc makewindow {} {
 
     pack .ctop -fill both -expand 1
     bindall <1> {selcanvline %W %x %y}
-    #bindall <B1-Motion> {selcanvline %W %x %y}
+
+    #Mouse / touchpad scrolling
     if {[tk windowingsystem] == "win32"} {
-        bind . <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D }
-        bind $ctext <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D ; break }
+        set scroll_D0 120
+        bind_mousewheel
     } elseif {[tk windowingsystem] == "x11"} {
         bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
         bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
@@ -2873,24 +2875,6 @@ proc makewindow {} {
     $diff_menu configure -tearoff 0
 }
 
-# Windows sends all mouse wheel events to the current focused window, not
-# the one where the mouse hovers, so bind those events here and redirect
-# to the correct window
-proc windows_mousewheel_redirector {W X Y D} {
-    global canv canv2 canv3
-    set w [winfo containing -displayof $W $X $Y]
-    if {$w ne ""} {
-        set u [expr {$D < 0 ? 5 : -5}]
-        if {$w == $canv || $w == $canv2 || $w == $canv3} {
-            allcanvs yview scroll $u units
-        } else {
-            catch {
-                $w yview scroll $u units
-            }
-        }
-    }
-}
-
 # Update row number label when selectedline changes
 proc selectedline_change {n1 n2 op} {
     global selectedline rownumsel