|
1 | 1 | #include "fastfetch.h" |
2 | 2 | #include "common/printing.h" |
3 | | -#include "common/parsing.h" |
4 | | -#include "detection/gtk_qt/gtk_qt.h" |
5 | | -#include "detection/displayserver/displayserver.h" |
| 3 | +#include "detection/theme/theme.h" |
6 | 4 |
|
7 | 5 | #define FF_THEME_MODULE_NAME "Theme" |
8 | | -#define FF_THEME_NUM_FORMAT_ARGS 7 |
| 6 | +#define FF_THEME_NUM_FORMAT_ARGS 1 |
9 | 7 |
|
10 | 8 | void ffPrintTheme(FFinstance* instance) |
11 | 9 | { |
12 | | - #if defined(__ANDROID__) || defined(__APPLE__) || defined(_WIN32) |
13 | | - |
14 | | - FF_UNUSED(instance); |
15 | | - ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, "Theme detection is not supported"); |
16 | | - return; |
17 | | - |
18 | | - #else |
19 | | - |
20 | | - const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance); |
21 | | - |
22 | | - if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, FF_WM_PROTOCOL_TTY) == 0) |
| 10 | + FF_STRBUF_AUTO_DESTROY theme; |
| 11 | + ffStrbufInit(&theme); |
| 12 | + const char* error = ffDetectTheme(instance, &theme); |
| 13 | + if (error) |
23 | 14 | { |
24 | | - ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, "Theme isn't supported in TTY"); |
| 15 | + ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, "%s", error); |
25 | 16 | return; |
26 | 17 | } |
27 | 18 |
|
28 | | - const FFQtResult* plasma = ffDetectQt(instance); |
29 | | - const FFstrbuf* gtk2 = &ffDetectGTK2(instance)->theme; |
30 | | - const FFstrbuf* gtk3 = &ffDetectGTK3(instance)->theme; |
31 | | - const FFstrbuf* gtk4 = &ffDetectGTK4(instance)->theme; |
32 | | - |
33 | | - if(plasma->widgetStyle.length == 0 && plasma->colorScheme.length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0) |
34 | | - { |
35 | | - ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, "No themes found"); |
36 | | - return; |
37 | | - } |
38 | | - |
39 | | - FF_STRBUF_AUTO_DESTROY plasmaColorPretty; |
40 | | - ffStrbufInit(&plasmaColorPretty); |
41 | | - if(ffStrbufStartsWithIgnCase(&plasma->colorScheme, &plasma->widgetStyle)) |
42 | | - ffStrbufAppendNS(&plasmaColorPretty, plasma->colorScheme.length - plasma->widgetStyle.length, &plasma->colorScheme.chars[plasma->widgetStyle.length]); |
43 | | - else |
44 | | - ffStrbufAppend(&plasmaColorPretty, &plasma->colorScheme); |
45 | | - |
46 | | - ffStrbufTrim(&plasmaColorPretty, ' '); |
47 | | - |
48 | | - FF_STRBUF_AUTO_DESTROY gtkPretty; |
49 | | - ffStrbufInit(>kPretty); |
50 | | - ffParseGTK(>kPretty, gtk2, gtk3, gtk4); |
51 | | - |
52 | 19 | if(instance->config.theme.outputFormat.length == 0) |
53 | 20 | { |
54 | 21 | ffPrintLogoAndKey(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme.key); |
55 | | - |
56 | | - if(plasma->widgetStyle.length > 0) |
57 | | - { |
58 | | - ffStrbufWriteTo(&plasma->widgetStyle, stdout); |
59 | | - |
60 | | - if(plasma->colorScheme.length > 0) |
61 | | - { |
62 | | - fputs(" (", stdout); |
63 | | - |
64 | | - if(plasmaColorPretty.length > 0) |
65 | | - ffStrbufWriteTo(&plasmaColorPretty, stdout); |
66 | | - else |
67 | | - ffStrbufWriteTo(&plasma->colorScheme, stdout); |
68 | | - |
69 | | - putchar(')'); |
70 | | - } |
71 | | - } |
72 | | - else if(plasma->colorScheme.length > 0) |
73 | | - { |
74 | | - if(plasmaColorPretty.length > 0) |
75 | | - ffStrbufWriteTo(&plasmaColorPretty, stdout); |
76 | | - else |
77 | | - ffStrbufWriteTo(&plasma->colorScheme, stdout); |
78 | | - } |
79 | | - |
80 | | - if(plasma->widgetStyle.length > 0 || plasma->colorScheme.length > 0) |
81 | | - { |
82 | | - fputs(" [QT]", stdout); |
83 | | - |
84 | | - if(gtkPretty.length > 0) |
85 | | - fputs(", ", stdout); |
86 | | - } |
87 | | - |
88 | | - ffStrbufPutTo(>kPretty, stdout); |
| 22 | + ffStrbufPutTo(&theme, stdout); |
89 | 23 | } |
90 | 24 | else |
91 | 25 | { |
92 | 26 | ffPrintFormat(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, FF_THEME_NUM_FORMAT_ARGS, (FFformatarg[]){ |
93 | | - {FF_FORMAT_ARG_TYPE_STRBUF, &plasma->widgetStyle}, |
94 | | - {FF_FORMAT_ARG_TYPE_STRBUF, &plasma->colorScheme}, |
95 | | - {FF_FORMAT_ARG_TYPE_STRBUF, &plasmaColorPretty}, |
96 | | - {FF_FORMAT_ARG_TYPE_STRBUF, gtk2}, |
97 | | - {FF_FORMAT_ARG_TYPE_STRBUF, gtk3}, |
98 | | - {FF_FORMAT_ARG_TYPE_STRBUF, gtk4}, |
99 | | - {FF_FORMAT_ARG_TYPE_STRBUF, >kPretty} |
| 27 | + {FF_FORMAT_ARG_TYPE_STRBUF, &theme} |
100 | 28 | }); |
101 | 29 | } |
102 | | - |
103 | | - #endif |
104 | 30 | } |
0 commit comments