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