JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
fix typo
[spectrwm.git] / spectrwm.c
index 17e2912..3b240f1 100644 (file)
@@ -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 *);
@@ -758,9 +759,15 @@ parse_rgb(const char *rgb, uint16_t *rr, uint16_t *gg, uint16_t *bb)
 xcb_screen_t *
 get_screen(int screen)
 {
+       const xcb_setup_t       *r;
        xcb_screen_iterator_t   iter;
 
-       iter = xcb_setup_roots_iterator(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)
                        return (iter.data);
@@ -1985,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);
@@ -7399,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)
 {
@@ -7702,17 +7749,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);