Damage damage;
Pixmap pixmap;
GLXPixmap glx_pixmap;
+ int recreate_pixmap;
unsigned texture;
unsigned mask_texture;
int use_mask;
+ int recreate_mask;
} CompositedWindow;
typedef struct CompositedMonitor
unsigned vertex_array;
unsigned tessellation;
unsigned nelements;
+ short *geometry_data;
+ unsigned geometry_data_size;
} CompositedMonitor;
typedef struct CompositedScreen
unsigned window_vertex_array;
unsigned framebuffer;
unsigned fb_texture;
+ Pixmap root_pixmap;
+ GLXPixmap root_glx_pixmap;
+ unsigned root_texture;
CompositedWindow *windows;
unsigned nwindows;
unsigned windows_capacity;
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB;
PFNGLXBINDTEXIMAGEEXTPROC glXBindTexImageEXT;
PFNGLXRELEASETEXIMAGEEXTPROC glXReleaseTexImageEXT;
+ Atom root_pmap_atom;
Atom correction_atom;
Atom monitors_atom;
+ Atom geometry_data_atom;
+ Window selection_window;
int dirty;
} Compositor;
static const char *vshader_src =
- "#version 150\n"
+ "#version 130\n"
"uniform vec4 geometry;\n"
"in vec2 vertex;\n"
"in vec2 texture_coord;\n"
"}\n";
static const char *fshader_src =
- "#version 150\n"
+ "#version 130\n"
"uniform sampler2D image;\n"
"in vec2 texcoord;\n"
"out vec4 frag_color;\n"
"}\n";
static const char *masked_fshader_src =
- "#version 150\n"
+ "#version 130\n"
"uniform sampler2D image;\n"
"uniform sampler2D mask;\n"
"in vec2 texcoord;\n"
return texture;
}
-int create_gl_resources(Compositor *compositor, CompositedScreen *screen)
+int create_gl_resources(CompositedScreen *screen)
{
unsigned stride;
int loc;
- use_gl(compositor, screen);
-
screen->shaders[0] = compile_shader(GL_VERTEX_SHADER, vshader_src);
screen->shaders[1] = compile_shader(GL_FRAGMENT_SHADER, fshader_src);
screen->shaders[2] = compile_shader(GL_FRAGMENT_SHADER, masked_fshader_src);
glDepthMask(GL_FALSE);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
+ screen->root_texture = create_2d_texture();
+
return 1;
}
return NULL;
}
-void create_window_pixmap(Compositor *compositor, CompositedScreen *screen, CompositedWindow *window)
+GLXPixmap pixmap_to_glx_pixmap(Compositor *compositor, CompositedScreen *screen, Pixmap pixmap)
{
int attribs[5];
unsigned i;
- if(window->pixmap)
- {
- glXDestroyPixmap(compositor->display, window->glx_pixmap);
- XFreePixmap(compositor->display, window->pixmap);
- }
-
i = 0;
attribs[i++] = GLX_TEXTURE_TARGET_EXT;
attribs[i++] = GLX_TEXTURE_2D_EXT;
attribs[i++] = GLX_TEXTURE_FORMAT_RGBA_EXT;
attribs[i++] = None;
+ return glXCreatePixmap(compositor->display, screen->fbconfig, pixmap, attribs);
+}
+
+void create_window_pixmap(Compositor *compositor, CompositedScreen *screen, CompositedWindow *window)
+{
+ if(window->pixmap)
+ {
+ glXDestroyPixmap(compositor->display, window->glx_pixmap);
+ XFreePixmap(compositor->display, window->pixmap);
+ }
+
window->pixmap = XCompositeNameWindowPixmap(compositor->display, window->window);
- window->glx_pixmap = glXCreatePixmap(compositor->display, screen->fbconfig, window->pixmap, attribs);
+ window->glx_pixmap = pixmap_to_glx_pixmap(compositor, screen, window->pixmap);
+ window->recreate_pixmap = 0;
}
void update_window_mask(Compositor *compositor, CompositedWindow *window)
glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, data);
free(data);
+
+ window->recreate_mask = 0;
}
CompositedWindow *add_window(Compositor *compositor, CompositedScreen *screen, Window w)
window->glx_pixmap = None;
XCompositeRedirectWindow(compositor->display, window->window, CompositeRedirectManual);
- if(window->map_state==IsViewable)
- create_window_pixmap(compositor, screen, window);
+ window->recreate_pixmap = (window->map_state==IsViewable);
window->texture = create_2d_texture();
window->mask_texture = create_2d_texture();
-
- if(window->map_state==IsViewable)
- update_window_mask(compositor, window);
+ window->use_mask = 0;
+ window->recreate_mask = (window->map_state==IsViewable);
XShapeSelectInput(compositor->display, window->window, ShapeNotifyMask);
}
}
+ monitor->geometry_data[0] = t;
+ for(i=0; i<3; ++i)
+ monitor->geometry_data[1+i] = eye[i]*10000;
+ for(y=0; y<2; ++y)
+ for(x=0; x<2; ++x)
+ {
+ i = 1+(1+y*2+x)*3;
+ monitor->geometry_data[i] = ((x-0.5f)*distance/monitor->perspective)*10000;
+ monitor->geometry_data[i+1] = (eye[1]+look[1]*distance-(y-monitor->vertical_center)*look[2]*distance/monitor->perspective/aspect)*10000;
+ monitor->geometry_data[i+2] = (eye[2]+look[2]*distance+(y-monitor->vertical_center)*look[1]*distance/monitor->perspective/aspect)*10000;
+ }
+ for(i=0; i<(t+1)*(t+1)*3; ++i)
+ monitor->geometry_data[16+i] = vertex_data[i]*10000;
+
for(y=t; y<=t; --y)
for(x=t; x<=t; --x)
{
if(!monitor->enabled)
{
XRRFreeOutputInfo(output);
+ monitor->geometry_data = NULL;
return 1;
}
monitor->index_buffer = buffers[1];
monitor->tessellation = 50;
+ monitor->geometry_data_size = (monitor->tessellation+1)*(monitor->tessellation+1)*3+16;
+ monitor->geometry_data = (short *)malloc(monitor->geometry_data_size*sizeof(short));
update_monitor_vertices(screen, monitor);
stride = 4*sizeof(float);
return NULL;
}
+CompositedMonitor *find_monitor_by_name_global(Compositor *compositor, char *name, CompositedScreen **screen)
+{
+ unsigned i, j;
+
+ for(i=0; i<compositor->nscreens; ++i)
+ for(j=0; j<compositor->screens[i].nmonitors; ++j)
+ if(!strcmp(compositor->screens[i].monitors[j].name, name))
+ {
+ if(screen)
+ *screen = &compositor->screens[i];
+ return &compositor->screens[i].monitors[j];
+ }
+
+ if(screen)
+ *screen = NULL;
+ return NULL;
+}
+
void update_geometry_correction(Compositor *compositor, CompositedScreen *screen)
{
Atom prop_type;
XFree(values);
}
+void update_root_pixmap(Compositor *compositor, CompositedScreen *screen)
+{
+ Atom prop_type;
+ int prop_format;
+ unsigned long overflow;
+ unsigned long length;
+ long *pixmap;
+ Window root;
+ int x, y;
+ unsigned width;
+ unsigned height;
+ unsigned border;
+ unsigned depth;
+
+ use_gl(compositor, screen);
+
+ if(screen->root_glx_pixmap)
+ {
+ glXDestroyPixmap(compositor->display, screen->root_glx_pixmap);
+ screen->root_glx_pixmap = None;
+ }
+
+ XGetWindowProperty(compositor->display, screen->root, compositor->root_pmap_atom, 0, 1, False, XA_PIXMAP,
+ &prop_type, &prop_format, &length, &overflow, (unsigned char **)&pixmap);
+ if(prop_type!=XA_PIXMAP || prop_format!=32)
+ {
+ screen->root_pixmap = None;
+ return;
+ }
+
+ screen->root_pixmap = pixmap[0];
+ if(XGetGeometry(compositor->display, screen->root_pixmap, &root, &x, &y, &width, &height, &border, &depth))
+ screen->root_glx_pixmap = pixmap_to_glx_pixmap(compositor, screen, screen->root_pixmap);
+ else
+ screen->root_pixmap = None;
+
+ XFree(pixmap);
+}
+
int initialize_screen(Compositor *compositor, unsigned number)
{
CompositedScreen *screen;
if(!initialize_gl(compositor, screen))
return 0;
- if(!create_gl_resources(compositor, screen))
+ use_gl(compositor, screen);
+
+ if(!create_gl_resources(screen))
return 0;
xrr_res = XRRGetScreenResources(compositor->display, screen->root);
return 0;
XRRFreeScreenResources(xrr_res);
+ screen->root_pixmap = None;
+ screen->root_glx_pixmap = None;
+
update_geometry_correction(compositor, screen);
+ update_root_pixmap(compositor, screen);
XQueryTree(compositor->display, screen->root, &dummy_root, &dummy_parent, &children, &nchildren);
compositor->glXBindTexImageEXT = (PFNGLXBINDTEXIMAGEEXTPROC)glXGetProcAddress((unsigned char *)"glXBindTexImageEXT");
compositor->glXReleaseTexImageEXT = (PFNGLXRELEASETEXIMAGEEXTPROC)glXGetProcAddress((unsigned char *)"glXReleaseTexImageEXT");
- compositor->correction_atom = XInternAtom(compositor->display, "GEOMETRY_CORRECTION", False);
- compositor->monitors_atom = XInternAtom(compositor->display, "GEOMETRY_CORRECTION_MONITORS", False);
+ compositor->root_pmap_atom = XInternAtom(compositor->display, "_XROOTPMAP_ID", False);
+ compositor->correction_atom = XInternAtom(compositor->display, "_MSP_GEOMETRY_CORRECTION", False);
+ compositor->monitors_atom = XInternAtom(compositor->display, "_MSP_GEOMETRY_CORRECTION_MONITORS", False);
+ compositor->geometry_data_atom = XInternAtom(compositor->display, "_MSP_GEOMETRY_CORRECTION_DATA", False);
compositor->nscreens = ScreenCount(compositor->display);
compositor->screens = (CompositedScreen *)malloc(compositor->nscreens*sizeof(CompositedScreen));
if(!initialize_screen(compositor, i))
return 0;
+ compositor->selection_window = XCreateWindow(compositor->display, compositor->screens[0].root, 0, 0, 1, 1, 0, CopyFromParent, InputOutput, CopyFromParent, 0, NULL);
+ XSetSelectionOwner(compositor->display, compositor->geometry_data_atom, compositor->selection_window, CurrentTime);
+
compositor->dirty = 1;
return 1;
glDeleteBuffers(1, &screen->monitors[i].index_buffer);
glDeleteVertexArrays(1, &screen->monitors[i].vertex_array);
}
+ if(screen->monitors[i].geometry_data)
+ free(screen->monitors[i].geometry_data);
}
+ glDeleteTextures(1, &screen->root_texture);
+ glXDestroyPixmap(compositor->display, screen->root_glx_pixmap);
+
glDeleteBuffers(1, &screen->window_vertex_buffer);
glDeleteVertexArrays(1, &screen->window_vertex_array);
glDeleteFramebuffers(1, &screen->framebuffer);
for(i=0; i<3; ++i)
glDeleteShader(screen->shaders[i]);
- glXMakeContextCurrent(compositor->display, 0, 0, NULL);
+ glXMakeContextCurrent(compositor->display, None, None, NULL);
glXDestroyContext(compositor->display, screen->glx_context);
glXDestroyWindow(compositor->display, screen->glx_window);
XDestroyWindow(compositor->display, screen->render_window);
shutdown_screen(compositor, &compositor->screens[i]);
free(compositor->screens);
+ XDestroyWindow(compositor->display, compositor->selection_window);
+
XCloseDisplay(compositor->display);
}
if((screen = find_screen_by_root(compositor, event->event)))
if((window = find_window(screen, event->window)))
+ {
+ use_gl(compositor, screen);
remove_window(compositor, screen, window, 1);
+ }
}
void process_map_event(Compositor *compositor, XMapEvent *event)
return;
window->map_state = IsViewable;
- create_window_pixmap(compositor, screen, window);
- update_window_mask(compositor, window);
+ window->recreate_pixmap = 1;
+ window->recreate_mask = 1;
mark_dirty(compositor, screen);
}
window->width = event->width;
window->height = event->height;
window->border = event->border_width;
- create_window_pixmap(compositor, screen, window);
- update_window_mask(compositor, window);
+ window->recreate_pixmap = 1;
}
reorder_window(screen, window, event->above);
{
CompositedScreen *screen;
- if(event->atom!=compositor->correction_atom)
- return;
-
screen = find_screen_by_root(compositor, event->window);
if(!screen)
return;
- update_geometry_correction(compositor, screen);
+ if(event->atom==compositor->correction_atom)
+ update_geometry_correction(compositor, screen);
+ else if(event->atom==compositor->root_pmap_atom)
+ update_root_pixmap(compositor, screen);
+}
+
+void process_selection_request_event(Compositor *compositor, XSelectionRequestEvent *event)
+{
+ Atom prop_type;
+ int prop_format;
+ unsigned long overflow;
+ unsigned long names_length;
+ XSelectionEvent notify;
+
+ if(event->selection==compositor->geometry_data_atom)
+ {
+ char *monitor_name;
+ CompositedMonitor *monitor;
+
+ XGetWindowProperty(compositor->display, event->requestor, event->property, 0, 64, False, XA_STRING,
+ &prop_type, &prop_format, &names_length, &overflow, (unsigned char **)&monitor_name);
+ if(prop_type!=XA_STRING || prop_format!=8)
+ return;
+
+ monitor = find_monitor_by_name_global(compositor, monitor_name, NULL);
+ if(monitor && monitor->enabled)
+ XChangeProperty(compositor->display, event->requestor, event->property, XA_INTEGER, 16, PropModeReplace, (unsigned char *)monitor->geometry_data, monitor->geometry_data_size);
+
+ notify.type = SelectionNotify;
+ notify.requestor = event->requestor;
+ notify.selection = event->selection;
+ notify.target = event->target;
+ notify.property = (monitor ? event->property : None);
+ notify.time = event->time;
+ XSendEvent(compositor->display, event->requestor, False, 0, (XEvent *)¬ify);
+ }
}
void process_damage_event(Compositor *compositor, XDamageNotifyEvent *event)
window = find_window_global(compositor, event->window, &screen);
if(window && window->map_state==IsViewable)
{
- update_window_mask(compositor, window);
+ window->recreate_mask = 1;
mark_dirty(compositor, screen);
}
}
case PropertyNotify:
process_property_event(compositor, &event.xproperty);
break;
+ case SelectionRequest:
+ process_selection_request_event(compositor, &event.xselectionrequest);
+ break;
default:
if(event.type==compositor->damage_event+XDamageNotify)
process_damage_event(compositor, (XDamageNotifyEvent *)&event);
unsigned i;
int use_mask;
+ for(i=0; i<screen->nwindows; ++i)
+ if(screen->windows[i].map_state==IsViewable)
+ XDamageSubtract(compositor->display, screen->windows[i].damage, None, None);
+ glXWaitX();
+
use_gl(compositor, screen);
+ glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, screen->framebuffer);
- glClearColor(0.5f, 0.5f, 0.5f, 0.0f);
- glClear(GL_COLOR_BUFFER_BIT);
-
use_mask = -1;
glBindVertexArray(screen->window_vertex_array);
+
+ if(screen->root_pixmap)
+ {
+ use_mask = 0;
+ glUseProgram(screen->program);
+ glBindTexture(GL_TEXTURE_2D, screen->root_texture);
+ compositor->glXBindTexImageEXT(compositor->display, screen->root_glx_pixmap, GLX_FRONT_LEFT_EXT, NULL);
+ glUniform4f(screen->geometry_loc, 0.0f, 0.0f, 1.0f, 1.0f);
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+ compositor->glXReleaseTexImageEXT(compositor->display, screen->root_glx_pixmap, GLX_FRONT_LEFT_EXT);
+ }
+ else
+ glClear(GL_COLOR_BUFFER_BIT);
+
for(i=0; i<screen->nwindows; ++i)
{
CompositedWindow *window;
glActiveTexture(GL_TEXTURE0);
}
- XDamageSubtract(compositor->display, window->damage, None, None);
+ if(window->recreate_pixmap)
+ create_window_pixmap(compositor, screen, window);
+ if(window->recreate_mask)
+ update_window_mask(compositor, window);
glBindTexture(GL_TEXTURE_2D, window->texture);
compositor->glXBindTexImageEXT(compositor->display, window->glx_pixmap, GLX_FRONT_LEFT_EXT, NULL);
}
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);