Add option to hide overlays when a gamepad is connected (Note: Restricted functionality on Android)

This commit is contained in:
jdgleaver 2020-08-25 11:10:37 +01:00
parent 7e74d830ca
commit cc2e098dab
13 changed files with 161 additions and 63 deletions

View File

@ -356,6 +356,11 @@
#define DEFAULT_SHOW_HIDDEN_FILES false
#define DEFAULT_OVERLAY_HIDE_IN_MENU true
/* Automatically disable overlays when a
* controller is connected in port 1 */
#define DEFAULT_OVERLAY_HIDE_WHEN_GAMEPAD_CONNECTED false
#define DEFAULT_OVERLAY_SHOW_MOUSE_CURSOR true
#define DEFAULT_DISPLAY_KEYBOARD_OVERLAY false

View File

@ -1670,6 +1670,7 @@ static struct config_bool_setting *populate_settings_bool(
SETTING_BOOL("input_overlay_enable_autopreferred", &settings->bools.input_overlay_enable_autopreferred, true, DEFAULT_OVERLAY_ENABLE_AUTOPREFERRED, false);
SETTING_BOOL("input_overlay_show_physical_inputs", &settings->bools.input_overlay_show_physical_inputs, true, DEFAULT_SHOW_PHYSICAL_INPUTS, false);
SETTING_BOOL("input_overlay_hide_in_menu", &settings->bools.input_overlay_hide_in_menu, true, DEFAULT_OVERLAY_HIDE_IN_MENU, false);
SETTING_BOOL("input_overlay_hide_when_gamepad_connected", &settings->bools.input_overlay_hide_when_gamepad_connected, true, DEFAULT_OVERLAY_HIDE_WHEN_GAMEPAD_CONNECTED, false);
SETTING_BOOL("input_overlay_show_mouse_cursor", &settings->bools.input_overlay_show_mouse_cursor, true, DEFAULT_OVERLAY_SHOW_MOUSE_CURSOR, false);
SETTING_BOOL("input_overlay_auto_rotate", &settings->bools.input_overlay_auto_rotate, true, DEFAULT_OVERLAY_AUTO_ROTATE, false);
#endif

View File

@ -487,6 +487,7 @@ typedef struct settings
bool input_overlay_enable;
bool input_overlay_enable_autopreferred;
bool input_overlay_hide_in_menu;
bool input_overlay_hide_when_gamepad_connected;
bool input_overlay_show_physical_inputs;
bool input_overlay_show_mouse_cursor;
bool input_overlay_auto_rotate;

View File

@ -198,15 +198,16 @@ typedef struct input_overlay input_overlay_t;
typedef struct
{
bool hide_in_menu;
bool overlay_enable;
size_t size;
float overlay_opacity;
float overlay_scale;
float overlay_center_x;
float overlay_center_y;
struct overlay *overlays;
struct overlay *active;
struct overlay *overlays;
struct overlay *active;
size_t size;
float overlay_opacity;
float overlay_scale;
float overlay_center_x;
float overlay_center_y;
bool overlay_enable;
bool hide_in_menu;
bool hide_when_gamepad_connected;
} overlay_task_data_t;
void input_overlay_free_overlay(struct overlay *overlay);

View File

@ -1392,6 +1392,10 @@ MSG_HASH(
MENU_ENUM_LABEL_INPUT_OVERLAY_HIDE_IN_MENU,
"overlay_hide_in_menu"
)
MSG_HASH(
MENU_ENUM_LABEL_INPUT_OVERLAY_HIDE_WHEN_GAMEPAD_CONNECTED,
"overlay_hide_when_gamepad_connected"
)
MSG_HASH(
MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS,
"overlay_show_physical_inputs"

View File

@ -3240,6 +3240,20 @@ MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_OVERLAY_HIDE_IN_MENU,
"Hide the overlay while inside the menu, and show it again when exiting the menu."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_HIDE_WHEN_GAMEPAD_CONNECTED,
"Hide Overlay When Gamepad is Connected"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_OVERLAY_HIDE_WHEN_GAMEPAD_CONNECTED,
"Hide the overlay when a physical gamepad is connected in port 1, and show it again when the gamepad is disconnected."
)
#if defined(ANDROID)
MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_OVERLAY_HIDE_WHEN_GAMEPAD_CONNECTED_ANDROID,
"Hide the overlay when a physical gamepad is connected in port 1. WARNING: Overlay will not be restored automatically when gamepad is disconnected."
)
#endif
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS,
"Show Inputs on Overlay"

View File

@ -404,6 +404,11 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_message_pos_x, MENU_
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_message_pos_y, MENU_ENUM_SUBLABEL_VIDEO_MESSAGE_POS_Y)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_video_font_size, MENU_ENUM_SUBLABEL_VIDEO_FONT_SIZE)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_overlay_hide_in_menu, MENU_ENUM_SUBLABEL_INPUT_OVERLAY_HIDE_IN_MENU)
#if defined(ANDROID)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_overlay_hide_when_gamepad_connected_android, MENU_ENUM_SUBLABEL_INPUT_OVERLAY_HIDE_WHEN_GAMEPAD_CONNECTED_ANDROID)
#else
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_overlay_hide_when_gamepad_connected, MENU_ENUM_SUBLABEL_INPUT_OVERLAY_HIDE_WHEN_GAMEPAD_CONNECTED)
#endif
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_overlay_show_mouse_cursor, MENU_ENUM_SUBLABEL_INPUT_OVERLAY_SHOW_MOUSE_CURSOR)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_overlay_auto_rotate, MENU_ENUM_SUBLABEL_INPUT_OVERLAY_AUTO_ROTATE)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_content_collection_list, MENU_ENUM_SUBLABEL_PLAYLISTS_TAB)
@ -2997,6 +3002,13 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_INPUT_OVERLAY_HIDE_IN_MENU:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_overlay_hide_in_menu);
break;
case MENU_ENUM_LABEL_INPUT_OVERLAY_HIDE_WHEN_GAMEPAD_CONNECTED:
#if defined(ANDROID)
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_overlay_hide_when_gamepad_connected_android);
#else
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_overlay_hide_when_gamepad_connected);
#endif
break;
case MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_overlay_show_physical_inputs);
break;

View File

@ -7537,17 +7537,18 @@ unsigned menu_displaylist_build_list(
settings_t *settings = config_get_ptr();
bool input_overlay_enable = settings->bools.input_overlay_enable;
menu_displaylist_build_info_selective_t build_list[] = {
{MENU_ENUM_LABEL_INPUT_OVERLAY_ENABLE, PARSE_ONLY_BOOL, true },
{MENU_ENUM_LABEL_INPUT_OVERLAY_HIDE_IN_MENU, PARSE_ONLY_BOOL, false },
{MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS, PARSE_ONLY_BOOL, false },
{MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT,PARSE_ONLY_BOOL, false },
{MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_MOUSE_CURSOR, PARSE_ONLY_BOOL, false },
{MENU_ENUM_LABEL_INPUT_OVERLAY_AUTO_ROTATE, PARSE_ONLY_BOOL, false },
{MENU_ENUM_LABEL_OVERLAY_PRESET, PARSE_ONLY_PATH, false },
{MENU_ENUM_LABEL_OVERLAY_OPACITY, PARSE_ONLY_FLOAT, false },
{MENU_ENUM_LABEL_OVERLAY_SCALE, PARSE_ONLY_FLOAT, false },
{MENU_ENUM_LABEL_OVERLAY_CENTER_X, PARSE_ONLY_FLOAT, false },
{MENU_ENUM_LABEL_OVERLAY_CENTER_Y, PARSE_ONLY_FLOAT, false },
{MENU_ENUM_LABEL_INPUT_OVERLAY_ENABLE, PARSE_ONLY_BOOL, true },
{MENU_ENUM_LABEL_INPUT_OVERLAY_HIDE_IN_MENU, PARSE_ONLY_BOOL, false },
{MENU_ENUM_LABEL_INPUT_OVERLAY_HIDE_WHEN_GAMEPAD_CONNECTED, PARSE_ONLY_BOOL, false },
{MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS, PARSE_ONLY_BOOL, false },
{MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT, PARSE_ONLY_BOOL, false },
{MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_MOUSE_CURSOR, PARSE_ONLY_BOOL, false },
{MENU_ENUM_LABEL_INPUT_OVERLAY_AUTO_ROTATE, PARSE_ONLY_BOOL, false },
{MENU_ENUM_LABEL_OVERLAY_PRESET, PARSE_ONLY_PATH, false },
{MENU_ENUM_LABEL_OVERLAY_OPACITY, PARSE_ONLY_FLOAT, false },
{MENU_ENUM_LABEL_OVERLAY_SCALE, PARSE_ONLY_FLOAT, false },
{MENU_ENUM_LABEL_OVERLAY_CENTER_X, PARSE_ONLY_FLOAT, false },
{MENU_ENUM_LABEL_OVERLAY_CENTER_Y, PARSE_ONLY_FLOAT, false },
};
for (i = 0; i < ARRAY_SIZE(build_list); i++)
@ -7555,6 +7556,7 @@ unsigned menu_displaylist_build_list(
switch (build_list[i].enum_idx)
{
case MENU_ENUM_LABEL_INPUT_OVERLAY_HIDE_IN_MENU:
case MENU_ENUM_LABEL_INPUT_OVERLAY_HIDE_WHEN_GAMEPAD_CONNECTED:
case MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS:
case MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT:
case MENU_ENUM_LABEL_INPUT_OVERLAY_SHOW_MOUSE_CURSOR:

View File

@ -12959,6 +12959,23 @@ static bool setting_append_list(
);
(*list)[list_info->index - 1].change_handler = overlay_enable_toggle_change_handler;
CONFIG_BOOL(
list, list_info,
&settings->bools.input_overlay_hide_when_gamepad_connected,
MENU_ENUM_LABEL_INPUT_OVERLAY_HIDE_WHEN_GAMEPAD_CONNECTED,
MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_HIDE_WHEN_GAMEPAD_CONNECTED,
DEFAULT_OVERLAY_HIDE_WHEN_GAMEPAD_CONNECTED,
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
);
(*list)[list_info->index - 1].change_handler = overlay_enable_toggle_change_handler;
CONFIG_BOOL(
list, list_info,
&settings->bools.input_overlay_show_physical_inputs,

View File

@ -923,6 +923,10 @@ enum msg_hash_enums
MENU_LABEL(INPUT_OSK_OVERLAY_ENABLE),
MENU_LABEL(INPUT_MENU_ENUM_TOGGLE_GAMEPAD_COMBO),
MENU_LABEL(INPUT_OVERLAY_HIDE_IN_MENU),
MENU_LABEL(INPUT_OVERLAY_HIDE_WHEN_GAMEPAD_CONNECTED),
#if defined(ANDROID)
MENU_ENUM_SUBLABEL_INPUT_OVERLAY_HIDE_WHEN_GAMEPAD_CONNECTED_ANDROID,
#endif
MENU_LABEL(INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS),
MENU_LABEL(INPUT_OVERLAY_SHOW_PHYSICAL_INPUTS_PORT),
MENU_LABEL(INPUT_OVERLAY_SHOW_MOUSE_CURSOR),

View File

@ -23239,14 +23239,20 @@ static void input_overlay_loaded(retro_task_t *task,
if (err)
return;
#ifdef HAVE_MENU
/* We can't display when the menu is up */
if (data->hide_in_menu && p_rarch->menu_driver_alive)
if (data->overlay_enable)
{
if (data->overlay_enable)
#ifdef HAVE_MENU
/* We can't display when the menu is up */
if (data->hide_in_menu && p_rarch->menu_driver_alive)
goto abort_load;
#endif
/* If 'hide_when_gamepad_connected' is enabled,
* we can't display when a gamepad is connected */
if (data->hide_when_gamepad_connected &&
(input_config_get_device_name(0) != NULL))
goto abort_load;
}
#endif
if ( !data->overlay_enable ||
!video_driver_overlay_interface(&iface) ||
@ -23505,22 +23511,23 @@ static void retroarch_overlay_deinit(struct rarch_state *p_rarch)
static void retroarch_overlay_init(struct rarch_state *p_rarch)
{
settings_t *settings = p_rarch->configuration_settings;
bool input_overlay_enable = settings->bools.input_overlay_enable;
const char *path_overlay = settings->paths.path_overlay;
float overlay_opacity = settings->floats.input_overlay_opacity;
float overlay_scale = settings->floats.input_overlay_scale;
float overlay_center_x = settings->floats.input_overlay_center_x;
float overlay_center_y = settings->floats.input_overlay_center_y;
bool load_enabled = input_overlay_enable;
settings_t *settings = p_rarch->configuration_settings;
bool input_overlay_enable = settings->bools.input_overlay_enable;
const char *path_overlay = settings->paths.path_overlay;
float overlay_opacity = settings->floats.input_overlay_opacity;
float overlay_scale = settings->floats.input_overlay_scale;
float overlay_center_x = settings->floats.input_overlay_center_x;
float overlay_center_y = settings->floats.input_overlay_center_y;
bool load_enabled = input_overlay_enable;
#ifdef HAVE_MENU
bool overlay_hide_in_menu = settings->bools.input_overlay_hide_in_menu;
bool overlay_hide_in_menu = settings->bools.input_overlay_hide_in_menu;
#else
bool overlay_hide_in_menu = false;
bool overlay_hide_in_menu = false;
#endif
bool overlay_hide_when_gamepad_connected = settings->bools.input_overlay_hide_when_gamepad_connected;
#if defined(GEKKO)
/* Avoid a crash at startup or even when toggling overlay in rgui */
uint64_t memory_free = frontend_driver_get_free_memory();
uint64_t memory_free = frontend_driver_get_free_memory();
if (memory_free < (3 * 1024 * 1024))
return;
#endif
@ -23534,10 +23541,16 @@ static void retroarch_overlay_init(struct rarch_state *p_rarch)
load_enabled = load_enabled && !p_rarch->menu_driver_alive;
#endif
/* Cancel load if 'hide_when_gamepad_connected' is
* enabled and a gamepad is currently connected */
if (overlay_hide_when_gamepad_connected)
load_enabled = load_enabled && (input_config_get_device_name(0) == NULL);
if (load_enabled)
task_push_overlay_load_default(input_overlay_loaded,
path_overlay,
overlay_hide_in_menu,
overlay_hide_when_gamepad_connected,
input_overlay_enable,
overlay_opacity,
overlay_scale,
@ -38770,12 +38783,31 @@ static enum runloop_state runloop_check_state(
#ifdef HAVE_OVERLAY
if (settings->bools.input_overlay_enable)
{
static char prev_overlay_restore = false;
static unsigned last_width = 0;
static unsigned last_height = 0;
bool check_next_rotation = true;
bool input_overlay_hide_in_menu = settings->bools.input_overlay_hide_in_menu;
bool input_overlay_auto_rotate = settings->bools.input_overlay_auto_rotate;
static char prev_overlay_restore = false;
static unsigned last_width = 0;
static unsigned last_height = 0;
bool check_next_rotation = true;
bool input_overlay_hide_in_menu = settings->bools.input_overlay_hide_in_menu;
bool input_overlay_hide_when_gamepad_connected = settings->bools.input_overlay_hide_when_gamepad_connected;
bool input_overlay_auto_rotate = settings->bools.input_overlay_auto_rotate;
/* Check whether overlay should be hidden
* when a gamepad is connected */
if (input_overlay_hide_when_gamepad_connected)
{
static bool last_controller_connected = false;
bool controller_connected = (input_config_get_device_name(0) != NULL);
if (controller_connected != last_controller_connected)
{
if (controller_connected)
retroarch_overlay_deinit(p_rarch);
else
retroarch_overlay_init(p_rarch);
last_controller_connected = controller_connected;
}
}
/* Check next overlay */
HOTKEY_CHECK(RARCH_OVERLAY_NEXT, CMD_EVENT_OVERLAY_NEXT, true, &check_next_rotation);

View File

@ -56,6 +56,7 @@ struct overlay_loader
bool driver_rgba_support;
bool overlay_enable;
bool overlay_hide_in_menu;
bool overlay_hide_when_gamepad_connected;
};
static void task_overlay_image_done(struct overlay *overlay)
@ -702,15 +703,16 @@ static void task_overlay_handler(retro_task_t *task)
overlay_task_data_t *data = (overlay_task_data_t*)
calloc(1, sizeof(*data));
data->overlays = loader->overlays;
data->size = loader->size;
data->active = loader->active;
data->hide_in_menu = loader->overlay_hide_in_menu;
data->overlay_enable = loader->overlay_enable;
data->overlay_opacity = loader->overlay_opacity;
data->overlay_scale = loader->overlay_scale;
data->overlay_center_x = loader->overlay_center_x;
data->overlay_center_y = loader->overlay_center_y;
data->overlays = loader->overlays;
data->active = loader->active;
data->size = loader->size;
data->overlay_opacity = loader->overlay_opacity;
data->overlay_scale = loader->overlay_scale;
data->overlay_center_x = loader->overlay_center_x;
data->overlay_center_y = loader->overlay_center_y;
data->overlay_enable = loader->overlay_enable;
data->hide_in_menu = loader->overlay_hide_in_menu;
data->hide_when_gamepad_connected = loader->overlay_hide_when_gamepad_connected;
task_set_data(task, data);
}
@ -737,6 +739,7 @@ bool task_push_overlay_load_default(
retro_task_callback_t cb,
const char *overlay_path,
bool overlay_hide_in_menu,
bool overlay_hide_when_gamepad_connected,
bool input_overlay_enable,
float input_overlay_opacity,
float input_overlay_scale,
@ -748,7 +751,7 @@ bool task_push_overlay_load_default(
retro_task_t *t = NULL;
config_file_t *conf = NULL;
overlay_loader_t *loader = NULL;
if (string_is_empty(overlay_path))
return false;
@ -788,19 +791,20 @@ bool task_push_overlay_load_default(
return false;
}
loader->overlay_hide_in_menu = overlay_hide_in_menu;
loader->overlay_enable = input_overlay_enable;
loader->overlay_opacity = input_overlay_opacity;
loader->overlay_scale = input_overlay_scale;
loader->overlay_center_x = input_overlay_center_x;
loader->overlay_center_y = input_overlay_center_y;
loader->conf = conf;
loader->state = OVERLAY_STATUS_DEFERRED_LOAD;
loader->pos_increment = (loader->size / 4) ? (loader->size / 4) : 4;
loader->overlay_hide_in_menu = overlay_hide_in_menu;
loader->overlay_hide_when_gamepad_connected = overlay_hide_when_gamepad_connected;
loader->overlay_enable = input_overlay_enable;
loader->overlay_opacity = input_overlay_opacity;
loader->overlay_scale = input_overlay_scale;
loader->overlay_center_x = input_overlay_center_x;
loader->overlay_center_y = input_overlay_center_y;
loader->conf = conf;
loader->state = OVERLAY_STATUS_DEFERRED_LOAD;
loader->pos_increment = (loader->size / 4) ? (loader->size / 4) : 4;
#ifdef RARCH_INTERNAL
loader->driver_rgba_support = video_driver_supports_rgba();
loader->driver_rgba_support = video_driver_supports_rgba();
#endif
t = task_init();
t = task_init();
if (!t)
{

View File

@ -158,6 +158,7 @@ bool task_push_overlay_load_default(
retro_task_callback_t cb,
const char *overlay_path,
bool overlay_hide_in_menu,
bool overlay_hide_when_gamepad_connected,
bool input_overlay_enable,
float input_overlay_opacity,
float input_overlay_scale,