X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=spectrwm.c;h=5ea7095429b62619367d05177cc2c8a622395fe0;hb=0943667cdc5a86458c17ce6ce223c546cf86c7e6;hp=6a1504b717adcfc11cf674f7cad7faa988b28a88;hpb=dbbf2709df31ce0c0944e45023b37e67dfd92e2b;p=spectrwm.git diff --git a/spectrwm.c b/spectrwm.c index 6a1504b..5ea7095 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -1251,26 +1251,34 @@ find_pid(long pid) return (NULL); } -unsigned long -name_to_color(char *colorname) -{ - Colormap cmap; - Status status; - XColor screen_def, exact_def; - unsigned long result = 0; - char cname[32] = "#"; - - cmap = DefaultColormap(display, screens[0].idx); - status = XAllocNamedColor(display, cmap, colorname, - &screen_def, &exact_def); - if (!status) { +uint32_t +name_to_color(const char *colorname) +{ + uint32_t result = 0; + char cname[32] = "#"; + xcb_screen_t *screen; + xcb_colormap_t cmap; + xcb_alloc_named_color_cookie_t c; + xcb_alloc_named_color_reply_t *r; + + /* XXX - does not support rgb:/RR/GG/BB + * will need to use xcb_alloc_color + */ + screen = xcb_setup_roots_iterator(xcb_get_setup(conn)).data; + cmap = screen->default_colormap; + + c = xcb_alloc_named_color(conn, cmap, strlen(colorname), colorname); + r = xcb_alloc_named_color_reply(conn, c, NULL); + if (!r) { strlcat(cname, colorname + 2, sizeof cname - 1); - status = XAllocNamedColor(display, cmap, cname, &screen_def, - &exact_def); + c = xcb_alloc_named_color(conn, cmap, strlen(cname), + cname); + r = xcb_alloc_named_color_reply(conn, c, NULL); } - if (status) - result = screen_def.pixel; - else + if (r) { + result = r->pixel; + free(r); + } else warnx("color '%s' not found", colorname); return (result); @@ -1814,8 +1822,8 @@ bar_toggle(struct swm_region *r, union arg *args) void bar_refresh(void) { - XSetWindowAttributes wa; struct swm_region *r; + uint32_t wa[2]; int i, num_screens; /* do this here because the conf file is in memory */ @@ -1847,18 +1855,15 @@ bar_refresh(void) } } - bzero(&wa, sizeof wa); num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); for (i = 0; i < num_screens; i++) TAILQ_FOREACH(r, &screens[i].rl, entry) { if (r->bar == NULL) continue; - wa.border_pixel = - screens[i].c[SWM_S_COLOR_BAR_BORDER].color; - wa.background_pixel = - screens[i].c[SWM_S_COLOR_BAR].color; - XChangeWindowAttributes(display, r->bar->id, - CWBackPixel | CWBorderPixel, &wa); + wa[0] = screens[i].c[SWM_S_COLOR_BAR].color; + wa[1] = screens[i].c[SWM_S_COLOR_BAR_BORDER].color; + xcb_change_window_attributes(conn, r->bar->id, + XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL, wa); } bar_update(); } @@ -4155,23 +4160,23 @@ constrain_window(struct ws_win *win, struct swm_region *r, int resizable) void update_window(struct ws_win *win) { - unsigned int mask; - XWindowChanges wc; - - bzero(&wc, sizeof wc); - mask = CWBorderWidth | CWWidth | CWHeight | CWX | CWY; + uint16_t mask; + uint32_t wc[5]; - wc.border_width = BORDER(win); - wc.x = X(win); - wc.y = Y(win); - wc.width = WIDTH(win); - wc.height = HEIGHT(win); + mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | + XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT | + XCB_CONFIG_WINDOW_BORDER_WIDTH; + wc[0] = X(win); + wc[1] = Y(win); + wc[2] = WIDTH(win); + wc[3] = HEIGHT(win); + wc[4] = BORDER(win); - DNPRINTF(SWM_D_EVENT, "update_window: window: 0x%lx, (x,y) w x h: " - "(%d,%d) %d x %d, bordered: %s\n", win->id, wc.x, wc.y, wc.width, - wc.height, YESNO(win->bordered)); + DNPRINTF(SWM_D_EVENT, "update_window: window: 0x%x, (x,y) w x h: " + "(%d,%d) %d x %d, bordered: %s\n", win->id, wc[0], wc[1], wc[2], + wc[3], YESNO(win->bordered)); - XConfigureWindow(display, win->id, mask, &wc); + xcb_configure_window(conn, win->id, mask, wc); } #define SWM_RESIZE_STEPS (50)