@ -41,9 +41,6 @@
# include "fps_metrics.h"
std : : unique_ptr < fpsMetrics > fpsmetrics ;
std : : mutex config_mtx ;
std : : condition_variable config_cv ;
bool config_ready = false ;
# if __cplusplus >= 201703L
@ -111,8 +108,8 @@ parse_control(const char *str)
int ret = os_socket_listen_abstract ( path . c_str ( ) , 1 ) ;
if ( ret < 0 ) {
SPDLOG_ DEBUG ( " Couldn't create socket pipe at '{}' " , path ) ;
SPDLOG_ DEBUG ( " ERROR: '{}' " , strerror ( errno ) ) ;
SPDLOG_ ERROR ( " Couldn't create socket pipe at '{}' " , path ) ;
SPDLOG_ ERROR ( " ERROR: '{}' " , strerror ( errno ) ) ;
return ret ;
}
@ -159,7 +156,6 @@ parse_string_to_keysym_vec(const char *str)
# define parse_upload_logs parse_string_to_keysym_vec
# define parse_toggle_fps_limit parse_string_to_keysym_vec
# define parse_toggle_preset parse_string_to_keysym_vec
# define parse_reset_fps_metrics parse_string_to_keysym_vec
# else
# define parse_toggle_hud(x) {}
@ -170,7 +166,6 @@ parse_string_to_keysym_vec(const char *str)
# define parse_upload_logs(x) {}
# define parse_toggle_fps_limit(x) {}
# define parse_toggle_preset(x) {}
# define parse_reset_fps_metrics(x) {}
# endif
// NOTE: This is NOT defined as an OVERLAY_PARAM and will be called manually
@ -486,7 +481,6 @@ parse_fps_metrics(const char *str){
# define parse_text_color(s) parse_color(s)
# define parse_media_player_color(s) parse_color(s)
# define parse_wine_color(s) parse_color(s)
# define parse_network_color(s) parse_color(s)
# define parse_gpu_load_color(s) parse_load_color(s)
# define parse_cpu_load_color(s) parse_load_color(s)
# define parse_gpu_load_value(s) parse_load_value(s)
@ -502,7 +496,6 @@ parse_fps_metrics(const char *str){
# define parse_text_outline_color(s) parse_color(s)
# define parse_text_outline_thickness(s) parse_float(s)
# define parse_device_battery(s) parse_str_tokenize(s)
# define parse_network(s) parse_str_tokenize(s)
static bool
parse_help ( const char * str )
@ -576,116 +569,61 @@ const char *overlay_param_names[] = {
# undef OVERLAY_PARAM_CUSTOM
} ;
static void
initialize_preset ( struct overlay_params * params )
{
if ( params - > options . find ( " preset " ) ! = params - > options . end ( ) ) {
auto presets = parse_preset ( params - > options . find ( " preset " ) - > second . c_str ( ) ) ;
if ( ! presets . empty ( ) )
params - > preset = presets ;
}
current_preset = params - > preset [ 0 ] ;
}
static void
set_parameters_from_options ( struct overlay_params * params )
{
bool read_cfg = false ;
if ( params - > options . find ( " read_cfg " ) ! = params - > options . end ( ) & & params - > options . find ( " read_cfg " ) - > second ! = " 0 " )
read_cfg = true ;
if ( params - > options . find ( " full " ) ! = params - > options . end ( ) & & params - > options . find ( " full " ) - > second ! = " 0 " ) {
# define OVERLAY_PARAM_BOOL(name) \
params - > enabled [ OVERLAY_PARAM_ENABLED_ # # name ] = 1 ;
# define OVERLAY_PARAM_CUSTOM(name)
OVERLAY_PARAMS
# undef OVERLAY_PARAM_BOOL
# undef OVERLAY_PARAM_CUSTOM
params - > enabled [ OVERLAY_PARAM_ENABLED_histogram ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_fps_only ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_battery_icon ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_mangoapp_steam ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_hide_fsr_sharpness ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_throttling_status ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_fcat ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_horizontal ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_hud_no_margin ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_log_versioning ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_hud_compact ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_exec_name ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_trilinear ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_bicubic ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_retro ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_debug ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_engine_short_names ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_dynamic_frame_timing ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_temp_fahrenheit ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_duration ] = false ;
params - > enabled [ OVERLAY_PARAM_ENABLED_core_bars ] = false ;
params - > enabled [ OVERLAY_PARAM_ENABLED_read_cfg ] = read_cfg ;
params - > enabled [ OVERLAY_PARAM_ENABLED_time_no_label ] = false ;
params - > options . erase ( " full " ) ;
}
for ( auto & it : params - > options ) {
# define OVERLAY_PARAM_BOOL(name) \
if ( it . first = = # name ) { \
params - > enabled [ OVERLAY_PARAM_ENABLED_ # # name ] = \
strtol ( it . second . c_str ( ) , NULL , 0 ) ; \
continue ; \
}
# define OVERLAY_PARAM_CUSTOM(name) \
if ( it . first = = # name ) { \
params - > name = parse_ # # name ( it . second . c_str ( ) ) ; \
continue ; \
}
OVERLAY_PARAMS
# undef OVERLAY_PARAM_BOOL
# undef OVERLAY_PARAM_CUSTOM
if ( it . first = = " preset " ) {
continue ; // Handled above
}
SPDLOG_ERROR ( " Unknown option '{}' " , it . first . c_str ( ) ) ;
}
}
static void
parse_overlay_env ( struct overlay_params * params ,
const char * env , bool use_existing_preset )
const char * env )
{
const char * env_start = env ;
uint32_t num ;
char key [ 256 ] , value [ 256 ] ;
while ( ( num = parse_string ( env , key , value ) ) ! = 0 ) {
trim_char ( key ) ;
trim_char ( value ) ;
env + = num ;
if ( ! strcmp ( " preset " , key ) ) {
if ( ! use_existing_preset ) {
add_to_options ( params , key , value ) ;
initialize_preset ( params ) ;
}
break ;
}
}
presets ( current_preset , params ) ;
env = env_start ;
while ( ( num = parse_string ( env , key , value ) ) ! = 0 ) {
trim_char ( key ) ;
trim_char ( value ) ;
env + = num ;
if ( ! strcmp ( " preset " , key ) ) {
continue ; // Avoid 'Unknown option' error
if ( ! strcmp ( " full " , key ) ) {
bool read_cfg = params - > enabled [ OVERLAY_PARAM_ENABLED_read_cfg ] ;
# define OVERLAY_PARAM_BOOL(name) \
params - > enabled [ OVERLAY_PARAM_ENABLED_ # # name ] = 1 ;
# define OVERLAY_PARAM_CUSTOM(name)
OVERLAY_PARAMS
# undef OVERLAY_PARAM_BOOL
# undef OVERLAY_PARAM_CUSTOM
params - > enabled [ OVERLAY_PARAM_ENABLED_histogram ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_gpu_load_change ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_cpu_load_change ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_fps_only ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_fps_color_change ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_core_load_change ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_battery_icon ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_mangoapp_steam ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_hide_fsr_sharpness ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_throttling_status ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_read_cfg ] = read_cfg ;
params - > enabled [ OVERLAY_PARAM_ENABLED_fcat ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_horizontal ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_horizontal_stretch ] = 1 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_hud_no_margin ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_log_versioning ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_hud_compact ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_exec_name ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_trilinear ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_bicubic ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_retro ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_debug ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_engine_short_names ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_dynamic_frame_timing ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_temp_fahrenheit ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_core_bars ] = false ;
}
# define OVERLAY_PARAM_BOOL(name) \
if ( ! strcmp ( # name , key ) ) { \
params - > enabled [ OVERLAY_PARAM_ENABLED_ # # name ] = \
strtol ( value , NULL , 0 ) ; \
add_to_options ( params , key , value ) ; \
continue ; \
}
# define OVERLAY_PARAM_CUSTOM(name) \
if ( ! strcmp ( # name , key ) ) { \
params - > name = parse_ # # name ( value ) ; \
add_to_options ( params , key , value ) ; \
continue ; \
}
@ -694,7 +632,6 @@ parse_overlay_env(struct overlay_params *params,
# undef OVERLAY_PARAM_CUSTOM
SPDLOG_ERROR ( " Unknown option '{}' " , key ) ;
}
set_parameters_from_options ( params ) ;
}
static void set_param_defaults ( struct overlay_params * params ) {
@ -758,7 +695,6 @@ static void set_param_defaults(struct overlay_params *params){
params - > background_color = 0x020202 ;
params - > text_color = 0xffffff ;
params - > media_player_color = 0xffffff ;
params - > network_color = 0xe07b85 ;
params - > media_player_name = " " ;
params - > font_scale = 1.0f ;
params - > wine_color = 0xeb5b5b ;
@ -794,15 +730,11 @@ parse_overlay_config(struct overlay_params *params,
. preset = use_existing_preset ? params - > preset : default_preset
} ;
set_param_defaults ( params ) ;
if ( ! use_existing_preset ) {
current_preset = params - > preset [ 0 ] ;
}
# ifdef HAVE_X11
params - > toggle_hud = { XK_Shift_R , XK_F12 } ;
params - > toggle_hud_position = { XK_Shift_R , XK_F11 } ;
params - > toggle_preset = { XK_Shift_R , XK_F10 } ;
params - > reset_fps_metrics = { XK_Shift_R , XK_F9 } ;
params - > toggle_fps_limit = { XK_Shift_L , XK_F1 } ;
params - > toggle_logging = { XK_Shift_L , XK_F2 } ;
params - > reload_cfg = { XK_Shift_L , XK_F4 } ;
@ -813,7 +745,6 @@ parse_overlay_config(struct overlay_params *params,
# ifdef _WIN32
params - > toggle_hud = { VK_F12 } ;
params - > toggle_preset = { VK_F10 } ;
params - > reset_fps_metrics = { VK_F9 } ;
params - > toggle_fps_limit = { VK_F3 } ;
params - > toggle_logging = { VK_F2 } ;
params - > reload_cfg = { VK_F4 } ;
@ -833,31 +764,77 @@ parse_overlay_config(struct overlay_params *params,
HUDElements . ordered_functions . clear ( ) ;
HUDElements . exec_list . clear ( ) ;
params - > options . clear ( ) ;
HUDElements . options . clear ( ) ;
// first pass with env var
if ( env )
parse_overlay_env ( params , env , use_existing_preset );
parse_overlay_env ( params , env ) ;
bool read_cfg = params - > enabled [ OVERLAY_PARAM_ENABLED_read_cfg ] ;
bool env_contains_preset = params - > options . find ( " preset " ) ! = params - > options . end ( ) ;
if ( ! env | | read_cfg ) {
// Get config options
parseConfigFile ( * params ) ;
if ( ! use_existing_preset & & ! env_contains_preset ) {
initialize_preset ( params ) ;
if ( ! use_existing_preset ) {
if ( params - > options . find ( " preset " ) ! = params - > options . end ( ) ) {
auto presets = parse_preset ( params - > options . find ( " preset " ) - > second . c_str ( ) ) ;
if ( ! presets . empty ( ) )
params - > preset = presets ;
}
current_preset = params - > preset [ 0 ] ;
}
// clear options since we don't want config options to appear first
params - > options . clear ( ) ;
HUDElements . options . clear ( ) ;
// add preset options
presets ( current_preset , params ) ;
// potentially override preset options with config options
parseConfigFile ( * params ) ;
set_parameters_from_options ( params ) ;
if ( params - > options . find ( " full " ) ! = params - > options . end ( ) & & params - > options . find ( " full " ) - > second ! = " 0 " ) {
# define OVERLAY_PARAM_BOOL(name) \
params - > enabled [ OVERLAY_PARAM_ENABLED_ # # name ] = 1 ;
# define OVERLAY_PARAM_CUSTOM(name)
OVERLAY_PARAMS
# undef OVERLAY_PARAM_BOOL
# undef OVERLAY_PARAM_CUSTOM
params - > enabled [ OVERLAY_PARAM_ENABLED_histogram ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_fps_only ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_battery_icon ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_mangoapp_steam ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_hide_fsr_sharpness ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_throttling_status ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_fcat ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_horizontal ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_hud_no_margin ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_log_versioning ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_hud_compact ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_exec_name ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_trilinear ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_bicubic ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_retro ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_debug ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_engine_short_names ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_dynamic_frame_timing ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_temp_fahrenheit ] = 0 ;
params - > enabled [ OVERLAY_PARAM_ENABLED_duration ] = false ;
params - > enabled [ OVERLAY_PARAM_ENABLED_core_bars ] = false ;
params - > options . erase ( " full " ) ;
}
for ( auto & it : params - > options ) {
# define OVERLAY_PARAM_BOOL(name) \
if ( it . first = = # name ) { \
params - > enabled [ OVERLAY_PARAM_ENABLED_ # # name ] = \
strtol ( it . second . c_str ( ) , NULL , 0 ) ; \
continue ; \
}
# define OVERLAY_PARAM_CUSTOM(name) \
if ( it . first = = # name ) { \
params - > name = parse_ # # name ( it . second . c_str ( ) ) ; \
continue ; \
}
OVERLAY_PARAMS
# undef OVERLAY_PARAM_BOOL
# undef OVERLAY_PARAM_CUSTOM
if ( it . first = = " preset " ) {
continue ;
}
SPDLOG_ERROR ( " Unknown option '{}' " , it . first . c_str ( ) ) ;
}
}
// TODO decide what to do for legacy_layout=0
@ -865,7 +842,7 @@ parse_overlay_config(struct overlay_params *params,
if ( params - > enabled [ OVERLAY_PARAM_ENABLED_legacy_layout ] & & env & & read_cfg ) {
// If passing legacy_layout=0 to MANGOHUD_CONFIG anyway then clear first pass' results
HUDElements . ordered_functions . clear ( ) ;
parse_overlay_env ( params , env , true );
parse_overlay_env ( params , env );
}
// If fps_only param is enabled disable legacy_layout
@ -879,7 +856,7 @@ parse_overlay_config(struct overlay_params *params,
params - > font_scale_media_player = 0.55f ;
// Convert from 0xRRGGBB to ImGui's format
std : : array < unsigned * , 2 3 > colors = {
std : : array < unsigned * , 2 2 > colors = {
& params - > cpu_color ,
& params - > gpu_color ,
& params - > vram_color ,
@ -902,7 +879,6 @@ parse_overlay_config(struct overlay_params *params,
& params - > fps_color [ 1 ] ,
& params - > fps_color [ 2 ] ,
& params - > text_outline_color ,
& params - > network_color ,
} ;
for ( auto color : colors ) {
@ -979,7 +955,6 @@ parse_overlay_config(struct overlay_params *params,
if ( params - > enabled [ OVERLAY_PARAM_ENABLED_legacy_layout ] ) {
HUDElements . legacy_elements ( ) ;
} else {
HUDElements . ordered_functions . clear ( ) ;
for ( auto & option : HUDElements . options ) {
HUDElements . sort_elements ( option ) ;
}
@ -1007,14 +982,6 @@ parse_overlay_config(struct overlay_params *params,
mangoapp_cv . notify_one ( ) ;
g_fsrSharpness = params - > fsr_steam_sharpness ;
# endif
if ( HUDElements . net )
HUDElements . net - > should_reset = true ;
{
std : : lock_guard < std : : mutex > lock ( config_mtx ) ;
config_ready = true ;
config_cv . notify_one ( ) ;
}
}
bool parse_preset_config ( int preset , struct overlay_params * params ) {
@ -1029,7 +996,7 @@ bool parse_preset_config(int preset, struct overlay_params *params){
stream . imbue ( std : : locale : : classic ( ) ) ;
if ( ! stream . good ( ) ) {
SPDLOG_ DEBUG ( " Failed to read presets file: '{}' . Falling back to default presets " , preset_path ) ;
SPDLOG_ ERROR ( " Failed to read presets file: '{}' " , preset_path ) ;
return false ;
}
@ -1147,11 +1114,6 @@ void presets(int preset, struct overlay_params *params, bool inherit) {
add_to_options ( params , " debug " , " 1 " ) ;
add_to_options ( params , " version " , " 0 " ) ;
add_to_options ( params , " frame_timing_detailed " , " 1 " ) ;
add_to_options ( params , " network " , " 1 " ) ;
add_to_options ( params , " present_mode " , " 0 " ) ;
if ( deviceID = = 0x1435 | | deviceID = = 0x163f )
add_to_options ( params , " gpu_fan " , " 0 " ) ;
break ;
}