X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmain.c;h=13038c29ef83f6b8292a6e970edd06225c4de652;hb=03938166b24208348b4ea25600b4d06c8fd2400a;hp=15486e61c83f3dfef06c88816d1f4db2ade4985b;hpb=ce6b94be7d334af14fac9f997ab66ff9a9aeecc5;p=geometrycompositor.git diff --git a/source/main.c b/source/main.c index 15486e6..13038c2 100644 --- a/source/main.c +++ b/source/main.c @@ -2,10 +2,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include @@ -24,6 +26,20 @@ typedef struct CompositedWindow unsigned texture; } CompositedWindow; +typedef struct CompositedMonitor +{ + int enabled; + int x; + int y; + unsigned width; + unsigned height; + unsigned vertex_buffer; + unsigned index_buffer; + unsigned vertex_array; + unsigned tessellation; + unsigned nelements; +} CompositedMonitor; + typedef struct CompositedScreen { int number; @@ -38,11 +54,15 @@ typedef struct CompositedScreen unsigned shaders[2]; unsigned program; unsigned geometry_loc; - unsigned vertex_buffer; - unsigned vertex_array; + unsigned window_vertex_buffer; + unsigned window_vertex_array; + unsigned framebuffer; + unsigned fb_texture; CompositedWindow *windows; unsigned nwindows; unsigned windows_capacity; + CompositedMonitor *monitors; + unsigned nmonitors; int dirty; } CompositedScreen; @@ -62,31 +82,35 @@ static const char *vshader = "#version 150\n" "uniform vec4 geometry;\n" "in vec2 vertex;\n" + "in vec2 texture_coord;\n" "out vec2 texcoord;\n" "void main()\n" "{\n" " gl_Position = vec4((geometry.xy+vertex*geometry.zw)*2.0-1.0, 0.0, 1.0);\n" - " texcoord = vec2(vertex.x, 1.0-vertex.y);\n" + " texcoord = texture_coord;\n" "}\n"; static const char *fshader = "#version 150\n" - "uniform sampler2D window;\n" + "uniform sampler2D image;\n" "in vec2 texcoord;\n" "out vec4 frag_color;\n" "void main()\n" "{\n" - " frag_color = texture(window, texcoord);\n" + " frag_color = texture(image, texcoord);\n" "}\n"; -static const float vertices[] = +static const float window_vertices[] = { - 0.0f, 1.0f, - 0.0f, 0.0f, - 1.0f, 1.0f, - 1.0f, 0.0f + /* vertex texcoord */ + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f, + 1.0f, 1.0f, 1.0f, 0.0f, + 1.0f, 0.0f, 1.0f, 1.0f }; +int terminate_requested = 0; + int x_error_handler(Display *display, XErrorEvent *event) { printf("Ignoring X error %d on resource %lx\n", event->error_code, event->resourceid); @@ -139,7 +163,7 @@ int initialize_gl(Compositor *compositor, CompositedScreen *screen) attribs[i++] = GLX_CONTEXT_MAJOR_VERSION_ARB; attribs[i++] = 3; attribs[i++] = GLX_CONTEXT_MINOR_VERSION_ARB; - attribs[i++] = 0; + attribs[i++] = 1; attribs[i] = None; screen->glx_context = compositor->glXCreateContextAttribsARB(compositor->display, screen->fbconfig, NULL, True, attribs); @@ -178,12 +202,40 @@ unsigned compile_shader(GLenum type, const char *source) return shader; } -int create_gl_resources(Compositor *compositor, CompositedScreen *screen) +unsigned link_program(unsigned *shaders, unsigned nshaders) { + unsigned program; + unsigned i; int status; char info_log[1024]; GLsizei length; + program = glCreateProgram(); + for(i=0; ishaders[0] = compile_shader(GL_VERTEX_SHADER, vshader); @@ -191,36 +243,41 @@ int create_gl_resources(Compositor *compositor, CompositedScreen *screen) if(!screen->shaders[0] || !screen->shaders[1]) return 0; - screen->program = glCreateProgram(); - glAttachShader(screen->program, screen->shaders[0]); - glAttachShader(screen->program, screen->shaders[1]); - glBindAttribLocation(screen->program, 0, "vertex"); - glLinkProgram(screen->program); + screen->program = link_program(screen->shaders, 2); + if(!screen->program) + return 0; screen->geometry_loc = glGetUniformLocation(screen->program, "geometry"); - glGetProgramiv(screen->program, GL_LINK_STATUS, &status); - glGetProgramInfoLog(screen->program, sizeof(info_log), &length, info_log); - if(!status) - { - fprintf(stderr, "Program link failed:\n%s\n", info_log); - glDeleteProgram(screen->program); - return 0; - } - else if(length) - printf("Program info log:\n%s\n", info_log); - - glGenBuffers(1, &screen->vertex_buffer); - glBindBuffer(GL_ARRAY_BUFFER, screen->vertex_buffer); - glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); + glGenBuffers(1, &screen->window_vertex_buffer); + glBindBuffer(GL_ARRAY_BUFFER, screen->window_vertex_buffer); + glBufferData(GL_ARRAY_BUFFER, sizeof(window_vertices), window_vertices, GL_STATIC_DRAW); - glGenVertexArrays(1, &screen->vertex_array); - glBindVertexArray(screen->vertex_array); - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL); + stride = 4*sizeof(float); + glGenVertexArrays(1, &screen->window_vertex_array); + glBindVertexArray(screen->window_vertex_array); + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, stride, NULL); glEnableVertexAttribArray(0); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, stride, (void *)(2*sizeof(float))); + glEnableVertexAttribArray(1); + glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); + glGenTextures(1, &screen->fb_texture); + glBindTexture(GL_TEXTURE_2D, screen->fb_texture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, screen->width, screen->height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + 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); + glBindTexture(GL_TEXTURE_2D, 0); + + glGenFramebuffers(1, &screen->framebuffer); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, screen->framebuffer); + glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, screen->fb_texture, 0); + glDepthMask(GL_FALSE); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + return 1; } @@ -257,24 +314,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) { @@ -305,6 +362,66 @@ 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, 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; inwindows; ++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; jnwindows; ++j) + if(screen->windows[j].window==above) + break; + + if(j>=screen->nwindows || i==j+1) + return window; + + if(jwindows[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]; } CompositedScreen *find_screen_by_root(Compositor *compositor, Window root) @@ -330,6 +447,103 @@ CompositedScreen *find_screen_by_window(Compositor *compositor, Window w) return NULL; } +void update_monitor_vertices(CompositedScreen *screen, CompositedMonitor *monitor) +{ + unsigned t; + unsigned data_size; + float *vertex_data; + unsigned short *index_data; + unsigned x, y; + unsigned i; + + t = monitor->tessellation; + + data_size = (t+1)*(t+1)*4*sizeof(float); + vertex_data = (float *)malloc(data_size); + for(y=0; y<=t; ++y) + for(x=0; x<=t; ++x) + { + float xf, yf; + float *v; + + xf = (float)x/t; + yf = (float)y/t; + v = vertex_data+(y*(t+1)+x)*4; + v[0] = xf; + v[1] = yf; + v[2] = (monitor->x+xf*monitor->width)/screen->width; + v[3] = (monitor->y+yf*monitor->height)/screen->height; + } + glBindBuffer(GL_ARRAY_BUFFER, monitor->vertex_buffer); + glBufferData(GL_ARRAY_BUFFER, data_size, vertex_data, GL_STATIC_DRAW); + glBindBuffer(GL_ARRAY_BUFFER, 0); + free(vertex_data); + + monitor->nelements = t*((t+1)*2+1)-1; + data_size = monitor->nelements*sizeof(unsigned short); + index_data = (unsigned short *)malloc(data_size); + i = 0; + for(y=0; y0) + index_data[i++] = 0xFFFF; + for(x=0; x<=t; ++x) + { + index_data[i++] = (y+1)*(t+1)+x; + index_data[i++] = y*(t+1)+x; + } + } + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, monitor->index_buffer); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, data_size, index_data, GL_STATIC_DRAW); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + free(index_data); +} + +int initialize_monitor(Compositor *compositor, CompositedScreen *screen, CompositedMonitor *monitor, XRRScreenResources *xrr_res, unsigned index) +{ + XRROutputInfo *output; + XRRCrtcInfo *crtc; + unsigned buffers[2]; + unsigned stride; + + output = XRRGetOutputInfo(compositor->display, xrr_res, xrr_res->outputs[index]); + monitor->enabled = !!output->crtc; + if(!monitor->enabled) + { + XRRFreeOutputInfo(output); + return 1; + } + + crtc = XRRGetCrtcInfo(compositor->display, xrr_res, output->crtc); + monitor->x = crtc->x; + monitor->y = crtc->y; + monitor->width = crtc->width; + monitor->height = crtc->height; + XRRFreeCrtcInfo(crtc); + XRRFreeOutputInfo(output); + + glGenBuffers(2, buffers); + monitor->vertex_buffer = buffers[0]; + monitor->index_buffer = buffers[1]; + + monitor->tessellation = 20; + update_monitor_vertices(screen, monitor); + stride = 4*sizeof(float); + + glGenVertexArrays(1, &monitor->vertex_array); + glBindVertexArray(monitor->vertex_array); + glBindBuffer(GL_ARRAY_BUFFER, monitor->vertex_buffer); + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, stride, NULL); + glEnableVertexAttribArray(0); + glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, stride, (void *)(2*sizeof(float))); + glEnableVertexAttribArray(1); + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, monitor->index_buffer); + glBindVertexArray(0); + + return 1; +} + int initialize_screen(Compositor *compositor, unsigned number) { CompositedScreen *screen; @@ -338,6 +552,7 @@ int initialize_screen(Compositor *compositor, unsigned number) int x, y; unsigned border; unsigned depth; + XRRScreenResources *xrr_res; Window dummy_parent; Window *children; unsigned nchildren; @@ -364,6 +579,14 @@ int initialize_screen(Compositor *compositor, unsigned number) if(!create_gl_resources(compositor, screen)) return 0; + xrr_res = XRRGetScreenResources(compositor->display, screen->root); + screen->nmonitors = xrr_res->noutput; + screen->monitors = (CompositedMonitor *)malloc(screen->nmonitors*sizeof(CompositedMonitor)); + for(i=0; inmonitors; ++i) + if(!initialize_monitor(compositor, screen, &screen->monitors[i], xrr_res, i)) + return 0; + XRRFreeScreenResources(xrr_res); + XQueryTree(compositor->display, screen->root, &dummy_root, &dummy_parent, &children, &nchildren); screen->windows = (CompositedWindow *)malloc(nchildren*sizeof(CompositedWindow)); @@ -422,6 +645,13 @@ int initialize_compositor(Compositor *compositor) else if(major_ver<1 || (major_ver==1 && minor_ver<1)) return with_error("XShape 1.1 or later is required"); + if(!XRRQueryExtension(compositor->display, &event_base, &error_base)) + return with_error("XRandR is required but was not found"); + else if(!XRRQueryVersion(compositor->display, &major_ver, &minor_ver)) + return with_error("Cannot determine XRandR version"); + else if(major_ver<1 || (major_ver==1 && minor_ver<2)) + return with_error("XRandR 1.2 or later is required"); + compositor->glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((unsigned char *)"glXCreateContextAttribsARB"); compositor->glXBindTexImageEXT = (PFNGLXBINDTEXIMAGEEXTPROC)glXGetProcAddress((unsigned char *)"glXBindTexImageEXT"); compositor->glXReleaseTexImageEXT = (PFNGLXRELEASETEXIMAGEEXTPROC)glXGetProcAddress((unsigned char *)"glXReleaseTexImageEXT"); @@ -439,64 +669,182 @@ int initialize_compositor(Compositor *compositor) void shutdown_screen(Compositor *compositor, CompositedScreen *screen) { + unsigned i; + + use_gl(compositor, screen); + + for(i=0; inwindows; ++i) + { + glDeleteTextures(1, &screen->windows[i].texture); + if(screen->windows[i].pixmap) + { + glXDestroyPixmap(compositor->display, screen->windows[i].glx_pixmap); + XFreePixmap(compositor->display, screen->windows[i].pixmap); + XDamageDestroy(compositor->display, screen->windows[i].damage); + } + } + + for(i=0; inmonitors; ++i) + if(screen->monitors[i].enabled) + { + glDeleteBuffers(1, &screen->monitors[i].vertex_buffer); + glDeleteBuffers(1, &screen->monitors[i].index_buffer); + glDeleteVertexArrays(1, &screen->monitors[i].vertex_array); + } + + glDeleteBuffers(1, &screen->window_vertex_buffer); + glDeleteVertexArrays(1, &screen->window_vertex_array); + glDeleteFramebuffers(1, &screen->framebuffer); + glDeleteTextures(1, &screen->fb_texture); + glDeleteProgram(screen->program); + glDeleteShader(screen->shaders[0]); + glDeleteShader(screen->shaders[1]); + + glXMakeContextCurrent(compositor->display, 0, 0, NULL); glXDestroyContext(compositor->display, screen->glx_context); glXDestroyWindow(compositor->display, screen->glx_window); XDestroyWindow(compositor->display, screen->render_window); XCompositeReleaseOverlayWindow(compositor->display, screen->overlay); + + free(screen->windows); + free(screen->monitors); } void shutdown_compositor(Compositor *compositor) { unsigned i; - glXMakeContextCurrent(compositor->display, 0, 0, NULL); for(i=0; inscreens; ++i) shutdown_screen(compositor, &compositor->screens[i]); + free(compositor->screens); + + 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); + CompositedScreen *screen; + + if((screen = find_screen_by_root(compositor, event->parent))) + add_window(compositor, screen, event->window); +} + +void process_destroy_window_event(Compositor *compositor, XDestroyWindowEvent *event) +{ + CompositedScreen *screen; + CompositedWindow *window; + + 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) +{ + CompositedScreen *screen; + CompositedWindow *window; + + screen = find_screen_by_root(compositor, event->event); if(!screen) return; - add_window(compositor, screen, event->window); + window = find_window(screen, event->window); + if(!window) + return; + + window->map_state = IsViewable; + create_window_pixmap(compositor, screen, window); + + mark_dirty(compositor, screen); } -void process_map_event(Compositor *compositor, XMapEvent *event) +void process_unmap_event(Compositor *compositor, XUnmapEvent *event) { - CompositedScreen *screen = find_screen_by_root(compositor, event->event); + CompositedScreen *screen; + CompositedWindow *window; + + screen = find_screen_by_root(compositor, event->event); if(!screen) return; - CompositedWindow *window = find_window(screen, event->window); + window = find_window(screen, event->window); if(window) + window->map_state = IsUnviewable; + + mark_dirty(compositor, screen); +} + +void process_reparent_event(Compositor *compositor, XReparentEvent *event) +{ + CompositedScreen *screen; + CompositedWindow *window; + + screen = find_screen_by_root(compositor, event->event); + if(!screen) + return; + + if(event->parent==screen->root) + window = add_window(compositor, screen, event->window); + else { - window->map_state = IsViewable; - create_window_pixmap(compositor, screen, window); + 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_unmap_event(Compositor *compositor, XUnmapEvent *event) +void process_configure_event(Compositor *compositor, XConfigureEvent *event) { - CompositedScreen *screen = find_screen_by_root(compositor, event->event); + CompositedScreen *screen; + CompositedWindow *window; + + screen = find_screen_by_root(compositor, event->event); if(!screen) return; - CompositedWindow *window = find_window(screen, event->window); - if(window) - window->map_state = IsUnviewable; + window = find_window(screen, event->window); + if(!window) + return; + + window->x = event->x; + window->y = event->y; + if((unsigned)event->width!=window->width || (unsigned)event->height!=window->height || (unsigned)event->border_width!=window->border) + { + window->width = event->width; + window->height = event->height; + window->border = event->border_width; + create_window_pixmap(compositor, screen, window); + } + reorder_window(screen, window, event->above); + + if(window->map_state==IsViewable) + mark_dirty(compositor, screen); } void process_damage_event(Compositor *compositor, XDamageNotifyEvent *event) { - CompositedScreen *screen = find_screen_by_window(compositor, event->drawable); + CompositedScreen *screen; + CompositedWindow *window; + + screen = find_screen_by_window(compositor, event->drawable); if(!screen) return; - screen->dirty = 1; - compositor->dirty = 1; + window = find_window(screen, event->drawable); + if(window->map_state==IsViewable) + mark_dirty(compositor, screen); } int process_event(Compositor *compositor) @@ -515,12 +863,21 @@ int process_event(Compositor *compositor) case CreateNotify: process_create_window_event(compositor, &event.xcreatewindow); break; + case DestroyNotify: + process_destroy_window_event(compositor, &event.xdestroywindow); + break; case MapNotify: process_map_event(compositor, &event.xmap); break; case UnmapNotify: process_unmap_event(compositor, &event.xunmap); break; + case ReparentNotify: + process_reparent_event(compositor, &event.xreparent); + break; + case ConfigureNotify: + process_configure_event(compositor, &event.xconfigure); + break; default: if(event.type==compositor->damage_event+XDamageNotify) process_damage_event(compositor, (XDamageNotifyEvent *)&event); @@ -531,52 +888,95 @@ 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); + + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, screen->framebuffer); + + glClearColor(0.5f, 0.5f, 0.5f, 0.0f); + glClear(GL_COLOR_BUFFER_BIT); + + glUseProgram(screen->program); + glBindVertexArray(screen->window_vertex_array); + for(i=0; inwindows; ++i) { - CompositedScreen *screen = &compositor->screens[i]; - use_gl(compositor, screen); + CompositedWindow *window = &screen->windows[i]; + if(window->map_state!=IsViewable) + continue; + + 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); + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); + glClearColor(0.5f, 0.0f, 0.5f, 0.0f); + glClear(GL_COLOR_BUFFER_BIT); + glBindTexture(GL_TEXTURE_2D, screen->fb_texture); + glEnable(GL_PRIMITIVE_RESTART); + glPrimitiveRestartIndex(0xFFFF); - 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); + for(i=0; inmonitors; ++i) + { + CompositedMonitor *monitor = &screen->monitors[i]; + if(!monitor->enabled) + continue; - screen->dirty = 0; + glUniform4f(screen->geometry_loc, + (float)monitor->x/screen->width, (float)monitor->y/screen->height, + (float)monitor->width/screen->width, (float)monitor->height/screen->height); + + glBindVertexArray(monitor->vertex_array); + glDrawElements(GL_TRIANGLE_STRIP, monitor->nelements, GL_UNSIGNED_SHORT, NULL); + } + + glXSwapBuffers(compositor->display, screen->glx_window); + + screen->dirty = 0; +} + +void refresh_all_screens(Compositor *compositor) +{ + unsigned i; + + for(i=0; inscreens; ++i) + { + CompositedScreen *screen = &compositor->screens[i]; + if(screen->dirty) + refresh_screen(compositor, screen); } compositor->dirty = 0; } +void sighandler(int sig) +{ + terminate_requested = 1; + (void)sig; +} + int main() { Compositor compositor; + signal(SIGINT, &sighandler); + signal(SIGTERM, &sighandler); + if(!initialize_compositor(&compositor)) return 1; - while(1) + while(!terminate_requested) { if(!process_event(&compositor)) - refresh_screens(&compositor); + refresh_all_screens(&compositor); } shutdown_compositor(&compositor);