Skip to content

Commit ee876c5

Browse files
committed
Theme: split detection code
1 parent 4af44a4 commit ee876c5

File tree

6 files changed

+101
-91
lines changed

6 files changed

+101
-91
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ if(LINUX)
359359
src/detection/temps/temps_linux.c
360360
src/detection/terminalfont/terminalfont_linux.c
361361
src/detection/terminalshell/terminalshell_linux.c
362+
src/detection/theme/theme_linux.c
362363
src/detection/uptime/uptime_linux.c
363364
src/detection/users/users_linux.c
364365
src/detection/wallpaper/wallpaper_linux.c
@@ -400,6 +401,7 @@ elseif(ANDROID)
400401
src/detection/temps/temps_linux.c
401402
src/detection/terminalfont/terminalfont_android.c
402403
src/detection/terminalshell/terminalshell_linux.c
404+
src/detection/theme/theme_nosupport.c
403405
src/detection/uptime/uptime_linux.c
404406
src/detection/users/users_linux.c
405407
src/detection/wallpaper/wallpaper_nosupport.c
@@ -449,6 +451,7 @@ elseif(BSD)
449451
src/detection/temps/temps_linux.c
450452
src/detection/terminalfont/terminalfont_linux.c
451453
src/detection/terminalshell/terminalshell_linux.c
454+
src/detection/theme/theme_linux.c
452455
src/detection/uptime/uptime_bsd.c
453456
src/detection/users/users_linux.c
454457
src/detection/wallpaper/wallpaper_linux.c
@@ -492,6 +495,7 @@ elseif(APPLE)
492495
src/detection/temps/temps_apple.c
493496
src/detection/terminalfont/terminalfont_apple.m
494497
src/detection/terminalshell/terminalshell_linux.c
498+
src/detection/theme/theme_nosupport.c
495499
src/detection/uptime/uptime_bsd.c
496500
src/detection/users/users_linux.c
497501
src/detection/wallpaper/wallpaper_apple.c
@@ -535,6 +539,7 @@ elseif(WIN32)
535539
src/detection/terminalfont/terminalfont_windows.c
536540
src/detection/terminalshell/terminalshell_windows.c
537541
src/detection/temps/temps_windows.cpp
542+
src/detection/theme/theme_nosupport.c
538543
src/detection/uptime/uptime_windows.c
539544
src/detection/users/users_windows.c
540545
src/detection/wallpaper/wallpaper_windows.c

src/detection/theme/theme.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
#ifndef FF_INCLUDED_detection_theme
4+
#define FF_INCLUDED_detection_theme
5+
6+
#include "fastfetch.h"
7+
8+
const char* ffDetectTheme(const FFinstance* instance, FFstrbuf* result);
9+
10+
#endif

src/detection/theme/theme_linux.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#include "theme.h"
2+
#include "common/parsing.h"
3+
#include "detection/gtk_qt/gtk_qt.h"
4+
#include "detection/displayserver/displayserver.h"
5+
6+
const char* ffDetectTheme(const FFinstance* instance, FFstrbuf* result)
7+
{
8+
const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance);
9+
10+
if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, FF_WM_PROTOCOL_TTY) == 0)
11+
return "Theme isn't supported in TTY";
12+
13+
const FFQtResult* plasma = ffDetectQt(instance);
14+
const FFstrbuf* gtk2 = &ffDetectGTK2(instance)->theme;
15+
const FFstrbuf* gtk3 = &ffDetectGTK3(instance)->theme;
16+
const FFstrbuf* gtk4 = &ffDetectGTK4(instance)->theme;
17+
18+
if(plasma->widgetStyle.length == 0 && plasma->colorScheme.length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0)
19+
return "No themes found";
20+
21+
FF_STRBUF_AUTO_DESTROY plasmaColorPretty;
22+
ffStrbufInit(&plasmaColorPretty);
23+
if(ffStrbufStartsWithIgnCase(&plasma->colorScheme, &plasma->widgetStyle))
24+
ffStrbufAppendNS(&plasmaColorPretty, plasma->colorScheme.length - plasma->widgetStyle.length, &plasma->colorScheme.chars[plasma->widgetStyle.length]);
25+
else
26+
ffStrbufAppend(&plasmaColorPretty, &plasma->colorScheme);
27+
28+
ffStrbufTrim(&plasmaColorPretty, ' ');
29+
30+
FF_STRBUF_AUTO_DESTROY gtkPretty;
31+
ffStrbufInit(&gtkPretty);
32+
ffParseGTK(&gtkPretty, gtk2, gtk3, gtk4);
33+
34+
if(plasma->widgetStyle.length > 0)
35+
{
36+
ffStrbufAppend(result, &plasma->widgetStyle);
37+
38+
if(plasma->colorScheme.length > 0)
39+
{
40+
ffStrbufAppendS(result, " (");
41+
42+
if(plasmaColorPretty.length > 0)
43+
ffStrbufAppend(result, &plasmaColorPretty);
44+
else
45+
ffStrbufAppend(result, &plasma->colorScheme);
46+
47+
ffStrbufAppendC(result, ')');
48+
}
49+
}
50+
else if(plasma->colorScheme.length > 0)
51+
{
52+
if(plasmaColorPretty.length > 0)
53+
ffStrbufAppend(result, &plasmaColorPretty);
54+
else
55+
ffStrbufAppend(result, &plasma->colorScheme);
56+
}
57+
58+
if(plasma->widgetStyle.length > 0 || plasma->colorScheme.length > 0)
59+
{
60+
ffStrbufAppendS(result, " [QT]");
61+
62+
if(gtkPretty.length > 0)
63+
ffStrbufAppendS(result, ", ");
64+
}
65+
66+
ffStrbufAppend(result, &gtkPretty);
67+
68+
return NULL;
69+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "theme.h"
2+
3+
const char* ffDetectTheme(FF_MAYBE_UNUSED const FFinstance* instance, FF_MAYBE_UNUSED FFstrbuf* result)
4+
{
5+
return "Not supported on this platform";
6+
}

src/fastfetch.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,8 @@ static inline void printCommandHelp(const char* command)
207207
}
208208
else if(strcasecmp(command, "theme-format") == 0)
209209
{
210-
constructAndPrintCommandHelpFormat("theme", "{} ({3}) [Plasma], {7}", 7,
211-
"Plasma theme",
212-
"Plasma color scheme",
213-
"Plasma color scheme pretty",
214-
"GTK2 theme",
215-
"GTK3 theme",
216-
"GTK4 theme",
217-
"Combined GTK themes"
210+
constructAndPrintCommandHelpFormat("theme", "{}", 1,
211+
"Combined themes"
218212
);
219213
}
220214
else if(strcasecmp(command, "icons-format") == 0)

src/modules/theme.c

Lines changed: 9 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,30 @@
11
#include "fastfetch.h"
22
#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"
64

75
#define FF_THEME_MODULE_NAME "Theme"
8-
#define FF_THEME_NUM_FORMAT_ARGS 7
6+
#define FF_THEME_NUM_FORMAT_ARGS 1
97

108
void ffPrintTheme(FFinstance* instance)
119
{
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)
2314
{
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);
2516
return;
2617
}
2718

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(&gtkPretty);
50-
ffParseGTK(&gtkPretty, gtk2, gtk3, gtk4);
51-
5219
if(instance->config.theme.outputFormat.length == 0)
5320
{
5421
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(&gtkPretty, stdout);
22+
ffStrbufPutTo(&theme, stdout);
8923
}
9024
else
9125
{
9226
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, &gtkPretty}
27+
{FF_FORMAT_ARG_TYPE_STRBUF, &theme}
10028
});
10129
}
102-
103-
#endif
10430
}

0 commit comments

Comments
 (0)