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-05 16:19:47 +08:00
|
|
|
#include "util/properties.h"
|
|
|
|
|
#include "util/parsing.h"
|
|
|
|
|
#include "util/settings.h"
|
2023-02-01 15:56:25 +01:00
|
|
|
#include "util/stringUtils.h"
|
2022-11-23 12:10:45 +08:00
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
static bool detectCursorGTK(FFCursorResult* result)
|
2022-11-23 12:10:45 +08:00
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
const FFGTKResult* gtk = ffDetectGTK4();
|
2022-11-23 12:10:45 +08:00
|
|
|
|
|
|
|
|
if(gtk->cursor.length == 0)
|
2023-06-24 10:59:53 +08:00
|
|
|
gtk = ffDetectGTK3();
|
2022-11-23 12:10:45 +08:00
|
|
|
|
|
|
|
|
if(gtk->cursor.length == 0)
|
2023-06-24 10:59:53 +08:00
|
|
|
gtk = ffDetectGTK2();
|
2022-11-23 12:10:45 +08:00
|
|
|
|
|
|
|
|
if(gtk->cursor.length == 0)
|
2023-01-17 17:49:41 +01:00
|
|
|
return false;
|
2022-11-23 12:10:45 +08:00
|
|
|
|
|
|
|
|
ffStrbufAppend(&result->theme, >k->cursor);
|
|
|
|
|
ffStrbufAppend(&result->size, >k->cursorSize);
|
2023-01-17 17:49:41 +01:00
|
|
|
return true;
|
2022-11-23 12:10:45 +08:00
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
static void detectCursorFromConfigFile(const char* relativeFilePath, const char* themeStart, const char* themeDefault, const char* sizeStart, const char* sizeDefault, FFCursorResult* result)
|
2022-11-23 12:10:45 +08:00
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
if(ffParsePropFileConfigValues(relativeFilePath, 2, (FFpropquery[]) {
|
2022-11-23 12:10:45 +08:00
|
|
|
{themeStart, &result->theme},
|
|
|
|
|
{sizeStart, &result->size}
|
|
|
|
|
})) {
|
|
|
|
|
|
|
|
|
|
if(result->theme.length == 0)
|
|
|
|
|
ffStrbufAppendS(&result->theme, themeDefault);
|
|
|
|
|
|
|
|
|
|
if(result->size.length == 0)
|
|
|
|
|
ffStrbufAppendS(&result->size, sizeDefault);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(result->theme.length == 0)
|
|
|
|
|
ffStrbufAppendF(&result->error, "Couldn't find cursor in %s", relativeFilePath);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
static bool detectCursorFromXResources(FFCursorResult* result)
|
2022-11-23 12:10:45 +08:00
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
ffParsePropFileHomeValues(".Xresources", 2, (FFpropquery[]) {
|
2022-11-23 12:10:45 +08:00
|
|
|
{"Xcursor.theme :", &result->theme},
|
|
|
|
|
{"Xcursor.size :", &result->size}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return result->theme.length > 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
static bool detectCursorFromEnv(FFCursorResult* result)
|
2022-11-23 12:10:45 +08:00
|
|
|
{
|
|
|
|
|
const char* xcursor_theme = getenv("XCURSOR_THEME");
|
|
|
|
|
|
|
|
|
|
if(!ffStrSet(xcursor_theme))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
ffStrbufAppendS(&result->theme, xcursor_theme);
|
|
|
|
|
ffStrbufAppendS(&result->size, getenv("XCURSOR_SIZE"));
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-07 20:08:41 +08:00
|
|
|
static bool detectCursorHyprcursor(FFCursorResult* result)
|
|
|
|
|
{
|
|
|
|
|
const char* hyprcursor_theme = getenv("HYPRCURSOR_THEME");
|
|
|
|
|
|
|
|
|
|
if(!ffStrSet(hyprcursor_theme))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
ffStrbufAppendS(&result->theme, hyprcursor_theme);
|
|
|
|
|
ffStrbufAppendS(&result->size, getenv("HYPRCURSOR_SIZE"));
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
void ffDetectCursor(FFCursorResult* result)
|
2022-11-23 12:10:45 +08:00
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
const FFDisplayServerResult* wmde = ffConnectDisplayServer();
|
2022-11-23 12:10:45 +08:00
|
|
|
|
2024-04-07 19:35:22 +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");
|
2024-04-07 19:35:22 +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");
|
2024-04-07 19:35:22 +08:00
|
|
|
else if(ffStrbufIgnCaseEqualS(&wmde->dePrettyName, FF_DE_PRETTY_PLASMA))
|
2023-06-24 10:59:53 +08:00
|
|
|
detectCursorFromConfigFile("kcminputrc", "cursorTheme =", "Breeze", "cursorSize =", "24", result);
|
2024-04-07 20:44:17 +08:00
|
|
|
else if(ffStrbufIgnCaseEqualS(&wmde->dePrettyName, FF_DE_PRETTY_LXQT))
|
2023-06-24 10:59:53 +08:00
|
|
|
detectCursorFromConfigFile("lxqt/session.conf", "cursor_theme =", "Adwaita", "cursor_size =", "24", result);
|
2024-04-07 20:08:41 +08:00
|
|
|
else if(ffStrbufIgnCaseEqualS(&wmde->wmPrettyName, FF_WM_PRETTY_HYPRLAND) && detectCursorHyprcursor(result))
|
|
|
|
|
return;
|
2023-01-17 17:49:41 +01:00
|
|
|
else if(
|
2023-06-24 10:59:53 +08:00
|
|
|
!detectCursorGTK(result) &&
|
|
|
|
|
!detectCursorFromEnv(result) &&
|
|
|
|
|
!ffParsePropFileHome(".icons/default/index.theme", "Inherits =", &result->theme) &&
|
|
|
|
|
!detectCursorFromXResources(result) &&
|
|
|
|
|
!ffParsePropFileData("icons/default/index.theme", "Inherits =", &result->theme)
|
2023-01-17 17:49:41 +01:00
|
|
|
) ffStrbufAppendS(&result->error, "Couldn't find cursor");
|
2022-11-23 12:10:45 +08:00
|
|
|
}
|