summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaud Fontaine <arnau@debian.org>2008-09-11 19:06:57 +0200
committerArnaud Fontaine <arnau@debian.org>2010-11-14 19:50:13 +0900
commit5f8dfed11b3fb485f952ab42971d05cf75a305b8 (patch)
tree13afb156a287f7cd1fc1b3fe7d8202d80b971b88
parent8a4dfb917f12b4e3ef36d135081379927c1ca1db (diff)
[atom] Move '*discriminated_atom*' functions from icccm to atom
-rw-r--r--atom/atoms.gperf.m474
-rw-r--r--atom/xcb_atom.h.m44
-rw-r--r--configure.ac1
3 files changed, 79 insertions, 0 deletions
diff --git a/atom/atoms.gperf.m4 b/atom/atoms.gperf.m4
index ec733de..b51122c 100644
--- a/atom/atoms.gperf.m4
+++ b/atom/atoms.gperf.m4
@@ -1,6 +1,15 @@
%{
+
+/* Rely on vasprintf (GNU extension) instead of vsnprintf if
+ possible... */
+#ifdef HAVE_VASPRINTF
+#define _GNU_SOURCE
+#include <stdio.h>
+#endif
+
#include <xcb/xcb.h>
#include <stdlib.h>
+#include <stdarg.h>
#include "xcb_atom.h"
define(`COUNT', 0)dnl
@@ -113,3 +122,68 @@ int get_atom_name(xcb_connection_t *c, xcb_atom_t atom, const char **namep, int
free(atomr);
return 1;
}
+
+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%lu", base, id);
+ else
+ return makename("U%lu", id);
+}
diff --git a/atom/xcb_atom.h.m4 b/atom/xcb_atom.h.m4
index 6ea81d3..48e874f 100644
--- a/atom/xcb_atom.h.m4
+++ b/atom/xcb_atom.h.m4
@@ -20,6 +20,10 @@ xcb_atom_t intern_atom_fast_reply(xcb_connection_t *c, intern_atom_fast_cookie_t
const char *get_atom_name_predefined(xcb_atom_t atom);
int get_atom_name(xcb_connection_t *c, xcb_atom_t atom, const char **namep, int *lengthp);
+char *xcb_atom_name_by_screen(const char *base, uint8_t screen);
+char *xcb_atom_name_by_resource(const char *base, uint32_t resource);
+char *xcb_atom_name_unique(const char *base, uint32_t id);
+
define(`DO', `extern const xcb_atom_t $1;')dnl
include(atomlist.m4)`'dnl
diff --git a/configure.ac b/configure.ac
index 73e6fbb..9188350 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,6 +20,7 @@ else
fi
fi
AC_SUBST(CWARNFLAGS)
+AC_CHECK_FUNCS_ONCE(vasprintf)
xcbincludedir='${includedir}/xcb'
AC_SUBST(xcbincludedir)