X-Git-Url: http://pileus.org/git/?p=wmpus;a=blobdiff_plain;f=sys-x11.c;h=02e90a808a0ae675fe5314399f8bcd9e3f5937c4;hp=7222b462141d7f5eb5a38b22ca62ef6585bdeaff;hb=ed3dbd05944250855712283a1c10419bf15f7c12;hpb=43cb9b7de22dac5864d73321ec974bb937a217ff diff --git a/sys-x11.c b/sys-x11.c index 7222b46..02e90a8 100644 --- a/sys-x11.c +++ b/sys-x11.c @@ -13,6 +13,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF */ +#define _GNU_SOURCE #include #include #include @@ -24,12 +25,13 @@ #include #include "util.h" +#include "conf.h" #include "sys.h" #include "wm.h" -#ifndef BORDER -#define BORDER 2 -#endif +/* Configuration */ +static int BORDER = 2; +static int NO_CAPTURE = 0; /* Internal structures */ struct win_sys { @@ -242,13 +244,18 @@ static win_t *win_find(Display *dpy, Window xid, int create) return new; } -static void win_remove(win_t *win) +static void win_free(win_t *win) { - tdelete(win, &cache, win_cmp); free(win->sys); free(win); } +static void win_remove(win_t *win) +{ + tdelete(win, &cache, win_cmp); + win_free(win); +} + static int win_viewable(win_t *win) { XWindowAttributes attr; @@ -457,6 +464,7 @@ void sys_show(win_t *win, state_t state) case st_show: printf("sys_show: show\n"); XMapWindow(win->sys->dpy, win->sys->xid); + XSync(win->sys->dpy, False); return; case st_full: printf("sys_show: full\n"); @@ -505,15 +513,11 @@ list_t *sys_info(win_t *win) { /* Use global copy of screens so we can add struts */ if (screens == NULL) { - int n; + /* Add Xinerama screens */ + int n = 0; XineramaScreenInfo *info = NULL; if (XineramaIsActive(win->sys->dpy)) info = XineramaQueryScreens(win->sys->dpy, &n); - if (!info) { - win_t *screen = new0(win_t); - *screen = *win; - return list_insert(NULL, screen); - } for (int i = 0; i < n; i++) { win_t *screen = new0(win_t); screen->x = info[i].x_org; @@ -523,6 +527,12 @@ list_t *sys_info(win_t *win) screens = list_append(screens, screen); } } + if (screens == NULL) { + /* No xinerama support */ + win_t *screen = new0(win_t); + *screen = *win; + screens = list_insert(NULL, screen); + } return screens; } @@ -531,6 +541,10 @@ win_t *sys_init(void) Display *dpy; Window xid; + /* Load configuration */ + BORDER = conf_get_int("main.border", BORDER); + NO_CAPTURE = conf_get_int("main.no-capture", NO_CAPTURE); + /* Open the display */ if (!(dpy = XOpenDisplay(NULL))) error("Unable to get display"); @@ -558,16 +572,20 @@ win_t *sys_init(void) void sys_run(win_t *root) { /* Add each initial window */ - unsigned int nkids; - Window par, xid, *kids = NULL; - if (XQueryTree(root->sys->dpy, root->sys->xid, - &par, &xid, &kids, &nkids)) - for(int i = 0; i < nkids; i++) { - win_t *win = win_find(root->sys->dpy, kids[i], 1); - if (win && win_viewable(win) && !strut_add(root,win)) - wm_insert(win); + if (!NO_CAPTURE) { + unsigned int nkids; + Window par, xid, *kids = NULL; + if (XQueryTree(root->sys->dpy, root->sys->xid, + &par, &xid, &kids, &nkids)) { + for(int i = 0; i < nkids; i++) { + win_t *win = win_find(root->sys->dpy, kids[i], 1); + if (win && win_viewable(win) && !strut_add(root,win)) + wm_insert(win); + } + XFree(kids); } - wm_update(); // For struts + wm_update(); // For struts + } /* Main loop */ running = 1; @@ -583,3 +601,11 @@ void sys_exit(void) { running = 0; } + +void sys_free(win_t *root) +{ + XCloseDisplay(root->sys->dpy); + while (screens) + screens = list_remove(screens, screens, 1); + tdestroy(cache, (void(*)(void*))win_free); +}