[PATCH] Hgk - add scroll by mouse wheel

Andrei Vermel avermel at mail.ru
Thu Jul 19 09:05:25 CDT 2007


> On MacOSX it works only in the diff and file panels. Scroll speed is OK.
Don't have a mac at hand, so can't do anything.

> It works well on Windows, only problem I found is it is ignored when 
> hovering the author or date panels right to the graph panel.

This is fixed in the patch below.

Andrei

# HG changeset patch
# User Andrei Vermel <avermel at mail.ru>
# Date 1184736602 -14400
# Node ID 6068b7fe665aa011c222375c82740f135ebba944
# Parent  42ebb931a74d52384428b7a015cb64dc6b534724
hgk: add scroll by wheel

diff -r 42ebb931a74d -r 6068b7fe665a contrib/hgk
--- a/contrib/hgk Thu Jul 19 18:01:23 2007 +0400
+++ b/contrib/hgk Wed Jul 18 09:30:02 2007 +0400
@@ -4,6 +4,41 @@
 # This program is free software; it may be used, copied, modified
 # and distributed under the terms of the GNU General Public Licence,
 # either version 2, or (at your option) any later version.
+
+proc wheelEvent { x y delta } {
+
+    # Find out what's the widget we're on
+    set act 0
+    set widget [winfo containing $x $y]
+    if { $widget == ".ctop.top.clist.canv2" ||  $widget == ".ctop.top.clist.canv3" } {
+       set widget ".ctop.top.clist.canv"
+    }
+
+    if {$widget != ""} {
+        # Make sure we've got a vertical scrollbar for this widget
+        if {[catch "$widget cget -yscrollcommand" cmd]} return
+
+        if {$cmd != ""} {
+            # Find out the scrollbar widget we're using
+            set scroller [lindex $cmd 0]
+
+            # Make sure we act
+            set act 1
+        }
+    }
+
+    if {$act == 1} {
+        # Now we know we have to process the wheel mouse event
+        set xy [$widget yview]
+        set factor [expr [lindex $xy 1]-[lindex $xy 0]]
+
+        # Make sure we activate the scrollbar's command
+        set cmd "[$scroller cget -command] scroll [expr -($delta/abs($delta))*int(pow(abs($delta/120), 3))] units"
+        eval $cmd
+    }
+}
+
+bind all <MouseWheel> "+wheelEvent %X %Y %D"
 
 proc gitdir {} {
     global env



-------------- next part --------------
A non-text attachment was scrubbed...
Name: hgk_wheel.diff
Type: application/octet-stream
Size: 1675 bytes
Desc: not available
Url : http://selenic.com/pipermail/mercurial-devel/attachments/20070719/56d0198c/attachment-0001.obj 


More information about the Mercurial-devel mailing list