diff options
-rw-r--r-- | include/mgl/window/event.h | 2 | ||||
-rw-r--r-- | src/window/window.c | 7 | ||||
-rw-r--r-- | tests/main.c | 2 |
3 files changed, 9 insertions, 2 deletions
diff --git a/include/mgl/window/event.h b/include/mgl/window/event.h index 0836098..4a3ba71 100644 --- a/include/mgl/window/event.h +++ b/include/mgl/window/event.h @@ -14,6 +14,8 @@ typedef struct { typedef struct { uint32_t codepoint; + int size; + unsigned char str[5]; /* utf8, null terminated */ } mgl_text_event; typedef struct { diff --git a/src/window/window.c b/src/window/window.c index cec6417..b53c4a1 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -4,6 +4,7 @@ #include "../../include/mgl/system/utf8.h" #include <X11/Xutil.h> #include <stdlib.h> +#include <string.h> #include <errno.h> #include <stdio.h> @@ -347,13 +348,17 @@ static void mgl_window_handle_text_event(mgl_window *self, XEvent *xev) { for(size_t i = 0; i < input_str_len;) { uint32_t codepoint = 0; const size_t clen = mgl_utf8_decode((const unsigned char*)&buf[i], &codepoint); - i += clen; mgl_event text_event; text_event.type = MGL_EVENT_TEXT_ENTERED; text_event.text.codepoint = codepoint; + text_event.text.size = clen; + memcpy(text_event.text.str, (const unsigned char*)&buf[i], clen); + text_event.text.str[clen] = '\0'; if(!x11_context_append_event(x11_context, &text_event)) break; + + i += clen; } } diff --git a/tests/main.c b/tests/main.c index 85754f2..2359cda 100644 --- a/tests/main.c +++ b/tests/main.c @@ -218,7 +218,7 @@ int main(int argc, char **argv) { while(mgl_window_poll_event(&window, &event)) { switch(event.type) { case MGL_EVENT_TEXT_ENTERED: { - fprintf(stderr, "text event, codepoint: %u\n", event.text.codepoint); + fprintf(stderr, "text event, codepoint: %u, str: %s\n", event.text.codepoint, event.text.str); break; } case MGL_EVENT_KEY_PRESSED: { |