mirror of
https://github.com/libretro/RetroArch
synced 2025-02-08 15:40:14 +00:00
Combine input_driver.c and input_keyboard.c
This commit is contained in:
parent
68516cf74c
commit
060753258a
@ -157,7 +157,6 @@ OBJ += frontend/frontend.o \
|
||||
retroarch.o \
|
||||
dirs.o \
|
||||
paths.o \
|
||||
input/input_keyboard.o \
|
||||
command.o \
|
||||
msg_hash.o \
|
||||
intl/msg_hash_us.o \
|
||||
|
@ -41,7 +41,7 @@
|
||||
#include <windows.h>
|
||||
#include <commdlg.h>
|
||||
#include "../../retroarch.h"
|
||||
#include "../../input/input_keyboard.h"
|
||||
#include "../../input/input_driver.h"
|
||||
#include "../../input/input_keymaps.h"
|
||||
#include "../video_thread_wrapper.h"
|
||||
#include <shellapi.h>
|
||||
|
@ -40,7 +40,7 @@
|
||||
#include "dbus_common.h"
|
||||
|
||||
#include "../../frontend/frontend_driver.h"
|
||||
#include "../../input/input_keyboard.h"
|
||||
#include "../../input/input_driver.h"
|
||||
#include "../../input/input_keymaps.h"
|
||||
#include "../../input/common/input_x11_common.h"
|
||||
#include "../../verbosity.h"
|
||||
|
@ -46,7 +46,6 @@
|
||||
#include "../../frontend/frontend_driver.h"
|
||||
#include "../../input/input_driver.h"
|
||||
#include "../../input/input_keymaps.h"
|
||||
#include "../../input/input_keyboard.h"
|
||||
|
||||
typedef struct gfx_ctx_wayland_data
|
||||
{
|
||||
|
@ -419,7 +419,6 @@ INPUT
|
||||
#include "../input/input_config.c"
|
||||
#include "../input/input_keymaps.c"
|
||||
#include "../input/input_remapping.c"
|
||||
#include "../input/input_keyboard.c"
|
||||
|
||||
#ifdef HAVE_OVERLAY
|
||||
#include "../input/input_overlay.c"
|
||||
|
@ -21,9 +21,8 @@
|
||||
#include <boolean.h>
|
||||
|
||||
#include "../input_config.h"
|
||||
#include "../input_keyboard.h"
|
||||
#include "../input_keymaps.h"
|
||||
#include "../input_driver.h"
|
||||
#include "../input_keymaps.h"
|
||||
|
||||
#include "../../tasks/tasks_internal.h"
|
||||
#include "../../configuration.h"
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "../input_config.h"
|
||||
#include "../input_driver.h"
|
||||
#include "../input_keymaps.h"
|
||||
#include "../input_keyboard.h"
|
||||
|
||||
#include "../../gfx/video_driver.h"
|
||||
#include "../../verbosity.h"
|
||||
|
@ -49,7 +49,6 @@
|
||||
#include "../input_config.h"
|
||||
#include "../input_driver.h"
|
||||
#include "../input_keymaps.h"
|
||||
#include "../input_keyboard.h"
|
||||
|
||||
#include "../../gfx/video_driver.h"
|
||||
#include "../common/linux_common.h"
|
||||
|
@ -40,7 +40,6 @@
|
||||
#include "../input_config.h"
|
||||
#include "../input_driver.h"
|
||||
#include "../input_keymaps.h"
|
||||
#include "../input_keyboard.h"
|
||||
|
||||
#include "../../gfx/video_driver.h"
|
||||
#include "../common/linux_common.h"
|
||||
|
@ -21,15 +21,15 @@
|
||||
#include <libretro.h>
|
||||
#include <retro_miscellaneous.h>
|
||||
|
||||
#include <wiiu/nsyskbd.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "../../config.h"
|
||||
#endif
|
||||
|
||||
#include "../input_config.h"
|
||||
#include "../input_driver.h"
|
||||
#include "../input_keyboard.h"
|
||||
#include "../input_keymaps.h"
|
||||
#include <wiiu/nsyskbd.h>
|
||||
|
||||
#include "wiiu_dbg.h"
|
||||
|
||||
|
@ -28,7 +28,6 @@
|
||||
|
||||
#include "../input_driver.h"
|
||||
#include "../input_config.h"
|
||||
#include "../input_keyboard.h"
|
||||
#include "../input_keymaps.h"
|
||||
#include "../../tasks/tasks_internal.h"
|
||||
#include "../drivers_keyboard/keyboard_event_dos.h"
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
#include "../input_config.h"
|
||||
#include "../input_keymaps.h"
|
||||
#include "../input_keyboard.h"
|
||||
#include "../input_driver.h"
|
||||
|
||||
#include "../../driver.h"
|
||||
#include "../../retroarch.h"
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
#include "../input_driver.h"
|
||||
#include "../input_keymaps.h"
|
||||
#include "../input_keyboard.h"
|
||||
#include "../../configuration.h"
|
||||
|
||||
#define MOD_MAP_SIZE 5
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <encodings/utf.h>
|
||||
#include <string/stdstring.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
@ -30,7 +31,6 @@
|
||||
|
||||
#include "input_driver.h"
|
||||
#include "input_config.h"
|
||||
#include "input_keyboard.h"
|
||||
#include "input_remapping.h"
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
@ -191,6 +191,31 @@ struct turbo_buttons
|
||||
unsigned count;
|
||||
};
|
||||
|
||||
struct input_keyboard_line
|
||||
{
|
||||
char *buffer;
|
||||
size_t ptr;
|
||||
size_t size;
|
||||
|
||||
/** Line complete callback.
|
||||
* Calls back after return is
|
||||
* pressed with the completed line.
|
||||
* Line can be NULL.
|
||||
**/
|
||||
input_keyboard_line_complete_t cb;
|
||||
void *userdata;
|
||||
};
|
||||
|
||||
static bool input_driver_keyboard_linefeed_enable = false;
|
||||
static input_keyboard_line_t *g_keyboard_line = NULL;
|
||||
|
||||
static void *g_keyboard_press_data = NULL;
|
||||
|
||||
static unsigned osk_last_codepoint = 0;
|
||||
static unsigned osk_last_codepoint_len = 0;
|
||||
|
||||
static input_keyboard_press_t g_keyboard_press_cb;
|
||||
|
||||
static turbo_buttons_t input_driver_turbo_btns;
|
||||
#ifdef HAVE_COMMAND
|
||||
static command_t *input_driver_command = NULL;
|
||||
@ -1624,3 +1649,299 @@ const hid_driver_t *input_hid_init_first(void)
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void osk_update_last_codepoint(const char *word)
|
||||
{
|
||||
const char *letter = word;
|
||||
const char *pos = letter;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
unsigned codepoint = utf8_walk(&letter);
|
||||
unsigned len = (unsigned)(letter - pos);
|
||||
|
||||
if (letter[0] == 0)
|
||||
{
|
||||
osk_last_codepoint = codepoint;
|
||||
osk_last_codepoint_len = len;
|
||||
break;
|
||||
}
|
||||
|
||||
pos = letter;
|
||||
}
|
||||
}
|
||||
|
||||
/* Depends on ASCII character values */
|
||||
#define ISPRINT(c) (((int)(c) >= ' ' && (int)(c) <= '~') ? 1 : 0)
|
||||
|
||||
/**
|
||||
* input_keyboard_line_event:
|
||||
* @state : Input keyboard line handle.
|
||||
* @character : Inputted character.
|
||||
*
|
||||
* Called on every keyboard character event.
|
||||
*
|
||||
* Returns: true (1) on success, otherwise false (0).
|
||||
**/
|
||||
static bool input_keyboard_line_event(
|
||||
input_keyboard_line_t *state, uint32_t character)
|
||||
{
|
||||
char array[2];
|
||||
bool ret = false;
|
||||
const char *word = NULL;
|
||||
char c = character >= 128 ? '?' : character;
|
||||
|
||||
/* Treat extended chars as ? as we cannot support
|
||||
* printable characters for unicode stuff. */
|
||||
|
||||
if (c == '\r' || c == '\n')
|
||||
{
|
||||
state->cb(state->userdata, state->buffer);
|
||||
|
||||
array[0] = c;
|
||||
array[1] = 0;
|
||||
|
||||
word = array;
|
||||
ret = true;
|
||||
}
|
||||
else if (c == '\b' || c == '\x7f') /* 0x7f is ASCII for del */
|
||||
{
|
||||
if (state->ptr)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < osk_last_codepoint_len; i++)
|
||||
{
|
||||
memmove(state->buffer + state->ptr - 1,
|
||||
state->buffer + state->ptr,
|
||||
state->size - state->ptr + 1);
|
||||
state->ptr--;
|
||||
state->size--;
|
||||
}
|
||||
|
||||
word = state->buffer;
|
||||
}
|
||||
}
|
||||
else if (ISPRINT(c))
|
||||
{
|
||||
/* Handle left/right here when suitable */
|
||||
char *newbuf = (char*)
|
||||
realloc(state->buffer, state->size + 2);
|
||||
if (!newbuf)
|
||||
return false;
|
||||
|
||||
memmove(newbuf + state->ptr + 1,
|
||||
newbuf + state->ptr,
|
||||
state->size - state->ptr + 1);
|
||||
newbuf[state->ptr] = c;
|
||||
state->ptr++;
|
||||
state->size++;
|
||||
newbuf[state->size] = '\0';
|
||||
|
||||
state->buffer = newbuf;
|
||||
|
||||
array[0] = c;
|
||||
array[1] = 0;
|
||||
|
||||
word = array;
|
||||
}
|
||||
|
||||
if (word != NULL)
|
||||
{
|
||||
/* OSK - update last character */
|
||||
if (word[0] == 0)
|
||||
{
|
||||
osk_last_codepoint = 0;
|
||||
osk_last_codepoint_len = 0;
|
||||
}
|
||||
else
|
||||
osk_update_last_codepoint(word);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool input_keyboard_line_append(const char *word)
|
||||
{
|
||||
unsigned i = 0;
|
||||
unsigned len = (unsigned)strlen(word);
|
||||
char *newbuf = (char*)
|
||||
realloc(g_keyboard_line->buffer,
|
||||
g_keyboard_line->size + len*2);
|
||||
|
||||
if (!newbuf)
|
||||
return false;
|
||||
|
||||
memmove(newbuf + g_keyboard_line->ptr + len,
|
||||
newbuf + g_keyboard_line->ptr,
|
||||
g_keyboard_line->size - g_keyboard_line->ptr + len);
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
newbuf[g_keyboard_line->ptr] = word[i];
|
||||
g_keyboard_line->ptr++;
|
||||
g_keyboard_line->size++;
|
||||
}
|
||||
|
||||
newbuf[g_keyboard_line->size] = '\0';
|
||||
|
||||
g_keyboard_line->buffer = newbuf;
|
||||
|
||||
if (word[0] == 0)
|
||||
{
|
||||
osk_last_codepoint = 0;
|
||||
osk_last_codepoint_len = 0;
|
||||
}
|
||||
else
|
||||
osk_update_last_codepoint(word);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* input_keyboard_start_line:
|
||||
* @userdata : Userdata.
|
||||
* @cb : Line complete callback function.
|
||||
*
|
||||
* Sets function pointer for keyboard line handle.
|
||||
*
|
||||
* The underlying buffer can be reallocated at any time
|
||||
* (or be NULL), but the pointer to it remains constant
|
||||
* throughout the objects lifetime.
|
||||
*
|
||||
* Returns: underlying buffer of the keyboard line.
|
||||
**/
|
||||
const char **input_keyboard_start_line(void *userdata,
|
||||
input_keyboard_line_complete_t cb)
|
||||
{
|
||||
input_keyboard_line_t *state = (input_keyboard_line_t*)
|
||||
calloc(1, sizeof(*state));
|
||||
if (!state)
|
||||
return NULL;
|
||||
|
||||
g_keyboard_line = state;
|
||||
g_keyboard_line->cb = cb;
|
||||
g_keyboard_line->userdata = userdata;
|
||||
|
||||
/* While reading keyboard line input, we have to block all hotkeys. */
|
||||
input_driver_keyboard_mapping_set_block(true);
|
||||
|
||||
return (const char**)&g_keyboard_line->buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
if (deferred_wait_keys)
|
||||
{
|
||||
if (down)
|
||||
return;
|
||||
|
||||
g_keyboard_press_cb = NULL;
|
||||
g_keyboard_press_data = NULL;
|
||||
input_driver_keyboard_mapping_set_block(false);
|
||||
deferred_wait_keys = false;
|
||||
}
|
||||
else if (g_keyboard_press_cb)
|
||||
{
|
||||
if (!down || code == RETROK_UNKNOWN)
|
||||
return;
|
||||
if (g_keyboard_press_cb(g_keyboard_press_data, code))
|
||||
return;
|
||||
deferred_wait_keys = true;
|
||||
}
|
||||
else if (g_keyboard_line)
|
||||
{
|
||||
if (!down)
|
||||
return;
|
||||
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_POINTER:
|
||||
if (code != 0x12d)
|
||||
character = (char)code;
|
||||
/* fall-through */
|
||||
default:
|
||||
if (!input_keyboard_line_event(g_keyboard_line, character))
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Line is complete, can free it now. */
|
||||
input_keyboard_ctl(RARCH_INPUT_KEYBOARD_CTL_LINE_FREE, NULL);
|
||||
|
||||
/* Unblock all hotkeys. */
|
||||
input_driver_keyboard_mapping_set_block(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
retro_keyboard_event_t *key_event = NULL;
|
||||
rarch_ctl(RARCH_CTL_KEY_EVENT_GET, &key_event);
|
||||
|
||||
if (key_event && *key_event)
|
||||
(*key_event)(down, code, character, mod);
|
||||
}
|
||||
}
|
||||
|
||||
bool input_keyboard_ctl(enum rarch_input_keyboard_ctl_state state, void *data)
|
||||
{
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case RARCH_INPUT_KEYBOARD_CTL_LINE_FREE:
|
||||
if (g_keyboard_line)
|
||||
{
|
||||
free(g_keyboard_line->buffer);
|
||||
free(g_keyboard_line);
|
||||
}
|
||||
g_keyboard_line = NULL;
|
||||
break;
|
||||
case RARCH_INPUT_KEYBOARD_CTL_START_WAIT_KEYS:
|
||||
{
|
||||
input_keyboard_ctx_wait_t *keys = (input_keyboard_ctx_wait_t*)data;
|
||||
|
||||
if (!keys)
|
||||
return false;
|
||||
|
||||
g_keyboard_press_cb = keys->cb;
|
||||
g_keyboard_press_data = keys->userdata;
|
||||
}
|
||||
|
||||
/* While waiting for input, we have to block all hotkeys. */
|
||||
input_driver_keyboard_mapping_set_block(true);
|
||||
break;
|
||||
case RARCH_INPUT_KEYBOARD_CTL_CANCEL_WAIT_KEYS:
|
||||
g_keyboard_press_cb = NULL;
|
||||
g_keyboard_press_data = NULL;
|
||||
input_driver_keyboard_mapping_set_block(false);
|
||||
break;
|
||||
case RARCH_INPUT_KEYBOARD_CTL_DESTROY:
|
||||
input_driver_keyboard_linefeed_enable = false;
|
||||
break;
|
||||
case RARCH_INPUT_KEYBOARD_CTL_SET_LINEFEED_ENABLED:
|
||||
input_driver_keyboard_linefeed_enable = true;
|
||||
break;
|
||||
case RARCH_INPUT_KEYBOARD_CTL_UNSET_LINEFEED_ENABLED:
|
||||
input_driver_keyboard_linefeed_enable = false;
|
||||
break;
|
||||
case RARCH_INPUT_KEYBOARD_CTL_IS_LINEFEED_ENABLED:
|
||||
return input_driver_keyboard_linefeed_enable;
|
||||
case RARCH_INPUT_KEYBOARD_CTL_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -37,6 +37,9 @@ typedef struct rarch_joypad_driver input_device_driver_t;
|
||||
|
||||
typedef struct hid_driver hid_driver_t;
|
||||
|
||||
/* Keyboard line reader. Handles textual input in a direct fashion. */
|
||||
typedef struct input_keyboard_line input_keyboard_line_t;
|
||||
|
||||
enum input_device_type
|
||||
{
|
||||
INPUT_DEVICE_TYPE_NONE = 0,
|
||||
@ -61,6 +64,27 @@ enum input_action
|
||||
INPUT_ACTION_MAX_USERS
|
||||
};
|
||||
|
||||
enum rarch_input_keyboard_ctl_state
|
||||
{
|
||||
RARCH_INPUT_KEYBOARD_CTL_NONE = 0,
|
||||
RARCH_INPUT_KEYBOARD_CTL_DESTROY,
|
||||
RARCH_INPUT_KEYBOARD_CTL_SET_LINEFEED_ENABLED,
|
||||
RARCH_INPUT_KEYBOARD_CTL_UNSET_LINEFEED_ENABLED,
|
||||
RARCH_INPUT_KEYBOARD_CTL_IS_LINEFEED_ENABLED,
|
||||
|
||||
RARCH_INPUT_KEYBOARD_CTL_LINE_FREE,
|
||||
|
||||
/*
|
||||
* Waits for keys to be pressed (used for binding
|
||||
* keys in the menu).
|
||||
* Callback returns false when all polling is done.
|
||||
**/
|
||||
RARCH_INPUT_KEYBOARD_CTL_START_WAIT_KEYS,
|
||||
|
||||
/* Cancels keyboard wait for keys function callback. */
|
||||
RARCH_INPUT_KEYBOARD_CTL_CANCEL_WAIT_KEYS
|
||||
};
|
||||
|
||||
struct retro_keybind
|
||||
{
|
||||
bool valid;
|
||||
@ -604,6 +628,55 @@ const hid_driver_t *input_hid_init_first(void);
|
||||
|
||||
const void *hid_driver_get_data(void);
|
||||
|
||||
/** Line complete callback.
|
||||
* Calls back after return is pressed with the completed line.
|
||||
* Line can be NULL.
|
||||
**/
|
||||
typedef void (*input_keyboard_line_complete_t)(void *userdata,
|
||||
const char *line);
|
||||
|
||||
typedef bool (*input_keyboard_press_t)(void *userdata, unsigned code);
|
||||
|
||||
typedef struct input_keyboard_ctx_wait
|
||||
{
|
||||
void *userdata;
|
||||
input_keyboard_press_t cb;
|
||||
} input_keyboard_ctx_wait_t;
|
||||
|
||||
/**
|
||||
* 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 driver struct and libretro callbacks.
|
||||
**/
|
||||
void input_keyboard_event(bool down, unsigned code, uint32_t character,
|
||||
uint16_t mod, unsigned device);
|
||||
|
||||
bool input_keyboard_line_append(const char *word);
|
||||
|
||||
/**
|
||||
* input_keyboard_start_line:
|
||||
* @userdata : Userdata.
|
||||
* @cb : Line complete callback function.
|
||||
*
|
||||
* Sets function pointer for keyboard line handle.
|
||||
*
|
||||
* The underlying buffer can be reallocated at any time
|
||||
* (or be NULL), but the pointer to it remains constant
|
||||
* throughout the objects lifetime.
|
||||
*
|
||||
* Returns: underlying buffer of the keyboard line.
|
||||
**/
|
||||
const char **input_keyboard_start_line(void *userdata,
|
||||
input_keyboard_line_complete_t cb);
|
||||
|
||||
|
||||
bool input_keyboard_ctl(enum rarch_input_keyboard_ctl_state state, void *data);
|
||||
|
||||
extern input_device_driver_t dinput_joypad;
|
||||
extern input_device_driver_t linuxraw_joypad;
|
||||
extern input_device_driver_t parport_joypad;
|
||||
|
@ -1,348 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2017 - Daniel De Matteis
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <encodings/utf.h>
|
||||
|
||||
#include "input_keyboard.h"
|
||||
|
||||
#include "input_driver.h"
|
||||
|
||||
#include "../retroarch.h"
|
||||
|
||||
struct input_keyboard_line
|
||||
{
|
||||
char *buffer;
|
||||
size_t ptr;
|
||||
size_t size;
|
||||
|
||||
/** Line complete callback.
|
||||
* Calls back after return is
|
||||
* pressed with the completed line.
|
||||
* Line can be NULL.
|
||||
**/
|
||||
input_keyboard_line_complete_t cb;
|
||||
void *userdata;
|
||||
};
|
||||
|
||||
static bool input_driver_keyboard_linefeed_enable = false;
|
||||
static input_keyboard_line_t *g_keyboard_line = NULL;
|
||||
|
||||
static void *g_keyboard_press_data = NULL;
|
||||
|
||||
static unsigned osk_last_codepoint = 0;
|
||||
static unsigned osk_last_codepoint_len = 0;
|
||||
|
||||
static input_keyboard_press_t g_keyboard_press_cb;
|
||||
|
||||
static void osk_update_last_codepoint(const char *word)
|
||||
{
|
||||
const char *letter = word;
|
||||
const char *pos = letter;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
unsigned codepoint = utf8_walk(&letter);
|
||||
unsigned len = (unsigned)(letter - pos);
|
||||
|
||||
if (letter[0] == 0)
|
||||
{
|
||||
osk_last_codepoint = codepoint;
|
||||
osk_last_codepoint_len = len;
|
||||
break;
|
||||
}
|
||||
|
||||
pos = letter;
|
||||
}
|
||||
}
|
||||
|
||||
/* Depends on ASCII character values */
|
||||
#define ISPRINT(c) (((int)(c) >= ' ' && (int)(c) <= '~') ? 1 : 0)
|
||||
|
||||
/**
|
||||
* input_keyboard_line_event:
|
||||
* @state : Input keyboard line handle.
|
||||
* @character : Inputted character.
|
||||
*
|
||||
* Called on every keyboard character event.
|
||||
*
|
||||
* Returns: true (1) on success, otherwise false (0).
|
||||
**/
|
||||
static bool input_keyboard_line_event(
|
||||
input_keyboard_line_t *state, uint32_t character)
|
||||
{
|
||||
char array[2];
|
||||
bool ret = false;
|
||||
const char *word = NULL;
|
||||
char c = character >= 128 ? '?' : character;
|
||||
|
||||
/* Treat extended chars as ? as we cannot support
|
||||
* printable characters for unicode stuff. */
|
||||
|
||||
if (c == '\r' || c == '\n')
|
||||
{
|
||||
state->cb(state->userdata, state->buffer);
|
||||
|
||||
array[0] = c;
|
||||
array[1] = 0;
|
||||
|
||||
word = array;
|
||||
ret = true;
|
||||
}
|
||||
else if (c == '\b' || c == '\x7f') /* 0x7f is ASCII for del */
|
||||
{
|
||||
if (state->ptr)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < osk_last_codepoint_len; i++)
|
||||
{
|
||||
memmove(state->buffer + state->ptr - 1,
|
||||
state->buffer + state->ptr,
|
||||
state->size - state->ptr + 1);
|
||||
state->ptr--;
|
||||
state->size--;
|
||||
}
|
||||
|
||||
word = state->buffer;
|
||||
}
|
||||
}
|
||||
else if (ISPRINT(c))
|
||||
{
|
||||
/* Handle left/right here when suitable */
|
||||
char *newbuf = (char*)
|
||||
realloc(state->buffer, state->size + 2);
|
||||
if (!newbuf)
|
||||
return false;
|
||||
|
||||
memmove(newbuf + state->ptr + 1,
|
||||
newbuf + state->ptr,
|
||||
state->size - state->ptr + 1);
|
||||
newbuf[state->ptr] = c;
|
||||
state->ptr++;
|
||||
state->size++;
|
||||
newbuf[state->size] = '\0';
|
||||
|
||||
state->buffer = newbuf;
|
||||
|
||||
array[0] = c;
|
||||
array[1] = 0;
|
||||
|
||||
word = array;
|
||||
}
|
||||
|
||||
if (word != NULL)
|
||||
{
|
||||
/* OSK - update last character */
|
||||
if (word[0] == 0)
|
||||
{
|
||||
osk_last_codepoint = 0;
|
||||
osk_last_codepoint_len = 0;
|
||||
}
|
||||
else
|
||||
osk_update_last_codepoint(word);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool input_keyboard_line_append(const char *word)
|
||||
{
|
||||
unsigned i = 0;
|
||||
unsigned len = (unsigned)strlen(word);
|
||||
char *newbuf = (char*)
|
||||
realloc(g_keyboard_line->buffer,
|
||||
g_keyboard_line->size + len*2);
|
||||
|
||||
if (!newbuf)
|
||||
return false;
|
||||
|
||||
memmove(newbuf + g_keyboard_line->ptr + len,
|
||||
newbuf + g_keyboard_line->ptr,
|
||||
g_keyboard_line->size - g_keyboard_line->ptr + len);
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
newbuf[g_keyboard_line->ptr] = word[i];
|
||||
g_keyboard_line->ptr++;
|
||||
g_keyboard_line->size++;
|
||||
}
|
||||
|
||||
newbuf[g_keyboard_line->size] = '\0';
|
||||
|
||||
g_keyboard_line->buffer = newbuf;
|
||||
|
||||
if (word[0] == 0)
|
||||
{
|
||||
osk_last_codepoint = 0;
|
||||
osk_last_codepoint_len = 0;
|
||||
}
|
||||
else
|
||||
osk_update_last_codepoint(word);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* input_keyboard_start_line:
|
||||
* @userdata : Userdata.
|
||||
* @cb : Line complete callback function.
|
||||
*
|
||||
* Sets function pointer for keyboard line handle.
|
||||
*
|
||||
* The underlying buffer can be reallocated at any time
|
||||
* (or be NULL), but the pointer to it remains constant
|
||||
* throughout the objects lifetime.
|
||||
*
|
||||
* Returns: underlying buffer of the keyboard line.
|
||||
**/
|
||||
const char **input_keyboard_start_line(void *userdata,
|
||||
input_keyboard_line_complete_t cb)
|
||||
{
|
||||
input_keyboard_line_t *state = (input_keyboard_line_t*)
|
||||
calloc(1, sizeof(*state));
|
||||
if (!state)
|
||||
return NULL;
|
||||
|
||||
g_keyboard_line = state;
|
||||
g_keyboard_line->cb = cb;
|
||||
g_keyboard_line->userdata = userdata;
|
||||
|
||||
/* While reading keyboard line input, we have to block all hotkeys. */
|
||||
input_driver_keyboard_mapping_set_block(true);
|
||||
|
||||
return (const char**)&g_keyboard_line->buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
if (deferred_wait_keys)
|
||||
{
|
||||
if (down)
|
||||
return;
|
||||
|
||||
g_keyboard_press_cb = NULL;
|
||||
g_keyboard_press_data = NULL;
|
||||
input_driver_keyboard_mapping_set_block(false);
|
||||
deferred_wait_keys = false;
|
||||
}
|
||||
else if (g_keyboard_press_cb)
|
||||
{
|
||||
if (!down || code == RETROK_UNKNOWN)
|
||||
return;
|
||||
if (g_keyboard_press_cb(g_keyboard_press_data, code))
|
||||
return;
|
||||
deferred_wait_keys = true;
|
||||
}
|
||||
else if (g_keyboard_line)
|
||||
{
|
||||
if (!down)
|
||||
return;
|
||||
|
||||
switch (device)
|
||||
{
|
||||
case RETRO_DEVICE_POINTER:
|
||||
if (code != 0x12d)
|
||||
character = (char)code;
|
||||
/* fall-through */
|
||||
default:
|
||||
if (!input_keyboard_line_event(g_keyboard_line, character))
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Line is complete, can free it now. */
|
||||
input_keyboard_ctl(RARCH_INPUT_KEYBOARD_CTL_LINE_FREE, NULL);
|
||||
|
||||
/* Unblock all hotkeys. */
|
||||
input_driver_keyboard_mapping_set_block(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
retro_keyboard_event_t *key_event = NULL;
|
||||
rarch_ctl(RARCH_CTL_KEY_EVENT_GET, &key_event);
|
||||
|
||||
if (key_event && *key_event)
|
||||
(*key_event)(down, code, character, mod);
|
||||
}
|
||||
}
|
||||
|
||||
bool input_keyboard_ctl(enum rarch_input_keyboard_ctl_state state, void *data)
|
||||
{
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case RARCH_INPUT_KEYBOARD_CTL_LINE_FREE:
|
||||
if (g_keyboard_line)
|
||||
{
|
||||
free(g_keyboard_line->buffer);
|
||||
free(g_keyboard_line);
|
||||
}
|
||||
g_keyboard_line = NULL;
|
||||
break;
|
||||
case RARCH_INPUT_KEYBOARD_CTL_START_WAIT_KEYS:
|
||||
{
|
||||
input_keyboard_ctx_wait_t *keys = (input_keyboard_ctx_wait_t*)data;
|
||||
|
||||
if (!keys)
|
||||
return false;
|
||||
|
||||
g_keyboard_press_cb = keys->cb;
|
||||
g_keyboard_press_data = keys->userdata;
|
||||
}
|
||||
|
||||
/* While waiting for input, we have to block all hotkeys. */
|
||||
input_driver_keyboard_mapping_set_block(true);
|
||||
break;
|
||||
case RARCH_INPUT_KEYBOARD_CTL_CANCEL_WAIT_KEYS:
|
||||
g_keyboard_press_cb = NULL;
|
||||
g_keyboard_press_data = NULL;
|
||||
input_driver_keyboard_mapping_set_block(false);
|
||||
break;
|
||||
case RARCH_INPUT_KEYBOARD_CTL_DESTROY:
|
||||
input_driver_keyboard_linefeed_enable = false;
|
||||
break;
|
||||
case RARCH_INPUT_KEYBOARD_CTL_SET_LINEFEED_ENABLED:
|
||||
input_driver_keyboard_linefeed_enable = true;
|
||||
break;
|
||||
case RARCH_INPUT_KEYBOARD_CTL_UNSET_LINEFEED_ENABLED:
|
||||
input_driver_keyboard_linefeed_enable = false;
|
||||
break;
|
||||
case RARCH_INPUT_KEYBOARD_CTL_IS_LINEFEED_ENABLED:
|
||||
return input_driver_keyboard_linefeed_enable;
|
||||
case RARCH_INPUT_KEYBOARD_CTL_NONE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2017 - Daniel De Matteis
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef INPUT_KEYBOARD_H__
|
||||
#define INPUT_KEYBOARD_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <boolean.h>
|
||||
#include <retro_common_api.h>
|
||||
#include <libretro.h>
|
||||
|
||||
RETRO_BEGIN_DECLS
|
||||
|
||||
enum rarch_input_keyboard_ctl_state
|
||||
{
|
||||
RARCH_INPUT_KEYBOARD_CTL_NONE = 0,
|
||||
RARCH_INPUT_KEYBOARD_CTL_DESTROY,
|
||||
RARCH_INPUT_KEYBOARD_CTL_SET_LINEFEED_ENABLED,
|
||||
RARCH_INPUT_KEYBOARD_CTL_UNSET_LINEFEED_ENABLED,
|
||||
RARCH_INPUT_KEYBOARD_CTL_IS_LINEFEED_ENABLED,
|
||||
|
||||
RARCH_INPUT_KEYBOARD_CTL_LINE_FREE,
|
||||
|
||||
/*
|
||||
* Waits for keys to be pressed (used for binding
|
||||
* keys in the menu).
|
||||
* Callback returns false when all polling is done.
|
||||
**/
|
||||
RARCH_INPUT_KEYBOARD_CTL_START_WAIT_KEYS,
|
||||
|
||||
/* Cancels keyboard wait for keys function callback. */
|
||||
RARCH_INPUT_KEYBOARD_CTL_CANCEL_WAIT_KEYS
|
||||
};
|
||||
|
||||
/* Keyboard line reader. Handles textual input in a direct fashion. */
|
||||
typedef struct input_keyboard_line input_keyboard_line_t;
|
||||
|
||||
/** Line complete callback.
|
||||
* Calls back after return is pressed with the completed line.
|
||||
* Line can be NULL.
|
||||
**/
|
||||
typedef void (*input_keyboard_line_complete_t)(void *userdata,
|
||||
const char *line);
|
||||
|
||||
typedef bool (*input_keyboard_press_t)(void *userdata, unsigned code);
|
||||
|
||||
typedef struct input_keyboard_ctx_wait
|
||||
{
|
||||
void *userdata;
|
||||
input_keyboard_press_t cb;
|
||||
} input_keyboard_ctx_wait_t;
|
||||
|
||||
/**
|
||||
* 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 driver struct and libretro callbacks.
|
||||
**/
|
||||
void input_keyboard_event(bool down, unsigned code, uint32_t character,
|
||||
uint16_t mod, unsigned device);
|
||||
|
||||
bool input_keyboard_line_append(const char *word);
|
||||
|
||||
/**
|
||||
* input_keyboard_start_line:
|
||||
* @userdata : Userdata.
|
||||
* @cb : Line complete callback function.
|
||||
*
|
||||
* Sets function pointer for keyboard line handle.
|
||||
*
|
||||
* The underlying buffer can be reallocated at any time
|
||||
* (or be NULL), but the pointer to it remains constant
|
||||
* throughout the objects lifetime.
|
||||
*
|
||||
* Returns: underlying buffer of the keyboard line.
|
||||
**/
|
||||
const char **input_keyboard_start_line(void *userdata,
|
||||
input_keyboard_line_complete_t cb);
|
||||
|
||||
|
||||
bool input_keyboard_ctl(enum rarch_input_keyboard_ctl_state state, void *data);
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
||||
#endif
|
||||
|
@ -32,8 +32,8 @@
|
||||
#include "../verbosity.h"
|
||||
#include "../gfx/video_driver.h"
|
||||
|
||||
#include "input_driver.h"
|
||||
#include "input_overlay.h"
|
||||
#include "input_keyboard.h"
|
||||
|
||||
#define OVERLAY_GET_KEY(state, key) (((state)->keys[(key) / 32] >> ((key) % 32)) & 1)
|
||||
#define OVERLAY_SET_KEY(state, key) (state)->keys[(key) / 32] |= 1 << ((key) % 32)
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "../menu_driver.h"
|
||||
|
||||
#include "../../input/input_driver.h"
|
||||
#include "../../input/input_keyboard.h"
|
||||
#include "../../input/input_config.h"
|
||||
|
||||
#include "../../configuration.h"
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
#include <retro_common_api.h>
|
||||
|
||||
#include "../../input/input_keyboard.h"
|
||||
#include "../../input/input_driver.h"
|
||||
|
||||
RETRO_BEGIN_DECLS
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
#include "menu_osk.h"
|
||||
|
||||
#include "../../input/input_keyboard.h"
|
||||
#include "../../input/input_driver.h"
|
||||
|
||||
static const char *osk_grid[45] = {NULL};
|
||||
|
||||
|
@ -90,7 +90,6 @@
|
||||
#include "driver.h"
|
||||
#include "input/input_driver.h"
|
||||
#include "input/input_config.h"
|
||||
#include "input/input_keyboard.h"
|
||||
#include "msg_hash.h"
|
||||
#include "movie.h"
|
||||
#include "dirs.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user