Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hud elements cat_file function #605

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ Parameters that are enabled by default have to be explicitly disabled. These (cu
| `battery` | Display current battery percent and energy consumption |
| `battery_icon` | Display battery icon instead of percent |
| `battery_color` | Change the BATT text color |
| `cat_file` | Display the first line of a text file in next column,e.g<br>`custom_text=Distro`<br>`cat_file=/etc/issue` |

Example: `MANGOHUD_CONFIG=cpu_temp,gpu_temp,position=top-right,height=500,font_size=32`
Because comma is also used as option delimiter and needs to be escaped for values with a backslash, you can use `+` like `MANGOHUD_CONFIG=fps_limit=60+30+0` instead.

Expand Down
26 changes: 26 additions & 0 deletions src/hud_elements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "memory.h"
#include "mesa/util/macros.h"
#include "string_utils.h"
#include "file_utils.h"
#include <IconsForkAwesome.h>

// Cut from https://github.com/ocornut/imgui/pull/2943
Expand Down Expand Up @@ -560,6 +561,17 @@ void HudElements::_exec(){
ImGui::PopFont();
}

void HudElements::_cat_file(){
std::string value = HUDElements.ordered_functions[HUDElements.place].second;
ImGui::PushFont(HUDElements.sw_stats->font1);
ImGui::TableNextColumn();
for (auto& item : HUDElements.cat_file_list){
if (item.pos == HUDElements.place)
ImGui::Text("%s", item.ret.c_str());
}
ImGui::PopFont();
}

void HudElements::gamemode(){
if (HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_gamemode]){
ImGui::TableNextRow(); ImGui::TableNextColumn();
Expand Down Expand Up @@ -773,6 +785,8 @@ void HudElements::sort_elements(std::pair<std::string, std::string> option){
if (param == "vkbasalt") { ordered_functions.push_back({vkbasalt, value}); }
if (param == "exec") { ordered_functions.push_back({_exec, value});
exec_list.push_back({int(ordered_functions.size() - 1), value}); }
if (param == "cat_file") { ordered_functions.push_back({_cat_file, value});
cat_file_list.push_back({int(ordered_functions.size() - 1), value}); }
if (param == "battery") { ordered_functions.push_back({battery, value}); }
if (param == "graphs"){
if (!HUDElements.params->enabled[OVERLAY_PARAM_ENABLED_graphs])
Expand Down Expand Up @@ -819,4 +833,16 @@ void HudElements::update_exec(){
item.ret = exec(item.value);
}

void HudElements::update_cat_file(){
for(auto& item : cat_file_list){

if (!file_exists(item.value)) {
item.ret = "File not found";
return ;
}
//amdgpu.busy = fopen((path + "/gpu_busy_percent").c_str(), "r");
item.ret = read_line(item.value);
}
}

HudElements HUDElements;
8 changes: 8 additions & 0 deletions src/hud_elements.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class HudElements{
std::string value;
std::string ret;
};
struct cat_file_list {
int pos;
std::string value;
std::string ret;
};
float ralign_width;
float old_scale;
float res_width, res_height;
Expand All @@ -30,9 +35,11 @@ class HudElements{
"vram", "ram", "cpu_temp", "gpu_temp"
};
std::vector<exec_list> exec_list;
std::vector<cat_file_list> cat_file_list;
void sort_elements(std::pair<std::string, std::string> option);
void legacy_elements();
void update_exec();
void update_cat_file();
static void version();
static void time();
static void gpu_stats();
Expand All @@ -57,6 +64,7 @@ class HudElements{
static void gamemode();
static void graphs();
static void _exec();
static void _cat_file();
static void battery();

void convert_colors(struct overlay_params& params);
Expand Down
1 change: 1 addition & 0 deletions src/overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void update_hw_info(struct swapchain_stats& sw_stats, struct overlay_params& par
graph_data.push_back(currentLogData);
logger->notify_data_valid();
HUDElements.update_exec();
HUDElements.update_cat_file();
}

void update_hud_info(struct swapchain_stats& sw_stats, struct overlay_params& params, uint32_t vendorID){
Expand Down
1 change: 1 addition & 0 deletions src/overlay_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ parse_overlay_config(struct overlay_params *params,

HUDElements.ordered_functions.clear();
HUDElements.exec_list.clear();
HUDElements.cat_file_list.clear();
// first pass with env var
if (env)
parse_overlay_env(params, env);
Expand Down
1 change: 1 addition & 0 deletions src/overlay_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ typedef unsigned long KeySym;
OVERLAY_PARAM_BOOL(custom_text_center) \
OVERLAY_PARAM_BOOL(custom_text) \
OVERLAY_PARAM_BOOL(exec) \
OVERLAY_PARAM_BOOL(cat_file) \
OVERLAY_PARAM_BOOL(vkbasalt) \
OVERLAY_PARAM_BOOL(gamemode) \
OVERLAY_PARAM_BOOL(battery) \
Expand Down