Skip to content

Commit

Permalink
Made sure that the TouchpadScroll event bindings won't polluate the g…
Browse files Browse the repository at this point in the history
…lobal namespace (thanks to Rolf Ade for triggering this improvement).
  • Loading branch information
csaba committed Jul 15, 2024
1 parent ed381a3 commit 6c40142
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
12 changes: 6 additions & 6 deletions library/listbox.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# tk::Priv elements used in this file:
#
# afterId - Token returned by "after" for autoscanning.
# listboxPrev - The last element to be selected or deselected
# listboxPrev - The last element to be selected or deselected
# during a selection operation.
# listboxSelection - All of the items that were selected before the
# current selection operation (such as a mouse
Expand Down Expand Up @@ -191,12 +191,12 @@ bind Listbox <TouchpadScroll> {
if {%# %% 5 != 0} {
return
}
lassign [tk::PreciseScrollDeltas %D] deltaX deltaY
if {$deltaX != 0} {
%W xview scroll [expr {-$deltaX}] units
lassign [tk::PreciseScrollDeltas %D] tk::Priv::deltaX tk::Priv::deltaY
if {$tk::Priv::deltaX != 0} {
%W xview scroll [expr {-$tk::Priv::deltaX}] units
}
if {$deltaY != 0} {
%W yview scroll [expr {-$deltaY}] units
if {$tk::Priv::deltaY != 0} {
%W yview scroll [expr {-$tk::Priv::deltaY}] units
}
}

Expand Down
10 changes: 5 additions & 5 deletions library/scrlbar.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ 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
lassign [tk::PreciseScrollDeltas %D] tk::Priv::deltaX tk::Priv::deltaY
if {$tk::Priv::deltaX != 0 && [%W cget -orient] eq "horizontal"} {
tk::ScrollbarScrollByPixels %W h $tk::Priv::deltaX
}
if {$deltaY != 0 && [%W cget -orient] eq "vertical"} {
tk::ScrollbarScrollByPixels %W v $deltaY
if {$tk::Priv::deltaY != 0 && [%W cget -orient] eq "vertical"} {
tk::ScrollbarScrollByPixels %W v $tk::Priv::deltaY
}
}

Expand Down
10 changes: 5 additions & 5 deletions library/text.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,12 @@ bind Text <Shift-Option-MouseWheel> {
tk::MouseWheel %W x [tk::ScaleNum %D] -1.2 pixels
}
bind Text <TouchpadScroll> {
lassign [tk::PreciseScrollDeltas %D] deltaX deltaY
if {$deltaX != 0} {
%W xview scroll [tk::ScaleNum [expr {-$deltaX}]] pixels
lassign [tk::PreciseScrollDeltas %D] tk::Priv::deltaX tk::Priv::deltaY
if {$tk::Priv::deltaX != 0} {
%W xview scroll [tk::ScaleNum [expr {-$tk::Priv::deltaX}]] pixels
}
if {$deltaY != 0} {
%W yview scroll [tk::ScaleNum [expr {-$deltaY}]] pixels
if {$tk::Priv::deltaY != 0} {
%W yview scroll [tk::ScaleNum [expr {-$tk::Priv::deltaY}]] pixels
}
}

Expand Down
6 changes: 3 additions & 3 deletions library/ttk/combobox.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ bind TCombobox <Shift-MouseWheel> {
# Ignore the event
}
bind TCombobox <TouchpadScroll> {
lassign [tk::PreciseScrollDeltas %D] deltaX deltaY
lassign [tk::PreciseScrollDeltas %D] tk::Priv::deltaX tk::Priv::deltaY
# TouchpadScroll events fire about 60 times per second.
if {$deltaY != 0 && %# %% 15 == 0} {
ttk::combobox::Scroll %W [expr {$deltaY > 0 ? -1 : 1}]
if {$tk::Priv::deltaY != 0 && %# %% 15 == 0} {
ttk::combobox::Scroll %W [expr {$tk::Priv::deltaY > 0 ? -1 : 1}]
}
}
bind TCombobox <<TraverseIn>> { ttk::combobox::TraverseIn %W }
Expand Down
6 changes: 3 additions & 3 deletions library/ttk/spinbox.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ bind TSpinbox <Shift-MouseWheel> {
# Ignore the event
}
bind TSpinbox <TouchpadScroll> {
lassign [tk::PreciseScrollDeltas %D] deltaX deltaY
lassign [tk::PreciseScrollDeltas %D] tk::Priv::deltaX tk::Priv::deltaY
# TouchpadScroll events fire about 60 times per second.
if {$deltaY != 0 && %# %% 12 == 0} {
ttk::spinbox::Spin %W [expr {$deltaY > 0 ? -1 : 1}]
if {$tk::Priv::deltaY != 0 && %# %% 12 == 0} {
ttk::spinbox::Spin %W [expr {$tk::Priv::deltaY > 0 ? -1 : 1}]
}
}

Expand Down
10 changes: 5 additions & 5 deletions library/ttk/utils.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,12 @@ bind TtkScrollable <TouchpadScroll> {
if {%# %% 5 != 0} {
return
}
lassign [tk::PreciseScrollDeltas %D] deltaX deltaY
if {$deltaX != 0} {
%W xview scroll [expr {-$deltaX}] units
lassign [tk::PreciseScrollDeltas %D] tk::Priv::deltaX tk::Priv::deltaY
if {$tk::Priv::deltaX != 0} {
%W xview scroll [expr {-$tk::Priv::deltaX}] units
}
if {$deltaY != 0} {
%W yview scroll [expr {-$deltaY}] units
if {$tk::Priv::deltaY != 0} {
%W yview scroll [expr {-$tk::Priv::deltaY}] units
}
}
#*EOF*

0 comments on commit 6c40142

Please sign in to comment.