xglcomp

view 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 source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <X11/Xlib.h>
5 #include <X11/Xutil.h>
6 #include <X11/Xatom.h>
7 #include <X11/extensions/Xcomposite.h>
8 #include <X11/extensions/Xdamage.h>
9 #include <GL/glew.h>
10 #include "cwin.h"
11 #include "logger.h"
13 static bool register_compositor();
15 static Display *dpy;
16 static int scr;
17 static Window root_win;
18 static int root_width, root_height;
20 int main(int argc, char **argv)
21 {
22 if(!(dpy = XOpenDisplay(0))) {
23 log_error("failed to open X display\n");
24 return 1;
25 }
26 scr = DefaultScreen(dpy);
27 root_win = RootWindow(dpy, scr);
28 root_width = DisplayWidth(dpy, scr);
29 root_height = DisplayHeight(dpy, scr);
30 log_info("display size %dx%d\n", root_width, root_height);
32 int xcomp_ev_base, xcomp_err_base, xcomp_ver_major, xcomp_ver_minor;
33 if(!XCompositeQueryExtension(dpy, &xcomp_ev_base, &xcomp_err_base)) {
34 log_error("X server doesn't support the composite extension\n");
35 return 1;
36 }
37 XCompositeQueryVersion(dpy, &xcomp_ver_major, &xcomp_ver_minor);
38 log_info("Found composite extension version %d.%d\n", xcomp_ver_major, xcomp_ver_minor);
39 if(xcomp_ver_major <= 10 && xcomp_ver_minor < 2) {
40 log_error("I need at least version 1.2\n"); // for NameWindowPixmap
41 return 1;
42 }
44 int xdmg_ev_base, xdmg_err_base;
45 if(!XDamageQueryExtension(dpy, &xdmg_ev_base, &xdmg_err_base)) {
46 log_error("X server doesn't support the damage extension\n");
47 return 1;
48 }
49 // TODO also XFixes ?
51 if(!register_compositor()) {
52 return 1;
53 }
55 XGrabServer(dpy);
56 XCompositeRedirectSubwindows(dpy, root_win, CompositeRedirectAutomatic);
57 XUngrabServer(dpy);
59 for(;;) {
60 XEvent ev;
61 XNextEvent(dpy, &ev);
62 // TODO
63 }
64 }
66 static bool register_compositor()
67 {
68 char atom_name[64];
69 sprintf(atom_name, "_NET_WM_CM_S%d", scr);
70 Atom xa_wm_cm = XInternAtom(dpy, atom_name, False);
72 Window win = XGetSelectionOwner(dpy, xa_wm_cm);
73 if(win != None) {
74 log_error("Another compositor is running. Stop it and try again.\n");
75 return false;
76 }
78 win = XCreateSimpleWindow(dpy, root_win, 0, 0, 1, 1, 0, None, None);
79 XSetSelectionOwner(dpy, xa_wm_cm, win, 0);
80 return true;
81 }