FIX: macOS backend reports wrong button for button_release_event - #31937
FIX: macOS backend reports wrong button for button_release_event#31937mishanilkazreen wants to merge 2 commits into
Conversation
|
Thank you for opening your first PR into Matplotlib! If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process. You can also join us on discourse chat for real-time discussion. For details on testing, writing docs, and our review process, please see the developer guide. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
|
Thanks for this! Your solution for the macOS backend made me realize a potential issue that I forgot to check in the original bug. Consider the following:
qtagg with your PR prints: If you do the same with Control instead of Alt/Option, qtagg instead prints: I suspect that we want Alt/Option to show |
|
Hi @iccir, Thanks for commenting on another case where it reports the wrong button release. I repeated your experiment and confirmed that it did affect qtagg. The cause is that the methods My solution was that I added a |
|
Just bumping this up for visibility, as I haven't heard back for more than one week. |
|
Hi @mishanilkazreen! Sorry for the delay in responding. A few weeks ago, I researched the history of "alt+click" emulating a middle click. As far as I can tell, this originates with the original implementation of Apple's XQuartz X11 server. It's not a widespread macOS convention like Control+Click. While I'm new to the project myself and not yet a maintainer, I don't think that this behavior should go into the other backends. I'm more inclined to remove it entirely from the macOS backend. That said, your implementation in the macosx backend is superior to my original one. Right now, we are in the process of adopting a reworked "macos" backend. As a result, I think your _macosx.m change in this PR is going to get lost in the chaos. I want you to get credit, however! I added you as a co-contributor to c7faa7f. I think that this will properly attribute you when I eventually merge. If this isn't the case, please let me know and I'll try to fix it! I'll also try to tag you on the eventual PR that will include this commit. |
|
Hi @iccir Thank you for your response and I appreciate you including my contribution to your rework. Much appreciated :) |
Fixes #31899
PR summary
The issue reports on macOS that Option+click and Ctrl+click were not correctly mapped to middle and right button clicks, respectively.
In qtagg, Option+click was hardcoded to
button = 1asbackend_qt.pydid not contain a button modifier mapping. Soevent.button()returned the physical button, which resulted in Option+click incorrectly emulating button 1 instead of button 2.In macosx, the
mouseDown:method was correctly mapped, however,mouseUp:hardcodedbutton = 1, which resulted in press and release being inconsistent.Fixes
For qtagg, I added a
_remap_darwin_button(...)static method inbackend_qt.pythat maps Alt/Option+left-click to the middle button on macOS.For macosx, I added a static variable
effectiveLeftButtonto store the resolved button at press time, allowingmouseUp:to read it back instead of hardcoding1.Minimum self-contained example
Instructions:
Outputs
Current
macosx
qtagg (PyQt6)
With Fixes
macosx & qtagg
Question
As raised in the initial issue, should the intended behaviour for the action
Alt + left-clickresult in the middle mouse? This implements it, but can be dropped by removing_remap_darwin_button(...)helper function.AI Disclosure
Claude Opus 4.8 was utilised to proofread my changes.
PR checklist