aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-10-21 09:28:11 -0400
committerDavid Robillard <d@drobilla.net>2023-10-21 10:25:12 -0400
commit6c2a219c3e4fd28b839449be46c285ea8fc68133 (patch)
tree8aaac4bf18a385532109e7adb31bff9bed1001d2 /src
parent720d4063eb18a00d02435658bd051dcd78f2e943 (diff)
downloadpugl-6c2a219c3e4fd28b839449be46c285ea8fc68133.tar.gz
pugl-6c2a219c3e4fd28b839449be46c285ea8fc68133.tar.bz2
pugl-6c2a219c3e4fd28b839449be46c285ea8fc68133.zip
Filter out corresponding modifiers from key events
Platforms differ here, but it's meaningless to ask about the state of a modifier that's currently being pressed or released, so simply mask this out in general so it's easy for platform implementations to clean events up before dispatching them.
Diffstat (limited to 'src')
-rw-r--r--src/internal.c23
-rw-r--r--src/internal.h4
-rw-r--r--src/mac.m6
-rw-r--r--src/win.c3
-rw-r--r--src/x11.c10
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);
diff --git a/src/mac.m b/src/mac.m
index 07eb28d..ad1ef2b 100644
--- a/src/mac.m
+++ b/src/mac.m
@@ -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};
diff --git a/src/win.c b/src/win.c
index 6838423..3d245f2 100644
--- a/src/win.c
+++ b/src/win.c
@@ -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;
diff --git a/src/x11.c b/src/x11.c
index e1e948f..ce0bf0b 100644
--- a/src/x11.c
+++ b/src/x11.c
@@ -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