diff --git a/README.md b/README.md index 8622bb5d9c..fca829d8e4 100644 --- a/README.md +++ b/README.md @@ -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
`custom_text=Distro`
`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. diff --git a/src/hud_elements.cpp b/src/hud_elements.cpp index 2425bf7732..1181a3c5b8 100644 --- a/src/hud_elements.cpp +++ b/src/hud_elements.cpp @@ -5,6 +5,7 @@ #include "memory.h" #include "mesa/util/macros.h" #include "string_utils.h" +#include "file_utils.h" #include // Cut from https://github.com/ocornut/imgui/pull/2943 @@ -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(); @@ -773,6 +785,8 @@ void HudElements::sort_elements(std::pair 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]) @@ -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; diff --git a/src/hud_elements.h b/src/hud_elements.h index 91e057587c..2afcde8395 100644 --- a/src/hud_elements.h +++ b/src/hud_elements.h @@ -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; @@ -30,9 +35,11 @@ class HudElements{ "vram", "ram", "cpu_temp", "gpu_temp" }; std::vector exec_list; + std::vector cat_file_list; void sort_elements(std::pair option); void legacy_elements(); void update_exec(); + void update_cat_file(); static void version(); static void time(); static void gpu_stats(); @@ -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); diff --git a/src/overlay.cpp b/src/overlay.cpp index ebdf0d08a0..70905afc70 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -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){ diff --git a/src/overlay_params.cpp b/src/overlay_params.cpp index 86450fa06e..67db9a9018 100644 --- a/src/overlay_params.cpp +++ b/src/overlay_params.cpp @@ -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); diff --git a/src/overlay_params.h b/src/overlay_params.h index 4c7663f78d..2061a05f00 100644 --- a/src/overlay_params.h +++ b/src/overlay_params.h @@ -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) \