master ohmu/fastfetch-openbsd / src / detection / theme / theme_linux.c
ohmu  ·  2026-10-15
 1#include "theme.h"
 2#include "common/debug.h"
 3#include "common/parsing.h"
 4#include "detection/gtk_qt/gtk_qt.h"
 5#include "detection/displayserver/displayserver.h"
 6
 7const char* ffDetectTheme(FFThemeResult* result) {
 8    const FFDisplayServerResult* wmde = ffConnectDisplayServer();
 9
10    if (ffStrbufIgnCaseEqualS(&wmde->wmProtocolName, FF_WM_PROTOCOL_TTY)) {
11        return "Theme isn't supported in TTY";
12    }
13
14    const FFQtResult* plasma = ffDetectQt();
15    const FFstrbuf* gtk2 = &ffDetectGTK2()->theme;
16    const FFstrbuf* gtk3 = &ffDetectGTK3()->theme;
17    const FFstrbuf* gtk4 = &ffDetectGTK4()->theme;
18
19    if (plasma->widgetStyle.length == 0 && plasma->colorScheme.length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0) {
20        FF_DEBUG("No themes found");
21        return "No themes found";
22    }
23
24    ffParseGTK(&result->theme2, gtk2, gtk3, gtk4);
25
26    FF_STRBUF_AUTO_DESTROY plasmaColorPretty = ffStrbufCreate();
27    if (ffStrbufStartsWithIgnCase(&plasma->colorScheme, &plasma->widgetStyle)) {
28        ffStrbufAppendNS(&plasmaColorPretty, plasma->colorScheme.length - plasma->widgetStyle.length, &plasma->colorScheme.chars[plasma->widgetStyle.length]);
29    } else {
30        ffStrbufAppend(&plasmaColorPretty, &plasma->colorScheme);
31    }
32
33    ffStrbufTrim(&plasmaColorPretty, ' ');
34
35    if (plasma->widgetStyle.length > 0) {
36        ffStrbufAppend(&result->theme1, &plasma->widgetStyle);
37
38        if (plasma->colorScheme.length > 0) {
39            ffStrbufAppendS(&result->theme1, " (");
40
41            if (plasmaColorPretty.length > 0) {
42                ffStrbufAppend(&result->theme1, &plasmaColorPretty);
43            } else {
44                ffStrbufAppend(&result->theme1, &plasma->colorScheme);
45            }
46
47            ffStrbufAppendC(&result->theme1, ')');
48        }
49    } else if (plasma->colorScheme.length > 0) {
50        if (plasmaColorPretty.length > 0) {
51            ffStrbufAppend(&result->theme1, &plasmaColorPretty);
52        } else {
53            ffStrbufAppend(&result->theme1, &plasma->colorScheme);
54        }
55    }
56
57    if (plasma->widgetStyle.length > 0 || plasma->colorScheme.length > 0) {
58        ffStrbufAppendS(&result->theme1, " [Qt]");
59    }
60
61    return nullptr;
62}