From 060753258a2791eecd036ab16e29fe4d9e4a4a48 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 11 Jun 2017 17:51:12 +0200 Subject: [PATCH] Combine input_driver.c and input_keyboard.c --- Makefile.common | 1 - gfx/common/win32_common.cpp | 2 +- gfx/common/x11_common.c | 2 +- gfx/drivers_context/wayland_ctx.c | 1 - griffin/griffin.c | 1 - input/drivers/rwebinput_input.c | 3 +- input/drivers/sdl_input.c | 1 - input/drivers/udev_input.c | 1 - input/drivers/wayland_input.c | 1 - input/drivers/wiiu_input.c | 4 +- input/drivers_joypad/dos_joypad.c | 1 - input/drivers_keyboard/keyboard_event_apple.c | 2 +- input/drivers_keyboard/keyboard_event_xkb.c | 1 - input/input_driver.c | 323 +++++++++++++++- input/input_driver.h | 73 ++++ input/input_keyboard.c | 348 ------------------ input/input_keyboard.h | 104 ------ input/input_overlay.c | 2 +- menu/widgets/menu_input_bind_dialog.c | 1 - menu/widgets/menu_input_dialog.h | 2 +- menu/widgets/menu_osk.c | 2 +- retroarch.c | 1 - 22 files changed, 404 insertions(+), 473 deletions(-) delete mode 100644 input/input_keyboard.c delete mode 100644 input/input_keyboard.h diff --git a/Makefile.common b/Makefile.common index 010482f056..31acfde9d7 100644 --- a/Makefile.common +++ b/Makefile.common @@ -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 \ diff --git a/gfx/common/win32_common.cpp b/gfx/common/win32_common.cpp index 157b9da1e7..3801f92700 100644 --- a/gfx/common/win32_common.cpp +++ b/gfx/common/win32_common.cpp @@ -41,7 +41,7 @@ #include #include #include "../../retroarch.h" -#include "../../input/input_keyboard.h" +#include "../../input/input_driver.h" #include "../../input/input_keymaps.h" #include "../video_thread_wrapper.h" #include diff --git a/gfx/common/x11_common.c b/gfx/common/x11_common.c index d0fe293d1f..a9d2fcb334 100644 --- a/gfx/common/x11_common.c +++ b/gfx/common/x11_common.c @@ -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" diff --git a/gfx/drivers_context/wayland_ctx.c b/gfx/drivers_context/wayland_ctx.c index f423b4c0b2..f4b272145a 100644 --- a/gfx/drivers_context/wayland_ctx.c +++ b/gfx/drivers_context/wayland_ctx.c @@ -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 { diff --git a/griffin/griffin.c b/griffin/griffin.c index be1a1da76b..5d16cfa507 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -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" diff --git a/input/drivers/rwebinput_input.c b/input/drivers/rwebinput_input.c index d8b0c72cd5..47af72d4ca 100644 --- a/input/drivers/rwebinput_input.c +++ b/input/drivers/rwebinput_input.c @@ -21,9 +21,8 @@ #include #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" diff --git a/input/drivers/sdl_input.c b/input/drivers/sdl_input.c index 08580661ea..7944f18cd7 100644 --- a/input/drivers/sdl_input.c +++ b/input/drivers/sdl_input.c @@ -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" diff --git a/input/drivers/udev_input.c b/input/drivers/udev_input.c index bb85b13336..1447074d96 100644 --- a/input/drivers/udev_input.c +++ b/input/drivers/udev_input.c @@ -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" diff --git a/input/drivers/wayland_input.c b/input/drivers/wayland_input.c index 3ff9b2356a..8ff137c3c6 100644 --- a/input/drivers/wayland_input.c +++ b/input/drivers/wayland_input.c @@ -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" diff --git a/input/drivers/wiiu_input.c b/input/drivers/wiiu_input.c index bf3ea76589..dcf19bbc2e 100644 --- a/input/drivers/wiiu_input.c +++ b/input/drivers/wiiu_input.c @@ -21,15 +21,15 @@ #include #include +#include + #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 #include "wiiu_dbg.h" diff --git a/input/drivers_joypad/dos_joypad.c b/input/drivers_joypad/dos_joypad.c index 755c51874c..fae3480b24 100644 --- a/input/drivers_joypad/dos_joypad.c +++ b/input/drivers_joypad/dos_joypad.c @@ -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" diff --git a/input/drivers_keyboard/keyboard_event_apple.c b/input/drivers_keyboard/keyboard_event_apple.c index d209bc76bd..6470adcccf 100644 --- a/input/drivers_keyboard/keyboard_event_apple.c +++ b/input/drivers_keyboard/keyboard_event_apple.c @@ -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" diff --git a/input/drivers_keyboard/keyboard_event_xkb.c b/input/drivers_keyboard/keyboard_event_xkb.c index 707aacfc9e..eae2f1e4c0 100644 --- a/input/drivers_keyboard/keyboard_event_xkb.c +++ b/input/drivers_keyboard/keyboard_event_xkb.c @@ -25,7 +25,6 @@ #include "../input_driver.h" #include "../input_keymaps.h" -#include "../input_keyboard.h" #include "../../configuration.h" #define MOD_MAP_SIZE 5 diff --git a/input/input_driver.c b/input/input_driver.c index 63e528ebf4..8eea99c10f 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -18,6 +18,7 @@ #include #include +#include #include #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; +} diff --git a/input/input_driver.h b/input/input_driver.h index 255f68d167..dbba226807 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -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; diff --git a/input/input_keyboard.c b/input/input_keyboard.c deleted file mode 100644 index 00f6d65cd6..0000000000 --- a/input/input_keyboard.c +++ /dev/null @@ -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 . - */ - -#include -#include -#include - -#include - -#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; -} diff --git a/input/input_keyboard.h b/input/input_keyboard.h deleted file mode 100644 index a94ae59f9c..0000000000 --- a/input/input_keyboard.h +++ /dev/null @@ -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 . - */ - -#ifndef INPUT_KEYBOARD_H__ -#define INPUT_KEYBOARD_H__ - -#include - -#include -#include -#include - -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 - diff --git a/input/input_overlay.c b/input/input_overlay.c index c690cdfff1..5cb48e6c50 100644 --- a/input/input_overlay.c +++ b/input/input_overlay.c @@ -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) diff --git a/menu/widgets/menu_input_bind_dialog.c b/menu/widgets/menu_input_bind_dialog.c index 8310462e17..be900689b6 100644 --- a/menu/widgets/menu_input_bind_dialog.c +++ b/menu/widgets/menu_input_bind_dialog.c @@ -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" diff --git a/menu/widgets/menu_input_dialog.h b/menu/widgets/menu_input_dialog.h index a1e5c31e10..7cc048bb4f 100644 --- a/menu/widgets/menu_input_dialog.h +++ b/menu/widgets/menu_input_dialog.h @@ -24,7 +24,7 @@ #include -#include "../../input/input_keyboard.h" +#include "../../input/input_driver.h" RETRO_BEGIN_DECLS diff --git a/menu/widgets/menu_osk.c b/menu/widgets/menu_osk.c index d853d9d52d..fa354ad085 100644 --- a/menu/widgets/menu_osk.c +++ b/menu/widgets/menu_osk.c @@ -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}; diff --git a/retroarch.c b/retroarch.c index 9fcafd9fe7..e1573a27b6 100644 --- a/retroarch.c +++ b/retroarch.c @@ -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"