Tk Source Code

View Ticket
Login
Ticket UUID: 6ff8f7b07a6b6cd3662409c77f7dbb140ba8b653
Title: Platform-independent way of using middle/right mouse button
Type: RFE Version: 8.6.9.1
Submitter: chrstphrchvz Created on: 2019-04-01 16:31:58
Subsystem: 01. Bindings Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2020-10-23 12:49:24
Resolution: Fixed Closed By: jan.nijtmans
    Closed on: 2020-10-23 12:49:24
Description:

On Tk Aqua, buttons 2 and 3 are the right and middle mouse buttons respectively, which is opposite of the convention used on X11 and Windows. If a Tk program wants to bind either of these buttons consistently on Aqua and non-Aqua platforms, then it must check if [tk windowingsystem] is "aqua" and bind to buttons 2 or 3 appropriately.

In a spirit similar to TIP #474, I would like for Tk to allow specifying the middle and right mouse buttons in a platform-independent manner without having to check if [tk windowingsystem] is "aqua".

Two potential implementations:

  • Define "aliases"/"synonyms" containing the physical placement of a button (middle or right) which are equivalent to events containing the number of the button on the platform currently in use. For example, <ButtonPress-Middle> would correspond to <ButtonPress-3> on Aqua, and <ButtonPress-2> on Windows/X11. (I do not know where existing synonyms are defined.)
  • Create similarly-named predefined virtual events in library/tk.tcl, for example <<ButtonPress-Right>>. (I do not know if this is an appropriate use case for predefined virtual events, however.)

For either approach, it may be desirable to also allow specifying the left mouse button by its physical placement rather than as button 1.

I would note that calling buttons by their physical placement (left/middle/right) is biased toward right-handed usage, but such convention is common, and I'm not sure what a better convention would be (maybe it's a reason numbered buttons were used in the first place).

Both approaches leave the existing numbered-button events available for compatibility with existing programs.

I do not think the approach of changing button 2 and button 3 to become consistent with other platforms is desirable, as it breaks existing programs that already try to work correctly on Aqua and non-Aqua platforms. My understanding is that Tk wishes to present windowingsystem events to programs as-is, even if there are inconsistencies between windowingsystems in how button events are numbered. There may be many programs out there (even code in Tk) that do not behave correctly on Aqua, but I'm not sure this justifies breaking programs that try to work correctly.

Another idea would be to add a runtime warning if numbered-button events are used to encourage using platform-independent event names instead; however such a warning would appear for programs that already try to work correctly, so I do not think this is a good idea, but I wanted to bring it up anyways.

I have also not considered how the Tcl C API might be improved for this.

User Comments: jan.nijtmans added on 2020-10-23 12:49:24:

Since TIP #474 is in Tk 8.7 now, this can be closed. Done!


chrstphrchvz added on 2019-07-24 13:01:54:

In discussing [1fb7af62] (Support buttons 4 and 5 on Windows) and [38dc27bd] (Add "numbered" events for buttons 6 and 7 or even higher), there is likely another approach to implementation: instead of defining new events, redefine the existing events to have a consistent meaning on all platforms, i.e. button 2 will always be the middle button, and button 3 will always the right button; buttons 4 and 5 might also be renumbered (they are typically 8 and 9 on X11).

I posted to Tcl-Core to try discussing higher-level issues of when and how platform-neutral mouse behavior can be implemented: whether any changes can be synchronized to appear in a single release, rather than gradually released (I think synchronizing these changes will be less confusing for the outside world); and whether they can be opt-in, i.e. for backward compatibility and the possibility of having this behavior in 8.6—programs must explicitly request the new behavior.