1 /*
2                                     __
3                                    / _|
4   __ _ _   _ _ __ ___  _ __ __ _  | |_ ___  ___ ___
5  / _` | | | | '__/ _ \| '__/ _` | |  _/ _ \/ __/ __|
6 | (_| | |_| | | | (_) | | | (_| | | || (_) \__ \__ \
7  \__,_|\__,_|_|  \___/|_|  \__,_| |_| \___/|___/___/
8 
9 Copyright (C) 2002 Keith Packard.
10 Copyright (C) 2018-2019 Aurora Free Open Source Software.
11 
12 This file is part of the Aurora Free Open Source Software. This
13 organization promote free and open source software that you can
14 redistribute and/or modify under the terms of the GNU Lesser General
15 Public License Version 3 as published by the Free Software Foundation or
16 (at your option) any later version approved by the Aurora Free Open Source
17 Software Organization. The license is available in the package root path
18 as 'LICENSE' file. Please review the following information to ensure the
19 GNU Lesser General Public License version 3 requirements will be met:
20 https://www.gnu.org/licenses/lgpl.html .
21 
22 Alternatively, this file may be used under the terms of the GNU General
23 Public License version 3 or later as published by the Free Software
24 Foundation. Please review the following information to ensure the GNU
25 General Public License requirements will be met:
26 http://www.gnu.org/licenses/gpl-3.0.html.
27 
28 NOTE: All products, services or anything associated to trademarks and
29 service marks used or referenced on this file are the property of their
30 respective companies/owners or its subsidiaries. Other names and brands
31 may be claimed as the property of others.
32 
33 For more info about intellectual property visit: aurorafoss.org or
34 directly send an email to: contact (at) aurorafoss.org .
35 
36 This file is part of X11 Xcursor implementation from X.Org Foundation.
37 */
38 
39 module aurorafw.gui.platform.x11.xcursor.types;
40 
41 import aurorafw.gui.platform.x11.x;
42 import aurorafw.gui.platform.x11.xlib;
43 
44 ///
45 alias XcursorBool = int;
46 ///
47 alias XcursorUInt = uint;
48 
49 ///
50 alias XcursorDim = XcursorUInt;
51 ///
52 alias XcursorPixel = XcursorUInt;
53 
54 ///
55 enum XcursorTrue = 1;
56 ///
57 enum XcursorFalse = 0;
58 
59 /**
60  * Cursor files start with a header.  The header
61  * contains a magic number, a version number and a
62  * table of contents which has type and offset information
63  * for the remaining tables in the file.
64  *
65  * File minor versions increment for compatible changes
66  * File major versions increment for incompatible changes (never, we hope)
67  *
68  * Chunks of the same type are always upward compatible.  Incompatible
69  * changes are made with new chunk types; the old data can remain under
70  * the old type.  Upward compatible changes can add header data as the
71  * header lengths are specified in the file.
72  *
73  *  File:
74  *	FileHeader
75  *	LISTofChunk
76  *
77  *  FileHeader:
78  *	CARD32		magic	    magic number
79  *	CARD32		header	    bytes in file header
80  *	CARD32		version	    file version
81  *	CARD32		ntoc	    number of toc entries
82  *	LISTofFileToc   toc	    table of contents
83  *
84  *  FileToc:
85  *	CARD32		type	    entry type
86  *	CARD32		subtype	    entry subtype (size for images)
87  *	CARD32		position    absolute file position
88  */
89 
90 /// "Xcur" LSBFirst
91 enum XCURSOR_MAGIC = 0x72756358;
92 
93 ///
94 struct XcursorFileToc {
95 	/// chunk type
96 	XcursorUInt type;
97 	/// subtype (size for images)
98 	XcursorUInt subtype;
99 	/// absolute position in file
100 	XcursorUInt position;
101 }
102 
103 ///
104 struct XcursorFileHeader {
105 	/// magic number
106 	XcursorUInt magic;
107 	/// byte length of header
108 	XcursorUInt header;
109 	/// file version number
110 	XcursorUInt version_;
111 	/// number of toc entries
112 	XcursorUInt ntoc;
113 	/// table of contents
114 	XcursorFileToc* tocs;
115 }
116 
117 /**
118  * The rest of the file is a list of chunks, each tagged by type
119  * and version.
120  *
121  *  Chunk:
122  *	ChunkHeader
123  *	<extra type-specific header fields>
124  *	<type-specific data>
125  *
126  *  ChunkHeader:
127  *	CARD32	    header	bytes in chunk header + type header
128  *	CARD32	    type	chunk type
129  *	CARD32	    subtype	chunk subtype
130  *	CARD32	    version	chunk type version
131  */
132 
133 enum XCURSOR_CHUNK_HEADER_LEN = 4 * 4;
134 
135 /// XcursorChunkHeader
136 struct _XcursorChunkHeader {
137 	/// bytes in chunk header
138 	XcursorUInt header;
139 	/// chunk type
140 	XcursorUInt type;
141 	/// chunk subtype (size for images)
142 	XcursorUInt subtype;
143 	/// version of this type
144 	XcursorUInt version_;
145 }
146 
147 /*
148  * Here's a list of the known chunk types
149  */
150 
151 /**
152  * Comments consist of a 4-byte length field followed by
153  * UTF-8 encoded text
154  *
155  *  Comment:
156  *	ChunkHeader header	chunk header
157  *	CARD32	    length	bytes in text
158  *	LISTofCARD8 text	UTF-8 encoded text
159  */
160 enum {
161 	///
162 	XCURSOR_COMMENT_TYPE = 0xfffe0001,
163 	///
164 	XCURSOR_COMMENT_VERSION = 1,
165 	///
166 	XCURSOR_COMMENT_HEADER_LEN = XCURSOR_CHUNK_HEADER_LEN + (1 *4),
167 	///
168 	XCURSOR_COMMENT_COPYRIGHT = 1,
169 	///
170 	XCURSOR_COMMENT_LICENSE = 2,
171 	///
172 	XCURSOR_COMMENT_OTHER = 3,
173 	///
174 	XCURSOR_COMMENT_MAX_LEN = 0x100000
175 }
176 
177 ///
178 struct XcursorComment {
179 	///
180 	XcursorUInt version_;
181 	///
182 	XcursorUInt comment_type;
183 	///
184 	char* comment;
185 }
186 
187 /**
188  * Each cursor image occupies a separate image chunk.
189  * The length of the image header follows the chunk header
190  * so that future versions can extend the header without
191  * breaking older applications
192  *
193  *  Image:
194  *	ChunkHeader	header	chunk header
195  *	CARD32		width	actual width
196  *	CARD32		height	actual height
197  *	CARD32		xhot	hot spot x
198  *	CARD32		yhot	hot spot y
199  *	CARD32		delay	animation delay
200  *	LISTofCARD32	pixels	ARGB pixels
201  */
202 enum {
203 	///
204 	XCURSOR_IMAGE_TYPE = 0xfffd0002,
205 	///
206 	XCURSOR_IMAGE_VERSION = 1,
207 	///
208 	XCURSOR_IMAGE_HEADER_LEN = XCURSOR_CHUNK_HEADER_LEN + (5*4),
209 	/// 32767x32767 max cursor size
210 	XCURSOR_IMAGE_MAX_SIZE = 0x7fff
211 }
212 
213 ///
214 struct XcursorImage {
215 	/// version of the image data
216 	XcursorUInt version_;
217 	/// nominal size for matching
218 	XcursorDim size;
219 	/// actual width
220 	XcursorDim width;
221 	/// actual height
222 	XcursorDim height;
223 	/// hot spot x (must be inside image)
224 	XcursorDim xhot;
225 	/// hot spot y (must be inside image)
226 	XcursorDim yhot;
227 	/// animation delay to next frame (ms)
228 	XcursorUInt delay;
229 	/// pointer to pixels
230 	XcursorPixel* pixels;
231 }
232 
233 /**
234  * Other data structures exposed by the library API
235  */
236 struct XcursorImages {
237 	/// number of images
238 	int nimage;
239 	/// array of XcursorImage pointers
240 	XcursorImage** images;
241 	/// name used to load images
242 	char* name;
243 }
244 
245 /// Display holding cursors
246 struct XcursorCursors {
247 	///
248 	Display* dpy;
249 	/// reference count
250 	int ref_;
251 	/// number of cursors
252 	int ncursor;
253 	/// array of cursors
254 	Cursor* cursors;
255 }
256 
257 ///
258 struct XcursorAnimate {
259 	/// list of cursors to use
260 	XcursorCursors* cursors;
261 	/// which cursor is next
262 	int sequence;
263 }
264 
265 ///
266 struct XcursorFile {
267 	///
268 	void* closure;
269 	extern(C) int function(XcursorFile* file, ubyte* buf, int len) read;
270 	///
271 	extern(C) int function(XcursorFile* file, ubyte* buf, int len) write;
272 	///
273 	extern(C) int function(XcursorFile* file, long offset, int whence) seek;
274 }
275 
276 ///
277 struct XcursorComments {
278 	/// number of comments
279 	int ncomment;
280 	/// array of XcursorComment pointers
281 	XcursorComment** comments;
282 }
283 
284 ///
285 enum XCURSOR_CORE_THEME = "core";
286 ///
287 enum XCURSOR_BITMAP_HASH_SIZE = 16;
288 
289 // function types
290 package extern(C) @nogc nothrow {
291 	alias da_XcursorImageCreate = XcursorImage* function(int width, int height);
292 	alias da_XcursorImageDestroy = void function(XcursorImage* image);
293 	alias da_XcursorImagesCreate = XcursorImages* function(int size);
294 	alias da_XcursorImagesDestroy = void function(XcursorImages* images);
295 	alias da_XcursorImageLoadCursor = Cursor function(Display* dpy, const XcursorImage* image);
296 }