mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 16:26:39 +01:00
Font (Windows): reads Control Panel registry directly
Improves performance
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "font.h"
|
||||
#include "common/windows/unicode.h"
|
||||
#include "common/windows/registry.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
@@ -23,19 +24,39 @@ static void generateString(FFFontResult* font)
|
||||
ffStrbufAppendC(&font->display, ']');
|
||||
}
|
||||
|
||||
WINUSERAPI WINBOOL WINAPI ClassicSystemParametersInfoW(UINT uiAction,UINT uiParam,PVOID pvParam,UINT fWinIni);
|
||||
|
||||
const char* ffDetectFontImpl(FFFontResult* result)
|
||||
{
|
||||
NONCLIENTMETRICSW info = { .cbSize = sizeof(info) };
|
||||
if(!SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0))
|
||||
return "SystemParametersInfoW(SPI_GETNONCLIENTMETRICS) failed";
|
||||
FF_AUTO_CLOSE_FD HANDLE hKey = NULL;
|
||||
if (!ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"Control Panel\\Desktop\\WindowMetrics", &hKey, NULL))
|
||||
return "ffRegOpenKeyForRead(HKEY_CURRENT_USER\\Control Panel\\Desktop\\WindowMetrics) failed";
|
||||
|
||||
LOGFONTW* fonts[4] = { &info.lfCaptionFont, &info.lfMenuFont, &info.lfMessageFont, &info.lfStatusFont };
|
||||
FF_LIST_AUTO_DESTROY CaptionFont = ffListCreate(sizeof(uint8_t));
|
||||
FF_LIST_AUTO_DESTROY MenuFont = ffListCreate(sizeof(uint8_t));
|
||||
FF_LIST_AUTO_DESTROY MessageFont = ffListCreate(sizeof(uint8_t));
|
||||
FF_LIST_AUTO_DESTROY StatusFont = ffListCreate(sizeof(uint8_t));
|
||||
|
||||
for(uint32_t i = 0; i < ARRAY_SIZE(fonts); ++i)
|
||||
if (!ffRegReadValues(hKey, 4, (FFRegValueArg[]) {
|
||||
FF_ARG(CaptionFont, L"CaptionFont"),
|
||||
FF_ARG(MenuFont, L"MenuFont"),
|
||||
FF_ARG(MessageFont, L"MessageFont"),
|
||||
FF_ARG(StatusFont, L"StatusFont"),
|
||||
}, NULL))
|
||||
return "ffRegReadValues(HKEY_CURRENT_USER\\Control Panel\\Desktop\\WindowMetrics) failed";
|
||||
|
||||
FFlist* fonts[4] = { &CaptionFont, &MenuFont, &MessageFont, &StatusFont };
|
||||
|
||||
for (uint32_t i = 0; i < ARRAY_SIZE(fonts); ++i)
|
||||
{
|
||||
ffStrbufSetWS(&result->fonts[i], fonts[i]->lfFaceName);
|
||||
if(fonts[i]->lfHeight < 0)
|
||||
ffStrbufAppendF(&result->fonts[i], " (%dpt)", (int)-fonts[i]->lfHeight);
|
||||
if (fonts[i]->length < sizeof(LOGFONTW))
|
||||
continue;
|
||||
|
||||
LOGFONTW* logFont = (LOGFONTW*) fonts[i]->data;
|
||||
|
||||
ffStrbufSetWS(&result->fonts[i], logFont->lfFaceName);
|
||||
if (logFont->lfHeight < 0)
|
||||
ffStrbufAppendF(&result->fonts[i], " (%dpt)", (int)-logFont->lfHeight);
|
||||
}
|
||||
|
||||
generateString(result);
|
||||
|
||||
Reference in New Issue
Block a user