diff options
author | csaba <csaba> | 2023-11-30 20:18:48 (GMT) |
---|---|---|
committer | csaba <csaba> | 2023-11-30 20:18:48 (GMT) |
commit | 226daa1f8ab5c7237b47cc49d4b6d29fc10f6948 (patch) | |
tree | 4e08ebf8d4350d5ca889a89df5c270d64a1e0784 /library/scrlbar.tcl | |
parent | 56396a8248cd1a56511782b5ad977660c84bd23f (diff) | |
download | tk-226daa1f8ab5c7237b47cc49d4b6d29fc10f6948.zip tk-226daa1f8ab5c7237b47cc49d4b6d29fc10f6948.tar.gz tk-226daa1f8ab5c7237b47cc49d4b6d29fc10f6948.tar.bz2 |
Minimize the number of artifacts caused by intermixed <MouseWheel> and <Shift-MouseWheel> events triggered by two-finger gestures.
Diffstat (limited to 'library/scrlbar.tcl')
-rw-r--r-- | library/scrlbar.tcl | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/library/scrlbar.tcl b/library/scrlbar.tcl index c18d4a8..35ff251 100644 --- a/library/scrlbar.tcl +++ b/library/scrlbar.tcl @@ -129,10 +129,19 @@ bind Scrollbar <<LineEnd>> { } } +bind Scrollbar <Enter> {+ + set tk::Priv(xEvents) 0; set tk::Priv(yEvents) 0 +} bind Scrollbar <MouseWheel> { - tk::ScrollByUnits %W hv %D -40.0 + tk::ScrollByUnits %W vh %D -40.0 } bind Scrollbar <Option-MouseWheel> { + tk::ScrollByUnits %W vh %D -12.0 +} +bind Scrollbar <Shift-MouseWheel> { + tk::ScrollByUnits %W hv %D -40.0 +} +bind Scrollbar <Shift-Option-MouseWheel> { tk::ScrollByUnits %W hv %D -12.0 } @@ -303,7 +312,7 @@ proc ::tk::ScrollEndDrag {w x y} { # Arguments: # w - The scrollbar widget. # orient - Which kinds of scrollbars this applies to: "h" for -# horizontal, "v" for vertical, "hv" for both. +# horizontal, "v" for vertical, "hv" or "vh" for both. # amount - How many units to scroll: typically 1 or -1. proc ::tk::ScrollByUnits {w orient amount {factor 1.0}} { @@ -312,6 +321,21 @@ proc ::tk::ScrollByUnits {w orient amount {factor 1.0}} { [string index [$w cget -orient] 0] $orient] < 0)} { return } + + if {[string length $orient] == 2 && $factor != 1.0} { + # Count both the <MouseWheel> and <Shift-MouseWheel> + # events, and ignore the non-dominant ones + + variable ::tk::Priv + set axis [expr {[string index $orient 0] eq "h" ? "x" : "y"}] + incr Priv(${axis}Events) + if {($Priv(xEvents) + $Priv(yEvents) > 10) && + ($axis eq "x" && $Priv(xEvents) < $Priv(yEvents) || + $axis eq "y" && $Priv(yEvents) < $Priv(xEvents))} { + return + } + } + set info [$w get] if {[llength $info] == 2} { uplevel #0 $cmd scroll [expr {$amount/$factor}] units |