git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] gitk - Handle MouseWheel events on Windows

From
Mark Levedahl <mdl123@verizon.net>
Date
Aug 8, 2007, 01:40 UTC
Message-ID
<11865372381125-git-send-email-mdl123@verizon.net>
In-Reply-To
<11865372352543-git-send-email-mdl123@verizon.net>

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>
---

This version is a slight clean-up of the original, collapsing two if/else blocks into a single conditional assignment.

 gitk |   27 +++++++++++++++++++++++++--
 1 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/gitk b/gitk
index 84f5ee4..eb2b194 100755
--- a/gitk
+++ b/gitk
@@ -823,8 +823,13 @@ proc makewindow {} {
     pack .ctop -fill both -expand 1
     bindall <1> {selcanvline %W %x %y}
     #bindall <B1-Motion> {selcanvline %W %x %y}
-    bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
-    bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
+    if {[tk windowingsystem] == "win32"} {
+	bind . <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D }
+	bind $ctext <MouseWheel> { windows_mousewheel_redirector %W %X %Y %D ; break }
+    } else {
+	bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
+	bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
+    }
     bindall <2> "canvscan mark %W %x %y"
     bindall <B2-Motion> "canvscan dragto %W %x %y"
     bindkey <Home> selfirstline
@@ -918,6 +923,24 @@ proc makewindow {} {
 	-command rmbranch
 }

+# 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} {
--
1.5.3.rc4.25.gade7b9
Previous: Mark LevedahlNext: Mark Levedahl
Message 4 of 6 in “gitk - enable selected patch text on Windows”
  1. gitk - enable selected patch text on WindowsMark Levedahl, Aug 6, 2007
  2. gitk - Handle MouseWheel events on WindowsMark Levedahl, Aug 6, 2007
  3. gitk - enable selected patch text on WindowsMark Levedahl, Aug 8, 2007
  4. gitk - Handle MouseWheel events on WindowsMark Levedahl, Aug 8, 2007
  5. Mark LevedahlAug 11, 2007
  6. Steffen ProhaskaAug 11, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.