#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <signal.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xcomposite.h>
#include <X11/extensions/Xdamage.h>
1.0f, 0.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);
void shutdown_screen(Compositor *compositor, CompositedScreen *screen)
{
+ unsigned i;
+
+ use_gl(compositor, screen);
+
+ for(i=0; i<screen->nwindows; ++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);
+ }
+ }
+
+ 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);
}
void shutdown_compositor(Compositor *compositor)
{
unsigned i;
- glXMakeContextCurrent(compositor->display, 0, 0, NULL);
for(i=0; i<compositor->nscreens; ++i)
shutdown_screen(compositor, &compositor->screens[i]);
+ free(compositor->screens);
+
+ XCloseDisplay(compositor->display);
}
void process_create_window_event(Compositor *compositor, XCreateWindowEvent *event)
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);