mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
optional gtk detection via dconf
This commit is contained in:
@@ -25,9 +25,23 @@ endif(BUILD_TESTS)
|
||||
|
||||
configure_file(src/fastfetch_config.h.in fastfetch_config.h)
|
||||
|
||||
find_package (PkgConfig QUIET)
|
||||
|
||||
if(${PkgConfig_FOUND})
|
||||
pkg_check_modules (GLIB2 QUIET glib-2.0)
|
||||
endif(${PkgConfig_FOUND})
|
||||
|
||||
if(NOT DEFINED GLIB2_INCLUDE_DIRS)
|
||||
set(GLIB2_INCLUDE_DIRS
|
||||
/usr/include/glib-2.0/
|
||||
/usr/lib/glib-2.0/include/
|
||||
)
|
||||
endif(NOT DEFINED GLIB2_INCLUDE_DIRS)
|
||||
|
||||
include_directories(
|
||||
${PROJECT_BINARY_DIR}
|
||||
${PROJECT_SOURCE_DIR}/src
|
||||
${GLIB2_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set(SRCS
|
||||
|
||||
@@ -29,6 +29,7 @@ Following libraries are used if present:
|
||||
* [`libpci`](https://github.com/pciutils/pciutils): Needed for GPU output. _Should_ be available on every linux system.
|
||||
* [`libX11`](https://gitlab.freedesktop.org/xorg/lib/libx11): Needed for resolution output
|
||||
* [`libXrandr`](https://gitlab.freedesktop.org/xorg/lib/libxrandr): Needed for appending refresh rate to resolution output.
|
||||
* [`libDConf`](https://developer.gnome.org/dconf/unstable/DConfClient.html): GTK theme/font/icons output on DEs which dont use config files (e.g. Gnome).
|
||||
|
||||
## Building
|
||||
|
||||
|
||||
@@ -176,6 +176,7 @@ __fastfetch_completion()
|
||||
"--lib-PCI"
|
||||
"--lib-X11"
|
||||
"--lib-Xrandr"
|
||||
"--lib-DConf"
|
||||
)
|
||||
|
||||
local FF_OPTIONS_LOGO=(
|
||||
|
||||
@@ -75,6 +75,7 @@ void ffDefaultConfig(FFconfig* config)
|
||||
ffStrbufInitA(&config->libPCI, 1);
|
||||
ffStrbufInitA(&config->libX11, 1);
|
||||
ffStrbufInitA(&config->libXrandr, 1);
|
||||
ffStrbufInitA(&config->libDConf, 1);
|
||||
|
||||
ffStrbufInitA(&config->diskFolders, 1);
|
||||
}
|
||||
|
||||
@@ -108,10 +108,12 @@ static inline void printHelp()
|
||||
" --lib-PCI <path>\n"
|
||||
" --lib-X11 <path>\n"
|
||||
" --lib-Xrandr <path>\n"
|
||||
" --lib-DConf <path>\n"
|
||||
"\n"
|
||||
"Module specific options:\n"
|
||||
" --disk-folders <folders>: A colon seperated list of folder paths for the disk output. Default is \"/:/home\"\n"
|
||||
"\n"
|
||||
"Parsing is not case sensetive. E.g. \"--lib-PCI\" is equal to \"--Lib-Pci\"\n"
|
||||
"If an value starts with an ?, it is optional. \"true\" will be used if not set.\n"
|
||||
"An (+) at the end indicates that more help can be printed with --help <option>\n"
|
||||
"All options can be make permanent in $XDG_CONFIG_HOME/fastfetch/config.conf"
|
||||
@@ -643,6 +645,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
optionParseString(key, value, &instance->config.libX11);
|
||||
else if(strcasecmp(key, "--lib-Xrandr") == 0)
|
||||
optionParseString(key, value, &instance->config.libXrandr);
|
||||
else if(strcasecmp(key, "--lib-DConf") == 0)
|
||||
optionParseString(key, value, &instance->config.libDConf);
|
||||
else if(strcasecmp(key, "--disk-folders") == 0)
|
||||
optionParseString(key, value, &instance->config.diskFolders);
|
||||
else
|
||||
|
||||
@@ -92,6 +92,7 @@ typedef struct FFconfig
|
||||
FFstrbuf libPCI;
|
||||
FFstrbuf libX11;
|
||||
FFstrbuf libXrandr;
|
||||
FFstrbuf libDConf;
|
||||
|
||||
FFstrbuf diskFolders;
|
||||
|
||||
|
||||
@@ -1,5 +1,88 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
#include "dconf/client/dconf-client.h"
|
||||
#include "dlfcn.h"
|
||||
|
||||
static inline bool allPropertiesSet(FFstrbuf* themeNamePtr, FFstrbuf* iconsNamePtr, FFstrbuf* fontNamePtr)
|
||||
{
|
||||
return
|
||||
themeNamePtr->length > 0 &&
|
||||
iconsNamePtr->length > 0 &&
|
||||
fontNamePtr->length > 0;
|
||||
}
|
||||
|
||||
static void parseGTKDConfSettings(FFinstance* instance, FFstrbuf* themeNamePtr, FFstrbuf* iconsNamePtr, FFstrbuf* fontNamePtr)
|
||||
{
|
||||
static const gchar* themeName;
|
||||
static const gchar* iconsName;
|
||||
static const gchar* fontName;
|
||||
|
||||
static bool init = false;
|
||||
if(init)
|
||||
{
|
||||
ffStrbufAppendS(themeNamePtr, themeName);
|
||||
ffStrbufAppendS(iconsNamePtr, iconsName);
|
||||
ffStrbufAppendS(fontNamePtr, fontName);
|
||||
return;
|
||||
}
|
||||
init = true;
|
||||
|
||||
void* dconf;
|
||||
if(instance->config.libDConf.length == 0)
|
||||
dconf = dlopen("libdconf.so", RTLD_LAZY);
|
||||
else
|
||||
dconf = dlopen(instance->config.libDConf.chars, RTLD_LAZY);
|
||||
|
||||
if(dconf == NULL)
|
||||
return;
|
||||
|
||||
DConfClient*(*ffdconf_client_new)(void) = dlsym(dconf, "dconf_client_new");
|
||||
if(ffdconf_client_new == NULL)
|
||||
{
|
||||
dlclose(dconf);
|
||||
return;
|
||||
}
|
||||
|
||||
const gchar*(*ffg_variant_get_string)(GVariant*, gsize*) = dlsym(dconf, "g_variant_get_string");
|
||||
if(ffg_variant_get_string == NULL)
|
||||
{
|
||||
dlclose(dconf);
|
||||
return;
|
||||
}
|
||||
|
||||
GVariant*(*ffdconf_client_read)(DConfClient*, const gchar*) = dlsym(dconf, "dconf_client_read");
|
||||
if(ffdconf_client_read == NULL)
|
||||
{
|
||||
dlclose(dconf);
|
||||
return;
|
||||
}
|
||||
|
||||
DConfClient* dconfClient = ffdconf_client_new();
|
||||
if(dconfClient == NULL)
|
||||
{
|
||||
dlclose(dconf);
|
||||
return;
|
||||
}
|
||||
|
||||
GVariant* themeNameVariant = ffdconf_client_read(dconfClient, "/org/gnome/desktop/interface/gtk-theme");
|
||||
if(themeNameVariant != NULL)
|
||||
themeName = ffg_variant_get_string(themeNameVariant, NULL);
|
||||
|
||||
GVariant* fontNameVariant = ffdconf_client_read(dconfClient, "/org/gnome/desktop/interface/font-name");
|
||||
if(fontNameVariant != NULL)
|
||||
fontName = ffg_variant_get_string(fontNameVariant, NULL);
|
||||
|
||||
GVariant* iconsNameVariant = ffdconf_client_read(dconfClient, "/org/gnome/desktop/interface/icon-theme");
|
||||
if(iconsNameVariant != NULL)
|
||||
iconsName = ffg_variant_get_string(iconsNameVariant, NULL);
|
||||
|
||||
dlclose(dconf);
|
||||
|
||||
ffStrbufAppendS(themeNamePtr, themeName);
|
||||
ffStrbufAppendS(iconsNamePtr, iconsName);
|
||||
ffStrbufAppendS(fontNamePtr, fontName);
|
||||
}
|
||||
|
||||
static void parseGTKConfigFile(FFstrbuf* fileName, FFstrbuf* themeNamePtr, FFstrbuf* iconsNamePtr, FFstrbuf* fontNamePtr)
|
||||
{
|
||||
FILE* file = fopen(fileName->chars, "r");
|
||||
@@ -51,6 +134,8 @@ static void calculateGTKFromConfigDir(const char* configDir, const char* version
|
||||
ffStrbufAppendS(&file1, ".0/settings.ini");
|
||||
parseGTKConfigFile(&file1, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
ffStrbufDestroy(&file1);
|
||||
if(allPropertiesSet(themeNamePtr, iconsNamePtr, fontNamePtr))
|
||||
return;
|
||||
|
||||
// <configdir>/gtk-<version>.0/gtkrc
|
||||
FFstrbuf file2;
|
||||
@@ -61,6 +146,8 @@ static void calculateGTKFromConfigDir(const char* configDir, const char* version
|
||||
ffStrbufAppendS(&file2, ".0/gtkrc");
|
||||
parseGTKConfigFile(&file2, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
ffStrbufDestroy(&file2);
|
||||
if(allPropertiesSet(themeNamePtr, iconsNamePtr, fontNamePtr))
|
||||
return;
|
||||
|
||||
// <configdir>/gtkrc-<version>.0
|
||||
FFstrbuf file3;
|
||||
@@ -71,6 +158,8 @@ static void calculateGTKFromConfigDir(const char* configDir, const char* version
|
||||
ffStrbufAppendS(&file3, ".0");
|
||||
parseGTKConfigFile(&file3, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
ffStrbufDestroy(&file3);
|
||||
if(allPropertiesSet(themeNamePtr, iconsNamePtr, fontNamePtr))
|
||||
return;
|
||||
|
||||
// <configdir>/.gtkrc-<version>.0
|
||||
FFstrbuf file4;
|
||||
@@ -118,9 +207,15 @@ static void calculateGTK(FFinstance* instance, const char* version, FFstrbuf* th
|
||||
}
|
||||
|
||||
if(xdgIsDifferent)
|
||||
{
|
||||
calculateGTKFromConfigDir(xdgConfigDir.chars, version, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
if(allPropertiesSet(themeNamePtr, iconsNamePtr, fontNamePtr))
|
||||
return;
|
||||
}
|
||||
|
||||
calculateGTKFromConfigDir(configDir.chars, version, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
if(allPropertiesSet(themeNamePtr, iconsNamePtr, fontNamePtr))
|
||||
return;
|
||||
|
||||
// <homedir>/gtkrc-<version>.0
|
||||
FFstrbuf homeConfig1;
|
||||
@@ -131,6 +226,8 @@ static void calculateGTK(FFinstance* instance, const char* version, FFstrbuf* th
|
||||
ffStrbufAppendS(&homeConfig1, ".0");
|
||||
parseGTKConfigFile(&homeConfig1, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
ffStrbufDestroy(&homeConfig1);
|
||||
if(allPropertiesSet(themeNamePtr, iconsNamePtr, fontNamePtr))
|
||||
return;
|
||||
|
||||
// <homedir>/.gtkrc-<version>.0
|
||||
FFstrbuf homeConfig2;
|
||||
@@ -141,6 +238,12 @@ static void calculateGTK(FFinstance* instance, const char* version, FFstrbuf* th
|
||||
ffStrbufAppendS(&homeConfig2, ".0");
|
||||
parseGTKConfigFile(&homeConfig2, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
ffStrbufDestroy(&homeConfig2);
|
||||
if(allPropertiesSet(themeNamePtr, iconsNamePtr, fontNamePtr))
|
||||
return;
|
||||
|
||||
parseGTKDConfSettings(instance, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
if(allPropertiesSet(themeNamePtr, iconsNamePtr, fontNamePtr))
|
||||
return;
|
||||
|
||||
calculateGTKFromConfigDir("/etc/", version, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ void ffPrintGPU(FFinstance* instance)
|
||||
pci = dlopen("libpci.so", RTLD_LAZY);
|
||||
else
|
||||
pci = dlopen(instance->config.libPCI.chars, RTLD_LAZY);
|
||||
|
||||
if(pci == NULL)
|
||||
{
|
||||
ffPrintError(instance, &key, NULL, "dlopen(\"libpci.so\", RTLD_LAZY) == NULL");
|
||||
@@ -83,6 +84,7 @@ void ffPrintGPU(FFinstance* instance)
|
||||
struct pci_access*(*ffpci_alloc)() = dlsym(pci, "pci_alloc");
|
||||
if(ffpci_alloc == NULL)
|
||||
{
|
||||
dlclose(pci);
|
||||
ffPrintError(instance, &key, NULL, "dlsym(pci, \"pci_alloc\") == NULL");
|
||||
return;
|
||||
}
|
||||
@@ -90,6 +92,7 @@ void ffPrintGPU(FFinstance* instance)
|
||||
void(*ffpci_init)(struct pci_access*) = dlsym(pci, "pci_init");
|
||||
if(ffpci_init == NULL)
|
||||
{
|
||||
dlclose(pci);
|
||||
ffPrintError(instance, &key, NULL, "dlsym(pci, \"pci_init\") == NULL");
|
||||
return;
|
||||
}
|
||||
@@ -97,6 +100,7 @@ void ffPrintGPU(FFinstance* instance)
|
||||
void(*ffpci_scan_bus)(struct pci_access*) = dlsym(pci, "pci_scan_bus");
|
||||
if(ffpci_scan_bus == NULL)
|
||||
{
|
||||
dlclose(pci);
|
||||
ffPrintError(instance, &key, NULL, "dlsym(pci, \"pci_init\") == NULL");
|
||||
return;
|
||||
}
|
||||
@@ -104,6 +108,7 @@ void ffPrintGPU(FFinstance* instance)
|
||||
int(*ffpci_fill_info)(struct pci_dev*, int) = dlsym(pci, "pci_fill_info");
|
||||
if(ffpci_fill_info == NULL)
|
||||
{
|
||||
dlclose(pci);
|
||||
ffPrintError(instance, &key, NULL, "dlsym(pci, \"pci_fill_info\") == NULL");
|
||||
return;
|
||||
}
|
||||
@@ -111,6 +116,7 @@ void ffPrintGPU(FFinstance* instance)
|
||||
char*(*ffpci_lookup_name)(struct pci_access*, char*, int, int, ...) = dlsym(pci, "pci_lookup_name");
|
||||
if(ffpci_lookup_name == NULL)
|
||||
{
|
||||
dlclose(pci);
|
||||
ffPrintError(instance, &key, NULL, "dlsym(pci, \"pci_lookup_name\") == NULL");
|
||||
return;
|
||||
}
|
||||
@@ -118,6 +124,7 @@ void ffPrintGPU(FFinstance* instance)
|
||||
void(*ffpci_cleanup)(struct pci_access*) = dlsym(pci, "pci_cleanup");
|
||||
if(ffpci_cleanup == NULL)
|
||||
{
|
||||
dlclose(pci);
|
||||
ffPrintError(instance, &key, NULL, "dlsym(pci, \"pci_cleanup\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -10,22 +10,32 @@ static int getCurrentRate(FFinstance* instance, Display* display)
|
||||
xrandr = dlopen("libXrandr.so", RTLD_LAZY);
|
||||
else
|
||||
xrandr = dlopen(instance->config.libXrandr.chars, RTLD_LAZY);
|
||||
|
||||
if(xrandr == NULL)
|
||||
return 0;
|
||||
|
||||
Window root = RootWindow(display, 0);
|
||||
|
||||
XRRScreenConfiguration*(*ffXRRGetScreenInfo)(Display*, Window) = dlsym(xrandr, "XRRGetScreenInfo");
|
||||
if(ffXRRGetScreenInfo == NULL)
|
||||
{
|
||||
dlclose(xrandr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
short(*ffXRRConfigCurrentRate)(XRRScreenConfiguration*) = dlsym(xrandr, "XRRConfigCurrentRate");
|
||||
if(ffXRRConfigCurrentRate == NULL)
|
||||
{
|
||||
dlclose(xrandr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Window root = RootWindow(display, 0);
|
||||
|
||||
XRRScreenConfiguration* xrrscreenconf = ffXRRGetScreenInfo(display, root);
|
||||
if(xrrscreenconf == NULL)
|
||||
{
|
||||
dlclose(xrandr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
short currentRate = ffXRRConfigCurrentRate(xrrscreenconf);
|
||||
|
||||
@@ -48,6 +58,7 @@ void ffPrintResolution(FFinstance* instance)
|
||||
x11 = dlopen("libX11.so", RTLD_LAZY);
|
||||
else
|
||||
x11 = dlopen(instance->config.libX11.chars, RTLD_LAZY);
|
||||
|
||||
if(x11 == NULL)
|
||||
{
|
||||
ffPrintError(instance, &instance->config.resolutionFormat, "Resolution", "dlopen(\"libX11.so\", RTLD_LAZY) == NULL");
|
||||
@@ -57,6 +68,7 @@ void ffPrintResolution(FFinstance* instance)
|
||||
Display*(*ffXOpenDisplay)(const char*) = dlsym(x11, "XOpenDisplay");
|
||||
if(ffXOpenDisplay == NULL)
|
||||
{
|
||||
dlclose(x11);
|
||||
ffPrintError(instance, &instance->config.resolutionFormat, "Resolution", "dlsym(x11, \"XOpenDisplay\") == NULL");
|
||||
return;
|
||||
}
|
||||
@@ -64,6 +76,7 @@ void ffPrintResolution(FFinstance* instance)
|
||||
Display* display = ffXOpenDisplay(NULL);
|
||||
if(display == NULL)
|
||||
{
|
||||
dlclose(x11);
|
||||
ffPrintError(instance, &instance->config.resolutionFormat, "Resolution", "ffXOpenDisplay(NULL) == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ void ffPrintWMTheme(FFinstance* instance)
|
||||
|
||||
if(wmName->length == 0)
|
||||
{
|
||||
ffPrintError(instance, &instance->config.wmThemeKey, "WM Theme", "WM Theme needs sucessfull wm detection");
|
||||
ffPrintError(instance, &instance->config.wmThemeKey, "WM Theme", "WM Theme needs sucessfull WM detection");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user