X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=spectrwm.c;h=3b240f1052965fbd9531e37a1eb69ee0c1726f45;hb=1fa17c86c27db076578a215f9393663c083644cd;hp=4ded07705e776ca047170fa69b3cdaef9c2ad59b;hpb=53586d8b864e74f7611e756bd2ed20e0a81c88b8;p=spectrwm.git diff --git a/spectrwm.c b/spectrwm.c index 4ded077..3b240f1 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -649,6 +649,7 @@ struct ewmh_hint { /* function prototypes */ void buttonpress(xcb_button_press_event_t *); +void check_conn(void); void clientmessage(xcb_client_message_event_t *); int conf_load(char *, int); void configurenotify(xcb_configure_notify_event_t *); @@ -701,8 +702,8 @@ char * expand_tilde(char *s) { struct passwd *pwd; - int i; - char user[LOGIN_NAME_MAX]; + int i, max; + char *user; const char *sc = s; char *result; @@ -715,6 +716,13 @@ expand_tilde(char *s) } ++s; + + if ((max = sysconf(_SC_LOGIN_NAME_MAX)) == -1) + errx(1, "expand_tilde: sysconf"); + + if ((user = calloc(1, max + 1)) == NULL) + errx(1, "expand_tilde: calloc"); + for (i = 0; s[i] != '/' && s[i] != '\0'; ++i) user[i] = s[i]; user[i] = '\0'; @@ -751,12 +759,18 @@ parse_rgb(const char *rgb, uint16_t *rr, uint16_t *gg, uint16_t *bb) xcb_screen_t * get_screen(int screen) { - xcb_screen_iterator_t i; + const xcb_setup_t *r; + xcb_screen_iterator_t iter; + + if ((r = xcb_get_setup(conn)) == NULL) { + DNPRINTF(SWM_D_MISC, "get_screen: xcb_get_setup\n"); + check_conn(); + } - i = xcb_setup_roots_iterator(xcb_get_setup(conn)); - for (; i.rem; --screen, xcb_screen_next(&i)) + iter = xcb_setup_roots_iterator(r); + for (; iter.rem; --screen, xcb_screen_next(&iter)) if (screen == 0) - return (i.data); + return (iter.data); return (NULL); } @@ -1340,7 +1354,9 @@ custom_region(char *val) sidx, num_screens); sidx--; - screen = get_screen(sidx); + if ((screen = get_screen(sidx)) == NULL) + errx(1, "ERROR: can't get screen %d.", sidx); + if (w < 1 || h < 1) errx(1, "region %ux%u+%u+%u too small", w, h, x, y); @@ -1894,10 +1910,13 @@ bar_setup(struct swm_region *r) { char *font, *fontpos, *dup, *search; int count; - xcb_screen_t *screen = get_screen(r->s->idx); + xcb_screen_t *screen; uint32_t wa[3]; XRenderColor color; + if ((screen = get_screen(r->s->idx)) == NULL) + errx(1, "ERROR: can't get screen %d.", r->s->idx); + if (r->bar != NULL) return; @@ -1973,8 +1992,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); @@ -7387,6 +7407,45 @@ clientmessage(xcb_client_message_event_t *e) xcb_flush(conn); } +#ifdef XCB_CONN_ERROR +void +check_conn(void) +{ + int err = xcb_connection_has_error(conn); + char *s; + + switch (err) { + case XCB_CONN_ERROR: + s = "Socket error, pipe error or other stream error."; + break; + case XCB_CONN_CLOSED_EXT_NOTSUPPORTED: + s = "Extension not supported."; + break; + case XCB_CONN_CLOSED_MEM_INSUFFICIENT: + s = "Insufficient memory."; + break; + case XCB_CONN_CLOSED_REQ_LEN_EXCEED: + s = "Request length was exceeded."; + break; + case XCB_CONN_CLOSED_PARSE_ERR: + s = "Error parsing display string."; + break; + default: + s = "Unknown error."; + } + + if (err) + errx(err, "X CONNECTION ERROR: %s", s); +} +#else +void +check_conn(void) +{ + if (conn->has_error) + errx(1, "X CONNECTION ERROR"); +} +#endif + int enable_wm(void) { @@ -7399,7 +7458,8 @@ enable_wm(void) /* this causes an error if some other window manager is running */ num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); for (i = 0; i < num_screens; i++) { - sc = get_screen(i); + if ((sc = get_screen(i)) == NULL) + errx(1, "ERROR: can't get screen %d.", i); DNPRINTF(SWM_D_INIT, "enable_wm: screen %d, root: 0x%x\n", i, sc->root); wac = xcb_change_window_attributes_checked(conn, sc->root, @@ -7504,7 +7564,10 @@ scan_xrandr(int i) xcb_randr_get_crtc_info_cookie_t cic; xcb_randr_get_crtc_info_reply_t *cir = NULL; xcb_randr_crtc_t *crtc; - xcb_screen_t *screen = get_screen(i); + xcb_screen_t *screen; + + if ((screen = get_screen(i)) == NULL) + errx(1, "ERROR: can't get screen %d.", i); num_screens = xcb_setup_roots_length(xcb_get_setup(conn)); if (i >= num_screens) @@ -7672,6 +7735,7 @@ setup_screens(void) struct workspace *ws; uint32_t gcv[1], wa[1]; const xcb_query_extension_reply_t *qep; + xcb_screen_t *screen; xcb_cursor_t cursor; xcb_font_t cursor_font; xcb_randr_query_version_cookie_t c; @@ -7685,15 +7749,18 @@ 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) - xrandr_support = 1; - free(r); - } qep = xcb_get_extension_data(conn, &xcb_randr_id); - xrandr_eventbase = qep->first_event; + 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); + } + } cursor_font = xcb_generate_id(conn); xcb_open_font(conn, cursor_font, strlen("cursor"), "cursor"); @@ -7709,7 +7776,9 @@ setup_screens(void) screens[i].idx = i; TAILQ_INIT(&screens[i].rl); TAILQ_INIT(&screens[i].orl); - screens[i].root = get_screen(i)->root; + if ((screen = get_screen(i)) == NULL) + errx(1, "ERROR: can't get screen %d.", i); + screens[i].root = screen->root; /* set default colors */ setscreencolor("red", i + 1, SWM_S_COLOR_FOCUS);