+
+ return window;
+}
+
+void remove_window(Compositor *compositor, CompositedScreen *screen, CompositedWindow *window, int destroyed)
+{
+ unsigned i;
+
+ glDeleteTextures(1, &window->texture);
+ if(!destroyed)
+ {
+ XDamageDestroy(compositor->display, window->damage);
+ if(window->pixmap)
+ {
+ glXDestroyPixmap(compositor->display, window->glx_pixmap);
+ XFreePixmap(compositor->display, window->pixmap);
+ }
+ XCompositeUnredirectWindow(compositor->display, window->window, CompositeRedirectManual);
+ }
+
+ --screen->nwindows;
+ for(i=window-screen->windows; i<screen->nwindows; ++i)
+ screen->windows[i] = screen->windows[i+1];
+}
+
+CompositedWindow *reorder_window(CompositedScreen *screen, CompositedWindow *window, Window above)
+{
+ unsigned i, j;
+ CompositedWindow hold;
+
+ i = window-screen->windows;
+ if(above)
+ {
+ for(j=0; j<screen->nwindows; ++j)
+ if(screen->windows[j].window==above)
+ break;
+
+ if(j>=screen->nwindows || i==j+1)
+ return window;
+
+ if(j<i)
+ ++j;
+ }
+ else
+ j = 0;
+
+ hold = *window;
+ if(i<j)
+ {
+ for(; i<j; ++i)
+ screen->windows[i] = screen->windows[i+1];
+ }
+ else
+ {
+ for(; i>j; --i)
+ screen->windows[i] = screen->windows[i-1];
+ }
+ screen->windows[j] = hold;
+
+ return &screen->windows[j];