$OpenBSD: patch-src_mainx_c,v 1.2 2011/01/05 12:45:04 dcoppa Exp $
--- src/mainx.c.orig	Wed Jun  9 09:58:15 2010
+++ src/mainx.c	Wed Jan  5 12:55:57 2011
@@ -283,6 +283,11 @@ int main(int argc, char *argv[], char *env[]) {
         if (xcb_connection_has_error(conn))
                 die("Cannot open display\n");
 
+        /* Get the root window */
+        xcb_screen_t *root_screen = xcb_aux_get_screen(conn, screens);
+        root = root_screen->root;
+        root_depth = root_screen->root_depth;
+
         load_configuration(conn, override_configpath, false);
         if (only_check_config) {
                 LOG("Done checking configuration file. Exiting.\n");
@@ -441,11 +446,7 @@ int main(int argc, char *argv[], char *env[]) {
         /* Watch size hints (to obey correct aspect ratio) */
         xcb_property_set_handler(&prophs, WM_NORMAL_HINTS, UINT_MAX, handle_normal_hints, NULL);
 
-        /* Get the root window and set the event mask */
-        xcb_screen_t *root_screen = xcb_aux_get_screen(conn, screens);
-        root = root_screen->root;
-        root_depth = root_screen->root_depth;
-
+        /* Set the event mask */
         uint32_t mask = XCB_CW_EVENT_MASK;
         uint32_t values[] = { XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT |
                               XCB_EVENT_MASK_STRUCTURE_NOTIFY |         /* when the user adds a screen (e.g. video
@@ -526,17 +527,18 @@ int main(int argc, char *argv[], char *env[]) {
         translate_keysyms();
         grab_all_keys(conn, false);
 
-        int randr_base;
+        int randr_base = -1;
         if (force_xinerama) {
                 initialize_xinerama(conn);
         } else {
                 DLOG("Checking for XRandR...\n");
                 initialize_randr(conn, &randr_base);
 
-                xcb_event_set_handler(&evenths,
-                                      randr_base + XCB_RANDR_SCREEN_CHANGE_NOTIFY,
-                                      handle_screen_change,
-                                      NULL);
+                if (randr_base != -1)
+                    xcb_event_set_handler(&evenths,
+                                          randr_base + XCB_RANDR_SCREEN_CHANGE_NOTIFY,
+                                          handle_screen_change,
+                                          NULL);
         }
 
         xcb_flush(conn);
