redirect rendering and get the composite overlay window
authorDana Jansens <danakj@orodu.net>
Tue, 4 Mar 2008 21:59:01 +0000 (16:59 -0500)
committerDana Jansens <danakj@orodu.net>
Tue, 4 Mar 2008 22:12:03 +0000 (17:12 -0500)
Makefile
screen.c
screen.h

index a5b283f..08bf416 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,3 +10,8 @@ dcompmgr: $(objs)
 
 %.o: %.c $(headers)
        $(CC) -c -o $@ $< $(CFLAGS)
+
+clean:
+       rm -f dcompmgr *.o
+
+VIRTUAL = clean
index dd637d4..dfad6e4 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -13,7 +13,7 @@
 #define SELECTION_MASK (XCB_EVENT_MASK_STRUCTURE_NOTIFY | \
                         XCB_EVENT_MASK_PROPERTY_CHANGE)
 
-static void screen_init(d_screen_t *sc);
+static gboolean screen_init(d_screen_t *sc);
 static xcb_timestamp_t screen_timestamp(d_screen_t *sc);
 
 gboolean
@@ -41,6 +41,8 @@ screen_register(struct d_display *dpy, int num, d_screen_t *sc)
     arep = xcb_intern_atom_reply(sc->dpy->conn, ack, NULL);
     g_free(name);
 
+    xcb_grab_server(sc->dpy->conn);
+
     sck = xcb_get_selection_owner(sc->dpy->conn, arep->atom);
     srep = xcb_get_selection_owner_reply(sc->dpy->conn, sck, NULL);
     taken = !!srep->owner;
@@ -58,22 +60,20 @@ screen_register(struct d_display *dpy, int num, d_screen_t *sc)
 
         time = screen_timestamp(sc);
 
-        xcb_grab_server(sc->dpy->conn);
         xcb_set_selection_owner(sc->dpy->conn, w, arep->atom, time);
         sck = xcb_get_selection_owner(sc->dpy->conn, arep->atom);
         srep = xcb_get_selection_owner_reply(sc->dpy->conn, sck, NULL);
         taken = srep->owner == w;
-        if (taken) {
-            screen_init(sc);
+        if (taken && screen_init(sc))
             ret = TRUE;
-        }
         else {
             xcb_destroy_window(sc->dpy->conn, w);
             ret = FALSE;
         }
-        xcb_ungrab_server(sc->dpy->conn);
-        xcb_flush(sc->dpy->conn);
     }
+
+    xcb_ungrab_server(sc->dpy->conn);
+    xcb_flush(sc->dpy->conn);
     return ret;
 }
 
@@ -83,16 +83,43 @@ window_hash(xcb_window_t *w) { return *w; }
 static gboolean
 window_compare(xcb_window_t *w1, xcb_window_t *w2) { return *w1 == *w2; }
 
-static void
+static gboolean
 screen_init(d_screen_t *sc)
 {
     uint32_t mask;
+    xcb_generic_error_t *err;
+    xcb_void_cookie_t redir_ck;
+    xcb_composite_get_overlay_window_cookie_t overlay_ck;
+    xcb_composite_get_overlay_window_reply_t *overlay_rep;
 
     sc->winhash = g_hash_table_new((GHashFunc)window_hash,
                                    (GCompareFunc)window_compare);
 
-//    xcb_composite_redirect_subwindows(sc->dpy->conn, sc->super.root,
-//                                      XCB_COMPOSITE_REDIRECT_MANUAL);
+    redir_ck =
+        xcb_composite_redirect_subwindows(sc->dpy->conn, sc->super.root,
+                                          XCB_COMPOSITE_REDIRECT_MANUAL);
+
+    overlay_ck = xcb_composite_get_overlay_window(sc->dpy->conn,
+                                                  sc->super.root);
+
+    /* check that the redirect worked */
+    err = xcb_request_check(sc->dpy->conn, redir_ck);
+    if (err) {
+        printf(_("unable to redirect rendering, another composite manager must be running"));
+        free(err);
+        return FALSE;
+    }
+
+    /* get the overlay window reply */
+    overlay_rep = xcb_composite_get_overlay_window_reply(sc->dpy->conn,
+                                                         overlay_ck,
+                                                         NULL);
+    if (!overlay_rep) {
+        printf(_("unable to get the composite overlay window\n"));
+        return FALSE;
+    }
+    sc->overlay = overlay_rep->overlay_win;
+    free(overlay_rep);
 
     mask = SELECTION_MASK;
     xcb_change_window_attributes(sc->dpy->conn, sc->selwin,
@@ -100,6 +127,7 @@ screen_init(d_screen_t *sc)
     mask = ROOT_MASK;
     xcb_change_window_attributes(sc->dpy->conn, sc->super.root,
                                  XCB_CW_EVENT_MASK, &mask);
+    return TRUE;
 }
 
 void
index 0dbf0b9..5317599 100644 (file)
--- a/screen.h
+++ b/screen.h
@@ -16,6 +16,8 @@ typedef struct d_screen {
     xcb_window_t      selwin;  /* for the selection */
     xcb_atom_t        selatom; /* ditto.. */
 
+    xcb_window_t      overlay;
+
     GHashTable       *winhash;
 } d_screen_t;