add text from xlib inputs

This commit is contained in:
Matthew 2025-12-23 18:36:23 +11:00
parent 7f4c109106
commit 809814577d
2 changed files with 19 additions and 13 deletions

View File

@ -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

View File

@ -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.pressed = pressed;
node.x = x;
node.y = y;
node.md = md;
node.text = text.length ? ConvToStr(Alloc!(char)(&inputs.arena, text)) : [];
DLLPushFront(inputs, node, null);
}
@ -1242,6 +1245,9 @@ HandleEvents(void* window_ptr)
{
XKeyEvent* kb_ev = &e.xkey;
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);
@ -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: