X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=spectrwm.c;h=1751412f18b4a70c6c3d34dca787b01f9800bcd9;hb=972d8078dac803b2896f7bfb3958d9e801e3321a;hp=1ef4c8d6ab8491d2c6eed9628a3f6ae9cd91d2c1;hpb=c7532ca6f471773d7ea399f30c935fd531b624a8;p=spectrwm.git diff --git a/spectrwm.c b/spectrwm.c index 1ef4c8d..1751412 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -647,7 +647,6 @@ struct ewmh_hint { }; /* function prototypes */ -xcb_char2b_t *char2b(const char *); int conf_load(char *, int); void constrain_window(struct ws_win *, struct swm_region *, int); void do_sync(void); @@ -659,7 +658,7 @@ void focus_magic(struct ws_win *); xcb_atom_t get_atom_from_string(const char *); xcb_screen_t *get_screen(int); char *get_win_name(xcb_window_t); -uint16_t getstate(xcb_window_t); +uint32_t getstate(xcb_window_t); void grabbuttons(struct ws_win *, int); void map_window_raised(xcb_window_t); void new_region(struct swm_screen *, int, int, int, int); @@ -672,26 +671,6 @@ void update_window(struct ws_win *); char *get_atom_name(xcb_atom_t); #endif -/* function definitions */ -xcb_char2b_t * -char2b(const char *str) -{ - xcb_char2b_t *s; - size_t i, len; - - len = strlen(str); - s = malloc(len * sizeof(xcb_char2b_t)); - if (!s) - return (NULL); - - for (i = 0; i < len; i++) { - s[i].byte1 = '\0'; - s[i].byte2 = str[i]; - } - - return (s); -} - int parse_rgb(const char *rgb, uint16_t *rr, uint16_t *gg, uint16_t *bb) { @@ -841,7 +820,7 @@ teardown_ewmh(void) pc = xcb_get_property(conn, 0, screens[i].root, sup_check, XCB_ATOM_WINDOW, 0, 1); pr = xcb_get_property_reply(conn, pc, NULL); - if (pr) { + if (pr && pr->format == sup_check) { id = *((xcb_window_t *)xcb_get_property_value(pr)); xcb_destroy_window(conn, id); @@ -1068,7 +1047,7 @@ void dumpwins(struct swm_region *r, union arg *args) { struct ws_win *win; - uint16_t state; + uint32_t state; xcb_get_window_attributes_cookie_t c; xcb_get_window_attributes_reply_t *wa; @@ -1394,7 +1373,8 @@ bar_print(struct swm_region *r, const char *s) DefaultVisual(display, r->s->idx), DefaultColormap(display, r->s->idx)); - XftDrawStringUtf8(draw, &bar_font_color, bar_font, x, bar_font->height, + XftDrawStringUtf8(draw, &bar_font_color, bar_font, x, + (HEIGHT(r->bar) + bar_font->height) / 2 - bar_font->descent, (FcChar8 *)s, len); XftDrawDestroy(draw); @@ -1866,40 +1846,53 @@ bar_refresh(void) void bar_setup(struct swm_region *r) { - char *font; + char *font, *fontpos; + int count; xcb_screen_t *screen = get_screen(r->s->idx); uint32_t wa[3]; XRenderColor color; - if (bar_font) { - XftColorFree(display, DefaultVisual(display, r->s->idx), - DefaultColormap(display, r->s->idx), &bar_font_color); - XftFontClose(display, bar_font); - bar_font = NULL; - } + if (r->bar != NULL) + return; if ((r->bar = calloc(1, sizeof(struct swm_bar))) == NULL) err(1, "bar_setup: calloc: failed to allocate memory."); - while ((font = strsep(&bar_fonts, " ,")) != NULL) { - if (*font == '\0') - continue; + if (bar_font == NULL) { + while ((font = strsep(&bar_fonts, ",")) != NULL) { + if (*font == '\0') + continue; - DNPRINTF(SWM_D_INIT, "bar_setup: try font %s\n", font); - bar_font = XftFontOpenName(display, r->s->idx, font); - if (!bar_font) { - warnx("unable to load font %s", font); - continue; - } else { - DNPRINTF(SWM_D_INIT, "successfully opened font %s\n", - font); - break; + DNPRINTF(SWM_D_INIT, "bar_setup: try font %s\n", font); + + count = 0; + fontpos = font; + while ((fontpos = index(fontpos, '-'))) { + count++; + fontpos++; + } + + if (count == 14) + bar_font = XftFontOpenXlfd(display, r->s->idx, + font); + else + bar_font = XftFontOpenName(display, r->s->idx, + font); + if (!bar_font) { + warnx("unable to load font %s", font); + continue; + } else { + DNPRINTF(SWM_D_INIT, "successfully opened " + "font %s\n", font); + break; + } } } + if (bar_font == NULL) errx(1, "unable to open a font"); - bar_height = bar_font->height + 4 * bar_border_width; + bar_height = bar_font->height + 2 * bar_border_width; if (bar_height < 1) bar_height = 1; @@ -1919,8 +1912,7 @@ bar_setup(struct swm_region *r) wa[0] = r->s->c[SWM_S_COLOR_BAR].pixel; wa[1] = r->s->c[SWM_S_COLOR_BAR_BORDER].pixel; wa[2] = XCB_EVENT_MASK_EXPOSURE; - DNPRINTF(SWM_D_BAR, "bar_setup: create_window: (x,y) w x h: (%d,%d) " - "%d x %d\n", X(r->bar), Y(r->bar), WIDTH(r->bar), HEIGHT(r->bar)); + xcb_create_window(conn, XCB_COPY_FROM_PARENT, r->bar->id, r->s->root, X(r->bar), Y(r->bar), WIDTH(r->bar), HEIGHT(r->bar), bar_border_width, XCB_WINDOW_CLASS_INPUT_OUTPUT, @@ -1971,10 +1963,10 @@ set_win_state(struct ws_win *win, uint16_t state) a_state, 32, 2, data); } -uint16_t +uint32_t getstate(xcb_window_t w) { - uint16_t result = 0; + uint32_t result = 0; xcb_get_property_cookie_t c; xcb_get_property_reply_t *r; @@ -1982,7 +1974,8 @@ getstate(xcb_window_t w) r = xcb_get_property_reply(conn, c, NULL); if (r) { - result = *((uint16_t *)xcb_get_property_value(r)); + if (r->type == a_state && r->format == 32 && r->length == 2) + result = *((uint32_t *)xcb_get_property_value(r)); free(r); } @@ -2306,8 +2299,10 @@ find_window(xcb_window_t id) return (NULL); /* if we were looking for the parent return that window instead */ - if (r->parent == 0 || r->root == r->parent) + if (r->parent == 0 || r->root == r->parent) { + free(r); return (NULL); + } /* look for parent */ for (i = 0; i < num_screens; i++) @@ -3737,12 +3732,10 @@ get_win_name(xcb_window_t 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) { - xcb_icccm_get_text_property_reply_wipe(&r); - return (NULL); + if (name) { + memcpy(name, r.name, r.name_len); + name[r.name_len] = '\0'; } - memcpy(name, r.name, r.name_len); - name[r.name_len] = '\0'; } xcb_icccm_get_text_property_reply_wipe(&r); } @@ -3877,6 +3870,7 @@ search_win(struct swm_region *r, union arg *args) char s[8]; FILE *lfile; size_t len; + XftDraw *draw; XGlyphInfo info; DNPRINTF(SWM_D_MISC, "search_win\n"); @@ -3930,7 +3924,15 @@ search_win(struct swm_region *r, union arg *args) XCB_GC_BACKGROUND | XCB_GC_GRAPHICS_EXPOSURES, gcv); map_window_raised(w); - xcb_image_text_8(conn, len, w, sw->gc, 2, bar_font->height, s); + 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); DNPRINTF(SWM_D_MISC, "search_win: mapped window: 0x%x\n", w); @@ -6383,7 +6385,8 @@ window_get_pid(xcb_window_t win) goto tryharder; } - ret = *((pid_t *)xcb_get_property_value(pr)); + if (pr->type == apid && pr->format == 32) + ret = *((pid_t *)xcb_get_property_value(pr)); free(pr); return (ret); @@ -6395,7 +6398,7 @@ tryharder: pr = xcb_get_property_reply(conn, pc, NULL); if (!pr) return (0); - if (pr->type != XCB_ATOM_STRING) { + if (pr->type != apid) { free(pr); return (0); } @@ -6419,7 +6422,7 @@ get_ws_idx(xcb_window_t id) xcb_get_property(conn, 0, id, a_swm_ws, XCB_ATOM_STRING, 0, SWM_PROPLEN), NULL); - if (gpr) { + if (gpr && gpr->type) { proplen = xcb_get_property_value_length(gpr); if (proplen > 0) { prop = malloc(proplen + 1); @@ -6440,6 +6443,7 @@ get_ws_idx(xcb_window_t id) DNPRINTF(SWM_D_PROP, "get_ws_idx: window: #%s: %s", errstr, prop); } + free(prop); } return ws_idx; @@ -7091,7 +7095,7 @@ maprequest(xcb_map_request_event_t *e) char * get_atom_name(xcb_atom_t atom) { - char *name; + char *name = NULL; size_t len; xcb_get_atom_name_reply_t *r; @@ -7105,14 +7109,12 @@ get_atom_name(xcb_atom_t atom) if (name) { memcpy(name, xcb_get_atom_name_name(r), len); name[len] = '\0'; - - return name; } } free(r); } - return NULL; + return (name); } #endif