From 809814577db807d5911e79216d6e114a2d5a2dfd Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 23 Dec 2025 18:36:23 +1100 Subject: [PATCH] add text from xlib inputs --- dlibincludes.c | 2 +- platform.d | 30 ++++++++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/dlibincludes.c b/dlibincludes.c index 4903881..28d8cd2 100644 --- a/dlibincludes.c +++ b/dlibincludes.c @@ -17,7 +17,7 @@ # include FT_GLYPH_H #endif -#ifdef NO_STBI +#ifndef NO_STBI # include "external/stb/stb_image.h" # include "external/stb/stb_image_write.h" #endif diff --git a/platform.d b/platform.d index 1cdfe60..9a0bc48 100644 --- a/platform.d +++ b/platform.d @@ -155,12 +155,13 @@ struct InputEvent { Input key; Modifier md; + InputEvent* next, prev; + string text; bool pressed; i32 x; i32 y; i32 rel_x; i32 rel_y; - InputEvent* next, prev; } enum ClipboardMode @@ -553,14 +554,16 @@ ResetInputs(Inputs* inputs) } void -Push(Inputs* inputs, Input input, i32 x, i32 y, bool pressed, Modifier md) +Push(Inputs* inputs, Input input, i32 x, i32 y, bool pressed, Modifier md, char[] text = []) { InputEvent* node = Alloc!(InputEvent)(&inputs.arena); - node.key = input; + + node.key = input; node.pressed = pressed; - node.x = x; - node.y = y; - node.md = md; + node.x = x; + node.y = y; + node.md = md; + node.text = text.length ? ConvToStr(Alloc!(char)(&inputs.arena, text)) : []; DLLPushFront(inputs, node, null); } @@ -1241,11 +1244,14 @@ HandleEvents(void* window_ptr) case KeyPress: { XKeyEvent* kb_ev = &e.xkey; - - bool pressed = e.type == KeyPress; - u32 code = kb_ev.keycode; - KeySym key_sym = XkbKeycodeToKeysym(w.display, cast(KeyCode)code, 0, 0); - Input input = ConvertInput(key_sym); + + char[32] chars; + i32 text_length = XLookupString(kb_ev, chars.ptr, chars.length, null, null); + char[] text = text_length ? chars[0 .. text_length] : []; + bool pressed = e.type == KeyPress; + u32 code = kb_ev.keycode; + KeySym key_sym = XkbKeycodeToKeysym(w.display, cast(KeyCode)code, 0, 0); + Input input = ConvertInput(key_sym); enum modifier_inputs = [Input.LeftShift, Input.RightShift, Input.LeftCtrl, Input.RightCtrl, Input.LeftAlt, Input.RightAlt]; enum modifiers = [MD.LeftShift, MD.RightShift, MD.LeftCtrl, MD.RightCtrl, MD.LeftAlt, MD.RightAlt]; @@ -1260,7 +1266,7 @@ HandleEvents(void* window_ptr) if(input != Input.None) { - Push(inputs, input, kb_ev.x, kb_ev.y, pressed, w.modifier); + Push(inputs, input, kb_ev.x, kb_ev.y, pressed, w.modifier, text); } } break; case ButtonPress: