From: Mark Levedahl Date: Wed, 8 Aug 2007 01:40:35 +0000 (-0400) Subject: [PATCH] gitk: Handle MouseWheel events on Windows X-Git-Tag: v1.5.3-rc5~24^2~4 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=314c30936f505f70534c619a48d99afb93451cb2;p=git.git [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 Signed-off-by: Paul Mackerras --- diff --git a/gitk b/gitk index 32206a68f..900038323 100755 --- a/gitk +++ b/gitk @@ -823,8 +823,13 @@ proc makewindow {} { pack .ctop -fill both -expand 1 bindall <1> {selcanvline %W %x %y} #bindall {selcanvline %W %x %y} - bindall "allcanvs yview scroll -5 units" - bindall "allcanvs yview scroll 5 units" + if {[tk windowingsystem] == "win32"} { + bind . { windows_mousewheel_redirector %W %X %Y %D } + bind $ctext { windows_mousewheel_redirector %W %X %Y %D ; break } + } else { + bindall "allcanvs yview scroll -5 units" + bindall "allcanvs yview scroll 5 units" + } bindall <2> "canvscan mark %W %x %y" bindall "canvscan dragto %W %x %y" bindkey selfirstline @@ -927,6 +932,24 @@ proc makewindow {} { -command {flist_hl 1} } +# 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 + } + } + } +} + # mouse-2 makes all windows scan vertically, but only the one # the cursor is in scans horizontally proc canvscan {op w x y} {