2 #define I3__FILE__ "randr.c"
4 * vim:ts=4:sw=4:expandtab
6 * i3 - an improved dynamic tiling window manager
7 * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
9 * For more information on RandR, please see the X.org RandR specification at
10 * http://cgit.freedesktop.org/xorg/proto/randrproto/tree/randrproto.txt
11 * (take your time to read it completely, it answers all questions).
17 #include <xcb/randr.h>
19 /* While a clean namespace is usually a pretty good thing, we really need
20 * to use shorter names than the whole xcb_randr_* default names. */
21 typedef xcb_randr_get_crtc_info_reply_t crtc_info;
22 typedef xcb_randr_get_screen_resources_current_reply_t resources_reply;
24 /* Pointer to the result of the query for primary output */
25 xcb_randr_get_output_primary_reply_t *primary;
27 /* Stores all outputs available in your current session. */
28 struct outputs_head outputs = TAILQ_HEAD_INITIALIZER(outputs);
30 static bool randr_disabled = false;
33 * Get a specific output by its internal X11 id. Used by randr_query_outputs
34 * to check if the output is new (only in the first scan) or if we are
38 static Output *get_output_by_id(xcb_randr_output_t id) {
40 TAILQ_FOREACH(output, &outputs, outputs)
48 * Returns the output with the given name if it is active (!) or NULL.
51 Output *get_output_by_name(const char *name) {
53 TAILQ_FOREACH(output, &outputs, outputs)
55 strcasecmp(output->name, name) == 0)
62 * Returns the first output which is active.
65 Output *get_first_output(void) {
68 TAILQ_FOREACH(output, &outputs, outputs)
72 die("No usable outputs available.\n");
76 * Returns the active (!) output which contains the coordinates x, y or NULL
77 * if there is no output which contains these coordinates.
80 Output *get_output_containing(unsigned int x, unsigned int y) {
82 TAILQ_FOREACH(output, &outputs, outputs) {
85 DLOG("comparing x=%d y=%d with x=%d and y=%d width %d height %d\n",
86 x, y, output->rect.x, output->rect.y, output->rect.width, output->rect.height);
87 if (x >= output->rect.x && x < (output->rect.x + output->rect.width) &&
88 y >= output->rect.y && y < (output->rect.y + output->rect.height))
96 * In contained_by_output, we check if any active output contains part of the container.
97 * We do this by checking if the output rect is intersected by the Rect.
98 * This is the 2-dimensional counterpart of get_output_containing.
99 * Since we don't actually need the outputs intersected by the given Rect (There could
100 * be many), we just return true or false for convenience.
103 bool contained_by_output(Rect rect) {
105 int lx = rect.x, uy = rect.y;
106 int rx = rect.x + rect.width, by = rect.y + rect.height;
107 TAILQ_FOREACH(output, &outputs, outputs) {
110 DLOG("comparing x=%d y=%d with x=%d and y=%d width %d height %d\n",
111 rect.x, rect.y, output->rect.x, output->rect.y, output->rect.width, output->rect.height);
112 if (rx >= (int)output->rect.x && lx <= (int)(output->rect.x + output->rect.width) &&
113 by >= (int)output->rect.y && uy <= (int)(output->rect.y + output->rect.height))
120 * Like get_output_next with close_far == CLOSEST_OUTPUT, but wraps.
122 * For example if get_output_next(D_DOWN, x, FARTHEST_OUTPUT) = NULL, then
123 * get_output_next_wrap(D_DOWN, x) will return the topmost output.
125 * This function always returns a output: if no active outputs can be found,
126 * current itself is returned.
129 Output *get_output_next_wrap(direction_t direction, Output *current) {
130 Output *best = get_output_next(direction, current, CLOSEST_OUTPUT);
131 /* If no output can be found, wrap */
133 direction_t opposite;
134 if (direction == D_RIGHT)
136 else if (direction == D_LEFT)
138 else if (direction == D_DOWN)
142 best = get_output_next(opposite, current, FARTHEST_OUTPUT);
146 DLOG("current = %s, best = %s\n", current->name, best->name);
151 * Gets the output which is the next one in the given direction.
153 * If close_far == CLOSEST_OUTPUT, then the output next to the current one will
154 * selected. If close_far == FARTHEST_OUTPUT, the output which is the last one
155 * in the given direction will be selected.
157 * NULL will be returned when no active outputs are present in the direction
158 * specified (note that “current” counts as such an output).
161 Output *get_output_next(direction_t direction, Output *current, output_close_far_t close_far) {
162 Rect *cur = &(current->rect),
166 TAILQ_FOREACH(output, &outputs, outputs) {
170 other = &(output->rect);
172 if ((direction == D_RIGHT && other->x > cur->x) ||
173 (direction == D_LEFT && other->x < cur->x)) {
174 /* Skip the output when it doesn’t overlap the other one’s y
175 * coordinate at all. */
176 if ((other->y + other->height) <= cur->y ||
177 (cur->y + cur->height) <= other->y)
179 } else if ((direction == D_DOWN && other->y > cur->y) ||
180 (direction == D_UP && other->y < cur->y)) {
181 /* Skip the output when it doesn’t overlap the other one’s x
182 * coordinate at all. */
183 if ((other->x + other->width) <= cur->x ||
184 (cur->x + cur->width) <= other->x)
189 /* No candidate yet? Start with this one. */
195 if (close_far == CLOSEST_OUTPUT) {
196 /* Is this output better (closer to the current output) than our
197 * current best bet? */
198 if ((direction == D_RIGHT && other->x < best->rect.x) ||
199 (direction == D_LEFT && other->x > best->rect.x) ||
200 (direction == D_DOWN && other->y < best->rect.y) ||
201 (direction == D_UP && other->y > best->rect.y)) {
206 /* Is this output better (farther to the current output) than our
207 * current best bet? */
208 if ((direction == D_RIGHT && other->x > best->rect.x) ||
209 (direction == D_LEFT && other->x < best->rect.x) ||
210 (direction == D_DOWN && other->y > best->rect.y) ||
211 (direction == D_UP && other->y < best->rect.y)) {
218 DLOG("current = %s, best = %s\n", current->name, (best ? best->name : "NULL"));
223 * Disables RandR support by creating exactly one output with the size of the
227 void disable_randr(xcb_connection_t *conn) {
228 DLOG("RandR extension unusable, disabling.\n");
230 Output *s = scalloc(sizeof(Output));
235 s->rect.width = root_screen->width_in_pixels;
236 s->rect.height = root_screen->height_in_pixels;
239 init_ws_for_output(s, output_get_content(s->con));
241 TAILQ_INSERT_TAIL(&outputs, s, outputs);
243 randr_disabled = true;
247 * Initializes a CT_OUTPUT Con (searches existing ones from inplace restart
248 * before) to use for the given Output.
251 void output_init_con(Output *output) {
252 Con *con = NULL, *current;
255 DLOG("init_con for output %s\n", output->name);
257 /* Search for a Con with that name directly below the root node. There
258 * might be one from a restored layout. */
259 TAILQ_FOREACH(current, &(croot->nodes_head), nodes) {
260 if (strcmp(current->name, output->name) != 0)
265 DLOG("Using existing con %p / %s\n", con, con->name);
270 con = con_new(croot, NULL);
272 con->name = sstrdup(output->name);
273 con->type = CT_OUTPUT;
274 con->layout = L_OUTPUT;
275 con_fix_percent(croot);
277 con->rect = output->rect;
281 sasprintf(&name, "[i3 con] output %s", con->name);
282 x_set_name(con, name);
286 DLOG("Not adding workspace, this was a reused con\n");
290 DLOG("Changing layout, adding top/bottom dockarea\n");
291 Con *topdock = con_new(NULL, NULL);
292 topdock->type = CT_DOCKAREA;
293 topdock->layout = L_DOCKAREA;
294 /* this container swallows dock clients */
295 Match *match = scalloc(sizeof(Match));
297 match->dock = M_DOCK_TOP;
298 match->insert_where = M_BELOW;
299 TAILQ_INSERT_TAIL(&(topdock->swallow_head), match, matches);
302 topdock->name = sstrdup("topdock");
304 sasprintf(&name, "[i3 con] top dockarea %s", con->name);
305 x_set_name(topdock, name);
308 con_attach(topdock, con, false);
310 /* content container */
312 DLOG("adding main content container\n");
313 Con *content = con_new(NULL, NULL);
314 content->type = CT_CON;
315 content->layout = L_SPLITH;
317 content->name = sstrdup("content");
319 sasprintf(&name, "[i3 con] content %s", con->name);
320 x_set_name(content, name);
322 con_attach(content, con, false);
324 /* bottom dock container */
325 Con *bottomdock = con_new(NULL, NULL);
326 bottomdock->type = CT_DOCKAREA;
327 bottomdock->layout = L_DOCKAREA;
328 /* this container swallows dock clients */
329 match = scalloc(sizeof(Match));
331 match->dock = M_DOCK_BOTTOM;
332 match->insert_where = M_BELOW;
333 TAILQ_INSERT_TAIL(&(bottomdock->swallow_head), match, matches);
335 FREE(bottomdock->name);
336 bottomdock->name = sstrdup("bottomdock");
338 sasprintf(&name, "[i3 con] bottom dockarea %s", con->name);
339 x_set_name(bottomdock, name);
342 con_attach(bottomdock, con, false);
346 * Initializes at least one workspace for this output, trying the following
347 * steps until there is at least one workspace:
349 * • Move existing workspaces, which are assigned to be on the given output, to
351 * • Create the first assigned workspace for this output.
352 * • Create the first unused workspace.
355 void init_ws_for_output(Output *output, Con *content) {
356 /* go through all assignments and move the existing workspaces to this output */
357 struct Workspace_Assignment *assignment;
358 TAILQ_FOREACH(assignment, &ws_assignments, ws_assignments) {
359 if (strcmp(assignment->output, output->name) != 0)
362 /* check if this workspace actually exists */
363 Con *workspace = NULL, *out;
364 TAILQ_FOREACH(out, &(croot->nodes_head), nodes)
365 GREP_FIRST(workspace, output_get_content(out),
366 !strcasecmp(child->name, assignment->name));
367 if (workspace == NULL)
370 /* check that this workspace is not already attached (that means the
371 * user configured this assignment twice) */
372 Con *workspace_out = con_get_output(workspace);
373 if (workspace_out == output->con) {
374 LOG("Workspace \"%s\" assigned to output \"%s\", but it is already "
375 "there. Do you have two assignment directives for the same "
376 "workspace in your configuration file?\n",
377 workspace->name, output->name);
381 /* if so, move it over */
382 LOG("Moving workspace \"%s\" from output \"%s\" to \"%s\" due to assignment\n",
383 workspace->name, workspace_out->name, output->name);
385 /* if the workspace is currently visible on that output, we need to
386 * switch to a different workspace - otherwise the output would end up
387 * with no active workspace */
388 bool visible = workspace_is_visible(workspace);
389 Con *previous = NULL;
390 if (visible && (previous = TAILQ_NEXT(workspace, focused))) {
391 LOG("Switching to previously used workspace \"%s\" on output \"%s\"\n",
392 previous->name, workspace_out->name);
393 workspace_show(previous);
396 /* Render the output on which the workspace was to get correct Rects.
397 * Then, we need to work with the "content" container, since we cannot
398 * be sure that the workspace itself was rendered at all (in case it’s
399 * invisible, it won’t be rendered). */
400 render_con(workspace_out, false);
401 Con *ws_out_content = output_get_content(workspace_out);
404 TAILQ_FOREACH(floating_con, &(workspace->floating_head), floating_windows)
405 /* NB: We use output->con here because content is not yet rendered,
406 * so it has a rect of {0, 0, 0, 0}. */
407 floating_fix_coordinates(floating_con, &(ws_out_content->rect), &(output->con->rect));
409 con_detach(workspace);
410 con_attach(workspace, content, false);
412 /* In case the workspace we just moved was visible but there was no
413 * other workspace to switch to, we need to initialize the source
415 if (visible && previous == NULL) {
416 LOG("There is no workspace left on \"%s\", re-initializing\n",
417 workspace_out->name);
418 init_ws_for_output(get_output_by_name(workspace_out->name),
419 output_get_content(workspace_out));
420 DLOG("Done re-initializing, continuing with \"%s\"\n", output->name);
424 /* if a workspace exists, we are done now */
425 if (!TAILQ_EMPTY(&(content->nodes_head))) {
426 /* ensure that one of the workspaces is actually visible (in fullscreen
427 * mode), if they were invisible before, this might not be the case. */
429 GREP_FIRST(visible, content, child->fullscreen_mode == CF_OUTPUT);
431 visible = TAILQ_FIRST(&(content->nodes_head));
433 workspace_show(visible);
438 /* otherwise, we create the first assigned ws for this output */
439 TAILQ_FOREACH(assignment, &ws_assignments, ws_assignments) {
440 if (strcmp(assignment->output, output->name) != 0)
443 LOG("Initializing first assigned workspace \"%s\" for output \"%s\"\n",
444 assignment->name, assignment->output);
446 workspace_show_by_name(assignment->name);
450 /* if there is still no workspace, we create the first free workspace */
451 DLOG("Now adding a workspace\n");
452 Con *ws = create_workspace_on_output(output, content);
454 /* TODO: Set focus in main.c */
459 * This function needs to be called when changing the mode of an output when
460 * it already has some workspaces (or a bar window) assigned.
462 * It reconfigures the bar window for the new mode, copies the new rect into
463 * each workspace on this output and forces all windows on the affected
464 * workspaces to be reconfigured.
466 * It is necessary to call render_layout() afterwards.
469 static void output_change_mode(xcb_connection_t *conn, Output *output) {
470 DLOG("Output mode changed, updating rect\n");
471 assert(output->con != NULL);
472 output->con->rect = output->rect;
474 Con *content, *workspace, *child;
476 /* Point content to the container of the workspaces */
477 content = output_get_content(output->con);
479 /* Fix the position of all floating windows on this output.
480 * The 'rect' of each workspace will be updated in src/render.c. */
481 TAILQ_FOREACH(workspace, &(content->nodes_head), nodes) {
482 TAILQ_FOREACH(child, &(workspace->floating_head), floating_windows) {
483 floating_fix_coordinates(child, &(workspace->rect), &(output->con->rect));
487 /* If default_orientation is NO_ORIENTATION, we change the orientation of
488 * the workspaces and their childs depending on output resolution. This is
489 * only done for workspaces with maximum one child. */
490 if (config.default_orientation == NO_ORIENTATION) {
491 TAILQ_FOREACH(workspace, &(content->nodes_head), nodes) {
492 /* Workspaces with more than one child are left untouched because
493 * we do not want to change an existing layout. */
494 if (con_num_children(workspace) > 1)
497 workspace->layout = (output->rect.height > output->rect.width) ? L_SPLITV : L_SPLITH;
498 DLOG("Setting workspace [%d,%s]'s layout to %d.\n", workspace->num, workspace->name, workspace->layout);
499 if ((child = TAILQ_FIRST(&(workspace->nodes_head)))) {
500 if (child->layout == L_SPLITV || child->layout == L_SPLITH)
501 child->layout = workspace->layout;
502 DLOG("Setting child [%d,%s]'s layout to %d.\n", child->num, child->name, child->layout);
509 * Gets called by randr_query_outputs() for each output. The function adds new
510 * outputs to the list of outputs, checks if the mode of existing outputs has
511 * been changed or if an existing output has been disabled. It will then change
512 * either the "changed" or the "to_be_deleted" flag of the output, if
516 static void handle_output(xcb_connection_t *conn, xcb_randr_output_t id,
517 xcb_randr_get_output_info_reply_t *output,
518 xcb_timestamp_t cts, resources_reply *res) {
519 /* each CRT controller has a position in which we are interested in */
522 Output *new = get_output_by_id(id);
523 bool existing = (new != NULL);
525 new = scalloc(sizeof(Output));
527 new->primary = (primary && primary->output == id);
529 sasprintf(&new->name, "%.*s",
530 xcb_randr_get_output_info_name_length(output),
531 xcb_randr_get_output_info_name(output));
533 DLOG("found output with name %s\n", new->name);
535 /* Even if no CRTC is used at the moment, we store the output so that
536 * we do not need to change the list ever again (we only update the
538 if (output->crtc == XCB_NONE) {
541 TAILQ_INSERT_HEAD(&outputs, new, outputs);
543 TAILQ_INSERT_TAIL(&outputs, new, outputs);
544 } else if (new->active)
545 new->to_be_disabled = true;
549 xcb_randr_get_crtc_info_cookie_t icookie;
550 icookie = xcb_randr_get_crtc_info(conn, output->crtc, cts);
551 if ((crtc = xcb_randr_get_crtc_info_reply(conn, icookie, NULL)) == NULL) {
552 DLOG("Skipping output %s: could not get CRTC (%p)\n",
558 if (output->connection == XCB_RANDR_CONNECTION_DISCONNECTED) {
559 DLOG("Disabling output %s: it is disconnected\n", new->name);
560 new->to_be_disabled = true;
564 bool updated = update_if_necessary(&(new->rect.x), crtc->x) |
565 update_if_necessary(&(new->rect.y), crtc->y) |
566 update_if_necessary(&(new->rect.width), crtc->width) |
567 update_if_necessary(&(new->rect.height), crtc->height);
569 new->active = (new->rect.width != 0 && new->rect.height != 0);
571 DLOG("width/height 0/0, disabling output\n");
575 DLOG("mode: %dx%d+%d+%d\n", new->rect.width, new->rect.height,
576 new->rect.x, new->rect.y);
578 /* If we don’t need to change an existing output or if the output
579 * does not exist in the first place, the case is simple: we either
580 * need to insert the new output or we are done. */
581 if (!updated || !existing) {
584 TAILQ_INSERT_HEAD(&outputs, new, outputs);
586 TAILQ_INSERT_TAIL(&outputs, new, outputs);
595 * (Re-)queries the outputs via RandR and stores them in the list of outputs.
598 void randr_query_outputs(void) {
599 Output *output, *other, *first;
600 xcb_randr_get_output_primary_cookie_t pcookie;
601 xcb_randr_get_screen_resources_current_cookie_t rcookie;
602 resources_reply *res;
604 /* timestamp of the configuration so that we get consistent replies to all
605 * requests (if the configuration changes between our different calls) */
608 /* an output is VGA-1, LVDS-1, etc. (usually physical video outputs) */
609 xcb_randr_output_t *randr_outputs;
614 /* Get screen resources (primary output, crtcs, outputs, modes) */
615 rcookie = xcb_randr_get_screen_resources_current(conn, root);
616 pcookie = xcb_randr_get_output_primary(conn, root);
618 if ((primary = xcb_randr_get_output_primary_reply(conn, pcookie, NULL)) == NULL)
619 ELOG("Could not get RandR primary output\n");
621 DLOG("primary output is %08x\n", primary->output);
622 if ((res = xcb_randr_get_screen_resources_current_reply(conn, rcookie, NULL)) == NULL) {
626 cts = res->config_timestamp;
628 int len = xcb_randr_get_screen_resources_current_outputs_length(res);
629 randr_outputs = xcb_randr_get_screen_resources_current_outputs(res);
631 /* Request information for each output */
632 xcb_randr_get_output_info_cookie_t ocookie[len];
633 for (int i = 0; i < len; i++)
634 ocookie[i] = xcb_randr_get_output_info(conn, randr_outputs[i], cts);
636 /* Loop through all outputs available for this X11 screen */
637 for (int i = 0; i < len; i++) {
638 xcb_randr_get_output_info_reply_t *output;
640 if ((output = xcb_randr_get_output_info_reply(conn, ocookie[i], NULL)) == NULL)
643 handle_output(conn, randr_outputs[i], output, cts, res);
647 /* Check for clones, disable the clones and reduce the mode to the
648 * lowest common mode */
649 TAILQ_FOREACH(output, &outputs, outputs) {
650 if (!output->active || output->to_be_disabled)
652 DLOG("output %p / %s, position (%d, %d), checking for clones\n",
653 output, output->name, output->rect.x, output->rect.y);
656 other != TAILQ_END(&outputs);
657 other = TAILQ_NEXT(other, outputs)) {
658 if (other == output || !other->active || other->to_be_disabled)
661 if (other->rect.x != output->rect.x ||
662 other->rect.y != output->rect.y)
665 DLOG("output %p has the same position, his mode = %d x %d\n",
666 other, other->rect.width, other->rect.height);
667 uint32_t width = min(other->rect.width, output->rect.width);
668 uint32_t height = min(other->rect.height, output->rect.height);
670 if (update_if_necessary(&(output->rect.width), width) |
671 update_if_necessary(&(output->rect.height), height))
672 output->changed = true;
674 update_if_necessary(&(other->rect.width), width);
675 update_if_necessary(&(other->rect.height), height);
677 DLOG("disabling output %p (%s)\n", other, other->name);
678 other->to_be_disabled = true;
680 DLOG("new output mode %d x %d, other mode %d x %d\n",
681 output->rect.width, output->rect.height,
682 other->rect.width, other->rect.height);
686 /* Ensure that all outputs which are active also have a con. This is
687 * necessary because in the next step, a clone might get disabled. Example:
688 * LVDS1 active, VGA1 gets activated as a clone of LVDS1 (has no con).
689 * LVDS1 gets disabled. */
690 TAILQ_FOREACH(output, &outputs, outputs) {
691 if (output->active && output->con == NULL) {
692 DLOG("Need to initialize a Con for output %s\n", output->name);
693 output_init_con(output);
694 output->changed = false;
698 /* Handle outputs which have a new mode or are disabled now (either
699 * because the user disabled them or because they are clones) */
700 TAILQ_FOREACH(output, &outputs, outputs) {
701 if (output->to_be_disabled) {
702 output->active = false;
703 DLOG("Output %s disabled, re-assigning workspaces/docks\n", output->name);
705 first = get_first_output();
707 /* TODO: refactor the following code into a nice function. maybe
708 * use an on_destroy callback which is implement differently for
709 * different container types (CT_CONTENT vs. CT_DOCKAREA)? */
710 Con *first_content = output_get_content(first->con);
712 if (output->con != NULL) {
713 /* We need to move the workspaces from the disappearing output to the first output */
714 /* 1: Get the con to focus next, if the disappearing ws is focused */
716 if (TAILQ_FIRST(&(croot->focus_head)) == output->con) {
717 DLOG("This output (%p) was focused! Getting next\n", output->con);
719 DLOG("next = %p\n", next);
722 /* 2: iterate through workspaces and re-assign them, fixing the coordinates
723 * of floating containers as we go */
725 Con *old_content = output_get_content(output->con);
726 while (!TAILQ_EMPTY(&(old_content->nodes_head))) {
727 current = TAILQ_FIRST(&(old_content->nodes_head));
728 if (current != next && TAILQ_EMPTY(&(current->focus_head))) {
729 /* the workspace is empty and not focused, get rid of it */
730 DLOG("Getting rid of current = %p / %s (empty, unfocused)\n", current, current->name);
731 tree_close(current, DONT_KILL_WINDOW, false, false);
734 DLOG("Detaching current = %p / %s\n", current, current->name);
736 DLOG("Re-attaching current = %p / %s\n", current, current->name);
737 con_attach(current, first_content, false);
738 DLOG("Fixing the coordinates of floating containers\n");
740 TAILQ_FOREACH(floating_con, &(current->floating_head), floating_windows)
741 floating_fix_coordinates(floating_con, &(output->con->rect), &(first->con->rect));
742 DLOG("Done, next\n");
744 DLOG("re-attached all workspaces\n");
747 DLOG("now focusing next = %p\n", next);
749 workspace_show(con_get_workspace(next));
752 /* 3: move the dock clients to the first output */
754 TAILQ_FOREACH(child, &(output->con->nodes_head), nodes) {
755 if (child->type != CT_DOCKAREA)
757 DLOG("Handling dock con %p\n", child);
759 while (!TAILQ_EMPTY(&(child->nodes_head))) {
760 dock = TAILQ_FIRST(&(child->nodes_head));
763 nc = con_for_window(first->con, dock->window, &match);
764 DLOG("Moving dock client %p to nc %p\n", dock, nc);
766 DLOG("Re-attaching\n");
767 con_attach(dock, nc, false);
772 DLOG("destroying disappearing con %p\n", output->con);
773 tree_close(output->con, DONT_KILL_WINDOW, true, false);
774 DLOG("Done. Should be fine now\n");
778 output->to_be_disabled = false;
779 output->changed = false;
782 if (output->changed) {
783 output_change_mode(conn, output);
784 output->changed = false;
788 if (TAILQ_EMPTY(&outputs)) {
789 ELOG("No outputs found via RandR, disabling\n");
793 /* Verifies that there is at least one active output as a side-effect. */
796 /* Just go through each active output and assign one workspace */
797 TAILQ_FOREACH(output, &outputs, outputs) {
800 Con *content = output_get_content(output->con);
801 if (!TAILQ_EMPTY(&(content->nodes_head)))
803 DLOG("Should add ws for output %s\n", output->name);
804 init_ws_for_output(output, content);
807 /* Focus the primary screen, if possible */
808 TAILQ_FOREACH(output, &outputs, outputs) {
809 if (!output->primary || !output->con)
812 DLOG("Focusing primary output %s\n", output->name);
813 con_focus(con_descend_focused(output->con));
816 /* render_layout flushes */
824 * We have just established a connection to the X server and need the initial
825 * XRandR information to setup workspaces for each screen.
828 void randr_init(int *event_base) {
829 const xcb_query_extension_reply_t *extreply;
831 extreply = xcb_get_extension_data(conn, &xcb_randr_id);
832 if (!extreply->present) {
836 randr_query_outputs();
838 if (event_base != NULL)
839 *event_base = extreply->first_event;
841 xcb_randr_select_input(conn, root,
842 XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE |
843 XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE |
844 XCB_RANDR_NOTIFY_MASK_CRTC_CHANGE |
845 XCB_RANDR_NOTIFY_MASK_OUTPUT_PROPERTY);