2023-10-30 22:46:38 +08:00
|
|
|
#include "de.h"
|
|
|
|
|
|
2024-04-17 19:00:45 +08:00
|
|
|
#include "common/dbus.h"
|
2023-10-31 19:51:05 +08:00
|
|
|
#include "common/io/io.h"
|
2023-12-11 16:36:12 +08:00
|
|
|
#include "common/library.h"
|
2023-10-30 22:46:38 +08:00
|
|
|
#include "common/parsing.h"
|
|
|
|
|
#include "common/properties.h"
|
|
|
|
|
#include "common/processing.h"
|
|
|
|
|
#include "detection/displayserver/displayserver.h"
|
2023-10-31 19:51:05 +08:00
|
|
|
#include "util/stringUtils.h"
|
2023-10-30 22:46:38 +08:00
|
|
|
|
2023-10-31 23:43:29 +08:00
|
|
|
#include <ctype.h>
|
|
|
|
|
|
2023-10-31 09:54:12 +08:00
|
|
|
static void getKDE(FFstrbuf* result, FFDEOptions* options)
|
2023-10-30 22:46:38 +08:00
|
|
|
{
|
2024-04-17 21:02:32 +08:00
|
|
|
ffParsePropFileValues(FASTFETCH_TARGET_DIR_USR "/share/wayland-sessions/plasma.desktop", 1, (FFpropquery[]) {
|
2023-10-30 22:46:38 +08:00
|
|
|
{"X-KDE-PluginInfo-Version =", result}
|
|
|
|
|
});
|
|
|
|
|
if(result->length == 0)
|
|
|
|
|
{
|
2024-04-17 21:02:32 +08:00
|
|
|
ffParsePropFileValues(FASTFETCH_TARGET_DIR_USR "/share/xsessions/plasmax11.desktop", 1, (FFpropquery[]) {
|
2023-10-30 22:46:38 +08:00
|
|
|
{"X-KDE-PluginInfo-Version =", result}
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-04-17 21:02:32 +08:00
|
|
|
if(result->length == 0)
|
|
|
|
|
ffParsePropFileData("xsessions/plasma.desktop", "X-KDE-PluginInfo-Version =", result);
|
|
|
|
|
if(result->length == 0)
|
|
|
|
|
ffParsePropFileData("xsessions/plasma5.desktop", "X-KDE-PluginInfo-Version =", result);
|
|
|
|
|
|
2023-10-30 22:46:38 +08:00
|
|
|
if(result->length == 0)
|
|
|
|
|
ffParsePropFileData("wayland-sessions/plasmawayland.desktop", "X-KDE-PluginInfo-Version =", result);
|
|
|
|
|
if(result->length == 0)
|
|
|
|
|
ffParsePropFileData("wayland-sessions/plasmawayland5.desktop", "X-KDE-PluginInfo-Version =", result);
|
|
|
|
|
|
2023-10-31 09:54:12 +08:00
|
|
|
if(result->length == 0 && options->slowVersionDetection)
|
2023-10-30 22:46:38 +08:00
|
|
|
{
|
|
|
|
|
if (ffProcessAppendStdOut(result, (char* const[]){
|
|
|
|
|
"plasmashell",
|
|
|
|
|
"--version",
|
|
|
|
|
NULL
|
|
|
|
|
}) == NULL) // plasmashell 5.27.5
|
|
|
|
|
ffStrbufSubstrAfterLastC(result, ' ');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-22 23:38:43 +08:00
|
|
|
static const char* getGnomeByDbus(FF_MAYBE_UNUSED FFstrbuf* result)
|
2024-04-17 19:00:45 +08:00
|
|
|
{
|
2024-04-22 18:22:00 +03:00
|
|
|
#ifdef FF_HAVE_DBUS
|
2024-04-17 19:00:45 +08:00
|
|
|
FFDBusData dbus;
|
|
|
|
|
if (ffDBusLoadData(DBUS_BUS_SESSION, &dbus) != NULL)
|
|
|
|
|
return "ffDBusLoadData() failed";
|
|
|
|
|
|
|
|
|
|
ffDBusGetPropertyString(&dbus, "org.gnome.Shell", "/org/gnome/Shell", "org.gnome.Shell", "ShellVersion", result);
|
|
|
|
|
return NULL;
|
2024-04-22 18:22:00 +03:00
|
|
|
#else // FF_HAVE_DBUS
|
|
|
|
|
return "ffDBusLoadData() failed: dbus support not compiled in";
|
|
|
|
|
#endif // FF_HAVE_DBUS
|
2024-04-17 19:00:45 +08:00
|
|
|
}
|
|
|
|
|
|
2023-10-31 09:54:12 +08:00
|
|
|
static void getGnome(FFstrbuf* result, FF_MAYBE_UNUSED FFDEOptions* options)
|
2023-10-30 22:46:38 +08:00
|
|
|
{
|
2024-04-22 23:38:43 +08:00
|
|
|
getGnomeByDbus(result);
|
2023-10-30 22:46:38 +08:00
|
|
|
|
2024-04-17 20:58:49 +08:00
|
|
|
if (result->length == 0 && options->slowVersionDetection)
|
2023-10-30 22:46:38 +08:00
|
|
|
{
|
|
|
|
|
if (ffProcessAppendStdOut(result, (char* const[]){
|
|
|
|
|
"gnome-shell",
|
|
|
|
|
"--version",
|
|
|
|
|
NULL
|
|
|
|
|
}) == NULL) // GNOME Shell 44.1
|
|
|
|
|
ffStrbufSubstrAfterLastC(result, ' ');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-31 09:54:12 +08:00
|
|
|
static void getCinnamon(FFstrbuf* result, FF_MAYBE_UNUSED FFDEOptions* options)
|
2023-10-30 22:46:38 +08:00
|
|
|
{
|
2024-07-03 09:09:06 +08:00
|
|
|
ffStrbufSetS(result, getenv("CINNAMON_VERSION"));
|
|
|
|
|
|
|
|
|
|
if (result->length == 0)
|
|
|
|
|
ffParsePropFileData("applications/cinnamon.desktop", "X-GNOME-Bugzilla-Version =", result);
|
|
|
|
|
|
|
|
|
|
if (!result->length == 0 && options->slowVersionDetection)
|
|
|
|
|
{
|
|
|
|
|
if (ffProcessAppendStdOut(result, (char* const[]){
|
|
|
|
|
"cinnamon",
|
|
|
|
|
"--version",
|
|
|
|
|
NULL
|
|
|
|
|
}) == NULL) // Cinnamon 6.2.2
|
|
|
|
|
ffStrbufSubstrAfterLastC(result, ' ');
|
|
|
|
|
}
|
2023-10-30 22:46:38 +08:00
|
|
|
}
|
|
|
|
|
|
2023-10-31 09:54:12 +08:00
|
|
|
static void getMate(FFstrbuf* result, FFDEOptions* options)
|
2023-10-30 22:46:38 +08:00
|
|
|
{
|
|
|
|
|
FF_STRBUF_AUTO_DESTROY major = ffStrbufCreate();
|
|
|
|
|
FF_STRBUF_AUTO_DESTROY minor = ffStrbufCreate();
|
|
|
|
|
FF_STRBUF_AUTO_DESTROY micro = ffStrbufCreate();
|
|
|
|
|
|
|
|
|
|
ffParsePropFileDataValues("mate-about/mate-version.xml", 3, (FFpropquery[]) {
|
|
|
|
|
{"<platform>", &major},
|
|
|
|
|
{"<minor>", &minor},
|
|
|
|
|
{"<micro>", µ}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ffParseSemver(result, &major, &minor, µ);
|
|
|
|
|
|
2023-10-31 09:54:12 +08:00
|
|
|
if(result->length == 0 && options->slowVersionDetection)
|
2023-10-30 22:46:38 +08:00
|
|
|
{
|
|
|
|
|
ffProcessAppendStdOut(result, (char* const[]){
|
|
|
|
|
"mate-session",
|
|
|
|
|
"--version",
|
|
|
|
|
NULL
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ffStrbufSubstrAfterFirstC(result, ' ');
|
|
|
|
|
ffStrbufTrim(result, ' ');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-11 16:36:12 +08:00
|
|
|
static const char* getXfce4ByLib(FFstrbuf* result)
|
2023-10-30 22:46:38 +08:00
|
|
|
{
|
2024-05-24 14:40:14 +08:00
|
|
|
#ifndef FF_DISABLE_DLOPEN
|
2023-12-11 16:36:12 +08:00
|
|
|
const char* xfce_version_string(void); // from `xfce4/libxfce4util/xfce-misutils.h
|
|
|
|
|
FF_LIBRARY_LOAD(xfce4util, NULL, "dlopen libxfce4util" FF_LIBRARY_EXTENSION "failed", "libxfce4util" FF_LIBRARY_EXTENSION, 7);
|
|
|
|
|
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(xfce4util, xfce_version_string);
|
|
|
|
|
ffStrbufSetS(result, ffxfce_version_string());
|
|
|
|
|
return NULL;
|
2024-05-24 14:40:14 +08:00
|
|
|
#else
|
|
|
|
|
FF_UNUSED(result);
|
|
|
|
|
return "dlopen is disabled";
|
|
|
|
|
#endif
|
2023-12-11 16:36:12 +08:00
|
|
|
}
|
2023-10-30 22:46:38 +08:00
|
|
|
|
2023-12-11 16:36:12 +08:00
|
|
|
static void getXFCE4(FFstrbuf* result, FFDEOptions* options)
|
|
|
|
|
{
|
|
|
|
|
getXfce4ByLib(result);
|
2023-10-30 22:46:38 +08:00
|
|
|
|
2023-10-31 09:54:12 +08:00
|
|
|
if(result->length == 0 && options->slowVersionDetection)
|
2023-10-30 22:46:38 +08:00
|
|
|
{
|
|
|
|
|
//This is somewhat slow
|
|
|
|
|
ffProcessAppendStdOut(result, (char* const[]){
|
|
|
|
|
"xfce4-session",
|
|
|
|
|
"--version",
|
|
|
|
|
NULL
|
|
|
|
|
});
|
|
|
|
|
|
2023-12-11 16:36:12 +08:00
|
|
|
ffStrbufSubstrBeforeFirstC(result, ')');
|
|
|
|
|
ffStrbufSubstrAfterLastC(result, ' ');
|
2023-10-30 22:46:38 +08:00
|
|
|
ffStrbufTrim(result, ' ');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-31 09:54:12 +08:00
|
|
|
static void getLXQt(FFstrbuf* result, FFDEOptions* options)
|
2023-10-30 22:46:38 +08:00
|
|
|
{
|
|
|
|
|
ffParsePropFileData("gconfig/lxqt.pc", "Version:", result);
|
|
|
|
|
|
|
|
|
|
if(result->length == 0)
|
|
|
|
|
ffParsePropFileData("cmake/lxqt/lxqt-config.cmake", "set ( LXQT_VERSION", result);
|
|
|
|
|
if(result->length == 0)
|
|
|
|
|
ffParsePropFileData("cmake/lxqt/lxqt-config-version.cmake", "set ( PACKAGE_VERSION", result);
|
|
|
|
|
|
2023-10-31 09:54:12 +08:00
|
|
|
if(result->length == 0 && options->slowVersionDetection)
|
2023-10-30 22:46:38 +08:00
|
|
|
{
|
|
|
|
|
//This is really, really, really slow. Thank you, LXQt developers
|
|
|
|
|
ffProcessAppendStdOut(result, (char* const[]){
|
|
|
|
|
"lxqt-session",
|
|
|
|
|
"-v",
|
|
|
|
|
NULL
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
result->length = 0; //don't set '\0' byte
|
|
|
|
|
ffParsePropLines(result->chars , "liblxqt", result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-31 09:54:12 +08:00
|
|
|
static void getBudgie(FFstrbuf* result, FF_MAYBE_UNUSED FFDEOptions* options)
|
2023-10-30 22:46:38 +08:00
|
|
|
{
|
|
|
|
|
ffParsePropFileData("budgie/budgie-version.xml", "<str>", result);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-31 09:54:12 +08:00
|
|
|
const char* ffDetectDEVersion(const FFstrbuf* deName, FFstrbuf* result, FFDEOptions* options)
|
2023-10-30 22:46:38 +08:00
|
|
|
{
|
|
|
|
|
if (ffStrbufEqualS(deName, FF_DE_PRETTY_PLASMA))
|
2023-10-31 09:54:12 +08:00
|
|
|
getKDE(result, options);
|
2023-11-17 22:23:36 +01:00
|
|
|
else if (ffStrbufEqualS(deName, FF_DE_PRETTY_GNOME))
|
2023-10-31 09:54:12 +08:00
|
|
|
getGnome(result, options);
|
2023-10-30 22:46:38 +08:00
|
|
|
else if (ffStrbufEqualS(deName, FF_DE_PRETTY_CINNAMON))
|
2023-10-31 09:54:12 +08:00
|
|
|
getCinnamon(result, options);
|
2023-10-30 22:46:38 +08:00
|
|
|
else if (ffStrbufEqualS(deName, FF_DE_PRETTY_XFCE4))
|
2023-10-31 09:54:12 +08:00
|
|
|
getXFCE4(result, options);
|
2023-10-30 22:46:38 +08:00
|
|
|
else if (ffStrbufEqualS(deName, FF_DE_PRETTY_MATE))
|
2023-10-31 09:54:12 +08:00
|
|
|
getMate(result, options);
|
2023-10-30 22:46:38 +08:00
|
|
|
else if (ffStrbufEqualS(deName, FF_DE_PRETTY_LXQT))
|
2023-10-31 09:54:12 +08:00
|
|
|
getLXQt(result, options);
|
2023-10-30 22:46:38 +08:00
|
|
|
else if (ffStrbufEqualS(deName, FF_DE_PRETTY_BUDGIE))
|
2023-10-31 09:54:12 +08:00
|
|
|
getBudgie(result, options);
|
2023-10-30 22:46:38 +08:00
|
|
|
else
|
|
|
|
|
return "Unsupported DE";
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|