X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=spectrwm.c;h=334dad34be1d3c4db9141792006d069c4ab53d43;hb=759e9ab081cd59dd8658f958820b664aafc1d20c;hp=f4ab936f4e6893b706eee702bbc97d6476a1b9b8;hpb=5e2b9113a98ce3991cf8971ec3db75cae812df3e;p=spectrwm.git diff --git a/spectrwm.c b/spectrwm.c index f4ab936..334dad3 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -151,7 +151,7 @@ static const char *buildstr = SPECTRWM_VERSION; #define xcb_icccm_wm_hints_t xcb_wm_hints_t #endif -#define SWM_DEBUG +/*#define SWM_DEBUG*/ #ifdef SWM_DEBUG #define DPRINTF(x...) do { \ if (swm_debug) \ @@ -329,43 +329,52 @@ double dialog_ratio = 0.6; "-misc-fixed-medium-r-*-*-*-*-*-*-*-*-*-*," \ "-*-*-*-r-*--*-*-*-*-*-*-*-*" -char *bar_argv[] = { NULL, NULL }; -int bar_pipe[2]; -unsigned char bar_ext[SWM_BAR_MAX]; -char bar_vertext[SWM_BAR_MAX]; -int bar_version = 0; -sig_atomic_t bar_alarm = 0; -int bar_delay = 30; -int bar_enabled = 1; -int bar_border_width = 1; -int bar_at_bottom = 0; -int bar_extra = 1; -int bar_extra_running = 0; -int bar_verbose = 1; -int bar_height = 0; -int bar_justify = SWM_BAR_JUSTIFY_LEFT; -char *bar_format = NULL; -int stack_enabled = 1; -int clock_enabled = 1; -int urgent_enabled = 0; -char *clock_format = NULL; -int title_name_enabled = 0; -int title_class_enabled = 0; -int window_name_enabled = 0; -int focus_mode = SWM_FOCUS_DEFAULT; -int focus_close = SWM_STACK_BELOW; -int focus_close_wrap = 1; -int focus_default = SWM_STACK_TOP; -int spawn_position = SWM_STACK_TOP; -int disable_border = 0; -int border_width = 1; -int verbose_layout = 0; -time_t time_started; -pid_t bar_pid; -XftFont *bar_font; -char *bar_fonts; -XftColor bar_font_color; -struct passwd *pwd; +#ifdef X_HAVE_UTF8_STRING +#define DRAWSTRING(x...) Xutf8DrawString(x) +#else +#define DRAWSTRING(x...) XmbDrawString(x) +#endif + +char *bar_argv[] = { NULL, NULL }; +int bar_pipe[2]; +unsigned char bar_ext[SWM_BAR_MAX]; +char bar_vertext[SWM_BAR_MAX]; +int bar_version = 0; +sig_atomic_t bar_alarm = 0; +int bar_delay = 30; +int bar_enabled = 1; +int bar_border_width = 1; +int bar_at_bottom = 0; +int bar_extra = 1; +int bar_extra_running = 0; +int bar_verbose = 1; +int bar_height = 0; +int bar_justify = SWM_BAR_JUSTIFY_LEFT; +char *bar_format = NULL; +int stack_enabled = 1; +int clock_enabled = 1; +int urgent_enabled = 0; +char *clock_format = NULL; +int title_name_enabled = 0; +int title_class_enabled = 0; +int window_name_enabled = 0; +int focus_mode = SWM_FOCUS_DEFAULT; +int focus_close = SWM_STACK_BELOW; +int focus_close_wrap = 1; +int focus_default = SWM_STACK_TOP; +int spawn_position = SWM_STACK_TOP; +int disable_border = 0; +int border_width = 1; +int verbose_layout = 0; +time_t time_started; +pid_t bar_pid; +XFontSet bar_fs; +XFontSetExtents *bar_fs_extents; +XftFont *bar_font; +int bar_font_legacy = 0; +char *bar_fonts; +XftColor bar_font_color; +struct passwd *pwd; /* layout manager data */ struct swm_geometry { @@ -522,6 +531,7 @@ struct swm_screen { } c[SWM_S_COLOR_MAX]; xcb_gcontext_t bar_gc; + GC bar_gc_legacy; }; struct swm_screen *screens; @@ -597,6 +607,7 @@ enum { _NET_WM_ACTION_MOVE, _NET_WM_ACTION_RESIZE, _NET_WM_ALLOWED_ACTIONS, + _NET_WM_NAME, _NET_WM_STATE, _NET_WM_STATE_ABOVE, _NET_WM_STATE_FULLSCREEN, @@ -629,6 +640,7 @@ struct ewmh_hint { {"_NET_WM_ACTION_MOVE", XCB_ATOM_NONE}, {"_NET_WM_ACTION_RESIZE", XCB_ATOM_NONE}, {"_NET_WM_ALLOWED_ACTIONS", XCB_ATOM_NONE}, + {"_NET_WM_NAME", XCB_ATOM_NONE}, {"_NET_WM_STATE", XCB_ATOM_NONE}, {"_NET_WM_STATE_ABOVE", XCB_ATOM_NONE}, {"_NET_WM_STATE_FULLSCREEN", XCB_ATOM_NONE}, @@ -701,7 +713,7 @@ void update_window(struct ws_win *); char * expand_tilde(char *s) { - struct passwd *pwd; + struct passwd *ppwd; int i, max; char *user; const char *sc = s; @@ -728,11 +740,11 @@ expand_tilde(char *s) user[i] = '\0'; s = &s[i]; - pwd = strlen(user) == 0 ? getpwuid(getuid()) : getpwnam(user); - if (pwd == NULL) + ppwd = strlen(user) == 0 ? getpwuid(getuid()) : getpwnam(user); + if (ppwd == NULL) result = strdup(sc); else - if (asprintf(&result, "%s%s", pwd->pw_dir, s) == -1) + if (asprintf(&result, "%s%s", ppwd->pw_dir, s) == -1) result = NULL; out: if (result == NULL) @@ -1009,7 +1021,7 @@ ewmh_update_actions(struct ws_win *win) #define _NET_WM_STATE_TOGGLE 2 /* toggle property */ void -ewmh_update_win_state(struct ws_win *win, long state, long action) +ewmh_update_win_state(struct ws_win *win, xcb_atom_t state, long action) { unsigned int mask = 0; unsigned int changed = 0; @@ -1019,7 +1031,7 @@ ewmh_update_win_state(struct ws_win *win, long state, long action) return; DNPRINTF(SWM_D_PROP, "ewmh_update_win_state: window: 0x%x, state: %ld, " - "action: %ld\n", win->id, state, action); + "action: %ld\n", win->id, (unsigned long)state, action); if (state == ewmh[_NET_WM_STATE_FULLSCREEN].atom) mask = EWMH_F_FULLSCREEN; @@ -1170,8 +1182,10 @@ dumpwins(struct swm_region *r, union arg *args) } #else void -dumpwins(struct swm_region *r, union arg *args) +dumpwins(struct swm_region *r, union arg *s) { + (void)r; + (void)s; } #endif /* SWM_DEBUG */ @@ -1386,6 +1400,60 @@ socket_setnonblock(int fd) } void +bar_print_legacy(struct swm_region *r, const char *s) +{ + xcb_rectangle_t rect; + uint32_t gcv[1]; + XGCValues gcvd; + int x = 0; + size_t len; + XRectangle ibox, lbox; + GC draw; + + len = strlen(s); + XmbTextExtents(bar_fs, s, len, &ibox, &lbox); + + switch (bar_justify) { + case SWM_BAR_JUSTIFY_LEFT: + x = SWM_BAR_OFFSET; + break; + case SWM_BAR_JUSTIFY_CENTER: + x = (WIDTH(r) - lbox.width) / 2; + break; + case SWM_BAR_JUSTIFY_RIGHT: + x = WIDTH(r) - lbox.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); + rect.height = HEIGHT(r->bar); + + /* clear back buffer */ + gcv[0] = r->s->c[SWM_S_COLOR_BAR].pixel; + xcb_change_gc(conn, r->s->bar_gc, XCB_GC_FOREGROUND, gcv); + xcb_poly_fill_rectangle(conn, r->bar->buffer, r->s->bar_gc, + sizeof(rect), &rect); + + /* draw back buffer */ + gcvd.graphics_exposures = 0; + draw = XCreateGC(display, r->bar->buffer, GCGraphicsExposures, &gcvd); + XSetForeground(display, draw, r->s->c[SWM_S_COLOR_BAR_FONT].pixel); + DRAWSTRING(display, r->bar->buffer, bar_fs, draw, + x, (bar_fs_extents->max_logical_extent.height - lbox.height) / 2 - + lbox.y, s, len); + XFreeGC(display, draw); + + /* blt */ + xcb_copy_area(conn, r->bar->buffer, r->bar->id, r->s->bar_gc, 0, 0, + 0, 0, WIDTH(r->bar), HEIGHT(r->bar)); +} + +void bar_print(struct swm_region *r, const char *s) { size_t len; @@ -1426,11 +1494,12 @@ bar_print(struct swm_region *r, const char *s) sizeof(rect), &rect); /* draw back buffer */ +#if 0 gcv[0] = r->s->c[SWM_S_COLOR_BAR].pixel; xcb_change_gc(conn, r->s->bar_gc, XCB_GC_BACKGROUND, gcv); gcv[0] = r->s->c[SWM_S_COLOR_BAR_FONT].pixel; xcb_change_gc(conn, r->s->bar_gc, XCB_GC_FOREGROUND, gcv); - +#endif draw = XftDrawCreate(display, r->bar->buffer, DefaultVisual(display, r->s->idx), DefaultColormap(display, r->s->idx)); @@ -1782,7 +1851,10 @@ bar_fmt_print(void) continue; bar_fmt(fmtexp, fmtnew, r, sizeof fmtnew); bar_replace(fmtnew, fmtrep, r, sizeof fmtrep); - bar_print(r, fmtrep); + if (bar_font_legacy) + bar_print_legacy(r, fmtrep); + else + bar_print(r, fmtrep); } } } @@ -1905,47 +1977,88 @@ bar_refresh(void) bar_update(); } +int +isxlfd(char *s) +{ + int count = 0; + + while ((s = index(s, '-'))) { + ++count; + ++s; + } + + return (count == 14); +} + void -bar_setup(struct swm_region *r) +fontset_init() { - char *font, *fontpos, *dup, *search; - int count; - xcb_screen_t *screen; - uint32_t wa[3]; - XRenderColor color; + char *default_string; + char **missing_charsets; + int num_missing_charsets = 0; + int i; - if ((screen = get_screen(r->s->idx)) == NULL) - errx(1, "ERROR: can't get screen %d.", r->s->idx); + if (bar_fs) { + XFreeFontSet(display, bar_fs); + bar_fs = NULL; + } - if (r->bar != NULL) - return; + DNPRINTF(SWM_D_INIT, "fontset_init: loading bar_fonts: %s\n", bar_fonts); - if ((r->bar = calloc(1, sizeof(struct swm_bar))) == NULL) - err(1, "bar_setup: calloc: failed to allocate memory."); + bar_fs = XCreateFontSet(display, bar_fonts, &missing_charsets, + &num_missing_charsets, &default_string); + + if (num_missing_charsets > 0) { + warnx("Unable to load charset(s):"); + + for (i = 0; i < num_missing_charsets; ++i) + warnx("%s", missing_charsets[i]); + + XFreeStringList(missing_charsets); + + if (strcmp(default_string, "")) + warnx("Glyphs from those sets will be replaced " + "by '%s'.", default_string); + else + warnx("Glyphs from those sets won't be drawn."); + } + + if (bar_fs == NULL) + errx(1, "Error creating font set structure."); + + bar_fs_extents = XExtentsOfFontSet(bar_fs); + + bar_height = bar_fs_extents->max_logical_extent.height + + 2 * bar_border_width; + + if (bar_height < 1) + bar_height = 1; +} + +void +xft_init(struct swm_region *r) +{ + char *font, *d, *search; + XRenderColor color; if (bar_font == NULL) { - if ((dup = strdup(bar_fonts)) == NULL) + if ((d = strdup(bar_fonts)) == NULL) errx(1, "insufficient memory."); - search = dup; + search = d; while ((font = strsep(&search, ",")) != NULL) { if (*font == '\0') continue; - DNPRINTF(SWM_D_INIT, "bar_setup: try font %s\n", font); + DNPRINTF(SWM_D_INIT, "xft_init: try font %s\n", font); - count = 0; - fontpos = font; - while ((fontpos = index(fontpos, '-'))) { - count++; - fontpos++; - } - - if (count == 14) + if (isxlfd(font)) { bar_font = XftFontOpenXlfd(display, r->s->idx, font); - else + } else { bar_font = XftFontOpenName(display, r->s->idx, font); + } + if (!bar_font) { warnx("unable to load font %s", font); continue; @@ -1955,22 +2068,46 @@ bar_setup(struct swm_region *r) break; } } - free(dup); + free(d); } if (bar_font == NULL) errx(1, "unable to open a font"); + PIXEL_TO_XRENDERCOLOR(r->s->c[SWM_S_COLOR_BAR_FONT].pixel, color); + + if (!XftColorAllocValue(display, DefaultVisual(display, r->s->idx), + DefaultColormap(display, r->s->idx), &color, &bar_font_color)) + warn("unable to allocate Xft color"); + bar_height = bar_font->height + 2 * bar_border_width; if (bar_height < 1) bar_height = 1; +} - PIXEL_TO_XRENDERCOLOR(r->s->c[SWM_S_COLOR_BAR_FONT].pixel, color); +void +bar_setup(struct swm_region *r) +{ + xcb_screen_t *screen; + uint32_t wa[3]; - if (!XftColorAllocValue(display, DefaultVisual(display, r->s->idx), - DefaultColormap(display, r->s->idx), &color, &bar_font_color)) - warn("unable to allocate Xft color"); + DNPRINTF(SWM_D_BAR, "bar_setup: screen %d.\n", + r->s->idx); + + if ((screen = get_screen(r->s->idx)) == NULL) + errx(1, "ERROR: can't get screen %d.", r->s->idx); + + if (r->bar != NULL) + return; + + if ((r->bar = calloc(1, sizeof(struct swm_bar))) == NULL) + err(1, "bar_setup: calloc: failed to allocate memory."); + + if (bar_font_legacy) + fontset_init(); + else + xft_init(r); X(r->bar) = X(r); Y(r->bar) = bar_at_bottom ? (Y(r) + HEIGHT(r) - bar_height) : Y(r); @@ -1992,8 +2129,9 @@ bar_setup(struct swm_region *r) xcb_create_pixmap(conn, screen->root_depth, r->bar->buffer, r->bar->id, WIDTH(r->bar), HEIGHT(r->bar)); - xcb_randr_select_input(conn, r->bar->id, - XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE); + if (xrandr_support) + xcb_randr_select_input(conn, r->bar->id, + XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE); if (bar_enabled) map_window_raised(r->bar->id); @@ -2121,12 +2259,13 @@ config_win(struct ws_win *win, xcb_configure_request_event_t *ev) ce.window = ev->window; /* make response appear more WM_SIZE_HINTS-compliant */ - if (win->sh.flags) + if (win->sh.flags) { DNPRINTF(SWM_D_MISC, "config_win: hints: window: 0x%x," " sh.flags: %u, min: %d x %d, max: %d x %d, inc: " "%d x %d\n", win->id, win->sh.flags, SH_MIN_W(win), SH_MIN_H(win), SH_MAX_W(win), SH_MAX_H(win), SH_INC_W(win), SH_INC_H(win)); + } /* min size */ if (SH_MIN(win)) { @@ -2289,9 +2428,13 @@ restart(struct swm_region *r, union arg *args) bar_extra = 1; unmap_all(); - XftFontClose(display, bar_font); - XftColorFree(display, DefaultVisual(display, r->s->idx), - DefaultColormap(display, r->s->idx), &bar_font_color); + if (bar_font_legacy) + XFreeFontSet(display, bar_fs); + else { + XftFontClose(display, bar_font); + XftColorFree(display, DefaultVisual(display, r->s->idx), + DefaultColormap(display, r->s->idx), &bar_font_color); + } xcb_key_symbols_free(syms); xcb_flush(conn); xcb_disconnect(conn); @@ -2759,6 +2902,8 @@ priorws(struct swm_region *r, union arg *args) { union arg a; + (void)args; + DNPRINTF(SWM_D_WS, "priorws: id: %d, screen[%d]:%dx%d+%d+%d, ws: %d\n", args->id, r->s->idx, WIDTH(r), HEIGHT(r), X(r), Y(r), r->ws->idx); @@ -3797,21 +3942,32 @@ get_win_name(xcb_window_t win) { char *name = NULL; xcb_get_property_cookie_t c; - xcb_icccm_get_text_property_reply_t r; + xcb_get_property_reply_t *r; - c = xcb_icccm_get_wm_name(conn, win); - if (xcb_icccm_get_wm_name_reply(conn, c, &r, NULL)) { - if (r.name_len > 0) { - name = malloc(r.name_len + 1); - if (name) { - memcpy(name, r.name, r.name_len); - name[r.name_len] = '\0'; - } + /* First try _NET_WM_NAME for UTF-8. */ + c = xcb_get_property(conn, 0, win, a_netwmname, + XCB_GET_PROPERTY_TYPE_ANY, 0, UINT_MAX); + r = xcb_get_property_reply(conn, c, NULL); + + if (!r || r->type == XCB_NONE) { + free(r); + /* Use WM_NAME instead; no UTF-8. */ + c = xcb_get_property(conn, 0, win, XCB_ATOM_WM_NAME, + XCB_GET_PROPERTY_TYPE_ANY, 0, UINT_MAX); + r = xcb_get_property_reply(conn, c, NULL); + + if(!r || r->type == XCB_NONE) { + free(r); + return NULL; } - xcb_icccm_get_text_property_reply_wipe(&r); } - return (name); + if (r->length > 0) + name = strndup(xcb_get_property_value(r), + xcb_get_property_value_length(r)); + + free(r); + return name; } void @@ -3924,7 +4080,6 @@ search_win_cleanup(void) while ((sw = TAILQ_FIRST(&search_wl)) != NULL) { xcb_destroy_window(conn, sw->indicator); - xcb_free_gc(conn, sw->gc); TAILQ_REMOVE(&search_wl, sw, entry); free(sw); } @@ -3936,13 +4091,16 @@ search_win(struct swm_region *r, union arg *args) struct ws_win *win = NULL; struct search_window *sw = NULL; xcb_window_t w; - uint32_t gcv[3], wa[2]; - int i; + uint32_t gcv, wa[2]; + int i, width, height; char s[8]; FILE *lfile; size_t len; XftDraw *draw; XGlyphInfo info; + GC l_draw; + XGCValues l_gcv; + XRectangle l_ibox, l_lbox; DNPRINTF(SWM_D_MISC, "search_win\n"); @@ -3974,36 +4132,62 @@ search_win(struct swm_region *r, union arg *args) snprintf(s, sizeof s, "%d", i); len = strlen(s); - XftTextExtentsUtf8(display, bar_font, (FcChar8 *)s, len, &info); - w = xcb_generate_id(conn); wa[0] = r->s->c[SWM_S_COLOR_FOCUS].pixel; wa[1] = r->s->c[SWM_S_COLOR_UNFOCUS].pixel; + + if (bar_font_legacy) { + XmbTextExtents(bar_fs, s, len, &l_ibox, &l_lbox); + width = l_lbox.width + 4; + height = bar_fs_extents->max_logical_extent.height + 4; + } else { + XftTextExtentsUtf8(display, bar_font, (FcChar8 *)s, len, + &info); + width = info.width + 4; + height = bar_font->height + 4; + } + xcb_create_window(conn, XCB_COPY_FROM_PARENT, w, win->id, 0, 0, - info.width + 4, bar_font->height + 4, - 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, - XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL, wa); + width, height, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, + XCB_COPY_FROM_PARENT, XCB_CW_BACK_PIXEL | + XCB_CW_BORDER_PIXEL, wa); + + map_window_raised(w); sw->indicator = w; TAILQ_INSERT_TAIL(&search_wl, sw, entry); - sw->gc = xcb_generate_id(conn); - gcv[0] = r->s->c[SWM_S_COLOR_BAR].pixel; - gcv[1] = r->s->c[SWM_S_COLOR_FOCUS].pixel; - gcv[2] = 0; - xcb_create_gc(conn, sw->gc, w, XCB_GC_FOREGROUND | - XCB_GC_BACKGROUND | XCB_GC_GRAPHICS_EXPOSURES, gcv); - map_window_raised(w); + if (bar_font_legacy) { + l_gcv.graphics_exposures = 0; + l_draw = XCreateGC(display, w, 0, &l_gcv); + + XSetForeground(display, l_draw, + r->s->c[SWM_S_COLOR_BAR].pixel); - draw = XftDrawCreate(display, w, - DefaultVisual(display, r->s->idx), - DefaultColormap(display, r->s->idx)); + DRAWSTRING(display, w, bar_fs, l_draw, 2, + (bar_fs_extents->max_logical_extent.height - + l_lbox.height) / 2 - l_lbox.y, s, len); - XftDrawStringUtf8(draw, &bar_font_color, bar_font, 2, - (HEIGHT(r->bar) + bar_font->height) / 2 - bar_font->descent, - (FcChar8 *)s, len); + XFreeGC(display, l_draw); + } else { +#if 0 + sw->gc = xcb_generate_id(conn); + gcv = 0; + xcb_create_gc(conn, sw->gc, w, XCB_GC_GRAPHICS_EXPOSURES, + &gcv); +#endif + + draw = XftDrawCreate(display, w, + DefaultVisual(display, r->s->idx), + DefaultColormap(display, r->s->idx)); + + XftDrawStringUtf8(draw, &bar_font_color, bar_font, 2, + (HEIGHT(r->bar) + bar_font->height) / 2 - + bar_font->descent, (FcChar8 *)s, len); - XftDrawDestroy(draw); + XftDrawDestroy(draw); +/* xcb_free_gc(conn, sw->gc);*/ + } DNPRINTF(SWM_D_MISC, "search_win: mapped window: 0x%x\n", w); @@ -5779,7 +5963,7 @@ setconfquirk(char *selector, char *value, int flags) { char *cp, *class, *name; int retval; - unsigned long quirks; + unsigned long qrks; /* suppress unused warning since var is needed */ (void)flags; @@ -5791,8 +5975,8 @@ setconfquirk(char *selector, char *value, int flags) *cp = '\0'; class = selector; name = cp + 1; - if ((retval = parsequirks(value, &quirks)) == 0) - setquirk(class, name, quirks); + if ((retval = parsequirks(value, &qrks)) == 0) + setquirk(class, name, qrks); return (retval); } @@ -5887,6 +6071,9 @@ setconfvalue(char *selector, char *value, int flags) err(1, "setconfvalue: asprintf: failed to allocate " "memory for bar_fonts."); free(b); + + if (isxlfd(value)) + bar_font_legacy = 1; break; case SWM_S_BAR_FORMAT: free(bar_format); @@ -6138,7 +6325,7 @@ setautorun(char *selector, char *value, int flags) int setlayout(char *selector, char *value, int flags) { - int ws_id, i, x, mg, ma, si, raise, f = 0; + int ws_id, i, x, mg, ma, si, ar, f = 0; int st = SWM_V_STACK, num_screens; char s[1024]; struct workspace *ws; @@ -6152,7 +6339,7 @@ setlayout(char *selector, char *value, int flags) bzero(s, sizeof s); if (sscanf(value, "ws[%d]:%d:%d:%d:%d:%1023c", - &ws_id, &mg, &ma, &si, &raise, s) != 6) + &ws_id, &mg, &ma, &si, &ar, s) != 6) errx(1, "invalid layout entry, should be 'ws[]:" "::::" "'"); @@ -6182,7 +6369,7 @@ setlayout(char *selector, char *value, int flags) ws = (struct workspace *)&screens[i].ws; ws[ws_id].cur_layout = &layouts[st]; - ws[ws_id].always_raise = raise; + ws[ws_id].always_raise = ar; if (st == SWM_MAX_STACK) continue; @@ -6278,7 +6465,7 @@ conf_load(char *filename, int keymapping) FILE *config; char *line, *cp, *optsub, *optval; size_t linelen, lineno = 0; - int wordlen, i, optind; + int wordlen, i, optidx; struct config_option *opt; DNPRINTF(SWM_D_CONF, "conf_load: begin\n"); @@ -6314,16 +6501,16 @@ conf_load(char *filename, int keymapping) filename, lineno); goto out; } - optind = -1; + optidx = -1; for (i = 0; i < LENGTH(configopt); i++) { opt = &configopt[i]; if (!strncasecmp(cp, opt->optname, wordlen) && (int)strlen(opt->optname) == wordlen) { - optind = i; + optidx = i; break; } } - if (optind == -1) { + if (optidx == -1) { warnx("%s: line %zd: unknown option %.*s", filename, lineno, wordlen, cp); goto out; @@ -6362,10 +6549,10 @@ conf_load(char *filename, int keymapping) /* get RHS value */ optval = strdup(cp); /* call function to deal with it all */ - if (configopt[optind].func(optsub, optval, - configopt[optind].funcflags) != 0) + if (configopt[optidx].func(optsub, optval, + configopt[optidx].funcflags) != 0) errx(1, "%s: line %zd: invalid data for %s", - filename, lineno, configopt[optind].optname); + filename, lineno, configopt[optidx].optname); free(optval); free(optsub); free(line); @@ -7409,10 +7596,10 @@ clientmessage(xcb_client_message_event_t *e) void check_conn(void) { - int err = xcb_connection_has_error(conn); + int errcode = xcb_connection_has_error(conn); +#ifdef XCB_CONN_ERROR char *s; - - switch (err) { + switch (errcode) { case XCB_CONN_ERROR: s = "Socket error, pipe error or other stream error."; break; @@ -7431,9 +7618,12 @@ check_conn(void) default: s = "Unknown error."; } - - if (err) - errx(err, "X CONNECTION ERROR: %s", s); + if (errcode) + errx(errcode, "X CONNECTION ERROR: %s", s); +#else + if (errcode) + errx(errcode, "X CONNECTION ERROR"); +#endif } int @@ -7739,17 +7929,17 @@ setup_screens(void) /* initial Xrandr setup */ xrandr_support = 0; - c = xcb_randr_query_version(conn, 1, 1); - r = xcb_randr_query_version_reply(conn, c, NULL); - if (r) { - if (r->major_version >= 1) { - qep = xcb_get_extension_data(conn, &xcb_randr_id); - if (qep) { + qep = xcb_get_extension_data(conn, &xcb_randr_id); + if (qep->present) { + c = xcb_randr_query_version(conn, 1, 1); + r = xcb_randr_query_version_reply(conn, c, NULL); + if (r) { + if (r->major_version >= 1) { xrandr_support = 1; xrandr_eventbase = qep->first_event; } + free(r); } - free(r); } cursor_font = xcb_generate_id(conn); @@ -7875,6 +8065,8 @@ workaround(void) void event_error(xcb_generic_error_t *e) { + (void)e; + DNPRINTF(SWM_D_EVENT, "event_error: %s(%u) from %s(%u), sequence: %u, " "resource_id: %u, minor_code: %u\n", xcb_event_get_error_label(e->error_code), e->error_code, @@ -7975,6 +8167,9 @@ main(int argc, char *argv[]) sact.sa_flags = SA_NOCLDSTOP; sigaction(SIGCHLD, &sact, NULL); + if (!X_HAVE_UTF8_STRING) + warnx("no UTF-8 support"); + if (!(display = XOpenDisplay(0))) errx(1, "can not open display"); @@ -8112,8 +8307,9 @@ noconfig: tv.tv_sec = 1; tv.tv_usec = 0; if (select(xfd + 1, &rd, NULL, NULL, &tv) == -1) - if (errno != EINTR) + if (errno != EINTR) { DNPRINTF(SWM_D_MISC, "select failed"); + } if (restart_wm == 1) restart(NULL, NULL); if (search_resp == 1) @@ -8133,9 +8329,13 @@ done: if (screens[i].bar_gc != 0) xcb_free_gc(conn, screens[i].bar_gc); - XftFontClose(display, bar_font); - XftColorFree(display, DefaultVisual(display, 0), - DefaultColormap(display, 0), &bar_font_color); + if (bar_font_legacy) { + XFreeFontSet(display, bar_fs); + } else { + XftFontClose(display, bar_font); + XftColorFree(display, DefaultVisual(display, r->s->idx), + DefaultColormap(display, r->s->idx), &bar_font_color); + } xcb_key_symbols_free(syms); xcb_flush(conn); xcb_disconnect(conn);