@@ -5577,7 +5577,7 @@ void input_pad_connect(unsigned port, input_device_driver_t *driver)
55775577static bool input_keys_pressed_other_sources (
55785578 input_driver_state_t * input_st ,
55795579 unsigned i ,
5580- input_bits_t * p_new_state )
5580+ input_bits_t * p_new_state )
55815581{
55825582#ifdef HAVE_COMMAND
55835583 int j ;
@@ -5623,8 +5623,10 @@ static void input_keys_pressed(
56235623 bool input_hotkey_device_merge )
56245624{
56255625 unsigned i ;
5626+ int32_t ret = 0 ;
56265627 input_driver_state_t * input_st = & input_driver_st ;
56275628 bool block_hotkey [RARCH_BIND_LIST_END ];
5629+ bool any_pressed = false;
56285630 bool libretro_hotkey_set =
56295631 binds [port ][RARCH_ENABLE_HOTKEY ].joykey != NO_BTN
56305632 || binds [port ][RARCH_ENABLE_HOTKEY ].joyaxis != AXIS_NONE
@@ -5660,75 +5662,71 @@ static void input_keys_pressed(
56605662 input_st -> flags |= INP_FLAG_BLOCK_LIBRETRO_INPUT ;
56615663 }
56625664 else
5663- {
5664- input_st -> input_hotkey_block_counter = 0 ;
56655665 input_st -> flags |= INP_FLAG_BLOCK_HOTKEY ;
5666- }
56675666 }
56685667
5669- if (!is_menu && binds [port ][RARCH_GAME_FOCUS_TOGGLE ].valid )
5670- {
5671- const struct retro_keybind * focus_binds_auto =
5672- & input_autoconf_binds [port ][RARCH_GAME_FOCUS_TOGGLE ];
5673- const struct retro_keybind * focus_normal =
5674- & binds [port ][RARCH_GAME_FOCUS_TOGGLE ];
5668+ /* Prevent triggering menu actions after binding */
5669+ if ( !(input_st -> flags & INP_FLAG_MENU_PRESS_PENDING )
5670+ && menu_state_get_ptr ()-> input_driver_flushing_input )
5671+ input_st -> flags |= INP_FLAG_WAIT_INPUT_RELEASE ;
56755672
5676- /* Allows Game Focus toggle hotkey to still work
5677- * even though every hotkey is blocked */
5678- if (CHECK_INPUT_DRIVER_BLOCK_HOTKEY (focus_normal , focus_binds_auto ))
5679- {
5680- if (input_state_wrap (
5681- input_st -> current_driver ,
5682- input_st -> current_data ,
5683- input_st -> primary_joypad ,
5684- sec_joypad ,
5685- joypad_info ,
5686- binds ,
5687- (input_st -> flags & INP_FLAG_KB_MAPPING_BLOCKED ) ? true : false,
5688- port , RETRO_DEVICE_JOYPAD , 0 ,
5689- RARCH_GAME_FOCUS_TOGGLE ))
5690- input_st -> flags &= ~INP_FLAG_BLOCK_HOTKEY ;
5691- }
5692- }
5673+ /* Check libretro input if emulated device type is active,
5674+ * except device type must be always active in menu. */
5675+ if ( !(input_st -> flags & INP_FLAG_BLOCK_LIBRETRO_INPUT )
5676+ && !(!is_menu && !input_config_get_device (port )))
5677+ ret = input_state_wrap (
5678+ input_st -> current_driver ,
5679+ input_st -> current_data ,
5680+ input_st -> primary_joypad ,
5681+ sec_joypad ,
5682+ joypad_info ,
5683+ binds ,
5684+ (input_st -> flags & INP_FLAG_KB_MAPPING_BLOCKED ) ? true : false,
5685+ port , RETRO_DEVICE_JOYPAD , 0 ,
5686+ RETRO_DEVICE_ID_JOYPAD_MASK );
56935687
5688+ for (i = 0 ; i < RARCH_FIRST_CUSTOM_BIND ; i ++ )
56945689 {
5695- int32_t ret = 0 ;
5696- bool libretro_input_pressed = false;
5697-
5698- /* Check libretro input if emulated device type is active,
5699- * except device type must be always active in menu. */
5700- if ( !(input_st -> flags & INP_FLAG_BLOCK_LIBRETRO_INPUT )
5701- && !(!is_menu && !input_config_get_device (port )))
5702- ret = input_state_wrap (
5703- input_st -> current_driver ,
5704- input_st -> current_data ,
5705- input_st -> primary_joypad ,
5706- sec_joypad ,
5707- joypad_info ,
5708- binds ,
5709- (input_st -> flags & INP_FLAG_KB_MAPPING_BLOCKED ) ? true : false,
5710- port , RETRO_DEVICE_JOYPAD , 0 ,
5711- RETRO_DEVICE_ID_JOYPAD_MASK );
5712-
5713- for (i = 0 ; i < RARCH_FIRST_CUSTOM_BIND ; i ++ )
5690+ if ( (ret & (UINT64_C (1 ) << i ))
5691+ || input_keys_pressed_other_sources (input_st , i , p_new_state ))
57145692 {
5715- if ( (ret & (UINT64_C (1 ) << i ))
5716- || input_keys_pressed_other_sources (input_st , i , p_new_state ))
5717- {
5718- BIT256_SET_PTR (p_new_state , i );
5719- libretro_input_pressed = true;
5720- }
5693+ any_pressed = true;
5694+ if (input_st -> flags & INP_FLAG_WAIT_INPUT_RELEASE )
5695+ continue ;
5696+
5697+ BIT256_SET_PTR (p_new_state , i );
57215698 }
5699+ }
57225700
5723- if (!libretro_input_pressed )
5701+ /* Read autoconf menu toggle regardless of 'enable_hotkey'
5702+ * unless 'enable_hotkey' is set in autoconf. */
5703+ if ( !any_pressed
5704+ && !(input_st -> flags & INP_FLAG_WAIT_INPUT_RELEASE )
5705+ && (input_autoconf_binds [port ][RARCH_MENU_TOGGLE ].joykey != NO_BTN )
5706+ && ( input_autoconf_binds [port ][RARCH_ENABLE_HOTKEY ].joykey == input_autoconf_binds [port ][RARCH_MENU_TOGGLE ].joykey
5707+ || input_autoconf_binds [port ][RARCH_ENABLE_HOTKEY ].joykey == NO_BTN )
5708+ && ( binds [port ][RARCH_MENU_TOGGLE ].joykey == input_autoconf_binds [port ][RARCH_MENU_TOGGLE ].joykey
5709+ || binds [port ][RARCH_MENU_TOGGLE ].joykey == NO_BTN ))
5710+ {
5711+ /* Ignore keyboard menu toggle button and check
5712+ * joypad menu toggle button for pressing
5713+ * it without 'enable_hotkey', because Guide button
5714+ * is not part of the usual buttons. */
5715+ i = RARCH_MENU_TOGGLE ;
5716+
5717+ if (!(binds [port ][i ].valid
5718+ && input_state_wrap (
5719+ input_st -> current_driver ,
5720+ input_st -> current_data ,
5721+ input_st -> primary_joypad ,
5722+ sec_joypad ,
5723+ joypad_info ,
5724+ binds ,
5725+ (input_st -> flags & INP_FLAG_KB_MAPPING_BLOCKED ) ? true : false,
5726+ port , RETRO_DEVICE_KEYBOARD , 0 ,
5727+ input_config_binds [port ][i ].key )))
57245728 {
5725- /* Ignore keyboard menu toggle button and check
5726- * joypad menu toggle button for pressing
5727- * it without 'enable_hotkey', because Guide button
5728- * is not part of the usual buttons. */
5729- i = RARCH_MENU_TOGGLE ;
5730-
5731- if (!(binds [port ][i ].valid
5729+ bool bit_pressed = binds [port ][i ].valid
57325730 && input_state_wrap (
57335731 input_st -> current_driver ,
57345732 input_st -> current_data ,
@@ -5737,31 +5735,42 @@ static void input_keys_pressed(
57375735 joypad_info ,
57385736 binds ,
57395737 (input_st -> flags & INP_FLAG_KB_MAPPING_BLOCKED ) ? true : false,
5740- port , RETRO_DEVICE_KEYBOARD , 0 ,
5741- input_config_binds [port ][i ].key )))
5742- {
5743- bool bit_pressed = binds [port ][i ].valid
5744- && input_state_wrap (
5745- input_st -> current_driver ,
5746- input_st -> current_data ,
5747- input_st -> primary_joypad ,
5748- sec_joypad ,
5749- joypad_info ,
5750- binds ,
5751- (input_st -> flags & INP_FLAG_KB_MAPPING_BLOCKED ) ? true : false,
5752- port , RETRO_DEVICE_JOYPAD , 0 , i );
5738+ port , RETRO_DEVICE_JOYPAD , 0 , i );
57535739
5754- if (
5755- bit_pressed
5756- || BIT64_GET (lifecycle_state , i )
5757- || input_keys_pressed_other_sources (input_st , i , p_new_state ))
5758- {
5759- BIT256_SET_PTR (p_new_state , i );
5760- }
5761- }
5740+ if ( bit_pressed
5741+ || BIT64_GET (lifecycle_state , i )
5742+ || input_keys_pressed_other_sources (input_st , i , p_new_state ))
5743+ input_st -> flags |= INP_FLAG_MENU_PRESS_PENDING ;
5744+ else if (input_st -> flags & INP_FLAG_MENU_PRESS_PENDING )
5745+ /* Also set 'enable_hotkey' to prevent hotkey delay untrigger */
5746+ BIT256_SET_PTR (p_new_state , RARCH_ENABLE_HOTKEY );
57625747 }
57635748 }
57645749
5750+ /* Ignore hotkey block delay when menu toggle and hotkey enabler share the same key */
5751+ if ( !any_pressed
5752+ && !(input_st -> flags & INP_FLAG_WAIT_INPUT_RELEASE )
5753+ && binds [port ][RARCH_MENU_TOGGLE ].key == binds [port ][RARCH_ENABLE_HOTKEY ].key )
5754+ {
5755+ i = RARCH_MENU_TOGGLE ;
5756+
5757+ if ( binds [port ][i ].valid
5758+ && input_state_wrap (
5759+ input_st -> current_driver ,
5760+ input_st -> current_data ,
5761+ input_st -> primary_joypad ,
5762+ sec_joypad ,
5763+ joypad_info ,
5764+ binds ,
5765+ (input_st -> flags & INP_FLAG_KB_MAPPING_BLOCKED ) ? true : false,
5766+ port , RETRO_DEVICE_KEYBOARD , 0 ,
5767+ input_config_binds [port ][i ].key ))
5768+ input_st -> flags |= INP_FLAG_MENU_PRESS_PENDING ;
5769+ else if (input_st -> flags & INP_FLAG_MENU_PRESS_PENDING )
5770+ /* Also set 'enable_hotkey' to prevent hotkey delay untrigger */
5771+ BIT256_SET_PTR (p_new_state , RARCH_ENABLE_HOTKEY );
5772+ }
5773+
57655774 /* Hotkeys are only relevant for first port */
57665775 if (port > 0 )
57675776 return ;
@@ -5869,7 +5878,6 @@ static void input_keys_pressed(
58695878 port , RETRO_DEVICE_JOYPAD , 0 ,
58705879 i ))
58715880 {
5872-
58735881 /* Only block if keyboard is not pressed */
58745882 if (!keyboard_hotkey_pressed )
58755883 block_hotkey [i ] = true;
@@ -5885,41 +5893,86 @@ static void input_keys_pressed(
58855893 block_hotkey [i ] = false;
58865894 }
58875895
5896+ if (!is_menu && binds [port ][RARCH_GAME_FOCUS_TOGGLE ].valid )
58885897 {
5889- for (i = RARCH_FIRST_META_KEY ; i < RARCH_BIND_LIST_END ; i ++ )
5898+ /* Never block Game Focus toggle hotkey */
5899+ block_hotkey [RARCH_GAME_FOCUS_TOGGLE ] = false;
5900+ }
5901+
5902+ for (i = RARCH_FIRST_META_KEY ; i < RARCH_BIND_LIST_END ; i ++ )
5903+ {
5904+ bool other_pressed = input_keys_pressed_other_sources (input_st , i , p_new_state );
5905+ bool bit_pressed = binds [port ][i ].valid
5906+ && input_state_wrap (
5907+ input_st -> current_driver ,
5908+ input_st -> current_data ,
5909+ input_st -> primary_joypad ,
5910+ sec_joypad ,
5911+ joypad_info ,
5912+ binds ,
5913+ (input_st -> flags & INP_FLAG_KB_MAPPING_BLOCKED ) ? true : false,
5914+ port , RETRO_DEVICE_JOYPAD , 0 ,
5915+ i );
5916+
5917+ if ( bit_pressed
5918+ || other_pressed
5919+ || BIT64_GET (lifecycle_state , i ))
58905920 {
5891- bool other_pressed = input_keys_pressed_other_sources (input_st , i , p_new_state );
5892- bool bit_pressed = binds [port ][i ].valid
5893- && input_state_wrap (
5894- input_st -> current_driver ,
5895- input_st -> current_data ,
5896- input_st -> primary_joypad ,
5897- sec_joypad ,
5898- joypad_info ,
5899- binds ,
5900- (input_st -> flags & INP_FLAG_KB_MAPPING_BLOCKED ) ? true : false,
5901- port , RETRO_DEVICE_JOYPAD , 0 ,
5902- i );
5921+ any_pressed = true;
5922+ if (input_st -> flags & INP_FLAG_WAIT_INPUT_RELEASE )
5923+ continue ;
59035924
5904- if ( bit_pressed
5905- || other_pressed
5906- || BIT64_GET (lifecycle_state , i ))
5925+ if (libretro_hotkey_set || keyboard_hotkey_set )
5926+ {
5927+ /* Do not block "other source" (input overlay) presses */
5928+ if (block_hotkey [i ] && !other_pressed )
5929+ continue ;
5930+ }
5931+
5932+ /* Set menu toggle on release */
5933+ if (i == RARCH_MENU_TOGGLE )
59075934 {
5908- if (libretro_hotkey_set || keyboard_hotkey_set )
5935+ if (!( input_st -> flags & INP_FLAG_MENU_PRESS_PENDING ) )
59095936 {
5910- /* Do not block "other source" (input overlay) presses */
5911- if (block_hotkey [i ] && !other_pressed )
5912- continue ;
5937+ input_st -> flags |= INP_FLAG_MENU_PRESS_PENDING ;
5938+ input_st -> flags &= ~INP_FLAG_MENU_PRESS_CANCEL ;
59135939 }
5940+ continue ;
5941+ }
5942+ else if (i != RARCH_ENABLE_HOTKEY )
5943+ input_st -> flags |= INP_FLAG_MENU_PRESS_CANCEL ;
59145944
5915- BIT256_SET_PTR (p_new_state , i );
5945+ BIT256_SET_PTR (p_new_state , i );
5946+ }
5947+ else
5948+ {
5949+ if (i == RARCH_MENU_TOGGLE )
5950+ {
5951+ /* Untrigger menu if press was shorter than hotkey block delay */
5952+ if ( (input_st -> flags & INP_FLAG_MENU_PRESS_PENDING )
5953+ && !(input_st -> flags & INP_FLAG_MENU_PRESS_CANCEL )
5954+ && !BIT256_GET_PTR (p_new_state , RARCH_ENABLE_HOTKEY )
5955+ && input_st -> input_hotkey_block_counter
5956+ && input_st -> input_hotkey_block_counter < input_hotkey_block_delay )
5957+ input_st -> flags &= ~INP_FLAG_MENU_PRESS_PENDING ;
5958+
5959+ if (input_st -> flags & INP_FLAG_MENU_PRESS_PENDING )
5960+ {
5961+ /* Forget menu press if any other hotkey was pressed */
5962+ if (!(input_st -> flags & INP_FLAG_MENU_PRESS_CANCEL ))
5963+ BIT256_SET_PTR (p_new_state , i );
59165964
5917- /* Ignore all other hotkeys if menu toggle is pressed */
5918- if (i == RARCH_MENU_TOGGLE )
5919- break ;
5965+ input_st -> flags &= ~(INP_FLAG_MENU_PRESS_PENDING | INP_FLAG_MENU_PRESS_CANCEL );
5966+ }
59205967 }
59215968 }
59225969 }
5970+
5971+ if ((input_st -> flags & INP_FLAG_WAIT_INPUT_RELEASE ) && !any_pressed )
5972+ input_st -> flags &= ~INP_FLAG_WAIT_INPUT_RELEASE ;
5973+
5974+ if (input_st -> flags & INP_FLAG_BLOCK_HOTKEY )
5975+ input_st -> input_hotkey_block_counter = 0 ;
59235976}
59245977
59255978#ifdef HAVE_BSV_MOVIE
@@ -7745,20 +7798,19 @@ void input_driver_collect_system_input(input_driver_state_t *input_st,
77457798 {RETROK_PAGEDOWN , RETRO_DEVICE_ID_JOYPAD_R },
77467799 {RETROK_HOME , RETRO_DEVICE_ID_JOYPAD_L3 },
77477800 {RETROK_END , RETRO_DEVICE_ID_JOYPAD_R3 },
7801+ /* Extra keys read regardless of 'enable_hotkey' */
77487802 {0 , RARCH_QUIT_KEY }, /* 14 */
77497803 {0 , RARCH_FULLSCREEN_TOGGLE_KEY },
77507804 {0 , RARCH_UI_COMPANION_TOGGLE },
77517805 {0 , RARCH_FPS_TOGGLE },
77527806 {0 , RARCH_NETPLAY_HOST_TOGGLE },
7753- {0 , RARCH_MENU_TOGGLE },
77547807 };
77557808
77567809 ids [14 ][0 ] = input_config_binds [0 ][RARCH_QUIT_KEY ].key ;
77577810 ids [15 ][0 ] = input_config_binds [0 ][RARCH_FULLSCREEN_TOGGLE_KEY ].key ;
77587811 ids [16 ][0 ] = input_config_binds [0 ][RARCH_UI_COMPANION_TOGGLE ].key ;
77597812 ids [17 ][0 ] = input_config_binds [0 ][RARCH_FPS_TOGGLE ].key ;
77607813 ids [18 ][0 ] = input_config_binds [0 ][RARCH_NETPLAY_HOST_TOGGLE ].key ;
7761- ids [19 ][0 ] = input_config_binds [0 ][RARCH_MENU_TOGGLE ].key ;
77627814
77637815 if (settings -> bools .input_menu_swap_ok_cancel_buttons )
77647816 {
0 commit comments