From 2580087ef23fe21ae4dbed45fb8cfa14fbfd7b9f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Tue, 21 Jan 2025 19:45:33 +0100 Subject: Add mapping notify event --- src/window/key.c | 30 +++++++++++++++++------------- src/window/window.c | 14 +++++++++++++- 2 files changed, 30 insertions(+), 14 deletions(-) (limited to 'src/window') diff --git a/src/window/key.c b/src/window/key.c index 7528a15..0ac0be6 100644 --- a/src/window/key.c +++ b/src/window/key.c @@ -29,22 +29,22 @@ const char* mgl_key_to_string(mgl_key key) { case MGL_KEY_X: return "X"; case MGL_KEY_Y: return "Y"; case MGL_KEY_Z: return "Z"; - case MGL_KEY_NUM0: return "Num0"; - case MGL_KEY_NUM1: return "Num1"; - case MGL_KEY_NUM2: return "Num2"; - case MGL_KEY_NUM3: return "Num3"; - case MGL_KEY_NUM4: return "Num4"; - case MGL_KEY_NUM5: return "Num5"; - case MGL_KEY_NUM6: return "Num6"; - case MGL_KEY_NUM7: return "Num7"; - case MGL_KEY_NUM8: return "Num8"; - case MGL_KEY_NUM9: return "Num9"; + case MGL_KEY_NUM0: return "0"; + case MGL_KEY_NUM1: return "1"; + case MGL_KEY_NUM2: return "2"; + case MGL_KEY_NUM3: return "3"; + case MGL_KEY_NUM4: return "4"; + case MGL_KEY_NUM5: return "5"; + case MGL_KEY_NUM6: return "6"; + case MGL_KEY_NUM7: return "7"; + case MGL_KEY_NUM8: return "8"; + case MGL_KEY_NUM9: return "9"; case MGL_KEY_ESCAPE: return "Escape"; - case MGL_KEY_LCONTROL: return "Left control"; + case MGL_KEY_LCONTROL: return "Left ctrl"; case MGL_KEY_LSHIFT: return "Left shift"; case MGL_KEY_LALT: return "Left alt"; case MGL_KEY_LSYSTEM: return "Left system"; - case MGL_KEY_RCONTROL: return "Right control"; + case MGL_KEY_RCONTROL: return "Right ctrl"; case MGL_KEY_RSHIFT: return "Right shift"; case MGL_KEY_RALT: return "Right alt"; case MGL_KEY_RSYSTEM: return "Right system"; @@ -60,7 +60,7 @@ const char* mgl_key_to_string(mgl_key key) { case MGL_KEY_TILDE: return "~"; case MGL_KEY_EQUAL: return "="; case MGL_KEY_HYPHEN: return "-"; - case MGL_KEY_SPACE: return " "; + case MGL_KEY_SPACE: return "Space"; case MGL_KEY_ENTER: return "Enter"; case MGL_KEY_BACKSPACE: return "Backspace"; case MGL_KEY_TAB: return "Tab"; @@ -108,3 +108,7 @@ const char* mgl_key_to_string(mgl_key key) { } return 0; } + +bool mgl_key_is_modifier(mgl_key key) { + return key >= MGL_KEY_LCONTROL && key <= MGL_KEY_RSYSTEM; +} diff --git a/src/window/window.c b/src/window/window.c index 485e400..9bf6917 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -1566,7 +1566,19 @@ static void mgl_window_on_receive_event(mgl_window *self, XEvent *xev, mgl_event } case MappingNotify: { XRefreshKeyboardMapping(&xev->xmapping); - event->type = MGL_EVENT_UNKNOWN; + event->type = MGL_EVENT_MAPPING_NOTIFY; + event->mapping_notify.notify_type = MappingModifier; + switch(xev->xmapping.request) { + case MappingModifier: + event->mapping_notify.notify_type = MGL_MAPPING_NOTIFY_MODIFIER; + break; + case MappingKeyboard: + event->mapping_notify.notify_type = MGL_MAPPING_NOTIFY_KEYBOARD; + break; + case MappingPointer: + event->mapping_notify.notify_type = MGL_MAPPING_NOTIFY_POINTER; + break; + } break; } default: { -- cgit v1.2.3