2021-06-20 21:04:55 +02:00
|
|
|
#include "fastfetch.h"
|
2022-07-25 12:24:23 +02:00
|
|
|
#include "common/properties.h"
|
2021-06-20 21:04:55 +02:00
|
|
|
|
2022-06-18 14:25:31 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2021-06-20 21:04:55 +02:00
|
|
|
#define FF_CURSOR_MODULE_NAME "Cursor"
|
|
|
|
|
#define FF_CURSOR_NUM_FORMAT_ARGS 2
|
|
|
|
|
|
2021-06-26 16:48:15 +02:00
|
|
|
static void printCursor(FFinstance* instance, FFstrbuf* cursorTheme, const FFstrbuf* cursorSize)
|
2021-06-20 21:04:55 +02:00
|
|
|
{
|
2021-06-26 16:48:15 +02:00
|
|
|
ffStrbufRemoveIgnCaseEndS(cursorTheme, "cursors");
|
|
|
|
|
ffStrbufRemoveIgnCaseEndS(cursorTheme, "cursor");
|
|
|
|
|
ffStrbufTrimRight(cursorTheme, '_');
|
2021-06-26 17:08:15 +02:00
|
|
|
ffStrbufTrimRight(cursorTheme, '-');
|
2021-06-26 16:48:15 +02:00
|
|
|
if(cursorTheme->length == 0)
|
|
|
|
|
ffStrbufAppendS(cursorTheme, "default");
|
|
|
|
|
|
2022-06-17 18:15:36 +02:00
|
|
|
if(instance->config.cursor.outputFormat.length == 0)
|
2022-02-14 11:44:10 +01:00
|
|
|
{
|
2022-06-17 18:15:36 +02:00
|
|
|
ffPrintLogoAndKey(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor.key);
|
2022-02-14 11:44:10 +01:00
|
|
|
ffStrbufWriteTo(cursorTheme, stdout);
|
|
|
|
|
|
|
|
|
|
if(cursorSize != NULL && cursorSize->length > 0)
|
|
|
|
|
{
|
|
|
|
|
fputs(" (", stdout);
|
|
|
|
|
ffStrbufWriteTo(cursorSize, stdout);
|
|
|
|
|
fputs("px)", stdout);
|
|
|
|
|
}
|
2021-06-20 21:04:55 +02:00
|
|
|
|
2022-02-14 11:44:10 +01:00
|
|
|
putchar('\n');
|
|
|
|
|
}
|
|
|
|
|
else
|
2021-06-20 21:04:55 +02:00
|
|
|
{
|
2022-06-17 18:15:36 +02:00
|
|
|
ffPrintFormat(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, FF_CURSOR_NUM_FORMAT_ARGS, (FFformatarg[]){
|
2022-02-14 11:44:10 +01:00
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, cursorTheme},
|
|
|
|
|
{FF_FORMAT_ARG_TYPE_STRBUF, cursorSize}
|
|
|
|
|
});
|
2021-06-20 21:04:55 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void printCursorGTK(FFinstance* instance)
|
|
|
|
|
{
|
|
|
|
|
const FFGTKResult* gtk = ffDetectGTK4(instance);
|
|
|
|
|
|
|
|
|
|
if(gtk->cursor.length == 0)
|
|
|
|
|
gtk = ffDetectGTK3(instance);
|
|
|
|
|
|
|
|
|
|
if(gtk->cursor.length == 0)
|
|
|
|
|
gtk = ffDetectGTK2(instance);
|
|
|
|
|
|
|
|
|
|
if(gtk->cursor.length == 0)
|
|
|
|
|
{
|
2022-06-17 18:15:36 +02:00
|
|
|
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Couldn't detect GTK Cursor");
|
2021-06-20 21:04:55 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-26 16:48:15 +02:00
|
|
|
//gtk->cursor is const, so we don't want to modify it
|
|
|
|
|
FFstrbuf theme;
|
|
|
|
|
ffStrbufInitCopy(&theme, >k->cursor);
|
|
|
|
|
|
|
|
|
|
printCursor(instance, &theme, >k->cursorSize);
|
|
|
|
|
|
|
|
|
|
ffStrbufDestroy(&theme);
|
2021-06-20 21:04:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void printCursorXFCE(FFinstance* instance)
|
|
|
|
|
{
|
|
|
|
|
FFstrbuf cursorTheme;
|
|
|
|
|
ffStrbufInit(&cursorTheme);
|
|
|
|
|
|
|
|
|
|
ffStrbufAppendS(&cursorTheme, ffSettingsGetXFConf(instance, "xsettings", "/Gtk/CursorThemeName", FF_VARIANT_TYPE_STRING).strValue);
|
|
|
|
|
|
|
|
|
|
if(cursorTheme.length == 0)
|
|
|
|
|
{
|
2022-06-17 18:15:36 +02:00
|
|
|
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Couldn't find xfce cursor in xfconf (xsettings::/Gtk/CursorThemeName)");
|
2021-06-20 21:04:55 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FFstrbuf cursorSize;
|
|
|
|
|
ffStrbufInit(&cursorSize);
|
|
|
|
|
int cursorSizeVal = ffSettingsGetXFConf(instance, "xsettings", "/Gtk/CursorThemeSize", FF_VARIANT_TYPE_INT).intValue;
|
|
|
|
|
if(cursorSizeVal > 0)
|
|
|
|
|
ffStrbufAppendF(&cursorSize, "%i", cursorSizeVal);
|
|
|
|
|
|
|
|
|
|
printCursor(instance, &cursorTheme, &cursorSize);
|
|
|
|
|
ffStrbufDestroy(&cursorTheme);
|
|
|
|
|
ffStrbufDestroy(&cursorSize);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-26 18:14:09 +02:00
|
|
|
static void printCursorFromConfigFile(FFinstance* instance, const char* relativeFilePath, const char* themeStart, const char* themeDefault, const char* sizeStart, const char* sizeDefault)
|
2021-06-26 17:31:50 +02:00
|
|
|
{
|
|
|
|
|
FFstrbuf cursorTheme;
|
|
|
|
|
ffStrbufInit(&cursorTheme);
|
|
|
|
|
|
|
|
|
|
FFstrbuf cursorSize;
|
|
|
|
|
ffStrbufInit(&cursorSize);
|
|
|
|
|
|
2021-06-26 18:14:09 +02:00
|
|
|
if(ffParsePropFileConfigValues(instance, relativeFilePath, 2, (FFpropquery[]) {
|
|
|
|
|
{themeStart, &cursorTheme},
|
|
|
|
|
{sizeStart, &cursorSize}
|
2021-06-26 17:31:50 +02:00
|
|
|
})) {
|
2021-06-26 18:14:09 +02:00
|
|
|
|
|
|
|
|
if(cursorTheme.length == 0)
|
|
|
|
|
ffStrbufAppendS(&cursorTheme, themeDefault);
|
|
|
|
|
|
|
|
|
|
if(cursorSize.length == 0)
|
|
|
|
|
ffStrbufAppendS(&cursorSize, sizeDefault);
|
2021-06-26 17:31:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(cursorTheme.length == 0)
|
2022-06-17 18:15:36 +02:00
|
|
|
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Couldn't find cursor in %s", relativeFilePath);
|
2021-06-26 19:00:15 +02:00
|
|
|
else
|
|
|
|
|
printCursor(instance, &cursorTheme, &cursorSize);
|
2021-06-26 17:31:50 +02:00
|
|
|
|
|
|
|
|
ffStrbufDestroy(&cursorTheme);
|
|
|
|
|
ffStrbufDestroy(&cursorSize);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-26 11:39:42 +02:00
|
|
|
static bool printCursorFromXResources(FFinstance* instance)
|
|
|
|
|
{
|
|
|
|
|
FFstrbuf theme;
|
|
|
|
|
ffStrbufInit(&theme);
|
|
|
|
|
|
|
|
|
|
FFstrbuf size;
|
|
|
|
|
ffStrbufInit(&size);
|
|
|
|
|
|
|
|
|
|
ffParsePropFileHomeValues(instance, ".Xresources", 2, (FFpropquery[]) {
|
|
|
|
|
{"Xcursor.theme :", &theme},
|
|
|
|
|
{"Xcursor.size :", &size}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if(theme.length == 0)
|
|
|
|
|
{
|
|
|
|
|
ffStrbufDestroy(&size);
|
|
|
|
|
ffStrbufDestroy(&theme);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printCursor(instance, &theme, &size);
|
|
|
|
|
ffStrbufDestroy(&size);
|
|
|
|
|
ffStrbufDestroy(&theme);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool printCursorFromXDG(FFinstance* instance, bool user)
|
|
|
|
|
{
|
|
|
|
|
FFstrbuf theme;
|
|
|
|
|
ffStrbufInit(&theme);
|
|
|
|
|
|
|
|
|
|
if(user)
|
|
|
|
|
ffParsePropFileHome(instance, ".icons/default/index.theme", "Inherits =", &theme);
|
|
|
|
|
else
|
2022-04-10 15:07:52 +02:00
|
|
|
ffParsePropFile(FASTFETCH_TARGET_DIR_USR"/share/icons/default/index.theme", "Inherits =", &theme);
|
2021-06-26 11:39:42 +02:00
|
|
|
|
|
|
|
|
if(theme.length == 0)
|
|
|
|
|
{
|
|
|
|
|
ffStrbufDestroy(&theme);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printCursor(instance, &theme, NULL);
|
|
|
|
|
ffStrbufDestroy(&theme);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool printCursorFromEnv(FFinstance* instance)
|
|
|
|
|
{
|
|
|
|
|
const char* xcursor_theme = getenv("XCURSOR_THEME");
|
|
|
|
|
|
2022-01-07 18:00:38 +01:00
|
|
|
if(!ffStrSet(xcursor_theme))
|
2021-06-26 11:39:42 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
FFstrbuf theme;
|
|
|
|
|
ffStrbufInit(&theme);
|
|
|
|
|
ffStrbufAppendS(&theme, xcursor_theme);
|
|
|
|
|
|
|
|
|
|
FFstrbuf size;
|
|
|
|
|
ffStrbufInit(&size);
|
|
|
|
|
ffStrbufAppendS(&size, getenv("XCURSOR_SIZE"));
|
|
|
|
|
|
|
|
|
|
printCursor(instance, &theme, &size);
|
|
|
|
|
|
|
|
|
|
ffStrbufDestroy(&size);
|
|
|
|
|
ffStrbufDestroy(&theme);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-20 21:04:55 +02:00
|
|
|
void ffPrintCursor(FFinstance* instance)
|
|
|
|
|
{
|
2022-01-10 14:41:34 +01:00
|
|
|
#ifdef __ANDROID__
|
2022-06-17 18:15:36 +02:00
|
|
|
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Cursor detection is not supported on Android");
|
2022-01-10 14:41:34 +01:00
|
|
|
return;
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-01-02 16:55:26 +01:00
|
|
|
const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance);
|
2021-06-20 21:04:55 +02:00
|
|
|
|
2022-06-18 14:55:56 +02:00
|
|
|
if(ffStrbufCompS(&wmde->wmPrettyName, "WSLg") == 0)
|
|
|
|
|
{
|
|
|
|
|
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "WSLg uses native windows cursor");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-27 21:53:50 +02:00
|
|
|
if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, "TTY") == 0)
|
|
|
|
|
{
|
2022-06-17 18:15:36 +02:00
|
|
|
ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Cursor isn't supported in TTY");
|
2021-06-27 21:53:50 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-20 21:04:55 +02:00
|
|
|
if(ffStrbufIgnCaseCompS(&wmde->dePrettyName, "KDE Plasma") == 0)
|
2021-06-26 11:39:42 +02:00
|
|
|
{
|
2021-06-26 18:14:09 +02:00
|
|
|
printCursorFromConfigFile(instance, "kcminputrc", "cursorTheme =", "Breeze", "cursorSize =", "24");
|
2021-06-26 11:39:42 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(ffStrbufStartsWithIgnCaseS(&wmde->dePrettyName, "XFCE"))
|
|
|
|
|
{
|
2021-06-20 21:04:55 +02:00
|
|
|
printCursorXFCE(instance);
|
2021-06-26 11:39:42 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-26 17:31:50 +02:00
|
|
|
if(ffStrbufStartsWithIgnCaseS(&wmde->dePrettyName, "LXQt"))
|
|
|
|
|
{
|
2021-06-26 18:14:09 +02:00
|
|
|
printCursorFromConfigFile(instance, "lxqt/session.conf", "cursor_theme =", "Adwaita", "cursor_size =", "24");
|
2021-06-26 17:31:50 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-26 11:39:42 +02:00
|
|
|
if(ffStrbufIgnCaseCompS(&wmde->dePrettyName, "Gnome") == 0 || ffStrbufIgnCaseCompS(&wmde->dePrettyName, "Cinnamon") == 0 || ffStrbufIgnCaseCompS(&wmde->dePrettyName, "Mate") == 0)
|
|
|
|
|
{
|
2021-06-20 21:04:55 +02:00
|
|
|
printCursorGTK(instance);
|
2021-06-26 11:39:42 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-27 21:18:43 +02:00
|
|
|
if(
|
|
|
|
|
printCursorFromEnv(instance) ||
|
|
|
|
|
printCursorFromXDG(instance, true) ||
|
|
|
|
|
printCursorFromXResources(instance) ||
|
|
|
|
|
printCursorFromXDG(instance, false)
|
|
|
|
|
) return;
|
2021-06-26 11:39:42 +02:00
|
|
|
|
|
|
|
|
printCursorGTK(instance);
|
2021-06-20 21:04:55 +02:00
|
|
|
}
|