window->glx_pixmap = glXCreatePixmap(compositor->display, screen->fbconfig, window->pixmap, attribs);
}
-void add_window(Compositor *compositor, CompositedScreen *screen, Window w)
+CompositedWindow *add_window(Compositor *compositor, CompositedScreen *screen, Window w)
{
CompositedWindow *window;
XWindowAttributes win_attr;
if(w==screen->root || w==screen->overlay)
- return;
+ return NULL;
if(!XGetWindowAttributes(compositor->display, w, &win_attr))
{
printf("XGetWindowAttributes failed; probably the window was already destroyed\n");
- return;
+ return NULL;
}
if(win_attr.class==InputOnly)
- return;
+ return NULL;
if(find_window(screen, w))
- return;
+ return NULL;
if(screen->nwindows==screen->windows_capacity)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+ return window;
}
-void remove_window(Compositor *compositor, CompositedScreen *screen, Window w, int destroyed)
+void remove_window(Compositor *compositor, CompositedScreen *screen, CompositedWindow *window, int destroyed)
{
unsigned i;
- for(i=0; i<screen->nwindows; ++i)
- if(screen->windows[i].window==w)
+ glDeleteTextures(1, &window->texture);
+ if(!destroyed)
+ {
+ XDamageDestroy(compositor->display, window->damage);
+ if(window->pixmap)
{
- glDeleteTextures(1, &screen->windows[i].texture);
- if(!destroyed)
- {
- XDamageDestroy(compositor->display, screen->windows[i].damage);
- if(screen->windows[i].pixmap)
- {
- glXDestroyPixmap(compositor->display, screen->windows[i].glx_pixmap);
- XFreePixmap(compositor->display, screen->windows[i].pixmap);
- }
- XCompositeUnredirectWindow(compositor->display, screen->windows[i].window, CompositeRedirectManual);
- }
-
- --screen->nwindows;
- for(; i<screen->nwindows; ++i)
- screen->windows[i] = screen->windows[i+1];
+ 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];
}
CompositedScreen *find_screen_by_root(Compositor *compositor, Window root)
XCloseDisplay(compositor->display);
}
+void mark_dirty(Compositor *compositor, CompositedScreen *screen)
+{
+ compositor->dirty = 1;
+ screen->dirty = 1;
+}
+
void process_create_window_event(Compositor *compositor, XCreateWindowEvent *event)
{
CompositedScreen *screen = find_screen_by_root(compositor, event->parent);
if(!screen)
return;
- remove_window(compositor, screen, event->window, 1);
+ CompositedWindow *window = find_window(screen, event->window);
+ if(window)
+ remove_window(compositor, screen, window, 1);
}
void process_map_event(Compositor *compositor, XMapEvent *event)
window->map_state = IsViewable;
create_window_pixmap(compositor, screen, window);
+
+ mark_dirty(compositor, screen);
}
void process_unmap_event(Compositor *compositor, XUnmapEvent *event)
CompositedWindow *window = find_window(screen, event->window);
if(window)
window->map_state = IsUnviewable;
+
+ mark_dirty(compositor, screen);
}
void process_reparent_event(Compositor *compositor, XReparentEvent *event)
if(!screen)
return;
+ CompositedWindow *window;
if(event->parent==screen->root)
- add_window(compositor, screen, event->window);
+ window = add_window(compositor, screen, event->window);
else
- remove_window(compositor, screen, event->window, 0);
+ {
+ window = find_window(screen, event->window);
+ if(!window)
+ return;
+
+ remove_window(compositor, screen, window, 0);
+ }
+
+ if(window && window->map_state==IsViewable)
+ mark_dirty(compositor, screen);
}
void process_damage_event(Compositor *compositor, XDamageNotifyEvent *event)
if(!screen)
return;
- screen->dirty = 1;
- compositor->dirty = 1;
+ CompositedWindow *window = find_window(screen, event->drawable);
+ if(window->map_state==IsViewable)
+ mark_dirty(compositor, screen);
}
int process_event(Compositor *compositor)