mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
basic gnome support
This commit is contained in:
+24
-6
@@ -15,7 +15,8 @@ typedef enum ProtocolHint
|
||||
typedef enum DEHint
|
||||
{
|
||||
FF_DE_HINT_UNKNOWN = 0,
|
||||
FF_DE_HINT_KDE
|
||||
FF_DE_HINT_PLASMA,
|
||||
FF_DE_HINT_GNOME
|
||||
} DEHint;
|
||||
|
||||
typedef struct ProcData
|
||||
@@ -115,7 +116,7 @@ static bool applyPrettyNameIfWM(FFWMDEResult* result, const FFstrbuf* processNam
|
||||
ffStrbufSetS(&result->wmPrettyName, "XFWM");
|
||||
*protocolHint = FF_PROTOCOL_HINT_X11;
|
||||
}
|
||||
else if(ffStrbufIgnCaseCompS(processName, "mutter") == 0)
|
||||
else if(ffStrbufIgnCaseCompS(processName, "gnome-session-binary") == 0)
|
||||
ffStrbufSetS(&result->wmPrettyName, "Mutter");
|
||||
else if(ffStrbufIgnCaseCompS(processName, "cinnamon") == 0)
|
||||
ffStrbufSetS(&result->wmPrettyName, "Muffin");
|
||||
@@ -132,7 +133,9 @@ static bool applyPrettyNameIfWM(FFWMDEResult* result, const FFstrbuf* processNam
|
||||
static bool applyDEHintIfDE(const FFstrbuf* processName, DEHint* deHint)
|
||||
{
|
||||
if(ffStrbufIgnCaseCompS(processName, "plasmashell") == 0)
|
||||
*deHint = FF_DE_HINT_KDE;
|
||||
*deHint = FF_DE_HINT_PLASMA;
|
||||
else if(ffStrbufIgnCaseCompS(processName, "gnome-shell") == 0)
|
||||
*deHint = FF_DE_HINT_GNOME;
|
||||
|
||||
return *deHint != FF_DE_HINT_UNKNOWN;
|
||||
}
|
||||
@@ -157,8 +160,10 @@ static void getFromProcDir(FFWMDEResult* result, ProcData* procData, bool search
|
||||
continue;
|
||||
|
||||
ffStrbufAppendS(&procPath, procData->dirent->d_name);
|
||||
ffStrbufAppendS(&procPath, "/comm");
|
||||
ffStrbufAppendS(&procPath, "/cmdline");
|
||||
ffGetFileContent(procPath.chars, &processName);
|
||||
ffStrbufRecalculateLength(&processName);
|
||||
ffStrbufSubstrAfterLastC(&processName, '/');
|
||||
ffStrbufSubstrBefore(&procPath, procPathLength);
|
||||
|
||||
//If the are searching for WM, we are also always searching for DE. Therefore !searchWM must be last in the condition
|
||||
@@ -194,7 +199,16 @@ static void getKDE(FFWMDEResult* result)
|
||||
ffStrbufSetS(&result->deProcessName, "plasmashell");
|
||||
ffStrbufSetS(&result->dePrettyName, "KDE Plasma");
|
||||
|
||||
ffParsePropFile("/usr/share/xsessions/plasma.desktop", "X-KDE-PluginInfo-Version=%[^\n]", result->deVersion.chars);
|
||||
ffParsePropFile("/usr/share/xsessions/plasma.desktop", " X-KDE-PluginInfo-Version=%[^\n]", result->deVersion.chars);
|
||||
ffStrbufRecalculateLength(&result->deVersion);
|
||||
}
|
||||
|
||||
static void getGnome(FFWMDEResult* result)
|
||||
{
|
||||
ffStrbufSetS(&result->deProcessName, "gnome-session-binary");
|
||||
ffStrbufSetS(&result->dePrettyName, "GNOME");
|
||||
|
||||
ffParsePropFile("/usr/share/gnome-shell/org.gnome.Extensions", " version: '%[^']", result->deVersion.chars);
|
||||
ffStrbufRecalculateLength(&result->deVersion);
|
||||
}
|
||||
|
||||
@@ -205,8 +219,10 @@ static inline void getDEFromHint(FFWMDEResult* result, ProcData* procData)
|
||||
if(procData->deHint == FF_DE_HINT_UNKNOWN)
|
||||
return;
|
||||
|
||||
if(procData->deHint == FF_DE_HINT_KDE)
|
||||
if(procData->deHint == FF_DE_HINT_PLASMA)
|
||||
getKDE(result);
|
||||
else if(procData->deHint == FF_DE_HINT_GNOME)
|
||||
getGnome(result);
|
||||
}
|
||||
|
||||
static inline void getDE(FFWMDEResult* result, ProcData* procData)
|
||||
@@ -224,6 +240,8 @@ static inline void getDE(FFWMDEResult* result, ProcData* procData)
|
||||
|
||||
if(strcasecmp(result->sessionDesktop, "KDE") == 0)
|
||||
getKDE(result);
|
||||
else if(strcasecmp(result->sessionDesktop, "Gnome") == 0 || strcasecmp(result->sessionDesktop, "ubuntu:GNOME") == 0 || strcasecmp(result->sessionDesktop, "ubuntu") == 0)
|
||||
getGnome(result);
|
||||
else
|
||||
{
|
||||
ffStrbufSetS(&result->deProcessName, result->sessionDesktop);
|
||||
|
||||
+4
-2
@@ -275,11 +275,13 @@ static inline void printCommandHelp(const char* command)
|
||||
}
|
||||
else if(strcasecmp(command, "packages-format") == 0)
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("packages", "{2} (pacman), {3} (flatpak), {4} (xbps)", 4,
|
||||
constructAndPrintCommandHelpFormat("packages", "{2} (pacman), {3} (xbps), {4} (dpkg), {5}, (flatpak), {6} (snap)", 6,
|
||||
"Number of all packages",
|
||||
"Number of pacman packages",
|
||||
"Number of xbps packages",
|
||||
"Number of dpkg packages",
|
||||
"Number of flatpak packages",
|
||||
"Number of xbps packages"
|
||||
"Number of snap packages"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "shell-format") == 0)
|
||||
|
||||
+40
-8
@@ -1,11 +1,12 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#define FF_PACKAGES_MODULE_NAME "Packages"
|
||||
#define FF_PACKAGES_NUM_FORMAT_ARGS 4
|
||||
#define FF_PACKAGES_NUM_FORMAT_ARGS 6
|
||||
|
||||
static uint32_t get_num_elements(const char* dirname, unsigned char type) {
|
||||
static uint32_t getNumElements(const char* dirname, unsigned char type) {
|
||||
uint32_t num_elements = 0;
|
||||
DIR * dirp;
|
||||
struct dirent *entry;
|
||||
@@ -27,13 +28,40 @@ static uint32_t get_num_elements(const char* dirname, unsigned char type) {
|
||||
return num_elements;
|
||||
}
|
||||
|
||||
static uint32_t getNumStrings(const char* filename, const char* needle)
|
||||
{
|
||||
FILE* file = fopen(filename, "r");
|
||||
if(file == NULL)
|
||||
return 0;
|
||||
|
||||
uint32_t count = 0;
|
||||
|
||||
char* line = NULL;
|
||||
size_t len = 0;
|
||||
|
||||
while(getline(&line, &len, file) != EOF)
|
||||
{
|
||||
if(strstr(line, needle) != NULL)
|
||||
++count;
|
||||
}
|
||||
|
||||
if(line != NULL)
|
||||
free(line);
|
||||
|
||||
fclose(file);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void ffPrintPackages(FFinstance* instance)
|
||||
{
|
||||
uint32_t pacman = get_num_elements("/var/lib/pacman/local", DT_DIR);
|
||||
uint32_t flatpak = get_num_elements("/var/lib/flatpak/app", DT_DIR);
|
||||
uint32_t xbps = get_num_elements("/var/db/xbps", DT_REG);
|
||||
uint32_t pacman = getNumElements("/var/lib/pacman/local", DT_DIR);
|
||||
uint32_t xbps = getNumElements("/var/db/xbps", DT_REG);
|
||||
uint32_t dpkg = getNumStrings("/var/lib/dpkg/status", "Status: ");
|
||||
uint32_t flatpak = getNumElements("/var/lib/flatpak/app", DT_DIR);
|
||||
uint32_t snap = getNumElements("/snap", DT_DIR);
|
||||
|
||||
uint32_t all = pacman + flatpak + xbps;
|
||||
uint32_t all = pacman + xbps + dpkg + flatpak + snap;
|
||||
|
||||
if(all == 0)
|
||||
{
|
||||
@@ -54,8 +82,10 @@ void ffPrintPackages(FFinstance* instance)
|
||||
};
|
||||
|
||||
FF_PRINT_PACKAGE(pacman)
|
||||
FF_PRINT_PACKAGE(flatpak)
|
||||
FF_PRINT_PACKAGE(xbps)
|
||||
FF_PRINT_PACKAGE(dpkg)
|
||||
FF_PRINT_PACKAGE(flatpak)
|
||||
FF_PRINT_PACKAGE(snap)
|
||||
|
||||
#undef FF_PRINT_PACKAGE
|
||||
|
||||
@@ -66,8 +96,10 @@ void ffPrintPackages(FFinstance* instance)
|
||||
ffPrintFormatString(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packagesKey, &instance->config.packagesFormat, NULL, FF_PACKAGES_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &all},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &pacman},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &xbps},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &dpkg},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &flatpak},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &xbps}
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &snap}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+36
-1
@@ -34,6 +34,39 @@ static void printKWin(FFinstance* instance)
|
||||
printWMTheme(instance, theme);
|
||||
}
|
||||
|
||||
static void printMutter(FFinstance* instance)
|
||||
{
|
||||
FFstrbuf theme;
|
||||
ffStrbufInit(&theme);
|
||||
|
||||
ffProcessAppendStdOut(&theme, (char* const[]) {
|
||||
"gsettings",
|
||||
"get",
|
||||
"org.gnome.shell.extensions.user-theme",
|
||||
"name",
|
||||
NULL
|
||||
});
|
||||
|
||||
ffStrbufTrim(&theme, '\'');
|
||||
|
||||
if(theme.length == 0)
|
||||
{
|
||||
ffProcessAppendStdOut(&theme, (char* const[]) {
|
||||
"gsettings",
|
||||
"get",
|
||||
"org.gnome.desktop.wm.preferences",
|
||||
"theme",
|
||||
NULL
|
||||
});
|
||||
}
|
||||
|
||||
ffStrbufTrim(&theme, '\'');
|
||||
|
||||
printWMTheme(instance, theme.chars);
|
||||
|
||||
ffStrbufDestroy(&theme);
|
||||
}
|
||||
|
||||
static void printOpenbox(FFinstance* instance, const FFstrbuf* dePrettyName)
|
||||
{
|
||||
FFstrbuf absolutePath;
|
||||
@@ -108,8 +141,10 @@ void ffPrintWMTheme(FFinstance* instance)
|
||||
return;
|
||||
}
|
||||
|
||||
if(ffStrbufIgnCaseCompS(&result->wmPrettyName, "KWin") == 0)
|
||||
if(ffStrbufIgnCaseCompS(&result->wmPrettyName, "KWin") == 0 || ffStrbufIgnCaseCompS(&result->wmPrettyName, "KDE") == 0 || ffStrbufIgnCaseCompS(&result->wmPrettyName, "Plasma") == 0)
|
||||
printKWin(instance);
|
||||
else if(ffStrbufIgnCaseCompS(&result->wmPrettyName, "Mutter") == 0 || ffStrbufIgnCaseCompS(&result->wmPrettyName, "Gnome") == 0 || ffStrbufIgnCaseCompS(&result->wmPrettyName, "Ubuntu") == 0)
|
||||
printMutter(instance);
|
||||
else if(ffStrbufIgnCaseCompS(&result->wmPrettyName, "Openbox") == 0)
|
||||
printOpenbox(instance, &result->dePrettyName);
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user