X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fxcb.c;h=c5a3aa061add1c9bf5d6f6694b9ad245f7e48084;hb=26944bea991c712adbe6774d822b9cefc785b7d9;hp=b445437ac782caca488978af4a04f11e1f81a13d;hpb=82dd64ff241b2dc376f44cea4e174a5face7c19d;p=i3%2Fi3 diff --git a/src/xcb.c b/src/xcb.c index b445437a..c5a3aa06 100644 --- a/src/xcb.c +++ b/src/xcb.c @@ -1,9 +1,20 @@ +/* + * vim:ts=8:expandtab + * + * i3 - an improved dynamic tiling window manager + * + * (c) 2009 Michael Stapelberg and contributors + * + * See file LICENSE for license information. + * + */ #include #include #include #include /* All the helper functions needed for efficiently using XCB */ +#include "util.h" /* * Returns the colorpixel to use for the given hex color (think of HTML). @@ -15,28 +26,31 @@ * */ uint32_t get_colorpixel(xcb_connection_t *conn, xcb_window_t window, char *hex) { - #define RGB_8_TO_16(i) (65535 * ((i) & 0xFF) / 255) + /* TODO: We need to store the colorpixels per child to remove these unnecessary requests every time */ + #define RGB_8_TO_16(i) (65535 * ((i) & 0xFF) / 255) char strgroups[3][3] = {{hex[1], hex[2], '\0'}, {hex[3], hex[4], '\0'}, {hex[5], hex[6], '\0'}}; - int rgb16[3] = {RGB_8_TO_16(strtol(strgroups[0], NULL, 16)), - RGB_8_TO_16(strtol(strgroups[1], NULL, 16)), - RGB_8_TO_16(strtol(strgroups[2], NULL, 16))}; + int rgb16[3] = {RGB_8_TO_16(strtol(strgroups[0], NULL, 16)), + RGB_8_TO_16(strtol(strgroups[1], NULL, 16)), + RGB_8_TO_16(strtol(strgroups[2], NULL, 16))}; - xcb_screen_t *root_screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data; + xcb_screen_t *root_screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data; - xcb_colormap_t colormapId = xcb_generate_id(conn); - xcb_create_colormap(conn, XCB_COLORMAP_ALLOC_NONE, colormapId, window, root_screen->root_visual); - xcb_alloc_color_reply_t *reply = xcb_alloc_color_reply(conn, - xcb_alloc_color(conn, colormapId, rgb16[0], rgb16[1], rgb16[2]), NULL); + xcb_colormap_t colormap_id = xcb_generate_id(conn); + xcb_void_cookie_t cookie = xcb_create_colormap_checked(conn, XCB_COLORMAP_ALLOC_NONE, + colormap_id, window, root_screen->root_visual); + check_error(conn, cookie, "Could not create colormap"); + xcb_alloc_color_reply_t *reply = xcb_alloc_color_reply(conn, + xcb_alloc_color(conn, colormap_id, rgb16[0], rgb16[1], rgb16[2]), NULL); - if (!reply) { - printf("color fail\n"); - exit(1); - } + if (!reply) { + printf("Could not allocate color\n"); + exit(1); + } - uint32_t pixel = reply->pixel; - free(reply); - xcb_free_colormap(conn, colormapId); - return pixel; + uint32_t pixel = reply->pixel; + free(reply); + xcb_free_colormap(conn, colormap_id); + return pixel; }