Abstract

This TIP proposes changing the default <MouseWheel> bindings in Tk to have
"better" behaved defaults for a larger set of applications.

Rationale

The existing <MouseWheel> bindings only operate on a small handful of widgets,
and only when they have focus. This essentially means that only the text
widget ever has useful <MouseWheel> behavior. This is not how the majority of
applications wish to use the MouseWheel. They operate primarily on a
mouse-focus model (scroll what the mouse is over, not what has focus).
In addition, <Shift-MouseWheel> horizontal scrolling support is added.

Instead of requiring a widget to have focus to receive <MouseWheel>
events, the new proposal operates with <MouseWheel> as a global binding. When
fired, it first does a safety check to prevent double-firing if an existing
<MouseWheel> binding is on the widget. It then finds the widget which the mouse
if over and uses that as the target for the scrolling event. If that widget
doesn't exist (usually meaning that it returned {} indicating we are outside
the Tk app), then use the widget which has the actual focus.

In scrolling, the scrollbar must be treated separately, since it has its own
calling conventions. All others widgets get called with the standard yview
scroll command, caught in case of errors, which are ignored.

This has been discussed on the tcl-mac mailing list already as the desired
behavior, and confirmed to be more intuitive on Windows as well. The above
code is already in use by applications that use widget extensions and
megawidgets such as BWidgets without any adverse effects seen. Note that the
existing <MouseWheel> bindings must first be removed, using the following code:

Reference Implementation

Discussion

This is adapted from tklib/style/as.tcl mousewheel adjustments and has proved
useful and workable across a variety of applications.

There is a bit of awkwardness in handling widgets that have their own
MouseWheel bindings in that core Tk requires these have focus to receive the
event. It may be better to fix this forced limitation in Tk rather than the
special-case code above (although that code does work).