From 5cd321dd02a046b2f944ad4053465ac8d8f3973a Mon Sep 17 00:00:00 2001 From: Volker Ruppert Date: Fri, 13 Jan 2017 21:37:06 +0000 Subject: [PATCH] Enabled gui console support for sdl2 using SDL_TEXTINPUT event. --- bochs/CHANGES | 2 +- bochs/gui/gui.cc | 2 ++ bochs/gui/gui.h | 3 +++ bochs/gui/sdl2.cc | 23 +++++++++++++++++++++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/bochs/CHANGES b/bochs/CHANGES index d1214ad15..0e9f354bc 100644 --- a/bochs/CHANGES +++ b/bochs/CHANGES @@ -11,7 +11,7 @@ Changes after 2.6.8 release: - GUI and display libraries - Show the runtime configuration in the Bochs VGA window (gui console) instead - of console / xterm (rfb, sdl, vncsrv and X11 guis). + of console / xterm (rfb, sdl, sdl2, vncsrv and X11 guis). - SDL2: Added get/set clipboard text support. - CPU / CPUDB diff --git a/bochs/gui/gui.cc b/bochs/gui/gui.cc index 6459592dc..1eaa9f871 100644 --- a/bochs/gui/gui.cc +++ b/bochs/gui/gui.cc @@ -1196,6 +1196,7 @@ char* bx_gui_c::bx_gets(char *s, int size) int pos = 0, done = 0; int cs_counter = 1, cs_visible = 0; + set_console_edit_mode(1); keystr[1] = 0; do { handle_events(); @@ -1234,6 +1235,7 @@ char* bx_gui_c::bx_gets(char *s, int size) } } while (!done); console.tminfo.cs_start |= 0x20; + set_console_edit_mode(0); return s; } #endif diff --git a/bochs/gui/gui.h b/bochs/gui/gui.h index 996e92f81..2729adf7b 100644 --- a/bochs/gui/gui.h +++ b/bochs/gui/gui.h @@ -135,6 +135,9 @@ public: virtual void beep_off(); virtual void get_capabilities(Bit16u *xres, Bit16u *yres, Bit16u *bpp); virtual void set_mouse_mode_absxy(bx_bool mode) {} +#if BX_USE_GUI_CONSOLE + virtual void set_console_edit_mode(bx_bool mode) {} +#endif // The following function(s) are defined already, and your // GUI code calls them diff --git a/bochs/gui/sdl2.cc b/bochs/gui/sdl2.cc index b6b4a2069..9fc61d887 100644 --- a/bochs/gui/sdl2.cc +++ b/bochs/gui/sdl2.cc @@ -53,6 +53,7 @@ public: #if BX_SHOW_IPS virtual void show_ips(Bit32u ips_count); #endif + virtual void set_console_edit_mode(bx_bool mode); private: void headerbar_click(int x); }; @@ -507,7 +508,7 @@ void bx_sdl2_gui_c::specific_init(int argc, char **argv, unsigned headerbar_y) if (gui_ci) { dialog_caps = BX_GUI_DLG_ALL; } else { -// console.present = 1; + console.present = 1; } } @@ -879,7 +880,10 @@ void bx_sdl2_gui_c::handle_events(void) case SDL_KEYDOWN: if (console_running()) { if ((sdl_event.key.keysym.sym & (1 << 30)) == 0) { - // TODO + Bit8u ascii = (Bit8u)sdl_event.key.keysym.sym; + if ((ascii == SDLK_RETURN) || (ascii == SDLK_BACKSPACE)) { + console_key_enq(ascii); + } } break; } @@ -967,6 +971,12 @@ void bx_sdl2_gui_c::handle_events(void) } break; + case SDL_TEXTINPUT: + if (console_running()) { + console_key_enq(sdl_event.text.text[0]); + } + break; + case SDL_QUIT: LOG_THIS setonoff(LOGLEV_PANIC, ACT_FATAL); BX_PANIC(("User requested shutdown.")); @@ -1463,6 +1473,15 @@ void bx_sdl2_gui_c::show_ips(Bit32u ips_count) } #endif +void bx_sdl2_gui_c::set_console_edit_mode(bx_bool mode) +{ + if (mode) { + SDL_StartTextInput(); + } else { + SDL_StopTextInput(); + } +} + /// key mapping code for SDL2 typedef struct {