diff --git a/input/input_driver.c b/input/input_driver.c index 5b1b87bad4..b8cb3d825c 100644 --- a/input/input_driver.c +++ b/input/input_driver.c @@ -37,6 +37,8 @@ #include "../verbosity.h" #include "../command.h" +#include "../menu/widgets/menu_input_dialog.h" + static const input_driver_t *input_drivers[] = { #ifdef __CELLOS_LV2__ &input_ps3, @@ -697,14 +699,14 @@ uint64_t input_menu_keys_pressed(void) if ( (((!input_driver_block_libretro_input && ((i < RARCH_FIRST_META_KEY))) || !input_driver_block_hotkey) && current_input->key_pressed) -#if 0 +#if 1 && settings->input.binds[0][i].valid #endif ) { int port; int port_max = 1; -#if 0 +#if 1 if (settings->input.all_users_control_menu) port_max = settings->input.max_users; @@ -748,6 +750,55 @@ uint64_t input_menu_keys_pressed(void) ret |= (UINT64_C(1) << i); } + const struct retro_keybind *binds[MAX_USERS] = {NULL}; + + if (menu_input_dialog_get_display_kb()) + return ret; + + if (current_input->input_state(current_input_data, binds, 0, + RETRO_DEVICE_KEYBOARD, 0, RETROK_RETURN)) + BIT32_SET(ret, settings->menu_ok_btn); + + if (current_input->input_state(current_input_data, binds, 0, + RETRO_DEVICE_KEYBOARD, 0, RETROK_BACKSPACE)) + BIT32_SET(ret, settings->menu_cancel_btn); + + if (current_input->input_state(current_input_data, binds, 0, + RETRO_DEVICE_KEYBOARD, 0, RETROK_SPACE)) + BIT32_SET(ret, settings->menu_default_btn); + + if (current_input->input_state(current_input_data, binds, 0, + RETRO_DEVICE_KEYBOARD, 0, RETROK_SLASH)) + BIT32_SET(ret, settings->menu_search_btn); + + if (current_input->input_state(current_input_data, binds, 0, + RETRO_DEVICE_KEYBOARD, 0, RETROK_RSHIFT)) + BIT32_SET(ret, settings->menu_info_btn); + + if (current_input->input_state(current_input_data, binds, 0, + RETRO_DEVICE_KEYBOARD, 0, RETROK_RIGHT)) + BIT32_SET(ret, RETRO_DEVICE_ID_JOYPAD_RIGHT); + + if (current_input->input_state(current_input_data, binds, 0, + RETRO_DEVICE_KEYBOARD, 0, RETROK_LEFT)) + BIT32_SET(ret, RETRO_DEVICE_ID_JOYPAD_LEFT); + + if (current_input->input_state(current_input_data, binds, 0, + RETRO_DEVICE_KEYBOARD, 0, RETROK_DOWN)) + BIT32_SET(ret, RETRO_DEVICE_ID_JOYPAD_DOWN); + + if (current_input->input_state(current_input_data, binds, 0, + RETRO_DEVICE_KEYBOARD, 0, RETROK_UP)) + BIT32_SET(ret, RETRO_DEVICE_ID_JOYPAD_UP); + + if (current_input->input_state(current_input_data, binds, 0, + RETRO_DEVICE_KEYBOARD, 0, settings->input.binds[0][RARCH_QUIT_KEY].key )) + BIT32_SET(ret, RARCH_QUIT_KEY); + + if (current_input->input_state(current_input_data, binds, 0, + RETRO_DEVICE_KEYBOARD, 0, settings->input.binds[0][RARCH_FULLSCREEN_TOGGLE_KEY].key )) + BIT32_SET(ret, RARCH_FULLSCREEN_TOGGLE_KEY); + return ret; } diff --git a/menu/menu_driver.c b/menu/menu_driver.c index 1baa4b0932..afe39fd68a 100644 --- a/menu/menu_driver.c +++ b/menu/menu_driver.c @@ -29,6 +29,7 @@ #include "menu_driver.h" #include "menu_cbs.h" #include "menu_display.h" +#include "menu_event.h" #include "menu_navigation.h" #include "widgets/menu_dialog.h" #include "widgets/menu_list.h" @@ -222,24 +223,27 @@ static void menu_input_key_event(bool down, unsigned keycode, (void)keycode; (void)mod; - if (character == '/') - menu_entry_action(NULL, 0, MENU_ACTION_SEARCH); +#if 0 + RARCH_LOG("down: %d, keycode: %d, mod: %d, character: %d\n", down, keycode, mod, character); +#endif + + menu_event_keyboard_set(down, (enum retro_key)keycode); } -static void menu_driver_toggle(bool latch) +static void menu_driver_toggle(bool on) { retro_keyboard_event_t *key_event = NULL; retro_keyboard_event_t *frontend_key_event = NULL; settings_t *settings = config_get_ptr(); - menu_driver_toggled = latch; + menu_driver_toggled = on; - if (!latch) + if (!on) menu_display_toggle_set_reason(MENU_TOGGLE_REASON_NONE); - menu_driver_ctl(RARCH_MENU_CTL_TOGGLE, &latch); + menu_driver_ctl(RARCH_MENU_CTL_TOGGLE, &on); - if (latch) + if (on) menu_driver_alive = true; else menu_driver_alive = false; @@ -761,12 +765,12 @@ bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data) break; case RARCH_MENU_CTL_TOGGLE: { - bool *latch = (bool*)data; - if (!latch) + bool *on = (bool*)data; + if (!on) return false; if (menu_driver_ctx && menu_driver_ctx->toggle) - menu_driver_ctx->toggle(menu_userdata, *latch); + menu_driver_ctx->toggle(menu_userdata, *on); } break; case RARCH_MENU_CTL_REFRESH: diff --git a/menu/menu_event.c b/menu/menu_event.c index 2f1dca3b4e..af44fc8f82 100644 --- a/menu/menu_event.c +++ b/menu/menu_event.c @@ -29,13 +29,20 @@ #include "menu_event.h" +#include "content.h" #include "menu_driver.h" #include "menu_input.h" #include "menu_animation.h" #include "menu_display.h" #include "menu_navigation.h" +#include "widgets/menu_dialog.h" + #include "../configuration.h" +#include "../retroarch.h" +#include "../runloop.h" + +static unsigned char menu_keyboard_key_state[RETROK_LAST]; static int menu_event_pointer(unsigned *action) { @@ -66,8 +73,29 @@ static int menu_event_pointer(unsigned *action) return 0; } +unsigned char menu_event_keyboard_is_set(enum retro_key key) +{ + return menu_keyboard_key_state[key]; +} + +void menu_event_keyboard_set(bool down, enum retro_key key) +{ + if (key == RETROK_UNKNOWN) + { + unsigned i; + + for (i = 0; i < RETROK_LAST; i++) + { + menu_keyboard_key_state[i] = (menu_keyboard_key_state[i] & 1) << 1; + } + } + else + menu_keyboard_key_state[key] = ((menu_keyboard_key_state[key] & 1) << 1) | down; +} + unsigned menu_event(uint64_t input, uint64_t trigger_input) { + unsigned i; menu_animation_ctx_delta_t delta; float delta_time; /* Used for key repeat */ @@ -215,6 +243,40 @@ unsigned menu_event(uint64_t input, uint64_t trigger_input) else if (trigger_input & (UINT64_C(1) << RARCH_MENU_TOGGLE)) ret = MENU_ACTION_TOGGLE; + if (menu_keyboard_key_state[RETROK_F11]) + { + command_event(CMD_EVENT_GRAB_MOUSE_TOGGLE, NULL); + menu_keyboard_key_state[RETROK_F11] = false; + } + + if (runloop_cmd_press(trigger_input, RARCH_QUIT_KEY)) + { + int should_we_quit = true; + + if (!runloop_is_quit_confirm()) + { + if (settings && settings->confirm_on_exit) + { + if (menu_dialog_is_active()) + should_we_quit = false; + else if (content_is_inited()) + { + if(menu_display_toggle_get_reason() != MENU_TOGGLE_REASON_USER) + menu_display_toggle_set_reason(MENU_TOGGLE_REASON_MESSAGE); + rarch_ctl(RARCH_CTL_MENU_RUNNING, NULL); + } + + menu_dialog_show_message(MENU_DIALOG_QUIT_CONFIRM, MENU_ENUM_LABEL_CONFIRM_ON_EXIT); + + should_we_quit = false; + } + + if ((settings && !settings->confirm_on_exit) || + should_we_quit) + return MENU_ACTION_QUIT; + } + } + mouse_enabled = settings->menu.mouse.enable; #ifdef HAVE_OVERLAY if (!mouse_enabled) diff --git a/menu/menu_event.h b/menu/menu_event.h index 3795ae4d0f..d6c9028421 100644 --- a/menu/menu_event.h +++ b/menu/menu_event.h @@ -22,6 +22,8 @@ #include +#include + RETRO_BEGIN_DECLS /* Send input code to menu for one frame. @@ -33,6 +35,10 @@ RETRO_BEGIN_DECLS */ unsigned menu_event(uint64_t input, uint64_t trigger_state); +void menu_event_keyboard_set(bool down, enum retro_key key); + +unsigned char menu_event_keyboard_is_set(enum retro_key key); + unsigned kbd_index; char kbd_grid[41]; bool kbd_upper; diff --git a/menu/menu_input.h b/menu/menu_input.h index c0ef63f172..90e30e3c3b 100644 --- a/menu/menu_input.h +++ b/menu/menu_input.h @@ -43,7 +43,8 @@ enum menu_action MENU_ACTION_SCROLL_UP, MENU_ACTION_TOGGLE, MENU_ACTION_POINTER_MOVED, - MENU_ACTION_POINTER_PRESSED + MENU_ACTION_POINTER_PRESSED, + MENU_ACTION_QUIT }; enum menu_input_pointer_state diff --git a/runloop.c b/runloop.c index 70fd7c77e0..3535fecbcb 100644 --- a/runloop.c +++ b/runloop.c @@ -93,6 +93,16 @@ #define runloop_cmd_menu_press(current_input, old_input, trigger_input) (BIT64_GET(trigger_input, RARCH_MENU_TOGGLE) || runloop_cmd_get_state_menu_toggle_button_combo(settings, current_input, old_input, trigger_input)) #endif +enum runloop_state +{ + RUNLOOP_STATE_NONE = 0, + RUNLOOP_STATE_ITERATE, + RUNLOOP_STATE_SLEEP, + RUNLOOP_STATE_MENU_ITERATE, + RUNLOOP_STATE_END, + RUNLOOP_STATE_QUIT +}; + static rarch_system_info_t runloop_system; static struct retro_frame_time_callback runloop_frame_time; static retro_keyboard_event_t runloop_key_event = NULL; @@ -715,16 +725,6 @@ void runloop_set_quit_confirm(bool on) runloop_quit_confirm = on; } -enum runloop_state -{ - RUNLOOP_STATE_NONE = 0, - RUNLOOP_STATE_ITERATE, - RUNLOOP_STATE_SLEEP, - RUNLOOP_STATE_MENU_ITERATE, - RUNLOOP_STATE_END, - RUNLOOP_STATE_QUIT -}; - /* Time to exit out of the main loop? * Reasons for exiting: * a) Shutdown environment callback was invoked. @@ -796,6 +796,10 @@ static INLINE int runloop_iterate_time_to_exit(bool quit_key_pressed) return -1; } +void runloop_external_state_checks(uint64_t trigger_input) +{ +} + static enum runloop_state runloop_check_state( settings_t *settings, uint64_t current_input, @@ -847,23 +851,6 @@ static enum runloop_state runloop_check_state( if (runloop_cmd_triggered(trigger_input, RARCH_GRAB_MOUSE_TOGGLE)) command_event(CMD_EVENT_GRAB_MOUSE_TOGGLE, NULL); -#ifdef HAVE_MENU - if (runloop_cmd_menu_press(current_input, old_input, trigger_input) || - rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL)) - { - if (menu_driver_ctl(RARCH_MENU_CTL_IS_ALIVE, NULL)) - { - if (rarch_ctl(RARCH_CTL_IS_INITED, NULL) && - !rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL)) - rarch_ctl(RARCH_CTL_MENU_RUNNING_FINISHED, NULL); - } - else - { - menu_display_toggle_set_reason(MENU_TOGGLE_REASON_USER); - rarch_ctl(RARCH_CTL_MENU_RUNNING, NULL); - } - } -#endif #ifdef HAVE_OVERLAY if (osk_enable && !input_keyboard_ctl( @@ -896,31 +883,77 @@ static enum runloop_state runloop_check_state( if (menu_driver_ctl(RARCH_MENU_CTL_IS_ALIVE, NULL)) { menu_ctx_iterate_t iter; - enum menu_action action = (enum menu_action)menu_event(current_input, trigger_input); - bool focused = settings->pause_nonactive ? video_driver_is_focused() : true; + bool skip = false; +#ifdef HAVE_OVERLAY + skip = osk_enable && BIT64_GET(trigger_input, settings->menu_ok_btn); +#endif - focused = focused && !ui_companion_is_on_foreground(); + if (!skip) + { + enum menu_action action = (enum menu_action)menu_event(current_input, trigger_input); + bool focused = settings->pause_nonactive ? video_driver_is_focused() : true; - iter.action = action; + focused = focused && !ui_companion_is_on_foreground(); - if (!menu_driver_ctl(RARCH_MENU_CTL_ITERATE, &iter)) - rarch_ctl(RARCH_CTL_MENU_RUNNING_FINISHED, NULL); + iter.action = action; - if (focused || !runloop_idle) - menu_driver_ctl(RARCH_MENU_CTL_RENDER, NULL); + if (!menu_driver_ctl(RARCH_MENU_CTL_ITERATE, &iter)) + rarch_ctl(RARCH_CTL_MENU_RUNNING_FINISHED, NULL); - if (!focused || runloop_idle) - return RUNLOOP_STATE_SLEEP; + if (focused || !runloop_idle) + menu_driver_ctl(RARCH_MENU_CTL_RENDER, NULL); + if (!focused) + return RUNLOOP_STATE_SLEEP; + + if (action == MENU_ACTION_QUIT) + return RUNLOOP_STATE_QUIT; + } + } +#endif + + if (runloop_idle) + return RUNLOOP_STATE_SLEEP; + +#ifdef HAVE_MENU + if (menu_event_keyboard_is_set(RETROK_F1) == 1) + { + if (menu_driver_ctl(RARCH_MENU_CTL_IS_ALIVE, NULL)) + { + if (rarch_ctl(RARCH_CTL_IS_INITED, NULL) && + !rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL)) + { + rarch_ctl(RARCH_CTL_MENU_RUNNING_FINISHED, NULL); + menu_event_keyboard_set(false, RETROK_F1); + } + } + } + else if ((!menu_event_keyboard_is_set(RETROK_F1) && runloop_cmd_menu_press(current_input, old_input, trigger_input)) || + rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL)) + { + if (menu_driver_ctl(RARCH_MENU_CTL_IS_ALIVE, NULL)) + { + if (rarch_ctl(RARCH_CTL_IS_INITED, NULL) && + !rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL)) + rarch_ctl(RARCH_CTL_MENU_RUNNING_FINISHED, NULL); + } + else + { + menu_display_toggle_set_reason(MENU_TOGGLE_REASON_USER); + rarch_ctl(RARCH_CTL_MENU_RUNNING, NULL); + } + } + else + menu_event_keyboard_set(false, RETROK_F1); + + if (menu_driver_ctl(RARCH_MENU_CTL_IS_ALIVE, NULL)) + { if (!settings->menu.throttle_framerate && !settings->fastforward_ratio) return RUNLOOP_STATE_MENU_ITERATE; return RUNLOOP_STATE_END; } #endif - - if (runloop_idle) - return RUNLOOP_STATE_SLEEP; if (settings->pause_nonactive) focused = video_driver_is_focused();