From c742c97a8c68dc168cca8b135609eb1501ac3225 Mon Sep 17 00:00:00 2001 From: Richard Grenville Date: Wed, 1 May 2013 22:08:43 +0800 Subject: Misc: Validate wallpaper pixmap & Documentation update - Split Pixmap validation out to validate_pixmap(). Validate wallpaper Pixmap as well. - Update README.md and man page. --- compton.c | 28 ++++------------------------ compton.h | 28 ++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/compton.c b/compton.c index 82ee6c714..1111c190b 100644 --- a/compton.c +++ b/compton.c @@ -669,30 +669,6 @@ win_rounded_corners(session_t *ps, win *w) { cxfree(rects); } -/** - * Validate pixmap of a window, and destroy pixmap and picture if invalid. - */ -static void -win_validate_pixmap(session_t *ps, win *w) { - if (!w->paint.pixmap) - return; - - // Detect whether the pixmap is valid with XGetGeometry. Well, maybe there - // are better ways. - bool invalid = false; - { - Window rroot = None; - int rx = 0, ry = 0; - unsigned rwid = 0, rhei = 0, rborder = 0, rdepth = 0; - invalid = (!XGetGeometry(ps->dpy, w->paint.pixmap, &rroot, &rx, &ry, - &rwid, &rhei, &rborder, &rdepth) || !rwid || !rhei); - } - - // Destroy pixmap and picture, if invalid - if (invalid) - free_paint(ps, &w->paint); -} - /** * Add a pattern to a condition linked list. */ @@ -840,6 +816,10 @@ get_root_tile(session_t *ps) { free_winprop(&prop); } + // Make sure the pixmap we got is valid + if (pixmap && !validate_pixmap(ps, pixmap)) + pixmap = None; + // Create a pixmap if there isn't any if (!pixmap) { pixmap = XCreatePixmap(ps->dpy, ps->root, 1, 1, ps->depth); diff --git a/compton.h b/compton.h index b069620cf..2e4e3d130 100644 --- a/compton.h +++ b/compton.h @@ -443,8 +443,32 @@ win_is_fullscreen(session_t *ps, const win *w) { static void win_rounded_corners(session_t *ps, win *w); -static void -win_validate_pixmap(session_t *ps, win *w); +/** + * Validate a pixmap. + * + * Detect whether the pixmap is valid with XGetGeometry. Well, maybe there + * are better ways. + */ +static inline bool +validate_pixmap(session_t *ps, Pixmap pxmap) { + if (!pxmap) return false; + + Window rroot = None; + int rx = 0, ry = 0; + unsigned rwid = 0, rhei = 0, rborder = 0, rdepth = 0; + return XGetGeometry(ps->dpy, pxmap, &rroot, &rx, &ry, + &rwid, &rhei, &rborder, &rdepth) && rwid && rhei; +} + +/** + * Validate pixmap of a window, and destroy pixmap and picture if invalid. + */ +static inline void +win_validate_pixmap(session_t *ps, win *w) { + // Destroy pixmap and picture, if invalid + if (!validate_pixmap(ps, w->paint.pixmap)) + free_paint(ps, &w->paint); +} /** * Wrapper of c2_match(). -- cgit v1.2.1