diff options
Diffstat (limited to 'src/mac.m')
-rw-r--r-- | src/mac.m | 32 |
1 files changed, 18 insertions, 14 deletions
@@ -372,7 +372,8 @@ getModifiers(const NSEvent* const ev) return (((modifierFlags & NSShiftKeyMask) ? PUGL_MOD_SHIFT : 0) | ((modifierFlags & NSControlKeyMask) ? PUGL_MOD_CTRL : 0) | ((modifierFlags & NSAlternateKeyMask) ? PUGL_MOD_ALT : 0) | - ((modifierFlags & NSCommandKeyMask) ? PUGL_MOD_SUPER : 0)); + ((modifierFlags & NSCommandKeyMask) ? PUGL_MOD_SUPER : 0) | + ((modifierFlags & (1U << 16U)) ? PUGL_MOD_CAPS_LOCK : 0)); } static PuglKey @@ -837,33 +838,36 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type) } } +static bool +flagDiffers(const uint32_t lhs, const uint32_t rhs, const uint32_t mask) +{ + return (lhs & mask) != (rhs & mask); +} + - (void)flagsChanged:(NSEvent*)event { const uint32_t mods = getModifiers(event); - PuglEventType type = PUGL_NOTHING; PuglKey special = (PuglKey)0; const uint16_t keyCode = [event keyCode]; - if ((mods & PUGL_MOD_SHIFT) != (puglview->impl->mods & PUGL_MOD_SHIFT)) { - type = mods & PUGL_MOD_SHIFT ? PUGL_KEY_PRESS : PUGL_KEY_RELEASE; + if (flagDiffers(mods, puglview->impl->mods, PUGL_MOD_SHIFT)) { special = (keyCode == 0x3C) ? PUGL_KEY_SHIFT_R : PUGL_KEY_SHIFT_L; - } else if ((mods & PUGL_MOD_CTRL) != (puglview->impl->mods & PUGL_MOD_CTRL)) { - type = mods & PUGL_MOD_CTRL ? PUGL_KEY_PRESS : PUGL_KEY_RELEASE; + } else if (flagDiffers(mods, puglview->impl->mods, PUGL_MOD_CTRL)) { special = (keyCode == 0x3E) ? PUGL_KEY_CTRL_R : PUGL_KEY_CTRL_L; - } else if ((mods & PUGL_MOD_ALT) != (puglview->impl->mods & PUGL_MOD_ALT)) { - type = mods & PUGL_MOD_ALT ? PUGL_KEY_PRESS : PUGL_KEY_RELEASE; + } else if (flagDiffers(mods, puglview->impl->mods, PUGL_MOD_ALT)) { special = (keyCode == 0x3D) ? PUGL_KEY_ALT_R : PUGL_KEY_ALT_L; - } else if ((mods & PUGL_MOD_SUPER) != - (puglview->impl->mods & PUGL_MOD_SUPER)) { - type = mods & PUGL_MOD_SUPER ? PUGL_KEY_PRESS : PUGL_KEY_RELEASE; + } else if (flagDiffers(mods, puglview->impl->mods, PUGL_MOD_SUPER)) { special = PUGL_KEY_SUPER_L; // Left and right command are identical + } else if (flagDiffers(mods, puglview->impl->mods, PUGL_MOD_CAPS_LOCK)) { + special = PUGL_KEY_CAPS_LOCK; } if (special != 0) { - const NSPoint wloc = [self eventLocation:event]; - const NSPoint rloc = [NSEvent mouseLocation]; + const NSPoint wloc = [self eventLocation:event]; + const NSPoint rloc = [NSEvent mouseLocation]; + const bool release = [event type] == NSEventTypeKeyUp; - const PuglKeyEvent ev = {type, + const PuglKeyEvent ev = {release ? PUGL_KEY_RELEASE : PUGL_KEY_PRESS, 0, [event timestamp], wloc.x, |