diff options
-rw-r--r-- | src/internal.c | 23 | ||||
-rw-r--r-- | src/internal.h | 4 | ||||
-rw-r--r-- | src/mac.m | 6 | ||||
-rw-r--r-- | src/win.c | 3 | ||||
-rw-r--r-- | src/x11.c | 10 |
5 files changed, 38 insertions, 8 deletions
diff --git a/src/internal.c b/src/internal.c index cff66be..b3ee86a 100644 --- a/src/internal.c +++ b/src/internal.c @@ -116,6 +116,29 @@ puglDecodeUTF8(const uint8_t* buf) return 0xFFFD; } +PuglMods +puglFilterMods(const PuglMods state, const PuglKey key) +{ + switch (key) { + case PUGL_KEY_SHIFT_L: + case PUGL_KEY_SHIFT_R: + return state & ~(PuglMods)PUGL_MOD_SHIFT; + case PUGL_KEY_CTRL_L: + case PUGL_KEY_CTRL_R: + return state & ~(PuglMods)PUGL_MOD_CTRL; + case PUGL_KEY_ALT_L: + case PUGL_KEY_ALT_R: + return state & ~(PuglMods)PUGL_MOD_ALT; + case PUGL_KEY_SUPER_L: + case PUGL_KEY_SUPER_R: + return state & ~(PuglMods)PUGL_MOD_SUPER; + default: + break; + }; + + return state; +} + PuglStatus puglPreRealize(PuglView* const view) { diff --git a/src/internal.h b/src/internal.h index 6c40dc2..3721c10 100644 --- a/src/internal.h +++ b/src/internal.h @@ -43,6 +43,10 @@ puglViewStringChanged(PuglView* view, PuglStringHint key, const char* value); uint32_t puglDecodeUTF8(const uint8_t* buf); +/// Return `state` with any flags related to `key` removed +PuglMods +puglFilterMods(PuglMods state, PuglKey key); + /// Prepare a view to be realized by the platform implementation if possible PuglStatus puglPreRealize(PuglView* view); @@ -679,7 +679,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type) wloc.y, rloc.x, [[NSScreen mainScreen] frame].size.height - rloc.y, - getModifiers(event), + puglFilterMods(getModifiers(event), spec), [event keyCode], (code != 0xFFFD) ? code : 0, }; @@ -710,7 +710,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type) wloc.y, rloc.x, [[NSScreen mainScreen] frame].size.height - rloc.y, - getModifiers(event), + puglFilterMods(getModifiers(event), spec), [event keyCode], (code != 0xFFFD) ? code : 0, }; @@ -868,7 +868,7 @@ handleCrossing(PuglWrapperView* view, NSEvent* event, const PuglEventType type) wloc.y, rloc.x, [[NSScreen mainScreen] frame].size.height - rloc.y, - mods, + puglFilterMods(mods, special), [event keyCode], special}; @@ -579,7 +579,8 @@ initKeyEvent(PuglKeyEvent* event, const PuglKey special = keySymToSpecial(vkey, ext); if (special) { - event->key = (uint32_t)special; + event->key = (uint32_t)special; + event->state = puglFilterMods(event->state, special); } else if (!dead) { // Translate unshifted key BYTE keyboardState[256] = PUGL_INIT_STRUCT; @@ -888,10 +888,12 @@ translateKey(PuglView* const view, XEvent* const xevent, PuglEvent* const event) KeySym sym = 0; const int ufound = XLookupString(&xevent->xkey, ustr, 8, &sym, NULL); const PuglKey special = keySymToSpecial(sym); - - event->key.key = - ((special || ufound <= 0) ? special - : (PuglKey)puglDecodeUTF8((const uint8_t*)ustr)); + if (special) { + event->key.state = puglFilterMods(event->key.state, special); + event->key.key = special; + } else if (ufound > 0) { + event->key.key = (PuglKey)puglDecodeUTF8((const uint8_t*)ustr); + } if (xevent->type == KeyPress && !filter && !special && view->impl->xic) { // Lookup shifted key for possible text event |