about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorYang Liu <liuyang22@iscas.ac.cn>2025-02-19 03:00:31 +0800
committerGitHub <noreply@github.com>2025-02-18 20:00:31 +0100
commit39a9cf903f3043c4fb53969caa2a824e5f3c4b6e (patch)
treeba64998791793ee5ecd64db7de4e6ecdbeca69bc /src
parent611ac3933c655690b09f14cc7b25fa48af54f64a (diff)
downloadbox64-39a9cf903f3043c4fb53969caa2a824e5f3c4b6e.tar.gz
box64-39a9cf903f3043c4fb53969caa2a824e5f3c4b6e.zip
[CORE] Display Box64 version info in mangohud (#2386)
* [CORE] Display Box64 version info in mangohud

* check for config files
Diffstat (limited to 'src')
-rw-r--r--src/core.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/core.c b/src/core.c
index 8bc76144..59267a29 100644
--- a/src/core.c
+++ b/src/core.c
@@ -6,6 +6,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <dirent.h>
+#include <pwd.h>
 #include <signal.h>
 #include <sys/syscall.h>
 #include <sys/mman.h>
@@ -469,6 +470,30 @@ static void displayMiscInfo()
     computeRDTSC();
 }
 
+static void hookMangoHud()
+{
+    const char* config = getenv("MANGOHUD_CONFIG");
+    const char* configfile = getenv("MANGOHUD_CONFIGFILE");
+    if (config || configfile) return;
+    if (FileExist("/etc/MangoHud.conf", IS_FILE)) return;
+    const char* configdir = getenv("XDG_CONFIG_HOME");
+    const char* homedir = getenv("HOME");
+    if (!homedir) homedir = getpwuid(getuid())->pw_dir;
+    if (!homedir) return;
+    const char* p = configdir ? configdir : homedir;
+    static char buf[512] = {};
+    memcpy(buf, p, strlen(p));
+    if (!configdir) strcat(buf, "/.config");
+    strcat(buf, "/MangoHud/MangoHud.conf");
+    if (FileExist(buf, IS_FILE)) return;
+
+    memcpy(buf, p, strlen(p));
+    if (!configdir) strcat(buf, "/.config");
+    strcat(buf, "/MangoHud/box64.conf");
+    if (FileExist(buf, IS_FILE)) return;
+    setenv("MANGOHUD_CONFIG", "legacy_layout=0,custom_text_center=" BOX64_BUILD_INFO_STRING ",gpu_stats=1,cpu_stats=1,fps=1,frame_timing=1", 0);
+}
+
 static void loadPath(path_collection_t *col, const char* defpath, const char* path)
 {
     if(path) {
@@ -850,7 +875,6 @@ void pressure_vessel(int argc, const char** argv, int nextarg, const char* prog)
 #endif
 extern char** environ;
 
-
 int initialize(int argc, const char **argv, char** env, x64emu_t** emulator, elfheader_t** elfheader, int exec)
 {
     #ifndef STATICBUILD
@@ -887,6 +911,8 @@ int initialize(int argc, const char **argv, char** env, x64emu_t** emulator, elf
 
     displayMiscInfo();
 
+    hookMangoHud();
+
     char* bashpath = NULL;
     {
         char* p = BOX64ENV(bash);