mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-28 15:53:51 +01:00
TTY improvements
This commit is contained in:
+23
-12
@@ -267,6 +267,25 @@ static inline void getSessionType(FFWMDEResult* result, ProtocolHint protocolHin
|
||||
getSessionTypeFallback(result, protocolHint);
|
||||
}
|
||||
|
||||
static inline void getWMDE(FFWMDEResult* result)
|
||||
{
|
||||
ProcData procData;
|
||||
procData.proc = opendir("/proc");
|
||||
procData.dirent = NULL;
|
||||
procData.protocolHint = FF_PROTOCOL_HINT_UNKNOWN;
|
||||
procData.deHint = FF_DE_HINT_UNKNOWN;
|
||||
|
||||
getSessionDesktop(result);
|
||||
getWM(result, &procData);
|
||||
getDE(result, &procData);
|
||||
|
||||
if(result->wmProtocolName.length == 0 && procData.protocolHint != FF_PROTOCOL_HINT_UNKNOWN)
|
||||
getSessionType(result, procData.protocolHint);
|
||||
|
||||
if(procData.proc != NULL)
|
||||
closedir(procData.proc);
|
||||
}
|
||||
|
||||
const FFWMDEResult* ffDetectWMDE(FFinstance* instance)
|
||||
{
|
||||
UNUSED(instance);
|
||||
@@ -289,19 +308,11 @@ const FFWMDEResult* ffDetectWMDE(FFinstance* instance)
|
||||
ffStrbufInit(&result.dePrettyName);
|
||||
ffStrbufInit(&result.deVersion);
|
||||
|
||||
ProcData procData;
|
||||
procData.proc = opendir("/proc");
|
||||
procData.dirent = NULL;
|
||||
procData.protocolHint = FF_PROTOCOL_HINT_UNKNOWN;
|
||||
procData.deHint = FF_DE_HINT_UNKNOWN;
|
||||
getSessionType(&result, FF_PROTOCOL_HINT_UNKNOWN);
|
||||
|
||||
getSessionDesktop(&result);
|
||||
getWM(&result, &procData);
|
||||
getDE(&result, &procData);
|
||||
getSessionType(&result, procData.protocolHint);
|
||||
|
||||
if(procData.proc != NULL)
|
||||
closedir(procData.proc);
|
||||
//Don't run anyting when on TTY. This prevents us to catch process from other users in at least that case.
|
||||
if(ffStrbufIgnCaseCompS(&result.wmProtocolName, "TTY") != 0)
|
||||
getWMDE(&result);
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
void ffProcessGetStdOut(FFstrbuf* buffer, char* const argv[])
|
||||
void ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[])
|
||||
{
|
||||
int pipes[2];
|
||||
|
||||
|
||||
+1
-1
@@ -225,7 +225,7 @@ void ffParsePropFile(const char* file, const char* regex, char* buffer);
|
||||
void ffParsePropFileHome(FFinstance* instance, const char* relativeFile, const char* regex, char* buffer);
|
||||
|
||||
//common/processing.c
|
||||
void ffProcessGetStdOut(FFstrbuf* buffer, char* const argv[]);
|
||||
void ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[]);
|
||||
|
||||
//common/logo.c
|
||||
void ffLoadLogoSet(FFconfig* config, const char* logo);
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ void ffPrintShell(FFinstance* instance)
|
||||
ffStrbufAppendTransformS(&command, shellName != NULL ? shellName : shellPath, toupper);
|
||||
ffStrbufAppendS(&command, "_VERSION\"");
|
||||
|
||||
ffProcessGetStdOut(&version, (char* const[]){
|
||||
ffProcessAppendStdOut(&version, (char* const[]){
|
||||
shellPath,
|
||||
"-c",
|
||||
command.chars,
|
||||
|
||||
@@ -7,6 +7,18 @@
|
||||
#define FF_TERMINAL_MODULE_NAME "Terminal"
|
||||
#define FF_TERMINAL_NUM_FORMAT_ARGS 3
|
||||
|
||||
static inline void getTerminalFromEnv(FFTerminalResult* result)
|
||||
{
|
||||
char* term = getenv("TERM");
|
||||
|
||||
//TTY
|
||||
if(term == NULL || strcasecmp(term, "linux") == 0)
|
||||
term = ttyname(STDIN_FILENO);
|
||||
|
||||
ffStrbufSetS(&result->exeName, term);
|
||||
ffStrbufSetS(&result->processName, term);
|
||||
}
|
||||
|
||||
static void getTerminalName(FFinstance* instance, const char* pid, FFTerminalResult* result)
|
||||
{
|
||||
char statFile[234];
|
||||
@@ -76,6 +88,14 @@ const FFTerminalResult* ffDetectTerminal(FFinstance* instance)
|
||||
|
||||
getTerminalName(instance, ppid, &result);
|
||||
|
||||
// This is mainly used when running in TTY. It also provides an fallback to $TERM if we _somehow_ failed
|
||||
if(
|
||||
ffStrbufStartsWithIgnCaseS(&result.exeName, "login") ||
|
||||
ffStrbufIgnCaseCompS(&result.exeName, "systemd") == 0 ||
|
||||
ffStrbufIgnCaseCompS(&result.exeName, "init") == 0 ||
|
||||
ffStrbufIgnCaseCompS(&result.exeName, "(init)") == 0
|
||||
) getTerminalFromEnv(&result);
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
return &result;
|
||||
|
||||
@@ -71,12 +71,24 @@ static void printXFCE4Terminal(FFinstance* instance)
|
||||
|
||||
static void printTTY(FFinstance* instance)
|
||||
{
|
||||
char font[128];
|
||||
ffParsePropFile("/etc/vconsole.conf", "Font=%[^\n]", font);
|
||||
if(font[0] == '\0')
|
||||
strcpy(font, "hardware-supplied VGA font");
|
||||
FFstrbuf font;
|
||||
ffStrbufInit(&font);
|
||||
|
||||
printTerminalFont(instance, font);
|
||||
ffParsePropFile("/etc/vconsole.conf", "Font=%[^\n]", font.chars);
|
||||
ffStrbufRecalculateLength(&font);
|
||||
|
||||
if(font.length == 0)
|
||||
{
|
||||
ffStrbufAppendS(&font, "VGA default kernel font ");
|
||||
ffProcessAppendStdOut(&font, (char* const[]){
|
||||
"showconsolefont",
|
||||
"--info",
|
||||
NULL
|
||||
});
|
||||
}
|
||||
|
||||
printTerminalFont(instance, font.chars);
|
||||
ffStrbufDestroy(&font);
|
||||
}
|
||||
|
||||
void ffPrintTerminalFont(FFinstance* instance)
|
||||
@@ -93,8 +105,8 @@ void ffPrintTerminalFont(FFinstance* instance)
|
||||
printKonsole(instance);
|
||||
else if(ffStrbufIgnCaseCompS(&result->exeName, "xfce4-terminal") == 0)
|
||||
printXFCE4Terminal(instance);
|
||||
else if(ffStrbufStartsWithIgnCaseS(&result->exeName, "login"))
|
||||
else if(ffStrbufStartsWithIgnCaseS(&result->exeName, "/dev/tty"))
|
||||
printTTY(instance);
|
||||
else
|
||||
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Terminal Font", "Unknown terminal: %s", result->exeName.chars);
|
||||
ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Unknown terminal: %s", result->exeName.chars);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user