add support for the root pixmap properties
[dana/dcompmgr.git] / screen.c
index b16373a..e02e4a6 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -14,7 +14,8 @@
 #include <xcb/xfixes.h>
 
 #define ROOT_MASK      (XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | \
-                        XCB_EVENT_MASK_STRUCTURE_NOTIFY)
+                        XCB_EVENT_MASK_STRUCTURE_NOTIFY | \
+                        XCB_EVENT_MASK_PROPERTY_CHANGE)
 
 #define SELECTION_MASK (XCB_EVENT_MASK_STRUCTURE_NOTIFY | \
                         XCB_EVENT_MASK_PROPERTY_CHANGE)
@@ -65,6 +66,9 @@ screen_unref(d_screen_t *sc)
     if (sc && --sc->ref == 0) {
         d_list_it_t *it, *next;
 
+        /* clean up pending requests */
+        screen_get_root_pixmap(sc);
+
         g_hash_table_unref(sc->winhash);
         for (it = list_top(sc->stacking); it; it = next) {
             next = it->next;
@@ -205,9 +209,41 @@ screen_init(d_screen_t *sc)
     xcb_change_window_attributes(sc->dpy->conn, sc->super.root,
                                  XCB_CW_EVENT_MASK, &mask);
 
+    screen_update_root_pixmap(sc);
+
     return TRUE;
 }
 
+void
+screen_update_root_pixmap(d_screen_t *sc)
+{
+    if (sc->root_pixmap_waiting) {
+        xcb_get_property_reply_t *rep;
+        rep = xcb_get_property_reply(sc->dpy->conn, sc->root_pixmap_ck[0],
+                                     NULL);
+        if (rep) free(rep);
+        rep = xcb_get_property_reply(sc->dpy->conn, sc->root_pixmap_ck[1],
+                                     NULL);
+        if (rep) free(rep);
+        rep = xcb_get_property_reply(sc->dpy->conn, sc->root_pixmap_ck[2],
+                                     NULL);
+        if (rep) free(rep);
+    }
+    sc->root_pixmap_ck[0] =
+        xcb_get_property_unchecked(sc->dpy->conn, FALSE,
+                                   sc->super.root, sc->dpy->a.xrootpmap_id,
+                                   sc->dpy->a.pixmap, 0, 1);
+    sc->root_pixmap_ck[1] =
+        xcb_get_property_unchecked(sc->dpy->conn, FALSE,
+                                   sc->super.root, sc->dpy->a.esetroot_pmap_id,
+                                   sc->dpy->a.pixmap, 0, 1);
+    sc->root_pixmap_ck[2] =
+        xcb_get_property_unchecked(sc->dpy->conn, FALSE,
+                                   sc->super.root, sc->dpy->a.xsetroot_id,
+                                   sc->dpy->a.pixmap, 0, 1);
+    sc->root_pixmap_waiting = TRUE;
+}
+
 d_window_t*
 screen_add_window(d_screen_t *sc, xcb_window_t wid)
 {
@@ -334,6 +370,7 @@ screen_setup_default_functions(d_screen_t *sc)
     sc->window_become_zombie = window_become_zombie;
     sc->window_move = window_move;
     sc->window_resize = window_resize;
+    sc->screen_root_pixmap_changed = screen_update_root_pixmap;
 }
 
 void
@@ -360,3 +397,26 @@ screen_refresh(d_screen_t *sc)
     sc->need_repaint = TRUE;
     //printf("*** need repaint! ***\n");
 }
+
+xcb_pixmap_t
+screen_get_root_pixmap(d_screen_t *sc)
+{
+    if (sc->root_pixmap_waiting) {
+        xcb_get_property_reply_t *rep;
+        int i;
+
+        sc->root_pixmap = XCB_NONE;
+        for (i = 2; i >= 0; --i) {
+            rep = xcb_get_property_reply(sc->dpy->conn, sc->root_pixmap_ck[i],
+                                         NULL);
+            if (rep) {
+                if (rep->type == sc->dpy->a.pixmap && rep->length >= 1) {
+                    sc->root_pixmap =
+                        ((xcb_pixmap_t*)xcb_get_property_value(rep))[0];
+                }
+                free(rep);
+            }
+        }
+    }
+    return sc->root_pixmap;
+}