2023-02-01 15:56:25 +01:00
|
|
|
#include "wmtheme.h"
|
2023-12-19 17:06:18 +09:00
|
|
|
#include "common/io/io.h"
|
2022-09-24 19:39:48 +08:00
|
|
|
#include "common/properties.h"
|
|
|
|
|
#include "common/parsing.h"
|
|
|
|
|
#include "common/settings.h"
|
2023-02-14 17:46:21 +08:00
|
|
|
#include "detection/gtk_qt/gtk_qt.h"
|
2022-09-24 19:39:48 +08:00
|
|
|
#include "detection/displayserver/displayserver.h"
|
2023-02-01 15:56:25 +01:00
|
|
|
#include "util/stringUtils.h"
|
2024-07-05 23:27:13 +08:00
|
|
|
#include "util/mallocHelper.h"
|
2022-09-24 19:39:48 +08:00
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
static bool detectWMThemeFromConfigFile(const char* configFile, const char* themeRegex, const char* defaultValue, FFstrbuf* themeOrError)
|
2022-09-24 19:39:48 +08:00
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
if(!ffParsePropFileConfig(configFile, themeRegex, themeOrError))
|
2022-09-24 19:39:48 +08:00
|
|
|
{
|
2023-04-15 15:29:54 +08:00
|
|
|
ffStrbufAppendF(themeOrError, "Config file %s doesn't exist", configFile);
|
2022-09-24 19:39:48 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(themeOrError->length == 0)
|
|
|
|
|
{
|
|
|
|
|
if(defaultValue == NULL)
|
|
|
|
|
{
|
|
|
|
|
ffStrbufAppendF(themeOrError, "Couldn't find WM theme in %s", configFile);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ffStrbufAppendS(themeOrError, defaultValue);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove Plasma-generated prefixes
|
|
|
|
|
uint32_t idx = 0;
|
|
|
|
|
|
|
|
|
|
idx = ffStrbufFirstIndexS(themeOrError, "qml_");
|
|
|
|
|
if(idx != themeOrError->length)
|
|
|
|
|
ffStrbufSubstrAfter(themeOrError, idx + 3);
|
|
|
|
|
|
|
|
|
|
idx = ffStrbufFirstIndexS(themeOrError, "svg__");
|
|
|
|
|
if(idx != themeOrError->length)
|
|
|
|
|
ffStrbufSubstrAfter(themeOrError, idx + 4);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
static bool detectWMThemeFromSettings(const char* dconfKey, const char* gsettingsSchemaName, const char* gsettingsPath, const char* gsettingsKey, FFstrbuf* themeOrError)
|
2022-09-24 19:39:48 +08:00
|
|
|
{
|
2025-09-04 16:17:01 +08:00
|
|
|
const char* theme = ffSettingsGetGnome(dconfKey, gsettingsSchemaName, gsettingsPath, gsettingsKey, FF_VARIANT_TYPE_STRING).strValue;
|
2022-09-24 19:39:48 +08:00
|
|
|
|
|
|
|
|
if(!ffStrSet(theme))
|
|
|
|
|
{
|
|
|
|
|
ffStrbufAppendS(themeOrError, "Couldn't find WM theme in DConf or GSettings");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ffStrbufAppendS(themeOrError, theme);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
static bool detectGTKThemeAsWMTheme(FFstrbuf* themeOrError)
|
2022-09-24 19:39:48 +08:00
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
const FFGTKResult* gtk = ffDetectGTK4();
|
2022-09-24 19:39:48 +08:00
|
|
|
if(gtk->theme.length > 0)
|
|
|
|
|
goto ok;
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
gtk = ffDetectGTK3();
|
2022-09-24 19:39:48 +08:00
|
|
|
if(gtk->theme.length > 0)
|
|
|
|
|
goto ok;
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
gtk = ffDetectGTK2();
|
2022-09-24 19:39:48 +08:00
|
|
|
if(gtk->theme.length > 0)
|
|
|
|
|
goto ok;
|
|
|
|
|
|
|
|
|
|
ffStrbufAppendS(themeOrError, "Couldn't detect GTK4/3/2 theme");
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
ok:
|
|
|
|
|
ffStrbufAppend(themeOrError, >k->theme);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
static bool detectMutter(FFstrbuf* themeOrError)
|
2022-09-24 19:39:48 +08:00
|
|
|
{
|
2025-09-04 16:17:01 +08:00
|
|
|
const char* theme = ffSettingsGetGnome("/org/gnome/shell/extensions/user-theme/name", "org.gnome.shell.extensions.user-theme", NULL, "name", FF_VARIANT_TYPE_STRING).strValue;
|
2022-09-24 19:39:48 +08:00
|
|
|
if(ffStrSet(theme))
|
|
|
|
|
{
|
|
|
|
|
ffStrbufAppendS(themeOrError, theme);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
return detectGTKThemeAsWMTheme(themeOrError);
|
2022-09-24 19:39:48 +08:00
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
static bool detectMuffin(FFstrbuf* themeOrError)
|
2022-09-24 19:39:48 +08:00
|
|
|
{
|
2025-09-04 16:17:01 +08:00
|
|
|
FF_AUTO_FREE const char* name = ffSettingsGetGnome("/org/cinnamon/theme/name", "org.cinnamon.theme", NULL, "name", FF_VARIANT_TYPE_STRING).strValue;
|
|
|
|
|
FF_AUTO_FREE const char* theme = ffSettingsGetGnome("/org/cinnamon/desktop/wm/preferences/theme", "org.cinnamon.desktop.wm.preferences", NULL, "theme", FF_VARIANT_TYPE_STRING).strValue;
|
2022-09-24 19:39:48 +08:00
|
|
|
|
|
|
|
|
if(name == NULL && theme == NULL)
|
|
|
|
|
{
|
|
|
|
|
ffStrbufAppendS(themeOrError, "Couldn't find muffin theme in GSettings / DConf");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(name == NULL)
|
|
|
|
|
{
|
|
|
|
|
ffStrbufAppendS(themeOrError, theme);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-02-01 10:43:24 +01:00
|
|
|
|
2022-09-24 19:39:48 +08:00
|
|
|
if(theme == NULL)
|
|
|
|
|
{
|
2023-02-01 10:43:24 +01:00
|
|
|
ffStrbufAppendS(themeOrError, name);
|
2022-09-24 19:39:48 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
2023-02-01 10:43:24 +01:00
|
|
|
|
2022-09-24 19:39:48 +08:00
|
|
|
ffStrbufAppendF(themeOrError, "%s (%s)", name, theme);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
static bool detectXFWM4(FFstrbuf* themeOrError)
|
2022-09-24 19:39:48 +08:00
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
const char* theme = ffSettingsGetXFConf("xfwm4", "/general/theme", FF_VARIANT_TYPE_STRING).strValue;
|
2022-09-24 19:39:48 +08:00
|
|
|
|
|
|
|
|
if(theme == NULL)
|
|
|
|
|
{
|
|
|
|
|
ffStrbufAppendS(themeOrError, "Couldn't find xfwm4::/general/theme in XFConf");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ffStrbufAppendS(themeOrError, theme);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
static bool detectOpenbox(const FFstrbuf* dePrettyName, FFstrbuf* themeOrError)
|
2022-09-24 19:39:48 +08:00
|
|
|
{
|
2023-04-15 15:29:54 +08:00
|
|
|
FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateA(64);
|
2024-07-05 23:27:13 +08:00
|
|
|
const char *configFileSubpath = "openbox/rc.xml";
|
2024-07-01 05:00:35 -03:00
|
|
|
if (ffStrbufIgnCaseCompS(dePrettyName, "LXQt") == 0)
|
2023-12-20 16:43:35 +09:00
|
|
|
configFileSubpath = "openbox/lxqt-rc.xml";
|
|
|
|
|
else if (ffStrbufIgnCaseCompS(dePrettyName, "LXDE") == 0)
|
|
|
|
|
configFileSubpath = "openbox/lxde-rc.xml";
|
|
|
|
|
|
|
|
|
|
if (!ffSearchUserConfigFile(&instance.state.platform.configDirs, configFileSubpath, &absolutePath))
|
|
|
|
|
{
|
|
|
|
|
ffStrbufAppendF(themeOrError, "Couldn't find config file \"%s\"", configFileSubpath);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-09-24 19:39:48 +08:00
|
|
|
|
2023-12-19 17:06:18 +09:00
|
|
|
FF_STRBUF_AUTO_DESTROY content = ffStrbufCreate();
|
|
|
|
|
if (!ffReadFileBuffer(absolutePath.chars, &content))
|
2022-09-24 19:39:48 +08:00
|
|
|
{
|
2023-12-19 17:06:18 +09:00
|
|
|
ffStrbufAppendF(themeOrError, "Couldn't read \"%s\"", absolutePath.chars);
|
2022-09-24 19:39:48 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-19 17:06:18 +09:00
|
|
|
const char *themeStart = strstr(content.chars, "<theme>");
|
|
|
|
|
if (themeStart == NULL)
|
|
|
|
|
goto theme_not_found;
|
2022-09-24 19:39:48 +08:00
|
|
|
|
2023-12-19 17:06:18 +09:00
|
|
|
const char *themeEnd = strstr(themeStart, "</theme>");
|
|
|
|
|
if (__builtin_expect(themeEnd == NULL, false)) // very rare case
|
|
|
|
|
goto theme_not_found;
|
2022-09-24 19:39:48 +08:00
|
|
|
|
2023-12-19 17:06:18 +09:00
|
|
|
const char *nameStart = strstr(themeStart, "<name>");
|
|
|
|
|
if (nameStart == NULL)
|
|
|
|
|
goto name_not_found;
|
2022-09-24 19:39:48 +08:00
|
|
|
|
2023-12-19 17:06:18 +09:00
|
|
|
const char *nameEnd = strstr(nameStart, "</name>");
|
|
|
|
|
if (nameEnd == NULL || nameEnd > themeEnd) // (nameEnd > themeEnd) means name is not a theme's child
|
|
|
|
|
goto name_not_found;
|
2022-09-24 19:39:48 +08:00
|
|
|
|
2023-12-19 17:06:18 +09:00
|
|
|
nameStart += strlen("<name>");
|
|
|
|
|
ffStrbufAppendNS(themeOrError, (uint32_t)(nameEnd - nameStart), nameStart);
|
|
|
|
|
ffStrbufTrim(themeOrError, ' ');
|
2022-09-24 19:39:48 +08:00
|
|
|
|
|
|
|
|
if(themeOrError->length == 0)
|
2023-12-19 17:06:18 +09:00
|
|
|
goto name_not_found;
|
2022-09-24 19:39:48 +08:00
|
|
|
|
|
|
|
|
return true;
|
2023-12-19 17:06:18 +09:00
|
|
|
|
|
|
|
|
theme_not_found:
|
|
|
|
|
ffStrbufAppendF(themeOrError, "Couldn't find theme node in \"%s\"", absolutePath.chars);
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
name_not_found:
|
|
|
|
|
ffStrbufAppendF(themeOrError, "Couldn't find theme name in \"%s\"", absolutePath.chars);
|
|
|
|
|
return false;
|
2022-09-24 19:39:48 +08:00
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
bool ffDetectWmTheme(FFstrbuf* themeOrError)
|
2022-09-24 19:39:48 +08:00
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
const FFDisplayServerResult* wm = ffConnectDisplayServer();
|
2022-09-24 19:39:48 +08:00
|
|
|
|
|
|
|
|
if(wm->wmPrettyName.length == 0)
|
|
|
|
|
{
|
2023-11-18 15:33:23 +01:00
|
|
|
ffStrbufAppendS(themeOrError, "WM Theme needs successful WM detection");
|
2022-09-24 19:39:48 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-30 18:46:39 +01:00
|
|
|
if(ffStrbufIgnCaseCompS(&wm->wmPrettyName, FF_WM_PRETTY_KWIN) == 0)
|
2023-06-24 10:59:53 +08:00
|
|
|
return detectWMThemeFromConfigFile("kwinrc", "theme =", "Breeze", themeOrError);
|
2022-09-24 19:39:48 +08:00
|
|
|
|
2023-01-30 18:46:39 +01:00
|
|
|
if(ffStrbufIgnCaseCompS(&wm->wmPrettyName, FF_WM_PRETTY_XFWM4) == 0)
|
2023-06-24 10:59:53 +08:00
|
|
|
return detectXFWM4(themeOrError);
|
2022-09-24 19:39:48 +08:00
|
|
|
|
2023-01-30 18:46:39 +01:00
|
|
|
if(ffStrbufIgnCaseCompS(&wm->wmPrettyName, FF_WM_PRETTY_MUTTER) == 0)
|
2022-09-24 19:39:48 +08:00
|
|
|
{
|
2023-06-11 18:56:40 +08:00
|
|
|
if(
|
|
|
|
|
ffStrbufIgnCaseCompS(&wm->dePrettyName, FF_DE_PRETTY_GNOME) == 0 ||
|
|
|
|
|
ffStrbufIgnCaseEqualS(&wm->dePrettyName, FF_DE_PRETTY_GNOME_CLASSIC)
|
|
|
|
|
)
|
2023-06-24 10:59:53 +08:00
|
|
|
return detectMutter(themeOrError);
|
2022-09-24 19:39:48 +08:00
|
|
|
else
|
2023-06-24 10:59:53 +08:00
|
|
|
return detectGTKThemeAsWMTheme(themeOrError);
|
2022-09-24 19:39:48 +08:00
|
|
|
}
|
|
|
|
|
|
2023-01-30 18:46:39 +01:00
|
|
|
if(ffStrbufIgnCaseCompS(&wm->wmPrettyName, FF_WM_PRETTY_MUFFIN) == 0)
|
2023-06-24 10:59:53 +08:00
|
|
|
return detectMuffin(themeOrError);
|
2022-09-24 19:39:48 +08:00
|
|
|
|
2023-01-30 18:46:39 +01:00
|
|
|
if(ffStrbufIgnCaseCompS(&wm->wmPrettyName, FF_WM_PRETTY_MARCO) == 0)
|
2023-06-24 10:59:53 +08:00
|
|
|
return detectWMThemeFromSettings("/org/mate/Marco/general/theme", "org.mate.Marco.general", NULL, "theme", themeOrError);
|
2022-09-24 19:39:48 +08:00
|
|
|
|
2023-01-30 18:46:39 +01:00
|
|
|
if(ffStrbufIgnCaseCompS(&wm->wmPrettyName, FF_WM_PRETTY_OPENBOX) == 0)
|
2023-06-24 10:59:53 +08:00
|
|
|
return detectOpenbox(&wm->dePrettyName, themeOrError);
|
2022-09-24 19:39:48 +08:00
|
|
|
|
|
|
|
|
ffStrbufAppendS(themeOrError, "Unknown WM: ");
|
2022-10-05 19:52:16 +08:00
|
|
|
ffStrbufAppend(themeOrError, &wm->wmPrettyName);
|
2022-09-24 19:39:48 +08:00
|
|
|
return false;
|
|
|
|
|
}
|