i3
con.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  * con.c: Functions which deal with containers directly (creating containers,
8  * searching containers, getting specific properties from containers,
9  * …).
10  *
11  */
12 #include "all.h"
13 #include "yajl_utils.h"
14 
15 static void con_on_remove_child(Con *con);
16 
17 /*
18  * force parent split containers to be redrawn
19  *
20  */
22  Con *parent = con;
23 
24  while (parent != NULL && parent->type != CT_WORKSPACE && parent->type != CT_DOCKAREA) {
25  if (!con_is_leaf(parent)) {
26  FREE(parent->deco_render_params);
27  }
28 
29  parent = parent->parent;
30  }
31 }
32 
33 /*
34  * Create a new container (and attach it to the given parent, if not NULL).
35  * This function only initializes the data structures.
36  *
37  */
38 Con *con_new_skeleton(Con *parent, i3Window *window) {
39  Con *new = scalloc(1, sizeof(Con));
40  new->on_remove_child = con_on_remove_child;
42  new->type = CT_CON;
43  new->window = window;
44  new->border_style = config.default_border;
45  new->current_border_width = -1;
46  if (window) {
47  new->depth = window->depth;
48  } else {
49  new->depth = root_depth;
50  }
51  DLOG("opening window\n");
52 
53  TAILQ_INIT(&(new->floating_head));
54  TAILQ_INIT(&(new->nodes_head));
55  TAILQ_INIT(&(new->focus_head));
56  TAILQ_INIT(&(new->swallow_head));
57  TAILQ_INIT(&(new->marks_head));
58 
59  if (parent != NULL)
60  con_attach(new, parent, false);
61 
62  return new;
63 }
64 
65 /* A wrapper for con_new_skeleton, to retain the old con_new behaviour
66  *
67  */
68 Con *con_new(Con *parent, i3Window *window) {
69  Con *new = con_new_skeleton(parent, window);
70  x_con_init(new);
71  return new;
72 }
73 
74 /*
75  * Frees the specified container.
76  *
77  */
78 void con_free(Con *con) {
79  free(con->name);
82  while (!TAILQ_EMPTY(&(con->swallow_head))) {
83  Match *match = TAILQ_FIRST(&(con->swallow_head));
84  TAILQ_REMOVE(&(con->swallow_head), match, matches);
85  match_free(match);
86  free(match);
87  }
88  while (!TAILQ_EMPTY(&(con->marks_head))) {
89  mark_t *mark = TAILQ_FIRST(&(con->marks_head));
90  TAILQ_REMOVE(&(con->marks_head), mark, marks);
91  FREE(mark->name);
92  FREE(mark);
93  }
94  DLOG("con %p freed\n", con);
95  free(con);
96 }
97 
98 static void _con_attach(Con *con, Con *parent, Con *previous, bool ignore_focus) {
99  con->parent = parent;
100  Con *loop;
101  Con *current = previous;
102  struct nodes_head *nodes_head = &(parent->nodes_head);
103  struct focus_head *focus_head = &(parent->focus_head);
104 
105  /* Workspaces are handled differently: they need to be inserted at the
106  * right position. */
107  if (con->type == CT_WORKSPACE) {
108  DLOG("it's a workspace. num = %d\n", con->num);
109  if (con->num == -1 || TAILQ_EMPTY(nodes_head)) {
110  TAILQ_INSERT_TAIL(nodes_head, con, nodes);
111  } else {
112  current = TAILQ_FIRST(nodes_head);
113  if (con->num < current->num) {
114  /* we need to insert the container at the beginning */
115  TAILQ_INSERT_HEAD(nodes_head, con, nodes);
116  } else {
117  while (current->num != -1 && con->num > current->num) {
118  current = TAILQ_NEXT(current, nodes);
119  if (current == TAILQ_END(nodes_head)) {
120  current = NULL;
121  break;
122  }
123  }
124  /* we need to insert con after current, if current is not NULL */
125  if (current)
126  TAILQ_INSERT_BEFORE(current, con, nodes);
127  else
128  TAILQ_INSERT_TAIL(nodes_head, con, nodes);
129  }
130  }
131  goto add_to_focus_head;
132  }
133 
134  if (parent->type == CT_DOCKAREA) {
135  /* Insert dock client, sorting alphanumerically by class and then
136  * instance name. This makes dock client order deterministic. As a side
137  * effect, bars without a custom bar id will be sorted according to
138  * their declaration order in the config file. See #3491. */
139  current = NULL;
140  TAILQ_FOREACH (loop, nodes_head, nodes) {
141  int result = strcasecmp_nullable(con->window->class_class, loop->window->class_class);
142  if (result == 0) {
144  }
145  if (result < 0) {
146  current = loop;
147  break;
148  }
149  }
150  if (current) {
151  TAILQ_INSERT_BEFORE(loop, con, nodes);
152  } else {
153  TAILQ_INSERT_TAIL(nodes_head, con, nodes);
154  }
155  goto add_to_focus_head;
156  }
157 
158  if (con->type == CT_FLOATING_CON) {
159  DLOG("Inserting into floating containers\n");
160  TAILQ_INSERT_TAIL(&(parent->floating_head), con, floating_windows);
161  } else {
162  if (!ignore_focus) {
163  /* Get the first tiling container in focus stack */
164  TAILQ_FOREACH (loop, &(parent->focus_head), focused) {
165  if (loop->type == CT_FLOATING_CON)
166  continue;
167  current = loop;
168  break;
169  }
170  }
171 
172  /* When the container is not a split container (but contains a window)
173  * and is attached to a workspace, we check if the user configured a
174  * workspace_layout. This is done in workspace_attach_to, which will
175  * provide us with the container to which we should attach (either the
176  * workspace or a new split container with the configured
177  * workspace_layout).
178  */
179  if (con->window != NULL &&
180  parent->type == CT_WORKSPACE &&
181  parent->workspace_layout != L_DEFAULT) {
182  DLOG("Parent is a workspace. Applying default layout...\n");
183  Con *target = workspace_attach_to(parent);
184 
185  /* Attach the original con to this new split con instead */
186  nodes_head = &(target->nodes_head);
187  focus_head = &(target->focus_head);
188  con->parent = target;
189  current = NULL;
190 
191  DLOG("done\n");
192  }
193 
194  /* Insert the container after the tiling container, if found.
195  * When adding to a CT_OUTPUT, just append one after another. */
196  if (current != NULL && parent->type != CT_OUTPUT) {
197  DLOG("Inserting con = %p after con %p\n", con, current);
198  TAILQ_INSERT_AFTER(nodes_head, current, con, nodes);
199  } else
200  TAILQ_INSERT_TAIL(nodes_head, con, nodes);
201  }
202 
203 add_to_focus_head:
204  /* We insert to the TAIL because con_focus() will correct this.
205  * This way, we have the option to insert Cons without having
206  * to focus them. */
207  TAILQ_INSERT_TAIL(focus_head, con, focused);
209 }
210 
211 /*
212  * Attaches the given container to the given parent. This happens when moving
213  * a container or when inserting a new container at a specific place in the
214  * tree.
215  *
216  * ignore_focus is to just insert the Con at the end (useful when creating a
217  * new split container *around* some containers, that is, detaching and
218  * attaching them in order without wanting to mess with the focus in between).
219  *
220  */
221 void con_attach(Con *con, Con *parent, bool ignore_focus) {
222  _con_attach(con, parent, NULL, ignore_focus);
223 }
224 
225 /*
226  * Detaches the given container from its current parent
227  *
228  */
229 void con_detach(Con *con) {
231  if (con->type == CT_FLOATING_CON) {
232  TAILQ_REMOVE(&(con->parent->floating_head), con, floating_windows);
233  TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
234  } else {
235  TAILQ_REMOVE(&(con->parent->nodes_head), con, nodes);
236  TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
237  }
238 }
239 
240 /*
241  * Sets input focus to the given container. Will be updated in X11 in the next
242  * run of x_push_changes().
243  *
244  */
245 void con_focus(Con *con) {
246  assert(con != NULL);
247  DLOG("con_focus = %p\n", con);
248 
249  /* 1: set focused-pointer to the new con */
250  /* 2: exchange the position of the container in focus stack of the parent all the way up */
251  TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
252  TAILQ_INSERT_HEAD(&(con->parent->focus_head), con, focused);
253  if (con->parent->parent != NULL)
254  con_focus(con->parent);
255 
256  focused = con;
257  /* We can't blindly reset non-leaf containers since they might have
258  * other urgent children. Therefore we only reset leafs and propagate
259  * the changes upwards via con_update_parents_urgency() which does proper
260  * checks before resetting the urgency.
261  */
262  if (con->urgent && con_is_leaf(con)) {
263  con_set_urgency(con, false);
266  ipc_send_window_event("urgent", con);
267  }
268 }
269 
270 /*
271  * Raise container to the top if it is floating or inside some floating
272  * container.
273  *
274  */
275 static void con_raise(Con *con) {
276  Con *floating = con_inside_floating(con);
277  if (floating) {
278  floating_raise_con(floating);
279  }
280 }
281 
282 /*
283  * Sets input focus to the given container and raises it to the top.
284  *
285  */
286 void con_activate(Con *con) {
287  con_focus(con);
288  con_raise(con);
289 }
290 
291 /*
292  * Activates the container like in con_activate but removes fullscreen
293  * restrictions and properly warps the pointer if needed.
294  *
295  */
297  Con *ws = con_get_workspace(con);
298  Con *previous_focus = focused;
299  Con *fullscreen_on_ws = con_get_fullscreen_covering_ws(ws);
300 
301  if (fullscreen_on_ws && fullscreen_on_ws != con && !con_has_parent(con, fullscreen_on_ws)) {
302  con_disable_fullscreen(fullscreen_on_ws);
303  }
304 
305  con_activate(con);
306 
307  /* If the container is not on the current workspace, workspace_show() will
308  * switch to a different workspace and (if enabled) trigger a mouse pointer
309  * warp to the currently focused container (!) on the target workspace.
310  *
311  * Therefore, before calling workspace_show(), we make sure that 'con' will
312  * be focused on the workspace. However, we cannot just con_focus(con)
313  * because then the pointer will not be warped at all (the code thinks we
314  * are already there).
315  *
316  * So we focus 'con' to make it the currently focused window of the target
317  * workspace, then revert focus. */
318  if (ws != con_get_workspace(previous_focus)) {
319  con_activate(previous_focus);
320  /* Now switch to the workspace, then focus */
321  workspace_show(ws);
322  con_activate(con);
323  }
324 }
325 
326 /*
327  * Closes the given container.
328  *
329  */
330 void con_close(Con *con, kill_window_t kill_window) {
331  assert(con != NULL);
332  DLOG("Closing con = %p.\n", con);
333 
334  /* We never close output or root containers. */
335  if (con->type == CT_OUTPUT || con->type == CT_ROOT) {
336  DLOG("con = %p is of type %d, not closing anything.\n", con, con->type);
337  return;
338  }
339 
340  if (con->type == CT_WORKSPACE) {
341  DLOG("con = %p is a workspace, closing all children instead.\n", con);
342  Con *child, *nextchild;
343  for (child = TAILQ_FIRST(&(con->focus_head)); child;) {
344  nextchild = TAILQ_NEXT(child, focused);
345  DLOG("killing child = %p.\n", child);
346  tree_close_internal(child, kill_window, false);
347  child = nextchild;
348  }
349 
350  return;
351  }
352 
353  tree_close_internal(con, kill_window, false);
354 }
355 
356 /*
357  * Returns true when this node is a leaf node (has no children)
358  *
359  */
360 bool con_is_leaf(Con *con) {
361  return TAILQ_EMPTY(&(con->nodes_head));
362 }
363 
364 /*
365  * Returns true when this con is a leaf node with a managed X11 window (e.g.,
366  * excluding dock containers)
367  */
369  return (con != NULL && con->window != NULL && con->window->id != XCB_WINDOW_NONE && con_get_workspace(con) != NULL);
370 }
371 
372 /*
373  * Returns true if this node has regular or floating children.
374  *
375  */
376 bool con_has_children(Con *con) {
377  return (!con_is_leaf(con) || !TAILQ_EMPTY(&(con->floating_head)));
378 }
379 
380 /*
381  * Returns true if a container should be considered split.
382  *
383  */
384 bool con_is_split(Con *con) {
385  if (con_is_leaf(con))
386  return false;
387 
388  switch (con->layout) {
389  case L_DOCKAREA:
390  case L_OUTPUT:
391  return false;
392 
393  default:
394  return true;
395  }
396 }
397 
398 /*
399  * This will only return true for containers which have some parent with
400  * a tabbed / stacked parent of which they are not the currently focused child.
401  *
402  */
403 bool con_is_hidden(Con *con) {
404  Con *current = con;
405 
406  /* ascend to the workspace level and memorize the highest-up container
407  * which is stacked or tabbed. */
408  while (current != NULL && current->type != CT_WORKSPACE) {
409  Con *parent = current->parent;
410  if (parent != NULL && (parent->layout == L_TABBED || parent->layout == L_STACKED)) {
411  if (TAILQ_FIRST(&(parent->focus_head)) != current)
412  return true;
413  }
414 
415  current = parent;
416  }
417 
418  return false;
419 }
420 
421 /*
422  * Returns whether the container or any of its children is sticky.
423  *
424  */
425 bool con_is_sticky(Con *con) {
426  if (con->sticky)
427  return true;
428 
429  Con *child;
430  TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
431  if (con_is_sticky(child))
432  return true;
433  }
434 
435  return false;
436 }
437 
438 /*
439  * Returns true if this node accepts a window (if the node swallows windows,
440  * it might already have swallowed enough and cannot hold any more).
441  *
442  */
444  /* 1: workspaces never accept direct windows */
445  if (con->type == CT_WORKSPACE)
446  return false;
447 
448  if (con_is_split(con)) {
449  DLOG("container %p does not accept windows, it is a split container.\n", con);
450  return false;
451  }
452 
453  /* TODO: if this is a swallowing container, we need to check its max_clients */
454  return (con->window == NULL);
455 }
456 
457 /*
458  * Gets the output container (first container with CT_OUTPUT in hierarchy) this
459  * node is on.
460  *
461  */
463  Con *result = con;
464  while (result != NULL && result->type != CT_OUTPUT)
465  result = result->parent;
466  /* We must be able to get an output because focus can never be set higher
467  * in the tree (root node cannot be focused). */
468  assert(result != NULL);
469  return result;
470 }
471 
472 /*
473  * Gets the workspace container this node is on.
474  *
475  */
477  Con *result = con;
478  while (result != NULL && result->type != CT_WORKSPACE)
479  result = result->parent;
480  return result;
481 }
482 
483 /*
484  * Searches parents of the given 'con' until it reaches one with the specified
485  * 'orientation'. Aborts when it comes across a floating_con.
486  *
487  */
489  DLOG("Searching for parent of Con %p with orientation %d\n", con, orientation);
490  Con *parent = con->parent;
491  if (parent->type == CT_FLOATING_CON)
492  return NULL;
493  while (con_orientation(parent) != orientation) {
494  DLOG("Need to go one level further up\n");
495  parent = parent->parent;
496  /* Abort when we reach a floating con, or an output con */
497  if (parent &&
498  (parent->type == CT_FLOATING_CON ||
499  parent->type == CT_OUTPUT ||
500  (parent->parent && parent->parent->type == CT_OUTPUT)))
501  parent = NULL;
502  if (parent == NULL)
503  break;
504  }
505  DLOG("Result: %p\n", parent);
506  return parent;
507 }
508 
509 /*
510  * helper data structure for the breadth-first-search in
511  * con_get_fullscreen_con()
512  *
513  */
514 struct bfs_entry {
516 
517  TAILQ_ENTRY(bfs_entry) entries;
518 };
519 
520 /*
521  * Returns the first fullscreen node below this node.
522  *
523  */
525  Con *current, *child;
526 
527  /* TODO: is breadth-first-search really appropriate? (check as soon as
528  * fullscreen levels and fullscreen for containers is implemented) */
529  TAILQ_HEAD(bfs_head, bfs_entry) bfs_head = TAILQ_HEAD_INITIALIZER(bfs_head);
530  struct bfs_entry *entry = smalloc(sizeof(struct bfs_entry));
531  entry->con = con;
532  TAILQ_INSERT_TAIL(&bfs_head, entry, entries);
533 
534  while (!TAILQ_EMPTY(&bfs_head)) {
535  entry = TAILQ_FIRST(&bfs_head);
536  current = entry->con;
537  if (current != con && current->fullscreen_mode == fullscreen_mode) {
538  /* empty the queue */
539  while (!TAILQ_EMPTY(&bfs_head)) {
540  entry = TAILQ_FIRST(&bfs_head);
541  TAILQ_REMOVE(&bfs_head, entry, entries);
542  free(entry);
543  }
544  return current;
545  }
546 
547  TAILQ_REMOVE(&bfs_head, entry, entries);
548  free(entry);
549 
550  TAILQ_FOREACH (child, &(current->nodes_head), nodes) {
551  entry = smalloc(sizeof(struct bfs_entry));
552  entry->con = child;
553  TAILQ_INSERT_TAIL(&bfs_head, entry, entries);
554  }
555 
556  TAILQ_FOREACH (child, &(current->floating_head), floating_windows) {
557  entry = smalloc(sizeof(struct bfs_entry));
558  entry->con = child;
559  TAILQ_INSERT_TAIL(&bfs_head, entry, entries);
560  }
561  }
562 
563  return NULL;
564 }
565 
566 /*
567  * Returns the fullscreen node that covers the given workspace if it exists.
568  * This is either a CF_GLOBAL fullscreen container anywhere or a CF_OUTPUT
569  * fullscreen container in the workspace.
570  *
571  */
573  if (!ws) {
574  return NULL;
575  }
577  if (!fs) {
578  return con_get_fullscreen_con(ws, CF_OUTPUT);
579  }
580  return fs;
581 }
582 
583 /*
584  * Returns true if the container is internal, such as __i3_scratch
585  *
586  */
588  return (con->name[0] == '_' && con->name[1] == '_');
589 }
590 
591 /*
592  * Returns true if the node is floating.
593  *
594  */
596  assert(con != NULL);
597  return (con->floating >= FLOATING_AUTO_ON);
598 }
599 
600 /*
601  * Returns true if the container is a docked container.
602  *
603  */
605  if (con->parent == NULL)
606  return false;
607 
608  if (con->parent->type == CT_DOCKAREA)
609  return true;
610 
611  return con_is_docked(con->parent);
612 }
613 
614 /*
615  * Checks if the given container is either floating or inside some floating
616  * container. It returns the FLOATING_CON container.
617  *
618  */
620  assert(con != NULL);
621  if (con->type == CT_FLOATING_CON)
622  return con;
623 
624  if (con->floating >= FLOATING_AUTO_ON)
625  return con->parent;
626 
627  if (con->type == CT_WORKSPACE || con->type == CT_OUTPUT)
628  return NULL;
629 
630  return con_inside_floating(con->parent);
631 }
632 
633 /*
634  * Checks if the given container is inside a focused container.
635  *
636  */
638  if (con == focused)
639  return true;
640  if (!con->parent)
641  return false;
642  return con_inside_focused(con->parent);
643 }
644 
645 /*
646  * Checks if the container has the given parent as an actual parent.
647  *
648  */
649 bool con_has_parent(Con *con, Con *parent) {
650  Con *current = con->parent;
651  if (current == NULL) {
652  return false;
653  }
654 
655  if (current == parent) {
656  return true;
657  }
658 
659  return con_has_parent(current, parent);
660 }
661 
662 /*
663  * Returns the container with the given client window ID or NULL if no such
664  * container exists.
665  *
666  */
667 Con *con_by_window_id(xcb_window_t window) {
668  Con *con;
670  if (con->window != NULL && con->window->id == window) {
671  return con;
672  }
673  }
674  return NULL;
675 }
676 
677 /*
678  * Returns the container with the given container ID or NULL if no such
679  * container exists.
680  *
681  */
682 Con *con_by_con_id(long target) {
683  Con *con;
685  if (con == (Con *)target) {
686  return con;
687  }
688  }
689 
690  return NULL;
691 }
692 
693 /*
694  * Returns true if the given container (still) exists.
695  * This can be used, e.g., to make sure a container hasn't been closed in the meantime.
696  *
697  */
699  return con_by_con_id((long)con) != NULL;
700 }
701 
702 /*
703  * Returns the container with the given frame ID or NULL if no such container
704  * exists.
705  *
706  */
707 Con *con_by_frame_id(xcb_window_t frame) {
708  Con *con;
710  if (con->frame.id == frame) {
711  return con;
712  }
713  }
714  return NULL;
715 }
716 
717 /*
718  * Returns the container with the given mark or NULL if no such container
719  * exists.
720  *
721  */
722 Con *con_by_mark(const char *mark) {
723  Con *con;
725  if (con_has_mark(con, mark))
726  return con;
727  }
728 
729  return NULL;
730 }
731 
732 /*
733  * Returns true if and only if the given containers holds the mark.
734  *
735  */
736 bool con_has_mark(Con *con, const char *mark) {
737  mark_t *current;
738  TAILQ_FOREACH (current, &(con->marks_head), marks) {
739  if (strcmp(current->name, mark) == 0)
740  return true;
741  }
742 
743  return false;
744 }
745 
746 /*
747  * Toggles the mark on a container.
748  * If the container already has this mark, the mark is removed.
749  * Otherwise, the mark is assigned to the container.
750  *
751  */
752 void con_mark_toggle(Con *con, const char *mark, mark_mode_t mode) {
753  assert(con != NULL);
754  DLOG("Toggling mark \"%s\" on con = %p.\n", mark, con);
755 
756  if (con_has_mark(con, mark)) {
757  con_unmark(con, mark);
758  } else {
759  con_mark(con, mark, mode);
760  }
761 }
762 
763 /*
764  * Assigns a mark to the container.
765  *
766  */
767 void con_mark(Con *con, const char *mark, mark_mode_t mode) {
768  assert(con != NULL);
769  DLOG("Setting mark \"%s\" on con = %p.\n", mark, con);
770 
771  con_unmark(NULL, mark);
772  if (mode == MM_REPLACE) {
773  DLOG("Removing all existing marks on con = %p.\n", con);
774 
775  mark_t *current;
776  while (!TAILQ_EMPTY(&(con->marks_head))) {
777  current = TAILQ_FIRST(&(con->marks_head));
778  con_unmark(con, current->name);
779  }
780  }
781 
782  mark_t *new = scalloc(1, sizeof(mark_t));
783  new->name = sstrdup(mark);
784  TAILQ_INSERT_TAIL(&(con->marks_head), new, marks);
785  ipc_send_window_event("mark", con);
786 
787  con->mark_changed = true;
788 }
789 
790 /*
791  * Removes marks from containers.
792  * If con is NULL, all containers are considered.
793  * If name is NULL, this removes all existing marks.
794  * Otherwise, it will only remove the given mark (if it is present).
795  *
796  */
797 void con_unmark(Con *con, const char *name) {
798  Con *current;
799  if (name == NULL) {
800  DLOG("Unmarking all containers.\n");
801  TAILQ_FOREACH (current, &all_cons, all_cons) {
802  if (con != NULL && current != con)
803  continue;
804 
805  if (TAILQ_EMPTY(&(current->marks_head)))
806  continue;
807 
808  mark_t *mark;
809  while (!TAILQ_EMPTY(&(current->marks_head))) {
810  mark = TAILQ_FIRST(&(current->marks_head));
811  FREE(mark->name);
812  TAILQ_REMOVE(&(current->marks_head), mark, marks);
813  FREE(mark);
814 
815  ipc_send_window_event("mark", current);
816  }
817 
818  current->mark_changed = true;
819  }
820  } else {
821  DLOG("Removing mark \"%s\".\n", name);
822  current = (con == NULL) ? con_by_mark(name) : con;
823  if (current == NULL) {
824  DLOG("No container found with this mark, so there is nothing to do.\n");
825  return;
826  }
827 
828  DLOG("Found mark on con = %p. Removing it now.\n", current);
829  current->mark_changed = true;
830 
831  mark_t *mark;
832  TAILQ_FOREACH (mark, &(current->marks_head), marks) {
833  if (strcmp(mark->name, name) != 0)
834  continue;
835 
836  FREE(mark->name);
837  TAILQ_REMOVE(&(current->marks_head), mark, marks);
838  FREE(mark);
839 
840  ipc_send_window_event("mark", current);
841  break;
842  }
843  }
844 }
845 
846 /*
847  * Returns the first container below 'con' which wants to swallow this window
848  * TODO: priority
849  *
850  */
851 Con *con_for_window(Con *con, i3Window *window, Match **store_match) {
852  Con *child;
853  Match *match;
854  //DLOG("searching con for window %p starting at con %p\n", window, con);
855  //DLOG("class == %s\n", window->class_class);
856 
857  TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
858  TAILQ_FOREACH (match, &(child->swallow_head), matches) {
859  if (!match_matches_window(match, window))
860  continue;
861  if (store_match != NULL)
862  *store_match = match;
863  return child;
864  }
865  Con *result = con_for_window(child, window, store_match);
866  if (result != NULL)
867  return result;
868  }
869 
870  TAILQ_FOREACH (child, &(con->floating_head), floating_windows) {
871  TAILQ_FOREACH (match, &(child->swallow_head), matches) {
872  if (!match_matches_window(match, window))
873  continue;
874  if (store_match != NULL)
875  *store_match = match;
876  return child;
877  }
878  Con *result = con_for_window(child, window, store_match);
879  if (result != NULL)
880  return result;
881  }
882 
883  return NULL;
884 }
885 
886 static int num_focus_heads(Con *con) {
887  int focus_heads = 0;
888 
889  Con *current;
890  TAILQ_FOREACH (current, &(con->focus_head), focused) {
891  focus_heads++;
892  }
893 
894  return focus_heads;
895 }
896 
897 /*
898  * Iterate over the container's focus stack and return an array with the
899  * containers inside it, ordered from higher focus order to lowest.
900  *
901  */
903  const int focus_heads = num_focus_heads(con);
904  Con **focus_order = smalloc(focus_heads * sizeof(Con *));
905  Con *current;
906  int idx = 0;
907  TAILQ_FOREACH (current, &(con->focus_head), focused) {
908  assert(idx < focus_heads);
909  focus_order[idx++] = current;
910  }
911 
912  return focus_order;
913 }
914 
915 /*
916  * Clear the container's focus stack and re-add it using the provided container
917  * array. The function doesn't check if the provided array contains the same
918  * containers with the previous focus stack but will not add floating containers
919  * in the new focus stack if container is not a workspace.
920  *
921  */
922 void set_focus_order(Con *con, Con **focus_order) {
923  int focus_heads = 0;
924  while (!TAILQ_EMPTY(&(con->focus_head))) {
925  Con *current = TAILQ_FIRST(&(con->focus_head));
926 
927  TAILQ_REMOVE(&(con->focus_head), current, focused);
928  focus_heads++;
929  }
930 
931  for (int idx = 0; idx < focus_heads; idx++) {
932  /* Useful when encapsulating a workspace. */
933  if (con->type != CT_WORKSPACE && con_inside_floating(focus_order[idx])) {
934  focus_heads++;
935  continue;
936  }
937 
938  TAILQ_INSERT_TAIL(&(con->focus_head), focus_order[idx], focused);
939  }
940 }
941 
942 /*
943  * Returns the number of children of this container.
944  *
945  */
947  Con *child;
948  int children = 0;
949 
950  TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
951  children++;
952  }
953 
954  return children;
955 }
956 
957 /*
958  * Returns the number of visible non-floating children of this container.
959  * For example, if the container contains a hsplit which has two children,
960  * this will return 2 instead of 1.
961  */
963  if (con == NULL)
964  return 0;
965 
966  int children = 0;
967  Con *current = NULL;
968  TAILQ_FOREACH (current, &(con->nodes_head), nodes) {
969  /* Visible leaf nodes are a child. */
970  if (!con_is_hidden(current) && con_is_leaf(current))
971  children++;
972  /* All other containers need to be recursed. */
973  else
974  children += con_num_visible_children(current);
975  }
976 
977  return children;
978 }
979 
980 /*
981  * Count the number of windows (i.e., leaf containers).
982  *
983  */
985  if (con == NULL)
986  return 0;
987 
989  return 1;
990 
991  int num = 0;
992  Con *current = NULL;
993  TAILQ_FOREACH (current, &(con->nodes_head), nodes) {
994  num += con_num_windows(current);
995  }
996 
997  TAILQ_FOREACH (current, &(con->floating_head), floating_windows) {
998  num += con_num_windows(current);
999  }
1000 
1001  return num;
1002 }
1003 
1004 /*
1005  * Updates the percent attribute of the children of the given container. This
1006  * function needs to be called when a window is added or removed from a
1007  * container.
1008  *
1009  */
1011  Con *child;
1012  int children = con_num_children(con);
1013 
1014  // calculate how much we have distributed and how many containers
1015  // with a percentage set we have
1016  double total = 0.0;
1017  int children_with_percent = 0;
1018  TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
1019  if (child->percent > 0.0) {
1020  total += child->percent;
1021  ++children_with_percent;
1022  }
1023  }
1024 
1025  // if there were children without a percentage set, set to a value that
1026  // will make those children proportional to all others
1027  if (children_with_percent != children) {
1028  TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
1029  if (child->percent <= 0.0) {
1030  if (children_with_percent == 0) {
1031  total += (child->percent = 1.0);
1032  } else {
1033  total += (child->percent = total / children_with_percent);
1034  }
1035  }
1036  }
1037  }
1038 
1039  // if we got a zero, just distribute the space equally, otherwise
1040  // distribute according to the proportions we got
1041  if (total == 0.0) {
1042  TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
1043  child->percent = 1.0 / children;
1044  }
1045  } else if (total != 1.0) {
1046  TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
1047  child->percent /= total;
1048  }
1049  }
1050 }
1051 
1052 /*
1053  * Toggles fullscreen mode for the given container. If there already is a
1054  * fullscreen container on this workspace, fullscreen will be disabled and then
1055  * enabled for the container the user wants to have in fullscreen mode.
1056  *
1057  */
1058 void con_toggle_fullscreen(Con *con, int fullscreen_mode) {
1059  if (con->type == CT_WORKSPACE) {
1060  DLOG("You cannot make a workspace fullscreen.\n");
1061  return;
1062  }
1063 
1064  DLOG("toggling fullscreen for %p / %s\n", con, con->name);
1065 
1066  if (con->fullscreen_mode == CF_NONE)
1067  con_enable_fullscreen(con, fullscreen_mode);
1068  else
1070 }
1071 
1072 /*
1073  * Sets the specified fullscreen mode for the given container, sends the
1074  * “fullscreen_mode” event and changes the XCB fullscreen property of the
1075  * container’s window, if any.
1076  *
1077  */
1078 static void con_set_fullscreen_mode(Con *con, fullscreen_mode_t fullscreen_mode) {
1079  con->fullscreen_mode = fullscreen_mode;
1080 
1081  DLOG("mode now: %d\n", con->fullscreen_mode);
1082 
1083  /* Send an ipc window "fullscreen_mode" event */
1084  ipc_send_window_event("fullscreen_mode", con);
1085 
1086  /* update _NET_WM_STATE if this container has a window */
1087  /* TODO: when a window is assigned to a container which is already
1088  * fullscreened, this state needs to be pushed to the client, too */
1089  if (con->window == NULL)
1090  return;
1091 
1092  if (con->fullscreen_mode != CF_NONE) {
1093  DLOG("Setting _NET_WM_STATE_FULLSCREEN for con = %p / window = %d.\n", con, con->window->id);
1094  xcb_add_property_atom(conn, con->window->id, A__NET_WM_STATE, A__NET_WM_STATE_FULLSCREEN);
1095  } else {
1096  DLOG("Removing _NET_WM_STATE_FULLSCREEN for con = %p / window = %d.\n", con, con->window->id);
1097  xcb_remove_property_atom(conn, con->window->id, A__NET_WM_STATE, A__NET_WM_STATE_FULLSCREEN);
1098  }
1099 }
1100 
1101 /*
1102  * Enables fullscreen mode for the given container, if necessary.
1103  *
1104  * If the container’s mode is already CF_OUTPUT or CF_GLOBAL, the container is
1105  * kept fullscreen but its mode is set to CF_GLOBAL and CF_OUTPUT,
1106  * respectively.
1107  *
1108  * Other fullscreen containers will be disabled first, if they hide the new
1109  * one.
1110  *
1111  */
1113  if (con->type == CT_WORKSPACE) {
1114  DLOG("You cannot make a workspace fullscreen.\n");
1115  return;
1116  }
1117 
1118  assert(fullscreen_mode == CF_GLOBAL || fullscreen_mode == CF_OUTPUT);
1119 
1120  if (fullscreen_mode == CF_GLOBAL)
1121  DLOG("enabling global fullscreen for %p / %s\n", con, con->name);
1122  else
1123  DLOG("enabling fullscreen for %p / %s\n", con, con->name);
1124 
1125  if (con->fullscreen_mode == fullscreen_mode) {
1126  DLOG("fullscreen already enabled for %p / %s\n", con, con->name);
1127  return;
1128  }
1129 
1130  Con *con_ws = con_get_workspace(con);
1131 
1132  /* Disable any fullscreen container that would conflict the new one. */
1133  Con *fullscreen = con_get_fullscreen_con(croot, CF_GLOBAL);
1134  if (fullscreen == NULL)
1135  fullscreen = con_get_fullscreen_con(con_ws, CF_OUTPUT);
1136  if (fullscreen != NULL)
1137  con_disable_fullscreen(fullscreen);
1138 
1139  /* Set focus to new fullscreen container. Unless in global fullscreen mode
1140  * and on another workspace restore focus afterwards.
1141  * Switch to the container’s workspace if mode is global. */
1142  Con *cur_ws = con_get_workspace(focused);
1143  Con *old_focused = focused;
1144  if (fullscreen_mode == CF_GLOBAL && cur_ws != con_ws)
1145  workspace_show(con_ws);
1146  con_activate(con);
1147  if (fullscreen_mode != CF_GLOBAL && cur_ws != con_ws)
1148  con_activate(old_focused);
1149 
1150  con_set_fullscreen_mode(con, fullscreen_mode);
1151 }
1152 
1153 /*
1154  * Disables fullscreen mode for the given container regardless of the mode, if
1155  * necessary.
1156  *
1157  */
1159  if (con->type == CT_WORKSPACE) {
1160  DLOG("You cannot make a workspace fullscreen.\n");
1161  return;
1162  }
1163 
1164  DLOG("disabling fullscreen for %p / %s\n", con, con->name);
1165 
1166  if (con->fullscreen_mode == CF_NONE) {
1167  DLOG("fullscreen already disabled for %p / %s\n", con, con->name);
1168  return;
1169  }
1170 
1172 }
1173 
1174 static bool _con_move_to_con(Con *con, Con *target, bool behind_focused, bool fix_coordinates, bool dont_warp, bool ignore_focus, bool fix_percentage) {
1175  Con *orig_target = target;
1176 
1177  /* Prevent moving if this would violate the fullscreen focus restrictions. */
1178  Con *target_ws = con_get_workspace(target);
1179  if (!ignore_focus && !con_fullscreen_permits_focusing(target_ws)) {
1180  LOG("Cannot move out of a fullscreen container.\n");
1181  return false;
1182  }
1183 
1184  if (con_is_floating(con)) {
1185  DLOG("Container is floating, using parent instead.\n");
1186  con = con->parent;
1187  }
1188 
1189  Con *source_ws = con_get_workspace(con);
1190 
1191  if (con->type == CT_WORKSPACE) {
1192  /* Re-parent all of the old workspace's floating windows. */
1193  Con *child;
1194  while (!TAILQ_EMPTY(&(source_ws->floating_head))) {
1195  child = TAILQ_FIRST(&(source_ws->floating_head));
1196  con_move_to_workspace(child, target_ws, true, true, false);
1197  }
1198 
1199  /* If there are no non-floating children, ignore the workspace. */
1200  if (con_is_leaf(con))
1201  return false;
1202 
1204  if (con == NULL) {
1205  ELOG("Workspace failed to move its contents into a container!\n");
1206  return false;
1207  }
1208  }
1209 
1210  /* Save the urgency state so that we can restore it. */
1211  bool urgent = con->urgent;
1212 
1213  /* Save the current workspace. So we can call workspace_show() by the end
1214  * of this function. */
1215  Con *current_ws = con_get_workspace(focused);
1216 
1217  Con *source_output = con_get_output(con),
1218  *dest_output = con_get_output(target_ws);
1219 
1220  /* 1: save the container which is going to be focused after the current
1221  * container is moved away */
1222  Con *focus_next = NULL;
1223  if (!ignore_focus && source_ws == current_ws && target_ws != source_ws) {
1224  focus_next = con_descend_focused(source_ws);
1225  if (focus_next == con || con_has_parent(focus_next, con)) {
1226  focus_next = con_next_focused(con);
1227  }
1228  }
1229 
1230  /* 2: we go up one level, but only when target is a normal container */
1231  if (target->type != CT_WORKSPACE) {
1232  DLOG("target originally = %p / %s / type %d\n", target, target->name, target->type);
1233  target = target->parent;
1234  }
1235 
1236  /* 3: if the original target is the direct child of a floating container, we
1237  * can't move con next to it - floating containers have only one child - so
1238  * we get the workspace instead. */
1239  if (target->type == CT_FLOATING_CON) {
1240  DLOG("floatingcon, going up even further\n");
1241  orig_target = target;
1242  target = target->parent;
1243  }
1244 
1245  if (con->type == CT_FLOATING_CON) {
1246  Con *ws = con_get_workspace(target);
1247  DLOG("This is a floating window, using workspace %p / %s\n", ws, ws->name);
1248  target = ws;
1249  }
1250 
1251  if (source_output != dest_output) {
1252  /* Take the relative coordinates of the current output, then add them
1253  * to the coordinate space of the correct output */
1254  if (fix_coordinates && con->type == CT_FLOATING_CON) {
1255  floating_fix_coordinates(con, &(source_output->rect), &(dest_output->rect));
1256  } else
1257  DLOG("Not fixing coordinates, fix_coordinates flag = %d\n", fix_coordinates);
1258  }
1259 
1260  /* If moving a fullscreen container and the destination already has a
1261  * fullscreen window on it, un-fullscreen the target's fullscreen con.
1262  * con->fullscreen_mode is not enough in some edge cases:
1263  * 1. con is CT_FLOATING_CON, child is fullscreen.
1264  * 2. con is the parent of a fullscreen container, can be triggered by
1265  * moving the parent with command criteria.
1266  */
1267  Con *fullscreen = con_get_fullscreen_con(target_ws, CF_OUTPUT);
1268  const bool con_has_fullscreen = con->fullscreen_mode != CF_NONE ||
1271  if (con_has_fullscreen && fullscreen != NULL) {
1272  con_toggle_fullscreen(fullscreen, CF_OUTPUT);
1273  fullscreen = NULL;
1274  }
1275 
1276  DLOG("Re-attaching container to %p / %s\n", target, target->name);
1277  /* 4: re-attach the con to the parent of this focused container */
1278  Con *parent = con->parent;
1279  con_detach(con);
1280  _con_attach(con, target, behind_focused ? NULL : orig_target, !behind_focused);
1281 
1282  /* 5: fix the percentages */
1283  if (fix_percentage) {
1284  con_fix_percent(parent);
1285  con->percent = 0.0;
1286  con_fix_percent(target);
1287  }
1288 
1289  /* 6: focus the con on the target workspace, but only within that
1290  * workspace, that is, don’t move focus away if the target workspace is
1291  * invisible.
1292  * We don’t focus the con for i3 pseudo workspaces like __i3_scratch and
1293  * we don’t focus when there is a fullscreen con on that workspace. We
1294  * also don't do it if the caller requested to ignore focus. */
1295  if (!ignore_focus && !con_is_internal(target_ws) && !fullscreen) {
1296  /* We need to save the focused workspace on the output in case the
1297  * new workspace is hidden and it's necessary to immediately switch
1298  * back to the originally-focused workspace. */
1299  Con *old_focus_ws = TAILQ_FIRST(&(output_get_content(dest_output)->focus_head));
1300  Con *old_focus = focused;
1302 
1303  if (old_focus_ws == current_ws && old_focus->type != CT_WORKSPACE) {
1304  /* Restore focus to the currently focused container. */
1305  con_activate(old_focus);
1306  } else if (con_get_workspace(focused) != old_focus_ws) {
1307  /* Restore focus if the output's focused workspace has changed. */
1308  con_focus(con_descend_focused(old_focus_ws));
1309  }
1310  }
1311 
1312  /* 7: when moving to another workspace, we leave the focus on the current
1313  * workspace. (see also #809) */
1314  if (!ignore_focus) {
1315  workspace_show(current_ws);
1316  if (dont_warp) {
1317  DLOG("x_set_warp_to(NULL) because dont_warp is set\n");
1318  x_set_warp_to(NULL);
1319  }
1320  }
1321 
1322  /* Set focus only if con was on current workspace before moving.
1323  * Otherwise we would give focus to some window on different workspace. */
1324  if (focus_next)
1325  con_activate(con_descend_focused(focus_next));
1326 
1327  /* 8. If anything within the container is associated with a startup sequence,
1328  * delete it so child windows won't be created on the old workspace. */
1329  if (!con_is_leaf(con)) {
1330  Con *child;
1331  TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
1332  if (!child->window)
1333  continue;
1335  }
1336  }
1337 
1338  if (con->window) {
1340  }
1341 
1342  /* 9. If the container was marked urgent, move the urgency hint. */
1343  if (urgent) {
1344  workspace_update_urgent_flag(source_ws);
1345  con_set_urgency(con, true);
1346  }
1347 
1348  /* Ensure the container will be redrawn. */
1350 
1351  CALL(parent, on_remove_child);
1352 
1353  ipc_send_window_event("move", con);
1355  return true;
1356 }
1357 
1358 /*
1359  * Moves the given container to the given mark.
1360  *
1361  */
1362 bool con_move_to_mark(Con *con, const char *mark) {
1363  Con *target = con_by_mark(mark);
1364  if (target == NULL) {
1365  DLOG("found no container with mark \"%s\"\n", mark);
1366  return false;
1367  }
1368 
1369  /* For target containers in the scratchpad, we just send the window to the scratchpad. */
1370  if (con_get_workspace(target) == workspace_get("__i3_scratch")) {
1371  DLOG("target container is in the scratchpad, moving container to scratchpad.\n");
1373  return true;
1374  }
1375 
1376  /* For floating target containers, we just send the window to the same workspace. */
1377  if (con_is_floating(target)) {
1378  DLOG("target container is floating, moving container to target's workspace.\n");
1379  con_move_to_workspace(con, con_get_workspace(target), true, false, false);
1380  return true;
1381  }
1382 
1383  if (target->type == CT_WORKSPACE && con_is_leaf(target)) {
1384  DLOG("target container is an empty workspace, simply moving the container there.\n");
1385  con_move_to_workspace(con, target, true, false, false);
1386  return true;
1387  }
1388 
1389  /* For split containers, we use the currently focused container within it.
1390  * This allows setting marks on, e.g., tabbed containers which will move
1391  * con to a new tab behind the focused tab. */
1392  if (con_is_split(target)) {
1393  DLOG("target is a split container, descending to the currently focused child.\n");
1394  target = TAILQ_FIRST(&(target->focus_head));
1395  }
1396 
1397  if (con == target || con_has_parent(target, con)) {
1398  DLOG("cannot move the container to or inside itself, aborting.\n");
1399  return false;
1400  }
1401 
1402  return _con_move_to_con(con, target, false, true, false, false, true);
1403 }
1404 
1405 /*
1406  * Moves the given container to the currently focused container on the given
1407  * workspace.
1408  *
1409  * The fix_coordinates flag will translate the current coordinates (offset from
1410  * the monitor position basically) to appropriate coordinates on the
1411  * destination workspace.
1412  * Not enabling this behaviour comes in handy when this function gets called by
1413  * floating_maybe_reassign_ws, which will only "move" a floating window when it
1414  * *already* changed its coordinates to a different output.
1415  *
1416  * The dont_warp flag disables pointer warping and will be set when this
1417  * function is called while dragging a floating window.
1418  *
1419  * If ignore_focus is set, the container will be moved without modifying focus
1420  * at all.
1421  *
1422  * TODO: is there a better place for this function?
1423  *
1424  */
1425 void con_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, bool dont_warp, bool ignore_focus) {
1426  assert(workspace->type == CT_WORKSPACE);
1427 
1428  Con *source_ws = con_get_workspace(con);
1429  if (workspace == source_ws) {
1430  DLOG("Not moving, already there\n");
1431  return;
1432  }
1433 
1434  Con *target = con_descend_focused(workspace);
1435  _con_move_to_con(con, target, true, fix_coordinates, dont_warp, ignore_focus, true);
1436 }
1437 
1438 /*
1439  * Moves the given container to the currently focused container on the
1440  * visible workspace on the given output.
1441  *
1442  */
1443 void con_move_to_output(Con *con, Output *output, bool fix_coordinates) {
1444  Con *ws = NULL;
1445  GREP_FIRST(ws, output_get_content(output->con), workspace_is_visible(child));
1446  assert(ws != NULL);
1447  DLOG("Moving con %p to output %s\n", con, output_primary_name(output));
1448  con_move_to_workspace(con, ws, fix_coordinates, false, false);
1449 }
1450 
1451 /*
1452  * Moves the given container to the currently focused container on the
1453  * visible workspace on the output specified by the given name.
1454  * The current output for the container is used to resolve relative names
1455  * such as left, right, up, down.
1456  *
1457  */
1458 bool con_move_to_output_name(Con *con, const char *name, bool fix_coordinates) {
1459  Output *current_output = get_output_for_con(con);
1460  Output *output = get_output_from_string(current_output, name);
1461  if (output == NULL) {
1462  ELOG("Could not find output \"%s\"\n", name);
1463  return false;
1464  }
1465 
1466  con_move_to_output(con, output, fix_coordinates);
1467  return true;
1468 }
1469 
1470 /*
1471  * Returns the orientation of the given container (for stacked containers,
1472  * vertical orientation is used regardless of the actual orientation of the
1473  * container).
1474  *
1475  */
1477  switch (con->layout) {
1478  case L_SPLITV:
1479  /* stacking containers behave like they are in vertical orientation */
1480  case L_STACKED:
1481  return VERT;
1482 
1483  case L_SPLITH:
1484  /* tabbed containers behave like they are in vertical orientation */
1485  case L_TABBED:
1486  return HORIZ;
1487 
1488  case L_DEFAULT:
1489  ELOG("Someone called con_orientation() on a con with L_DEFAULT, this is a bug in the code.\n");
1490  assert(false);
1491 
1492  case L_DOCKAREA:
1493  case L_OUTPUT:
1494  ELOG("con_orientation() called on dockarea/output (%d) container %p\n", con->layout, con);
1495  assert(false);
1496  }
1497  /* should not be reached */
1498  assert(false);
1499 }
1500 
1501 /*
1502  * Returns the container which will be focused next when the given container
1503  * is not available anymore. Called in tree_close_internal and con_move_to_workspace
1504  * to properly restore focus.
1505  *
1506  */
1508  /* dock clients cannot be focused, so we focus the workspace instead */
1509  if (con->parent->type == CT_DOCKAREA) {
1510  DLOG("selecting workspace for dock client\n");
1512  }
1513  if (con_is_floating(con)) {
1514  con = con->parent;
1515  }
1516 
1517  /* if 'con' is not the first entry in the focus stack, use the first one as
1518  * it’s currently focused already */
1519  Con *next = TAILQ_FIRST(&(con->parent->focus_head));
1520  if (next != con) {
1521  DLOG("Using first entry %p\n", next);
1522  } else {
1523  /* try to focus the next container on the same level as this one or fall
1524  * back to its parent */
1525  if (!(next = TAILQ_NEXT(con, focused))) {
1526  next = con->parent;
1527  }
1528  }
1529 
1530  /* now go down the focus stack as far as
1531  * possible, excluding the current container */
1532  while (!TAILQ_EMPTY(&(next->focus_head)) && TAILQ_FIRST(&(next->focus_head)) != con) {
1533  next = TAILQ_FIRST(&(next->focus_head));
1534  }
1535 
1536  if (con->type == CT_FLOATING_CON && next != con->parent) {
1537  next = con_descend_focused(next);
1538  }
1539 
1540  return next;
1541 }
1542 
1543 /*
1544  * Returns the focused con inside this client, descending the tree as far as
1545  * possible. This comes in handy when attaching a con to a workspace at the
1546  * currently focused position, for example.
1547  *
1548  */
1550  Con *next = con;
1551  while (next != focused && !TAILQ_EMPTY(&(next->focus_head)))
1552  next = TAILQ_FIRST(&(next->focus_head));
1553  return next;
1554 }
1555 
1556 /*
1557  * Returns the focused con inside this client, descending the tree as far as
1558  * possible. This comes in handy when attaching a con to a workspace at the
1559  * currently focused position, for example.
1560  *
1561  * Works like con_descend_focused but considers only tiling cons.
1562  *
1563  */
1565  Con *next = con;
1566  Con *before;
1567  Con *child;
1568  if (next == focused)
1569  return next;
1570  do {
1571  before = next;
1572  TAILQ_FOREACH (child, &(next->focus_head), focused) {
1573  if (child->type == CT_FLOATING_CON)
1574  continue;
1575 
1576  next = child;
1577  break;
1578  }
1579  } while (before != next && next != focused);
1580  return next;
1581 }
1582 
1583 /*
1584  * Returns the leftmost, rightmost, etc. container in sub-tree. For example, if
1585  * direction is D_LEFT, then we return the rightmost container and if direction
1586  * is D_RIGHT, we return the leftmost container. This is because if we are
1587  * moving D_LEFT, and thus want the rightmost container.
1588  *
1589  */
1591  Con *most = NULL;
1592  Con *current;
1593  int orientation = con_orientation(con);
1594  DLOG("con_descend_direction(%p, orientation %d, direction %d)\n", con, orientation, direction);
1595  if (direction == D_LEFT || direction == D_RIGHT) {
1596  if (orientation == HORIZ) {
1597  /* If the direction is horizontal, we can use either the first
1598  * (D_RIGHT) or the last con (D_LEFT) */
1599  if (direction == D_RIGHT)
1600  most = TAILQ_FIRST(&(con->nodes_head));
1601  else
1602  most = TAILQ_LAST(&(con->nodes_head), nodes_head);
1603  } else if (orientation == VERT) {
1604  /* Wrong orientation. We use the last focused con. Within that con,
1605  * we recurse to chose the left/right con or at least the last
1606  * focused one. */
1607  TAILQ_FOREACH (current, &(con->focus_head), focused) {
1608  if (current->type != CT_FLOATING_CON) {
1609  most = current;
1610  break;
1611  }
1612  }
1613  } else {
1614  /* If the con has no orientation set, it’s not a split container
1615  * but a container with a client window, so stop recursing */
1616  return con;
1617  }
1618  }
1619 
1620  if (direction == D_UP || direction == D_DOWN) {
1621  if (orientation == VERT) {
1622  /* If the direction is vertical, we can use either the first
1623  * (D_DOWN) or the last con (D_UP) */
1624  if (direction == D_UP)
1625  most = TAILQ_LAST(&(con->nodes_head), nodes_head);
1626  else
1627  most = TAILQ_FIRST(&(con->nodes_head));
1628  } else if (orientation == HORIZ) {
1629  /* Wrong orientation. We use the last focused con. Within that con,
1630  * we recurse to chose the top/bottom con or at least the last
1631  * focused one. */
1632  TAILQ_FOREACH (current, &(con->focus_head), focused) {
1633  if (current->type != CT_FLOATING_CON) {
1634  most = current;
1635  break;
1636  }
1637  }
1638  } else {
1639  /* If the con has no orientation set, it’s not a split container
1640  * but a container with a client window, so stop recursing */
1641  return con;
1642  }
1643  }
1644 
1645  if (!most)
1646  return con;
1647  return con_descend_direction(most, direction);
1648 }
1649 
1650 /*
1651  * Returns a "relative" Rect which contains the amount of pixels that need to
1652  * be added to the original Rect to get the final position (obviously the
1653  * amount of pixels for normal, 1pixel and borderless are different).
1654  *
1655  */
1658  if (!con_is_floating(con)) {
1659  return (Rect){0, 0, 0, 0};
1660  }
1661  }
1662 
1663  adjacent_t borders_to_hide = ADJ_NONE;
1664  int border_width = con->current_border_width;
1665  DLOG("The border width for con is set to: %d\n", con->current_border_width);
1666  Rect result;
1667  if (con->current_border_width < 0) {
1668  if (con_is_floating(con)) {
1669  border_width = config.default_floating_border_width;
1670  } else {
1671  border_width = config.default_border_width;
1672  }
1673  }
1674  DLOG("Effective border width is set to: %d\n", border_width);
1675  /* Shortcut to avoid calling con_adjacent_borders() on dock containers. */
1676  int border_style = con_border_style(con);
1677  if (border_style == BS_NONE)
1678  return (Rect){0, 0, 0, 0};
1679  if (border_style == BS_NORMAL) {
1680  result = (Rect){border_width, 0, -(2 * border_width), -(border_width)};
1681  } else {
1682  result = (Rect){border_width, border_width, -(2 * border_width), -(2 * border_width)};
1683  }
1684 
1685  borders_to_hide = con_adjacent_borders(con) & config.hide_edge_borders;
1686  if (borders_to_hide & ADJ_LEFT_SCREEN_EDGE) {
1687  result.x -= border_width;
1688  result.width += border_width;
1689  }
1690  if (borders_to_hide & ADJ_RIGHT_SCREEN_EDGE) {
1691  result.width += border_width;
1692  }
1693  if (borders_to_hide & ADJ_UPPER_SCREEN_EDGE && (border_style != BS_NORMAL)) {
1694  result.y -= border_width;
1695  result.height += border_width;
1696  }
1697  if (borders_to_hide & ADJ_LOWER_SCREEN_EDGE) {
1698  result.height += border_width;
1699  }
1700  return result;
1701 }
1702 
1703 /*
1704  * Returns adjacent borders of the window. We need this if hide_edge_borders is
1705  * enabled.
1706  */
1708  adjacent_t result = ADJ_NONE;
1709  /* Floating windows are never adjacent to any other window, so
1710  don’t hide their border(s). This prevents bug #998. */
1711  if (con_is_floating(con))
1712  return result;
1713 
1714  Con *workspace = con_get_workspace(con);
1715  if (con->rect.x == workspace->rect.x)
1716  result |= ADJ_LEFT_SCREEN_EDGE;
1717  if (con->rect.x + con->rect.width == workspace->rect.x + workspace->rect.width)
1718  result |= ADJ_RIGHT_SCREEN_EDGE;
1719  if (con->rect.y == workspace->rect.y)
1720  result |= ADJ_UPPER_SCREEN_EDGE;
1721  if (con->rect.y + con->rect.height == workspace->rect.y + workspace->rect.height)
1722  result |= ADJ_LOWER_SCREEN_EDGE;
1723  return result;
1724 }
1725 
1726 /*
1727  * Use this function to get a container’s border style. This is important
1728  * because when inside a stack, the border style is always BS_NORMAL.
1729  * For tabbed mode, the same applies, with one exception: when the container is
1730  * borderless and the only element in the tabbed container, the border is not
1731  * rendered.
1732  *
1733  * For children of a CT_DOCKAREA, the border style is always none.
1734  *
1735  */
1738  DLOG("this one is fullscreen! overriding BS_NONE\n");
1739  return BS_NONE;
1740  }
1741 
1742  if (con->parent->layout == L_STACKED)
1743  return (con_num_children(con->parent) == 1 ? con->border_style : BS_NORMAL);
1744 
1746  return (con_num_children(con->parent) == 1 ? con->border_style : BS_NORMAL);
1747 
1748  if (con->parent->type == CT_DOCKAREA)
1749  return BS_NONE;
1750 
1751  return con->border_style;
1752 }
1753 
1754 /*
1755  * Sets the given border style on con, correctly keeping the position/size of a
1756  * floating window.
1757  *
1758  */
1759 void con_set_border_style(Con *con, int border_style, int border_width) {
1760  /* Handle the simple case: non-floating containerns */
1761  if (!con_is_floating(con)) {
1762  con->border_style = border_style;
1763  con->current_border_width = border_width;
1764  return;
1765  }
1766 
1767  /* For floating containers, we want to keep the position/size of the
1768  * *window* itself. We first add the border pixels to con->rect to make
1769  * con->rect represent the absolute position of the window (same for
1770  * parent). Then, we change the border style and subtract the new border
1771  * pixels. For the parent, we do the same also for the decoration. */
1772  DLOG("This is a floating container\n");
1773 
1774  Con *parent = con->parent;
1776  int deco_height = (con->border_style == BS_NORMAL ? render_deco_height() : 0);
1777 
1778  con->rect = rect_add(con->rect, bsr);
1779  parent->rect = rect_add(parent->rect, bsr);
1780  parent->rect.y += deco_height;
1781  parent->rect.height -= deco_height;
1782 
1783  /* Change the border style, get new border/decoration values. */
1784  con->border_style = border_style;
1785  con->current_border_width = border_width;
1786  bsr = con_border_style_rect(con);
1787  deco_height = (con->border_style == BS_NORMAL ? render_deco_height() : 0);
1788 
1789  con->rect = rect_sub(con->rect, bsr);
1790  parent->rect = rect_sub(parent->rect, bsr);
1791  parent->rect.y -= deco_height;
1792  parent->rect.height += deco_height;
1793 }
1794 
1795 /*
1796  * This function changes the layout of a given container. Use it to handle
1797  * special cases like changing a whole workspace to stacked/tabbed (creates a
1798  * new split container before).
1799  *
1800  */
1801 void con_set_layout(Con *con, layout_t layout) {
1802  DLOG("con_set_layout(%p, %d), con->type = %d\n",
1803  con, layout, con->type);
1804 
1805  /* Users can focus workspaces, but not any higher in the hierarchy.
1806  * Focus on the workspace is a special case, since in every other case, the
1807  * user means "change the layout of the parent split container". */
1808  if (con->type != CT_WORKSPACE)
1809  con = con->parent;
1810 
1811  /* We fill in last_split_layout when switching to a different layout
1812  * since there are many places in the code that don’t use
1813  * con_set_layout(). */
1814  if (con->layout == L_SPLITH || con->layout == L_SPLITV)
1816 
1817  /* When the container type is CT_WORKSPACE, the user wants to change the
1818  * whole workspace into stacked/tabbed mode. To do this and still allow
1819  * intuitive operations (like level-up and then opening a new window), we
1820  * need to create a new split container. */
1821  if (con->type == CT_WORKSPACE) {
1822  if (con_num_children(con) == 0) {
1823  layout_t ws_layout = (layout == L_STACKED || layout == L_TABBED) ? layout : L_DEFAULT;
1824  DLOG("Setting workspace_layout to %d\n", ws_layout);
1825  con->workspace_layout = ws_layout;
1826  DLOG("Setting layout to %d\n", layout);
1827  con->layout = layout;
1828  } else if (layout == L_STACKED || layout == L_TABBED || layout == L_SPLITV || layout == L_SPLITH) {
1829  DLOG("Creating new split container\n");
1830  /* 1: create a new split container */
1831  Con *new = con_new(NULL, NULL);
1832  new->parent = con;
1833 
1834  /* 2: Set the requested layout on the split container and mark it as
1835  * split. */
1836  new->layout = layout;
1837  new->last_split_layout = con->last_split_layout;
1838 
1839  /* 3: move the existing cons of this workspace below the new con */
1840  Con **focus_order = get_focus_order(con);
1841 
1842  DLOG("Moving cons\n");
1843  Con *child;
1844  while (!TAILQ_EMPTY(&(con->nodes_head))) {
1845  child = TAILQ_FIRST(&(con->nodes_head));
1846  con_detach(child);
1847  con_attach(child, new, true);
1848  }
1849 
1850  set_focus_order(new, focus_order);
1851  free(focus_order);
1852 
1853  /* 4: attach the new split container to the workspace */
1854  DLOG("Attaching new split to ws\n");
1855  con_attach(new, con, false);
1856 
1858  }
1860  return;
1861  }
1862 
1863  if (layout == L_DEFAULT) {
1864  /* Special case: the layout formerly known as "default" (in combination
1865  * with an orientation). Since we switched to splith/splitv layouts,
1866  * using the "default" layout (which "only" should happen when using
1867  * legacy configs) is using the last split layout (either splith or
1868  * splitv) in order to still do the same thing. */
1870  /* In case last_split_layout was not initialized… */
1871  if (con->layout == L_DEFAULT)
1872  con->layout = L_SPLITH;
1873  } else {
1874  con->layout = layout;
1875  }
1877 }
1878 
1879 /*
1880  * This function toggles the layout of a given container. toggle_mode can be
1881  * either 'default' (toggle only between stacked/tabbed/last_split_layout),
1882  * 'split' (toggle only between splitv/splith) or 'all' (toggle between all
1883  * layouts).
1884  *
1885  */
1886 void con_toggle_layout(Con *con, const char *toggle_mode) {
1887  Con *parent = con;
1888  /* Users can focus workspaces, but not any higher in the hierarchy.
1889  * Focus on the workspace is a special case, since in every other case, the
1890  * user means "change the layout of the parent split container". */
1891  if (con->type != CT_WORKSPACE)
1892  parent = con->parent;
1893  DLOG("con_toggle_layout(%p, %s), parent = %p\n", con, toggle_mode, parent);
1894 
1895  const char delim[] = " ";
1896 
1897  if (strcasecmp(toggle_mode, "split") == 0 || strstr(toggle_mode, delim)) {
1898  /* L_DEFAULT is used as a placeholder value to distinguish if
1899  * the first layout has already been saved. (it can never be L_DEFAULT) */
1900  layout_t new_layout = L_DEFAULT;
1901  bool current_layout_found = false;
1902  char *tm_dup = sstrdup(toggle_mode);
1903  char *cur_tok = strtok(tm_dup, delim);
1904 
1905  for (layout_t layout; cur_tok != NULL; cur_tok = strtok(NULL, delim)) {
1906  if (strcasecmp(cur_tok, "split") == 0) {
1907  /* Toggle between splits. When the current layout is not a split
1908  * layout, we just switch back to last_split_layout. Otherwise, we
1909  * change to the opposite split layout. */
1910  if (parent->layout != L_SPLITH && parent->layout != L_SPLITV) {
1911  layout = parent->last_split_layout;
1912  /* In case last_split_layout was not initialized… */
1913  if (layout == L_DEFAULT) {
1914  layout = L_SPLITH;
1915  }
1916  } else {
1917  layout = (parent->layout == L_SPLITH) ? L_SPLITV : L_SPLITH;
1918  }
1919  } else {
1920  bool success = layout_from_name(cur_tok, &layout);
1921  if (!success || layout == L_DEFAULT) {
1922  ELOG("The token '%s' was not recognized and has been skipped.\n", cur_tok);
1923  continue;
1924  }
1925  }
1926 
1927  /* If none of the specified layouts match the current,
1928  * fall back to the first layout in the list */
1929  if (new_layout == L_DEFAULT) {
1930  new_layout = layout;
1931  }
1932 
1933  /* We found the active layout in the last iteration, so
1934  * now let's activate the current layout (next in list) */
1935  if (current_layout_found) {
1936  new_layout = layout;
1937  break;
1938  }
1939 
1940  if (parent->layout == layout) {
1941  current_layout_found = true;
1942  }
1943  }
1944  free(tm_dup);
1945 
1946  if (new_layout != L_DEFAULT) {
1947  con_set_layout(con, new_layout);
1948  }
1949  } else if (strcasecmp(toggle_mode, "all") == 0 || strcasecmp(toggle_mode, "default") == 0) {
1950  if (parent->layout == L_STACKED)
1952  else if (parent->layout == L_TABBED) {
1953  if (strcasecmp(toggle_mode, "all") == 0)
1955  else
1957  } else if (parent->layout == L_SPLITH || parent->layout == L_SPLITV) {
1958  if (strcasecmp(toggle_mode, "all") == 0) {
1959  /* When toggling through all modes, we toggle between
1960  * splith/splitv, whereas normally we just directly jump to
1961  * stacked. */
1962  if (parent->layout == L_SPLITH)
1964  else
1966  } else {
1968  }
1969  }
1970  }
1971 }
1972 
1973 /*
1974  * Callback which will be called when removing a child from the given con.
1975  * Kills the container if it is empty and replaces it with the child if there
1976  * is exactly one child.
1977  *
1978  */
1979 static void con_on_remove_child(Con *con) {
1980  DLOG("on_remove_child\n");
1981 
1982  /* Every container 'above' (in the hierarchy) the workspace content should
1983  * not be closed when the last child was removed */
1984  if (con->type == CT_OUTPUT ||
1985  con->type == CT_ROOT ||
1986  con->type == CT_DOCKAREA ||
1987  (con->parent != NULL && con->parent->type == CT_OUTPUT)) {
1988  DLOG("not handling, type = %d, name = %s\n", con->type, con->name);
1989  return;
1990  }
1991 
1992  /* For workspaces, close them only if they're not visible anymore */
1993  if (con->type == CT_WORKSPACE) {
1994  if (TAILQ_EMPTY(&(con->focus_head)) && !workspace_is_visible(con)) {
1995  LOG("Closing old workspace (%p / %s), it is empty\n", con, con->name);
1996  yajl_gen gen = ipc_marshal_workspace_event("empty", con, NULL);
1998 
1999  const unsigned char *payload;
2000  ylength length;
2001  y(get_buf, &payload, &length);
2002  ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, (const char *)payload);
2003 
2004  y(free);
2005  }
2006  return;
2007  }
2008 
2012 
2013  /* TODO: check if this container would swallow any other client and
2014  * don’t close it automatically. */
2015  int children = con_num_children(con);
2016  if (children == 0) {
2017  DLOG("Container empty, closing\n");
2019  return;
2020  }
2021 }
2022 
2023 /*
2024  * Determines the minimum size of the given con by looking at its children (for
2025  * split/stacked/tabbed cons). Will be called when resizing floating cons
2026  *
2027  */
2029  DLOG("Determining minimum size for con %p\n", con);
2030 
2031  if (con_is_leaf(con)) {
2032  DLOG("leaf node, returning 75x50\n");
2033  return (Rect){0, 0, 75, 50};
2034  }
2035 
2036  if (con->type == CT_FLOATING_CON) {
2037  DLOG("floating con\n");
2038  Con *child = TAILQ_FIRST(&(con->nodes_head));
2039  return con_minimum_size(child);
2040  }
2041 
2042  if (con->layout == L_STACKED || con->layout == L_TABBED) {
2043  uint32_t max_width = 0, max_height = 0, deco_height = 0;
2044  Con *child;
2045  TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
2046  Rect min = con_minimum_size(child);
2047  deco_height += child->deco_rect.height;
2048  max_width = max(max_width, min.width);
2049  max_height = max(max_height, min.height);
2050  }
2051  DLOG("stacked/tabbed now, returning %d x %d + deco_rect = %d\n",
2052  max_width, max_height, deco_height);
2053  return (Rect){0, 0, max_width, max_height + deco_height};
2054  }
2055 
2056  /* For horizontal/vertical split containers we sum up the width (h-split)
2057  * or height (v-split) and use the maximum of the height (h-split) or width
2058  * (v-split) as minimum size. */
2059  if (con_is_split(con)) {
2060  uint32_t width = 0, height = 0;
2061  Con *child;
2062  TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
2063  Rect min = con_minimum_size(child);
2064  if (con->layout == L_SPLITH) {
2065  width += min.width;
2066  height = max(height, min.height);
2067  } else {
2068  height += min.height;
2069  width = max(width, min.width);
2070  }
2071  }
2072  DLOG("split container, returning width = %d x height = %d\n", width, height);
2073  return (Rect){0, 0, width, height};
2074  }
2075 
2076  ELOG("Unhandled case, type = %d, layout = %d, split = %d\n",
2078  assert(false);
2079 }
2080 
2081 /*
2082  * Returns true if changing the focus to con would be allowed considering
2083  * the fullscreen focus constraints. Specifically, if a fullscreen container or
2084  * any of its descendants is focused, this function returns true if and only if
2085  * focusing con would mean that focus would still be visible on screen, i.e.,
2086  * the newly focused container would not be obscured by a fullscreen container.
2087  *
2088  * In the simplest case, if a fullscreen container or any of its descendants is
2089  * fullscreen, this functions returns true if con is the fullscreen container
2090  * itself or any of its descendants, as this means focus wouldn't escape the
2091  * boundaries of the fullscreen container.
2092  *
2093  * In case the fullscreen container is of type CF_OUTPUT, this function returns
2094  * true if con is on a different workspace, as focus wouldn't be obscured by
2095  * the fullscreen container that is constrained to a different workspace.
2096  *
2097  * Note that this same logic can be applied to moving containers. If a
2098  * container can be focused under the fullscreen focus constraints, it can also
2099  * become a parent or sibling to the currently focused container.
2100  *
2101  */
2103  /* No focus, no problem. */
2104  if (!focused)
2105  return true;
2106 
2107  /* Find the first fullscreen ascendent. */
2108  Con *fs = focused;
2109  while (fs && fs->fullscreen_mode == CF_NONE)
2110  fs = fs->parent;
2111 
2112  /* fs must be non-NULL since the workspace con doesn’t have CF_NONE and
2113  * there always has to be a workspace con in the hierarchy. */
2114  assert(fs != NULL);
2115  /* The most common case is we hit the workspace level. In this
2116  * situation, changing focus is also harmless. */
2117  assert(fs->fullscreen_mode != CF_NONE);
2118  if (fs->type == CT_WORKSPACE)
2119  return true;
2120 
2121  /* Allow it if the container itself is the fullscreen container. */
2122  if (con == fs)
2123  return true;
2124 
2125  /* If fullscreen is per-output, the focus being in a different workspace is
2126  * sufficient to guarantee that change won't leave fullscreen in bad shape. */
2127  if (fs->fullscreen_mode == CF_OUTPUT &&
2129  return true;
2130  }
2131 
2132  /* Allow it only if the container to be focused is contained within the
2133  * current fullscreen container. */
2134  return con_has_parent(con, fs);
2135 }
2136 
2137 /*
2138  *
2139  * Checks if the given container has an urgent child.
2140  *
2141  */
2143  Con *child;
2144 
2145  if (con_is_leaf(con))
2146  return con->urgent;
2147 
2148  /* We are not interested in floating windows since they can only be
2149  * attached to a workspace → nodes_head instead of focus_head */
2150  TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
2151  if (con_has_urgent_child(child))
2152  return true;
2153  }
2154 
2155  return false;
2156 }
2157 
2158 /*
2159  * Make all parent containers urgent if con is urgent or clear the urgent flag
2160  * of all parent containers if there are no more urgent children left.
2161  *
2162  */
2164  Con *parent = con->parent;
2165 
2166  /* Urgency hints should not be set on any container higher up in the
2167  * hierarchy than the workspace level. Unfortunately, since the content
2168  * container has type == CT_CON, that’s not easy to verify in the loop
2169  * below, so we need another condition to catch that case: */
2170  if (con->type == CT_WORKSPACE)
2171  return;
2172 
2173  bool new_urgency_value = con->urgent;
2174  while (parent && parent->type != CT_WORKSPACE && parent->type != CT_DOCKAREA) {
2175  if (new_urgency_value) {
2176  parent->urgent = true;
2177  } else {
2178  /* We can only reset the urgency when the parent
2179  * has no other urgent children */
2180  if (!con_has_urgent_child(parent))
2181  parent->urgent = false;
2182  }
2183  parent = parent->parent;
2184  }
2185 }
2186 
2187 /*
2188  * Set urgency flag to the container, all the parent containers and the workspace.
2189  *
2190  */
2191 void con_set_urgency(Con *con, bool urgent) {
2192  if (urgent && focused == con) {
2193  DLOG("Ignoring urgency flag for current client\n");
2194  return;
2195  }
2196 
2197  const bool old_urgent = con->urgent;
2198 
2199  if (con->urgency_timer == NULL) {
2200  con->urgent = urgent;
2201  } else
2202  DLOG("Discarding urgency WM_HINT because timer is running\n");
2203 
2204  //CLIENT_LOG(con);
2205  if (con->window) {
2206  if (con->urgent) {
2207  gettimeofday(&con->window->urgent, NULL);
2208  } else {
2209  con->window->urgent.tv_sec = 0;
2210  con->window->urgent.tv_usec = 0;
2211  }
2212  }
2213 
2215 
2216  Con *ws;
2217  /* Set the urgency flag on the workspace, if a workspace could be found
2218  * (for dock clients, that is not the case). */
2219  if ((ws = con_get_workspace(con)) != NULL)
2221 
2222  if (con->urgent != old_urgent) {
2223  LOG("Urgency flag changed to %d\n", con->urgent);
2224  ipc_send_window_event("urgent", con);
2225  }
2226 }
2227 
2228 /*
2229  * Create a string representing the subtree under con.
2230  *
2231  */
2233  /* this code works as follows:
2234  * 1) create a string with the layout type (D/V/H/T/S) and an opening bracket
2235  * 2) append the tree representation of the children to the string
2236  * 3) add closing bracket
2237  *
2238  * The recursion ends when we hit a leaf, in which case we return the
2239  * class_instance of the contained window.
2240  */
2241 
2242  /* end of recursion */
2243  if (con_is_leaf(con)) {
2244  if (!con->window)
2245  return sstrdup("nowin");
2246 
2247  if (!con->window->class_instance)
2248  return sstrdup("noinstance");
2249 
2250  return sstrdup(con->window->class_instance);
2251  }
2252 
2253  char *buf;
2254  /* 1) add the Layout type to buf */
2255  if (con->layout == L_DEFAULT)
2256  buf = sstrdup("D[");
2257  else if (con->layout == L_SPLITV)
2258  buf = sstrdup("V[");
2259  else if (con->layout == L_SPLITH)
2260  buf = sstrdup("H[");
2261  else if (con->layout == L_TABBED)
2262  buf = sstrdup("T[");
2263  else if (con->layout == L_STACKED)
2264  buf = sstrdup("S[");
2265  else {
2266  ELOG("BUG: Code not updated to account for new layout type\n");
2267  assert(false);
2268  }
2269 
2270  /* 2) append representation of children */
2271  Con *child;
2272  TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
2273  char *child_txt = con_get_tree_representation(child);
2274 
2275  char *tmp_buf;
2276  sasprintf(&tmp_buf, "%s%s%s", buf,
2277  (TAILQ_FIRST(&(con->nodes_head)) == child ? "" : " "), child_txt);
2278  free(buf);
2279  buf = tmp_buf;
2280  free(child_txt);
2281  }
2282 
2283  /* 3) close the brackets */
2284  char *complete_buf;
2285  sasprintf(&complete_buf, "%s]", buf);
2286  free(buf);
2287 
2288  return complete_buf;
2289 }
2290 
2291 /*
2292  * Returns the container's title considering the current title format.
2293  *
2294  */
2296  assert(con->title_format != NULL);
2297 
2298  i3Window *win = con->window;
2299 
2300  /* We need to ensure that we only escape the window title if pango
2301  * is used by the current font. */
2302  const bool pango_markup = font_is_pango();
2303 
2304  char *title;
2305  char *class;
2306  char *instance;
2307  if (win == NULL) {
2309  class = sstrdup("i3-frame");
2310  instance = sstrdup("i3-frame");
2311  } else {
2312  title = pango_escape_markup(sstrdup((win->name == NULL) ? "" : i3string_as_utf8(win->name)));
2313  class = pango_escape_markup(sstrdup((win->class_class == NULL) ? "" : win->class_class));
2314  instance = pango_escape_markup(sstrdup((win->class_instance == NULL) ? "" : win->class_instance));
2315  }
2316 
2317  placeholder_t placeholders[] = {
2318  {.name = "%title", .value = title},
2319  {.name = "%class", .value = class},
2320  {.name = "%instance", .value = instance}};
2321  const size_t num = sizeof(placeholders) / sizeof(placeholder_t);
2322 
2323  char *formatted_str = format_placeholders(con->title_format, &placeholders[0], num);
2324  i3String *formatted = i3string_from_utf8(formatted_str);
2325  i3string_set_markup(formatted, pango_markup);
2326 
2327  free(formatted_str);
2328  free(title);
2329  free(class);
2330  free(instance);
2331 
2332  return formatted;
2333 }
2334 
2335 /*
2336  * Swaps the two containers.
2337  *
2338  */
2339 bool con_swap(Con *first, Con *second) {
2340  assert(first != NULL);
2341  assert(second != NULL);
2342  DLOG("Swapping containers %p / %p\n", first, second);
2343 
2344  if (first->type != CT_CON) {
2345  ELOG("Only regular containers can be swapped, but found con = %p with type = %d.\n", first, first->type);
2346  return false;
2347  }
2348 
2349  if (second->type != CT_CON) {
2350  ELOG("Only regular containers can be swapped, but found con = %p with type = %d.\n", second, second->type);
2351  return false;
2352  }
2353 
2354  if (first == second) {
2355  DLOG("Swapping container %p with itself, nothing to do.\n", first);
2356  return false;
2357  }
2358 
2359  if (con_has_parent(first, second) || con_has_parent(second, first)) {
2360  ELOG("Cannot swap containers %p and %p because they are in a parent-child relationship.\n", first, second);
2361  return false;
2362  }
2363 
2364  Con *ws1 = con_get_workspace(first);
2365  Con *ws2 = con_get_workspace(second);
2366  Con *restore_focus = NULL;
2367  if (ws1 == ws2 && ws1 == con_get_workspace(focused)) {
2368  /* Preserve focus in the current workspace. */
2369  restore_focus = focused;
2370  } else if (first == focused || con_has_parent(focused, first)) {
2371  restore_focus = second;
2372  } else if (second == focused || con_has_parent(focused, second)) {
2373  restore_focus = first;
2374  }
2375 
2376 #define SWAP_CONS_IN_TREE(headname, field) \
2377  do { \
2378  struct headname *head1 = &(first->parent->headname); \
2379  struct headname *head2 = &(second->parent->headname); \
2380  Con *first_prev = TAILQ_PREV(first, headname, field); \
2381  Con *second_prev = TAILQ_PREV(second, headname, field); \
2382  if (second_prev == first) { \
2383  TAILQ_SWAP(first, second, head1, field); \
2384  } else if (first_prev == second) { \
2385  TAILQ_SWAP(second, first, head1, field); \
2386  } else { \
2387  TAILQ_REMOVE(head1, first, field); \
2388  TAILQ_REMOVE(head2, second, field); \
2389  if (second_prev == NULL) { \
2390  TAILQ_INSERT_HEAD(head2, first, field); \
2391  } else { \
2392  TAILQ_INSERT_AFTER(head2, second_prev, first, field); \
2393  } \
2394  if (first_prev == NULL) { \
2395  TAILQ_INSERT_HEAD(head1, second, field); \
2396  } else { \
2397  TAILQ_INSERT_AFTER(head1, first_prev, second, field); \
2398  } \
2399  } \
2400  } while (0)
2401 
2402  SWAP_CONS_IN_TREE(nodes_head, nodes);
2403  SWAP_CONS_IN_TREE(focus_head, focused);
2404  SWAP(first->parent, second->parent, Con *);
2405 
2406  /* Floating nodes are children of CT_FLOATING_CONs, they are listed in
2407  * nodes_head and focus_head like all other containers. Thus, we don't need
2408  * to do anything special other than swapping the floating status and the
2409  * relevant rects. */
2410  SWAP(first->floating, second->floating, int);
2411  SWAP(first->rect, second->rect, Rect);
2412  SWAP(first->window_rect, second->window_rect, Rect);
2413 
2414  /* We need to copy each other's percentages to ensure that the geometry
2415  * doesn't change during the swap. */
2416  SWAP(first->percent, second->percent, double);
2417 
2418  if (restore_focus) {
2419  con_focus(restore_focus);
2420  }
2421 
2422  /* Update new parents' & workspaces' urgency. */
2423  con_set_urgency(first, first->urgent);
2424  con_set_urgency(second, second->urgent);
2425 
2426  /* Exchange fullscreen modes, can't use SWAP because we need to call the
2427  * correct functions. */
2428  fullscreen_mode_t second_fullscreen_mode = second->fullscreen_mode;
2429  if (first->fullscreen_mode == CF_NONE) {
2430  con_disable_fullscreen(second);
2431  } else {
2432  con_enable_fullscreen(second, first->fullscreen_mode);
2433  }
2434  if (second_fullscreen_mode == CF_NONE) {
2435  con_disable_fullscreen(first);
2436  } else {
2437  con_enable_fullscreen(first, second_fullscreen_mode);
2438  }
2439 
2440  /* We don't actually need this since percentages-wise we haven't changed
2441  * anything, but we'll better be safe than sorry and just make sure as we'd
2442  * otherwise crash i3. */
2443  con_fix_percent(first->parent);
2444  con_fix_percent(second->parent);
2445 
2446  FREE(first->deco_render_params);
2447  FREE(second->deco_render_params);
2450 
2451  return true;
2452 }
2453 
2454 /*
2455  * Returns container's rect size depending on its orientation.
2456  * i.e. its width when horizontal, its height when vertical.
2457  *
2458  */
2460  return (con_orientation(con) == HORIZ ? con->rect.width : con->rect.height);
2461 }
2462 
2463 /*
2464  * Merges container specific data that should move with the window (e.g. marks,
2465  * title format, and the window itself) into another container, and closes the
2466  * old container.
2467  *
2468  */
2469 void con_merge_into(Con *old, Con *new) {
2470  new->window = old->window;
2471  old->window = NULL;
2472 
2473  if (old->title_format) {
2474  FREE(new->title_format);
2475  new->title_format = old->title_format;
2476  old->title_format = NULL;
2477  }
2478 
2479  if (old->sticky_group) {
2480  FREE(new->sticky_group);
2481  new->sticky_group = old->sticky_group;
2482  old->sticky_group = NULL;
2483  }
2484 
2485  new->sticky = old->sticky;
2486 
2487  con_set_urgency(new, old->urgent);
2488 
2489  mark_t *mark;
2490  TAILQ_FOREACH (mark, &(old->marks_head), marks) {
2491  TAILQ_INSERT_TAIL(&(new->marks_head), mark, marks);
2492  ipc_send_window_event("mark", new);
2493  }
2494  new->mark_changed = (TAILQ_FIRST(&(old->marks_head)) != NULL);
2495  TAILQ_INIT(&(old->marks_head));
2496 
2498 }
#define y(x,...)
Definition: commands.c:18
void con_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, bool dont_warp, bool ignore_focus)
Moves the given container to the currently focused container on the given workspace.
Definition: con.c:1425
Con * con_get_fullscreen_covering_ws(Con *ws)
Returns the fullscreen node that covers the given workspace if it exists.
Definition: con.c:572
Con * con_descend_direction(Con *con, direction_t direction)
Returns the leftmost, rightmost, etc.
Definition: con.c:1590
bool con_move_to_mark(Con *con, const char *mark)
Moves the given container to the given mark.
Definition: con.c:1362
bool con_move_to_output_name(Con *con, const char *name, bool fix_coordinates)
Moves the given container to the currently focused container on the visible workspace on the output s...
Definition: con.c:1458
void con_set_urgency(Con *con, bool urgent)
Set urgency flag to the container, all the parent containers and the workspace.
Definition: con.c:2191
bool con_is_floating(Con *con)
Returns true if the node is floating.
Definition: con.c:595
Con * con_by_con_id(long target)
Returns the container with the given container ID or NULL if no such container exists.
Definition: con.c:682
void con_close(Con *con, kill_window_t kill_window)
Closes the given container.
Definition: con.c:330
static void con_raise(Con *con)
Definition: con.c:275
orientation_t con_orientation(Con *con)
Returns the orientation of the given container (for stacked containers, vertical orientation is used ...
Definition: con.c:1476
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Definition: con.c:476
void con_force_split_parents_redraw(Con *con)
force parent split containers to be redrawn
Definition: con.c:21
void con_unmark(Con *con, const char *name)
Removes marks from containers.
Definition: con.c:797
bool con_has_managed_window(Con *con)
Returns true when this con is a leaf node with a managed X11 window (e.g., excluding dock containers)
Definition: con.c:368
void con_update_parents_urgency(Con *con)
Make all parent containers urgent if con is urgent or clear the urgent flag of all parent containers ...
Definition: con.c:2163
Con * con_new_skeleton(Con *parent, i3Window *window)
Create a new container (and attach it to the given parent, if not NULL).
Definition: con.c:38
bool con_is_hidden(Con *con)
This will only return true for containers which have some parent with a tabbed / stacked parent of wh...
Definition: con.c:403
bool con_is_split(Con *con)
Returns true if a container should be considered split.
Definition: con.c:384
bool con_has_children(Con *con)
Returns true if this node has regular or floating children.
Definition: con.c:376
Con * con_by_window_id(xcb_window_t window)
Returns the container with the given client window ID or NULL if no such container exists.
Definition: con.c:667
void con_disable_fullscreen(Con *con)
Disables fullscreen mode for the given container, if necessary.
Definition: con.c:1158
Con ** get_focus_order(Con *con)
Iterate over the container's focus stack and return an array with the containers inside it,...
Definition: con.c:902
Con * con_get_fullscreen_con(Con *con, fullscreen_mode_t fullscreen_mode)
Returns the first fullscreen node below this node.
Definition: con.c:524
static int num_focus_heads(Con *con)
Definition: con.c:886
bool con_is_docked(Con *con)
Returns true if the container is a docked container.
Definition: con.c:604
int con_num_visible_children(Con *con)
Returns the number of visible non-floating children of this container.
Definition: con.c:962
Con * con_parent_with_orientation(Con *con, orientation_t orientation)
Searches parents of the given 'con' until it reaches one with the specified 'orientation'.
Definition: con.c:488
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
Definition: con.c:1549
void con_mark(Con *con, const char *mark, mark_mode_t mode)
Assigns a mark to the container.
Definition: con.c:767
Con * con_by_frame_id(xcb_window_t frame)
Returns the container with the given frame ID or NULL if no such container exists.
Definition: con.c:707
void con_activate_unblock(Con *con)
Activates the container like in con_activate but removes fullscreen restrictions and properly warps t...
Definition: con.c:296
static void con_on_remove_child(Con *con)
Definition: con.c:1979
Rect con_border_style_rect(Con *con)
Returns a "relative" Rect which contains the amount of pixels that need to be added to the original R...
Definition: con.c:1656
Con * con_by_mark(const char *mark)
Returns the container with the given mark or NULL if no such container exists.
Definition: con.c:722
Con * con_descend_tiling_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
Definition: con.c:1564
i3String * con_parse_title_format(Con *con)
Returns the window title considering the current title format.
Definition: con.c:2295
void con_mark_toggle(Con *con, const char *mark, mark_mode_t mode)
Toggles the mark on a container.
Definition: con.c:752
bool con_fullscreen_permits_focusing(Con *con)
Returns true if changing the focus to con would be allowed considering the fullscreen focus constrain...
Definition: con.c:2102
bool con_swap(Con *first, Con *second)
Swaps the two containers.
Definition: con.c:2339
bool con_accepts_window(Con *con)
Returns true if this node accepts a window (if the node swallows windows, it might already have swall...
Definition: con.c:443
uint32_t con_rect_size_in_orientation(Con *con)
Returns given container's rect size depending on its orientation.
Definition: con.c:2459
bool con_is_internal(Con *con)
Returns true if the container is internal, such as __i3_scratch.
Definition: con.c:587
Con * con_next_focused(Con *con)
Returns the container which will be focused next when the given container is not available anymore.
Definition: con.c:1507
bool con_exists(Con *con)
Returns true if the given container (still) exists.
Definition: con.c:698
void con_detach(Con *con)
Detaches the given container from its current parent.
Definition: con.c:229
void con_move_to_output(Con *con, Output *output, bool fix_coordinates)
Moves the given container to the currently focused container on the visible workspace on the given ou...
Definition: con.c:1443
void set_focus_order(Con *con, Con **focus_order)
Clear the container's focus stack and re-add it using the provided container array.
Definition: con.c:922
int con_border_style(Con *con)
Use this function to get a container’s border style.
Definition: con.c:1736
void con_toggle_fullscreen(Con *con, int fullscreen_mode)
Toggles fullscreen mode for the given container.
Definition: con.c:1058
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given container.
Definition: con.c:1010
Con * con_new(Con *parent, i3Window *window)
A wrapper for con_new_skeleton, to retain the old con_new behaviour.
Definition: con.c:68
Con * con_inside_floating(Con *con)
Checks if the given container is either floating or inside some floating container.
Definition: con.c:619
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
Definition: con.c:221
Rect con_minimum_size(Con *con)
Determines the minimum size of the given con by looking at its children (for split/stacked/tabbed con...
Definition: con.c:2028
static void _con_attach(Con *con, Con *parent, Con *previous, bool ignore_focus)
Definition: con.c:98
bool con_inside_focused(Con *con)
Checks if the given container is inside a focused container.
Definition: con.c:637
#define SWAP_CONS_IN_TREE(headname, field)
Con * con_get_output(Con *con)
Gets the output container (first container with CT_OUTPUT in hierarchy) this node is on.
Definition: con.c:462
void con_free(Con *con)
Frees the specified container.
Definition: con.c:78
static bool _con_move_to_con(Con *con, Con *target, bool behind_focused, bool fix_coordinates, bool dont_warp, bool ignore_focus, bool fix_percentage)
Definition: con.c:1174
void con_set_border_style(Con *con, int border_style, int border_width)
Sets the given border style on con, correctly keeping the position/size of a floating window.
Definition: con.c:1759
void con_merge_into(Con *old, Con *new)
Merges container specific data that should move with the window (e.g.
Definition: con.c:2469
bool con_is_leaf(Con *con)
Returns true when this node is a leaf node (has no children)
Definition: con.c:360
int con_num_children(Con *con)
Returns the number of children of this container.
Definition: con.c:946
adjacent_t con_adjacent_borders(Con *con)
Returns adjacent borders of the window.
Definition: con.c:1707
void con_set_layout(Con *con, layout_t layout)
This function changes the layout of a given container.
Definition: con.c:1801
void con_activate(Con *con)
Sets input focus to the given container and raises it to the top.
Definition: con.c:286
char * con_get_tree_representation(Con *con)
Create a string representing the subtree under con.
Definition: con.c:2232
void con_toggle_layout(Con *con, const char *toggle_mode)
This function toggles the layout of a given container.
Definition: con.c:1886
bool con_has_mark(Con *con, const char *mark)
Returns true if and only if the given containers holds the mark.
Definition: con.c:736
bool con_has_urgent_child(Con *con)
Checks if the given container has an urgent child.
Definition: con.c:2142
void con_enable_fullscreen(Con *con, fullscreen_mode_t fullscreen_mode)
Enables fullscreen mode for the given container, if necessary.
Definition: con.c:1112
bool con_has_parent(Con *con, Con *parent)
Checks if the container has the given parent as an actual parent.
Definition: con.c:649
int con_num_windows(Con *con)
Count the number of windows (i.e., leaf containers).
Definition: con.c:984
void con_focus(Con *con)
Sets input focus to the given container.
Definition: con.c:245
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
bool con_is_sticky(Con *con)
Returns whether the container or any of its children is sticky.
Definition: con.c:425
static void con_set_fullscreen_mode(Con *con, fullscreen_mode_t fullscreen_mode)
Definition: con.c:1078
Config config
Definition: config.c:17
void ewmh_update_wm_desktop(void)
Updates _NET_WM_DESKTOP for all windows.
Definition: ewmh.c:184
void floating_raise_con(Con *con)
Raises the given container in the list of floating containers.
Definition: floating.c:486
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
void ipc_send_event(const char *event, uint32_t message_type, const char *payload)
Sends the specified event to all IPC clients which are currently connected and subscribed to this kin...
Definition: ipc.c:163
yajl_gen ipc_marshal_workspace_event(const char *change, Con *current, Con *old)
Generates a json workspace event.
Definition: ipc.c:1581
void ipc_send_window_event(const char *property, Con *con)
For the window events we send, along the usual "change" field, also the window container,...
Definition: ipc.c:1630
struct pending_marks * marks
xcb_connection_t * conn
XCB connection and root screen.
Definition: main.c:51
uint8_t root_depth
Definition: main.c:69
void match_free(Match *match)
Frees the given match.
Definition: match.c:267
bool match_matches_window(Match *match, i3Window *window)
Check if a match data structure matches the given window.
Definition: match.c:87
Output * get_output_from_string(Output *current_output, const char *output_str)
Returns an 'output' corresponding to one of left/right/down/up or a specific output name.
Definition: output.c:33
char * output_primary_name(Output *output)
Retrieves the primary name of an output.
Definition: output.c:53
Con * output_get_content(Con *output)
Returns the output container below the given output container.
Definition: output.c:16
Output * get_output_for_con(Con *con)
Returns the output for the given con.
Definition: output.c:57
int render_deco_height(void)
Returns the height for the decorations.
Definition: render.c:27
void scratchpad_move(Con *con)
Moves the specified window to the __i3_scratch workspace, making it floating and setting the appropri...
Definition: scratchpad.c:19
void startup_sequence_delete_by_window(i3Window *win)
Deletes the startup sequence for a window if it exists.
Definition: startup.c:367
struct Con * focused
Definition: tree.c:13
void tree_flatten(Con *con)
tree_flatten() removes pairs of redundant split containers, e.g.
Definition: tree.c:651
struct Con * croot
Definition: tree.c:12
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
struct all_cons_head all_cons
Definition: tree.c:15
char * pango_escape_markup(char *input)
Escapes the given string if a pango font is currently used.
Definition: util.c:321
Rect rect_add(Rect a, Rect b)
Definition: util.c:39
int min(int a, int b)
Definition: util.c:24
bool layout_from_name(const char *layout_str, layout_t *out)
Set 'out' to the layout_t value for the given layout.
Definition: util.c:82
Rect rect_sub(Rect a, Rect b)
Definition: util.c:46
int max(int a, int b)
Definition: util.c:28
Con * workspace_encapsulate(Con *ws)
Creates a new container and re-parents all of children from the given workspace into it.
Definition: workspace.c:931
Con * workspace_get(const char *num)
Returns a pointer to the workspace with the given number (starting at 0), creating the workspace if n...
Definition: workspace.c:127
void workspace_update_urgent_flag(Con *ws)
Goes through all clients on the given workspace and updates the workspace’s urgent flag accordingly.
Definition: workspace.c:842
void workspace_show(Con *workspace)
Switches to the given workspace.
Definition: workspace.c:417
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
Definition: workspace.c:303
Con * workspace_attach_to(Con *ws)
Called when a new con (with a window, not an empty or split con) should be attached to the workspace ...
Definition: workspace.c:899
void x_con_init(Con *con)
Initializes the X11 part for the given container.
Definition: x.c:127
void x_set_warp_to(Rect *rect)
Set warp_to coordinates.
Definition: x.c:1429
void xcb_add_property_atom(xcb_connection_t *conn, xcb_window_t window, xcb_atom_t property, xcb_atom_t atom)
Add an atom to a list of atoms the given property defines.
Definition: xcb.c:235
void xcb_remove_property_atom(xcb_connection_t *conn, xcb_window_t window, xcb_atom_t property, xcb_atom_t atom)
Remove an atom from a list of atoms the given property defines without removing any other potentially...
Definition: xcb.c:245
@ HEBM_SMART
Definition: data.h:82
struct Rect Rect
Definition: data.h:41
layout_t
Container layouts.
Definition: data.h:90
@ L_STACKED
Definition: data.h:92
@ L_TABBED
Definition: data.h:93
@ L_DOCKAREA
Definition: data.h:94
@ L_OUTPUT
Definition: data.h:95
@ L_SPLITH
Definition: data.h:97
@ L_SPLITV
Definition: data.h:96
@ L_DEFAULT
Definition: data.h:91
mark_mode_t
Definition: data.h:84
@ MM_REPLACE
Definition: data.h:84
orientation_t
Definition: data.h:56
@ VERT
Definition: data.h:58
@ HORIZ
Definition: data.h:57
adjacent_t
describes if the window is adjacent to the output (physical screen) edges.
Definition: data.h:72
@ ADJ_LEFT_SCREEN_EDGE
Definition: data.h:73
@ ADJ_LOWER_SCREEN_EDGE
Definition: data.h:76
@ ADJ_RIGHT_SCREEN_EDGE
Definition: data.h:74
@ ADJ_UPPER_SCREEN_EDGE
Definition: data.h:75
@ ADJ_NONE
Definition: data.h:72
fullscreen_mode_t
Fullscreen modes.
Definition: data.h:590
@ CF_OUTPUT
Definition: data.h:591
@ CF_GLOBAL
Definition: data.h:592
@ CF_NONE
Definition: data.h:590
@ BS_NONE
Definition: data.h:62
@ BS_NORMAL
Definition: data.h:61
kill_window_t
parameter to specify whether tree_close_internal() and x_window_kill() should kill only this specific...
Definition: data.h:67
@ DONT_KILL_WINDOW
Definition: data.h:67
direction_t
Definition: data.h:52
@ D_RIGHT
Definition: data.h:53
@ D_LEFT
Definition: data.h:52
@ D_UP
Definition: data.h:54
@ D_DOWN
Definition: data.h:55
struct _i3String i3String
Opaque data structure for storing strings.
Definition: libi3.h:48
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
#define DLOG(fmt,...)
Definition: libi3.h:104
const char * i3string_as_utf8(i3String *str)
Returns the UTF-8 encoded version of the i3String.
#define LOG(fmt,...)
Definition: libi3.h:94
int strcasecmp_nullable(const char *a, const char *b)
Like strcasecmp but considers the case where either string is NULL.
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
#define ELOG(fmt,...)
Definition: libi3.h:99
char * format_placeholders(char *format, placeholder_t *placeholders, int num)
Replaces occurrences of the defined placeholders in the format string.
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...
void i3string_set_markup(i3String *str, bool pango_markup)
Set whether the i3String should use Pango markup.
i3String * i3string_from_utf8(const char *from_utf8)
Build an i3String from an UTF-8 encoded string.
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...
bool font_is_pango(void)
Returns true if and only if the current font is a pango font.
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:347
#define TAILQ_END(head)
Definition: queue.h:337
#define TAILQ_INIT(head)
Definition: queue.h:360
#define TAILQ_HEAD(name, type)
Definition: queue.h:318
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:376
#define TAILQ_FIRST(head)
Definition: queue.h:336
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:402
#define TAILQ_NEXT(elm, field)
Definition: queue.h:338
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
#define TAILQ_EMPTY(head)
Definition: queue.h:344
#define TAILQ_INSERT_BEFORE(listelm, elm, field)
Definition: queue.h:394
#define TAILQ_LAST(head, headname)
Definition: queue.h:339
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:366
#define TAILQ_ENTRY(type)
Definition: queue.h:327
#define TAILQ_INSERT_AFTER(head, listelm, elm, field)
Definition: queue.h:384
#define CALL(obj, member,...)
Definition: util.h:53
#define GREP_FIRST(dest, head, condition)
Definition: util.h:38
#define SWAP(first, second, type)
Definition: util.h:55
#define FREE(pointer)
Definition: util.h:47
size_t ylength
Definition: yajl_utils.h:24
Definition: con.c:514
Con * con
Definition: con.c:515
int default_border_width
hide_edge_borders_mode_t hide_edge_borders
Remove borders if they are adjacent to the screen edge.
int default_floating_border_width
border_style_t default_border
The default border style for new windows.
Stores a rectangle, for example the size of a window, the child window etc.
Definition: data.h:155
uint32_t height
Definition: data.h:159
uint32_t x
Definition: data.h:156
uint32_t y
Definition: data.h:157
uint32_t width
Definition: data.h:158
An Output is a physical output on your graphics driver.
Definition: data.h:360
Con * con
Pointer to the Con which represents this output.
Definition: data.h:380
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
Definition: data.h:393
char * class_instance
Definition: data.h:407
struct timeval urgent
When this window was marked urgent.
Definition: data.h:442
i3String * name
The name of the window.
Definition: data.h:410
xcb_window_t id
Definition: data.h:394
char * class_class
Definition: data.h:406
uint16_t depth
Depth of the window.
Definition: data.h:448
A "match" is a data structure which acts like a mask or expression to match certain windows or not.
Definition: data.h:492
Definition: data.h:594
char * name
Definition: data.h:595
A 'Con' represents everything from the X11 root window down to a single X11 window.
Definition: data.h:604
struct Con * parent
Definition: data.h:636
struct Rect deco_rect
Definition: data.h:646
layout_t workspace_layout
Definition: data.h:708
double percent
Definition: data.h:665
layout_t last_split_layout
Definition: data.h:708
struct Rect rect
Definition: data.h:640
enum Con::@20 type
int current_border_width
Definition: data.h:669
bool sticky
Definition: data.h:692
enum Con::@21 floating
floating? (= not in tiling layout) This cannot be simply a bool because we want to keep track of whet...
layout_t layout
Definition: data.h:708
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
struct ev_timer * urgency_timer
Definition: data.h:674
struct Rect window_rect
Definition: data.h:643
struct Window * window
Definition: data.h:671
char * title_format
The format with which the window's name should be displayed.
Definition: data.h:653
surface_t frame
Definition: data.h:619
border_style_t border_style
Definition: data.h:709
char * name
Definition: data.h:650
char * sticky_group
Definition: data.h:658
struct deco_render_params * deco_render_params
Cache for the decoration rendering.
Definition: data.h:677
bool mark_changed
Definition: data.h:663
fullscreen_mode_t fullscreen_mode
Definition: data.h:687
bool urgent
Definition: data.h:609
Helper structure for usage in format_placeholders().
Definition: libi3.h:544
const char * name
Definition: libi3.h:546
xcb_drawable_t id
Definition: libi3.h:569