]> git.tdb.fi Git - geometrycompositor.git/commitdiff
Some more refactoring
authorMikko Rasa <tdb@tdb.fi>
Sat, 12 Dec 2015 11:26:33 +0000 (13:26 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 12 Dec 2015 11:27:41 +0000 (13:27 +0200)
source/main.c

index f4704aead4e0aef22c003bd38cc1507fc7d9c85f..c0bbe0e20c8d0d711242216e36a706d4b013eb8e 100644 (file)
@@ -567,11 +567,10 @@ void mark_dirty(Compositor *compositor, CompositedScreen *screen)
 
 void process_create_window_event(Compositor *compositor, XCreateWindowEvent *event)
 {
-       CompositedScreen *screen = find_screen_by_root(compositor, event->parent);
-       if(!screen)
-               return;
+       CompositedScreen *screen;
 
-       add_window(compositor, screen, event->window);
+       if((screen = find_screen_by_root(compositor, event->parent)))
+               add_window(compositor, screen, event->window);
 }
 
 void process_destroy_window_event(Compositor *compositor, XDestroyWindowEvent *event)
@@ -579,13 +578,9 @@ void process_destroy_window_event(Compositor *compositor, XDestroyWindowEvent *e
        CompositedScreen *screen;
        CompositedWindow *window;
 
-       screen = find_screen_by_root(compositor, event->event);
-       if(!screen)
-               return;
-
-       window = find_window(screen, event->window);
-       if(window)
-               remove_window(compositor, screen, window, 1);
+       if((screen = find_screen_by_root(compositor, event->event)))
+               if((window = find_window(screen, event->window)))
+                       remove_window(compositor, screen, window, 1);
 }
 
 void process_map_event(Compositor *compositor, XMapEvent *event)
@@ -730,39 +725,47 @@ int process_event(Compositor *compositor)
        return 1;
 }
 
-void refresh_screens(Compositor *compositor)
+void refresh_screen(Compositor *compositor, CompositedScreen *screen)
 {
-       unsigned i, j;
+       unsigned i;
 
-       for(i=0; i<compositor->nscreens; ++i)
+       use_gl(compositor, screen);
+
+       glClearColor(0.5f, 0.5f, 0.5f, 0.0f);
+       glClear(GL_COLOR_BUFFER_BIT);
+
+       glUseProgram(screen->program);
+       glBindVertexArray(screen->vertex_array);
+       for(i=0; i<screen->nwindows; ++i)
        {
-               CompositedScreen *screen = &compositor->screens[i];
-               if(!screen->dirty)
+               CompositedWindow *window = &screen->windows[i];
+               if(window->map_state!=IsViewable)
                        continue;
 
-               use_gl(compositor, screen);
+               glBindTexture(GL_TEXTURE_2D, window->texture);
+               compositor->glXBindTexImageEXT(compositor->display, window->glx_pixmap, GLX_FRONT_LEFT_EXT, NULL);
+               glUniform4f(screen->geometry_loc,
+                       (float)window->x/screen->width, (float)(screen->height-window->y-window->height)/screen->height,
+                       (float)(window->width+2*window->border)/screen->width, (float)(window->height+2*window->border)/screen->height);
+               glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+               compositor->glXReleaseTexImageEXT(compositor->display, window->glx_pixmap, GLX_FRONT_LEFT_EXT);
+               XDamageSubtract(compositor->display, window->damage, None, None);
+       }
 
-               glClearColor(0.5f, 0.5f, 0.5f, 0.0f);
-               glClear(GL_COLOR_BUFFER_BIT);
+       glXSwapBuffers(compositor->display, screen->glx_window);
 
-               glUseProgram(screen->program);
-               glBindVertexArray(screen->vertex_array);
-               for(j=0; j<screen->nwindows; ++j)
-               {
-                       CompositedWindow *window = &screen->windows[j];
-                       if(window->map_state==IsViewable)
-                       {
-                               glBindTexture(GL_TEXTURE_2D, window->texture);
-                               compositor->glXBindTexImageEXT(compositor->display, window->glx_pixmap, GLX_FRONT_LEFT_EXT, NULL);
-                               glUniform4f(screen->geometry_loc, (float)window->x/screen->width, (float)(screen->height-window->y-window->height)/screen->height, (float)(window->width+2*window->border)/screen->width, (float)(window->height+2*window->border)/screen->height);
-                               glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-                               compositor->glXReleaseTexImageEXT(compositor->display, window->glx_pixmap, GLX_FRONT_LEFT_EXT);
-                               XDamageSubtract(compositor->display, window->damage, None, None);
-                       }
-               }
-               glXSwapBuffers(compositor->display, screen->glx_window);
+       screen->dirty = 0;
+}
+
+void refresh_all_screens(Compositor *compositor)
+{
+       unsigned i;
 
-               screen->dirty = 0;
+       for(i=0; i<compositor->nscreens; ++i)
+       {
+               CompositedScreen *screen = &compositor->screens[i];
+               if(screen->dirty)
+                       refresh_screen(compositor, screen);
        }
 
        compositor->dirty = 0;
@@ -787,7 +790,7 @@ int main()
        while(!terminate_requested)
        {
                if(!process_event(&compositor))
-                       refresh_screens(&compositor);
+                       refresh_all_screens(&compositor);
        }
 
        shutdown_compositor(&compositor);