Eliminate implicit conversions
Use explicit conversions everywhere. Adding bounds check assertions when necessary. Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
79
src/x.c
79
src/x.c
@ -38,18 +38,21 @@
|
||||
* and number of items. A blank one on failure.
|
||||
*/
|
||||
winprop_t wid_get_prop_adv(const session_t *ps, xcb_window_t w, xcb_atom_t atom,
|
||||
long offset, long length, xcb_atom_t rtype, int rformat) {
|
||||
int offset, int length, xcb_atom_t rtype, int rformat) {
|
||||
xcb_get_property_reply_t *r = xcb_get_property_reply(
|
||||
ps->c, xcb_get_property(ps->c, 0, w, atom, rtype, offset, length), NULL);
|
||||
ps->c,
|
||||
xcb_get_property(ps->c, 0, w, atom, rtype, to_u32_checked(offset),
|
||||
to_u32_checked(length)),
|
||||
NULL);
|
||||
|
||||
if (r && xcb_get_property_value_length(r) &&
|
||||
(rtype == XCB_GET_PROPERTY_TYPE_ANY || r->type == rtype) &&
|
||||
(!rformat || r->format == rformat) &&
|
||||
(r->format == 8 || r->format == 16 || r->format == 32)) {
|
||||
int len = xcb_get_property_value_length(r);
|
||||
auto len = xcb_get_property_value_length(r);
|
||||
return (winprop_t){
|
||||
.ptr = xcb_get_property_value(r),
|
||||
.nitems = len / (r->format / 8),
|
||||
.nitems = (ulong)(len / (r->format / 8)),
|
||||
.type = r->type,
|
||||
.format = r->format,
|
||||
.r = r,
|
||||
@ -73,7 +76,7 @@ xcb_window_t wid_get_prop_window(session_t *ps, xcb_window_t wid, xcb_atom_t apr
|
||||
|
||||
// Return it
|
||||
if (prop.nitems) {
|
||||
p = *prop.p32;
|
||||
p = (xcb_window_t)*prop.p32;
|
||||
}
|
||||
|
||||
free_winprop(&prop);
|
||||
@ -182,7 +185,7 @@ int x_get_visual_depth(xcb_connection_t *c, xcb_visualid_t visual) {
|
||||
xcb_render_picture_t
|
||||
x_create_picture_with_pictfmt_and_pixmap(xcb_connection_t *c,
|
||||
const xcb_render_pictforminfo_t *pictfmt,
|
||||
xcb_pixmap_t pixmap, unsigned long valuemask,
|
||||
xcb_pixmap_t pixmap, uint32_t valuemask,
|
||||
const xcb_render_create_picture_value_list_t *attr) {
|
||||
void *buf = NULL;
|
||||
if (attr) {
|
||||
@ -208,7 +211,7 @@ x_create_picture_with_pictfmt_and_pixmap(xcb_connection_t *c,
|
||||
|
||||
xcb_render_picture_t
|
||||
x_create_picture_with_visual_and_pixmap(xcb_connection_t *c, xcb_visualid_t visual,
|
||||
xcb_pixmap_t pixmap, unsigned long valuemask,
|
||||
xcb_pixmap_t pixmap, uint32_t valuemask,
|
||||
const xcb_render_create_picture_value_list_t *attr) {
|
||||
const xcb_render_pictforminfo_t *pictfmt = x_get_pictform_for_visual(c, visual);
|
||||
return x_create_picture_with_pictfmt_and_pixmap(c, pictfmt, pixmap, valuemask, attr);
|
||||
@ -216,7 +219,7 @@ x_create_picture_with_visual_and_pixmap(xcb_connection_t *c, xcb_visualid_t visu
|
||||
|
||||
xcb_render_picture_t
|
||||
x_create_picture_with_standard_and_pixmap(xcb_connection_t *c, xcb_pict_standard_t standard,
|
||||
xcb_pixmap_t pixmap, unsigned long valuemask,
|
||||
xcb_pixmap_t pixmap, uint32_t valuemask,
|
||||
const xcb_render_create_picture_value_list_t *attr) {
|
||||
x_get_server_pictfmts(c);
|
||||
|
||||
@ -229,12 +232,12 @@ x_create_picture_with_standard_and_pixmap(xcb_connection_t *c, xcb_pict_standard
|
||||
* Create an picture.
|
||||
*/
|
||||
xcb_render_picture_t
|
||||
x_create_picture_with_pictfmt(xcb_connection_t *c, xcb_drawable_t d, int wid, int hei,
|
||||
const xcb_render_pictforminfo_t *pictfmt, unsigned long valuemask,
|
||||
x_create_picture_with_pictfmt(xcb_connection_t *c, xcb_drawable_t d, int w, int h,
|
||||
const xcb_render_pictforminfo_t *pictfmt, uint32_t valuemask,
|
||||
const xcb_render_create_picture_value_list_t *attr) {
|
||||
int depth = pictfmt->depth;
|
||||
uint8_t depth = pictfmt->depth;
|
||||
|
||||
xcb_pixmap_t tmp_pixmap = x_create_pixmap(c, depth, d, wid, hei);
|
||||
xcb_pixmap_t tmp_pixmap = x_create_pixmap(c, depth, d, w, h);
|
||||
if (!tmp_pixmap)
|
||||
return XCB_NONE;
|
||||
|
||||
@ -248,7 +251,7 @@ x_create_picture_with_pictfmt(xcb_connection_t *c, xcb_drawable_t d, int wid, in
|
||||
|
||||
xcb_render_picture_t
|
||||
x_create_picture_with_visual(xcb_connection_t *c, xcb_drawable_t d, int w, int h,
|
||||
xcb_visualid_t visual, unsigned long valuemask,
|
||||
xcb_visualid_t visual, uint32_t valuemask,
|
||||
const xcb_render_create_picture_value_list_t *attr) {
|
||||
auto pictfmt = x_get_pictform_for_visual(c, visual);
|
||||
return x_create_picture_with_pictfmt(c, d, w, h, pictfmt, valuemask, attr);
|
||||
@ -279,21 +282,22 @@ bool x_fetch_region(xcb_connection_t *c, xcb_xfixes_region_t r, pixman_region32_
|
||||
}
|
||||
|
||||
void x_set_picture_clip_region(xcb_connection_t *c, xcb_render_picture_t pict,
|
||||
int clip_x_origin, int clip_y_origin, const region_t *reg) {
|
||||
int16_t clip_x_origin, int16_t clip_y_origin,
|
||||
const region_t *reg) {
|
||||
int nrects;
|
||||
const rect_t *rects = pixman_region32_rectangles((region_t *)reg, &nrects);
|
||||
auto xrects = ccalloc(nrects, xcb_rectangle_t);
|
||||
for (int i = 0; i < nrects; i++)
|
||||
xrects[i] = (xcb_rectangle_t){
|
||||
.x = rects[i].x1,
|
||||
.y = rects[i].y1,
|
||||
.width = rects[i].x2 - rects[i].x1,
|
||||
.height = rects[i].y2 - rects[i].y1,
|
||||
.x = to_i16_checked(rects[i].x1),
|
||||
.y = to_i16_checked(rects[i].y1),
|
||||
.width = to_u16_checked(rects[i].x2 - rects[i].x1),
|
||||
.height = to_u16_checked(rects[i].y2 - rects[i].y1),
|
||||
};
|
||||
|
||||
xcb_generic_error_t *e =
|
||||
xcb_request_check(c, xcb_render_set_picture_clip_rectangles_checked(
|
||||
c, pict, clip_x_origin, clip_y_origin, nrects, xrects));
|
||||
xcb_generic_error_t *e = xcb_request_check(
|
||||
c, xcb_render_set_picture_clip_rectangles_checked(
|
||||
c, pict, clip_x_origin, clip_y_origin, to_u32_checked(nrects), xrects));
|
||||
if (e)
|
||||
log_error("Failed to set clip region");
|
||||
free(e);
|
||||
@ -321,7 +325,7 @@ enum { XSyncBadCounter = 0,
|
||||
*
|
||||
* XXX consider making this error to string
|
||||
*/
|
||||
void x_print_error(unsigned long serial, uint8_t major, uint8_t minor, uint8_t error_code) {
|
||||
void x_print_error(unsigned long serial, uint8_t major, uint16_t minor, uint8_t error_code) {
|
||||
session_t *const ps = ps_g;
|
||||
|
||||
int o = 0;
|
||||
@ -405,10 +409,10 @@ void x_print_error(unsigned long serial, uint8_t major, uint8_t minor, uint8_t e
|
||||
* Create a pixmap and check that creation succeeded.
|
||||
*/
|
||||
xcb_pixmap_t x_create_pixmap(xcb_connection_t *c, uint8_t depth, xcb_drawable_t drawable,
|
||||
uint16_t width, uint16_t height) {
|
||||
int width, int height) {
|
||||
xcb_pixmap_t pix = xcb_generate_id(c);
|
||||
xcb_void_cookie_t cookie =
|
||||
xcb_create_pixmap_checked(c, depth, pix, drawable, width, height);
|
||||
xcb_void_cookie_t cookie = xcb_create_pixmap_checked(
|
||||
c, depth, pix, drawable, to_u16_checked(width), to_u16_checked(height));
|
||||
xcb_generic_error_t *err = xcb_request_check(c, cookie);
|
||||
if (err == NULL)
|
||||
return pix;
|
||||
@ -456,7 +460,7 @@ xcb_pixmap_t x_get_root_back_pixmap(session_t *ps) {
|
||||
winprop_t prop =
|
||||
wid_get_prop(ps, ps->root, prop_atom, 1, XCB_ATOM_PIXMAP, 32);
|
||||
if (prop.nitems) {
|
||||
pixmap = *prop.p32;
|
||||
pixmap = (xcb_pixmap_t)*prop.p32;
|
||||
free_winprop(&prop);
|
||||
break;
|
||||
}
|
||||
@ -523,10 +527,10 @@ bool x_fence_sync(xcb_connection_t *c, xcb_sync_fence_t f) {
|
||||
* @param[inout] size size of the array pointed to by `ret`, in number of elements
|
||||
* @return number of elements filled into `*ret`
|
||||
*/
|
||||
size_t x_picture_filter_from_conv(const conv *kernel, double center,
|
||||
xcb_render_fixed_t **ret, size_t *size) {
|
||||
int x_picture_filter_from_conv(const conv *kernel, double center,
|
||||
xcb_render_fixed_t **ret, size_t *size) {
|
||||
if (*size < (size_t)(kernel->w * kernel->h + 2)) {
|
||||
*size = kernel->w * kernel->h + 2;
|
||||
*size = (size_t)(kernel->w * kernel->h + 2);
|
||||
*ret = crealloc(*ret, *size);
|
||||
}
|
||||
auto buf = *ret;
|
||||
@ -550,18 +554,18 @@ size_t x_picture_filter_from_conv(const conv *kernel, double center,
|
||||
}
|
||||
|
||||
/// Generate a search criteria for fbconfig from a X visual.
|
||||
/// Returns {-1, -1, -1, -1, -1, -1} on failure
|
||||
/// Returns {-1, -1, -1, -1, -1, 0} on failure
|
||||
struct xvisual_info x_get_visual_info(xcb_connection_t *c, xcb_visualid_t visual) {
|
||||
auto pictfmt = x_get_pictform_for_visual(c, visual);
|
||||
auto depth = x_get_visual_depth(c, visual);
|
||||
if (!pictfmt || depth == -1) {
|
||||
log_error("Invalid visual %#03x", visual);
|
||||
return (struct xvisual_info){-1, -1, -1, -1, -1, -1};
|
||||
return (struct xvisual_info){-1, -1, -1, -1, -1, 0};
|
||||
}
|
||||
if (pictfmt->type != XCB_RENDER_PICT_TYPE_DIRECT) {
|
||||
log_error("compton cannot handle non-DirectColor visuals. Report an "
|
||||
"issue if you see this error message.");
|
||||
return (struct xvisual_info){-1, -1, -1, -1, -1, -1};
|
||||
return (struct xvisual_info){-1, -1, -1, -1, -1, 0};
|
||||
}
|
||||
|
||||
int red_size = popcountl(pictfmt->direct.red_mask),
|
||||
@ -578,3 +582,14 @@ struct xvisual_info x_get_visual_info(xcb_connection_t *c, xcb_visualid_t visual
|
||||
.visual = visual,
|
||||
};
|
||||
}
|
||||
|
||||
xcb_screen_t *x_screen_of_display(xcb_connection_t *c, int screen) {
|
||||
xcb_screen_iterator_t iter;
|
||||
|
||||
iter = xcb_setup_roots_iterator(xcb_get_setup(c));
|
||||
for (; iter.rem; --screen, xcb_screen_next(&iter))
|
||||
if (screen == 0)
|
||||
return iter.data;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user