From a51a8bbe15114abe6accf1c0f63f9fcb2b97767e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 12 Dec 2015 13:26:33 +0200 Subject: [PATCH] Some more refactoring --- source/main.c | 77 ++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/source/main.c b/source/main.c index f4704ae..c0bbe0e 100644 --- a/source/main.c +++ b/source/main.c @@ -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; inscreens; ++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; inwindows; ++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; jnwindows; ++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; inscreens; ++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); -- 2.45.2