'Automatic Mouse Grab' option

This commit is contained in:
sonninnos 2021-07-29 00:28:26 +03:00
parent 0f5f8798ea
commit 149beaf061
10 changed files with 51 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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"

View file

@ -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;

View file

@ -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)

View file

@ -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,

View file

@ -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,

View file

@ -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)
{

View file

@ -1695,6 +1695,7 @@ struct runloop
bool force_nonblock;
bool paused;
bool idle;
bool focused;
bool slowmotion;
bool fastmotion;
bool shutdown_initiated;