From bc5a4cf5fcc70e30028ff8fa91dca075896b2764 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 13 Dec 2023 20:17:13 +0100 Subject: Include all libxcb utils (wm, util, image, errors, cursor) --- depends/libxcb-util/xcb/atoms.c | 87 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 depends/libxcb-util/xcb/atoms.c (limited to 'depends/libxcb-util/xcb/atoms.c') diff --git a/depends/libxcb-util/xcb/atoms.c b/depends/libxcb-util/xcb/atoms.c new file mode 100644 index 0000000..fe7fe94 --- /dev/null +++ b/depends/libxcb-util/xcb/atoms.c @@ -0,0 +1,87 @@ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* Rely on vasprintf (GNU extension) instead of vsnprintf if + possible... */ +#define _GNU_SOURCE +#include + +#include +#include +#include +#include "xcb_atom.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with older compilers. */ +#endif + +#if __has_attribute(__format__) \ + || defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 203) +__attribute__((__format__(__printf__,1,2))) +#endif +static char *makename(const char *fmt, ...) +{ + char *ret; + int n; + va_list ap; + +#ifndef HAVE_VASPRINTF + char *np; + int size = 64; + + /* First allocate 'size' bytes, should be enough usually */ + if((ret = malloc(size)) == NULL) + return NULL; + + while(1) + { + va_start(ap, fmt); + n = vsnprintf(ret, size, fmt, ap); + va_end(ap); + + if(n < 0) + return NULL; + + if(n < size) + return ret; + + size = n + 1; + if((np = realloc(ret, size)) == NULL) + { + free(ret); + return NULL; + } + + ret = np; + } +#else + va_start(ap, fmt); + n = vasprintf(&ret, fmt, ap); + va_end(ap); + + if(n < 0) + return NULL; + + return ret; +#endif +} + +char *xcb_atom_name_by_screen(const char *base, uint8_t screen) +{ + return makename("%s_S%u", base, screen); +} + +char *xcb_atom_name_by_resource(const char *base, uint32_t resource) +{ + return makename("%s_R%08X", base, resource); +} + +char *xcb_atom_name_unique(const char *base, uint32_t id) +{ + if(base) + return makename("%s_U%u", base, id); + else + return makename("U%u", id); +} -- cgit v1.2.3