cursor: remove struct typedefs, rename to snake case

Signed-off-by: Simon Ser <contact@emersion.fr>
This commit is contained in:
Simon Ser 2022-04-21 11:29:08 +02:00
parent 21394fd5f7
commit a46d8be4e1
3 changed files with 76 additions and 78 deletions

View file

@ -274,7 +274,7 @@ load_fallback_theme(struct wl_cursor_theme *theme)
} }
static struct wl_cursor * static struct wl_cursor *
wl_cursor_create_from_xcursor_images(XcursorImages *images, wl_cursor_create_from_xcursor_images(struct xcursor_images *images,
struct wl_cursor_theme *theme) struct wl_cursor_theme *theme)
{ {
struct cursor *cursor; struct cursor *cursor;
@ -335,7 +335,7 @@ wl_cursor_create_from_xcursor_images(XcursorImages *images,
} }
static void static void
load_callback(XcursorImages *images, void *data) load_callback(struct xcursor_images *images, void *data)
{ {
struct wl_cursor_theme *theme = data; struct wl_cursor_theme *theme = data;
struct wl_cursor *cursor; struct wl_cursor *cursor;

View file

@ -74,19 +74,19 @@
#define XCURSOR_FILE_HEADER_LEN (4 * 4) #define XCURSOR_FILE_HEADER_LEN (4 * 4)
#define XCURSOR_FILE_TOC_LEN (3 * 4) #define XCURSOR_FILE_TOC_LEN (3 * 4)
typedef struct _XcursorFileToc { struct xcursor_file_toc {
uint32_t type; /* chunk type */ uint32_t type; /* chunk type */
uint32_t subtype; /* subtype (size for images) */ uint32_t subtype; /* subtype (size for images) */
uint32_t position; /* absolute position in file */ uint32_t position; /* absolute position in file */
} XcursorFileToc; };
typedef struct _XcursorFileHeader { struct xcursor_file_header {
uint32_t magic; /* magic number */ uint32_t magic; /* magic number */
uint32_t header; /* byte length of header */ uint32_t header; /* byte length of header */
uint32_t version; /* file version number */ uint32_t version; /* file version number */
uint32_t ntoc; /* number of toc entries */ uint32_t ntoc; /* number of toc entries */
XcursorFileToc *tocs; /* table of contents */ struct xcursor_file_toc *tocs; /* table of contents */
} XcursorFileHeader; };
/* /*
* The rest of the file is a list of chunks, each tagged by type * The rest of the file is a list of chunks, each tagged by type
@ -106,12 +106,12 @@ typedef struct _XcursorFileHeader {
#define XCURSOR_CHUNK_HEADER_LEN (4 * 4) #define XCURSOR_CHUNK_HEADER_LEN (4 * 4)
typedef struct _XcursorChunkHeader { struct xcursor_chunk_header {
uint32_t header; /* bytes in chunk header */ uint32_t header; /* bytes in chunk header */
uint32_t type; /* chunk type */ uint32_t type; /* chunk type */
uint32_t subtype; /* chunk subtype (size for images) */ uint32_t subtype; /* chunk subtype (size for images) */
uint32_t version; /* version of this type */ uint32_t version; /* version of this type */
} XcursorChunkHeader; };
/* /*
* Here's a list of the known chunk types * Here's a list of the known chunk types
@ -135,11 +135,11 @@ typedef struct _XcursorChunkHeader {
#define XCURSOR_COMMENT_OTHER 3 #define XCURSOR_COMMENT_OTHER 3
#define XCURSOR_COMMENT_MAX_LEN 0x100000 #define XCURSOR_COMMENT_MAX_LEN 0x100000
typedef struct _XcursorComment { struct xcursor_comment {
uint32_t version; uint32_t version;
uint32_t comment_type; uint32_t comment_type;
char *comment; char *comment;
} XcursorComment; };
/* /*
* Each cursor image occupies a separate image chunk. * Each cursor image occupies a separate image chunk.
@ -162,35 +162,33 @@ typedef struct _XcursorComment {
#define XCURSOR_IMAGE_HEADER_LEN (XCURSOR_CHUNK_HEADER_LEN + (5*4)) #define XCURSOR_IMAGE_HEADER_LEN (XCURSOR_CHUNK_HEADER_LEN + (5*4))
#define XCURSOR_IMAGE_MAX_SIZE 0x7fff /* 32767x32767 max cursor size */ #define XCURSOR_IMAGE_MAX_SIZE 0x7fff /* 32767x32767 max cursor size */
typedef struct _XcursorFile XcursorFile; struct xcursor_file {
struct _XcursorFile {
void *closure; void *closure;
int (*read)(XcursorFile *file, unsigned char *buf, int len); int (*read)(struct xcursor_file *file, unsigned char *buf, int len);
int (*write)(XcursorFile *file, unsigned char *buf, int len); int (*write)(struct xcursor_file *file, unsigned char *buf, int len);
int (*seek)(XcursorFile *file, long offset, int whence); int (*seek)(struct xcursor_file *file, long offset, int whence);
}; };
typedef struct _XcursorComments { struct xcursor_comments {
int ncomment; /* number of comments */ int ncomment; /* number of comments */
XcursorComment **comments; /* array of XcursorComment pointers */ struct xcursor_comments **comments; /* array of XcursorComment pointers */
} XcursorComments; };
/* /*
* From libXcursor/src/file.c * From libXcursor/src/file.c
*/ */
static XcursorImage * static struct xcursor_image *
XcursorImageCreate(int width, int height) XcursorImageCreate(int width, int height)
{ {
XcursorImage *image; struct xcursor_image *image;
if (width < 0 || height < 0) if (width < 0 || height < 0)
return NULL; return NULL;
if (width > XCURSOR_IMAGE_MAX_SIZE || height > XCURSOR_IMAGE_MAX_SIZE) if (width > XCURSOR_IMAGE_MAX_SIZE || height > XCURSOR_IMAGE_MAX_SIZE)
return NULL; return NULL;
image = malloc(sizeof(XcursorImage) + image = malloc(sizeof(struct xcursor_image) +
width * height * sizeof(uint32_t)); width * height * sizeof(uint32_t));
if (!image) if (!image)
return NULL; return NULL;
@ -204,28 +202,28 @@ XcursorImageCreate(int width, int height)
} }
static void static void
XcursorImageDestroy(XcursorImage *image) XcursorImageDestroy(struct xcursor_image *image)
{ {
free(image); free(image);
} }
static XcursorImages * static struct xcursor_images *
XcursorImagesCreate(int size) XcursorImagesCreate(int size)
{ {
XcursorImages *images; struct xcursor_images *images;
images = malloc(sizeof(XcursorImages) + images = malloc(sizeof(struct xcursor_images) +
size * sizeof(XcursorImage *)); size * sizeof(struct xcursor_image *));
if (!images) if (!images)
return NULL; return NULL;
images->nimage = 0; images->nimage = 0;
images->images = (XcursorImage **) (images + 1); images->images = (struct xcursor_image **) (images + 1);
images->name = NULL; images->name = NULL;
return images; return images;
} }
void void
XcursorImagesDestroy(XcursorImages *images) XcursorImagesDestroy(struct xcursor_images *images)
{ {
int n; int n;
@ -239,7 +237,7 @@ XcursorImagesDestroy(XcursorImages *images)
} }
static void static void
XcursorImagesSetName(XcursorImages *images, const char *name) XcursorImagesSetName(struct xcursor_images *images, const char *name)
{ {
char *new; char *new;
@ -257,7 +255,7 @@ XcursorImagesSetName(XcursorImages *images, const char *name)
} }
static bool static bool
_XcursorReadUInt(XcursorFile *file, uint32_t *u) _XcursorReadUInt(struct xcursor_file *file, uint32_t *u)
{ {
unsigned char bytes[4]; unsigned char bytes[4];
@ -275,34 +273,34 @@ _XcursorReadUInt(XcursorFile *file, uint32_t *u)
} }
static void static void
_XcursorFileHeaderDestroy(XcursorFileHeader *fileHeader) _XcursorFileHeaderDestroy(struct xcursor_file_header *fileHeader)
{ {
free(fileHeader); free(fileHeader);
} }
static XcursorFileHeader * static struct xcursor_file_header *
_XcursorFileHeaderCreate(uint32_t ntoc) _XcursorFileHeaderCreate(uint32_t ntoc)
{ {
XcursorFileHeader *fileHeader; struct xcursor_file_header *fileHeader;
if (ntoc > 0x10000) if (ntoc > 0x10000)
return NULL; return NULL;
fileHeader = malloc(sizeof(XcursorFileHeader) + fileHeader = malloc(sizeof(struct xcursor_file_header) +
ntoc * sizeof(XcursorFileToc)); ntoc * sizeof(struct xcursor_file_toc));
if (!fileHeader) if (!fileHeader)
return NULL; return NULL;
fileHeader->magic = XCURSOR_MAGIC; fileHeader->magic = XCURSOR_MAGIC;
fileHeader->header = XCURSOR_FILE_HEADER_LEN; fileHeader->header = XCURSOR_FILE_HEADER_LEN;
fileHeader->version = XCURSOR_FILE_VERSION; fileHeader->version = XCURSOR_FILE_VERSION;
fileHeader->ntoc = ntoc; fileHeader->ntoc = ntoc;
fileHeader->tocs = (XcursorFileToc *) (fileHeader + 1); fileHeader->tocs = (struct xcursor_file_toc *) (fileHeader + 1);
return fileHeader; return fileHeader;
} }
static XcursorFileHeader * static struct xcursor_file_header *
_XcursorReadFileHeader(XcursorFile *file) _XcursorReadFileHeader(struct xcursor_file *file)
{ {
XcursorFileHeader head, *fileHeader; struct xcursor_file_header head, *fileHeader;
uint32_t skip; uint32_t skip;
unsigned int n; unsigned int n;
@ -346,8 +344,8 @@ _XcursorReadFileHeader(XcursorFile *file)
} }
static bool static bool
_XcursorSeekToToc(XcursorFile *file, _XcursorSeekToToc(struct xcursor_file *file,
XcursorFileHeader *fileHeader, struct xcursor_file_header *fileHeader,
int toc) int toc)
{ {
if (!file || !fileHeader || if (!file || !fileHeader ||
@ -357,10 +355,10 @@ _XcursorSeekToToc(XcursorFile *file,
} }
static bool static bool
_XcursorFileReadChunkHeader(XcursorFile *file, _XcursorFileReadChunkHeader(struct xcursor_file *file,
XcursorFileHeader *fileHeader, struct xcursor_file_header *fileHeader,
int toc, int toc,
XcursorChunkHeader *chunkHeader) struct xcursor_chunk_header *chunkHeader)
{ {
if (!file || !fileHeader || !chunkHeader) if (!file || !fileHeader || !chunkHeader)
return false; return false;
@ -384,7 +382,7 @@ _XcursorFileReadChunkHeader(XcursorFile *file,
#define dist(a,b) ((a) > (b) ? (a) - (b) : (b) - (a)) #define dist(a,b) ((a) > (b) ? (a) - (b) : (b) - (a))
static uint32_t static uint32_t
_XcursorFindBestSize(XcursorFileHeader *fileHeader, _XcursorFindBestSize(struct xcursor_file_header *fileHeader,
uint32_t size, uint32_t size,
int *nsizesp) int *nsizesp)
{ {
@ -412,7 +410,7 @@ _XcursorFindBestSize(XcursorFileHeader *fileHeader,
} }
static int static int
_XcursorFindImageToc(XcursorFileHeader *fileHeader, _XcursorFindImageToc(struct xcursor_file_header *fileHeader,
uint32_t size, uint32_t size,
int count) int count)
{ {
@ -437,14 +435,14 @@ _XcursorFindImageToc(XcursorFileHeader *fileHeader,
return toc; return toc;
} }
static XcursorImage * static struct xcursor_image *
_XcursorReadImage(XcursorFile *file, _XcursorReadImage(struct xcursor_file *file,
XcursorFileHeader *fileHeader, struct xcursor_file_header *fileHeader,
int toc) int toc)
{ {
XcursorChunkHeader chunkHeader; struct xcursor_chunk_header chunkHeader;
XcursorImage head; struct xcursor_image head;
XcursorImage *image; struct xcursor_image *image;
int n; int n;
uint32_t *p; uint32_t *p;
@ -494,13 +492,13 @@ _XcursorReadImage(XcursorFile *file,
return image; return image;
} }
static XcursorImages * static struct xcursor_images *
XcursorXcFileLoadImages(XcursorFile *file, int size) XcursorXcFileLoadImages(struct xcursor_file *file, int size)
{ {
XcursorFileHeader *fileHeader; struct xcursor_file_header *fileHeader;
uint32_t bestSize; uint32_t bestSize;
int nsize; int nsize;
XcursorImages *images; struct xcursor_images *images;
int n; int n;
int toc; int toc;
@ -538,28 +536,28 @@ XcursorXcFileLoadImages(XcursorFile *file, int size)
} }
static int static int
_XcursorStdioFileRead(XcursorFile *file, unsigned char *buf, int len) _XcursorStdioFileRead(struct xcursor_file *file, unsigned char *buf, int len)
{ {
FILE *f = file->closure; FILE *f = file->closure;
return fread(buf, 1, len, f); return fread(buf, 1, len, f);
} }
static int static int
_XcursorStdioFileWrite(XcursorFile *file, unsigned char *buf, int len) _XcursorStdioFileWrite(struct xcursor_file *file, unsigned char *buf, int len)
{ {
FILE *f = file->closure; FILE *f = file->closure;
return fwrite(buf, 1, len, f); return fwrite(buf, 1, len, f);
} }
static int static int
_XcursorStdioFileSeek(XcursorFile *file, long offset, int whence) _XcursorStdioFileSeek(struct xcursor_file *file, long offset, int whence)
{ {
FILE *f = file->closure; FILE *f = file->closure;
return fseek(f, offset, whence); return fseek(f, offset, whence);
} }
static void static void
_XcursorStdioFileInitialize(FILE *stdfile, XcursorFile *file) _XcursorStdioFileInitialize(FILE *stdfile, struct xcursor_file *file)
{ {
file->closure = stdfile; file->closure = stdfile;
file->read = _XcursorStdioFileRead; file->read = _XcursorStdioFileRead;
@ -567,10 +565,10 @@ _XcursorStdioFileInitialize(FILE *stdfile, XcursorFile *file)
file->seek = _XcursorStdioFileSeek; file->seek = _XcursorStdioFileSeek;
} }
static XcursorImages * static struct xcursor_images *
XcursorFileLoadImages(FILE *file, int size) XcursorFileLoadImages(FILE *file, int size)
{ {
XcursorFile f; struct xcursor_file f;
if (!file) if (!file)
return NULL; return NULL;
@ -784,14 +782,14 @@ _XcursorThemeInherits(const char *full)
static void static void
load_all_cursors_from_dir(const char *path, int size, load_all_cursors_from_dir(const char *path, int size,
void (*load_callback)(XcursorImages *, void *), void (*load_callback)(struct xcursor_images *, void *),
void *user_data) void *user_data)
{ {
FILE *f; FILE *f;
DIR *dir = opendir(path); DIR *dir = opendir(path);
struct dirent *ent; struct dirent *ent;
char *full; char *full;
XcursorImages *images; struct xcursor_images *images;
if (!dir) if (!dir)
return; return;
@ -830,25 +828,25 @@ load_all_cursors_from_dir(const char *path, int size,
/** Load all the cursor of a theme /** Load all the cursor of a theme
* *
* This function loads all the cursor images of a given theme and its * This function loads all the cursor images of a given theme and its
* inherited themes. Each cursor is loaded into an XcursorImages object * inherited themes. Each cursor is loaded into an struct xcursor_images object
* which is passed to the caller's load callback. If a cursor appears * which is passed to the caller's load callback. If a cursor appears
* more than once across all the inherited themes, the load callback * more than once across all the inherited themes, the load callback
* will be called multiple times, with possibly different XcursorImages * will be called multiple times, with possibly different struct xcursor_images
* object which have the same name. The user is expected to destroy the * object which have the same name. The user is expected to destroy the
* XcursorImages objects passed to the callback with * struct xcursor_images objects passed to the callback with
* XcursorImagesDestroy(). * XcursorImagesDestroy().
* *
* \param theme The name of theme that should be loaded * \param theme The name of theme that should be loaded
* \param size The desired size of the cursor images * \param size The desired size of the cursor images
* \param load_callback A callback function that will be called * \param load_callback A callback function that will be called
* for each cursor loaded. The first parameter is the XcursorImages * for each cursor loaded. The first parameter is the struct xcursor_images
* object representing the loaded cursor and the second is a pointer * object representing the loaded cursor and the second is a pointer
* to data provided by the user. * to data provided by the user.
* \param user_data The data that should be passed to the load callback * \param user_data The data that should be passed to the load callback
*/ */
void void
xcursor_load_theme(const char *theme, int size, xcursor_load_theme(const char *theme, int size,
void (*load_callback)(XcursorImages *, void *), void (*load_callback)(struct xcursor_images *, void *),
void *user_data) void *user_data)
{ {
char *full, *dir; char *full, *dir;

View file

@ -28,7 +28,7 @@
#include <stdint.h> #include <stdint.h>
typedef struct _XcursorImage { struct xcursor_image {
uint32_t version; /* version of the image data */ uint32_t version; /* version of the image data */
uint32_t size; /* nominal size for matching */ uint32_t size; /* nominal size for matching */
uint32_t width; /* actual width */ uint32_t width; /* actual width */
@ -37,22 +37,22 @@ typedef struct _XcursorImage {
uint32_t yhot; /* hot spot y (must be inside image) */ uint32_t yhot; /* hot spot y (must be inside image) */
uint32_t delay; /* animation delay to next frame (ms) */ uint32_t delay; /* animation delay to next frame (ms) */
uint32_t *pixels; /* pointer to pixels */ uint32_t *pixels; /* pointer to pixels */
} XcursorImage; };
/* /*
* Other data structures exposed by the library API * Other data structures exposed by the library API
*/ */
typedef struct _XcursorImages { struct xcursor_images {
int nimage; /* number of images */ int nimage; /* number of images */
XcursorImage **images; /* array of XcursorImage pointers */ struct xcursor_image **images; /* array of XcursorImage pointers */
char *name; /* name used to load images */ char *name; /* name used to load images */
} XcursorImages; };
void void
XcursorImagesDestroy(XcursorImages *images); XcursorImagesDestroy(struct xcursor_images *images);
void void
xcursor_load_theme(const char *theme, int size, xcursor_load_theme(const char *theme, int size,
void (*load_callback)(XcursorImages *, void *), void (*load_callback)(struct xcursor_images *, void *),
void *user_data); void *user_data);
#endif #endif