+/*
+ * Initializes a CT_OUTPUT Con (searches existing ones from inplace restart
+ * before) to use for the given Output.
+ *
+ * XXX: for assignments, we probably need to move workspace creation from here
+ * to after the loop in randr_query_outputs().
+ *
+ */
+void output_init_con(Output *output) {
+ Con *con = NULL, *current;
+ bool reused = false;
+ static int c = 1;
+
+ DLOG("init_con for output %s\n", output->name);
+
+ /* Search for a Con with that name directly below the root node. There
+ * might be one from a restored layout. */
+ TAILQ_FOREACH(current, &(croot->nodes_head), nodes) {
+ if (strcmp(current->name, output->name) != 0)
+ continue;
+
+ con = current;
+ reused = true;
+ DLOG("Using existing con %p / %s\n", con, con->name);
+ break;
+ }
+
+ if (con == NULL) {
+ con = con_new(croot);
+ FREE(con->name);
+ con->name = sstrdup(output->name);
+ con->type = CT_OUTPUT;
+ }
+ con->rect = output->rect;
+ output->con = con;
+
+ char *name;
+ asprintf(&name, "[i3 con] output %s", con->name);
+ x_set_name(con, name);
+ free(name);
+
+ if (reused) {
+ DLOG("Not adding workspace, this was a reused con\n");
+ return;
+ }
+ DLOG("Now adding a workspace\n");
+
+ /* add a workspace to this output */
+ Con *ws = con_new(NULL);
+ ws->type = CT_WORKSPACE;
+ /* TODO: don't just number workspaces, but get the next assigned one / unused one */
+ ws->num = c;
+ FREE(ws->name);
+ asprintf(&(ws->name), "%d", c);
+ c++;
+ con_attach(ws, con, false);
+
+ asprintf(&name, "[i3 con] workspace %s", ws->name);
+ x_set_name(ws, name);
+ free(name);
+
+ ws->fullscreen_mode = CF_OUTPUT;
+ ws->orientation = HORIZ;
+
+ /* TODO: Set focus in main.c */
+ con_focus(ws);
+}
+