Files
fastfetch/src/detection/cursor/cursor_linux.c
T

102 lines
3.5 KiB
C
Raw Normal View History

2022-11-23 12:10:45 +08:00
#include "cursor.h"
2023-02-14 17:46:21 +08:00
#include "detection/gtk_qt/gtk_qt.h"
2022-11-23 12:10:45 +08:00
#include "detection/displayserver/displayserver.h"
2026-01-06 09:48:38 +08:00
#include "common/properties.h"
#include "common/parsing.h"
#include "common/settings.h"
#include "common/stringUtils.h"
2022-11-23 12:10:45 +08:00
#include <stdlib.h>
2026-03-29 09:28:49 +08:00
static bool detectCursorGTK(FFCursorResult* result) {
const FFGTKResult* gtk = ffDetectGTK4();
2022-11-23 12:10:45 +08:00
2026-03-29 09:28:49 +08:00
if (gtk->cursor.length == 0) {
gtk = ffDetectGTK3();
2026-03-29 09:28:49 +08:00
}
2022-11-23 12:10:45 +08:00
2026-03-29 09:28:49 +08:00
if (gtk->cursor.length == 0) {
gtk = ffDetectGTK2();
2026-03-29 09:28:49 +08:00
}
2022-11-23 12:10:45 +08:00
2026-03-29 09:28:49 +08:00
if (gtk->cursor.length == 0) {
2023-01-17 17:49:41 +01:00
return false;
2026-03-29 09:28:49 +08:00
}
2022-11-23 12:10:45 +08:00
ffStrbufAppend(&result->theme, &gtk->cursor);
ffStrbufAppend(&result->size, &gtk->cursorSize);
2023-01-17 17:49:41 +01:00
return true;
2022-11-23 12:10:45 +08:00
}
2026-03-29 09:28:49 +08:00
static void detectCursorFromConfigFile(const char* relativeFilePath, const char* themeStart, const char* themeDefault, const char* sizeStart, const char* sizeDefault, FFCursorResult* result) {
if (ffParsePropFileConfigValues(relativeFilePath, 2, (FFpropquery[]) {{themeStart, &result->theme}, {sizeStart, &result->size}})) {
if (result->theme.length == 0) {
2022-11-23 12:10:45 +08:00
ffStrbufAppendS(&result->theme, themeDefault);
2026-03-29 09:28:49 +08:00
}
2022-11-23 12:10:45 +08:00
2026-03-29 09:28:49 +08:00
if (result->size.length == 0) {
2022-11-23 12:10:45 +08:00
ffStrbufAppendS(&result->size, sizeDefault);
2026-03-29 09:28:49 +08:00
}
2022-11-23 12:10:45 +08:00
}
2026-03-29 09:28:49 +08:00
if (result->theme.length == 0) {
2022-11-23 12:10:45 +08:00
ffStrbufAppendF(&result->error, "Couldn't find cursor in %s", relativeFilePath);
2026-03-29 09:28:49 +08:00
}
2022-11-23 12:10:45 +08:00
}
2026-03-29 09:28:49 +08:00
static bool detectCursorFromXResources(FFCursorResult* result) {
ffParsePropFileHomeValues(".Xresources", 2, (FFpropquery[]) {{"Xcursor.theme :", &result->theme}, {"Xcursor.size :", &result->size}});
2022-11-23 12:10:45 +08:00
return result->theme.length > 0;
}
2026-03-29 09:28:49 +08:00
static bool detectCursorFromEnv(FFCursorResult* result) {
2022-11-23 12:10:45 +08:00
const char* xcursor_theme = getenv("XCURSOR_THEME");
2026-03-29 09:28:49 +08:00
if (!ffStrSet(xcursor_theme)) {
2022-11-23 12:10:45 +08:00
return false;
2026-03-29 09:28:49 +08:00
}
2022-11-23 12:10:45 +08:00
ffStrbufAppendS(&result->theme, xcursor_theme);
ffStrbufAppendS(&result->size, getenv("XCURSOR_SIZE"));
return true;
}
2026-03-29 09:28:49 +08:00
static bool detectCursorHyprcursor(FFCursorResult* result) {
const char* hyprcursor_theme = getenv("HYPRCURSOR_THEME");
2026-03-29 09:28:49 +08:00
if (!ffStrSet(hyprcursor_theme)) {
return false;
2026-03-29 09:28:49 +08:00
}
ffStrbufAppendS(&result->theme, hyprcursor_theme);
ffStrbufAppendS(&result->size, getenv("HYPRCURSOR_SIZE"));
return true;
}
2026-03-29 09:28:49 +08:00
void ffDetectCursor(FFCursorResult* result) {
const FFDisplayServerResult* wmde = ffConnectDisplayServer();
2022-11-23 12:10:45 +08:00
2026-03-29 09:28:49 +08:00
if (ffStrbufEqualS(&wmde->wmPrettyName, FF_WM_PRETTY_WSLG)) {
2022-11-23 12:10:45 +08:00
ffStrbufAppendS(&result->error, "WSLg uses native windows cursor");
2026-03-29 09:28:49 +08:00
} else if (ffStrbufIgnCaseEqualS(&wmde->wmProtocolName, FF_WM_PROTOCOL_TTY)) {
2022-11-23 12:10:45 +08:00
ffStrbufAppendS(&result->error, "Cursor isn't supported in TTY");
2026-03-29 09:28:49 +08:00
} else if (ffStrbufIgnCaseEqualS(&wmde->dePrettyName, FF_DE_PRETTY_PLASMA)) {
detectCursorFromConfigFile("kcminputrc", "cursorTheme =", "Breeze", "cursorSize =", "24", result);
2026-03-29 09:28:49 +08:00
} else if (ffStrbufIgnCaseEqualS(&wmde->dePrettyName, FF_DE_PRETTY_LXQT)) {
detectCursorFromConfigFile("lxqt/session.conf", "cursor_theme =", "Adwaita", "cursor_size =", "24", result);
2026-03-29 09:28:49 +08:00
} else if (ffStrbufIgnCaseEqualS(&wmde->wmPrettyName, FF_WM_PRETTY_HYPRLAND) && detectCursorHyprcursor(result)) {
return;
2026-03-29 09:28:49 +08:00
} else if (
!detectCursorGTK(result) &&
!detectCursorFromEnv(result) &&
!ffParsePropFileHome(".icons/default/index.theme", "Inherits =", &result->theme) &&
!detectCursorFromXResources(result) &&
2026-03-29 09:28:49 +08:00
!ffParsePropFileData("icons/default/index.theme", "Inherits =", &result->theme)) {
ffStrbufAppendS(&result->error, "Couldn't find cursor");
}
2022-11-23 12:10:45 +08:00
}