successfully queries the server for atoms and extensions
authorDana Jansens <danakj@orodu.net>
Tue, 4 Mar 2008 20:54:00 +0000 (15:54 -0500)
committerDana Jansens <danakj@orodu.net>
Tue, 4 Mar 2008 21:06:25 +0000 (16:06 -0500)
dcompmgr.c
display.c

index 175b522..1c4a5f9 100644 (file)
@@ -71,6 +71,27 @@ main(int argc, char **argv)
         return 1;
     }
 
+    if (!dpy->composite.present) {
+        printf(_("no composite extension present on the display\n"));
+        display_unref(dpy);
+        return 1;
+    }
+    if (!dpy->xfixes.present) {
+        printf(_("no xfixes extension present on the display\n"));
+        display_unref(dpy);
+        return 1;
+    }
+    if (!dpy->damage.present) {
+        printf(_("no damage extension present on the display\n"));
+        display_unref(dpy);
+        return 1;
+    }
+    if (!dpy->render.present) {
+        printf(_("no render extension present on the display\n"));
+        display_unref(dpy);
+        return 1;
+    }
+
     nscreens = all_screens(dpy, &screens);
     if (nscreens < 1) {
         printf(_("found no screens to run on\n"));
index c937103..1bc3d80 100644 (file)
--- a/display.c
+++ b/display.c
@@ -8,41 +8,66 @@
 #include <xcb/xfixes.h>
 #include <xcb/composite.h>
 
-typedef xcb_void_cookie_t
-(*query_version_func_t)(xcb_connection_t *c,
-                        uint32_t major,
-                        uint32_t minor);
-
-typedef struct {
-    d_display_ext_t      *ext;
-    xcb_extension_t      *xcb;
-    query_version_func_t  ver;
-    int                   major;
-    int                   minor;
-    xcb_void_cookie_t     ck;
-} d_extension_query_t;
-
 typedef struct {
     xcb_atom_t               *atom;
     const char               *name;
     xcb_intern_atom_cookie_t  ck;
 } d_atom_query_t;
 
-static void
-query_extension(d_display_t *dpy, d_extension_query_t *q)
-{
-    const xcb_query_extension_reply_t *rep;
+#define setup_extension(name) \
+    xcb_##name##_query_version_cookie_t ck_##name;
 
-    xcb_prefetch_extension_data(dpy->conn, q->xcb);
-    rep = xcb_get_extension_data(dpy->conn, q->xcb);
-    q->ext->present = rep && rep->present;
-    q->ext->error   = rep && rep->first_error;
-    q->ext->event   = rep && rep->first_event;
-    q->ext->opcode  = rep && rep->major_opcode;
+#define find_extension_xfixes(dpy) &dpy->xfixes;
+#define find_extension_render(dpy) &dpy->render;
+#define find_extension_composite(dpy) &dpy->composite;
+#define find_extension_damage(dpy) &dpy->damage;
 
-    if (q->ext->present) {
-        q->ck = q->ver(dpy->conn, q->major, q->minor);
-    }
+#define version_extension_xfixes \
+  XCB_XFIXES_MAJOR_VERSION, XCB_XFIXES_MAJOR_VERSION
+#define version_extension_render \
+  XCB_RENDER_MAJOR_VERSION, XCB_RENDER_MAJOR_VERSION
+#define version_extension_composite \
+  XCB_COMPOSITE_MAJOR_VERSION, XCB_COMPOSITE_MAJOR_VERSION
+#define version_extension_damage \
+  XCB_DAMAGE_MAJOR_VERSION, XCB_DAMAGE_MAJOR_VERSION
+
+#define query_extension(dpy, name) \
+{ \
+    const xcb_query_extension_reply_t *rep;          \
+    d_display_ext_t *ext; \
+\
+    xcb_prefetch_extension_data(dpy->conn, &xcb_##name##_id);  \
+    rep = xcb_get_extension_data(dpy->conn, &xcb_##name##_id); \
+\
+    ext = find_extension_##name(dpy) \
+    ext->present = rep && rep->present;       \
+    ext->error   = rep && rep->first_error;   \
+    ext->event   = rep && rep->first_event;   \
+    ext->opcode  = rep && rep->major_opcode;  \
+\
+    if (ext->present) \
+        ck_##name = xcb_##name##_query_version(dpy->conn, \
+                                               version_extension_##name); \
+}
+
+#define reply_extension(dpy, name) \
+{ \
+    xcb_##name##_query_version_reply_t *rep; \
+    d_display_ext_t *ext; \
+\
+    ext = find_extension_##name(dpy) \
+    if (ext->present) { \
+        rep = xcb_##name##_query_version_reply(dpy->conn, ck_##name, NULL); \
+        if (rep) { \
+            ext->major_version = rep->major_version; \
+            ext->minor_version = rep->minor_version; \
+            free(rep); \
+        } \
+        else { \
+            printf("error querying the %s extension's version\n", "##name##");\
+            ext->present = FALSE; \
+        } \
+    } \
 }
 
 static void
@@ -52,39 +77,23 @@ query_atom(d_display_t *dpy, d_atom_query_t *q)
 }
 
 static void
+reply_atom(d_display_t *dpy, d_atom_query_t *q)
+{
+    xcb_intern_atom_reply_t *rep;
+    rep = xcb_intern_atom_reply(dpy->conn, q->ck, NULL);
+    if (rep) {
+        *q->atom = rep->atom;
+        free(rep);
+    }
+    else {
+        printf("unable to query atom %s\n", q->name);
+        *q->atom = 0;
+    }
+}
+
+static void
 query_statics(d_display_t *dpy)
 {
-    d_extension_query_t extensions[] = {
-        {
-            .ext = &dpy->xfixes,
-            .xcb = &xcb_xfixes_id,
-            .ver = (query_version_func_t)xcb_xfixes_query_version,
-            .major = XCB_XFIXES_MAJOR_VERSION,
-            .minor = XCB_XFIXES_MINOR_VERSION
-        },
-        {
-            .ext = &dpy->render,
-            .xcb = &xcb_render_id,
-            .ver = (query_version_func_t)xcb_render_query_version,
-            .major = XCB_RENDER_MAJOR_VERSION,
-            .minor = XCB_RENDER_MINOR_VERSION
-        },
-        {
-            .ext = &dpy->damage,
-            .xcb = &xcb_damage_id,
-            .ver = (query_version_func_t)xcb_damage_query_version,
-            .major = XCB_DAMAGE_MAJOR_VERSION,
-            .minor = XCB_DAMAGE_MINOR_VERSION
-        },
-        {
-            .ext = &dpy->composite,
-            .xcb = &xcb_composite_id,
-            .ver = (query_version_func_t)xcb_composite_query_version,
-            .major = XCB_COMPOSITE_MAJOR_VERSION,
-            .minor = XCB_COMPOSITE_MINOR_VERSION
-        },
-        { .ext = NULL }
-    };
     d_atom_query_t atoms[] = {
         { .atom = &dpy->a.atom,
           .name = "ATOM" },
@@ -127,12 +136,28 @@ query_statics(d_display_t *dpy)
         { .atom = NULL }
     };
     int i;
+    setup_extension(xfixes);
+    setup_extension(render);
+    setup_extension(composite);
+    setup_extension(damage);
+
+    query_extension(dpy, xfixes);
+    query_extension(dpy, render);
+    query_extension(dpy, composite);
+    query_extension(dpy, damage);
 
-    for (i = 0; extensions[i].ext != NULL; ++i)
-        query_extension(dpy, &extensions[i]);
     for (i = 0; atoms[i].atom != NULL; ++i)
         query_atom(dpy, &atoms[i]);
 
+    xcb_flush(dpy->conn);
+
+    reply_extension(dpy, xfixes);
+    reply_extension(dpy, render);
+    reply_extension(dpy, composite);
+    reply_extension(dpy, damage);
+
+    for (i = 0; atoms[i].atom != NULL; ++i)
+        reply_atom(dpy, &atoms[i]);
 }
 
 d_display_t*