Skip to content

[Bug]: macOS backend reports wrong button for button_release_event #31899

Open

Description

@iccir

Bug summary

Run the attached code with the qtagg as well as the macosx backends.

While the mouse cursor is over the figure, perform the following:

  1. Click mouse. Release mouse
  2. Hold Option: Click mouse. Release mouse.
  3. Hold Control: Click mouse. Release mouse.

Code for reproduction

import matplotlib.pyplot as plt

def on_button_press(event):
    print(f'button press: {event.button}')
def on_button_release(event):
    print(f'button release: {event.button}')

fig = plt.figure()
fig.canvas.mpl_connect('button_press_event',   on_button_press)
fig.canvas.mpl_connect('button_release_event', on_button_release)

plt.show()

Actual outcome

qtagg:

button press: 1
button release: 1
button press: 1
button release: 1
button press: 3
button release: 3

macosx:

button press: 1
button release: 1
button press: 2
button release: 1
button press: 3
button release: 1

Expected outcome

Based on these code comments in _macosx.m:

if (modifier & NSEventModifierFlagControl)
    /* emulate a right-button click */
    button = 3;
else if (modifier & NSEventModifierFlagOption)
    /* emulate a middle-button click */
    button = 2;

I would expect:

button press: 1
button release: 1
button press: 2
button release: 2
button press: 3
button release: 3

However, if alt+click should not result in "middle click", I would expect macosx to match qtagg.

Additional information

No response

Operating system

macOS 14.8.5

Matplotlib Version

dev

Matplotlib Backend

qtagg, macosx

Python version

3.14.5

Jupyter version

No response

Installation

None

Activity

  1. added a commit that references this issue on Jun 28, 2026
    92c4212
  2. iccir commented on Jul 15, 2026

    @iccir
    ContributorAuthor

    I have tried to investigate the history of "alt+click" emulating a middle click. While control+click is a standard shortcut on macOS for a right click, alt+click has no system-default meaning.

    As far as I can tell, this probably originated with Apple's XQuartz X11 server. There is a "enable_fake_buttons" default that can be enabled. By default, it is off. It is unclear if "Button 2" and "Button 3" as mentioned in the man page correspond to 2=middle/3=right or 2=right/3=middle. Various open-source projects running on darwin map these differently.

    As this behavior dates back to the original inclusion of _macosx.m in the project from 2008. My assumption is that the original author used the XQuartz or a similar environment with alt+click set to emulate a middle mouse button.

    If this is the case, I don't believe that this behavior should be propagated to other backends. In addition, I'm more inclined to have the macosx backend only map control+click to a right click (as qtagg does). I'm not sure if others have strong opinions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions