i3
randr.c
Go to the documentation of this file.
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  * For more information on RandR, please see the X.org RandR specification at
8  * https://cgit.freedesktop.org/xorg/proto/randrproto/tree/randrproto.txt
9  * (take your time to read it completely, it answers all questions).
10  *
11  */
12 #include "all.h"
13 
14 #include <time.h>
15 
16 #include <xcb/randr.h>
17 
18 /* Pointer to the result of the query for primary output */
19 xcb_randr_get_output_primary_reply_t *primary;
20 
21 /* Stores all outputs available in your current session. */
22 struct outputs_head outputs = TAILQ_HEAD_INITIALIZER(outputs);
23 
24 /* This is the output covering the root window */
26 static bool has_randr_1_5 = false;
27 
28 /*
29  * Get a specific output by its internal X11 id. Used by randr_query_outputs
30  * to check if the output is new (only in the first scan) or if we are
31  * re-scanning.
32  *
33  */
34 static Output *get_output_by_id(xcb_randr_output_t id) {
35  Output *output;
36  TAILQ_FOREACH (output, &outputs, outputs) {
37  if (output->id == id) {
38  return output;
39  }
40  }
41 
42  return NULL;
43 }
44 
45 /*
46  * Returns the output with the given name or NULL.
47  * If require_active is true, only active outputs are considered.
48  *
49  */
50 Output *get_output_by_name(const char *name, const bool require_active) {
51  Output *output;
52  bool get_primary = (strcasecmp("primary", name) == 0);
53  TAILQ_FOREACH (output, &outputs, outputs) {
54  if (require_active && !output->active) {
55  continue;
56  }
57  if (output->primary && get_primary) {
58  return output;
59  }
60  struct output_name *output_name;
61  SLIST_FOREACH (output_name, &output->names_head, names) {
62  if (strcasecmp(output_name->name, name) == 0) {
63  return output;
64  }
65  }
66  }
67 
68  return NULL;
69 }
70 
71 /*
72  * Returns the first output which is active.
73  *
74  */
76  Output *output, *result = NULL;
77 
78  TAILQ_FOREACH (output, &outputs, outputs) {
79  if (output->active) {
80  if (output->primary) {
81  return output;
82  }
83  if (!result) {
84  result = output;
85  }
86  }
87  }
88 
89  if (result) {
90  return result;
91  }
92 
93  die("No usable outputs available.\n");
94 }
95 
96 /*
97  * Check whether there are any active outputs (excluding the root output).
98  *
99  */
100 static bool any_randr_output_active(void) {
101  Output *output;
102 
103  TAILQ_FOREACH (output, &outputs, outputs) {
104  if (output != root_output && !output->to_be_disabled && output->active)
105  return true;
106  }
107 
108  return false;
109 }
110 
111 /*
112  * Returns the active (!) output which contains the coordinates x, y or NULL
113  * if there is no output which contains these coordinates.
114  *
115  */
116 Output *get_output_containing(unsigned int x, unsigned int y) {
117  Output *output;
118  TAILQ_FOREACH (output, &outputs, outputs) {
119  if (!output->active)
120  continue;
121  DLOG("comparing x=%d y=%d with x=%d and y=%d width %d height %d\n",
122  x, y, output->rect.x, output->rect.y, output->rect.width, output->rect.height);
123  if (x >= output->rect.x && x < (output->rect.x + output->rect.width) &&
124  y >= output->rect.y && y < (output->rect.y + output->rect.height))
125  return output;
126  }
127 
128  return NULL;
129 }
130 
131 /*
132  * Returns the active output which contains the midpoint of the given rect. If
133  * such an output doesn't exist, returns the output which contains most of the
134  * rectangle or NULL if there is no output which intersects with it.
135  *
136  */
138  unsigned int mid_x = rect.x + rect.width / 2;
139  unsigned int mid_y = rect.y + rect.height / 2;
140  Output *output = get_output_containing(mid_x, mid_y);
141 
142  return output ? output : output_containing_rect(rect);
143 }
144 
145 /*
146  * Returns the active output which spans exactly the area specified by
147  * rect or NULL if there is no output like this.
148  *
149  */
151  Output *output;
152  TAILQ_FOREACH (output, &outputs, outputs) {
153  if (!output->active)
154  continue;
155  DLOG("comparing x=%d y=%d %dx%d with x=%d and y=%d %dx%d\n",
156  rect.x, rect.y, rect.width, rect.height,
157  output->rect.x, output->rect.y, output->rect.width, output->rect.height);
158  if (rect.x == output->rect.x && rect.width == output->rect.width &&
159  rect.y == output->rect.y && rect.height == output->rect.height)
160  return output;
161  }
162 
163  return NULL;
164 }
165 
166 /*
167  * In output_containing_rect, we check if any active output contains part of the container.
168  * We do this by checking if the output rect is intersected by the Rect.
169  * This is the 2-dimensional counterpart of get_output_containing.
170  * Returns the output with the maximum intersecting area.
171  *
172  */
174  Output *output;
175  int lx = rect.x, uy = rect.y;
176  int rx = rect.x + rect.width, by = rect.y + rect.height;
177  long max_area = 0;
178  Output *result = NULL;
179  TAILQ_FOREACH (output, &outputs, outputs) {
180  if (!output->active)
181  continue;
182  int lx_o = (int)output->rect.x, uy_o = (int)output->rect.y;
183  int rx_o = (int)(output->rect.x + output->rect.width), by_o = (int)(output->rect.y + output->rect.height);
184  DLOG("comparing x=%d y=%d with x=%d and y=%d width %d height %d\n",
185  rect.x, rect.y, output->rect.x, output->rect.y, output->rect.width, output->rect.height);
186  int left = max(lx, lx_o);
187  int right = min(rx, rx_o);
188  int bottom = min(by, by_o);
189  int top = max(uy, uy_o);
190  if (left < right && bottom > top) {
191  long area = (right - left) * (bottom - top);
192  if (area > max_area) {
193  result = output;
194  }
195  }
196  }
197  return result;
198 }
199 
200 /*
201  * Like get_output_next with close_far == CLOSEST_OUTPUT, but wraps.
202  *
203  * For example if get_output_next(D_DOWN, x, FARTHEST_OUTPUT) = NULL, then
204  * get_output_next_wrap(D_DOWN, x) will return the topmost output.
205  *
206  * This function always returns a output: if no active outputs can be found,
207  * current itself is returned.
208  *
209  */
211  Output *best = get_output_next(direction, current, CLOSEST_OUTPUT);
212  /* If no output can be found, wrap */
213  if (!best) {
214  direction_t opposite;
215  if (direction == D_RIGHT)
216  opposite = D_LEFT;
217  else if (direction == D_LEFT)
218  opposite = D_RIGHT;
219  else if (direction == D_DOWN)
220  opposite = D_UP;
221  else
222  opposite = D_DOWN;
223  best = get_output_next(opposite, current, FARTHEST_OUTPUT);
224  }
225  if (!best)
226  best = current;
227  DLOG("current = %s, best = %s\n", output_primary_name(current), output_primary_name(best));
228  return best;
229 }
230 
231 /*
232  * Gets the output which is the next one in the given direction.
233  *
234  * If close_far == CLOSEST_OUTPUT, then the output next to the current one will
235  * selected. If close_far == FARTHEST_OUTPUT, the output which is the last one
236  * in the given direction will be selected.
237  *
238  * NULL will be returned when no active outputs are present in the direction
239  * specified (note that “current” counts as such an output).
240  *
241  */
242 Output *get_output_next(direction_t direction, Output *current, output_close_far_t close_far) {
243  Rect *cur = &(current->rect),
244  *other;
245  Output *output,
246  *best = NULL;
247  TAILQ_FOREACH (output, &outputs, outputs) {
248  if (!output->active)
249  continue;
250 
251  other = &(output->rect);
252 
253  if ((direction == D_RIGHT && other->x > cur->x) ||
254  (direction == D_LEFT && other->x < cur->x)) {
255  /* Skip the output when it doesn’t overlap the other one’s y
256  * coordinate at all. */
257  if ((other->y + other->height) <= cur->y ||
258  (cur->y + cur->height) <= other->y)
259  continue;
260  } else if ((direction == D_DOWN && other->y > cur->y) ||
261  (direction == D_UP && other->y < cur->y)) {
262  /* Skip the output when it doesn’t overlap the other one’s x
263  * coordinate at all. */
264  if ((other->x + other->width) <= cur->x ||
265  (cur->x + cur->width) <= other->x)
266  continue;
267  } else
268  continue;
269 
270  /* No candidate yet? Start with this one. */
271  if (!best) {
272  best = output;
273  continue;
274  }
275 
276  if (close_far == CLOSEST_OUTPUT) {
277  /* Is this output better (closer to the current output) than our
278  * current best bet? */
279  if ((direction == D_RIGHT && other->x < best->rect.x) ||
280  (direction == D_LEFT && other->x > best->rect.x) ||
281  (direction == D_DOWN && other->y < best->rect.y) ||
282  (direction == D_UP && other->y > best->rect.y)) {
283  best = output;
284  continue;
285  }
286  } else {
287  /* Is this output better (farther to the current output) than our
288  * current best bet? */
289  if ((direction == D_RIGHT && other->x > best->rect.x) ||
290  (direction == D_LEFT && other->x < best->rect.x) ||
291  (direction == D_DOWN && other->y > best->rect.y) ||
292  (direction == D_UP && other->y < best->rect.y)) {
293  best = output;
294  continue;
295  }
296  }
297  }
298 
299  DLOG("current = %s, best = %s\n", output_primary_name(current), (best ? output_primary_name(best) : "NULL"));
300  return best;
301 }
302 
303 /*
304  * Creates an output covering the root window.
305  *
306  */
307 Output *create_root_output(xcb_connection_t *conn) {
308  Output *s = scalloc(1, sizeof(Output));
309 
310  s->active = false;
311  s->rect.x = 0;
312  s->rect.y = 0;
313  s->rect.width = root_screen->width_in_pixels;
314  s->rect.height = root_screen->height_in_pixels;
315 
316  struct output_name *output_name = scalloc(1, sizeof(struct output_name));
317  output_name->name = "xroot-0";
318  SLIST_INIT(&s->names_head);
319  SLIST_INSERT_HEAD(&s->names_head, output_name, names);
320 
321  return s;
322 }
323 
324 /*
325  * Initializes a CT_OUTPUT Con (searches existing ones from inplace restart
326  * before) to use for the given Output.
327  *
328  */
329 void output_init_con(Output *output) {
330  Con *con = NULL, *current;
331  bool reused = false;
332 
333  DLOG("init_con for output %s\n", output_primary_name(output));
334 
335  /* Search for a Con with that name directly below the root node. There
336  * might be one from a restored layout. */
337  TAILQ_FOREACH (current, &(croot->nodes_head), nodes) {
338  if (strcmp(current->name, output_primary_name(output)) != 0)
339  continue;
340 
341  con = current;
342  reused = true;
343  DLOG("Using existing con %p / %s\n", con, con->name);
344  break;
345  }
346 
347  if (con == NULL) {
348  con = con_new(croot, NULL);
349  FREE(con->name);
350  con->name = sstrdup(output_primary_name(output));
351  con->type = CT_OUTPUT;
352  con->layout = L_OUTPUT;
354  }
355  con->rect = output->rect;
356  output->con = con;
357 
358  char *name;
359  sasprintf(&name, "[i3 con] output %s", con->name);
360  x_set_name(con, name);
361  FREE(name);
362 
363  if (reused) {
364  DLOG("Not adding workspace, this was a reused con\n");
365  return;
366  }
367 
368  DLOG("Changing layout, adding top/bottom dockarea\n");
369  Con *topdock = con_new(NULL, NULL);
370  topdock->type = CT_DOCKAREA;
371  topdock->layout = L_DOCKAREA;
372  /* this container swallows dock clients */
373  Match *match = scalloc(1, sizeof(Match));
374  match_init(match);
375  match->dock = M_DOCK_TOP;
376  match->insert_where = M_BELOW;
377  TAILQ_INSERT_TAIL(&(topdock->swallow_head), match, matches);
378 
379  FREE(topdock->name);
380  topdock->name = sstrdup("topdock");
381 
382  sasprintf(&name, "[i3 con] top dockarea %s", con->name);
383  x_set_name(topdock, name);
384  FREE(name);
385  DLOG("attaching\n");
386  con_attach(topdock, con, false);
387 
388  /* content container */
389 
390  DLOG("adding main content container\n");
391  Con *content = con_new(NULL, NULL);
392  content->type = CT_CON;
393  content->layout = L_SPLITH;
394  FREE(content->name);
395  content->name = sstrdup("content");
396 
397  sasprintf(&name, "[i3 con] content %s", con->name);
398  x_set_name(content, name);
399  FREE(name);
400  con_attach(content, con, false);
401 
402  /* bottom dock container */
403  Con *bottomdock = con_new(NULL, NULL);
404  bottomdock->type = CT_DOCKAREA;
405  bottomdock->layout = L_DOCKAREA;
406  /* this container swallows dock clients */
407  match = scalloc(1, sizeof(Match));
408  match_init(match);
409  match->dock = M_DOCK_BOTTOM;
410  match->insert_where = M_BELOW;
411  TAILQ_INSERT_TAIL(&(bottomdock->swallow_head), match, matches);
412 
413  FREE(bottomdock->name);
414  bottomdock->name = sstrdup("bottomdock");
415 
416  sasprintf(&name, "[i3 con] bottom dockarea %s", con->name);
417  x_set_name(bottomdock, name);
418  FREE(name);
419  DLOG("attaching\n");
420  con_attach(bottomdock, con, false);
421 
422  /* Change focus to the content container */
423  TAILQ_REMOVE(&(con->focus_head), content, focused);
424  TAILQ_INSERT_HEAD(&(con->focus_head), content, focused);
425 }
426 
427 /*
428  * Initializes at least one workspace for this output, trying the following
429  * steps until there is at least one workspace:
430  *
431  * • Move existing workspaces, which are assigned to be on the given output, to
432  * the output.
433  * • Create the first assigned workspace for this output.
434  * • Create the first unused workspace.
435  *
436  */
437 void init_ws_for_output(Output *output) {
438  Con *content = output_get_content(output->con);
439  Con *previous_focus = con_get_workspace(focused);
440 
441  /* Iterate over all workspaces and check if any of them should be assigned
442  * to this output. */
443  Con *output_con;
444  TAILQ_FOREACH (output_con, &(croot->nodes_head), nodes) {
445  if (con_is_internal(output_con)) {
446  continue;
447  }
448 
449  Con *workspace;
450  TAILQ_FOREACH (workspace, &(output_get_content(output_con)->nodes_head), nodes) {
451  Con *workspace_out = get_assigned_output(workspace->name, workspace->num);
452  if (output->con != workspace_out) {
453  continue;
454  }
455 
456  DLOG("Moving workspace \"%s\" from output \"%s\" to \"%s\" due to assignment\n",
457  workspace->name, workspace_out->name, output_primary_name(output));
458  /* Need to copy output's rect since content is not yet rendered. We
459  * can't call render_con here because render_output only proceeds
460  * if a workspace exists. */
461  content->rect = output->con->rect;
462  workspace_move_to_output(workspace, output);
463  }
464  }
465 
466  /* Temporarily set the focused container, might not be initialized yet. */
467  focused = content;
468 
469  /* if a workspace exists, we are done now */
470  if (!TAILQ_EMPTY(&(content->nodes_head))) {
471  /* ensure that one of the workspaces is actually visible (in fullscreen
472  * mode), if they were invisible before, this might not be the case. */
473  Con *visible = NULL;
474  GREP_FIRST(visible, content, child->fullscreen_mode == CF_OUTPUT);
475  if (!visible) {
476  visible = TAILQ_FIRST(&(content->nodes_head));
477  workspace_show(visible);
478  }
479  goto restore_focus;
480  }
481 
482  /* otherwise, we create the first assigned ws for this output */
483  struct Workspace_Assignment *assignment;
485  if (!output_triggers_assignment(output, assignment)) {
486  continue;
487  }
488 
489  LOG("Initializing first assigned workspace \"%s\" for output \"%s\"\n",
490  assignment->name, assignment->output);
491  workspace_show_by_name(assignment->name);
492  goto restore_focus;
493  }
494 
495  /* if there is still no workspace, we create the first free workspace */
496  DLOG("Now adding a workspace\n");
498 
499 restore_focus:
500  if (previous_focus) {
501  workspace_show(previous_focus);
502  }
503 }
504 
505 /*
506  * This function needs to be called when changing the mode of an output when
507  * it already has some workspaces (or a bar window) assigned.
508  *
509  * It reconfigures the bar window for the new mode, copies the new rect into
510  * each workspace on this output and forces all windows on the affected
511  * workspaces to be reconfigured.
512  *
513  * It is necessary to call render_layout() afterwards.
514  *
515  */
516 static void output_change_mode(xcb_connection_t *conn, Output *output) {
517  DLOG("Output mode changed, updating rect\n");
518  assert(output->con != NULL);
519  output->con->rect = output->rect;
520 
521  Con *content, *workspace, *child;
522 
523  /* Point content to the container of the workspaces */
524  content = output_get_content(output->con);
525 
526  /* Fix the position of all floating windows on this output.
527  * The 'rect' of each workspace will be updated in src/render.c. */
528  TAILQ_FOREACH (workspace, &(content->nodes_head), nodes) {
529  TAILQ_FOREACH (child, &(workspace->floating_head), floating_windows) {
530  floating_fix_coordinates(child, &(workspace->rect), &(output->con->rect));
531  }
532  }
533 
534  /* If default_orientation is NO_ORIENTATION, we change the orientation of
535  * the workspaces and their children depending on output resolution. This is
536  * only done for workspaces with maximum one child. */
538  TAILQ_FOREACH (workspace, &(content->nodes_head), nodes) {
539  /* Workspaces with more than one child are left untouched because
540  * we do not want to change an existing layout. */
541  if (con_num_children(workspace) > 1)
542  continue;
543 
544  workspace->layout = (output->rect.height > output->rect.width) ? L_SPLITV : L_SPLITH;
545  DLOG("Setting workspace [%d,%s]'s layout to %d.\n", workspace->num, workspace->name, workspace->layout);
546  if ((child = TAILQ_FIRST(&(workspace->nodes_head)))) {
547  if (child->layout == L_SPLITV || child->layout == L_SPLITH)
548  child->layout = workspace->layout;
549  DLOG("Setting child [%d,%s]'s layout to %d.\n", child->num, child->name, child->layout);
550  }
551  }
552  }
553 }
554 
555 /*
556  * randr_query_outputs_15 uses RandR ≥ 1.5 to update outputs.
557  *
558  */
559 static bool randr_query_outputs_15(void) {
560 #if XCB_RANDR_MINOR_VERSION < 5
561  return false;
562 #else
563  /* RandR 1.5 available at compile-time, i.e. libxcb is new enough */
564  if (!has_randr_1_5) {
565  return false;
566  }
567  /* RandR 1.5 available at run-time (supported by the server and not
568  * disabled by the user) */
569  DLOG("Querying outputs using RandR 1.5\n");
570  xcb_generic_error_t *err;
571  xcb_randr_get_monitors_reply_t *monitors =
572  xcb_randr_get_monitors_reply(
573  conn, xcb_randr_get_monitors(conn, root, true), &err);
574  if (err != NULL) {
575  ELOG("Could not get RandR monitors: X11 error code %d\n", err->error_code);
576  free(err);
577  /* Fall back to RandR ≤ 1.4 */
578  return false;
579  }
580 
581  /* Mark all outputs as to_be_disabled, since xcb_randr_get_monitors() will
582  * only return active outputs. */
583  Output *output;
585  if (output != root_output) {
586  output->to_be_disabled = true;
587  }
588  }
589 
590  DLOG("%d RandR monitors found (timestamp %d)\n",
591  xcb_randr_get_monitors_monitors_length(monitors),
592  monitors->timestamp);
593 
594  xcb_randr_monitor_info_iterator_t iter;
595  for (iter = xcb_randr_get_monitors_monitors_iterator(monitors);
596  iter.rem;
597  xcb_randr_monitor_info_next(&iter)) {
598  const xcb_randr_monitor_info_t *monitor_info = iter.data;
599  xcb_get_atom_name_reply_t *atom_reply =
600  xcb_get_atom_name_reply(
601  conn, xcb_get_atom_name(conn, monitor_info->name), &err);
602  if (err != NULL) {
603  ELOG("Could not get RandR monitor name: X11 error code %d\n", err->error_code);
604  free(err);
605  continue;
606  }
607  char *name;
608  sasprintf(&name, "%.*s",
609  xcb_get_atom_name_name_length(atom_reply),
610  xcb_get_atom_name_name(atom_reply));
611  free(atom_reply);
612 
613  Output *new = get_output_by_name(name, false);
614  if (new == NULL) {
615  new = scalloc(1, sizeof(Output));
616 
617  SLIST_INIT(&new->names_head);
618 
619  /* Register associated output names in addition to the monitor name */
620  xcb_randr_output_t *randr_outputs = xcb_randr_monitor_info_outputs(monitor_info);
621  int randr_output_len = xcb_randr_monitor_info_outputs_length(monitor_info);
622  for (int i = 0; i < randr_output_len; i++) {
623  xcb_randr_output_t randr_output = randr_outputs[i];
624 
625  xcb_randr_get_output_info_reply_t *info =
626  xcb_randr_get_output_info_reply(conn,
627  xcb_randr_get_output_info(conn, randr_output, monitors->timestamp),
628  NULL);
629 
630  if (info != NULL && info->crtc != XCB_NONE) {
631  char *oname;
632  sasprintf(&oname, "%.*s",
633  xcb_randr_get_output_info_name_length(info),
634  xcb_randr_get_output_info_name(info));
635 
636  if (strcmp(name, oname) != 0) {
637  struct output_name *output_name = scalloc(1, sizeof(struct output_name));
638  output_name->name = sstrdup(oname);
639  SLIST_INSERT_HEAD(&new->names_head, output_name, names);
640  } else {
641  free(oname);
642  }
643  }
644  FREE(info);
645  }
646 
647  /* Insert the monitor name last, so that it's used as the primary name */
648  struct output_name *output_name = scalloc(1, sizeof(struct output_name));
650  SLIST_INSERT_HEAD(&new->names_head, output_name, names);
651 
652  if (monitor_info->primary) {
654  } else {
656  }
657  }
658  /* We specified get_active == true in xcb_randr_get_monitors(), so we
659  * will only receive active outputs. */
660  new->active = true;
661  new->to_be_disabled = false;
662 
663  new->primary = monitor_info->primary;
664 
665  new->changed =
666  update_if_necessary(&(new->rect.x), monitor_info->x) |
667  update_if_necessary(&(new->rect.y), monitor_info->y) |
668  update_if_necessary(&(new->rect.width), monitor_info->width) |
669  update_if_necessary(&(new->rect.height), monitor_info->height);
670 
671  DLOG("name %s, x %d, y %d, width %d px, height %d px, width %d mm, height %d mm, primary %d, automatic %d\n",
672  name,
673  monitor_info->x, monitor_info->y, monitor_info->width, monitor_info->height,
674  monitor_info->width_in_millimeters, monitor_info->height_in_millimeters,
675  monitor_info->primary, monitor_info->automatic);
676  free(name);
677  }
678  free(monitors);
679  return true;
680 #endif
681 }
682 
683 /*
684  * Gets called by randr_query_outputs_14() for each output. The function adds
685  * new outputs to the list of outputs, checks if the mode of existing outputs
686  * has been changed or if an existing output has been disabled. It will then
687  * change either the "changed" or the "to_be_deleted" flag of the output, if
688  * appropriate.
689  *
690  */
691 static void handle_output(xcb_connection_t *conn, xcb_randr_output_t id,
692  xcb_randr_get_output_info_reply_t *output,
693  xcb_timestamp_t cts,
694  xcb_randr_get_screen_resources_current_reply_t *res) {
695  /* each CRT controller has a position in which we are interested in */
696  xcb_randr_get_crtc_info_reply_t *crtc;
697 
698  Output *new = get_output_by_id(id);
699  bool existing = (new != NULL);
700  if (!existing) {
701  new = scalloc(1, sizeof(Output));
702  SLIST_INIT(&new->names_head);
703  }
704  new->id = id;
705  new->primary = (primary && primary->output == id);
706  while (!SLIST_EMPTY(&new->names_head)) {
707  FREE(SLIST_FIRST(&new->names_head)->name);
708  struct output_name *old_head = SLIST_FIRST(&new->names_head);
709  SLIST_REMOVE_HEAD(&new->names_head, names);
710  FREE(old_head);
711  }
712  struct output_name *output_name = scalloc(1, sizeof(struct output_name));
713  sasprintf(&output_name->name, "%.*s",
714  xcb_randr_get_output_info_name_length(output),
715  xcb_randr_get_output_info_name(output));
716  SLIST_INSERT_HEAD(&new->names_head, output_name, names);
717 
718  DLOG("found output with name %s\n", output_primary_name(new));
719 
720  /* Even if no CRTC is used at the moment, we store the output so that
721  * we do not need to change the list ever again (we only update the
722  * position/size) */
723  if (output->crtc == XCB_NONE) {
724  if (!existing) {
725  if (new->primary)
727  else
729  } else if (new->active)
730  new->to_be_disabled = true;
731  return;
732  }
733 
734  xcb_randr_get_crtc_info_cookie_t icookie;
735  icookie = xcb_randr_get_crtc_info(conn, output->crtc, cts);
736  if ((crtc = xcb_randr_get_crtc_info_reply(conn, icookie, NULL)) == NULL) {
737  DLOG("Skipping output %s: could not get CRTC (%p)\n",
738  output_primary_name(new), crtc);
739  free(new);
740  return;
741  }
742 
743  bool updated = update_if_necessary(&(new->rect.x), crtc->x) |
744  update_if_necessary(&(new->rect.y), crtc->y) |
745  update_if_necessary(&(new->rect.width), crtc->width) |
746  update_if_necessary(&(new->rect.height), crtc->height);
747  free(crtc);
748  new->active = (new->rect.width != 0 && new->rect.height != 0);
749  if (!new->active) {
750  DLOG("width/height 0/0, disabling output\n");
751  return;
752  }
753 
754  DLOG("mode: %dx%d+%d+%d\n", new->rect.width, new->rect.height,
755  new->rect.x, new->rect.y);
756 
757  /* If we don’t need to change an existing output or if the output
758  * does not exist in the first place, the case is simple: we either
759  * need to insert the new output or we are done. */
760  if (!updated || !existing) {
761  if (!existing) {
762  if (new->primary)
764  else
766  }
767  return;
768  }
769 
770  new->changed = true;
771 }
772 
773 /*
774  * randr_query_outputs_14 uses RandR ≤ 1.4 to update outputs.
775  *
776  */
777 static void randr_query_outputs_14(void) {
778  DLOG("Querying outputs using RandR ≤ 1.4\n");
779 
780  /* Get screen resources (primary output, crtcs, outputs, modes) */
781  xcb_randr_get_screen_resources_current_cookie_t rcookie;
782  rcookie = xcb_randr_get_screen_resources_current(conn, root);
783  xcb_randr_get_output_primary_cookie_t pcookie;
784  pcookie = xcb_randr_get_output_primary(conn, root);
785 
786  if ((primary = xcb_randr_get_output_primary_reply(conn, pcookie, NULL)) == NULL)
787  ELOG("Could not get RandR primary output\n");
788  else
789  DLOG("primary output is %08x\n", primary->output);
790 
791  xcb_randr_get_screen_resources_current_reply_t *res =
792  xcb_randr_get_screen_resources_current_reply(conn, rcookie, NULL);
793  if (res == NULL) {
794  ELOG("Could not query screen resources.\n");
795  return;
796  }
797 
798  /* timestamp of the configuration so that we get consistent replies to all
799  * requests (if the configuration changes between our different calls) */
800  const xcb_timestamp_t cts = res->config_timestamp;
801 
802  const int len = xcb_randr_get_screen_resources_current_outputs_length(res);
803 
804  /* an output is VGA-1, LVDS-1, etc. (usually physical video outputs) */
805  xcb_randr_output_t *randr_outputs = xcb_randr_get_screen_resources_current_outputs(res);
806 
807  /* Request information for each output */
808  xcb_randr_get_output_info_cookie_t ocookie[len];
809  for (int i = 0; i < len; i++)
810  ocookie[i] = xcb_randr_get_output_info(conn, randr_outputs[i], cts);
811 
812  /* Loop through all outputs available for this X11 screen */
813  for (int i = 0; i < len; i++) {
814  xcb_randr_get_output_info_reply_t *output;
815 
816  if ((output = xcb_randr_get_output_info_reply(conn, ocookie[i], NULL)) == NULL)
817  continue;
818 
819  handle_output(conn, randr_outputs[i], output, cts, res);
820  free(output);
821  }
822 
823  FREE(res);
824 }
825 
826 /*
827  * Move the content of an outputs container to the first output.
828  *
829  * TODO: Maybe use an on_destroy callback which is implement differently for
830  * different container types (CT_CONTENT vs. CT_DOCKAREA)?
831  *
832  */
833 static void move_content(Con *con) {
834  Con *first = get_first_output()->con;
835  Con *first_content = output_get_content(first);
836 
837  /* We need to move the workspaces from the disappearing output to the first output */
838  /* 1: Get the con to focus next */
839  Con *next = focused;
840 
841  /* 2: iterate through workspaces and re-assign them, fixing the coordinates
842  * of floating containers as we go */
843  Con *current;
844  Con *old_content = output_get_content(con);
845  while (!TAILQ_EMPTY(&(old_content->nodes_head))) {
846  current = TAILQ_FIRST(&(old_content->nodes_head));
847  if (current != next && TAILQ_EMPTY(&(current->focus_head))) {
848  /* the workspace is empty and not focused, get rid of it */
849  DLOG("Getting rid of current = %p / %s (empty, unfocused)\n", current, current->name);
850  tree_close_internal(current, DONT_KILL_WINDOW, false);
851  continue;
852  }
853  DLOG("Detaching current = %p / %s\n", current, current->name);
854  con_detach(current);
855  DLOG("Re-attaching current = %p / %s\n", current, current->name);
856  con_attach(current, first_content, false);
857  DLOG("Fixing the coordinates of floating containers\n");
858  Con *floating_con;
859  TAILQ_FOREACH (floating_con, &(current->floating_head), floating_windows) {
860  floating_fix_coordinates(floating_con, &(con->rect), &(first->rect));
861  }
862  }
863 
864  /* Restore focus after con_detach / con_attach. next can be NULL, see #3523. */
865  if (next) {
866  DLOG("now focusing next = %p\n", next);
867  con_focus(next);
869  }
870 
871  /* 3: move the dock clients to the first output */
872  Con *child;
873  TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
874  if (child->type != CT_DOCKAREA) {
875  continue;
876  }
877  DLOG("Handling dock con %p\n", child);
878  Con *dock;
879  while (!TAILQ_EMPTY(&(child->nodes_head))) {
880  dock = TAILQ_FIRST(&(child->nodes_head));
881  Con *nc;
882  Match *match;
883  nc = con_for_window(first, dock->window, &match);
884  DLOG("Moving dock client %p to nc %p\n", dock, nc);
885  con_detach(dock);
886  DLOG("Re-attaching\n");
887  con_attach(dock, nc, false);
888  DLOG("Done\n");
889  }
890  }
891 
892  DLOG("Destroying disappearing con %p\n", con);
894 }
895 
896 /*
897  * (Re-)queries the outputs via RandR and stores them in the list of outputs.
898  *
899  * If no outputs are found use the root window.
900  *
901  */
903  Output *output, *other;
904 
905  if (!randr_query_outputs_15()) {
907  }
908 
909  /* If there's no randr output, enable the output covering the root window. */
910  if (any_randr_output_active()) {
911  DLOG("Active RandR output found. Disabling root output.\n");
912  if (root_output && root_output->active) {
913  root_output->to_be_disabled = true;
914  }
915  } else {
916  DLOG("No active RandR output found. Enabling root output.\n");
917  root_output->active = true;
918  }
919 
920  /* Check for clones, disable the clones and reduce the mode to the
921  * lowest common mode */
922  TAILQ_FOREACH (output, &outputs, outputs) {
923  if (!output->active || output->to_be_disabled)
924  continue;
925  DLOG("output %p / %s, position (%d, %d), checking for clones\n",
926  output, output_primary_name(output), output->rect.x, output->rect.y);
927 
928  for (other = output;
929  other != TAILQ_END(&outputs);
930  other = TAILQ_NEXT(other, outputs)) {
931  if (other == output || !other->active || other->to_be_disabled)
932  continue;
933 
934  if (other->rect.x != output->rect.x ||
935  other->rect.y != output->rect.y)
936  continue;
937 
938  DLOG("output %p has the same position, its mode = %d x %d\n",
939  other, other->rect.width, other->rect.height);
940  uint32_t width = min(other->rect.width, output->rect.width);
941  uint32_t height = min(other->rect.height, output->rect.height);
942 
943  if (update_if_necessary(&(output->rect.width), width) |
944  update_if_necessary(&(output->rect.height), height))
945  output->changed = true;
946 
947  update_if_necessary(&(other->rect.width), width);
948  update_if_necessary(&(other->rect.height), height);
949 
950  DLOG("disabling output %p (%s)\n", other, output_primary_name(other));
951  other->to_be_disabled = true;
952 
953  DLOG("new output mode %d x %d, other mode %d x %d\n",
954  output->rect.width, output->rect.height,
955  other->rect.width, other->rect.height);
956  }
957  }
958 
959  /* Ensure that all outputs which are active also have a con. This is
960  * necessary because in the next step, a clone might get disabled. Example:
961  * LVDS1 active, VGA1 gets activated as a clone of LVDS1 (has no con).
962  * LVDS1 gets disabled. */
963  TAILQ_FOREACH (output, &outputs, outputs) {
964  if (output->active && output->con == NULL) {
965  DLOG("Need to initialize a Con for output %s\n", output_primary_name(output));
966  output_init_con(output);
967  output->changed = false;
968  }
969  }
970 
971  /* Ensure that all containers with type CT_OUTPUT have a valid
972  * corresponding entry in outputs. This can happen in situations related to
973  * those mentioned #3767 e.g. when a CT_OUTPUT is created from an in-place
974  * restart's layout but the output is disabled by a randr query happening
975  * at the same time. */
976  Con *con;
977  for (con = TAILQ_FIRST(&(croot->nodes_head)); con;) {
978  Con *next = TAILQ_NEXT(con, nodes);
979  if (!con_is_internal(con) && get_output_by_name(con->name, true) == NULL) {
980  DLOG("No output %s found, moving its old content to first output\n", con->name);
981  move_content(con);
982  }
983  con = next;
984  }
985 
986  /* Handle outputs which have a new mode or are disabled now (either
987  * because the user disabled them or because they are clones) */
988  TAILQ_FOREACH (output, &outputs, outputs) {
989  if (output->to_be_disabled) {
990  randr_disable_output(output);
991  }
992 
993  if (output->changed) {
994  output_change_mode(conn, output);
995  output->changed = false;
996  }
997  }
998 
999  /* Just go through each active output and assign one workspace */
1000  TAILQ_FOREACH (output, &outputs, outputs) {
1001  if (!output->active)
1002  continue;
1003  Con *content = output_get_content(output->con);
1004  if (!TAILQ_EMPTY(&(content->nodes_head)))
1005  continue;
1006  DLOG("Should add ws for output %s\n", output_primary_name(output));
1007  init_ws_for_output(output);
1008  }
1009 
1010  /* Focus the primary screen, if possible */
1011  TAILQ_FOREACH (output, &outputs, outputs) {
1012  if (!output->primary || !output->con)
1013  continue;
1014 
1015  DLOG("Focusing primary output %s\n", output_primary_name(output));
1016  Con *content = output_get_content(output->con);
1017  Con *ws = TAILQ_FIRST(&(content)->focus_head);
1018  workspace_show(ws);
1019  }
1020 
1021  /* render_layout flushes */
1023  tree_render();
1024 
1025  FREE(primary);
1026 }
1027 
1028 /*
1029  * Disables the output and moves its content.
1030  *
1031  */
1033  assert(output->to_be_disabled);
1034 
1035  output->active = false;
1036  DLOG("Output %s disabled, re-assigning workspaces/docks\n", output_primary_name(output));
1037 
1038  if (output->con != NULL) {
1039  /* clear the pointer before move_content calls tree_close_internal in which the memory is freed */
1040  Con *con = output->con;
1041  output->con = NULL;
1042  move_content(con);
1043  }
1044 
1045  output->to_be_disabled = false;
1046  output->changed = false;
1047 }
1048 
1049 static void fallback_to_root_output(void) {
1050  root_output->active = true;
1053 }
1054 
1055 /*
1056  * We have just established a connection to the X server and need the initial
1057  * XRandR information to setup workspaces for each screen.
1058  *
1059  */
1060 void randr_init(int *event_base, const bool disable_randr15) {
1061  const xcb_query_extension_reply_t *extreply;
1062 
1065 
1066  extreply = xcb_get_extension_data(conn, &xcb_randr_id);
1067  if (!extreply->present) {
1068  DLOG("RandR is not present, activating root output.\n");
1070  return;
1071  }
1072 
1073  xcb_generic_error_t *err;
1074  xcb_randr_query_version_reply_t *randr_version =
1075  xcb_randr_query_version_reply(
1076  conn, xcb_randr_query_version(conn, XCB_RANDR_MAJOR_VERSION, XCB_RANDR_MINOR_VERSION), &err);
1077  if (err != NULL) {
1078  ELOG("Could not query RandR version: X11 error code %d\n", err->error_code);
1079  free(err);
1081  return;
1082  }
1083 
1084  has_randr_1_5 = (randr_version->major_version >= 1) &&
1085  (randr_version->minor_version >= 5) &&
1086  !disable_randr15;
1087 
1088  free(randr_version);
1089 
1091 
1092  if (event_base != NULL)
1093  *event_base = extreply->first_event;
1094 
1095  xcb_randr_select_input(conn, root,
1096  XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE |
1097  XCB_RANDR_NOTIFY_MASK_OUTPUT_CHANGE |
1098  XCB_RANDR_NOTIFY_MASK_CRTC_CHANGE |
1099  XCB_RANDR_NOTIFY_MASK_OUTPUT_PROPERTY);
1100 
1101  xcb_flush(conn);
1102 }
workspace_show
void workspace_show(Con *workspace)
Switches to the given workspace.
Definition: workspace.c:417
TAILQ_FIRST
#define TAILQ_FIRST(head)
Definition: queue.h:336
tree_render
void tree_render(void)
Renders the tree, that is rendering all outputs using render_con() and pushing the changes to X11 usi...
Definition: tree.c:451
create_root_output
Output * create_root_output(xcb_connection_t *conn)
Creates an output covering the root window.
Definition: randr.c:307
L_OUTPUT
@ L_OUTPUT
Definition: data.h:95
randr_disable_output
void randr_disable_output(Output *output)
Disables the output and moves its content.
Definition: randr.c:1032
con_new
Con * con_new(Con *parent, i3Window *window)
A wrapper for con_new_skeleton, to retain the old con_new behaviour.
Definition: con.c:68
DLOG
#define DLOG(fmt,...)
Definition: libi3.h:104
randr_query_outputs_14
static void randr_query_outputs_14(void)
Definition: randr.c:777
match_init
void match_init(Match *match)
Initializes the Match data structure.
Definition: match.c:26
TAILQ_END
#define TAILQ_END(head)
Definition: queue.h:337
get_output_next
Output * get_output_next(direction_t direction, Output *current, output_close_far_t close_far)
Gets the output which is the next one in the given direction.
Definition: randr.c:242
L_SPLITV
@ L_SPLITV
Definition: data.h:96
get_output_from_rect
Output * get_output_from_rect(Rect rect)
Returns the active output which contains the midpoint of the given rect.
Definition: randr.c:137
Con::layout
layout_t layout
Definition: data.h:708
D_LEFT
@ D_LEFT
Definition: data.h:52
output_name
Definition: data.h:348
root_output
static Output * root_output
Definition: randr.c:25
Rect
Stores a rectangle, for example the size of a window, the child window etc.
Definition: data.h:155
get_output_containing
Output * get_output_containing(unsigned int x, unsigned int y)
Returns the active (!) output which contains the coordinates x, y or NULL if there is no output which...
Definition: randr.c:116
output_primary_name
char * output_primary_name(Output *output)
Retrieves the primary name of an output.
Definition: output.c:53
tree_close_internal
bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_parent)
Closes the given container including all children.
Definition: tree.c:191
max
int max(int a, int b)
Definition: util.c:28
NO_ORIENTATION
@ NO_ORIENTATION
Definition: data.h:56
update_if_necessary
bool update_if_necessary(uint32_t *destination, const uint32_t new_value)
Updates *destination with new_value and returns true if it was changed or false if it was the same.
Definition: util.c:126
sstrdup
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
die
#define die(...)
Definition: util.h:19
L_DOCKAREA
@ L_DOCKAREA
Definition: data.h:94
randr_query_outputs
void randr_query_outputs(void)
Initializes the specified output, assigning the specified workspace to it.
Definition: randr.c:902
SLIST_FOREACH
#define SLIST_FOREACH(var, head, field)
Definition: queue.h:114
output_init_con
void output_init_con(Output *output)
Initializes a CT_OUTPUT Con (searches existing ones from inplace restart before) to use for the given...
Definition: randr.c:329
Con::num
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
Definition: data.h:634
TAILQ_NEXT
#define TAILQ_NEXT(elm, field)
Definition: queue.h:338
ws_assignments
struct ws_assignments_head ws_assignments
Definition: main.c:95
FREE
#define FREE(pointer)
Definition: util.h:47
con_detach
void con_detach(Con *con)
Detaches the given container from its current parent.
Definition: con.c:229
ewmh_update_desktop_properties
void ewmh_update_desktop_properties(void)
Updates all the EWMH desktop properties.
Definition: ewmh.c:118
xoutput::rect
Rect rect
x, y, width, height
Definition: data.h:383
L_SPLITH
@ L_SPLITH
Definition: data.h:97
output_containing_rect
Output * output_containing_rect(Rect rect)
In output_containing_rect, we check if any active output contains part of the container.
Definition: randr.c:173
output_close_far_t
output_close_far_t
Definition: randr.h:22
all.h
CF_OUTPUT
@ CF_OUTPUT
Definition: data.h:591
y
#define y(x,...)
Definition: commands.c:18
output_triggers_assignment
bool output_triggers_assignment(Output *output, struct Workspace_Assignment *assignment)
Returns true if the first output assigned to a workspace with the given workspace assignment is the s...
Definition: workspace.c:116
TAILQ_EMPTY
#define TAILQ_EMPTY(head)
Definition: queue.h:344
SLIST_FIRST
#define SLIST_FIRST(head)
Definition: queue.h:109
get_output_next_wrap
Output * get_output_next_wrap(direction_t direction, Output *current)
Like get_output_next with close_far == CLOSEST_OUTPUT, but wraps.
Definition: randr.c:210
Workspace_Assignment
Stores which workspace (by name or number) goes to which output.
Definition: data.h:205
Rect::height
uint32_t height
Definition: data.h:159
SLIST_REMOVE_HEAD
#define SLIST_REMOVE_HEAD(head, field)
Definition: queue.h:149
get_first_output
Output * get_first_output(void)
Returns the first output which is active.
Definition: randr.c:75
workspace_show_by_name
void workspace_show_by_name(const char *num)
Looks up the workspace by name and switches to it.
Definition: workspace.c:549
fallback_to_root_output
static void fallback_to_root_output(void)
Definition: randr.c:1049
get_output_with_dimensions
Output * get_output_with_dimensions(Rect rect)
Returns the active output which spans exactly the area specified by rect or NULL if there is no outpu...
Definition: randr.c:150
TAILQ_INSERT_TAIL
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:376
handle_output
static void handle_output(xcb_connection_t *conn, xcb_randr_output_t id, xcb_randr_get_output_info_reply_t *output, xcb_timestamp_t cts, xcb_randr_get_screen_resources_current_reply_t *res)
Definition: randr.c:691
D_RIGHT
@ D_RIGHT
Definition: data.h:53
scalloc
void * scalloc(size_t num, size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
xoutput::id
xcb_randr_output_t id
Output id, so that we can requery the output directly later.
Definition: data.h:362
D_DOWN
@ D_DOWN
Definition: data.h:55
Rect::width
uint32_t width
Definition: data.h:158
Con::type
enum Con::@8 type
xoutput::to_be_disabled
bool to_be_disabled
Definition: data.h:371
Rect::x
uint32_t x
Definition: data.h:156
SLIST_INSERT_HEAD
#define SLIST_INSERT_HEAD(head, elm, field)
Definition: queue.h:138
con_num_children
int con_num_children(Con *con)
Returns the number of children of this container.
Definition: con.c:946
randr_init
void randr_init(int *event_base, const bool disable_randr15)
We have just established a connection to the X server and need the initial XRandR information to setu...
Definition: randr.c:1060
randr_query_outputs_15
static bool randr_query_outputs_15(void)
Definition: randr.c:559
TAILQ_HEAD_INITIALIZER
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
con_is_internal
bool con_is_internal(Con *con)
Returns true if the container is internal, such as __i3_scratch.
Definition: con.c:587
xoutput::changed
bool changed
Internal flags, necessary for querying RandR screens (happens in two stages)
Definition: data.h:370
SLIST_INIT
#define SLIST_INIT(head)
Definition: queue.h:127
xoutput::active
bool active
Whether the output is currently active (has a CRTC attached with a valid mode)
Definition: data.h:366
DONT_KILL_WINDOW
@ DONT_KILL_WINDOW
Definition: data.h:67
get_assigned_output
Con * get_assigned_output(const char *name, long parsed_num)
Returns the first output that is assigned to a workspace specified by the given name or number.
Definition: workspace.c:84
xoutput::con
Con * con
Pointer to the Con which represents this output.
Definition: data.h:380
has_randr_1_5
static bool has_randr_1_5
Definition: randr.c:26
root_screen
xcb_screen_t * root_screen
Definition: main.c:63
Con::rect
struct Rect rect
Definition: data.h:640
primary
xcb_randr_get_output_primary_reply_t * primary
Definition: randr.c:19
focused
struct Con * focused
Definition: tree.c:13
move_content
static void move_content(Con *con)
Definition: randr.c:833
xoutput
An Output is a physical output on your graphics driver.
Definition: data.h:360
Con::window
struct Window * window
Definition: data.h:671
SLIST_EMPTY
#define SLIST_EMPTY(head)
Definition: queue.h:111
outputs
struct outputs_head outputs
Definition: randr.c:22
con_attach
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
Definition: con.c:221
con_for_window
Con * con_for_window(Con *con, i3Window *window, Match **store_match)
Returns the first container below 'con' which wants to swallow this window TODO: priority.
Definition: con.c:851
config
Config config
Definition: config.c:17
get_output_by_id
static Output * get_output_by_id(xcb_randr_output_t id)
Definition: randr.c:34
Workspace_Assignment::output
char * output
Definition: data.h:207
FARTHEST_OUTPUT
@ FARTHEST_OUTPUT
Definition: randr.h:24
output_change_mode
static void output_change_mode(xcb_connection_t *conn, Output *output)
Definition: randr.c:516
create_workspace_on_output
Con * create_workspace_on_output(Output *output, Con *content)
Returns a pointer to a new workspace in the given output.
Definition: workspace.c:239
Workspace_Assignment::name
char * name
Definition: data.h:206
x_set_name
void x_set_name(Con *con, const char *name)
Sets the WM_NAME property (so, no UTF8, but used only for debugging anyways) of the given name.
Definition: x.c:1383
Match::insert_where
enum Match::@5 insert_where
floating_fix_coordinates
void floating_fix_coordinates(Con *con, Rect *old_rect, Rect *new_rect)
Fixes the coordinates of the floating window whenever the window gets reassigned to a different outpu...
Definition: floating.c:804
GREP_FIRST
#define GREP_FIRST(dest, head, condition)
Definition: util.h:38
output_name::name
char * name
Definition: data.h:349
CLOSEST_OUTPUT
@ CLOSEST_OUTPUT
Definition: randr.h:23
TAILQ_INSERT_HEAD
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:366
any_randr_output_active
static bool any_randr_output_active(void)
Definition: randr.c:100
conn
xcb_connection_t * conn
XCB connection and root screen.
Definition: main.c:51
init_ws_for_output
void init_ws_for_output(Output *output)
Initializes at least one workspace for this output, trying the following steps until there is at leas...
Definition: randr.c:437
con_focus
void con_focus(Con *con)
Sets input focus to the given container.
Definition: con.c:245
TAILQ_FOREACH
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:347
get_output_by_name
Output * get_output_by_name(const char *name, const bool require_active)
Returns the output with the given name or NULL.
Definition: randr.c:50
croot
struct Con * croot
Definition: tree.c:12
Match::dock
enum Match::@3 dock
xoutput::primary
bool primary
Definition: data.h:372
Match
A "match" is a data structure which acts like a mask or expression to match certain windows or not.
Definition: data.h:492
Con::fullscreen_mode
fullscreen_mode_t fullscreen_mode
Definition: data.h:687
Con::name
char * name
Definition: data.h:650
root
xcb_window_t root
Definition: main.c:64
min
int min(int a, int b)
Definition: util.c:24
LOG
#define LOG(fmt,...)
Definition: libi3.h:94
D_UP
@ D_UP
Definition: data.h:54
workspace_move_to_output
void workspace_move_to_output(Con *ws, Output *output)
Move the given workspace to the specified output.
Definition: workspace.c:963
con_get_workspace
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Definition: con.c:476
Rect::y
uint32_t y
Definition: data.h:157
sasprintf
int sasprintf(char **strp, const char *fmt,...)
Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory avail...
Con
A 'Con' represents everything from the X11 root window down to a single X11 window.
Definition: data.h:604
output_get_content
Con * output_get_content(Con *output)
Returns the output container below the given output container.
Definition: output.c:16
ELOG
#define ELOG(fmt,...)
Definition: libi3.h:99
con_fix_percent
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given container.
Definition: con.c:1010
direction_t
direction_t
Definition: data.h:52
Config::default_orientation
int default_orientation
Default orientation for new containers.
Definition: configuration.h:105
TAILQ_REMOVE
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:402