Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX: macosx keep track of mouse up/down for cursor hand changes #25548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2023

Conversation

greglucas
Copy link
Contributor

PR Summary

Keep track of whether the left mouse is up or down so that we can set the proper open/closed cursor hand within set_cursor().

To test this, you can run the mouse_cursor example and click down and move the mouse in the "MOVE" section. Previously the cursor would be reset to the open-hand once the cursor is moved. With this update, the open/closed cursor depends on whether the left-button is depressed or not.
python galleries/examples/widgets/mouse_cursor.py

Suggested by @daniilS in #25412 (comment) and this PR does help the macOS version of that PR as well.

PR Checklist

Documentation and Tests

  • [-] Has pytest style unit tests (and pytest passes)
  • [-] Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • [-] New plotting related features are documented with examples.

Release Notes

  • [-] New features are marked with a .. versionadded:: directive in the docstring and documented in doc/users/next_whats_new/
  • [-] API changes are marked with a .. versionchanged:: directive in the docstring and documented in doc/api/next_api_changes/
  • [-] Release notes conform with instructions in next_whats_new/README.rst or next_api_changes/README.rst

@greglucas greglucas added this to the v3.8.0 milestone Mar 25, 2023
@daniilS
Copy link
Contributor

daniilS commented Apr 5, 2023

I finally got hold of a Mac to test this on. I wanted to see how the default pan tool avoids the issue of _wait_cursor_for_draw_cm() resetting the closed hand back to the open hand - turns out that since 3.6.0, it doesn't either if you move the mouse quickly. This PR fixes that as well, though I haven't found out what caused it to break in the first place, so don't know if it's anything important.

src/_macosx.m Outdated
Comment on lines 1531 to 1516
leftMouseDown = true;
button = 1;
if ([NSCursor currentCursor]==[NSCursor openHandCursor])
[[NSCursor closedHandCursor] set];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
leftMouseDown = true;
button = 1;
if ([NSCursor currentCursor]==[NSCursor openHandCursor])
[[NSCursor closedHandCursor] set];
button = 1;
if ([NSCursor currentCursor]==[NSCursor openHandCursor])
{
leftMouseDown = true;
[[NSCursor closedHandCursor] set];
}

This avoids showing a closed hand when the click happened outside of the draggable object, or before the pan mode became active.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... I purposefully put it outside the if-branch actually because I figured if the cursor is down, we want the closed hand regardless of if we have grabbed anything or not. I can see arguments both ways, so is there a standard to follow for that kind of interaction? With this, there is an open-hand even if I have the mouse down indicating I may be able to grab something again, even though that isn't possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MacOS documentation mentions:

  • Open hand: Appears when the mouse pointer is over an item that you can move and adjust within specific bounds [...]
  • Closed hand: Appears when you’re moving and adjusting an item within specific bounds [...]

hence my proposed change. To me it also seem that the closed hand should only ever appear if something is actively being dragged. The open hand with mouse down sounds fine - it means you are not currently grabbing anything, but could if you clicked again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'm sold. Updated with that behavior now.

@greglucas greglucas force-pushed the macosx-cursor-hand branch 2 times, most recently from b60ca42 to 888269f Compare April 7, 2023 01:21
@greglucas greglucas force-pushed the macosx-cursor-hand branch from 888269f to da95b70 Compare April 26, 2023 15:06
@greglucas greglucas force-pushed the macosx-cursor-hand branch from da95b70 to 05c6009 Compare June 2, 2023 14:52
Keep track of whether the left mouse is up or down so that we can
set the proper open/closed cursor hand within set_cursor().
@greglucas greglucas force-pushed the macosx-cursor-hand branch from 05c6009 to 03730da Compare June 15, 2023 13:54
@greglucas
Copy link
Contributor Author

@jklymak since you've got a mac do you care to test this one out? You can run the example in the PR description to see the before/after with this change.

@jklymak jklymak merged commit f588d2b into matplotlib:main Jun 16, 2023
@greglucas greglucas deleted the macosx-cursor-hand branch June 16, 2023 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants