mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 21:32:45 +00:00
Move input code from retroarch.c to input_driver.c
This commit is contained in:
parent
0c0b86c4cf
commit
61d30cdc31
@ -42,6 +42,7 @@
|
||||
#include "../menu/menu_driver.h"
|
||||
#endif
|
||||
|
||||
#include "../accessibility.h"
|
||||
#include "../command.h"
|
||||
#include "../config.def.keybinds.h"
|
||||
#include "../driver.h"
|
||||
@ -5464,3 +5465,274 @@ void input_driver_collect_system_input(input_driver_state_t *input_st,
|
||||
#endif /* defined(HAVE_ACCESSIBILITY) && defined(HAVE_TRANSLATE) */
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(HAVE_MENU) && defined(HAVE_ACCESSIBILITY)
|
||||
static const char *accessibility_lut_name(char key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
#if 0
|
||||
/* TODO/FIXME - overlaps with tilde */
|
||||
case '`':
|
||||
return "left quote";
|
||||
#endif
|
||||
case '`':
|
||||
return "tilde";
|
||||
case '!':
|
||||
return "exclamation point";
|
||||
case '@':
|
||||
return "at sign";
|
||||
case '#':
|
||||
return "hash sign";
|
||||
case '$':
|
||||
return "dollar sign";
|
||||
case '%':
|
||||
return "percent sign";
|
||||
case '^':
|
||||
return "carrot";
|
||||
case '&':
|
||||
return "ampersand";
|
||||
case '*':
|
||||
return "asterisk";
|
||||
case '(':
|
||||
return "left bracket";
|
||||
case ')':
|
||||
return "right bracket";
|
||||
case '-':
|
||||
return "minus";
|
||||
case '_':
|
||||
return "underscore";
|
||||
case '=':
|
||||
return "equals";
|
||||
case '+':
|
||||
return "plus";
|
||||
case '[':
|
||||
return "left square bracket";
|
||||
case '{':
|
||||
return "left curl bracket";
|
||||
case ']':
|
||||
return "right square bracket";
|
||||
case '}':
|
||||
return "right curl bracket";
|
||||
case '\\':
|
||||
return "back slash";
|
||||
case '|':
|
||||
return "pipe";
|
||||
case ';':
|
||||
return "semicolon";
|
||||
case ':':
|
||||
return "colon";
|
||||
case '\'':
|
||||
return "single quote";
|
||||
case '\"':
|
||||
return "double quote";
|
||||
case ',':
|
||||
return "comma";
|
||||
case '<':
|
||||
return "left angle bracket";
|
||||
case '.':
|
||||
return "period";
|
||||
case '>':
|
||||
return "right angle bracket";
|
||||
case '/':
|
||||
return "front slash";
|
||||
case '?':
|
||||
return "question mark";
|
||||
case ' ':
|
||||
return "space";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
void input_keyboard_event(bool down, unsigned code,
|
||||
uint32_t character, uint16_t mod, unsigned device)
|
||||
{
|
||||
static bool deferred_wait_keys;
|
||||
runloop_state_t *runloop_st = runloop_state_get_ptr();
|
||||
retro_keyboard_event_t
|
||||
*key_event = &runloop_st->key_event;
|
||||
input_driver_state_t
|
||||
*input_st = input_state_get_ptr();
|
||||
access_state_t *access_st = access_state_get_ptr();
|
||||
#ifdef HAVE_ACCESSIBILITY
|
||||
settings_t *settings = config_get_ptr();
|
||||
bool accessibility_enable = settings->bools.accessibility_enable;
|
||||
unsigned accessibility_narrator_speech_speed = settings->uints.accessibility_narrator_speech_speed;
|
||||
#endif
|
||||
#ifdef HAVE_MENU
|
||||
struct menu_state *menu_st = menu_state_get_ptr();
|
||||
|
||||
/* If screensaver is active, then it should be
|
||||
* disabled if:
|
||||
* - Key is down AND
|
||||
* - OSK is active, OR:
|
||||
* - Key is *not* mapped to RetroPad input (these
|
||||
* inputs are handled in menu_event() - if we
|
||||
* allow mapped RetroPad keys to toggle off
|
||||
* the screensaver, then we end up with a 'duplicate'
|
||||
* input that will trigger unwanted menu action)
|
||||
* - For extra amusement, a number of keyboard keys
|
||||
* are hard-coded to RetroPad inputs (while the menu
|
||||
* is running) in such a way that they cannot be
|
||||
* detected via the regular 'keyboard_mapping_bits'
|
||||
* record. We therefore have to check each of these
|
||||
* explicitly...
|
||||
* Otherwise, input is ignored whenever screensaver
|
||||
* is active */
|
||||
if (menu_st->screensaver_active)
|
||||
{
|
||||
if (down &&
|
||||
(code != RETROK_UNKNOWN) &&
|
||||
(menu_input_dialog_get_display_kb() ||
|
||||
!((code == RETROK_SPACE) || /* RETRO_DEVICE_ID_JOYPAD_START */
|
||||
(code == RETROK_SLASH) || /* RETRO_DEVICE_ID_JOYPAD_X */
|
||||
(code == RETROK_RSHIFT) || /* RETRO_DEVICE_ID_JOYPAD_SELECT */
|
||||
(code == RETROK_RIGHT) || /* RETRO_DEVICE_ID_JOYPAD_RIGHT */
|
||||
(code == RETROK_LEFT) || /* RETRO_DEVICE_ID_JOYPAD_LEFT */
|
||||
(code == RETROK_DOWN) || /* RETRO_DEVICE_ID_JOYPAD_DOWN */
|
||||
(code == RETROK_UP) || /* RETRO_DEVICE_ID_JOYPAD_UP */
|
||||
(code == RETROK_PAGEUP) || /* RETRO_DEVICE_ID_JOYPAD_L */
|
||||
(code == RETROK_PAGEDOWN) || /* RETRO_DEVICE_ID_JOYPAD_R */
|
||||
(code == RETROK_BACKSPACE) || /* RETRO_DEVICE_ID_JOYPAD_B */
|
||||
(code == RETROK_RETURN) || /* RETRO_DEVICE_ID_JOYPAD_A */
|
||||
(code == RETROK_DELETE) || /* RETRO_DEVICE_ID_JOYPAD_Y */
|
||||
BIT512_GET(input_st->keyboard_mapping_bits, code))))
|
||||
{
|
||||
menu_ctx_environment_t menu_environ;
|
||||
menu_environ.type = MENU_ENVIRON_DISABLE_SCREENSAVER;
|
||||
menu_environ.data = NULL;
|
||||
menu_st->screensaver_active = false;
|
||||
menu_st->input_last_time_us = menu_st->current_time_us;
|
||||
menu_driver_ctl(RARCH_MENU_CTL_ENVIRONMENT, &menu_environ);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (down)
|
||||
menu_st->input_last_time_us = menu_st->current_time_us;
|
||||
|
||||
#ifdef HAVE_ACCESSIBILITY
|
||||
if (menu_input_dialog_get_display_kb()
|
||||
&& down && is_accessibility_enabled(
|
||||
accessibility_enable,
|
||||
access_st->enabled))
|
||||
{
|
||||
if (code != 303 && code != 0)
|
||||
{
|
||||
char* say_char = (char*)malloc(sizeof(char)+1);
|
||||
|
||||
if (say_char)
|
||||
{
|
||||
char c = (char) character;
|
||||
*say_char = c;
|
||||
say_char[1] = '\0';
|
||||
|
||||
if (character == 127 || character == 8)
|
||||
accessibility_speak_priority(
|
||||
accessibility_enable,
|
||||
accessibility_narrator_speech_speed,
|
||||
"backspace", 10);
|
||||
else
|
||||
{
|
||||
const char *lut_name = accessibility_lut_name(c);
|
||||
|
||||
if (lut_name)
|
||||
accessibility_speak_priority(
|
||||
accessibility_enable,
|
||||
accessibility_narrator_speech_speed,
|
||||
lut_name, 10);
|
||||
else if (character != 0)
|
||||
accessibility_speak_priority(
|
||||
accessibility_enable,
|
||||
accessibility_narrator_speech_speed,
|
||||
say_char, 10);
|
||||
}
|
||||
free(say_char);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (deferred_wait_keys)
|
||||
{
|
||||
if (down)
|
||||
return;
|
||||
|
||||
input_st->keyboard_press_cb = NULL;
|
||||
input_st->keyboard_press_data = NULL;
|
||||
input_st->keyboard_mapping_blocked = false;
|
||||
deferred_wait_keys = false;
|
||||
}
|
||||
else if (input_st->keyboard_press_cb)
|
||||
{
|
||||
if (!down || code == RETROK_UNKNOWN)
|
||||
return;
|
||||
if (input_st->keyboard_press_cb(input_st->keyboard_press_data, code))
|
||||
return;
|
||||
deferred_wait_keys = true;
|
||||
}
|
||||
else if (input_st->keyboard_line.enabled)
|
||||
{
|
||||
if (!down)
|
||||
return;
|
||||
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_POINTER:
|
||||
if (code != 0x12d)
|
||||
character = (char)code;
|
||||
/* fall-through */
|
||||
default:
|
||||
if (!input_keyboard_line_event(input_st,
|
||||
&input_st->keyboard_line, character))
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Line is complete, can free it now. */
|
||||
if (input_st->keyboard_line.buffer)
|
||||
free(input_st->keyboard_line.buffer);
|
||||
input_st->keyboard_line.buffer = NULL;
|
||||
input_st->keyboard_line.ptr = 0;
|
||||
input_st->keyboard_line.size = 0;
|
||||
input_st->keyboard_line.cb = NULL;
|
||||
input_st->keyboard_line.userdata = NULL;
|
||||
input_st->keyboard_line.enabled = false;
|
||||
|
||||
/* Unblock all hotkeys. */
|
||||
input_st->keyboard_mapping_blocked = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (code == RETROK_UNKNOWN)
|
||||
return;
|
||||
|
||||
/* Block hotkey + RetroPad mapped keyboard key events,
|
||||
* but not with game focus, and from keyboard device type,
|
||||
* and with 'enable_hotkey' modifier set and unpressed */
|
||||
if (!input_st->game_focus_state.enabled &&
|
||||
BIT512_GET(input_st->keyboard_mapping_bits, code))
|
||||
{
|
||||
input_mapper_t *handle = &input_st->mapper;
|
||||
struct retro_keybind hotkey = input_config_binds[0][RARCH_ENABLE_HOTKEY];
|
||||
bool hotkey_pressed =
|
||||
(input_st->input_hotkey_block_counter > 0)
|
||||
|| (hotkey.key == code);
|
||||
|
||||
if (!(MAPPER_GET_KEY(handle, code)) &&
|
||||
!(!hotkey_pressed && (
|
||||
hotkey.key != RETROK_UNKNOWN ||
|
||||
hotkey.joykey != NO_BTN ||
|
||||
hotkey.joyaxis != AXIS_NONE
|
||||
)))
|
||||
return;
|
||||
}
|
||||
|
||||
if (*key_event)
|
||||
(*key_event)(down, code, character, mod);
|
||||
}
|
||||
}
|
||||
|
@ -1039,6 +1039,21 @@ void input_keys_pressed(
|
||||
void input_driver_collect_system_input(input_driver_state_t *input_st,
|
||||
settings_t *settings, input_bits_t *current_bits);
|
||||
|
||||
/**
|
||||
* input_keyboard_event:
|
||||
* @down : Keycode was pressed down?
|
||||
* @code : Keycode.
|
||||
* @character : Character inputted.
|
||||
* @mod : TODO/FIXME: ???
|
||||
*
|
||||
* Keyboard event utils. Called by drivers when keyboard events
|
||||
* are fired.
|
||||
* This interfaces with the global system driver struct
|
||||
* and libretro callbacks.
|
||||
**/
|
||||
void input_keyboard_event(bool down, unsigned code,
|
||||
uint32_t character, uint16_t mod, unsigned device);
|
||||
|
||||
extern input_device_driver_t *joypad_drivers[];
|
||||
extern input_driver_t *input_drivers[];
|
||||
#ifdef HAVE_HID
|
||||
|
283
retroarch.c
283
retroarch.c
@ -10883,289 +10883,6 @@ const char* config_get_joypad_driver_options(void)
|
||||
return char_list_new_special(STRING_LIST_INPUT_JOYPAD_DRIVERS, NULL);
|
||||
}
|
||||
|
||||
#if defined(HAVE_MENU) && defined(HAVE_ACCESSIBILITY)
|
||||
static const char *accessibility_lut_name(char key)
|
||||
{
|
||||
switch (key)
|
||||
{
|
||||
#if 0
|
||||
/* TODO/FIXME - overlaps with tilde */
|
||||
case '`':
|
||||
return "left quote";
|
||||
#endif
|
||||
case '`':
|
||||
return "tilde";
|
||||
case '!':
|
||||
return "exclamation point";
|
||||
case '@':
|
||||
return "at sign";
|
||||
case '#':
|
||||
return "hash sign";
|
||||
case '$':
|
||||
return "dollar sign";
|
||||
case '%':
|
||||
return "percent sign";
|
||||
case '^':
|
||||
return "carrot";
|
||||
case '&':
|
||||
return "ampersand";
|
||||
case '*':
|
||||
return "asterisk";
|
||||
case '(':
|
||||
return "left bracket";
|
||||
case ')':
|
||||
return "right bracket";
|
||||
case '-':
|
||||
return "minus";
|
||||
case '_':
|
||||
return "underscore";
|
||||
case '=':
|
||||
return "equals";
|
||||
case '+':
|
||||
return "plus";
|
||||
case '[':
|
||||
return "left square bracket";
|
||||
case '{':
|
||||
return "left curl bracket";
|
||||
case ']':
|
||||
return "right square bracket";
|
||||
case '}':
|
||||
return "right curl bracket";
|
||||
case '\\':
|
||||
return "back slash";
|
||||
case '|':
|
||||
return "pipe";
|
||||
case ';':
|
||||
return "semicolon";
|
||||
case ':':
|
||||
return "colon";
|
||||
case '\'':
|
||||
return "single quote";
|
||||
case '\"':
|
||||
return "double quote";
|
||||
case ',':
|
||||
return "comma";
|
||||
case '<':
|
||||
return "left angle bracket";
|
||||
case '.':
|
||||
return "period";
|
||||
case '>':
|
||||
return "right angle bracket";
|
||||
case '/':
|
||||
return "front slash";
|
||||
case '?':
|
||||
return "question mark";
|
||||
case ' ':
|
||||
return "space";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* input_keyboard_event:
|
||||
* @down : Keycode was pressed down?
|
||||
* @code : Keycode.
|
||||
* @character : Character inputted.
|
||||
* @mod : TODO/FIXME: ???
|
||||
*
|
||||
* Keyboard event utils. Called by drivers when keyboard events
|
||||
* are fired.
|
||||
* This interfaces with the global system driver struct
|
||||
* and libretro callbacks.
|
||||
**/
|
||||
void input_keyboard_event(bool down, unsigned code,
|
||||
uint32_t character, uint16_t mod, unsigned device)
|
||||
{
|
||||
static bool deferred_wait_keys;
|
||||
runloop_state_t *runloop_st = &runloop_state;
|
||||
retro_keyboard_event_t
|
||||
*key_event = &runloop_st->key_event;
|
||||
input_driver_state_t
|
||||
*input_st = input_state_get_ptr();
|
||||
access_state_t *access_st = access_state_get_ptr();
|
||||
#ifdef HAVE_ACCESSIBILITY
|
||||
settings_t *settings = config_get_ptr();
|
||||
bool accessibility_enable = settings->bools.accessibility_enable;
|
||||
unsigned accessibility_narrator_speech_speed = settings->uints.accessibility_narrator_speech_speed;
|
||||
#endif
|
||||
#ifdef HAVE_MENU
|
||||
struct menu_state *menu_st = menu_state_get_ptr();
|
||||
|
||||
/* If screensaver is active, then it should be
|
||||
* disabled if:
|
||||
* - Key is down AND
|
||||
* - OSK is active, OR:
|
||||
* - Key is *not* mapped to RetroPad input (these
|
||||
* inputs are handled in menu_event() - if we
|
||||
* allow mapped RetroPad keys to toggle off
|
||||
* the screensaver, then we end up with a 'duplicate'
|
||||
* input that will trigger unwanted menu action)
|
||||
* - For extra amusement, a number of keyboard keys
|
||||
* are hard-coded to RetroPad inputs (while the menu
|
||||
* is running) in such a way that they cannot be
|
||||
* detected via the regular 'keyboard_mapping_bits'
|
||||
* record. We therefore have to check each of these
|
||||
* explicitly...
|
||||
* Otherwise, input is ignored whenever screensaver
|
||||
* is active */
|
||||
if (menu_st->screensaver_active)
|
||||
{
|
||||
if (down &&
|
||||
(code != RETROK_UNKNOWN) &&
|
||||
(menu_input_dialog_get_display_kb() ||
|
||||
!((code == RETROK_SPACE) || /* RETRO_DEVICE_ID_JOYPAD_START */
|
||||
(code == RETROK_SLASH) || /* RETRO_DEVICE_ID_JOYPAD_X */
|
||||
(code == RETROK_RSHIFT) || /* RETRO_DEVICE_ID_JOYPAD_SELECT */
|
||||
(code == RETROK_RIGHT) || /* RETRO_DEVICE_ID_JOYPAD_RIGHT */
|
||||
(code == RETROK_LEFT) || /* RETRO_DEVICE_ID_JOYPAD_LEFT */
|
||||
(code == RETROK_DOWN) || /* RETRO_DEVICE_ID_JOYPAD_DOWN */
|
||||
(code == RETROK_UP) || /* RETRO_DEVICE_ID_JOYPAD_UP */
|
||||
(code == RETROK_PAGEUP) || /* RETRO_DEVICE_ID_JOYPAD_L */
|
||||
(code == RETROK_PAGEDOWN) || /* RETRO_DEVICE_ID_JOYPAD_R */
|
||||
(code == RETROK_BACKSPACE) || /* RETRO_DEVICE_ID_JOYPAD_B */
|
||||
(code == RETROK_RETURN) || /* RETRO_DEVICE_ID_JOYPAD_A */
|
||||
(code == RETROK_DELETE) || /* RETRO_DEVICE_ID_JOYPAD_Y */
|
||||
BIT512_GET(input_st->keyboard_mapping_bits, code))))
|
||||
{
|
||||
menu_ctx_environment_t menu_environ;
|
||||
menu_environ.type = MENU_ENVIRON_DISABLE_SCREENSAVER;
|
||||
menu_environ.data = NULL;
|
||||
menu_st->screensaver_active = false;
|
||||
menu_st->input_last_time_us = menu_st->current_time_us;
|
||||
menu_driver_ctl(RARCH_MENU_CTL_ENVIRONMENT, &menu_environ);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (down)
|
||||
menu_st->input_last_time_us = menu_st->current_time_us;
|
||||
|
||||
#ifdef HAVE_ACCESSIBILITY
|
||||
if (menu_input_dialog_get_display_kb()
|
||||
&& down && is_accessibility_enabled(
|
||||
accessibility_enable,
|
||||
access_st->enabled))
|
||||
{
|
||||
if (code != 303 && code != 0)
|
||||
{
|
||||
char* say_char = (char*)malloc(sizeof(char)+1);
|
||||
|
||||
if (say_char)
|
||||
{
|
||||
char c = (char) character;
|
||||
*say_char = c;
|
||||
say_char[1] = '\0';
|
||||
|
||||
if (character == 127 || character == 8)
|
||||
accessibility_speak_priority(
|
||||
accessibility_enable,
|
||||
accessibility_narrator_speech_speed,
|
||||
"backspace", 10);
|
||||
else
|
||||
{
|
||||
const char *lut_name = accessibility_lut_name(c);
|
||||
|
||||
if (lut_name)
|
||||
accessibility_speak_priority(
|
||||
accessibility_enable,
|
||||
accessibility_narrator_speech_speed,
|
||||
lut_name, 10);
|
||||
else if (character != 0)
|
||||
accessibility_speak_priority(
|
||||
accessibility_enable,
|
||||
accessibility_narrator_speech_speed,
|
||||
say_char, 10);
|
||||
}
|
||||
free(say_char);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (deferred_wait_keys)
|
||||
{
|
||||
if (down)
|
||||
return;
|
||||
|
||||
input_st->keyboard_press_cb = NULL;
|
||||
input_st->keyboard_press_data = NULL;
|
||||
input_st->keyboard_mapping_blocked = false;
|
||||
deferred_wait_keys = false;
|
||||
}
|
||||
else if (input_st->keyboard_press_cb)
|
||||
{
|
||||
if (!down || code == RETROK_UNKNOWN)
|
||||
return;
|
||||
if (input_st->keyboard_press_cb(input_st->keyboard_press_data, code))
|
||||
return;
|
||||
deferred_wait_keys = true;
|
||||
}
|
||||
else if (input_st->keyboard_line.enabled)
|
||||
{
|
||||
if (!down)
|
||||
return;
|
||||
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_POINTER:
|
||||
if (code != 0x12d)
|
||||
character = (char)code;
|
||||
/* fall-through */
|
||||
default:
|
||||
if (!input_keyboard_line_event(input_st,
|
||||
&input_st->keyboard_line, character))
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Line is complete, can free it now. */
|
||||
if (input_st->keyboard_line.buffer)
|
||||
free(input_st->keyboard_line.buffer);
|
||||
input_st->keyboard_line.buffer = NULL;
|
||||
input_st->keyboard_line.ptr = 0;
|
||||
input_st->keyboard_line.size = 0;
|
||||
input_st->keyboard_line.cb = NULL;
|
||||
input_st->keyboard_line.userdata = NULL;
|
||||
input_st->keyboard_line.enabled = false;
|
||||
|
||||
/* Unblock all hotkeys. */
|
||||
input_st->keyboard_mapping_blocked = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (code == RETROK_UNKNOWN)
|
||||
return;
|
||||
|
||||
/* Block hotkey + RetroPad mapped keyboard key events,
|
||||
* but not with game focus, and from keyboard device type,
|
||||
* and with 'enable_hotkey' modifier set and unpressed */
|
||||
if (!input_st->game_focus_state.enabled &&
|
||||
BIT512_GET(input_st->keyboard_mapping_bits, code))
|
||||
{
|
||||
input_mapper_t *handle = &input_st->mapper;
|
||||
struct retro_keybind hotkey = input_config_binds[0][RARCH_ENABLE_HOTKEY];
|
||||
bool hotkey_pressed =
|
||||
(input_st->input_hotkey_block_counter > 0)
|
||||
|| (hotkey.key == code);
|
||||
|
||||
if (!(MAPPER_GET_KEY(handle, code)) &&
|
||||
!(!hotkey_pressed && (
|
||||
hotkey.key != RETROK_UNKNOWN ||
|
||||
hotkey.joykey != NO_BTN ||
|
||||
hotkey.joyaxis != AXIS_NONE
|
||||
)))
|
||||
return;
|
||||
}
|
||||
|
||||
if (*key_event)
|
||||
(*key_event)(down, code, character, mod);
|
||||
}
|
||||
}
|
||||
|
||||
/* AUDIO */
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user