redirect rendering and get the composite overlay window
[dana/dcompmgr.git] / dcompmgr.c
1 #include "screen.h"
2 #include "window.h"
3 #include "display.h"
4 #include "gettext.h"
5
6 #include <glib.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <xcb/xcb.h>
11
12 typedef struct {
13     int foo;
14 } d_options_t;
15
16 static
17 void read_options(int argc, char **argv, d_options_t *opts)
18 {
19     opts->foo = argc && argv;
20 }
21
22 int
23 main(int argc, char **argv)
24 {
25     d_display_t         *dpy;
26     xcb_generic_event_t *ev;
27     d_options_t          opts;
28
29     read_options(argc, argv, &opts);
30
31     dpy = display_open(NULL);
32     if (!dpy) {
33         printf(_("Unable to connect to display\n"));
34         return 1;
35     }
36
37     if (!dpy->composite.present) {
38         printf(_("no composite extension present on the display\n"));
39         display_unref(dpy);
40         return 1;
41     }
42     if (!dpy->xfixes.present) {
43         printf(_("no xfixes extension present on the display\n"));
44         display_unref(dpy);
45         return 1;
46     }
47     if (!dpy->damage.present) {
48         printf(_("no damage extension present on the display\n"));
49         display_unref(dpy);
50         return 1;
51     }
52     if (!dpy->render.present) {
53         printf(_("no render extension present on the display\n"));
54         display_unref(dpy);
55         return 1;
56     }
57     if (dpy->composite.major_version <= 0 && dpy->composite.minor_version < 3)
58     {
59         printf(_("composite extension does not support the overlay window"));
60         display_unref(dpy);
61         return 1;
62     }
63
64     if (!display_claim_screens(dpy)) {
65         printf(_("found no screens to run on\n"));
66         display_unref(dpy);
67         return 0;
68     }
69
70     while ((ev = xcb_wait_for_event(dpy->conn))) {
71         printf("event %d\n", ev->response_type);
72
73         if (!ev->response_type) {
74             display_error(dpy, (xcb_generic_error_t*)ev);
75             free(ev);
76             continue;
77         }
78
79         switch (ev->response_type) {
80         case XCB_CREATE_NOTIFY:
81         {
82             xcb_create_notify_event_t *cev;
83             d_screen_t *sc;
84
85             cev = (xcb_create_notify_event_t*)ev;
86             sc = display_screen_from_root(dpy, cev->parent);
87             if (!sc) break;
88             screen_add_window(sc, cev->window);
89             break;
90         }
91         case XCB_DESTROY_NOTIFY:
92         {
93             xcb_destroy_notify_event_t *dev;
94             d_screen_t *sc;
95             d_window_t *w;
96
97             dev = (xcb_destroy_notify_event_t*)ev;
98             sc = display_screen_from_root(dpy, dev->event);
99             if (!sc) break;
100             w = screen_find_window(sc, dev->window);
101             w->hide(w);
102             screen_remove_window(sc, w);
103             break;
104         }
105         case XCB_REPARENT_NOTIFY:
106         {
107             xcb_reparent_notify_event_t *rev;
108             d_screen_t *sc;
109             d_window_t *w;
110
111             rev = (xcb_reparent_notify_event_t*)ev;
112             sc = display_screen_from_root(dpy, rev->event);
113             if (!sc) break;
114             w = screen_find_window(sc, rev->window);
115             if (rev->parent == sc->super.root)
116                 screen_add_window(sc, rev->window);
117             else {
118                 w->hide(w);
119                 screen_remove_window(sc, w);
120             }
121             break;
122         }
123         case XCB_MAP_NOTIFY:
124         {
125             xcb_map_notify_event_t *mev;
126             d_screen_t *sc;
127             d_window_t *w;
128
129             mev = (xcb_map_notify_event_t*)ev;
130             sc = display_screen_from_root(dpy, mev->event);
131             if (!sc) break;
132             w = screen_find_window(sc, mev->window);
133             window_show(w);
134             break;
135         }
136         case XCB_UNMAP_NOTIFY:
137         {
138             xcb_unmap_notify_event_t *mev;
139             d_screen_t *sc;
140             d_window_t *w;
141
142             mev = (xcb_unmap_notify_event_t*)ev;
143             sc = display_screen_from_root(dpy, mev->event);
144             if (!sc) break;
145             w = screen_find_window(sc, mev->window);
146             window_hide(w);
147             break;
148         }
149         default:
150             break;
151         }
152         free(ev);
153     }
154
155     display_unref(dpy);
156     return 0;
157 }