From 70b6aa848f45bebde46b55045075ea4003be2df8 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sat, 22 Oct 2022 13:07:13 +1100 Subject: [PATCH] - Clean up the availability detection of `kdialog` and `gxmessage` in POSIX sources. * Both `kdialog` and `gxmessage` are not core components of the KDE or GNOME desktop environments. * The environment variable `GNOME_DESKTOP_SESSION_ID` has been deprecated for nearly a decade. * Systems like Steam Deck are shipping with stripped down DEs where these environment variables were set, but without the associated binaries. --- .../common/platform/posix/sdl/crashcatcher.c | 7 +++--- source/common/platform/posix/sdl/i_system.cpp | 24 ++++++++----------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/source/common/platform/posix/sdl/crashcatcher.c b/source/common/platform/posix/sdl/crashcatcher.c index 698707027..c88e0fe8a 100644 --- a/source/common/platform/posix/sdl/crashcatcher.c +++ b/source/common/platform/posix/sdl/crashcatcher.c @@ -15,6 +15,8 @@ #include #endif +int I_FileAvailable(const char* filename); + static const char crash_switch[] = "--cc-handle-crash"; @@ -363,12 +365,11 @@ static void crash_handler(const char *logfile) if(logfile) { - const char *str; char buf[512]; - if((str=getenv("KDE_FULL_SESSION")) && strcmp(str, "true") == 0) + if(I_FileAvailable("kdialog")) snprintf(buf, sizeof(buf), "kdialog --title \"Very Fatal Error\" --textbox \"%s\" 800 600", logfile); - else if((str=getenv("GNOME_DESKTOP_SESSION_ID")) && str[0] != '\0') + else if(I_FileAvailable("gxmessage")) snprintf(buf, sizeof(buf), "gxmessage -buttons \"Okay:0\" -geometry 800x600 -title \"Very Fatal Error\" -center -file \"%s\"", logfile); else snprintf(buf, sizeof(buf), "xmessage -buttons \"Okay:0\" -center -file \"%s\"", logfile); diff --git a/source/common/platform/posix/sdl/i_system.cpp b/source/common/platform/posix/sdl/i_system.cpp index 8db0f63ce..512a7d62b 100644 --- a/source/common/platform/posix/sdl/i_system.cpp +++ b/source/common/platform/posix/sdl/i_system.cpp @@ -85,22 +85,18 @@ void I_SetIWADInfo() { } -static bool I_KDialogAvailable() +extern "C" int I_FileAvailable(const char* filename) { - // Is KDE running? - const char* str = getenv("KDE_FULL_SESSION"); - if (str && strcmp(str, "true") == 0) + FString cmd = "which {0} >/dev/null 2>&1"; + cmd.Substitute("{0}", filename); + + if (FILE* f = popen(cmd.GetChars(), "r")) { - // Is kdialog available? - FILE* f = popen("which kdialog >/dev/null 2>&1", "r"); - if (f != NULL) - { - int status = pclose(f); - return WIFEXITED(status) && WEXITSTATUS(status) == 0; - } + int status = pclose(f); + return WIFEXITED(status) && WEXITSTATUS(status) == 0; } - return false; + return 0; } // @@ -117,7 +113,7 @@ void Unix_I_FatalError(const char* errortext) // Close window or exit fullscreen and release mouse capture SDL_QuitSubSystem(SDL_INIT_VIDEO); - if(I_KDialogAvailable()) + if(I_FileAvailable("kdialog")) { FString cmd; cmd << "kdialog --title \"" GAMENAME " " << GetVersionString() @@ -311,7 +307,7 @@ int I_PickIWad (WadStuff *wads, int numwads, bool showwin, int defaultiwad, int& } #ifndef __APPLE__ - if(I_KDialogAvailable()) + if(I_FileAvailable("kdialog")) { FString cmd("kdialog --title \"" GAMENAME " "); cmd << GetVersionString() << ": Select an IWAD to use\""