diff --git a/src/common.h b/src/common.h index f6c8207..b8a032a 100644 --- a/src/common.h +++ b/src/common.h @@ -438,7 +438,7 @@ typedef struct { struct _glx_texture { GLuint texture; GLXPixmap glpixmap; - Pixmap pixmap; + xcb_pixmap_t pixmap; GLenum target; unsigned width; unsigned height; @@ -495,7 +495,7 @@ typedef uint32_t glx_prog_main_t; #endif typedef struct { - Pixmap pixmap; + xcb_pixmap_t pixmap; xcb_render_picture_t pict; glx_texture_t *ptex; } paint_t; @@ -2311,34 +2311,3 @@ wintype_arr_enable(bool arr[]) { arr[i] = true; } } - -/** - * Destroy a Pixmap. - */ -static inline void -free_pixmap(session_t *ps, Pixmap *p) { - if (*p) { - xcb_connection_t *c = XGetXCBConnection(ps->dpy); - xcb_free_pixmap(c, *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; -} diff --git a/src/compton.c b/src/compton.c index fc032a0..cb28029 100644 --- a/src/compton.c +++ b/src/compton.c @@ -667,7 +667,7 @@ win_build_shadow(session_t *ps, win *w, double opacity) { const int height = w->heightb; xcb_image_t *shadow_image = NULL; - Pixmap shadow_pixmap = None, shadow_pixmap_argb = None; + xcb_pixmap_t shadow_pixmap = None, shadow_pixmap_argb = None; xcb_render_picture_t shadow_picture = None, shadow_picture_argb = None; GC gc = None; xcb_connection_t *c = XGetXCBConnection(ps->dpy); @@ -678,8 +678,8 @@ win_build_shadow(session_t *ps, win *w, double opacity) { return None; } - shadow_pixmap = create_pixmap(ps, 8, ps->root, shadow_image->width, shadow_image->height); - shadow_pixmap_argb = create_pixmap(ps, 32, ps->root, shadow_image->width, shadow_image->height); + shadow_pixmap = x_create_pixmap(ps, 8, ps->root, shadow_image->width, shadow_image->height); + shadow_pixmap_argb = x_create_pixmap(ps, 32, ps->root, shadow_image->width, shadow_image->height); if (!shadow_pixmap || !shadow_pixmap_argb) { printf_errf("(): failed to create shadow pixmaps"); @@ -742,14 +742,14 @@ shadow_picture_err: static xcb_render_picture_t solid_picture(session_t *ps, bool argb, double a, double r, double g, double b) { - Pixmap pixmap; + xcb_pixmap_t pixmap; xcb_render_picture_t picture; xcb_render_create_picture_value_list_t pa; xcb_render_color_t col; xcb_rectangle_t rect; xcb_connection_t *c = XGetXCBConnection(ps->dpy); - pixmap = create_pixmap(ps, argb ? 32 : 8, ps->root, 1, 1); + pixmap = x_create_pixmap(ps, argb ? 32 : 8, ps->root, 1, 1); if (!pixmap) return None; pa.repeat = True; @@ -917,7 +917,7 @@ get_root_tile(session_t *ps) { ps->root_tile_fill = false; bool fill = false; - Pixmap pixmap = None; + xcb_pixmap_t pixmap = None; // Get the values of background attributes for (int p = 0; background_props_str[p]; p++) { @@ -939,7 +939,7 @@ get_root_tile(session_t *ps) { // Create a pixmap if there isn't any if (!pixmap) { - pixmap = create_pixmap(ps, ps->depth, ps->root, 1, 1); + pixmap = x_create_pixmap(ps, ps->depth, ps->root, 1, 1); if (pixmap == XCB_NONE) { fprintf(stderr, "Failed to create some pixmap\n"); exit(1); @@ -1719,7 +1719,7 @@ paint_all(session_t *ps, region_t *region, const region_t *region_real, win * co else { if (!ps->tgt_buffer.pixmap) { free_paint(ps, &ps->tgt_buffer); - ps->tgt_buffer.pixmap = create_pixmap(ps, ps->depth, ps->root, ps->root_width, ps->root_height); + ps->tgt_buffer.pixmap = x_create_pixmap(ps, ps->depth, ps->root, ps->root_width, ps->root_height); if (ps->tgt_buffer.pixmap == XCB_NONE) { fprintf(stderr, "Failed to allocate a screen-sized pixmap\n"); exit(1); diff --git a/src/compton.h b/src/compton.h index af225e5..bd32a11 100644 --- a/src/compton.h +++ b/src/compton.h @@ -197,9 +197,12 @@ free_texture(session_t *ps, glx_texture_t **t) { */ static inline void free_paint(session_t *ps, paint_t *ppaint) { + xcb_connection_t *c = XGetXCBConnection(ps->dpy); free_paint_glx(ps, ppaint); free_picture(ps, &ppaint->pict); - free_pixmap(ps, &ppaint->pixmap); + if (ppaint->pixmap) + xcb_free_pixmap(c, ppaint->pixmap); + ppaint->pixmap = XCB_NONE; } /** @@ -233,10 +236,13 @@ free_win_res(session_t *ps, win *w) { */ static inline void free_root_tile(session_t *ps) { + xcb_connection_t *c = XGetXCBConnection(ps->dpy); free_picture(ps, &ps->root_tile_paint.pict); free_texture(ps, &ps->root_tile_paint.ptex); - if (ps->root_tile_fill) - free_pixmap(ps, &ps->root_tile_paint.pixmap); + if (ps->root_tile_fill) { + xcb_free_pixmap(c, ps->root_tile_paint.pixmap); + ps->root_tile_paint.pixmap = XCB_NONE; + } ps->root_tile_paint.pixmap = None; ps->root_tile_fill = false; } @@ -392,7 +398,7 @@ dump_drawable(session_t *ps, Drawable drawable) { * are better ways. */ static inline bool -validate_pixmap(session_t *ps, Pixmap pxmap) { +validate_pixmap(session_t *ps, xcb_pixmap_t pxmap) { if (!pxmap) return false; Window rroot = None; diff --git a/src/opengl.c b/src/opengl.c index 3233f6b..470a5b0 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -727,14 +727,13 @@ glx_load_prog_main(session_t *ps, * Bind a X pixmap to an OpenGL texture. */ bool -glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, Pixmap pixmap, +glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap, unsigned width, unsigned height, unsigned depth) { if (ps->o.backend != BKEND_GLX) return true; if (!pixmap) { - printf_errf("(%#010lx): Binding to an empty pixmap. This can't work.", - pixmap); + printf_errf("(%#010x): Binding to an empty pixmap. This can't work.", pixmap); return false; } @@ -776,7 +775,7 @@ glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, Pixmap pixmap, unsigned rbdwid = 0; if (!XGetGeometry(ps->dpy, pixmap, &rroot, &rx, &ry, &width, &height, &rbdwid, &depth)) { - printf_errf("(%#010lx): Failed to query Pixmap info.", pixmap); + printf_errf("(%#010x): Failed to query Pixmap info.", pixmap); return false; } if (depth > OPENGL_MAX_DEPTH) { diff --git a/src/opengl.h b/src/opengl.h index 4757b4e..068cff7 100644 --- a/src/opengl.h +++ b/src/opengl.h @@ -156,7 +156,7 @@ glx_load_prog_main(session_t *ps, #endif bool -glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, Pixmap pixmap, +glx_bind_pixmap(session_t *ps, glx_texture_t **pptex, xcb_pixmap_t pixmap, unsigned width, unsigned height, unsigned depth); void @@ -169,7 +169,7 @@ __attribute__((nonnull(1, 2))); * Check if a texture is binded, or is binded to the given pixmap. */ static inline bool -glx_tex_binded(const glx_texture_t *ptex, Pixmap pixmap) { +glx_tex_binded(const glx_texture_t *ptex, xcb_pixmap_t pixmap) { return ptex && ptex->glpixmap && ptex->texture && (!pixmap || pixmap == ptex->pixmap); } diff --git a/src/x.c b/src/x.c index 183f952..b8188c7 100644 --- a/src/x.c +++ b/src/x.c @@ -200,13 +200,15 @@ x_create_picture(session_t *ps, int wid, int hei, int depth = pictfmt->depth; - Pixmap tmp_pixmap = create_pixmap(ps, depth, ps->root, wid, hei); + xcb_pixmap_t tmp_pixmap = x_create_pixmap(ps, depth, ps->root, wid, hei); if (!tmp_pixmap) return None; xcb_render_picture_t picture = x_create_picture_with_pictfmt_and_pixmap(ps, pictfmt, tmp_pixmap, valuemask, attr); - free_pixmap(ps, &tmp_pixmap); + + xcb_connection_t *c = XGetXCBConnection(ps->dpy); + xcb_free_pixmap(c, tmp_pixmap); return picture; } @@ -361,3 +363,21 @@ x_print_error(unsigned long serial, uint8_t major, uint8_t minor, uint8_t error_ // print_backtrace(); } + +/** + * Create a pixmap and check that creation succeeded. + */ +xcb_pixmap_t +x_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; +} diff --git a/src/x.h b/src/x.h index 6475555..f5508c0 100644 --- a/src/x.h +++ b/src/x.h @@ -96,3 +96,6 @@ void x_set_picture_clip_region(session_t *ps, xcb_render_picture_t, */ void x_print_error(unsigned long serial, uint8_t major, uint8_t minor, uint8_t error_code); + +xcb_pixmap_t +x_create_pixmap(session_t *ps, uint8_t depth, xcb_drawable_t drawable, uint16_t width, uint16_t height); diff --git a/src/xrescheck.h b/src/xrescheck.h index a783f8f..6933f29 100644 --- a/src/xrescheck.h +++ b/src/xrescheck.h @@ -56,7 +56,7 @@ xcb_composite_name_window_pixmap_(xcb_connection_t *c, xcb_window_t window, xcb_ xcb_composite_name_window_pixmap_(dpy, window, pixmap, M_POS_DATA) static inline void -xcb_free_pixmap_(xcb_connection_t *c, Pixmap pixmap, M_POS_DATA_PARAMS) { +xcb_free_pixmap_(xcb_connection_t *c, xcb_pixmap_t pixmap, M_POS_DATA_PARAMS) { xcb_free_pixmap(c, pixmap); xrc_delete_xid_(pixmap, M_POS_DATA_PASSTHROUGH); }