From e60bb1d1684ee6d7fe33195116885d86f38439f0 Mon Sep 17 00:00:00 2001 From: meancoot Date: Sun, 25 Nov 2012 20:23:31 -0500 Subject: [PATCH] Add RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK. An interface for allowing keyboard event data to be sent to the core. --- dynamic.c | 9 +++++++++ general.h | 2 ++ gfx/context/sdl_ctx.c | 18 ++++++++++++++++++ libretro.h | 14 ++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/dynamic.c b/dynamic.c index 9abb9a47c5..45bca30912 100644 --- a/dynamic.c +++ b/dynamic.c @@ -482,6 +482,15 @@ static bool environment_cb(unsigned cmd, void *data) break; } + + case RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK: + { + const struct retro_keyboard_callback *info = (const struct retro_keyboard_callback*)data; + + g_extern.system.key_event = info->callback; + + break; + } default: RARCH_LOG("Environ UNSUPPORTED (#%u).\n", cmd); diff --git a/general.h b/general.h index 0c4f5908aa..73c682df6e 100644 --- a/general.h +++ b/general.h @@ -320,6 +320,8 @@ struct global bool force_nonblock; const char *input_desc_btn[MAX_PLAYERS][RARCH_FIRST_CUSTOM_BIND]; + + retro_keyboard_event_t key_event; } system; struct diff --git a/gfx/context/sdl_ctx.c b/gfx/context/sdl_ctx.c index 3dbe7038d9..0cb63552e7 100644 --- a/gfx/context/sdl_ctx.c +++ b/gfx/context/sdl_ctx.c @@ -254,6 +254,24 @@ static void gfx_ctx_check_window(bool *quit, *width = event.resize.w; *height = event.resize.h; break; + + case SDL_KEYDOWN: + case SDL_KEYUP: + if(g_extern.system.key_event) + { + static bool unicodeOn = false; + + if(!unicodeOn) + { + unicodeOn = true; + SDL_EnableUNICODE(true); + } + + // For now it seems that all RETROK_* constant values match the SDLK_* values. + // Ultimately the table in sdl_input.c should be used in case this changes. + g_extern.system.key_event(event.type == SDL_KEYDOWN, event.key.keysym.sym, event.key.keysym.unicode); + } + break; } } diff --git a/libretro.h b/libretro.h index f077a17915..e3ff8cd92f 100755 --- a/libretro.h +++ b/libretro.h @@ -388,8 +388,22 @@ enum retro_key // It is up to the frontend to present this in a usable way. // The array is terminated by retro_input_descriptor::description being set to NULL. // This function can be called at any time, but it is recommended to call it as early as possible. +#define RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK 12 + // const struct retro_keyboard_callback * -- + // Sets a callback function used to notify core about keyboard events. +// Callback type passed in RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK. Called by the frontend in response to keyboard events. +// down is set if the key is being pressed, or false if it is being released. +// keycode is the RETROK value of the char. +// character is the text character of the pressed key. (UTF?) +typedef void (*retro_keyboard_event_t)(bool down, unsigned keycode, unsigned character); + +struct retro_keyboard_callback +{ + retro_keyboard_event_t callback; +}; + enum retro_pixel_format { // 0RGB1555, native endian. 0 bit must be set to 0.