diff options
author | dec05eba <dec05eba@protonmail.com> | 2025-01-21 19:45:33 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2025-01-21 19:45:33 +0100 |
commit | 2580087ef23fe21ae4dbed45fb8cfa14fbfd7b9f (patch) | |
tree | d88508b9b7303a418ad56d27c7ba4a837a9b6913 | |
parent | 66e7ceaa96de5c2acdea89b33773219ec0bb2c27 (diff) |
Add mapping notify event
-rw-r--r-- | include/mgl/window/event.h | 12 | ||||
-rw-r--r-- | include/mgl/window/key.h | 3 | ||||
-rw-r--r-- | src/window/key.c | 30 | ||||
-rw-r--r-- | src/window/window.c | 14 |
4 files changed, 45 insertions, 14 deletions
diff --git a/include/mgl/window/event.h b/include/mgl/window/event.h index 4813154..ab7ce35 100644 --- a/include/mgl/window/event.h +++ b/include/mgl/window/event.h @@ -60,6 +60,16 @@ typedef struct { } mgl_monitor_disconnected_event; typedef enum { + MGL_MAPPING_NOTIFY_MODIFIER, + MGL_MAPPING_NOTIFY_KEYBOARD, + MGL_MAPPING_NOTIFY_POINTER +} mgl_mapping_notify_type; + +typedef struct { + int notify_type; /* mgl_mapping_notify_type */ +} mgl_mapping_notify_event; + +typedef enum { MGL_EVENT_UNKNOWN, MGL_EVENT_CLOSED, /* Window closed */ MGL_EVENT_RESIZED, /* Window resized */ @@ -75,6 +85,7 @@ typedef enum { MGL_EVENT_MONITOR_CONNECTED, MGL_EVENT_MONITOR_DISCONNECTED, MGL_EVENT_MONITOR_PROPERTY_CHANGED, + MGL_EVENT_MAPPING_NOTIFY } mgl_event_type; struct mgl_event { @@ -89,6 +100,7 @@ struct mgl_event { mgl_monitor_connected_event monitor_connected; mgl_monitor_disconnected_event monitor_disconnected; mgl_monitor_property_changed_event monitor_property_changed; + mgl_mapping_notify_event mapping_notify; }; }; diff --git a/include/mgl/window/key.h b/include/mgl/window/key.h index c58fbcd..6863256 100644 --- a/include/mgl/window/key.h +++ b/include/mgl/window/key.h @@ -1,6 +1,8 @@ #ifndef _MGL_KEY_H_ #define _MGL_KEY_H_ +#include <stdbool.h> + typedef enum { MGL_KEY_UNKNOWN, MGL_KEY_A, @@ -111,5 +113,6 @@ typedef enum { /* Return NULL if unknown key */ const char* mgl_key_to_string(mgl_key key); +bool mgl_key_is_modifier(mgl_key key); #endif /* _MGL_KEY_H_ */ 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: { |