From 149beaf06133577cdb552137351ad3b3af5967bb Mon Sep 17 00:00:00 2001 From: sonninnos Date: Thu, 29 Jul 2021 00:28:26 +0300 Subject: [PATCH] 'Automatic Mouse Grab' option --- configuration.c | 1 + configuration.h | 1 + intl/msg_hash_lbl.h | 4 ++++ intl/msg_hash_us.h | 8 ++++++++ menu/cbs/menu_cbs_sublabel.c | 4 ++++ menu/menu_displaylist.c | 4 ++++ menu/menu_setting.c | 16 ++++++++++++++++ msg_hash.h | 1 + retroarch.c | 12 +++++++++++- retroarch_data.h | 1 + 10 files changed, 51 insertions(+), 1 deletion(-) diff --git a/configuration.c b/configuration.c index c497b103ac..1e3b5e7a7f 100644 --- a/configuration.c +++ b/configuration.c @@ -1820,6 +1820,7 @@ static struct config_bool_setting *populate_settings_bool( SETTING_BOOL("show_hidden_files", &settings->bools.show_hidden_files, true, DEFAULT_SHOW_HIDDEN_FILES, false); SETTING_BOOL("use_last_start_directory", &settings->bools.use_last_start_directory, true, DEFAULT_USE_LAST_START_DIRECTORY, false); SETTING_BOOL("input_autodetect_enable", &settings->bools.input_autodetect_enable, true, input_autodetect_enable, false); + SETTING_BOOL("input_auto_mouse_grab", &settings->bools.input_auto_mouse_grab, true, false, false); #if defined(HAVE_DINPUT) || defined(HAVE_WINRAWINPUT) SETTING_BOOL("input_nowinkey_enable", &settings->bools.input_nowinkey_enable, true, false, false); #endif diff --git a/configuration.h b/configuration.h index b5b326cc9e..7ff805481c 100644 --- a/configuration.h +++ b/configuration.h @@ -558,6 +558,7 @@ typedef struct settings bool input_backtouch_toggle; bool input_small_keyboard_enable; bool input_keyboard_gamepad_enable; + bool input_auto_mouse_grab; #if defined(HAVE_DINPUT) || defined(HAVE_WINRAWINPUT) bool input_nowinkey_enable; #endif diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index fe048346b5..e5f079d144 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -1408,6 +1408,10 @@ MSG_HASH( MENU_ENUM_LABEL_INPUT_SENSORS_ENABLE, "input_sensors_enable" ) +MSG_HASH( + MENU_ENUM_LABEL_INPUT_AUTO_MOUSE_GRAB, + "input_auto_mouse_grab" + ) MSG_HASH( MENU_ENUM_LABEL_INPUT_AUTO_GAME_FOCUS, "input_auto_game_focus" diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 6cd7527e9c..66c7fa1631 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -2136,6 +2136,14 @@ MSG_HASH( MENU_ENUM_SUBLABEL_INPUT_SENSORS_ENABLE, "Enable input from accelerometer, gyroscope and illuminance sensors, if supported by the current hardware. May have a performance impact and/or increase power drain on some platforms." ) +MSG_HASH( + MENU_ENUM_LABEL_VALUE_INPUT_AUTO_MOUSE_GRAB, + "Automatic Mouse Grab" + ) +MSG_HASH( + MENU_ENUM_SUBLABEL_INPUT_AUTO_MOUSE_GRAB, + "Enable mouse grab on application focus." + ) MSG_HASH( MENU_ENUM_LABEL_VALUE_INPUT_AUTO_GAME_FOCUS, "Auto Enable 'Game Focus' Mode" diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index 44dc396dcd..d61e6179bf 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -528,6 +528,7 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_autodetect_enable, MENU_ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_nowinkey_enable, MENU_ENUM_SUBLABEL_INPUT_NOWINKEY_ENABLE) #endif DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_sensors_enable, MENU_ENUM_SUBLABEL_INPUT_SENSORS_ENABLE) +DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_auto_mouse_grab, MENU_ENUM_SUBLABEL_INPUT_AUTO_MOUSE_GRAB) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_auto_game_focus, MENU_ENUM_SUBLABEL_INPUT_AUTO_GAME_FOCUS) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_swap_ok_cancel, MENU_ENUM_SUBLABEL_MENU_INPUT_SWAP_OK_CANCEL) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_pause_libretro, MENU_ENUM_SUBLABEL_PAUSE_LIBRETRO) @@ -3061,6 +3062,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_INPUT_SENSORS_ENABLE: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_sensors_enable); break; + case MENU_ENUM_LABEL_INPUT_AUTO_MOUSE_GRAB: + BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_auto_mouse_grab); + break; case MENU_ENUM_LABEL_INPUT_AUTO_GAME_FOCUS: BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_auto_game_focus); break; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index def33619ce..bc195bd6cd 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -6344,6 +6344,10 @@ unsigned menu_displaylist_build_list( MENU_ENUM_LABEL_INPUT_SENSORS_ENABLE, PARSE_ONLY_BOOL, false) == 0) count++; + if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list, + MENU_ENUM_LABEL_INPUT_AUTO_MOUSE_GRAB, + PARSE_ONLY_BOOL, false) == 0) + count++; if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list, MENU_ENUM_LABEL_INPUT_AUTO_GAME_FOCUS, PARSE_ONLY_UINT, false) == 0) diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 2cc00060de..36b8a27948 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -12831,6 +12831,22 @@ static bool setting_append_list( SD_FLAG_NONE ); + CONFIG_BOOL( + list, list_info, + &settings->bools.input_auto_mouse_grab, + MENU_ENUM_LABEL_INPUT_AUTO_MOUSE_GRAB, + MENU_ENUM_LABEL_VALUE_INPUT_AUTO_MOUSE_GRAB, + false, + MENU_ENUM_LABEL_VALUE_OFF, + MENU_ENUM_LABEL_VALUE_ON, + &group_info, + &subgroup_info, + parent_group, + general_write_handler, + general_read_handler, + SD_FLAG_NONE + ); + CONFIG_UINT( list, list_info, &settings->uints.input_auto_game_focus, diff --git a/msg_hash.h b/msg_hash.h index ea724912dd..5547f45272 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -954,6 +954,7 @@ enum msg_hash_enums MENU_LABEL(INPUT_NOWINKEY_ENABLE), #endif MENU_LABEL(INPUT_SENSORS_ENABLE), + MENU_LABEL(INPUT_AUTO_MOUSE_GRAB), MENU_LABEL(INPUT_AUTO_GAME_FOCUS), MENU_ENUM_LABEL_VALUE_INPUT_AUTO_GAME_FOCUS_OFF, diff --git a/retroarch.c b/retroarch.c index 53fa87c2dc..8bc6d84fab 100644 --- a/retroarch.c +++ b/retroarch.c @@ -15127,7 +15127,9 @@ bool command_event(enum event_command cmd, void *data) input_driver_grab_mouse(p_rarch); video_driver_hide_mouse(); } - else if (!video_fullscreen) + /* Ungrab only if windowed and auto mouse grab is disabled */ + else if (!video_fullscreen && + !settings->bools.input_auto_mouse_grab) { input_driver_ungrab_mouse(p_rarch); video_driver_show_mouse(); @@ -38027,6 +38029,14 @@ static enum runloop_state runloop_check_state( /* Check mouse grab toggle */ HOTKEY_CHECK(RARCH_GRAB_MOUSE_TOGGLE, CMD_EVENT_GRAB_MOUSE_TOGGLE, true, NULL); + /* Automatic mouse grab on focus */ + if (settings->bools.input_auto_mouse_grab && + is_focused && + is_focused != runloop_state.focused && + !p_rarch->input_driver_grab_mouse_state) + command_event(CMD_EVENT_GRAB_MOUSE_TOGGLE, NULL); + runloop_state.focused = is_focused; + #ifdef HAVE_OVERLAY if (settings->bools.input_overlay_enable) { diff --git a/retroarch_data.h b/retroarch_data.h index b48ace713d..15a2c96076 100644 --- a/retroarch_data.h +++ b/retroarch_data.h @@ -1695,6 +1695,7 @@ struct runloop bool force_nonblock; bool paused; bool idle; + bool focused; bool slowmotion; bool fastmotion; bool shutdown_initiated;