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