Windows: add basic support for msys2

This commit is contained in:
李通洲
2022-10-02 17:52:09 +08:00
parent 145e09d164
commit eaa4230bf5
8 changed files with 52 additions and 19 deletions
+1 -1
View File
@@ -257,7 +257,7 @@ void ffInitInstance(FFinstance* instance)
defaultConfig(instance);
}
#if !defined(__ANDROID__)
#if !defined(__ANDROID__) && !defined(__CYGWIN__)
static void* connectDisplayServerThreadMain(void* instance)
{
+1 -1
View File
@@ -5,7 +5,7 @@
const char* ffGetCpuUsageInfo(long* inUseAll, long* totalAll)
{
long user, nice, system, idle, iowait, irq, softirq;
long user = 0, nice = 0, system = 0, idle = 0, iowait = 0, irq = 0, softirq = 0;
FILE* procStat = fopen("/proc/stat", "r");
if(procStat == NULL)
+1
View File
@@ -6,6 +6,7 @@
#include "fastfetch.h"
#define FF_HOST_PRODUCT_NAME_WSL "Windows Subsystem for Linux"
#define FF_HOST_PRODUCT_NAME_MSYS "Windows on MSYS"
typedef struct FFHostResult
{
+8 -6
View File
@@ -109,10 +109,12 @@ void ffDetectHostImpl(FFHostResult* host)
if(ffStrbufStartsWithS(&host->productName, "Standard PC"))
ffStrbufPrependS(&host->productName, "KVM/QEMU ");
//On WSL, the real host can't be detected. Instead use WSL as host.
if(host->productFamily.length == 0 && host->productName.length == 0 && (
getenv("WSLENV") != NULL ||
getenv("WSL_DISTRO") != NULL ||
getenv("WSL_INTEROP") != NULL
)) ffStrbufAppendS(&host->productName, FF_HOST_PRODUCT_NAME_WSL);
if(host->productFamily.length == 0 && host->productName.length == 0)
{
//On WSL, the real host can't be detected. Instead use WSL as host.
if(getenv("WSL_DISTRO") != NULL || getenv("WSL_INTEROP") != NULL)
ffStrbufAppendS(&host->productName, FF_HOST_PRODUCT_NAME_WSL);
else if(getenv("MSYSTEM") != NULL && strcmp(getenv("MSYSTEM"), "MSYS") == 0)
ffStrbufAppendS(&host->productName, FF_HOST_PRODUCT_NAME_MSYS);
}
}
+8 -6
View File
@@ -1,4 +1,5 @@
#include "fastfetch.h"
#include "detection/host/host.h"
#include "detection/terminalshell.h"
#include "common/io.h"
#include "common/parsing.h"
@@ -149,17 +150,18 @@ static void getTerminalFromEnv(FFTerminalShellResult* result)
getenv("KONSOLE_VERSION") != NULL
)) term = "konsole";
//MacOS
//MacOS, mintty
if(!ffStrSet(term))
term = getenv("TERM_PROGRAM");
//We are in WSL but not in Windows Terminal
if(!ffStrSet(term) && (
getenv("WSLENV") != NULL ||
getenv("WSL_DISTRO") != NULL ||
getenv("WSL_INTEROP") != NULL
))
if(!ffStrSet(term))
{
const FFHostResult* host = ffDetectHost();
if(ffStrbufCompS(&host->productName, FF_HOST_PRODUCT_NAME_WSL) == 0 ||
ffStrbufCompS(&host->productName, FF_HOST_PRODUCT_NAME_MSYS) == 0)
term = "conhost";
}
//Normal Terminal
if(!ffStrSet(term))
@@ -312,6 +312,29 @@ static void detectFromWindowsTeriminal(const FFinstance* instance, FFTerminalFon
#endif
static void detectMintty(const FFinstance* instance, FFTerminalFontResult* terminalFont)
{
FFstrbuf fontName;
ffStrbufInit(&fontName);
FFstrbuf fontSize;
ffStrbufInit(&fontSize);
ffParsePropFileHomeValues(instance, ".minttyrc", 2, (FFpropquery[]) {
{"Font=", &fontName},
{"FontHeight=", &fontSize}
});
if(fontName.length == 0)
ffStrbufAppendS(&fontName, "Lucida Console");
if(fontSize.length == 0)
ffStrbufAppendC(&fontSize, '9');
ffFontInitValues(&terminalFont->font, fontName.chars, fontSize.chars);
ffStrbufDestroy(&fontName);
ffStrbufDestroy(&fontSize);
}
void ffDetectTerminalFontPlatform(const FFinstance* instance, const FFTerminalShellResult* terminalShell, FFTerminalFontResult* terminalFont)
{
if(ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "konsole") == 0)
@@ -326,4 +349,6 @@ void ffDetectTerminalFontPlatform(const FFinstance* instance, const FFTerminalSh
detectFromGSettings(instance, "/org/gnome/terminal/legacy/profiles:/:", "org.gnome.Terminal.ProfilesList", "org.gnome.Terminal.Legacy.Profile", terminalFont);
else if(ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "Windows Terminal") == 0)
detectFromWindowsTeriminal(instance, terminalFont);
else if(ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "mintty") == 0)
detectMintty(instance, terminalFont);
}