1
0
mirror of https://github.com/libretro/RetroArch synced 2025-03-25 16:44:01 +00:00

(Key Events) Add modifier flag argument; plus cleanup.

This commit is contained in:
meancoot 2012-12-07 03:18:18 -05:00
parent e60bb1d168
commit be1fdd419b
2 changed files with 42 additions and 16 deletions

@ -1,6 +1,6 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
@ -70,11 +70,11 @@ static void gfx_ctx_swap_interval(unsigned interval)
GL_SYM_WRAP(glx_swap_interval, "glXSwapInterval");
if (!glx_swap_interval)
GL_SYM_WRAP(glx_swap_interval, "glXSwapIntervalMESA");
if (!glx_swap_interval)
if (!glx_swap_interval)
GL_SYM_WRAP(glx_swap_interval, "glXSwapIntervalSGI");
if (glx_swap_interval)
success = glx_swap_interval(g_interval) == 0;
else
else
RARCH_WARN("Could not find GLX VSync call.\n");
#endif
}
@ -118,7 +118,7 @@ static bool gfx_ctx_init(void)
return ret;
}
static void gfx_ctx_destroy(void)
static void gfx_ctx_destroy(void)
{
SDL_QuitSubSystem(SDL_INIT_VIDEO);
g_inited = false;
@ -254,22 +254,32 @@ 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)
if (g_extern.system.key_event)
{
static bool unicodeOn = false;
if(!unicodeOn)
SDL_EnableUNICODE(true);
uint16_t mods = 0;
if (event.key.keysym.mod)
{
unicodeOn = true;
SDL_EnableUNICODE(true);
mods |= (event.key.keysym.mod & KMOD_CTRL) ? RETROKMOD_CTRL : 0;
mods |= (event.key.keysym.mod & KMOD_ALT) ? RETROKMOD_ALT : 0;
mods |= (event.key.keysym.mod & KMOD_SHIFT) ? RETROKMOD_SHIFT : 0;
mods |= (event.key.keysym.mod & KMOD_META) ? RETROKMOD_META : 0;
mods |= (event.key.keysym.mod & KMOD_NUM) ? RETROKMOD_NUMLOCK : 0;
mods |= (event.key.keysym.mod & KMOD_CAPS) ? RETROKMOD_CAPSLOCK : 0;
// TODO: What is KMOD_MODE in SDL?
mods |= (event.key.keysym.mod & KMOD_MODE) ? RETROKMOD_SCROLLOCK : 0;
}
// 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);
// TODO: event.key.keysym.unicode is UTF-16
g_extern.system.key_event(event.type == SDL_KEYDOWN, event.key.keysym.sym, event.key.keysym.unicode, mods);
}
break;
}

@ -310,6 +310,21 @@ enum retro_key
RETROK_LAST
};
enum retro_mod
{
RETROKMOD_NONE = 0x0000,
RETROKMOD_SHIFT = 0x01,
RETROKMOD_CTRL = 0x02,
RETROKMOD_ALT = 0x04,
RETROKMOD_META = 0x08,
RETROKMOD_NUMLOCK = 0x10,
RETROKMOD_CAPSLOCK = 0x20,
RETROKMOD_SCROLLOCK = 0x40
};
// Environment commands.
#define RETRO_ENVIRONMENT_SET_ROTATION 1 // const unsigned * --
// Sets screen rotation of graphics.
@ -353,7 +368,7 @@ enum retro_key
//
// It can be used by the frontend to potentially warn
// about too demanding implementations.
//
//
// The levels are "floating", but roughly defined as:
// 0: Low-powered embedded devices such as Raspberry Pi
// 1: 6th generation consoles, such as Wii/Xbox 1, and phones, tablets, etc.
@ -396,8 +411,9 @@ enum retro_key
// 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);
// character is the text character of the pressed key. (UTF-32).
// key_modifiers is a set of RETROKMOD values or'ed together.
typedef void (*retro_keyboard_event_t)(bool down, unsigned keycode, uint32_t character, uint16_t key_modifiers);
struct retro_keyboard_callback
{