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);
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);
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;
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);
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;
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,
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;
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);
}
char s[8];
FILE *lfile;
size_t len;
+ XftDraw *draw;
XGlyphInfo info;
DNPRINTF(SWM_D_MISC, "search_win\n");
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);
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);
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);
}
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);