Files
fastfetch/src/modules/theme.c
T

107 lines
3.5 KiB
C
Raw Normal View History

2021-02-18 22:25:36 +01:00
#include "fastfetch.h"
#include "common/printing.h"
#include "common/parsing.h"
2022-07-26 17:42:28 +02:00
#include "detection/qt.h"
2022-07-26 17:47:08 +02:00
#include "detection/gtk.h"
2022-09-06 15:42:37 +02:00
#include "detection/displayserver/displayserver.h"
2021-02-18 22:25:36 +01:00
2021-04-15 18:59:26 +02:00
#define FF_THEME_MODULE_NAME "Theme"
#define FF_THEME_NUM_FORMAT_ARGS 7
2021-02-27 18:30:05 +01:00
void ffPrintTheme(FFinstance* instance)
2021-02-18 22:25:36 +01:00
{
2022-10-14 16:39:48 +08:00
#if defined(__ANDROID__) || defined(__APPLE__) || defined(_WIN32)
2022-09-25 18:22:16 +08:00
FF_UNUSED(instance);
ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, "Theme detection is not supported");
return;
#else
2022-01-10 14:41:34 +01:00
2022-01-02 16:55:26 +01:00
const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance);
2021-06-27 21:53:50 +02:00
if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, FF_WM_PROTOCOL_TTY) == 0)
2021-06-27 21:53:50 +02:00
{
2022-06-17 18:15:36 +02:00
ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, "Theme isn't supported in TTY");
2021-06-27 21:53:50 +02:00
return;
}
2022-07-22 17:18:36 +02:00
const FFQtResult* plasma = ffDetectQt(instance);
2021-04-28 19:53:30 +02:00
const FFstrbuf* gtk2 = &ffDetectGTK2(instance)->theme;
const FFstrbuf* gtk3 = &ffDetectGTK3(instance)->theme;
const FFstrbuf* gtk4 = &ffDetectGTK4(instance)->theme;
2021-03-27 18:14:19 +01:00
if(plasma->widgetStyle.length == 0 && plasma->colorScheme.length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0)
2021-04-05 19:25:34 +02:00
{
2022-06-17 18:15:36 +02:00
ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, "No themes found");
2021-04-05 19:25:34 +02:00
return;
}
2021-03-19 20:57:07 +01:00
2021-04-09 19:21:56 +02:00
FF_STRBUF_CREATE(plasmaColorPretty);
if(ffStrbufStartsWithIgnCase(&plasma->colorScheme, &plasma->widgetStyle))
ffStrbufAppendNS(&plasmaColorPretty, plasma->colorScheme.length - plasma->widgetStyle.length, &plasma->colorScheme.chars[plasma->widgetStyle.length]);
2021-04-09 19:21:56 +02:00
else
ffStrbufAppend(&plasmaColorPretty, &plasma->colorScheme);
2021-04-09 19:21:56 +02:00
ffStrbufTrim(&plasmaColorPretty, ' ');
FF_STRBUF_CREATE(gtkPretty);
2022-04-08 15:50:49 +02:00
ffParseGTK(&gtkPretty, gtk2, gtk3, gtk4);
2021-03-19 20:57:07 +01:00
2022-06-17 18:15:36 +02:00
if(instance->config.theme.outputFormat.length == 0)
2021-03-19 20:57:07 +01:00
{
2022-06-17 18:15:36 +02:00
ffPrintLogoAndKey(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme.key);
if(plasma->widgetStyle.length > 0)
2021-04-09 19:21:56 +02:00
{
ffStrbufWriteTo(&plasma->widgetStyle, stdout);
2021-04-09 19:21:56 +02:00
if(plasma->colorScheme.length > 0)
2021-04-09 19:21:56 +02:00
{
fputs(" (", stdout);
if(plasmaColorPretty.length > 0)
ffStrbufWriteTo(&plasmaColorPretty, stdout);
else
ffStrbufWriteTo(&plasma->colorScheme, stdout);
2021-04-09 19:21:56 +02:00
putchar(')');
}
}
else if(plasma->colorScheme.length > 0)
2021-04-09 19:21:56 +02:00
{
if(plasmaColorPretty.length > 0)
ffStrbufWriteTo(&plasmaColorPretty, stdout);
else
ffStrbufWriteTo(&plasma->colorScheme, stdout);
2021-04-09 19:21:56 +02:00
}
if(plasma->widgetStyle.length > 0 || plasma->colorScheme.length > 0)
2021-04-07 12:55:11 +02:00
{
2022-07-22 17:18:36 +02:00
fputs(" [QT]", stdout);
2021-04-07 12:55:11 +02:00
if(gtkPretty.length > 0)
fputs(", ", stdout);
}
2021-03-19 20:57:07 +01:00
2021-03-22 20:02:32 +01:00
ffStrbufPutTo(&gtkPretty, stdout);
2021-03-19 20:57:07 +01:00
}
2021-02-19 16:23:41 +01:00
else
2021-03-19 20:57:07 +01:00
{
2022-06-17 18:15:36 +02:00
ffPrintFormat(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, FF_THEME_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &plasma->widgetStyle},
{FF_FORMAT_ARG_TYPE_STRBUF, &plasma->colorScheme},
2021-04-15 18:59:26 +02:00
{FF_FORMAT_ARG_TYPE_STRBUF, &plasmaColorPretty},
{FF_FORMAT_ARG_TYPE_STRBUF, gtk2},
{FF_FORMAT_ARG_TYPE_STRBUF, gtk3},
{FF_FORMAT_ARG_TYPE_STRBUF, gtk4},
2021-04-15 18:59:26 +02:00
{FF_FORMAT_ARG_TYPE_STRBUF, &gtkPretty}
});
2021-03-19 20:57:07 +01:00
}
2021-04-09 19:21:56 +02:00
ffStrbufDestroy(&plasmaColorPretty);
ffStrbufDestroy(&gtkPretty);
2022-09-25 18:22:16 +08:00
#endif
2021-03-27 18:14:19 +01:00
}