From dae9d5553cd08e7ddf14e0ae2cd1585a53856d80 Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Sun, 9 Mar 2025 10:25:55 +0000 Subject: [PATCH] Use SDL_TextInputEvent for input FossilOrigin-Name: 4c092023dc2a717a1cf2df148d04b1c35a0371f43fcfc8aa69e60093ee4a4be2 --- src/Cube.mm | 10 +++++++--- src/console.mm | 21 +++++++++++++-------- src/protos.h | 3 ++- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/Cube.mm b/src/Cube.mm index a91d05c..d763483 100644 --- a/src/Cube.mm +++ b/src/Cube.mm @@ -239,8 +239,12 @@ VARP(minmillis, 0, 5, 1000); case SDL_KEYUP: if (_repeatsKeys || event.key.repeat == 0) keypress(event.key.keysym.sym, - event.key.state == SDL_PRESSED, - event.key.keysym.sym); + event.key.state == SDL_PRESSED); + break; + case SDL_TEXTINPUT: + @autoreleasepool { + input(@(event.text.text)); + } break; case SDL_MOUSEMOTION: if (ignore) { @@ -257,7 +261,7 @@ VARP(minmillis, 0, 5, 1000); break; keypress(-event.button.button, - event.button.state != 0, 0); + event.button.state != 0); lasttype = event.type; lastbut = event.button.button; break; diff --git a/src/console.mm b/src/console.mm index bedb218..bbe66c7 100644 --- a/src/console.mm +++ b/src/console.mm @@ -181,11 +181,11 @@ history(int n) COMMAND(history, ARG_1INT) void -keypress(int code, bool isdown, int cooked) +keypress(int code, bool isDown) { - if (saycommandon) // keystrokes go to commandline - { - if (isdown) { + // keystrokes go to commandline + if (saycommandon) { + if (isDown) { switch (code) { case SDLK_RETURN: break; @@ -226,8 +226,6 @@ keypress(int code, bool isdown, int cooked) default: resetcomplete(); - if (cooked) - [commandbuf appendFormat:@"%c", cooked]; } } else { if (code == SDLK_RETURN) { @@ -259,20 +257,27 @@ keypress(int code, bool isdown, int cooked) saycommand(NULL); } } - } else if (!menukey(code, isdown)) { + } else if (!menukey(code, isDown)) { // keystrokes go to menu for (KeyMapping *mapping in keyMappings) { if (mapping.code == code) { // keystrokes go to game, lookup in keymap and // execute - execute(mapping.action, isdown); + execute(mapping.action, isDown); return; } } } } +void +input(OFString *text) +{ + if (saycommandon) + [commandbuf appendString:text]; +} + OFString * getcurcommand() { diff --git a/src/protos.h b/src/protos.h index e9f2ff5..8d992bd 100644 --- a/src/protos.h +++ b/src/protos.h @@ -17,7 +17,8 @@ extern OFString *getalias(OFString *name); extern void writecfg(); // console -extern void keypress(int code, bool isdown, int cooked); +extern void keypress(int code, bool isDown); +extern void input(OFString *text); extern void renderconsole(); extern void conoutf(OFConstantString *format, ...); extern OFString *getcurcommand();