xglcomp

diff src/main.cc @ 1:b2b7cb950c28

window list and compositor registration
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 21 Jan 2016 22:50:10 +0200
parents d9b3fba68705
children 876efea9424c
line diff
     1.1 --- a/src/main.cc	Thu Jan 21 08:45:31 2016 +0200
     1.2 +++ b/src/main.cc	Thu Jan 21 22:50:10 2016 +0200
     1.3 @@ -5,5 +5,77 @@
     1.4  #include <X11/Xutil.h>
     1.5  #include <X11/Xatom.h>
     1.6  #include <X11/extensions/Xcomposite.h>
     1.7 +#include <X11/extensions/Xdamage.h>
     1.8  #include <GL/glew.h>
     1.9  #include "cwin.h"
    1.10 +#include "logger.h"
    1.11 +
    1.12 +static bool register_compositor();
    1.13 +
    1.14 +static Display *dpy;
    1.15 +static int scr;
    1.16 +static Window root_win;
    1.17 +static int root_width, root_height;
    1.18 +
    1.19 +int main(int argc, char **argv)
    1.20 +{
    1.21 +	if(!(dpy = XOpenDisplay(0))) {
    1.22 +		log_error("failed to open X display\n");
    1.23 +		return 1;
    1.24 +	}
    1.25 +	scr = DefaultScreen(dpy);
    1.26 +	root_win = RootWindow(dpy, scr);
    1.27 +	root_width = DisplayWidth(dpy, scr);
    1.28 +	root_height = DisplayHeight(dpy, scr);
    1.29 +	log_info("display size %dx%d\n", root_width, root_height);
    1.30 +
    1.31 +	int xcomp_ev_base, xcomp_err_base, xcomp_ver_major, xcomp_ver_minor;
    1.32 +	if(!XCompositeQueryExtension(dpy, &xcomp_ev_base, &xcomp_err_base)) {
    1.33 +		log_error("X server doesn't support the composite extension\n");
    1.34 +		return 1;
    1.35 +	}
    1.36 +	XCompositeQueryVersion(dpy, &xcomp_ver_major, &xcomp_ver_minor);
    1.37 +	log_info("Found composite extension version %d.%d\n", xcomp_ver_major, xcomp_ver_minor);
    1.38 +	if(xcomp_ver_major <= 10 && xcomp_ver_minor < 2) {
    1.39 +		log_error("I need at least version 1.2\n");	// for NameWindowPixmap
    1.40 +		return 1;
    1.41 +	}
    1.42 +
    1.43 +	int xdmg_ev_base, xdmg_err_base;
    1.44 +	if(!XDamageQueryExtension(dpy, &xdmg_ev_base, &xdmg_err_base)) {
    1.45 +		log_error("X server doesn't support the damage extension\n");
    1.46 +		return 1;
    1.47 +	}
    1.48 +	// TODO also XFixes ?
    1.49 +
    1.50 +	if(!register_compositor()) {
    1.51 +		return 1;
    1.52 +	}
    1.53 +
    1.54 +	XGrabServer(dpy);
    1.55 +	XCompositeRedirectSubwindows(dpy, root_win, CompositeRedirectAutomatic);
    1.56 +	XUngrabServer(dpy);
    1.57 +
    1.58 +	for(;;) {
    1.59 +		XEvent ev;
    1.60 +		XNextEvent(dpy, &ev);
    1.61 +		// TODO
    1.62 +	}
    1.63 +}
    1.64 +
    1.65 +static bool register_compositor()
    1.66 +{
    1.67 +	char atom_name[64];
    1.68 +	sprintf(atom_name, "_NET_WM_CM_S%d", scr);
    1.69 +	Atom xa_wm_cm = XInternAtom(dpy, atom_name, False);
    1.70 +
    1.71 +	Window win = XGetSelectionOwner(dpy, xa_wm_cm);
    1.72 +	if(win != None) {
    1.73 +		log_error("Another compositor is running. Stop it and try again.\n");
    1.74 +		return false;
    1.75 +	}
    1.76 +
    1.77 +	win = XCreateSimpleWindow(dpy, root_win, 0, 0, 1, 1, 0, None, None);
    1.78 +	XSetSelectionOwner(dpy, xa_wm_cm, win, 0);
    1.79 +	return true;
    1.80 +}