]> git.tdb.fi Git - geometrycompositor.git/commitdiff
Set the dirty flags on most events, but only if the window was viewable
authorMikko Rasa <tdb@tdb.fi>
Fri, 11 Dec 2015 17:25:04 +0000 (19:25 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 11 Dec 2015 17:25:04 +0000 (19:25 +0200)
source/main.c

index 2da64e601b6472a42fba0dab7f4781fa1ead4d79..b26c46597beb22008963c5f01758aa96162ef73b 100644 (file)
@@ -260,24 +260,24 @@ void create_window_pixmap(Compositor *compositor, CompositedScreen *screen, Comp
        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)
        {
@@ -308,31 +308,29 @@ void add_window(Compositor *compositor, CompositedScreen *screen, Window w)
        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)
@@ -503,6 +501,12 @@ void shutdown_compositor(Compositor *compositor)
        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);
@@ -518,7 +522,9 @@ void process_destroy_window_event(Compositor *compositor, XDestroyWindowEvent *e
        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)
@@ -533,6 +539,8 @@ 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)
@@ -544,6 +552,8 @@ 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)
@@ -552,10 +562,20 @@ 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)
@@ -564,8 +584,9 @@ 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)