@matheusbsbs / matheus-bagliano / commits / 314c30936f
Fork 0

[PATCH] gitk: Handle MouseWheel events on Windows

Windows, unlike X-Windows, sends mousewheel events by default to the window that has keyboard focus and uses the MouseWheel event to do so. The window to be scrolled must be able to take focus, but gitk's panels are disabled so cannot take focus. For all these reasons, a different design is needed to use the mousewheel on Windows. The approach here is to bind the mousewheel events to the top level window and redirect them based upon the current mouse position. Signed-off-by: Mark Levedahl <mdl123@verizon.net> Signed-off-by: Paul Mackerras <paulus@samba.org>

Mark Levedahl committed Aug 7, 2007 at 21:40 UTC 314c30936f505f70534c619a48d99afb93451cb2
1 file changed +25 -2
gitk
+25 -2
@@ -823,8 +823,13 @@ proc makewindow {} {
823 pack .ctop -fill both -expand 1
824 bindall <1> {selcanvline %W %x %y}
825 #bindall <B1-Motion> {selcanvline %W %x %y}
826 - bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
827 - bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
826 + if {[tk windowingsystem] == "win32"} {
827 + bind . <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D }
828 + bind $ctext <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D ; break }
829 + } else {
830 + bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
831 + bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
832 + }
833 bindall <2> "canvscan mark %W %x %y"
834 bindall <B2-Motion> "canvscan dragto %W %x %y"
835 bindkey <Home> selfirstline
@@ -927,6 +932,24 @@ proc makewindow {} {
932 -command {flist_hl 1}
933 }
934
935 +# Windows sends all mouse wheel events to the current focused window, not
936 +# the one where the mouse hovers, so bind those events here and redirect
937 +# to the correct window
938 +proc windows_mousewheel_redirector {W X Y D} {
939 + global canv canv2 canv3
940 + set w [winfo containing -displayof $W $X $Y]
941 + if {$w ne ""} {
942 + set u [expr {$D < 0 ? 5 : -5}]
943 + if {$w == $canv || $w == $canv2 || $w == $canv3} {
944 + allcanvs yview scroll $u units
945 + } else {
946 + catch {
947 + $w yview scroll $u units
948 + }
949 + }
950 + }
951 +}
952 +
953 # mouse-2 makes all windows scan vertically, but only the one
954 # the cursor is in scans horizontally
955 proc canvscan {op w x y} {