X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=spectrwm.c;h=9d54d1498bf1d6d0177c2bfeef6dae5636c4e922;hb=eaa16b866569f6a308c28a05d24c34bb7b8be500;hp=fc0bcd25b56b118a013f4e506069fe7988070ff1;hpb=a5f8037d4690ecd411d0385e1acc296dbc11839b;p=spectrwm.git diff --git a/spectrwm.c b/spectrwm.c index fc0bcd2..9d54d14 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -89,7 +89,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -260,6 +261,8 @@ int ss_enabled = 0; int xrandr_support; int xrandr_eventbase; unsigned int numlockmask = 0; + +Display *display; xcb_connection_t *conn; xcb_key_symbols_t *syms; @@ -348,7 +351,7 @@ int border_width = 1; int verbose_layout = 0; time_t time_started; pid_t bar_pid; -xcb_font_t bar_fs; +XftFont *bar_fs; int32_t bar_fs_height; char *bar_fonts; struct passwd *pwd; @@ -806,7 +809,7 @@ setup_ewmh(void) num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); for (i = 0; i < num_screens; i++) { /* Support check window will be created by workaround(). */ - + /* Report supported atoms */ xcb_delete_property(conn, screens[i].root, sup_list); for (j = 0; j < LENGTH(ewmh); j++) @@ -1337,41 +1340,28 @@ bar_print(struct swm_region *r, const char *s) size_t len; xcb_rectangle_t rect; uint32_t gcv[1]; - xcb_char2b_t *c2b; - xcb_query_text_extents_reply_t *ter; - int32_t x, width; - + int32_t x; + XGlyphInfo info; + len = strlen(s); - c2b = char2b(s); - if (!c2b) - return; - ter = xcb_query_text_extents_reply(conn, - xcb_query_text_extents(conn, bar_fs, len, c2b), - NULL); - if (!ter) { - free(c2b); - return; - } - width = ter->overall_width; + + XftTextExtentsUtf8(display, bar_fs, (FcChar8 *)s, len, &info); - free(c2b); - free(ter); - switch (bar_justify) { case SWM_BAR_JUSTIFY_LEFT: x = SWM_BAR_OFFSET; break; case SWM_BAR_JUSTIFY_CENTER: - x = (WIDTH(r) - width) / 2; + x = (WIDTH(r) - info.width) / 2; break; case SWM_BAR_JUSTIFY_RIGHT: - x = WIDTH(r) - width - SWM_BAR_OFFSET; + x = WIDTH(r) - info.width - SWM_BAR_OFFSET; break; } if (x < SWM_BAR_OFFSET) x = SWM_BAR_OFFSET; - + rect.x = 0; rect.y = 0; rect.width = WIDTH(r->bar); @@ -1388,9 +1378,7 @@ bar_print(struct swm_region *r, const char *s) xcb_change_gc(conn, r->s->bar_gc, XCB_GC_BACKGROUND, gcv); gcv[0] = r->s->c[SWM_S_COLOR_BAR_FONT].color; xcb_change_gc(conn, r->s->bar_gc, XCB_GC_FOREGROUND, gcv); - gcv[0] = bar_fs; - xcb_change_gc(conn, r->s->bar_gc, XCB_GC_FONT, gcv); - + xcb_image_text_8(conn, len, r->bar->buffer, r->s->bar_gc, x, bar_fs_height, s); @@ -1857,57 +1845,38 @@ bar_setup(struct swm_region *r) char *bar_font; xcb_screen_t *screen = get_screen(r->s->idx); uint32_t wa[3]; - xcb_generic_error_t *error; - xcb_void_cookie_t voc; - xcb_query_font_reply_t *bar_fs_info; if (bar_fs) { - xcb_close_font(conn, bar_fs); - bar_fs = 0; + XftFontClose(display, bar_fs); + bar_fs = NULL; } if ((r->bar = calloc(1, sizeof(struct swm_bar))) == NULL) err(1, "bar_setup: calloc: failed to allocate memory."); - bar_fs = xcb_generate_id(conn); - while ((bar_font = strsep(&bar_fonts, " ,")) != NULL) { if (*bar_font == '\0') continue; - - DNPRINTF(SWM_D_INIT, "bar_setup: try font %s\n", bar_font); - voc = xcb_open_font_checked(conn, bar_fs, strlen(bar_font), - bar_font); - - if ((error = xcb_request_check(conn, voc))) { - DNPRINTF(SWM_D_INIT, - "bar_setup: unable to open font: %s\n", + + DNPRINTF(SWM_D_INIT, "bar_setup: try font %s\n", bar_font); + bar_fs = XftFontOpenName(display, DefaultScreen(display), bar_font); - free(error); + if (!bar_fs) { warnx("unable to load font %s", bar_font); + continue; } else { - DNPRINTF(SWM_D_INIT, - "bar_setup: successfully opened font: %s\n", - bar_font); + DNPRINTF(SWM_D_INIT, "successfully opened font %s\n", + bar_font); break; } } - bar_fs_info = xcb_query_font_reply(conn, - xcb_query_font(conn, bar_fs), - NULL); - if (!bar_fs_info) - errx(1, "unable to get font information for font %s\n", - bar_font); - bar_fs_height = bar_fs_info->font_ascent + bar_fs_info->font_descent; - free(bar_fs_info); - - bar_height = bar_fs_info->font_ascent + bar_fs_info->font_descent + - 4 * bar_border_width; + bar_fs_height = bar_fs->height; + bar_height = bar_fs_height + 4 * bar_border_width; if (bar_height < 1) bar_height = 1; - + X(r->bar) = X(r); Y(r->bar) = bar_at_bottom ? (Y(r) + HEIGHT(r) - bar_height) : Y(r); WIDTH(r->bar) = WIDTH(r) - 2 * bar_border_width; @@ -3847,7 +3816,7 @@ search_win(struct swm_region *r, union arg *args) char s[8]; FILE *lfile; size_t len; - XRectangle ibox, lbox; + XGlyphInfo info; DNPRINTF(SWM_D_MISC, "search_win\n"); @@ -3879,26 +3848,15 @@ search_win(struct swm_region *r, union arg *args) snprintf(s, sizeof s, "%d", i); len = strlen(s); - /* FIXME fix calculations */ -#if 0 - XmbTextExtents(bar_fs, s, len, &ibox, &lbox); -#endif - + XftTextExtentsUtf8(display, bar_fs, (FcChar8 *)s, len, &info); + w = xcb_generate_id(conn); wa[0] = r->s->c[SWM_S_COLOR_FOCUS].color; wa[1] = r->s->c[SWM_S_COLOR_UNFOCUS].color; -#if 0 xcb_create_window(conn, XCB_COPY_FROM_PARENT, w, win->id, 0, 0, - lbox.width + 4, bar_fs_extents->max_logical_extent.height, + info.width + 4, bar_fs_height + 4, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL, wa); -#else - /* workaround */ - xcb_create_window(conn, XCB_COPY_FROM_PARENT, w, win->id, 0, 0, - 22, 20, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, - XCB_COPY_FROM_PARENT, XCB_CW_BACK_PIXEL | - XCB_CW_BORDER_PIXEL, wa); -#endif sw->indicator = w; TAILQ_INSERT_TAIL(&search_wl, sw, entry); @@ -3908,17 +3866,11 @@ search_win(struct swm_region *r, union arg *args) gcv[1] = r->s->c[SWM_S_COLOR_FOCUS].color; gcv[2] = 0; xcb_create_gc(conn, sw->gc, w, XCB_GC_FOREGROUND | - XCB_GC_BACKGROUND | XCB_GC_GRAPHICS_EXPOSURES, gcv); + XCB_GC_BACKGROUND | XCB_GC_GRAPHICS_EXPOSURES, + gcv); map_window_raised(w); -#if 0 - xcb_image_text_8(conn, len, w, sw->gc, 2, - (bar_fs_extents->max_logical_extent.height - - lbox.height) / 2 - lbox.y, s); -#else - /* workaround */ - xcb_image_text_8(conn, len, w, sw->gc, 6, 14, s); -#endif + xcb_image_text_8(conn, len, w, sw->gc, 2, bar_fs_height, s); DNPRINTF(SWM_D_MISC, "search_win: mapped window: 0x%x\n", w); @@ -7707,7 +7659,10 @@ main(int argc, char *argv[]) sact.sa_flags = SA_NOCLDSTOP; sigaction(SIGCHLD, &sact, NULL); - conn = xcb_connect(NULL, NULL); + if (!(display = XOpenDisplay(0))) + errx(1, "can not open display"); + + conn = XGetXCBConnection(display); if (xcb_connection_has_error(conn)) errx(1, "can not get XCB connection");