X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Frandr.c;h=1bd9993164d946b455db95ba3a5b0fd31f2ef503;hb=55e8d06ee4f9dbb190c18198cac7c6e9f137f11a;hp=a4a0f6fd6d36fe7c626d836e7bc23d8c34573cdb;hpb=67e00b3ab8a325143df90703317a3155c6ae9f5f;p=i3%2Fi3 diff --git a/src/randr.c b/src/randr.c index a4a0f6fd..1bd99931 100644 --- a/src/randr.c +++ b/src/randr.c @@ -4,7 +4,7 @@ * vim:ts=4:sw=4:expandtab * * i3 - an improved dynamic tiling window manager - * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE) + * © 2009 Michael Stapelberg and contributors (see also: LICENSE) * * For more information on RandR, please see the X.org RandR specification at * http://cgit.freedesktop.org/xorg/proto/randrproto/tree/randrproto.txt @@ -69,7 +69,7 @@ Output *get_first_output(void) { if (output->active) return output; - die("No usable outputs available.\n"); + return NULL; } /* @@ -555,6 +555,12 @@ static void handle_output(xcb_connection_t *conn, xcb_randr_output_t id, return; } + if (output->connection == XCB_RANDR_CONNECTION_DISCONNECTED) { + DLOG("Disabling output %s: it is disconnected\n", new->name); + new->to_be_disabled = true; + return; + } + bool updated = update_if_necessary(&(new->rect.x), crtc->x) | update_if_necessary(&(new->rect.y), crtc->y) | update_if_necessary(&(new->rect.width), crtc->width) | @@ -564,6 +570,8 @@ static void handle_output(xcb_connection_t *conn, xcb_randr_output_t id, if (!new->active) { DLOG("width/height 0/0, disabling output\n"); return; + } else { + new->to_be_disabled = false; } DLOG("mode: %dx%d+%d+%d\n", new->rect.width, new->rect.height, @@ -585,11 +593,7 @@ static void handle_output(xcb_connection_t *conn, xcb_randr_output_t id, new->changed = true; } -/* - * (Re-)queries the outputs via RandR and stores them in the list of outputs. - * - */ -void randr_query_outputs(void) { +static bool __randr_query_outputs(void) { Output *output, *other, *first; xcb_randr_get_output_primary_cookie_t pcookie; xcb_randr_get_screen_resources_current_cookie_t rcookie; @@ -603,7 +607,7 @@ void randr_query_outputs(void) { xcb_randr_output_t *randr_outputs; if (randr_disabled) - return; + return true; /* Get screen resources (primary output, crtcs, outputs, modes) */ rcookie = xcb_randr_get_screen_resources_current(conn, root); @@ -615,7 +619,7 @@ void randr_query_outputs(void) { DLOG("primary output is %08x\n", primary->output); if ((res = xcb_randr_get_screen_resources_current_reply(conn, rcookie, NULL)) == NULL) { disable_randr(conn); - return; + return true; } cts = res->config_timestamp; @@ -697,6 +701,11 @@ void randr_query_outputs(void) { DLOG("Output %s disabled, re-assigning workspaces/docks\n", output->name); first = get_first_output(); + if (!first) { + FREE(res); + FREE(primary); + return false; + } /* TODO: refactor the following code into a nice function. maybe * use an on_destroy callback which is implement differently for @@ -812,6 +821,32 @@ void randr_query_outputs(void) { FREE(res); FREE(primary); + + return true; +} + +/* + * (Re-)queries the outputs via RandR and stores them in the list of outputs. + * + */ +void randr_query_outputs(void) { + static bool first_query = true; + + if (first_query) { + /* find monitors at least once via RandR */ + if (!__randr_query_outputs()) + die("No usable outputs available.\n"); + first_query = false; + } else { + /* requery */ + if (!__randr_query_outputs()) { + DLOG("sleep %f ms due to zero displays\n", config.zero_disp_exit_timer_ms); + usleep(config.zero_disp_exit_timer_ms * 1000); + + if (!__randr_query_outputs()) + die("No usable outputs available.\n"); + } + } } /*