Basic parse config
parent
d578d612d4
commit
ebc49ae8c5
@ -0,0 +1,52 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include "config.h"
|
||||
#include "overlay_params.h"
|
||||
#include <vector>
|
||||
std::vector<const char*> config_params;
|
||||
|
||||
void configParams(){
|
||||
config_params.push_back("height");
|
||||
}
|
||||
|
||||
void parseConfigLine(std::string line, struct overlay_params *params){
|
||||
if(line.find("#")!=std::string::npos)
|
||||
{
|
||||
line = line.erase(line.find("#"),std::string::npos);
|
||||
}
|
||||
size_t space = line.find(" ");
|
||||
while(space!=std::string::npos)
|
||||
{
|
||||
line = line.erase(space,1);
|
||||
space = line.find(" ");
|
||||
}
|
||||
space = line.find("\t");
|
||||
while(space!=std::string::npos)
|
||||
{
|
||||
line = line.erase(space,1);
|
||||
space = line.find("\t");
|
||||
}
|
||||
size_t equal = line.find("=");
|
||||
if(equal==std::string::npos)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << "set option " << line.substr(0,equal) << " equal to " << line.substr(equal+1) << std::endl;
|
||||
}
|
||||
|
||||
void parseConfigFile(struct overlay_params *params) {
|
||||
configParams();
|
||||
std::string home = std::getenv("HOME");
|
||||
std::string filePath = home + "/.local/share/MangoHud/MangoHud.conf";
|
||||
std::ifstream stream(filePath);
|
||||
|
||||
std::string line;
|
||||
|
||||
while (std::getline(stream, line))
|
||||
{
|
||||
parseConfigLine(line, params);
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
void parseConfigFile(struct overlay_params *params);
|
@ -1,264 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2019 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include "X11/keysym.h"
|
||||
|
||||
#include "overlay_params.h"
|
||||
|
||||
#include "mesa/util/os_socket.h"
|
||||
|
||||
static enum overlay_param_position
|
||||
parse_position(const char *str)
|
||||
{
|
||||
if (!str || !strcmp(str, "top-left"))
|
||||
return LAYER_POSITION_TOP_LEFT;
|
||||
if (!strcmp(str, "top-right"))
|
||||
return LAYER_POSITION_TOP_RIGHT;
|
||||
if (!strcmp(str, "bottom-left"))
|
||||
return LAYER_POSITION_BOTTOM_LEFT;
|
||||
if (!strcmp(str, "bottom-right"))
|
||||
return LAYER_POSITION_BOTTOM_RIGHT;
|
||||
return LAYER_POSITION_TOP_LEFT;
|
||||
}
|
||||
|
||||
static FILE *
|
||||
parse_output_file(const char *str)
|
||||
{
|
||||
return fopen(str, "w+");
|
||||
}
|
||||
|
||||
static int
|
||||
parse_control(const char *str)
|
||||
{
|
||||
int ret = os_socket_listen_abstract(str, 1);
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "ERROR: Couldn't create socket pipe at '%s'\n", str);
|
||||
fprintf(stderr, "ERROR: '%s'\n", strerror(errno));
|
||||
return ret;
|
||||
}
|
||||
|
||||
os_socket_block(ret, false);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static float
|
||||
parse_font_size(const char *str)
|
||||
{
|
||||
return strtof(str, NULL);
|
||||
}
|
||||
|
||||
static KeySym
|
||||
parse_toggle_hud(const char *str)
|
||||
{
|
||||
return XStringToKeysym(str);
|
||||
}
|
||||
|
||||
static KeySym
|
||||
parse_toggle_logging(const char *str)
|
||||
{
|
||||
return XStringToKeysym(str);
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
parse_fps_sampling_period(const char *str)
|
||||
{
|
||||
return strtol(str, NULL, 0) * 1000;
|
||||
}
|
||||
|
||||
static bool
|
||||
parse_no_display(const char *str)
|
||||
{
|
||||
return strtol(str, NULL, 0) != 0;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
parse_unsigned(const char *str)
|
||||
{
|
||||
return strtol(str, NULL, 0);
|
||||
}
|
||||
|
||||
#define parse_width(s) parse_unsigned(s)
|
||||
#define parse_height(s) parse_unsigned(s)
|
||||
|
||||
static bool
|
||||
parse_help(const char *str)
|
||||
{
|
||||
fprintf(stderr, "Layer params using VK_LAYER_MESA_OVERLAY_CONFIG=\n");
|
||||
#define OVERLAY_PARAM_BOOL(name) \
|
||||
fprintf(stderr, "\t%s=0|1\n", #name);
|
||||
#define OVERLAY_PARAM_CUSTOM(name)
|
||||
OVERLAY_PARAMS
|
||||
#undef OVERLAY_PARAM_BOOL
|
||||
#undef OVERLAY_PARAM_CUSTOM
|
||||
fprintf(stderr, "\tposition=top-left|top-right|bottom-left|bottom-right\n");
|
||||
fprintf(stderr, "\tfps_sampling_period=number-of-milliseconds\n");
|
||||
fprintf(stderr, "\tno_display=0|1\n");
|
||||
fprintf(stderr, "\toutput_file=/path/to/output.txt\n");
|
||||
fprintf(stderr, "\twidth=width-in-pixels\n");
|
||||
fprintf(stderr, "\theight=height-in-pixels\n");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool is_delimiter(char c)
|
||||
{
|
||||
return c == 0 || c == ',' || c == ':' || c == ';' || c == '=';
|
||||
}
|
||||
|
||||
static int
|
||||
parse_string(const char *s, char *out_param, char *out_value)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (; !is_delimiter(*s); s++, out_param++, i++)
|
||||
*out_param = *s;
|
||||
|
||||
*out_param = 0;
|
||||
|
||||
if (*s == '=') {
|
||||
s++;
|
||||
i++;
|
||||
for (; !is_delimiter(*s); s++, out_value++, i++)
|
||||
*out_value = *s;
|
||||
} else
|
||||
*(out_value++) = '1';
|
||||
*out_value = 0;
|
||||
|
||||
if (*s && is_delimiter(*s)) {
|
||||
s++;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (*s && !i) {
|
||||
fprintf(stderr, "mesa-overlay: syntax error: unexpected '%c' (%i) while "
|
||||
"parsing a string\n", *s, *s);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
const char *overlay_param_names[] = {
|
||||
#define OVERLAY_PARAM_BOOL(name) #name,
|
||||
#define OVERLAY_PARAM_CUSTOM(name)
|
||||
OVERLAY_PARAMS
|
||||
#undef OVERLAY_PARAM_BOOL
|
||||
#undef OVERLAY_PARAM_CUSTOM
|
||||
};
|
||||
|
||||
void
|
||||
parse_overlay_env(struct overlay_params *params,
|
||||
const char *env)
|
||||
{
|
||||
uint32_t num;
|
||||
char key[256], value[256];
|
||||
|
||||
memset(params, 0, sizeof(*params));
|
||||
|
||||
/* Visible by default */
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_fps] = true;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_frame_timing] = true;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_core_load] = false;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_cpu_temp] = false;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_gpu_temp] = false;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_cpu_stats] = true;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_gpu_stats] = true;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_ram] = false;
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_vram] = false;
|
||||
params->fps_sampling_period = 500000; /* 500ms */
|
||||
params->width = 280;
|
||||
params->height = 140;
|
||||
params->control = -1;
|
||||
params->toggle_hud = 65481;
|
||||
params->toggle_logging = 65471;
|
||||
|
||||
if (!env)
|
||||
return;
|
||||
|
||||
while ((num = parse_string(env, key, value)) != 0) {
|
||||
env += num;
|
||||
|
||||
#define OVERLAY_PARAM_BOOL(name) \
|
||||
if (!strcmp(#name, key)) { \
|
||||
params->enabled[OVERLAY_PARAM_ENABLED_##name] = \
|
||||
strtol(value, NULL, 0); \
|
||||
continue; \
|
||||
}
|
||||
#define OVERLAY_PARAM_CUSTOM(name) \
|
||||
if (!strcmp(#name, key)) { \
|
||||
params->name = parse_##name(value); \
|
||||
continue; \
|
||||
}
|
||||
OVERLAY_PARAMS
|
||||
#undef OVERLAY_PARAM_BOOL
|
||||
#undef OVERLAY_PARAM_CUSTOM
|
||||
fprintf(stderr, "Unknown option '%s'\n", key);
|
||||
}
|
||||
// if font_size is used and height has not been changed from default
|
||||
// increase height as needed based on font_size
|
||||
|
||||
// params->toggle_hud = "F12";
|
||||
|
||||
bool heightChanged = false;
|
||||
|
||||
if (params->height != 140)
|
||||
heightChanged = true;
|
||||
|
||||
if (!params->font_size)
|
||||
params->font_size = 24.0f;
|
||||
|
||||
int FrameTimeGraphHeight = 0;
|
||||
|
||||
if (!heightChanged){
|
||||
if (params->enabled[OVERLAY_PARAM_ENABLED_frame_timing])
|
||||
FrameTimeGraphHeight = 50 + params->font_size / 2;
|
||||
|
||||
if (params->font_size)
|
||||
params->height = (params->font_size - 3 * 2) * 3 + FrameTimeGraphHeight;
|
||||
|
||||
// Apply more hud height if cores are enabled
|
||||
if (params->enabled[OVERLAY_PARAM_ENABLED_core_load])
|
||||
params->height += ((params->font_size - 3) * get_nprocs());
|
||||
|
||||
if (params->enabled[OVERLAY_PARAM_ENABLED_gpu_stats])
|
||||
params->height += ((params->font_size) / 2);
|
||||
|
||||
if (params->enabled[OVERLAY_PARAM_ENABLED_cpu_stats])
|
||||
params->height += ((params->font_size) / 2);
|
||||
|
||||
if (params->enabled[OVERLAY_PARAM_ENABLED_ram])
|
||||
params->height += (params->font_size - 3);
|
||||
|
||||
if (params->enabled[OVERLAY_PARAM_ENABLED_vram])
|
||||
params->height += (params->font_size - 3);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue