Search box usability improvements (#15617)

This commit is contained in:
sonninnos 2023-08-18 22:38:29 +03:00 committed by GitHub
parent ee7735f82e
commit c708187cd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 28 deletions

View File

@ -1050,6 +1050,27 @@ void input_keyboard_line_append(
keyboard_line->buffer = newbuf;
}
void input_keyboard_line_clear(input_driver_state_t *input_st)
{
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;
}
void input_keyboard_line_free(input_driver_state_t *input_st)
{
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;
}
const char **input_keyboard_start_line(
void *userdata,
struct input_keyboard_line *keyboard_line,
@ -6313,6 +6334,23 @@ void input_driver_collect_system_input(input_driver_state_t *input_st,
BIT256_SET_PTR(current_bits, ids[i][1]);
}
}
else if (display_kb
&& current_input
&& current_input->input_state)
{
/* Set RetroPad Select bit when pressing Escape while keyboard
* is open in order to clear the input window and close it */
if (current_input->input_state(
input_st->current_data,
joypad,
sec_joypad,
&joypad_info,
(const retro_keybind_set *)input_config_binds,
(input_st->flags & INP_FLAG_KB_MAPPING_BLOCKED) ? true : false,
0,
RETRO_DEVICE_KEYBOARD, 0, RETROK_ESCAPE))
BIT256_SET_PTR(current_bits, RETRO_DEVICE_ID_JOYPAD_SELECT);
}
}
else
#endif /* HAVE_MENU */
@ -6552,14 +6590,7 @@ void input_keyboard_event(bool down, unsigned code,
return;
/* 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;
input_keyboard_line_free(input_st);
/* Unblock all hotkeys. */
input_st->flags &= ~INP_FLAG_KB_MAPPING_BLOCKED;

View File

@ -930,6 +930,9 @@ void input_keyboard_line_append(
struct input_keyboard_line *keyboard_line,
const char *word, size_t len);
void input_keyboard_line_clear(input_driver_state_t *input_st);
void input_keyboard_line_free(input_driver_state_t *input_st);
/**
* input_keyboard_start_line:
* @userdata : Userdata.

View File

@ -5488,12 +5488,29 @@ unsigned menu_event(
strlen(input_st->osk_grid[input_st->osk_ptr]));
}
/* Cancel: Send backspace if buffer is not empty, otherwise close window */
if (BIT256_GET_PTR(p_trigger_input, menu_cancel_btn))
input_keyboard_event(true, '\x7f', '\x7f',
0, RETRO_DEVICE_KEYBOARD);
{
if (input_st->keyboard_line.size)
input_keyboard_event(true, '\x7f', '\x7f', 0, RETRO_DEVICE_KEYBOARD);
else
input_keyboard_event(true, '\n', '\n', 0, RETRO_DEVICE_KEYBOARD);
}
/* send return key to close keyboard input window */
if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_START))
/* Select: Clear and close the keyboard input window */
if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_SELECT))
{
input_keyboard_line_clear(input_st);
input_keyboard_event(true, '\n', '\n', 0, RETRO_DEVICE_KEYBOARD);
}
/* Scan: Clear the keyboard input window */
if (BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_Y))
input_keyboard_line_clear(input_st);
/* Start + Search: Send return key to close keyboard input window */
if ( BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_START)
|| BIT256_GET_PTR(p_trigger_input, RETRO_DEVICE_ID_JOYPAD_X))
input_keyboard_event(true, '\n', '\n', 0, RETRO_DEVICE_KEYBOARD);
#ifdef HAVE_MIST
@ -7849,14 +7866,7 @@ bool menu_input_dialog_start_search(void)
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SEARCH),
sizeof(menu_st->input_dialog_kb_label));
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;
input_keyboard_line_free(input_st);
#ifdef HAVE_ACCESSIBILITY
if (is_accessibility_enabled(
@ -7910,14 +7920,7 @@ bool menu_input_dialog_start(menu_input_ctx_line_t *line)
menu_st->input_dialog_kb_type = line->type;
menu_st->input_dialog_kb_idx = line->idx;
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;
input_keyboard_line_free(input_st);
#ifdef HAVE_ACCESSIBILITY
if (is_accessibility_enabled(