]> icculus.org git repositories - dana/openbox.git/blob - loco/loco.c
ad8446572864fc88a27999d1236bf764e3b1b657
[dana/openbox.git] / loco / loco.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    loco.c for the Openbox window manager
4    Copyright (c) 2008        Derek Foreman
5    Copyright (c) 2008        Dana Jansens
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include <stdio.h>
21 #include "obt/mainloop.h"
22 #include "obt/display.h"
23 #include "obt/mainloop.h"
24 #include "obt/prop.h"
25 #include <glib.h>
26 #include <GL/glx.h>
27 #include <GL/glext.h>
28 #include <GL/glxext.h>
29 #include <GL/glxtokens.h>
30 /*
31 <dana> you want CreateNotify, DestroyNotify, MapNotify, UnmapNotify, and
32           ConfigureNotify
33           <dana> and then xdamage or whatever
34
35 */
36
37 #define glError()                                      \
38 {                                                      \
39     /*const GLchar *err_file = strrchr(err_path, '/');*/ \
40     GLenum        gl_error = glGetError();             \
41                                                        \
42     /*++err_file;*/                                        \
43                                                        \
44     for (; (gl_error); gl_error = glGetError())        \
45       fprintf(stderr, "%s: %d caught at line %u\n",    \
46               __FUNCTION__, gl_error, __LINE__);       \
47               /*(const GLchar*)gluErrorString(gl_error)*/ \
48 }
49
50
51 #define MAX_DEPTH 32
52 #define REFRESH_RATE (G_USEC_PER_SEC/60)
53
54 typedef struct {
55     Window id;
56     gint x, y, w, h;
57     gint depth;
58     gboolean input_only;
59     gboolean visible;
60     gint type; /* XXX make this an enum */
61     GLuint texname;
62     Damage damage;
63     GLXPixmap glpixmap;
64     gboolean damaged;
65 } LocoWindow;
66
67 typedef struct _LocoList {
68     struct _LocoList *next;
69     struct _LocoList *prev;
70     LocoWindow *window;
71 } LocoList;
72
73 static Window      loco_root;
74 static Window      loco_overlay;
75 /* Maps X Window ID -> LocoWindow* */
76 static GHashTable *window_map;
77 /* Maps X Window ID -> LocoList* which is in the stacking_top/bottom list */
78 static GHashTable *stacking_map;
79 /* From top to bottom */
80 static LocoList   *stacking_top;
81 static LocoList   *stacking_bottom;
82 static VisualID visualIDs[MAX_DEPTH + 1];
83 static XVisualInfo *glxPixmapVisuals[MAX_DEPTH + 1];
84 static int loco_screen_num;
85 static gboolean full_redraw_required;
86 static gboolean redraw_required;
87
88 typedef void (*BindEXTFunc)(Display *, GLXDrawable, int, const int *);
89 typedef void (*ReleaseEXTFunc)(Display *, GLXDrawable, int);
90
91 BindEXTFunc    BindTexImageEXT;
92 ReleaseEXTFunc ReleaseTexImageEXT;
93
94 static void show_window(LocoWindow *lw);
95 static void remove_window(LocoWindow *lw);
96
97 /*
98 static void print_stacking()
99 {
100     LocoList *it;
101
102     for (it = stacking_top; it; it = it->next) {
103         printf("0x%lx\n", it->window->id);
104     }
105 }
106 */
107
108 static glong timecompare(GTimeVal *a, GTimeVal *b)
109 {
110     glong r;
111     if ((r = a->tv_sec - b->tv_sec)) return r;
112     return a->tv_usec - b->tv_usec;
113 }
114
115 static void timeadd(GTimeVal *t, glong microseconds)
116 {
117     t->tv_usec += microseconds;
118     while (t->tv_usec >= G_USEC_PER_SEC) {
119         t->tv_usec -= G_USEC_PER_SEC;
120         ++t->tv_sec;
121     }
122     while (t->tv_usec < 0) {
123         t->tv_usec += G_USEC_PER_SEC;
124         --t->tv_sec;
125     }
126 }
127
128 int create_glxpixmap(LocoWindow *lw)
129 {
130     XVisualInfo  *visinfo;
131     Pixmap pixmap;
132     static const int attrs[] =
133         {
134             GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT,
135             None
136         };
137
138     static const int drawable_tfp_attrs[] =
139         {
140             GLX_CONFIG_CAVEAT, GLX_NONE,
141             GLX_DOUBLEBUFFER, False,
142             GLX_DEPTH_SIZE, 0,
143             GLX_RED_SIZE, 1,
144             GLX_GREEN_SIZE, 1,
145             GLX_BLUE_SIZE, 1,
146             GLX_ALPHA_SIZE, 1,
147             GLX_RENDER_TYPE, GLX_RGBA_BIT,
148             GLX_BIND_TO_TEXTURE_RGBA_EXT, True, // additional for tfp
149             None
150         };
151     int count;
152
153     pixmap = XCompositeNameWindowPixmap(obt_display, lw->id);
154     visinfo = glxPixmapVisuals[lw->depth];
155     if (!visinfo) {
156         printf("no visinfo for depth %d\n", lw->depth);
157         return 0;
158     }
159
160     GLXFBConfig fbc;
161     GLXFBConfig *fbconfigs = glXChooseFBConfig(obt_display,
162                                                loco_screen_num,
163                                                drawable_tfp_attrs, &count);
164
165     int i;
166     fbc = 0;
167     for(i = 0; i < count; ++i ) {
168         int value;
169         glXGetFBConfigAttrib(obt_display,
170                              fbconfigs[i], GLX_VISUAL_ID, &value);
171         if(value == (int)visinfo->visualid)
172         {
173             fbc = fbconfigs[i];
174             XFree(fbconfigs);
175         }
176     }
177
178     if (!fbc) {
179         printf("fbconfigless\n");
180         return 0;
181     }
182
183     lw->glpixmap = glXCreatePixmap(obt_display, fbc, pixmap, attrs);
184     return !!lw->glpixmap;
185 }
186
187 int bindPixmapToTexture(LocoWindow *lw)
188 {
189     if (lw->glpixmap != None)
190         return 1; /* already bound */
191
192     if (!create_glxpixmap(lw))
193         return 0; /* horrible failure */
194
195 /*
196     if (screen->queryDrawable (screen->display->display,
197                                texture->pixmap,
198                                GLX_TEXTURE_TARGET_EXT,
199                                &target))
200     {
201         fprintf (stderr, "%s: glXQueryDrawable failed\n", programName);
202
203         glXDestroyGLXPixmap (screen->display->display, texture->pixmap);
204         texture->pixmap = None;
205
206         return FALSE;
207     }
208 */
209
210     glBindTexture(GL_TEXTURE_2D, lw->texname);
211 glError();
212     BindTexImageEXT(obt_display, lw->glpixmap, GLX_FRONT_LEFT_EXT, NULL);
213
214     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
215     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
216
217     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
218     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
219     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
220     return 1;
221 }
222
223 void releasePixmapFromTexture(LocoWindow *lw)
224 {
225     if (lw->glpixmap) {
226         glBindTexture(GL_TEXTURE_2D, lw->texname);
227
228         ReleaseTexImageEXT(obt_display, lw->glpixmap, GLX_FRONT_LEFT_EXT);
229
230         glBindTexture(GL_TEXTURE_2D, 0);
231     }
232 }
233
234 void destroy_glxpixmap(LocoWindow *lw)
235 {
236     if (lw->glpixmap) {
237         releasePixmapFromTexture(lw);
238
239         glXDestroyGLXPixmap(obt_display, lw->glpixmap);
240         lw->glpixmap = None;
241     }
242 }
243
244 static void full_composite(void)
245 {
246     int ret;
247     LocoList *it;
248
249     /* XXX if (full_redraw_required) */
250         glClear(GL_COLOR_BUFFER_BIT);
251
252     for (it = stacking_bottom; it != stacking_top; it = it->prev) {
253         if (it->window->input_only) continue;
254         if (!it->window->visible)   continue;
255         /* XXX if (!full_redraw_required && !it->window->damaged) continue; */
256
257         if (!full_redraw_required) {
258             /* XXX if the window is transparent, then clear the background
259                behind it */
260         }
261
262         glBindTexture(GL_TEXTURE_2D, it->window->texname);
263         ret = bindPixmapToTexture(it->window);
264         glBegin(GL_QUADS);
265         glColor3f(1.0, 1.0, 1.0);
266         glVertex2i(it->window->x, it->window->y);
267         glTexCoord2f(1, 0);
268         glVertex2i(it->window->x + it->window->w, it->window->y);
269         glTexCoord2f(1, 1);
270         glVertex2i(it->window->x + it->window->w,
271                    it->window->y + it->window->h);
272         glTexCoord2f(0, 1);
273         glVertex2i(it->window->x, it->window->y + it->window->h);
274         glTexCoord2f(0, 0);
275         glEnd();
276
277         it->window->damaged = FALSE;
278     }
279     glXSwapBuffers(obt_display, loco_overlay);
280
281     full_redraw_required = redraw_required = FALSE;
282 }
283
284 static LocoList* loco_list_prepend(LocoList **top, LocoList **bottom,
285                                    LocoWindow *window)
286 {
287     LocoList *n = g_new(LocoList, 1);
288     n->window = window;
289
290     n->prev = NULL;
291     n->next = *top;
292     if (n->next) n->next->prev = n;
293
294     *top = n;
295     if (!*bottom) *bottom = n;
296     return n;
297 }
298
299 static void loco_list_delete_link(LocoList **top, LocoList **bottom,
300                                   LocoList *pos)
301 {
302     LocoList *prev = pos->prev;
303     LocoList *next = pos->next;
304
305     if (next)
306         next->prev = prev;
307     if (prev)
308         prev->next = next;
309     if (!next)
310         *bottom = prev;
311     if (!prev)
312         *top = next;
313
314     g_free(pos);
315 }
316
317 static void loco_list_move_before(LocoList **top, LocoList **bottom,
318                                   LocoList *move, LocoList *before)
319 {
320     LocoList *prev, *next;
321
322     /* these won't move it anywhere */
323     if (move == before || move->next == before) return;
324
325     prev = move->prev;
326     next = move->next;
327
328     /* remove it from the list */
329     if (next) next->prev = prev;
330     else      *bottom = prev;
331     if (prev) prev->next = next;
332     else      *top = next;
333
334     /* reinsert it */
335     if (before) {
336         move->next = before;
337         move->prev = before->prev;
338         move->next->prev = move;
339         if (move->prev) move->prev->next = move;
340     }
341     else {
342         /* after the bottom */
343         move->prev = *bottom;
344         move->next = NULL;
345         if (move->prev) move->prev->next = move;
346         *bottom = move;
347     }
348
349     if (!move->prev) *top = move;
350 }
351
352 /* Returns a LocoWindow structure */
353 static LocoWindow* find_window(Window window)
354 {
355     return g_hash_table_lookup(window_map, &window);
356 }
357
358 /* Returns a node from the stacking_top/bottom list */
359 static LocoList* find_stacking(Window window)
360 {
361     return g_hash_table_lookup(stacking_map, &window);
362 }
363
364 static void add_window(Window window)
365 {
366     LocoWindow *lw;
367     LocoList *it;
368     XWindowAttributes attrib;
369
370     printf("add window 0x%lx\n", window);
371
372     if (!XGetWindowAttributes(obt_display, window, &attrib))
373         return;
374
375     lw = g_new0(LocoWindow, 1);
376     lw->id = window;
377     lw->input_only = attrib.class == InputOnly;
378     lw->x = attrib.x;
379     lw->y = attrib.y;
380     lw->w = attrib.width;
381     lw->h = attrib.height;
382     lw->depth = attrib.depth;
383
384     g_hash_table_insert(window_map, &lw->id, lw);
385     /* new windows are at the top */
386     it = loco_list_prepend(&stacking_top, &stacking_bottom, lw);
387     g_hash_table_insert(stacking_map, &lw->id, it);
388
389     if (!lw->input_only) {
390         glGenTextures(1, &lw->texname);
391         //  glTexImage2D(TARGET, 0, GL_RGB, lw->w, lw->h, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
392         lw->damage = XDamageCreate(obt_display, window, XDamageReportNonEmpty);
393     }
394
395     //print_stacking();
396
397     if (attrib.map_state != IsUnmapped)
398         show_window(lw);
399 }
400
401 static void remove_window(LocoWindow *lw)
402 {
403     printf("remove window 0x%lx\n", lw->id);
404
405     LocoList *pos = find_stacking(lw->id);
406     g_assert(pos);
407
408     if (!lw->input_only) {
409         glDeleteTextures(1, &lw->texname);
410                 obt_display_ignore_errors(TRUE);
411                 XDamageDestroy(obt_display, lw->damage);
412         obt_display_ignore_errors(FALSE);
413     }
414
415     loco_list_delete_link(&stacking_top, &stacking_bottom, pos);
416     g_hash_table_remove(stacking_map, &lw->id);
417     g_hash_table_remove(window_map, &lw->id);
418
419     g_free(lw);
420
421     //print_stacking();
422 }
423
424 static void show_window(LocoWindow *lw)
425 {
426     guint32 *type;
427     guint i, ntype;
428
429     lw->visible = TRUE;
430
431     /* get the window's semantic type (for different effects!) */
432     lw->type = 0; /* XXX set this to the default type */
433     if (OBT_PROP_GETA32(lw->id, NET_WM_WINDOW_TYPE, ATOM, &type, &ntype)) {
434         /* use the first value that we know about in the array */
435         for (i = 0; i < ntype; ++i) {
436             /* XXX SET THESE TO AN ENUM'S VALUES */
437             if (type[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_DESKTOP))
438                 lw->type = 1;
439             if (type[i] == OBT_PROP_ATOM(NET_WM_WINDOW_TYPE_MENU))
440                 lw->type = 2;
441             /* XXX there are more TYPES that need to be added to prop.h */
442         }
443         g_free(type);
444     }
445
446     full_redraw_required = redraw_required = TRUE;
447 }
448
449 static void hide_window(LocoWindow *lw, gboolean destroyed)
450 {
451     /* if destroyed, then the window is no longer available */
452     lw->visible = FALSE;
453     destroy_glxpixmap(lw);
454
455     full_redraw_required = redraw_required = TRUE;
456 }
457
458 static void configure_window(LocoWindow *lw, const XConfigureEvent *e)
459 {
460     LocoList *above, *pos;
461
462     pos = find_stacking(e->window);
463     above = find_stacking(e->above);
464
465     g_assert(pos != NULL && pos->window != NULL);
466     if (e->above && !above)
467         printf("missing windows from the stacking list!!\n");
468
469     if ((lw->x != e->x) || (lw->y != e->y)) {
470         lw->x = e->x;
471         lw->y = e->y;
472
473         full_redraw_required = redraw_required = TRUE;
474     }
475         
476     if ((lw->w != e->width) || (lw->h != e->height)) {
477         lw->w = e->width;
478         lw->h = e->height;
479
480         destroy_glxpixmap(lw);
481
482         full_redraw_required = redraw_required = TRUE;
483     }
484
485     if (pos->next != above) {
486         printf("Window 0x%lx above 0x%lx\n", pos->window->id,
487                above ? above->window->id : 0);
488         loco_list_move_before(&stacking_top, &stacking_bottom, pos, above);
489
490         full_redraw_required = redraw_required = TRUE;
491     }
492 }
493
494 static void damage_window(LocoWindow *lw)
495 {
496     LocoList *it, *pos;
497
498     pos = find_stacking(lw->id);
499
500     /* XXX if it is transparent, then damage any windows below it that
501        intersect */
502
503     /* damage any windows above it that intersect */
504     for (it = pos; it; it = it->prev) {
505         const LocoWindow *lwa = it->window;
506         if (lwa->x < lw->x + lw->w && lwa->x + lwa->w > lw->x &&
507             lwa->y < lw->y + lw->h && lwa->y + lwa->h > lw->y)
508         {
509             it->window->damaged = TRUE;
510         }
511     }
512
513     lw->damaged = TRUE;
514     redraw_required = TRUE;
515 }
516
517 void COMPOSTER_RAWR(const XEvent *e, gpointer data)
518 {
519     //g_print("COMPOSTER_RAWR() %d\n", e->type);
520
521     if (e->type == ConfigureNotify) {
522         LocoWindow *lw;
523         printf("Window 0x%lx moved or something\n", e->xconfigure.window);
524
525         lw = find_window(e->xconfigure.window);
526         if (lw)
527             configure_window(lw, &e->xconfigure);
528         //print_stacking();
529     }
530     else if (e->type == CreateNotify) {
531         add_window(e->xmap.window);
532     }
533     else if (e->type == DestroyNotify) {
534         LocoWindow *lw = find_window(e->xdestroywindow.window);
535         if (lw) {
536             hide_window(lw, TRUE);
537             remove_window(lw);
538         }
539         else
540             printf("destroy notify for unknown window 0x%lx\n",
541                    e->xdestroywindow.window);
542     }
543     else if (e->type == ReparentNotify) {
544         if (e->xreparent.parent == loco_root)
545             add_window(e->xreparent.window);
546         else {
547             LocoWindow *lw = find_window(e->xreparent.window);
548             if (lw) {
549                 printf("window 0x%lx reparented from root\n", lw->id);
550                 hide_window(lw, FALSE);
551                 remove_window(lw);
552             }
553             else
554                 printf("reparent notify away from root for unknown window "
555                        "0x%lx\n", e->xreparent.window);
556         }
557     }
558
559     else if (e->type == MapNotify) {
560         LocoWindow *lw = find_window(e->xmap.window);
561         if (lw)
562             show_window(lw);
563         else
564             printf("map notify for unknown window 0x%lx\n",
565                    e->xmap.window);
566     }
567     else if (e->type == UnmapNotify) {
568         LocoWindow *lw = find_window(e->xunmap.window);
569         if (lw)
570             hide_window(lw, FALSE);
571         else
572             printf("unmap notify for unknown window 0x%lx\n",
573                    e->xunmap.window);
574     }
575     else if (e->type == obt_display_extension_damage_basep + XDamageNotify) {
576         const XDamageNotifyEvent *de;
577         LocoWindow *lw;
578
579         de = (const XDamageNotifyEvent*)e;
580         lw = find_window(de->drawable);
581         if (lw) {
582             damage_window(lw);
583             /* mark the damage as fixed - we know about it now */
584             XDamageSubtract(obt_display, lw->damage, None, None);
585         }
586         else if (de->drawable == loco_root) {
587             XDamageSubtract(obt_display, de->damage, None, None);
588             full_redraw_required = redraw_required = TRUE;
589         }
590     }
591 }
592
593 static void find_all_windows(gint screen)
594 {
595     guint i, nchild;
596     Window w, *children;
597
598     if (!XQueryTree(obt_display, loco_root, &w, &w, &children, &nchild))
599         nchild = 0;
600
601     for (i = 0; i < nchild; ++i)
602         if (children[i] != None) add_window(children[i]);
603
604     if (children) XFree(children);
605 }
606
607 static gboolean compositor_timeout(gpointer data)
608 {
609     if (redraw_required)
610         full_composite();
611     return TRUE; /* repeat */
612 }
613
614 static guint window_hash(Window *w) { return *w; }
615 static gboolean window_comp(Window *w1, Window *w2) { return *w1 == *w2; }
616
617 void loco_set_mainloop(gint screen_num, ObtMainLoop *loop)
618 {
619     int db, stencil, depth;
620     int i, j, value, count;
621     int w, h;
622     XVisualInfo *vi, tvis, *visinfo;
623     GLXContext cont;
624     int config[] =
625         { GLX_DEPTH_SIZE, 1, GLX_DOUBLEBUFFER, GLX_RGBA, None };
626
627     loco_screen_num = screen_num;
628     loco_root = obt_root(screen_num);
629     loco_overlay = XCompositeGetOverlayWindow(obt_display, loco_root);
630 XserverRegion region = XFixesCreateRegion(obt_display, NULL, 0);
631
632     XFixesSetWindowShapeRegion (obt_display,
633                                 loco_overlay,
634                                 ShapeBounding,
635                                 0, 0,
636                                 0);
637     XFixesSetWindowShapeRegion (obt_display,
638                                 loco_overlay,
639                                 ShapeInput,
640                                 0, 0,
641                                 region);
642
643     XFixesDestroyRegion (obt_display, region);
644
645     vi = glXChooseVisual(obt_display, screen_num, config);
646     cont = glXCreateContext(obt_display, vi, NULL, GL_TRUE);
647     if (cont == NULL)
648         printf("context creation failed\n");
649     glXMakeCurrent(obt_display, loco_overlay, cont);
650
651     BindTexImageEXT = (BindEXTFunc)
652         glXGetProcAddress((const guchar*)"glXBindTexImageEXT");
653     ReleaseTexImageEXT = (ReleaseEXTFunc)
654         glXGetProcAddress((const guchar*)"glXReleaseTexImageEXT");
655
656     w = WidthOfScreen(ScreenOfDisplay(obt_display, screen_num));
657     h = HeightOfScreen(ScreenOfDisplay(obt_display, screen_num));
658     glViewport(0, 0, w, h);
659     glMatrixMode(GL_PROJECTION);
660     glLoadIdentity();
661 printf("Setting up an orthographic projection of %dx%d\n", w, h);
662     glOrtho(0, w, h, 0.0, -1.0, 100.0);
663     glMatrixMode(GL_MODELVIEW);
664     glLoadIdentity();
665     glClear(GL_COLOR_BUFFER_BIT);
666     glEnable(GL_TEXTURE_2D);
667 glError();
668     glXSwapBuffers(obt_display, loco_overlay);
669     glClearColor(1.0, 0.0, 0.0, 1.0);
670 //    glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
671 //    glEnable(GL_BLEND);
672     db = 32767;
673     stencil = 32767;
674     depth = 32767;
675     for (i = 0; i <= MAX_DEPTH; i++) {
676         tvis.depth = i;
677         visualIDs[i] = 0;
678         visinfo = XGetVisualInfo(obt_display, VisualDepthMask, &tvis, &count);
679         for (j = 0; j < count; j++) {
680             glXGetConfig(obt_display, &visinfo[j], GLX_USE_GL, &value);
681             if (!value)
682                 continue;
683
684             glXGetConfig(obt_display, &visinfo[j], GLX_DOUBLEBUFFER, &value);
685             if (value > db)
686                 continue;
687             db = value;
688
689             glXGetConfig(obt_display, &visinfo[j], GLX_STENCIL_SIZE, &value);
690             if (value > stencil)
691                 continue;
692             stencil = value;
693
694             glXGetConfig(obt_display, &visinfo[j], GLX_DEPTH_SIZE, &value);
695             if (value > depth)
696                 continue;
697             depth = value;
698
699             visualIDs[i] = visinfo[j].visualid;
700         }
701     }
702
703     for (i = 0 ;i <= MAX_DEPTH; i++) {
704         tvis.visualid = visualIDs[i];
705         glxPixmapVisuals[i] = XGetVisualInfo(obt_display, VisualIDMask, &tvis, &count);
706         if (glxPixmapVisuals[i])
707             printf("supporting depth %d\n", i);
708     }
709     obt_main_loop_x_add(loop, COMPOSTER_RAWR, NULL, NULL);
710     window_map = g_hash_table_new((GHashFunc)window_hash,
711                                   (GEqualFunc)window_comp);
712     stacking_map = g_hash_table_new((GHashFunc)window_hash,
713                                     (GEqualFunc)window_comp);
714     stacking_top = stacking_bottom = NULL;
715
716     XGrabServer(obt_display);
717
718     XCompositeRedirectSubwindows(obt_display, loco_root,
719                                  CompositeRedirectManual);
720     find_all_windows(screen_num);
721
722     XUngrabServer(obt_display);
723
724     full_redraw_required = redraw_required = TRUE;
725
726     obt_main_loop_timeout_add(loop, REFRESH_RATE,
727                               (GSourceFunc)compositor_timeout,
728                               NULL, NULL, NULL);
729 }
730
731 void loco_shutdown(void)
732 {
733 }