X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=spectrwm.c;h=753bbf039a21153f5f5ee8a837ea986e39140666;hb=ebb72d68f2e0cf5f5d921f98f7c2f0f9e118ae6f;hp=0e70061ff51a6cde35ea74ccf5966ddd0242347e;hpb=ac57a15638eed3753b39e4f5c934e0a3f67ba7c3;p=spectrwm.git diff --git a/spectrwm.c b/spectrwm.c index 0e70061..753bbf0 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 *); @@ -700,7 +701,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; @@ -727,11 +728,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) @@ -761,7 +762,11 @@ get_screen(int screen) const xcb_setup_t *r; xcb_screen_iterator_t iter; - r = xcb_get_setup(conn); + if ((r = xcb_get_setup(conn)) == NULL) { + DNPRINTF(SWM_D_MISC, "get_screen: xcb_get_setup\n"); + check_conn(); + } + iter = xcb_setup_roots_iterator(r); for (; iter.rem; --screen, xcb_screen_next(&iter)) if (screen == 0) @@ -1987,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); @@ -5774,7 +5780,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; @@ -5786,8 +5792,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); } @@ -7401,6 +7407,39 @@ clientmessage(xcb_client_message_event_t *e) xcb_flush(conn); } +void +check_conn(void) +{ + int errcode = xcb_connection_has_error(conn); + char *s; +#ifdef XCB_CONN_ERROR + switch (errcode) { + 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 (errcode) + errx(errcode, "X CONNECTION ERROR: %s", s); +#else + if (errcode) + errx(errcode, "X CONNECTION ERROR"); +#endif +} + int enable_wm(void) { @@ -7704,17 +7743,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);