unsigned nscreens;
int damage_event;
int shape_event;
+ int randr_event;
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB;
PFNGLXBINDTEXIMAGEEXTPROC glXBindTexImageEXT;
PFNGLXRELEASETEXIMAGEEXTPROC glXReleaseTexImageEXT;
return NULL;
}
+void create_geometry_correction(CompositedMonitor *monitor)
+{
+ unsigned buffers[2];
+ unsigned stride;
+
+ glGenBuffers(2, buffers);
+ monitor->vertex_buffer = buffers[0];
+ 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));
+ 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);
+}
+
+void free_geometry_correction(CompositedMonitor *monitor)
+{
+ unsigned buffers[2];
+
+ buffers[0] = monitor->vertex_buffer;
+ buffers[1] = monitor->index_buffer;
+ glDeleteBuffers(2, buffers);
+ monitor->vertex_buffer = 0;
+ monitor->index_buffer = 0;
+
+ glDeleteVertexArrays(1, &monitor->vertex_array);
+
+ free(monitor->geometry_data);
+ monitor->geometry_data = 0;
+}
+
void update_monitor_vertices(CompositedScreen *screen, CompositedMonitor *monitor)
{
unsigned t;
XRROutputInfo *output;
int namelen;
XRRCrtcInfo *crtc;
- unsigned buffers[2];
- unsigned stride;
monitor = &screen->monitors[index];
if(!monitor->enabled)
{
XRRFreeOutputInfo(output);
+ monitor->vertex_buffer = 0;
+ monitor->index_buffer = 0;
+ monitor->vertex_array = 0;
monitor->geometry_data = NULL;
return 1;
}
monitor->vertical_center = 0.5f;
monitor->perspective = 1.0f;
- glGenBuffers(2, buffers);
- monitor->vertex_buffer = buffers[0];
- 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));
+ create_geometry_correction(monitor);
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;
}
return NULL;
}
+void update_monitors(Compositor *compositor, CompositedScreen *screen)
+{
+ XRRScreenResources *xrr_res;
+ int i;
+
+ xrr_res = XRRGetScreenResources(compositor->display, screen->root);
+ for(i=0; i<xrr_res->noutput; ++i)
+ {
+ XRROutputInfo *output;
+ CompositedMonitor *monitor;
+ int was_enabled;
+ XRRCrtcInfo *crtc;
+
+ output = XRRGetOutputInfo(compositor->display, xrr_res, xrr_res->outputs[i]);
+ monitor = find_monitor_by_name(screen, output->name);
+ if(!monitor)
+ continue;
+
+ was_enabled = monitor->enabled;
+ monitor->enabled = !!output->crtc;
+ if(!monitor->enabled)
+ {
+ XRRFreeOutputInfo(output);
+ if(was_enabled)
+ free_geometry_correction(monitor);
+ continue;
+ }
+
+ 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);
+
+ if(!was_enabled)
+ create_geometry_correction(monitor);
+
+ update_monitor_vertices(screen, monitor);
+ }
+ XRRFreeScreenResources(xrr_res);
+}
+
void update_geometry_correction(Compositor *compositor, CompositedScreen *screen)
{
Atom prop_type;
screen->root = RootWindow(compositor->display, screen->number);
XSelectInput(compositor->display, screen->root, SubstructureNotifyMask|PropertyChangeMask);
screen->overlay = XCompositeGetOverlayWindow(compositor->display, screen->root);
+ XSelectInput(compositor->display, screen->overlay, StructureNotifyMask);
XGetGeometry(compositor->display, screen->overlay, &dummy_root, &x, &y, &screen->width, &screen->height, &border, &depth);
XShapeCombineRectangles(compositor->display, screen->overlay, ShapeInput, 0, 0, NULL, 0, ShapeSet, Unsorted);
if(!initialize_monitor(compositor, screen, xrr_res, i))
return 0;
XRRFreeScreenResources(xrr_res);
+ XRRSelectInput(compositor->display, screen->root, RRScreenChangeNotifyMask);
screen->root_pixmap = None;
screen->root_glx_pixmap = None;
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))
+ if(!XRRQueryExtension(compositor->display, &compositor->randr_event, &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");
{
free(screen->monitors[i].name);
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);
- }
- if(screen->monitors[i].geometry_data)
- free(screen->monitors[i].geometry_data);
+ free_geometry_correction(&screen->monitors[i]);
}
glDeleteTextures(1, &screen->root_texture);
if(!screen)
return;
+ if(event->window==screen->overlay)
+ {
+ screen->width = event->width;
+ screen->height = event->height;
+
+ XResizeWindow(compositor->display, screen->render_window, screen->width, screen->height);
+ use_gl(compositor, screen);
+ 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);
+ glBindTexture(GL_TEXTURE_2D, 0);
+ return;
+ }
+
window = find_window(screen, event->window);
if(!window)
return;
}
}
+void process_randr_event(Compositor *compositor, XRRScreenChangeNotifyEvent *event)
+{
+ CompositedScreen *screen;
+
+ if((screen = find_screen_by_root(compositor, event->root)))
+ update_monitors(compositor, screen);
+}
+
void process_events(Compositor *compositor)
{
int pending;
process_damage_event(compositor, (XDamageNotifyEvent *)&event);
else if(event.type==compositor->shape_event+ShapeNotify)
process_shape_event(compositor, (XShapeEvent *)&event);
+ else if(event.type==compositor->randr_event+RRScreenChangeNotify)
+ process_randr_event(compositor, (XRRScreenChangeNotifyEvent *)&event);
}
}
}
use_gl(compositor, screen);
+ glViewport(0, 0, screen->width, screen->height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, screen->framebuffer);