]> git.sur5r.net Git - i3/i3/blob - src/con.c
Merge branch 'fix-baf-after-scratchpad'
[i3/i3] / src / con.c
1 #undef I3__FILE__
2 #define I3__FILE__ "con.c"
3 /*
4  * vim:ts=4:sw=4:expandtab
5  *
6  * i3 - an improved dynamic tiling window manager
7  * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
8  *
9  * con.c: Functions which deal with containers directly (creating containers,
10  *        searching containers, getting specific properties from containers,
11  *        …).
12  *
13  */
14 #include "all.h"
15
16 char *colors[] = {
17     "#ff0000",
18     "#00FF00",
19     "#0000FF",
20     "#ff00ff",
21     "#00ffff",
22     "#ffff00",
23     "#aa0000",
24     "#00aa00",
25     "#0000aa",
26     "#aa00aa"
27 };
28
29 static void con_on_remove_child(Con *con);
30
31 /*
32  * Create a new container (and attach it to the given parent, if not NULL).
33  * This function initializes the data structures and creates the appropriate
34  * X11 IDs using x_con_init().
35  *
36  */
37 Con *con_new(Con *parent, i3Window *window) {
38     Con *new = scalloc(sizeof(Con));
39     new->on_remove_child = con_on_remove_child;
40     TAILQ_INSERT_TAIL(&all_cons, new, all_cons);
41     new->type = CT_CON;
42     new->window = window;
43     new->border_style = config.default_border;
44     static int cnt = 0;
45     DLOG("opening window %d\n", cnt);
46
47     /* TODO: remove window coloring after test-phase */
48     DLOG("color %s\n", colors[cnt]);
49     new->name = strdup(colors[cnt]);
50     //uint32_t cp = get_colorpixel(colors[cnt]);
51     cnt++;
52     if ((cnt % (sizeof(colors) / sizeof(char*))) == 0)
53         cnt = 0;
54     if (window)
55         x_con_init(new, window->depth);
56     else
57         x_con_init(new, XCB_COPY_FROM_PARENT);
58
59     TAILQ_INIT(&(new->floating_head));
60     TAILQ_INIT(&(new->nodes_head));
61     TAILQ_INIT(&(new->focus_head));
62     TAILQ_INIT(&(new->swallow_head));
63
64     if (parent != NULL)
65         con_attach(new, parent, false);
66
67     return new;
68 }
69
70 /*
71  * Attaches the given container to the given parent. This happens when moving
72  * a container or when inserting a new container at a specific place in the
73  * tree.
74  *
75  * ignore_focus is to just insert the Con at the end (useful when creating a
76  * new split container *around* some containers, that is, detaching and
77  * attaching them in order without wanting to mess with the focus in between).
78  *
79  */
80 void con_attach(Con *con, Con *parent, bool ignore_focus) {
81     con->parent = parent;
82     Con *loop;
83     Con *current = NULL;
84     struct nodes_head *nodes_head = &(parent->nodes_head);
85     struct focus_head *focus_head = &(parent->focus_head);
86
87     /* Workspaces are handled differently: they need to be inserted at the
88      * right position. */
89     if (con->type == CT_WORKSPACE) {
90         DLOG("it's a workspace. num = %d\n", con->num);
91         if (con->num == -1 || TAILQ_EMPTY(nodes_head)) {
92             TAILQ_INSERT_TAIL(nodes_head, con, nodes);
93         } else {
94             current = TAILQ_FIRST(nodes_head);
95             if (con->num < current->num) {
96                 /* we need to insert the container at the beginning */
97                 TAILQ_INSERT_HEAD(nodes_head, con, nodes);
98             } else {
99                 while (current->num != -1 && con->num > current->num) {
100                     current = TAILQ_NEXT(current, nodes);
101                     if (current == TAILQ_END(nodes_head)) {
102                         current = NULL;
103                         break;
104                     }
105                 }
106                 /* we need to insert con after current, if current is not NULL */
107                 if (current)
108                     TAILQ_INSERT_BEFORE(current, con, nodes);
109                 else TAILQ_INSERT_TAIL(nodes_head, con, nodes);
110             }
111         }
112         goto add_to_focus_head;
113     }
114
115     if (con->type == CT_FLOATING_CON) {
116         DLOG("Inserting into floating containers\n");
117         TAILQ_INSERT_TAIL(&(parent->floating_head), con, floating_windows);
118     } else {
119         if (!ignore_focus) {
120             /* Get the first tiling container in focus stack */
121             TAILQ_FOREACH(loop, &(parent->focus_head), focused) {
122                 if (loop->type == CT_FLOATING_CON)
123                     continue;
124                 current = loop;
125                 break;
126             }
127         }
128
129         /* When the container is not a split container (but contains a window)
130          * and is attached to a workspace, we check if the user configured a
131          * workspace_layout. This is done in workspace_attach_to, which will
132          * provide us with the container to which we should attach (either the
133          * workspace or a new split container with the configured
134          * workspace_layout).
135          */
136         if (con->window != NULL &&
137             parent->type == CT_WORKSPACE &&
138             parent->workspace_layout != L_DEFAULT) {
139             DLOG("Parent is a workspace. Applying default layout...\n");
140             Con *target = workspace_attach_to(parent);
141
142             /* Attach the original con to this new split con instead */
143             nodes_head = &(target->nodes_head);
144             focus_head = &(target->focus_head);
145             con->parent = target;
146             current = NULL;
147
148             DLOG("done\n");
149         }
150
151         /* Insert the container after the tiling container, if found.
152          * When adding to a CT_OUTPUT, just append one after another. */
153         if (current && parent->type != CT_OUTPUT) {
154             DLOG("Inserting con = %p after last focused tiling con %p\n",
155                  con, current);
156             TAILQ_INSERT_AFTER(nodes_head, current, con, nodes);
157         } else TAILQ_INSERT_TAIL(nodes_head, con, nodes);
158     }
159
160 add_to_focus_head:
161     /* We insert to the TAIL because con_focus() will correct this.
162      * This way, we have the option to insert Cons without having
163      * to focus them. */
164     TAILQ_INSERT_TAIL(focus_head, con, focused);
165 }
166
167 /*
168  * Detaches the given container from its current parent
169  *
170  */
171 void con_detach(Con *con) {
172     if (con->type == CT_FLOATING_CON) {
173         TAILQ_REMOVE(&(con->parent->floating_head), con, floating_windows);
174         TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
175     } else {
176         TAILQ_REMOVE(&(con->parent->nodes_head), con, nodes);
177         TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
178     }
179 }
180
181 /*
182  * Sets input focus to the given container. Will be updated in X11 in the next
183  * run of x_push_changes().
184  *
185  */
186 void con_focus(Con *con) {
187     assert(con != NULL);
188     DLOG("con_focus = %p\n", con);
189
190     /* 1: set focused-pointer to the new con */
191     /* 2: exchange the position of the container in focus stack of the parent all the way up */
192     TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
193     TAILQ_INSERT_HEAD(&(con->parent->focus_head), con, focused);
194     if (con->parent->parent != NULL)
195         con_focus(con->parent);
196
197     focused = con;
198     if (con->urgent) {
199         con->urgent = false;
200         workspace_update_urgent_flag(con_get_workspace(con));
201     }
202 }
203
204 /*
205  * Returns true when this node is a leaf node (has no children)
206  *
207  */
208 bool con_is_leaf(Con *con) {
209     return TAILQ_EMPTY(&(con->nodes_head));
210 }
211
212 /*
213  * Returns true if this node accepts a window (if the node swallows windows,
214  * it might already have swallowed enough and cannot hold any more).
215  *
216  */
217 bool con_accepts_window(Con *con) {
218     /* 1: workspaces never accept direct windows */
219     if (con->type == CT_WORKSPACE)
220         return false;
221
222     if (con->split) {
223         DLOG("container %p does not accept windows, it is a split container.\n", con);
224         return false;
225     }
226
227     /* TODO: if this is a swallowing container, we need to check its max_clients */
228     return (con->window == NULL);
229 }
230
231 /*
232  * Gets the output container (first container with CT_OUTPUT in hierarchy) this
233  * node is on.
234  *
235  */
236 Con *con_get_output(Con *con) {
237     Con *result = con;
238     while (result != NULL && result->type != CT_OUTPUT)
239         result = result->parent;
240     /* We must be able to get an output because focus can never be set higher
241      * in the tree (root node cannot be focused). */
242     assert(result != NULL);
243     return result;
244 }
245
246 /*
247  * Gets the workspace container this node is on.
248  *
249  */
250 Con *con_get_workspace(Con *con) {
251     Con *result = con;
252     while (result != NULL && result->type != CT_WORKSPACE)
253         result = result->parent;
254     return result;
255 }
256
257 /*
258  * Searches parenst of the given 'con' until it reaches one with the specified
259  * 'orientation'. Aborts when it comes across a floating_con.
260  *
261  */
262 Con *con_parent_with_orientation(Con *con, orientation_t orientation) {
263     DLOG("Searching for parent of Con %p with orientation %d\n", con, orientation);
264     Con *parent = con->parent;
265     if (parent->type == CT_FLOATING_CON)
266         return NULL;
267     while (con_orientation(parent) != orientation) {
268         DLOG("Need to go one level further up\n");
269         parent = parent->parent;
270         /* Abort when we reach a floating con, or an output con */
271         if (parent &&
272             (parent->type == CT_FLOATING_CON ||
273              parent->type == CT_OUTPUT ||
274              (parent->parent && parent->parent->type == CT_OUTPUT)))
275             parent = NULL;
276         if (parent == NULL)
277             break;
278     }
279     DLOG("Result: %p\n", parent);
280     return parent;
281 }
282
283 /*
284  * helper data structure for the breadth-first-search in
285  * con_get_fullscreen_con()
286  *
287  */
288 struct bfs_entry {
289     Con *con;
290
291     TAILQ_ENTRY(bfs_entry) entries;
292 };
293
294 /*
295  * Returns the first fullscreen node below this node.
296  *
297  */
298 Con *con_get_fullscreen_con(Con *con, int fullscreen_mode) {
299     Con *current, *child;
300
301     /* TODO: is breadth-first-search really appropriate? (check as soon as
302      * fullscreen levels and fullscreen for containers is implemented) */
303     TAILQ_HEAD(bfs_head, bfs_entry) bfs_head = TAILQ_HEAD_INITIALIZER(bfs_head);
304     struct bfs_entry *entry = smalloc(sizeof(struct bfs_entry));
305     entry->con = con;
306     TAILQ_INSERT_TAIL(&bfs_head, entry, entries);
307
308     while (!TAILQ_EMPTY(&bfs_head)) {
309         entry = TAILQ_FIRST(&bfs_head);
310         current = entry->con;
311         if (current != con && current->fullscreen_mode == fullscreen_mode) {
312             /* empty the queue */
313             while (!TAILQ_EMPTY(&bfs_head)) {
314                 entry = TAILQ_FIRST(&bfs_head);
315                 TAILQ_REMOVE(&bfs_head, entry, entries);
316                 free(entry);
317             }
318             return current;
319         }
320
321         TAILQ_REMOVE(&bfs_head, entry, entries);
322         free(entry);
323
324         TAILQ_FOREACH(child, &(current->nodes_head), nodes) {
325             entry = smalloc(sizeof(struct bfs_entry));
326             entry->con = child;
327             TAILQ_INSERT_TAIL(&bfs_head, entry, entries);
328         }
329
330         TAILQ_FOREACH(child, &(current->floating_head), floating_windows) {
331             entry = smalloc(sizeof(struct bfs_entry));
332             entry->con = child;
333             TAILQ_INSERT_TAIL(&bfs_head, entry, entries);
334         }
335     }
336
337     return NULL;
338 }
339
340 /*
341  * Returns true if the node is floating.
342  *
343  */
344 bool con_is_floating(Con *con) {
345     assert(con != NULL);
346     DLOG("checking if con %p is floating\n", con);
347     return (con->floating >= FLOATING_AUTO_ON);
348 }
349
350 /*
351  * Checks if the given container is either floating or inside some floating
352  * container. It returns the FLOATING_CON container.
353  *
354  */
355 Con *con_inside_floating(Con *con) {
356     assert(con != NULL);
357     if (con->type == CT_FLOATING_CON)
358         return con;
359
360     if (con->floating >= FLOATING_AUTO_ON)
361         return con->parent;
362
363     if (con->type == CT_WORKSPACE || con->type == CT_OUTPUT)
364         return NULL;
365
366     return con_inside_floating(con->parent);
367 }
368
369 /*
370  * Checks if the given container is inside a focused container.
371  *
372  */
373 bool con_inside_focused(Con *con) {
374     if (con == focused)
375         return true;
376     if (!con->parent)
377         return false;
378     return con_inside_focused(con->parent);
379 }
380
381 /*
382  * Returns the container with the given client window ID or NULL if no such
383  * container exists.
384  *
385  */
386 Con *con_by_window_id(xcb_window_t window) {
387     Con *con;
388     TAILQ_FOREACH(con, &all_cons, all_cons)
389         if (con->window != NULL && con->window->id == window)
390             return con;
391     return NULL;
392 }
393
394 /*
395  * Returns the container with the given frame ID or NULL if no such container
396  * exists.
397  *
398  */
399 Con *con_by_frame_id(xcb_window_t frame) {
400     Con *con;
401     TAILQ_FOREACH(con, &all_cons, all_cons)
402         if (con->frame == frame)
403             return con;
404     return NULL;
405 }
406
407 /*
408  * Returns the first container below 'con' which wants to swallow this window
409  * TODO: priority
410  *
411  */
412 Con *con_for_window(Con *con, i3Window *window, Match **store_match) {
413     Con *child;
414     Match *match;
415     //DLOG("searching con for window %p starting at con %p\n", window, con);
416     //DLOG("class == %s\n", window->class_class);
417
418     TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
419         TAILQ_FOREACH(match, &(child->swallow_head), matches) {
420             if (!match_matches_window(match, window))
421                 continue;
422             if (store_match != NULL)
423                 *store_match = match;
424             return child;
425         }
426         Con *result = con_for_window(child, window, store_match);
427         if (result != NULL)
428             return result;
429     }
430
431     TAILQ_FOREACH(child, &(con->floating_head), floating_windows) {
432         TAILQ_FOREACH(match, &(child->swallow_head), matches) {
433             if (!match_matches_window(match, window))
434                 continue;
435             if (store_match != NULL)
436                 *store_match = match;
437             return child;
438         }
439         Con *result = con_for_window(child, window, store_match);
440         if (result != NULL)
441             return result;
442     }
443
444     return NULL;
445 }
446
447 /*
448  * Returns the number of children of this container.
449  *
450  */
451 int con_num_children(Con *con) {
452     Con *child;
453     int children = 0;
454
455     TAILQ_FOREACH(child, &(con->nodes_head), nodes)
456         children++;
457
458     return children;
459 }
460
461 /*
462  * Updates the percent attribute of the children of the given container. This
463  * function needs to be called when a window is added or removed from a
464  * container.
465  *
466  */
467 void con_fix_percent(Con *con) {
468     Con *child;
469     int children = con_num_children(con);
470
471     // calculate how much we have distributed and how many containers
472     // with a percentage set we have
473     double total = 0.0;
474     int children_with_percent = 0;
475     TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
476         if (child->percent > 0.0) {
477             total += child->percent;
478             ++children_with_percent;
479         }
480     }
481
482     // if there were children without a percentage set, set to a value that
483     // will make those children proportional to all others
484     if (children_with_percent != children) {
485         TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
486             if (child->percent <= 0.0) {
487                 if (children_with_percent == 0)
488                     total += (child->percent = 1.0);
489                 else total += (child->percent = total / children_with_percent);
490             }
491         }
492     }
493
494     // if we got a zero, just distribute the space equally, otherwise
495     // distribute according to the proportions we got
496     if (total == 0.0) {
497         TAILQ_FOREACH(child, &(con->nodes_head), nodes)
498             child->percent = 1.0 / children;
499     } else if (total != 1.0) {
500         TAILQ_FOREACH(child, &(con->nodes_head), nodes)
501             child->percent /= total;
502     }
503 }
504
505 /*
506  * Toggles fullscreen mode for the given container. Fullscreen mode will not be
507  * entered when there already is a fullscreen container on this workspace.
508  *
509  */
510 void con_toggle_fullscreen(Con *con, int fullscreen_mode) {
511     Con *workspace, *fullscreen;
512
513     if (con->type == CT_WORKSPACE) {
514         DLOG("You cannot make a workspace fullscreen.\n");
515         return;
516     }
517
518     DLOG("toggling fullscreen for %p / %s\n", con, con->name);
519     if (con->fullscreen_mode == CF_NONE) {
520         /* 1: check if there already is a fullscreen con */
521         if (fullscreen_mode == CF_GLOBAL)
522             fullscreen = con_get_fullscreen_con(croot, CF_GLOBAL);
523         else {
524             workspace = con_get_workspace(con);
525             fullscreen = con_get_fullscreen_con(workspace, CF_OUTPUT);
526         }
527         if (fullscreen != NULL) {
528             /* Disable fullscreen for the currently fullscreened
529              * container and enable it for the one the user wants
530              * to have in fullscreen mode. */
531             LOG("Disabling fullscreen for (%p/%s) upon user request\n",
532                 fullscreen, fullscreen->name);
533             fullscreen->fullscreen_mode = CF_NONE;
534         }
535
536         /* 2: enable fullscreen */
537         con->fullscreen_mode = fullscreen_mode;
538     } else {
539         /* 1: disable fullscreen */
540         con->fullscreen_mode = CF_NONE;
541     }
542
543     DLOG("mode now: %d\n", con->fullscreen_mode);
544
545     /* update _NET_WM_STATE if this container has a window */
546     /* TODO: when a window is assigned to a container which is already
547      * fullscreened, this state needs to be pushed to the client, too */
548     if (con->window == NULL)
549         return;
550
551     uint32_t values[1];
552     unsigned int num = 0;
553
554     if (con->fullscreen_mode != CF_NONE)
555         values[num++] = A__NET_WM_STATE_FULLSCREEN;
556
557     xcb_change_property(conn, XCB_PROP_MODE_REPLACE, con->window->id,
558                         A__NET_WM_STATE, XCB_ATOM_ATOM, 32, num, values);
559 }
560
561 /*
562  * Moves the given container to the currently focused container on the given
563  * workspace.
564  *
565  * The fix_coordinates flag will translate the current coordinates (offset from
566  * the monitor position basically) to appropriate coordinates on the
567  * destination workspace.
568  * Not enabling this behaviour comes in handy when this function gets called by
569  * floating_maybe_reassign_ws, which will only "move" a floating window when it
570  * *already* changed its coordinates to a different output.
571  *
572  * The dont_warp flag disables pointer warping and will be set when this
573  * function is called while dragging a floating window.
574  *
575  * TODO: is there a better place for this function?
576  *
577  */
578 void con_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, bool dont_warp) {
579     if (con->type == CT_WORKSPACE) {
580         DLOG("Moving workspaces is not yet implemented.\n");
581         return;
582     }
583
584     /* Prevent moving if this would violate the fullscreen focus restrictions. */
585     if (!con_fullscreen_permits_focusing(workspace)) {
586         LOG("Cannot move out of a fullscreen container");
587         return;
588     }
589
590     if (con_is_floating(con)) {
591         DLOG("Using FLOATINGCON instead\n");
592         con = con->parent;
593     }
594
595     Con *source_ws = con_get_workspace(con);
596     if (workspace == source_ws) {
597         DLOG("Not moving, already there\n");
598         return;
599     }
600
601     /* Save the current workspace. So we can call workspace_show() by the end
602      * of this function. */
603     Con *current_ws = con_get_workspace(focused);
604
605     Con *source_output = con_get_output(con),
606         *dest_output = con_get_output(workspace);
607
608     /* 1: save the container which is going to be focused after the current
609      * container is moved away */
610     Con *focus_next = con_next_focused(con);
611
612     /* 2: get the focused container of this workspace */
613     Con *next = con_descend_focused(workspace);
614
615     /* 3: we go up one level, but only when next is a normal container */
616     if (next->type != CT_WORKSPACE) {
617         DLOG("next originally = %p / %s / type %d\n", next, next->name, next->type);
618         next = next->parent;
619     }
620
621     /* 4: if the target container is floating, we get the workspace instead.
622      * Only tiling windows need to get inserted next to the current container.
623      * */
624     Con *floatingcon = con_inside_floating(next);
625     if (floatingcon != NULL) {
626         DLOG("floatingcon, going up even further\n");
627         next = floatingcon->parent;
628     }
629
630     if (con->type == CT_FLOATING_CON) {
631         Con *ws = con_get_workspace(next);
632         DLOG("This is a floating window, using workspace %p / %s\n", ws, ws->name);
633         next = ws;
634     }
635
636     if (source_output != dest_output) {
637         /* Take the relative coordinates of the current output, then add them
638          * to the coordinate space of the correct output */
639         if (fix_coordinates && con->type == CT_FLOATING_CON) {
640             floating_fix_coordinates(con, &(source_output->rect), &(dest_output->rect));
641         } else DLOG("Not fixing coordinates, fix_coordinates flag = %d\n", fix_coordinates);
642
643         /* If moving to a visible workspace, call show so it can be considered
644          * focused. Must do before attaching because workspace_show checks to see
645          * if focused container is in its area. */
646         if (workspace_is_visible(workspace)) {
647             workspace_show(workspace);
648
649             /* Don’t warp if told so (when dragging floating windows with the
650              * mouse for example) */
651             if (dont_warp)
652                 x_set_warp_to(NULL);
653             else
654                 x_set_warp_to(&(con->rect));
655         }
656     }
657
658     DLOG("Re-attaching container to %p / %s\n", next, next->name);
659     /* 5: re-attach the con to the parent of this focused container */
660     Con *parent = con->parent;
661     con_detach(con);
662     con_attach(con, next, false);
663
664     /* 6: fix the percentages */
665     con_fix_percent(parent);
666     con->percent = 0.0;
667     con_fix_percent(next);
668
669     /* 7: focus the con on the target workspace, but only within that
670      * workspace, that is, don’t move focus away if the target workspace is
671      * invisible.
672      * We don’t focus the con for i3 pseudo workspaces like __i3_scratch and
673      * we don’t focus when there is a fullscreen con on that workspace. */
674     if ((workspace->name[0] != '_' || workspace->name[1] != '_') &&
675         con_get_fullscreen_con(workspace, CF_OUTPUT) == NULL) {
676         /* We need to save focus on workspace level and restore it afterwards.
677          * Otherwise, we might focus a different workspace without actually
678          * switching workspaces. */
679         Con *old_focus = TAILQ_FIRST(&(output_get_content(dest_output)->focus_head));
680         con_focus(con_descend_focused(con));
681         con_focus(old_focus);
682     }
683
684     /* 8: when moving to a visible workspace on a different output, we keep the
685      * con focused. Otherwise, we leave the focus on the current workspace as we
686      * don’t want to focus invisible workspaces */
687     if (source_output != dest_output &&
688         workspace_is_visible(workspace) &&
689         workspace->name[0] != '_' &&
690         workspace->name[1] != '_') {
691         DLOG("Moved to a different output, focusing target\n");
692     } else {
693         /* Descend focus stack in case focus_next is a workspace which can
694          * occur if we move to the same workspace.  Also show current workspace
695          * to ensure it is focused. */
696         workspace_show(current_ws);
697
698         /* Set focus only if con was on current workspace before moving.
699          * Otherwise we would give focus to some window on different workspace. */
700         if (source_ws == current_ws)
701             con_focus(con_descend_focused(focus_next));
702     }
703
704     CALL(parent, on_remove_child);
705 }
706
707 /*
708  * Returns the orientation of the given container (for stacked containers,
709  * vertical orientation is used regardless of the actual orientation of the
710  * container).
711  *
712  */
713 int con_orientation(Con *con) {
714     switch (con->layout) {
715         case L_SPLITV:
716         /* stacking containers behave like they are in vertical orientation */
717         case L_STACKED:
718             return VERT;
719
720         case L_SPLITH:
721         /* tabbed containers behave like they are in vertical orientation */
722         case L_TABBED:
723             return HORIZ;
724
725         case L_DEFAULT:
726             DLOG("Someone called con_orientation() on a con with L_DEFAULT, this is a bug in the code.\n");
727             assert(false);
728             return HORIZ;
729
730         case L_DOCKAREA:
731         case L_OUTPUT:
732             DLOG("con_orientation() called on dockarea/output (%d) container %p\n", con->layout, con);
733             assert(false);
734             return HORIZ;
735
736         default:
737             DLOG("con_orientation() ran into default\n");
738             assert(false);
739     }
740 }
741
742 /*
743  * Returns the container which will be focused next when the given container
744  * is not available anymore. Called in tree_close and con_move_to_workspace
745  * to properly restore focus.
746  *
747  */
748 Con *con_next_focused(Con *con) {
749     Con *next;
750     /* floating containers are attached to a workspace, so we focus either the
751      * next floating container (if any) or the workspace itself. */
752     if (con->type == CT_FLOATING_CON) {
753         DLOG("selecting next for CT_FLOATING_CON\n");
754         next = TAILQ_NEXT(con, floating_windows);
755         DLOG("next = %p\n", next);
756         if (!next) {
757             next = TAILQ_PREV(con, floating_head, floating_windows);
758             DLOG("using prev, next = %p\n", next);
759         }
760         if (!next) {
761             Con *ws = con_get_workspace(con);
762             next = ws;
763             DLOG("no more floating containers for next = %p, restoring workspace focus\n", next);
764             while (next != TAILQ_END(&(ws->focus_head)) && !TAILQ_EMPTY(&(next->focus_head))) {
765                 next = TAILQ_FIRST(&(next->focus_head));
766                 if (next == con) {
767                     DLOG("skipping container itself, we want the next client\n");
768                     next = TAILQ_NEXT(next, focused);
769                 }
770             }
771             if (next == TAILQ_END(&(ws->focus_head))) {
772                 DLOG("Focus list empty, returning ws\n");
773                 next = ws;
774             }
775         } else {
776             /* Instead of returning the next CT_FLOATING_CON, we descend it to
777              * get an actual window to focus. */
778             next = con_descend_focused(next);
779         }
780         return next;
781     }
782
783     /* dock clients cannot be focused, so we focus the workspace instead */
784     if (con->parent->type == CT_DOCKAREA) {
785         DLOG("selecting workspace for dock client\n");
786         return con_descend_focused(output_get_content(con->parent->parent));
787     }
788
789     /* if 'con' is not the first entry in the focus stack, use the first one as
790      * it’s currently focused already */
791     Con *first = TAILQ_FIRST(&(con->parent->focus_head));
792     if (first != con) {
793         DLOG("Using first entry %p\n", first);
794         next = first;
795     } else {
796         /* try to focus the next container on the same level as this one or fall
797          * back to its parent */
798         if (!(next = TAILQ_NEXT(con, focused)))
799             next = con->parent;
800     }
801
802     /* now go down the focus stack as far as
803      * possible, excluding the current container */
804     while (!TAILQ_EMPTY(&(next->focus_head)) &&
805            TAILQ_FIRST(&(next->focus_head)) != con)
806         next = TAILQ_FIRST(&(next->focus_head));
807
808     return next;
809 }
810
811 /*
812  * Get the next/previous container in the specified orientation. This may
813  * travel up until it finds a container with suitable orientation.
814  *
815  */
816 Con *con_get_next(Con *con, char way, orientation_t orientation) {
817     DLOG("con_get_next(way=%c, orientation=%d)\n", way, orientation);
818     /* 1: get the first parent with the same orientation */
819     Con *cur = con;
820     while (con_orientation(cur->parent) != orientation) {
821         DLOG("need to go one level further up\n");
822         if (cur->parent->type == CT_WORKSPACE) {
823             LOG("that's a workspace, we can't go further up\n");
824             return NULL;
825         }
826         cur = cur->parent;
827     }
828
829     /* 2: chose next (or previous) */
830     Con *next;
831     if (way == 'n') {
832         next = TAILQ_NEXT(cur, nodes);
833         /* if we are at the end of the list, we need to wrap */
834         if (next == TAILQ_END(&(parent->nodes_head)))
835             return NULL;
836     } else {
837         next = TAILQ_PREV(cur, nodes_head, nodes);
838         /* if we are at the end of the list, we need to wrap */
839         if (next == TAILQ_END(&(cur->nodes_head)))
840             return NULL;
841     }
842     DLOG("next = %p\n", next);
843
844     return next;
845 }
846
847 /*
848  * Returns the focused con inside this client, descending the tree as far as
849  * possible. This comes in handy when attaching a con to a workspace at the
850  * currently focused position, for example.
851  *
852  */
853 Con *con_descend_focused(Con *con) {
854     Con *next = con;
855     while (next != focused && !TAILQ_EMPTY(&(next->focus_head)))
856         next = TAILQ_FIRST(&(next->focus_head));
857     return next;
858 }
859
860 /*
861  * Returns the focused con inside this client, descending the tree as far as
862  * possible. This comes in handy when attaching a con to a workspace at the
863  * currently focused position, for example.
864  *
865  * Works like con_descend_focused but considers only tiling cons.
866  *
867  */
868 Con *con_descend_tiling_focused(Con *con) {
869     Con *next = con;
870     Con *before;
871     Con *child;
872     if (next == focused)
873         return next;
874     do {
875         before = next;
876         TAILQ_FOREACH(child, &(next->focus_head), focused) {
877             if (child->type == CT_FLOATING_CON)
878                 continue;
879
880             next = child;
881             break;
882         }
883     } while (before != next && next != focused);
884     return next;
885 }
886
887 /*
888  * Returns the leftmost, rightmost, etc. container in sub-tree. For example, if
889  * direction is D_LEFT, then we return the rightmost container and if direction
890  * is D_RIGHT, we return the leftmost container.  This is because if we are
891  * moving D_LEFT, and thus want the rightmost container.
892  *
893  */
894 Con *con_descend_direction(Con *con, direction_t direction) {
895     Con *most = NULL;
896     int orientation = con_orientation(con);
897     DLOG("con_descend_direction(%p, orientation %d, direction %d)\n", con, orientation, direction);
898     if (direction == D_LEFT || direction == D_RIGHT) {
899         if (orientation == HORIZ) {
900             /* If the direction is horizontal, we can use either the first
901              * (D_RIGHT) or the last con (D_LEFT) */
902             if (direction == D_RIGHT)
903                 most = TAILQ_FIRST(&(con->nodes_head));
904             else most = TAILQ_LAST(&(con->nodes_head), nodes_head);
905         } else if (orientation == VERT) {
906             /* Wrong orientation. We use the last focused con. Within that con,
907              * we recurse to chose the left/right con or at least the last
908              * focused one. */
909             most = TAILQ_FIRST(&(con->focus_head));
910         } else {
911             /* If the con has no orientation set, it’s not a split container
912              * but a container with a client window, so stop recursing */
913             return con;
914         }
915     }
916
917     if (direction == D_UP || direction == D_DOWN) {
918         if (orientation == VERT) {
919             /* If the direction is vertical, we can use either the first
920              * (D_DOWN) or the last con (D_UP) */
921             if (direction == D_UP)
922                 most = TAILQ_LAST(&(con->nodes_head), nodes_head);
923             else most = TAILQ_FIRST(&(con->nodes_head));
924         } else if (orientation == HORIZ) {
925             /* Wrong orientation. We use the last focused con. Within that con,
926              * we recurse to chose the top/bottom con or at least the last
927              * focused one. */
928             most = TAILQ_FIRST(&(con->focus_head));
929         } else {
930             /* If the con has no orientation set, it’s not a split container
931              * but a container with a client window, so stop recursing */
932             return con;
933         }
934     }
935
936     if (!most)
937         return con;
938     return con_descend_direction(most, direction);
939 }
940
941 /*
942  * Returns a "relative" Rect which contains the amount of pixels that need to
943  * be added to the original Rect to get the final position (obviously the
944  * amount of pixels for normal, 1pixel and borderless are different).
945  *
946  */
947 Rect con_border_style_rect(Con *con) {
948     adjacent_t borders_to_hide = ADJ_NONE;
949     Rect result;
950     /* Shortcut to avoid calling con_adjacent_borders() on dock containers. */
951     int border_style = con_border_style(con);
952     if (border_style == BS_NONE)
953         return (Rect){ 0, 0, 0, 0 };
954     borders_to_hide = con_adjacent_borders(con) & config.hide_edge_borders;
955     switch (border_style) {
956     case BS_NORMAL:
957         result = (Rect){2, 0, -(2 * 2), -2};
958         if (borders_to_hide & ADJ_LEFT_SCREEN_EDGE) {
959             result.x -= 2;
960             result.width += 2;
961         }
962         if (borders_to_hide & ADJ_RIGHT_SCREEN_EDGE) {
963             result.width += 2;
964         }
965         /* With normal borders we never hide the upper border */
966         if (borders_to_hide & ADJ_LOWER_SCREEN_EDGE) {
967             result.height += 2;
968         }
969         return result;
970
971     case BS_1PIXEL:
972         result = (Rect){1, 1, -2, -2};
973         if (borders_to_hide & ADJ_LEFT_SCREEN_EDGE) {
974             result.x -= 1;
975             result.width += 1;
976         }
977         if (borders_to_hide & ADJ_RIGHT_SCREEN_EDGE) {
978             result.width += 1;
979         }
980         if (borders_to_hide & ADJ_UPPER_SCREEN_EDGE) {
981             result.y -= 1;
982             result.height += 1;
983         }
984         if (borders_to_hide & ADJ_LOWER_SCREEN_EDGE) {
985             result.height += 1;
986         }
987         return result;
988
989     case BS_NONE:
990         return (Rect){0, 0, 0, 0};
991
992     default:
993         assert(false);
994     }
995 }
996
997 /*
998  * Returns adjacent borders of the window. We need this if hide_edge_borders is
999  * enabled.
1000  */
1001 adjacent_t con_adjacent_borders(Con *con) {
1002     adjacent_t result = ADJ_NONE;
1003     Con *workspace = con_get_workspace(con);
1004     if (con->rect.x == workspace->rect.x)
1005         result |= ADJ_LEFT_SCREEN_EDGE;
1006     if (con->rect.x + con->rect.width == workspace->rect.x + workspace->rect.width)
1007         result |= ADJ_RIGHT_SCREEN_EDGE;
1008     if (con->rect.y == workspace->rect.y)
1009         result |= ADJ_UPPER_SCREEN_EDGE;
1010     if (con->rect.y + con->rect.height == workspace->rect.y + workspace->rect.height)
1011         result |= ADJ_LOWER_SCREEN_EDGE;
1012     return result;
1013 }
1014
1015 /*
1016  * Use this function to get a container’s border style. This is important
1017  * because when inside a stack, the border style is always BS_NORMAL.
1018  * For tabbed mode, the same applies, with one exception: when the container is
1019  * borderless and the only element in the tabbed container, the border is not
1020  * rendered.
1021  *
1022  * For children of a CT_DOCKAREA, the border style is always none.
1023  *
1024  */
1025 int con_border_style(Con *con) {
1026     Con *fs = con_get_fullscreen_con(con->parent, CF_OUTPUT);
1027     if (fs == con) {
1028         DLOG("this one is fullscreen! overriding BS_NONE\n");
1029         return BS_NONE;
1030     }
1031
1032     if (con->parent->layout == L_STACKED)
1033         return (con_num_children(con->parent) == 1 ? con->border_style : BS_NORMAL);
1034
1035     if (con->parent->layout == L_TABBED && con->border_style != BS_NORMAL)
1036         return (con_num_children(con->parent) == 1 ? con->border_style : BS_NORMAL);
1037
1038     if (con->parent->type == CT_DOCKAREA)
1039         return BS_NONE;
1040
1041     return con->border_style;
1042 }
1043
1044 /*
1045  * Sets the given border style on con, correctly keeping the position/size of a
1046  * floating window.
1047  *
1048  */
1049 void con_set_border_style(Con *con, int border_style) {
1050     /* Handle the simple case: non-floating containerns */
1051     if (!con_is_floating(con)) {
1052         con->border_style = border_style;
1053         return;
1054     }
1055
1056     /* For floating containers, we want to keep the position/size of the
1057      * *window* itself. We first add the border pixels to con->rect to make
1058      * con->rect represent the absolute position of the window. Then, we change
1059      * the border and subtract the new border pixels. Afterwards, we update
1060      * parent->rect to contain con. */
1061     DLOG("This is a floating container\n");
1062
1063     Rect bsr = con_border_style_rect(con);
1064     con->rect.x += bsr.x;
1065     con->rect.y += bsr.y;
1066     con->rect.width += bsr.width;
1067     con->rect.height += bsr.height;
1068
1069     /* Change the border style, get new border/decoration values. */
1070     con->border_style = border_style;
1071     bsr = con_border_style_rect(con);
1072     int deco_height =
1073         (con->border_style == BS_NORMAL ? config.font.height + 5 : 0);
1074
1075     con->rect.x -= bsr.x;
1076     con->rect.y -= bsr.y;
1077     con->rect.width -= bsr.width;
1078     con->rect.height -= bsr.height;
1079
1080     Con *parent = con->parent;
1081     parent->rect.x = con->rect.x;
1082     parent->rect.y = con->rect.y - deco_height;
1083     parent->rect.width = con->rect.width;
1084     parent->rect.height = con->rect.height + deco_height;
1085 }
1086
1087 /*
1088  * This function changes the layout of a given container. Use it to handle
1089  * special cases like changing a whole workspace to stacked/tabbed (creates a
1090  * new split container before).
1091  *
1092  */
1093 void con_set_layout(Con *con, int layout) {
1094     DLOG("con_set_layout(%p, %d), con->type = %d\n",
1095          con, layout, con->type);
1096
1097     /* Users can focus workspaces, but not any higher in the hierarchy.
1098      * Focus on the workspace is a special case, since in every other case, the
1099      * user means "change the layout of the parent split container". */
1100     if (con->type != CT_WORKSPACE)
1101         con = con->parent;
1102
1103     /* We fill in last_split_layout when switching to a different layout
1104      * since there are many places in the code that don’t use
1105      * con_set_layout(). */
1106     if (con->layout == L_SPLITH || con->layout == L_SPLITV)
1107         con->last_split_layout = con->layout;
1108
1109     /* When the container type is CT_WORKSPACE, the user wants to change the
1110      * whole workspace into stacked/tabbed mode. To do this and still allow
1111      * intuitive operations (like level-up and then opening a new window), we
1112      * need to create a new split container. */
1113     if (con->type == CT_WORKSPACE &&
1114         (layout == L_STACKED || layout == L_TABBED)) {
1115         if (con_num_children(con) == 0) {
1116             DLOG("Setting workspace_layout to %d\n", layout);
1117             con->workspace_layout = layout;
1118         } else {
1119             DLOG("Creating new split container\n");
1120             /* 1: create a new split container */
1121             Con *new = con_new(NULL, NULL);
1122             new->parent = con;
1123
1124             /* 2: Set the requested layout on the split container and mark it as
1125              * split. */
1126             new->layout = layout;
1127             new->last_split_layout = con->last_split_layout;
1128             new->split = true;
1129
1130             Con *old_focused = TAILQ_FIRST(&(con->focus_head));
1131             if (old_focused == TAILQ_END(&(con->focus_head)))
1132                 old_focused = NULL;
1133
1134             /* 3: move the existing cons of this workspace below the new con */
1135             DLOG("Moving cons\n");
1136             Con *child;
1137             while (!TAILQ_EMPTY(&(con->nodes_head))) {
1138                 child = TAILQ_FIRST(&(con->nodes_head));
1139                 con_detach(child);
1140                 con_attach(child, new, true);
1141             }
1142
1143             /* 4: attach the new split container to the workspace */
1144             DLOG("Attaching new split to ws\n");
1145             con_attach(new, con, false);
1146
1147             if (old_focused)
1148                 con_focus(old_focused);
1149
1150             tree_flatten(croot);
1151         }
1152         return;
1153     }
1154
1155     if (layout == L_DEFAULT) {
1156         /* Special case: the layout formerly known as "default" (in combination
1157          * with an orientation). Since we switched to splith/splitv layouts,
1158          * using the "default" layout (which "only" should happen when using
1159          * legacy configs) is using the last split layout (either splith or
1160          * splitv) in order to still do the same thing.
1161          *
1162          * Starting from v4.6 though, we will nag users about using "layout
1163          * default", and in v4.9 we will remove it entirely (with an
1164          * appropriate i3-migrate-config mechanism). */
1165         con->layout = con->last_split_layout;
1166         /* In case last_split_layout was not initialized… */
1167         if (con->layout == L_DEFAULT)
1168             con->layout = L_SPLITH;
1169     } else {
1170         con->layout = layout;
1171     }
1172 }
1173
1174 /*
1175  * This function toggles the layout of a given container. toggle_mode can be
1176  * either 'default' (toggle only between stacked/tabbed/last_split_layout),
1177  * 'split' (toggle only between splitv/splith) or 'all' (toggle between all
1178  * layouts).
1179  *
1180  */
1181 void con_toggle_layout(Con *con, const char *toggle_mode) {
1182     Con *parent = con;
1183     /* Users can focus workspaces, but not any higher in the hierarchy.
1184      * Focus on the workspace is a special case, since in every other case, the
1185      * user means "change the layout of the parent split container". */
1186     if (con->type != CT_WORKSPACE)
1187         parent = con->parent;
1188     DLOG("con_toggle_layout(%p, %s), parent = %p\n", con, toggle_mode, parent);
1189
1190     if (strcmp(toggle_mode, "split") == 0) {
1191         /* Toggle between splits. When the current layout is not a split
1192          * layout, we just switch back to last_split_layout. Otherwise, we
1193          * change to the opposite split layout. */
1194         if (parent->layout != L_SPLITH && parent->layout != L_SPLITV)
1195             con_set_layout(con, parent->last_split_layout);
1196         else {
1197             if (parent->layout == L_SPLITH)
1198                 con_set_layout(con, L_SPLITV);
1199             else con_set_layout(con, L_SPLITH);
1200         }
1201     } else {
1202         if (parent->layout == L_STACKED)
1203             con_set_layout(con, L_TABBED);
1204         else if (parent->layout == L_TABBED) {
1205             if (strcmp(toggle_mode, "all") == 0)
1206                 con_set_layout(con, L_SPLITH);
1207             else con_set_layout(con, parent->last_split_layout);
1208         } else if (parent->layout == L_SPLITH || parent->layout == L_SPLITV) {
1209             if (strcmp(toggle_mode, "all") == 0) {
1210                 /* When toggling through all modes, we toggle between
1211                  * splith/splitv, whereas normally we just directly jump to
1212                  * stacked. */
1213                 if (parent->layout == L_SPLITH)
1214                     con_set_layout(con, L_SPLITV);
1215                 else con_set_layout(con, L_STACKED);
1216             } else {
1217                 con_set_layout(con, L_STACKED);
1218             }
1219         }
1220     }
1221 }
1222
1223 /*
1224  * Callback which will be called when removing a child from the given con.
1225  * Kills the container if it is empty and replaces it with the child if there
1226  * is exactly one child.
1227  *
1228  */
1229 static void con_on_remove_child(Con *con) {
1230     DLOG("on_remove_child\n");
1231
1232     /* Every container 'above' (in the hierarchy) the workspace content should
1233      * not be closed when the last child was removed */
1234     if (con->type == CT_OUTPUT ||
1235         con->type == CT_ROOT ||
1236         con->type == CT_DOCKAREA) {
1237         DLOG("not handling, type = %d\n", con->type);
1238         return;
1239     }
1240
1241     /* For workspaces, close them only if they're not visible anymore */
1242     if (con->type == CT_WORKSPACE) {
1243         if (TAILQ_EMPTY(&(con->focus_head)) && !workspace_is_visible(con)) {
1244             LOG("Closing old workspace (%p / %s), it is empty\n", con, con->name);
1245             tree_close(con, DONT_KILL_WINDOW, false, false);
1246             ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"empty\"}");
1247         }
1248         return;
1249     }
1250
1251     /* TODO: check if this container would swallow any other client and
1252      * don’t close it automatically. */
1253     int children = con_num_children(con);
1254     if (children == 0) {
1255         DLOG("Container empty, closing\n");
1256         tree_close(con, DONT_KILL_WINDOW, false, false);
1257         return;
1258     }
1259 }
1260
1261 /*
1262  * Determines the minimum size of the given con by looking at its children (for
1263  * split/stacked/tabbed cons). Will be called when resizing floating cons
1264  *
1265  */
1266 Rect con_minimum_size(Con *con) {
1267     DLOG("Determining minimum size for con %p\n", con);
1268
1269     if (con_is_leaf(con)) {
1270         DLOG("leaf node, returning 75x50\n");
1271         return (Rect){ 0, 0, 75, 50 };
1272     }
1273
1274     if (con->type == CT_FLOATING_CON) {
1275         DLOG("floating con\n");
1276         Con *child = TAILQ_FIRST(&(con->nodes_head));
1277         return con_minimum_size(child);
1278     }
1279
1280     if (con->layout == L_STACKED || con->layout == L_TABBED) {
1281         uint32_t max_width = 0, max_height = 0, deco_height = 0;
1282         Con *child;
1283         TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
1284             Rect min = con_minimum_size(child);
1285             deco_height += child->deco_rect.height;
1286             max_width = max(max_width, min.width);
1287             max_height = max(max_height, min.height);
1288         }
1289         DLOG("stacked/tabbed now, returning %d x %d + deco_rect = %d\n",
1290              max_width, max_height, deco_height);
1291         return (Rect){ 0, 0, max_width, max_height + deco_height };
1292     }
1293
1294     /* For horizontal/vertical split containers we sum up the width (h-split)
1295      * or height (v-split) and use the maximum of the height (h-split) or width
1296      * (v-split) as minimum size. */
1297     if (con->split) {
1298         uint32_t width = 0, height = 0;
1299         Con *child;
1300         TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
1301             Rect min = con_minimum_size(child);
1302             if (con->layout == L_SPLITH) {
1303                 width += min.width;
1304                 height = max(height, min.height);
1305             } else {
1306                 height += min.height;
1307                 width = max(width, min.width);
1308             }
1309         }
1310         DLOG("split container, returning width = %d x height = %d\n", width, height);
1311         return (Rect){ 0, 0, width, height };
1312     }
1313
1314     ELOG("Unhandled case, type = %d, layout = %d, split = %d\n",
1315          con->type, con->layout, con->split);
1316     assert(false);
1317 }
1318
1319 /*
1320  * Returns true if changing the focus to con would be allowed considering
1321  * the fullscreen focus constraints. Specifically, if a fullscreen container or
1322  * any of its descendants is focused, this function returns true if and only if
1323  * focusing con would mean that focus would still be visible on screen, i.e.,
1324  * the newly focused container would not be obscured by a fullscreen container.
1325  *
1326  * In the simplest case, if a fullscreen container or any of its descendants is
1327  * fullscreen, this functions returns true if con is the fullscreen container
1328  * itself or any of its descendants, as this means focus wouldn't escape the
1329  * boundaries of the fullscreen container.
1330  *
1331  * In case the fullscreen container is of type CF_OUTPUT, this function returns
1332  * true if con is on a different workspace, as focus wouldn't be obscured by
1333  * the fullscreen container that is constrained to a different workspace.
1334  *
1335  * Note that this same logic can be applied to moving containers. If a
1336  * container can be focused under the fullscreen focus constraints, it can also
1337  * become a parent or sibling to the currently focused container.
1338  *
1339  */
1340 bool con_fullscreen_permits_focusing(Con *con) {
1341     /* No focus, no problem. */
1342     if (!focused)
1343         return true;
1344
1345     /* Find the first fullscreen ascendent. */
1346     Con *fs = focused;
1347     while (fs && fs->fullscreen_mode == CF_NONE)
1348         fs = fs->parent;
1349
1350     /* fs must be non-NULL since the workspace con doesn’t have CF_NONE and
1351      * there always has to be a workspace con in the hierarchy. */
1352     assert(fs != NULL);
1353     /* The most common case is we hit the workspace level. In this
1354      * situation, changing focus is also harmless. */
1355     assert(fs->fullscreen_mode != CF_NONE);
1356     if (fs->type == CT_WORKSPACE)
1357         return true;
1358
1359     /* Allow it if the container itself is the fullscreen container. */
1360     if (con == fs)
1361         return true;
1362
1363     /* If fullscreen is per-output, the focus being in a different workspace is
1364      * sufficient to guarantee that change won't leave fullscreen in bad shape. */
1365     if (fs->fullscreen_mode == CF_OUTPUT &&
1366         con_get_workspace(con) != con_get_workspace(fs)) {
1367             return true;
1368     }
1369
1370     /* Allow it only if the container to be focused is contained within the
1371      * current fullscreen container. */
1372     do {
1373         if (con->parent == fs)
1374             return true;
1375         con = con->parent;
1376     } while (con);
1377
1378     /* Focusing con would hide it behind a fullscreen window, disallow it. */
1379     return false;
1380 }