X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=sys-x11.c;h=6c43780979ef3491dc96d380867453721ea959c7;hb=cbc34d3fb6dc1db9b0e33fd8f92c14805ba4fde2;hp=a5ae667f6e3e794676df052921ad6c54a03a8988;hpb=a6f2be4a52a3dd478c0640714c5be9c5cf87c64e;p=wmpus diff --git a/sys-x11.c b/sys-x11.c index a5ae667..6c43780 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 @@ -55,6 +56,7 @@ typedef enum { } color_t; /* Global data */ +static int running; static void *cache; static Atom atoms[natoms]; static int (*xerrorxlib)(Display *, XErrorEvent *); @@ -241,13 +243,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; @@ -275,7 +282,7 @@ static void process_event(int type, XEvent *ev, win_t *root) //printf("event: %d\n", type); /* Common data for all these events ... */ - ptr_t ptr; mod_t mod; + ptr_t ptr = {}; mod_t mod = {}; if (type == KeyPress || type == KeyRelease || type == ButtonPress || type == ButtonRelease || type == MotionNotify) { @@ -456,6 +463,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"); @@ -504,15 +512,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; @@ -522,6 +526,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; } @@ -560,19 +570,35 @@ void sys_run(win_t *root) unsigned int nkids; Window par, xid, *kids = NULL; if (XQueryTree(root->sys->dpy, root->sys->xid, - &par, &xid, &kids, &nkids)) + &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 /* Main loop */ - for(;;) + running = 1; + while (running) { XEvent ev; XNextEvent(root->sys->dpy, &ev); process_event(ev.type, &ev, root); } } + +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); +}