8000 MNT: Add modifier key press handling to macosx backend · matplotlib/matplotlib@0f7a7fc · GitHub
[go: up one dir, main page]

Skip to content

Commit 0f7a7fc

Browse files
committed
MNT: Add modifier key press handling to macosx backend
The flagsChanged event handles single presses of modifier keys, so we need to send the corresponding string to our key press handlers from within that routine. Modifier + second key is handled within the KeyUp/KeyDown routines already, so leave those alone.
1 parent a6bd3be commit 0f7a7fc

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/_macosx.m

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ - (void)keyDown:(NSEvent*)event;
247247
- (void)keyUp:(NSEvent*)event;
248248
- (void)scrollWheel:(NSEvent *)event;
249249
- (BOOL)acceptsFirstResponder;
250-
//- (void)flagsChanged:(NSEvent*)event;
250+
- (void)flagsChanged:(NSEvent*)event;
251251
@end
252252

253253
/* ---------------------------- Python classes ---------------------------- */
@@ -1711,29 +1711,31 @@ - (BOOL)acceptsFirstResponder
17111711
return YES;
17121712
}
17131713

1714-
/* This is all wrong. Address of pointer is being passed instead of pointer, keynames don't
1715-
match up with what the front-end and does the front-end even handle modifier keys by themselves?
1716-
1717-
- (void)flagsChanged:(NSEvent*)event
1714+
// flagsChanged gets called on single modifier keypresses
1715+
// The modifier + second key gets handled in convertKeyEvent in KeyUp/KeyDown
1716+
- (void)flagsChanged:(NSEvent *)event
17181717
{
17191718
const char *s = NULL;
1720-
if (([event modifierFlags] & NSControlKeyMask) == NSControlKeyMask)
1719+
if ([event modifierFlags] & NSEventModifierFlagControl)
17211720
s = "control";
1722-
else if (([event modifierFlags] & NSShiftKeyMask) == NSShiftKeyMask)
1721+
else if ([event modifierFlags] & NSEventModifierFlagShift)
17231722
s = "shift";
1724-
else if (([event modifierFlags] & NSAlternateKeyMask) == NSAlternateKeyMask)
1723+
else if ([event modifierFlags] & NSEventModifierFlagOption)
17251724
s = "alt";
1725+
else if ([event modifierFlags] & NSEventModifierFlagCommand)
1726+
s = "cmd";
1727+
else if ([event modifierFlags] & NSEventModifierFlagCapsLock)
1728+
s = "caps_lock";
17261729
else return;
17271730
PyGILState_STATE gstate = PyGILState_Ensure();
1728-
PyObject* result = PyObject_CallMethod(canvas, "key_press_event", "s", &s);
1731+
PyObject* result = PyObject_CallMethod(canvas, "key_press_event", "s", s);
17291732
if (result)
17301733
Py_DECREF(result);
17311734
else
17321735
PyErr_Print();
17331736

17341737
PyGILState_Release(gstate);
17351738
}
1736-
*/
17371739
@end
17381740

17391741
static PyObject*

0 commit comments

Comments
 (0)
0