diff options
author | marc_culler <marc.culler@gmail.com> | 2023-12-11 02:28:43 (GMT) |
---|---|---|
committer | marc_culler <marc.culler@gmail.com> | 2023-12-11 02:28:43 (GMT) |
commit | 730e3b750ea3dfdd1e339bc82743ee4d4b9bffbd (patch) | |
tree | c891bd75c4bc34d13042ffae147599a11ce9ebab /library/scrlbar.tcl | |
parent | 8a1948af29ccf03658724cf589bdf9deb773911b (diff) | |
parent | fa30d6e92c313f3f6cfb3d1a9f99da4c04fe4022 (diff) | |
download | tk-730e3b750ea3dfdd1e339bc82743ee4d4b9bffbd.zip tk-730e3b750ea3dfdd1e339bc82743ee4d4b9bffbd.tar.gz tk-730e3b750ea3dfdd1e339bc82743ee4d4b9bffbd.tar.bz2 |
Merge implementation of TIP #684.
Diffstat (limited to 'library/scrlbar.tcl')
-rw-r--r-- | library/scrlbar.tcl | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/library/scrlbar.tcl b/library/scrlbar.tcl index 35ff251..283b7a2 100644 --- a/library/scrlbar.tcl +++ b/library/scrlbar.tcl @@ -144,6 +144,15 @@ bind Scrollbar <Shift-MouseWheel> { bind Scrollbar <Shift-Option-MouseWheel> { tk::ScrollByUnits %W hv %D -12.0 } +bind Scrollbar <TouchpadScroll> { + lassign [tk::PreciseScrollDeltas %D] deltaX deltaY + if {$deltaX != 0 && [%W cget -orient] eq "horizontal"} { + tk::ScrollbarScrollByPixels %W h $deltaX + } + if {$deltaY != 0 && [%W cget -orient] eq "vertical"} { + tk::ScrollbarScrollByPixels %W v $deltaY + } +} # tk::ScrollButtonDown -- # This procedure is invoked when a button is pressed in a scrollbar. @@ -304,6 +313,49 @@ proc ::tk::ScrollEndDrag {w x y} { set Priv(initPos) "" } +# ::tk::ScrollbarScrollByPixels -- +# This procedure tells the scrollbar's associated widget to scroll up +# or down by a given number of pixels. It only works with scrollbars +# because it uses the delta command. +# +# Arguments: +# w - The scrollbar widget. +# orient - Which kind of scrollbar this applies to: "h" for +# horizontal, "v" for vertical. +# amount - How many pixels to scroll. + +proc ::tk::ScrollbarScrollByPixels {w orient amount} { + set cmd [$w cget -command] + if {$cmd eq ""} { + return + } + set xyview [lindex [split $cmd] end] + if {$orient eq "v"} { + if {$xyview eq "xview"} { + return + } + set size [winfo height $w] + } + if {$orient eq "h"} { + if {$xyview eq "yview"} { + return + } + set size [winfo width $w] + } + + # The code below works with both the current and old syntax for + # the scrollbar get command. + + set info [$w get] + if {[llength $info] == 2} { + set first [lindex $info 0] + } else { + set first [lindex $info 2] + } + set pixels [expr {-$amount}] + uplevel #0 $cmd moveto [expr $first + [$w delta $pixels $pixels]] +} + # ::tk::ScrollByUnits -- # This procedure tells the scrollbar's associated widget to scroll up # or down by a given number of units. It notifies the associated widget |