mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:14:37 +02:00
TerminalFont: add conhost detection
This commit is contained in:
@@ -317,6 +317,9 @@ static void detectFromWindowsTeriminal(const FFinstance* instance, FFTerminalFon
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) || defined(__MSYS__)
|
||||
// TODO: move to a separate file
|
||||
|
||||
static void detectMintty(const FFinstance* instance, FFTerminalFontResult* terminalFont)
|
||||
{
|
||||
FFstrbuf fontName;
|
||||
@@ -340,6 +343,56 @@ static void detectMintty(const FFinstance* instance, FFTerminalFontResult* termi
|
||||
ffStrbufDestroy(&fontSize);
|
||||
}
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#include <Windows.h>
|
||||
|
||||
static void detectConhost(const FFinstance* instance, FFTerminalFontResult* terminalFont)
|
||||
{
|
||||
FF_UNUSED(instance);
|
||||
|
||||
//Current font of conhost doesn't seem to be detectable, we detect default font instead
|
||||
|
||||
HKEY hKey;
|
||||
if(RegOpenKeyExW(HKEY_CURRENT_USER, L"Console", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
|
||||
{
|
||||
ffStrbufAppendS(&terminalFont->error, "RegOpenKeyExW() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
DWORD bufSize;
|
||||
|
||||
wchar_t fontNameW[64];
|
||||
bufSize = sizeof(fontNameW);
|
||||
if(RegQueryValueExW(hKey, L"FaceName", NULL, NULL, (LPBYTE)fontNameW, &bufSize) != ERROR_SUCCESS)
|
||||
{
|
||||
ffStrbufAppendS(&terminalFont->error, "RegOpenKeyExW(FaceName) failed");
|
||||
goto exit;
|
||||
}
|
||||
fontNameW[bufSize] = '\0';
|
||||
|
||||
char fontNameA[128];
|
||||
int fontNameALen = WideCharToMultiByte(CP_UTF8, 0, fontNameW, (int)(bufSize / 2), fontNameA, sizeof(fontNameA), NULL, NULL);
|
||||
fontNameA[fontNameALen] = '\0';
|
||||
|
||||
uint32_t fontSizeNum = 0;
|
||||
bufSize = sizeof(fontSizeNum);
|
||||
if(RegQueryValueExW(hKey, L"fontSize", NULL, NULL, (LPBYTE)&fontSizeNum, &bufSize) != ERROR_SUCCESS)
|
||||
{
|
||||
ffStrbufAppendS(&terminalFont->error, "RegOpenKeyExW(fontSize) failed");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
char fontSize[16];
|
||||
snprintf(fontSize, sizeof(fontSize), "%u", (fontSizeNum >> 16));
|
||||
|
||||
ffFontInitValues(&terminalFont->font, fontNameA, fontSize);
|
||||
|
||||
exit:
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
|
||||
#endif //defined(_WIN32) || defined(__MSYS__)
|
||||
|
||||
void ffDetectTerminalFontPlatform(const FFinstance* instance, const FFTerminalShellResult* terminalShell, FFTerminalFontResult* terminalFont)
|
||||
{
|
||||
if(ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "konsole") == 0)
|
||||
@@ -355,6 +408,11 @@ void ffDetectTerminalFontPlatform(const FFinstance* instance, const FFTerminalSh
|
||||
else if(ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "Windows Terminal") == 0 ||
|
||||
ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "WindowsTerminal.exe") == 0)
|
||||
detectFromWindowsTeriminal(instance, terminalFont);
|
||||
|
||||
#if defined(_WIN32) || defined(__MSYS__)
|
||||
else if(ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "mintty") == 0)
|
||||
detectMintty(instance, terminalFont);
|
||||
else if(ffStrbufIgnCaseCompS(&terminalShell->terminalProcessName, "conhost.exe") == 0)
|
||||
detectConhost(instance, terminalFont);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user