# HG changeset patch # User John Tsiombikas # Date 1453409410 -7200 # Node ID b2b7cb950c289a6ee88059538d43177100c5f001 # Parent d9b3fba68705de5151b6e5d60156d85ede73a7db window list and compositor registration diff -r d9b3fba68705 -r b2b7cb950c28 Makefile --- a/Makefile Thu Jan 21 08:45:31 2016 +0200 +++ b/Makefile Thu Jan 21 22:50:10 2016 +0200 @@ -12,8 +12,8 @@ incpaths = -Isrc/optcfg CFLAGS = $(warn) $(dbg) $(opt) $(incpaths) -CXXFLAGS = $(warn) $(dbg) $(opt) $(incpaths) -LDFLAGS = -lGL -lGLEW -lX11 -lXext -lXcomposite -lm +CXXFLAGS = -std=c++11 $(warn) $(dbg) $(opt) $(incpaths) +LDFLAGS = -lGL -lGLEW -lX11 -lXext -lXcomposite -lXdamage -lm -lpthread $(bin): $(obj) $(CXX) -o $@ $(obj) $(LDFLAGS) diff -r d9b3fba68705 -r b2b7cb950c28 src/cwin.cc --- a/src/cwin.cc Thu Jan 21 08:45:31 2016 +0200 +++ b/src/cwin.cc Thu Jan 21 22:50:10 2016 +0200 @@ -1,8 +1,9 @@ #include +#include #include "cwin.h" #include "logger.h" -static std::vector cwinlist; +static std::vector cwinlist; void add_window(CompWindow *cwin) { @@ -14,4 +15,54 @@ cwinlist.push_back(cwin); } -void delete_window( +bool delete_window(CompWindow *cwin) +{ + auto it = std::find(cwinlist.begin(), cwinlist.end(), cwin); + if(it != cwinlist.end()) { + cwinlist.erase(it); + return true; + } + return false; +} + +bool have_window(CompWindow *cwin) +{ + return std::find(cwinlist.begin(), cwinlist.end(), cwin) != cwinlist.end(); +} + +CompWindow *find_window_xid(Window xid) +{ + if(!xid) return 0; + + for(size_t i=0; ixwin == xid) { + return cwinlist[i]; + } + } + return 0; +} + +CompWindow *find_window_pixmap(Pixmap pix) +{ + if(!pix) return 0; + + for(size_t i=0; ixpixmap == pix) { + return cwinlist[i]; + } + } + return 0; +} + +int get_window_count() +{ + return (int)cwinlist.size(); +} + +CompWindow *get_window(int idx) +{ + if(idx < 0 || idx >= (int)cwinlist.size()) { + return 0; + } + return cwinlist[idx]; +} diff -r d9b3fba68705 -r b2b7cb950c28 src/cwin.h --- a/src/cwin.h Thu Jan 21 08:45:31 2016 +0200 +++ b/src/cwin.h Thu Jan 21 22:50:10 2016 +0200 @@ -11,9 +11,10 @@ }; void add_window(CompWindow *cwin); -void delete_window(CompWindow *cwin); +bool delete_window(CompWindow *cwin); bool have_window(CompWindow *cwin); CompWindow *find_window_xid(Window xid); +CompWindow *find_window_pixmap(Pixmap pix); int get_window_count(); CompWindow *get_window(int idx); diff -r d9b3fba68705 -r b2b7cb950c28 src/main.cc --- a/src/main.cc Thu Jan 21 08:45:31 2016 +0200 +++ b/src/main.cc Thu Jan 21 22:50:10 2016 +0200 @@ -5,5 +5,77 @@ #include #include #include +#include #include #include "cwin.h" +#include "logger.h" + +static bool register_compositor(); + +static Display *dpy; +static int scr; +static Window root_win; +static int root_width, root_height; + +int main(int argc, char **argv) +{ + if(!(dpy = XOpenDisplay(0))) { + log_error("failed to open X display\n"); + return 1; + } + scr = DefaultScreen(dpy); + root_win = RootWindow(dpy, scr); + root_width = DisplayWidth(dpy, scr); + root_height = DisplayHeight(dpy, scr); + log_info("display size %dx%d\n", root_width, root_height); + + int xcomp_ev_base, xcomp_err_base, xcomp_ver_major, xcomp_ver_minor; + if(!XCompositeQueryExtension(dpy, &xcomp_ev_base, &xcomp_err_base)) { + log_error("X server doesn't support the composite extension\n"); + return 1; + } + XCompositeQueryVersion(dpy, &xcomp_ver_major, &xcomp_ver_minor); + log_info("Found composite extension version %d.%d\n", xcomp_ver_major, xcomp_ver_minor); + if(xcomp_ver_major <= 10 && xcomp_ver_minor < 2) { + log_error("I need at least version 1.2\n"); // for NameWindowPixmap + return 1; + } + + int xdmg_ev_base, xdmg_err_base; + if(!XDamageQueryExtension(dpy, &xdmg_ev_base, &xdmg_err_base)) { + log_error("X server doesn't support the damage extension\n"); + return 1; + } + // TODO also XFixes ? + + if(!register_compositor()) { + return 1; + } + + XGrabServer(dpy); + XCompositeRedirectSubwindows(dpy, root_win, CompositeRedirectAutomatic); + XUngrabServer(dpy); + + for(;;) { + XEvent ev; + XNextEvent(dpy, &ev); + // TODO + } +} + +static bool register_compositor() +{ + char atom_name[64]; + sprintf(atom_name, "_NET_WM_CM_S%d", scr); + Atom xa_wm_cm = XInternAtom(dpy, atom_name, False); + + Window win = XGetSelectionOwner(dpy, xa_wm_cm); + if(win != None) { + log_error("Another compositor is running. Stop it and try again.\n"); + return false; + } + + win = XCreateSimpleWindow(dpy, root_win, 0, 0, 1, 1, 0, None, None); + XSetSelectionOwner(dpy, xa_wm_cm, win, 0); + return true; +}