This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathwayland-cursor-xdg-dirs.patch
208 lines (198 loc) · 4.92 KB
/
wayland-cursor-xdg-dirs.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
From abea67d38acecdcf6e70f2f4bce090b158dee161 Mon Sep 17 00:00:00 2001
From: Robert McQueen <rob@endlessm.com>
Date: Wed, 16 May 2018 14:43:34 +0100
Subject: [PATCH] cursor: check XDG_DATA_HOME and XDG_DATA_DIRS for cursor
themes
Use the XDG-defined user and system dirs to look for icons/ directories
before falling back to hardcoded default/legacy XCURSOR_PATH values. Fixes
the availability of themed cursors in sandboxed and other environments
that rely on XDG_DATA_DIRS being set and respected.
---
cursor/xcursor.c | 150 +++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 125 insertions(+), 25 deletions(-)
diff --git a/cursor/xcursor.c b/cursor/xcursor.c
index 689c702..8ed15fc 100644
--- a/cursor/xcursor.c
+++ b/cursor/xcursor.c
@@ -24,6 +24,8 @@
*/
#include "xcursor.h"
+
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -608,6 +610,14 @@ XcursorFileLoadImages (FILE *file, int size)
return XcursorXcFileLoadImages (&f, size);
}
+#ifndef USER_DATA_DIR
+#define USER_DATA_DIR ".local/share/"
+#endif
+
+#ifndef ICON_SUBDIR
+#define ICON_SUBDIR "icons/"
+#endif
+
/*
* From libXcursor/src/library.c
*/
@@ -617,23 +627,9 @@ XcursorFileLoadImages (FILE *file, int size)
#endif
#ifndef XCURSORPATH
-#define XCURSORPATH "~/.icons:/usr/share/icons:/usr/share/pixmaps:~/.cursors:/usr/share/cursors/xorg-x11:"ICONDIR
+#define XCURSORPATH "~/.icons/:/usr/share/pixmaps/:~/.cursors/:/usr/share/cursors/xorg-x11/:"ICONDIR
#endif
-static const char *
-XcursorLibraryPath (void)
-{
- static const char *path;
-
- if (!path)
- {
- path = getenv ("XCURSOR_PATH");
- if (!path)
- path = XCURSORPATH;
- }
- return path;
-}
-
static void
_XcursorAddPathElt (char *path, const char *elt, int len)
{
@@ -657,6 +653,120 @@ _XcursorAddPathElt (char *path, const char *elt, int len)
path[pathlen + len] = '\0';
}
+static const char *
+_XcursorNextPath (const char *path)
+{
+ char *colon = strchr (path, ':');
+
+ if (!colon)
+ return NULL;
+ return colon + 1;
+}
+
+static const char *
+_XcursorDataDirs (void)
+{
+ static char *data_dirs = NULL;
+ const char *xdg_data_home = NULL;
+ const char *xdg_data_dirs = NULL;
+ char *user_data_dir = NULL;
+ int user_data_dir_len;
+
+ if (data_dirs)
+ return data_dirs;
+
+ xdg_data_home = getenv ("XDG_DATA_HOME");
+ if (!xdg_data_home || !xdg_data_home[0])
+ xdg_data_home = "~/";
+
+ xdg_data_dirs = getenv ("XDG_DATA_DIRS");
+ if (!xdg_data_dirs || !xdg_data_dirs[0])
+ xdg_data_dirs = "/usr/local/share/:/usr/share/";
+
+ /* home dir + / + .local/share/ + NULL */
+ user_data_dir_len = strlen (xdg_data_home) + 1 + strlen (USER_DATA_DIR) + 1;
+ user_data_dir = malloc (user_data_dir_len);
+ if (!user_data_dir)
+ return NULL;
+
+ strcpy (user_data_dir, xdg_data_home);
+ _XcursorAddPathElt (user_data_dir, USER_DATA_DIR, strlen (USER_DATA_DIR));
+
+ data_dirs = NULL;
+ asprintf (&data_dirs, "%s:%s", user_data_dir, xdg_data_dirs);
+ free (user_data_dir);
+
+ return data_dirs;
+}
+
+static const char *
+XcursorLibraryPath (void)
+{
+ static char *path = NULL;
+ const char *dir;
+ const char *colon;
+ char *tmp;
+ char *oldpath;
+ int dirlen;
+ int len;
+
+ if (path)
+ return path;
+
+ path = getenv ("XCURSOR_PATH");
+ if (path)
+ return path;
+
+ for (dir = _XcursorDataDirs ();
+ dir;
+ dir = _XcursorNextPath (dir))
+ {
+ colon = strchr (dir, ':');
+ if (!colon)
+ colon = dir + strlen (dir);
+
+ dirlen = colon - dir;
+
+ len = dirlen + 1 + strlen (ICON_SUBDIR) + 1;
+ tmp = malloc (len);
+ if (!tmp)
+ {
+ free (path);
+ path = NULL;
+ return NULL;
+ }
+
+ strncpy (tmp, dir, dirlen);
+ tmp[dirlen] = '\0';
+ _XcursorAddPathElt (tmp, ICON_SUBDIR, strlen (ICON_SUBDIR));
+
+ if (!path)
+ {
+ path = tmp;
+ continue;
+ }
+
+ oldpath = path;
+ path = NULL;
+ asprintf (&path, "%s:%s", oldpath, tmp);
+ if (!path)
+ {
+ free (tmp);
+ return NULL;
+ }
+
+ free (tmp);
+ free (oldpath);
+ }
+
+ oldpath = path;
+ path = NULL;
+ asprintf (&path, "%s:%s", oldpath, XCURSORPATH);
+ free (oldpath);
+
+ return path;
+}
+
static char *
_XcursorBuildThemeDir (const char *dir, const char *theme)
{
@@ -732,16 +842,6 @@ _XcursorBuildFullname (const char *dir, const char *subdir, const char *file)
return full;
}
-static const char *
-_XcursorNextPath (const char *path)
-{
- char *colon = strchr (path, ':');
-
- if (!colon)
- return NULL;
- return colon + 1;
-}
-
#define XcursorWhite(c) ((c) == ' ' || (c) == '\t' || (c) == '\n')
#define XcursorSep(c) ((c) == ';' || (c) == ',')
--
2.11.0