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

Skip to content

Commit 05c6009

Browse files
committed
FIX: macosx keep track of mouse up/down for cursor hand changes
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().
1 parent 74c0cd0 commit 05c6009

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/_macosx.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
static bool keyChangeShift = false;
4646
static bool keyChangeOption = false;
4747
static bool keyChangeCapsLock = false;
48+
/* Keep track of the current mouse up/down state for open/closed cursor hand */
49+
static bool leftMouseGrabbing = false;
4850

4951
/* -------------------------- Helper function ---------------------------- */
5052

@@ -457,7 +459,13 @@ int mpl_check_modifier(
457459
case 1: [[NSCursor arrowCursor] set]; break;
458460
case 2: [[NSCursor pointingHandCursor] set]; break;
459461
case 3: [[NSCursor crosshairCursor] set]; break;
460-
case 4: [[NSCursor openHandCursor] set]; break;
462+
case 4:
463+
if (leftMouseGrabbing) {
464+
[[NSCursor closedHandCursor] set];
465+
} else {
466+
[[NSCursor openHandCursor] set];
467+
}
468+
break;
461469
/* OSX handles busy state itself so no need to set a cursor here */
462470
case 5: break;
463471
case 6: [[NSCursor resizeLeftRightCursor] set]; break;
@@ -1503,8 +1511,10 @@ - (void)mouseDown:(NSEvent *)event
15031511
else
15041512
{
15051513
button = 1;
1506-
if ([NSCursor currentCursor]==[NSCursor openHandCursor])
1514+
if ([NSCursor currentCursor]==[NSCursor openHandCursor]) {
1515+
leftMouseGrabbing = true;
15071516
[[NSCursor closedHandCursor] set];
1517+
}
15081518
}
15091519
break;
15101520
}
@@ -1531,6 +1541,7 @@ - (void)mouseUp:(NSEvent *)event
15311541
y = location.y * device_scale;
15321542
switch ([event type])
15331543
{ case NSEventTypeLeftMouseUp:
1544+
leftMouseGrabbing = false;
15341545
button = 1;
15351546
if ([NSCursor currentCursor]==[NSCursor closedHandCursor])
15361547
[[NSCursor openHandCursor] set];

0 commit comments

Comments
 (0)