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 | |
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.
-rw-r--r-- | library/scrlbar.tcl | 28 | ||||
-rw-r--r-- | library/ttk/combobox.tcl | 5 | ||||
-rw-r--r-- | library/ttk/notebook.tcl | 34 | ||||
-rw-r--r-- | library/ttk/scrollbar.tcl | 12 | ||||
-rw-r--r-- | library/ttk/spinbox.tcl | 5 |
5 files changed, 76 insertions, 8 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 diff --git a/library/ttk/combobox.tcl b/library/ttk/combobox.tcl index 653102e..9756376 100644 --- a/library/ttk/combobox.tcl +++ b/library/ttk/combobox.tcl @@ -52,7 +52,10 @@ bind TCombobox <Triple-Button-1> { ttk::combobox::Press "3" %W %x %y } bind TCombobox <B1-Motion> { ttk::combobox::Drag %W %x } bind TCombobox <Motion> { ttk::combobox::Motion %W %x %y } -ttk::bindMouseWheel TCombobox [list ttk::combobox::Scroll %W] +ttk::bindMouseWheel TCombobox { ttk::combobox::Scroll %W } +bind TCombobox <Shift-MouseWheel> { + # Ignore the event +} bind TCombobox <<TraverseIn>> { ttk::combobox::TraverseIn %W } diff --git a/library/ttk/notebook.tcl b/library/ttk/notebook.tcl index 7097c45..d8ed23b 100644 --- a/library/ttk/notebook.tcl +++ b/library/ttk/notebook.tcl @@ -16,7 +16,21 @@ bind TNotebook <Control-ISO_Left_Tab> { ttk::notebook::CycleTab %W -1; break } } bind TNotebook <Destroy> { ttk::notebook::Cleanup %W } -ttk::bindMouseWheel TNotebook [list ttk::notebook::CycleTab %W] +bind TNotebook <Enter> { + set tk::Priv(xEvents) 0; set tk::Priv(yEvents) 0 +} +bind TNotebook <MouseWheel> { + ttk::notebook::CondCycleTab %W y %D -120.0 +} +bind TNotebook <Option-MouseWheel> { + ttk::notebook::CondCycleTab %W y %D -12.0 +} +bind TNotebook <Shift-MouseWheel> { + ttk::notebook::CondCycleTab %W x %D -120.0 +} +bind TNotebook <Shift-Option-MouseWheel> { + ttk::notebook::CondCycleTab %W x %D -12.0 +} # ActivateTab $nb $tab -- # Select the specified tab and set focus. @@ -75,6 +89,24 @@ proc ttk::notebook::CycleTab {w dir {factor 1.0}} { } } +# CondCycleTab -- +# Conditionally invoke the ttk::notebook::CycleTab proc. +# +proc ttk::notebook::CondCycleTab {w axis dir {factor 1.0}} { + # Count both the <MouseWheel> and <Shift-MouseWheel> + # events, and ignore the non-dominant ones + + variable ::tk::Priv + 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 + } + + CycleTab $w $dir $factor +} + # MnemonicTab $nb $key -- # Scan all tabs in the specified notebook for one with the # specified mnemonic. If found, returns path name of tab; diff --git a/library/ttk/scrollbar.tcl b/library/ttk/scrollbar.tcl index 6ad6e15..4f73f1f 100644 --- a/library/ttk/scrollbar.tcl +++ b/library/ttk/scrollbar.tcl @@ -17,10 +17,16 @@ bind TScrollbar <Button-2> { ttk::scrollbar::Jump %W %x %y } bind TScrollbar <B2-Motion> { ttk::scrollbar::Drag %W %x %y } bind TScrollbar <ButtonRelease-2> { ttk::scrollbar::Release %W %x %y } -# Redirect scrollwheel bindings to the scrollbar widget +# Copy the mouse wheel event bindings from Scrollbar to TScrollbar # -bind TScrollbar <MouseWheel> [bind Scrollbar <MouseWheel>] -bind TScrollbar <Option-MouseWheel> [bind Scrollbar <Option-MouseWheel>] +bind TScrollbar <Enter> { + set tk::Priv(xEvents) 0; set tk::Priv(yEvents) 0 +} +foreach event {<MouseWheel> <Option-MouseWheel> + <Shift-MouseWheel> <Shift-Option-MouseWheel>} { + bind TScrollbar $event [bind Scrollbar $event] +} +unset event proc ttk::scrollbar::Scroll {w n units} { set cmd [$w cget -command] diff --git a/library/ttk/spinbox.tcl b/library/ttk/spinbox.tcl index 9f002cd..5aca894 100644 --- a/library/ttk/spinbox.tcl +++ b/library/ttk/spinbox.tcl @@ -23,7 +23,10 @@ bind TSpinbox <Down> { event generate %W <<Decrement>> } bind TSpinbox <<Increment>> { ttk::spinbox::Spin %W +1 } bind TSpinbox <<Decrement>> { ttk::spinbox::Spin %W -1 } -ttk::bindMouseWheel TSpinbox [list ttk::spinbox::Spin %W] +ttk::bindMouseWheel TSpinbox { ttk::spinbox::Spin %W } +bind TSpinbox <Shift-MouseWheel> { + # Ignore the event +} ## Motion -- # Sets cursor. |