Skip to content

Commit

Permalink
sdl2: textinput + terminal
Browse files Browse the repository at this point in the history
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
  • Loading branch information
kraxel committed Jun 2, 2014
1 parent 363f59d commit f233579
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion ui/sdl2.c
Expand Up @@ -214,6 +214,23 @@ static void sdl_process_key(struct sdl2_state *scon,
int qcode = sdl2_scancode_to_qcode[ev->keysym.scancode];
QemuConsole *con = scon ? scon->dcl.con : NULL;

if (!qemu_console_is_graphic(con)) {
if (ev->type == SDL_KEYDOWN) {
switch (ev->keysym.scancode) {
case SDL_SCANCODE_RETURN:
kbd_put_keysym_console(con, '\n');
break;
case SDL_SCANCODE_BACKSPACE:
kbd_put_keysym_console(con, QEMU_KEY_BACKSPACE);
break;
default:
kbd_put_qcode_console(con, qcode);
break;
}
}
return;
}

switch (ev->keysym.scancode) {
#if 0
case SDL_SCANCODE_NUMLOCKCLEAR:
Expand Down Expand Up @@ -309,6 +326,11 @@ static void sdl_show_cursor(void)

static void sdl_grab_start(struct sdl2_state *scon)
{
QemuConsole *con = scon ? scon->dcl.con : NULL;

if (!con || !qemu_console_is_graphic(con)) {
return;
}
/*
* If the application is not active, do not try to enter grab state. This
* prevents 'SDL_WM_GrabInput(SDL_GRAB_ON)' from blocking all the
Expand Down Expand Up @@ -569,6 +591,17 @@ static void handle_keyup(SDL_Event *ev)
}
}

static void handle_textinput(SDL_Event *ev)
{
struct sdl2_state *scon = get_scon_from_window(ev->key.windowID);
QemuConsole *con = scon ? scon->dcl.con : NULL;

if (qemu_console_is_graphic(con)) {
return;
}
kbd_put_string_console(con, ev->text.text, strlen(ev->text.text));
}

static void handle_mousemotion(SDL_Event *ev)
{
int max_x, max_y;
Expand Down Expand Up @@ -705,6 +738,9 @@ static void sdl_refresh(DisplayChangeListener *dcl)
case SDL_KEYUP:
handle_keyup(ev);
break;
case SDL_TEXTINPUT:
handle_textinput(ev);
break;
case SDL_QUIT:
if (!no_quit) {
no_shutdown = 0;
Expand Down Expand Up @@ -833,14 +869,17 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)

for (i = 0;; i++) {
QemuConsole *con = qemu_console_lookup_by_index(i);
if (!con || !qemu_console_is_graphic(con)) {
if (!con) {
break;
}
}
sdl2_num_outputs = i;
sdl2_console = g_new0(struct sdl2_state, sdl2_num_outputs);
for (i = 0; i < sdl2_num_outputs; i++) {
QemuConsole *con = qemu_console_lookup_by_index(i);
if (!qemu_console_is_graphic(con)) {
sdl2_console[i].hidden = true;
}
sdl2_console[i].dcl.ops = &dcl_ops;
sdl2_console[i].dcl.con = con;
register_displaychangelistener(&sdl2_console[i].dcl);
Expand Down

0 comments on commit f233579

Please sign in to comment.