* 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
if (output->active)
return output;
- die("No usable outputs available.\n");
+ return NULL;
}
/*
void disable_randr(xcb_connection_t *conn) {
DLOG("RandR extension unusable, disabling.\n");
- Output *s = scalloc(sizeof(Output));
+ Output *s = scalloc(1, sizeof(Output));
s->active = true;
s->rect.x = 0;
topdock->type = CT_DOCKAREA;
topdock->layout = L_DOCKAREA;
/* this container swallows dock clients */
- Match *match = scalloc(sizeof(Match));
+ Match *match = scalloc(1, sizeof(Match));
match_init(match);
match->dock = M_DOCK_TOP;
match->insert_where = M_BELOW;
bottomdock->type = CT_DOCKAREA;
bottomdock->layout = L_DOCKAREA;
/* this container swallows dock clients */
- match = scalloc(sizeof(Match));
+ match = scalloc(1, sizeof(Match));
match_init(match);
match->dock = M_DOCK_BOTTOM;
match->insert_where = M_BELOW;
Output *new = get_output_by_id(id);
bool existing = (new != NULL);
if (!existing)
- new = scalloc(sizeof(Output));
+ new = scalloc(1, sizeof(Output));
new->id = id;
new->primary = (primary && primary->output == id);
FREE(new->name);
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) |
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,
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;
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);
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;
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
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");
+ }
+ }
}
/*