Add a function that allocates a pixmap and checks success

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter
2018-09-30 09:31:22 +02:00
parent 6ec951763e
commit 8848676540
3 changed files with 37 additions and 15 deletions

View File

@ -1251,6 +1251,9 @@ extern session_t *ps_g;
static inline void
print_timestamp(session_t *ps);
void
ev_xcb_error(session_t *ps, xcb_generic_error_t *err);
#ifdef DEBUG_BACKTRACE
#include <execinfo.h>
@ -2530,3 +2533,22 @@ free_pixmap(session_t *ps, Pixmap *p) {
*p = None;
}
}
/**
* Create a pixmap and check that creation succeeded.
*/
static inline xcb_pixmap_t
create_pixmap(session_t *ps, uint8_t depth, xcb_drawable_t drawable, uint16_t width, uint16_t height)
{
xcb_connection_t *c = XGetXCBConnection(ps->dpy);
xcb_pixmap_t pix = xcb_generate_id(c);
xcb_void_cookie_t cookie = xcb_create_pixmap_checked(c, depth, pix, drawable, width, height);
xcb_generic_error_t *err = xcb_request_check(c, cookie);
if (err == NULL)
return pix;
printf_err("Failed to create pixmap:");
ev_xcb_error(ps, err);
free(err);
return XCB_NONE;
}