i3
gaps.c
Go to the documentation of this file.
1/*
2 * vim:ts=4:sw=4:expandtab
3 *
4 * i3 - an improved tiling window manager
5 * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
6 *
7 * gaps.c: gaps logic: whether to display gaps at all, and how big
8 * they should be.
9 *
10 */
11#include "all.h"
12
17 Con *workspace = con_get_workspace(con);
18 if (workspace == NULL) {
19 return (gaps_t){0, 0, 0, 0, 0};
20 }
21
22 bool one_child = con_num_visible_children(workspace) <= 1 ||
23 (con_num_children(workspace) == 1 &&
24 (TAILQ_FIRST(&(workspace->nodes_head))->layout == L_TABBED ||
25 TAILQ_FIRST(&(workspace->nodes_head))->layout == L_STACKED));
26
27 if (config.smart_gaps == SMART_GAPS_ON && one_child) {
28 return (gaps_t){0, 0, 0, 0, 0};
29 }
30
31 gaps_t gaps = {
32 .inner = (workspace->gaps.inner + config.gaps.inner),
33 .top = 0,
34 .right = 0,
35 .bottom = 0,
36 .left = 0};
37
38 if (config.smart_gaps != SMART_GAPS_INVERSE_OUTER || one_child) {
39 gaps.top = workspace->gaps.top + config.gaps.top;
40 gaps.right = workspace->gaps.right + config.gaps.right;
41 gaps.bottom = workspace->gaps.bottom + config.gaps.bottom;
42 gaps.left = workspace->gaps.left + config.gaps.left;
43 }
44
45 return gaps;
46}
47
48/*
49 * Decides whether the container should be inset.
50 */
51bool gaps_should_inset_con(Con *con, int children) {
52 /* No parent? None of the conditionals below can be true. */
53 if (con->parent == NULL) {
54 return false;
55 }
56
57 /* Floating split containers should never have gaps inside them. */
58 if (con_inside_floating(con)) {
59 return false;
60 }
61
62 const bool leaf_or_stacked_tabbed =
63 con_is_leaf(con) ||
64 (con->layout == L_STACKED || con->layout == L_TABBED);
65
66 /* Inset direct children of the workspace that are leaf containers or
67 stacked/tabbed containers. */
68 if (leaf_or_stacked_tabbed &&
69 con->parent->type == CT_WORKSPACE) {
70 return true;
71 }
72
73 /* Inset direct children of vertical or horizontal split containers at any
74 depth in the tree. Do not inset as soon as any parent is a stacked or
75 tabbed container, to avoid double insets. */
76 if (leaf_or_stacked_tabbed &&
78 con->parent->type == CT_CON &&
79 (con->parent->layout == L_SPLITH ||
80 con->parent->layout == L_SPLITV)) {
81 return true;
82 }
83
84 return false;
85}
86
87/*
88 * Returns whether the given container has an adjacent container in the
89 * specified direction. In other words, this returns true if and only if
90 * the container is not touching the edge of the screen in that direction.
91 */
93 Con *workspace = con_get_workspace(con);
94 Con *fullscreen = con_get_fullscreen_con(workspace, CF_GLOBAL);
95 if (fullscreen == NULL) {
96 fullscreen = con_get_fullscreen_con(workspace, CF_OUTPUT);
97 }
98
99 /* If this container is fullscreen by itself, there's no adjacent container. */
100 if (con == fullscreen) {
101 return false;
102 }
103
104 Con *first = con;
105 Con *second = NULL;
106 bool found_neighbor = resize_find_tiling_participants(&first, &second, direction, false);
107 if (!found_neighbor) {
108 return false;
109 }
110
111 /* If we have an adjacent container and nothing is fullscreen, we consider it. */
112 if (fullscreen == NULL) {
113 return true;
114 }
115
116 /* For fullscreen containers, only consider the adjacent container if it is also fullscreen. */
117 return con_has_parent(con, fullscreen) && con_has_parent(second, fullscreen);
118}
119
120/*
121 * Returns the configured gaps for this workspace based on the workspace name,
122 * number, and configured workspace gap assignments.
123 */
125 gaps_t gaps = (gaps_t){0, 0, 0, 0, 0};
126 gaps_mask_t mask = 0;
127 struct Workspace_Assignment *assignment;
129 if (strcmp(assignment->name, ws->name) == 0) {
130 gaps = assignment->gaps;
131 mask = assignment->gaps_mask;
132 break;
133 } else if (ws->num != -1 && name_is_digits(assignment->name) && ws_name_to_number(assignment->name) == ws->num) {
134 gaps = assignment->gaps;
135 mask = assignment->gaps_mask;
136 }
137 }
138 if (mask == 0) {
139 return gaps;
140 }
141
142 if (mask & GAPS_INNER) {
144 }
145 if (mask & GAPS_TOP) {
147 }
148 if (mask & GAPS_RIGHT) {
150 }
151 if (mask & GAPS_BOTTOM) {
153 }
154 if (mask & GAPS_LEFT) {
156 }
157
158 return gaps;
159}
160
161/*
162 * Re-applies all workspace gap assignments to existing workspaces after
163 * reloading the configuration file.
164 *
165 */
167 Con *output, *workspace = NULL;
168 TAILQ_FOREACH (output, &(croot->nodes_head), nodes) {
169 Con *content = output_get_content(output);
170 TAILQ_FOREACH (workspace, &(content->nodes_head), nodes) {
171 DLOG("updating gap assignments for workspace %s\n", workspace->name);
172 workspace->gaps = gaps_for_workspace(workspace);
173 }
174 }
175}
Con * con_get_fullscreen_con(Con *con, fullscreen_mode_t fullscreen_mode)
Returns the first fullscreen node below this node.
Definition con.c:599
bool con_inside_stacked_or_tabbed(Con *con)
Returns true if the container is within any stacked/tabbed split container.
Definition con.c:2752
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Definition con.c:547
int con_num_visible_children(Con *con)
Returns the number of visible non-floating children of this container.
Definition con.c:1091
Con * con_inside_floating(Con *con)
Checks if the given container is either floating or inside some floating container.
Definition con.c:696
bool con_is_leaf(Con *con)
Returns true when this node is a leaf node (has no children)
Definition con.c:366
int con_num_children(Con *con)
Returns the number of children of this container.
Definition con.c:1075
bool con_has_parent(Con *con, Con *parent)
Checks if the container has the given parent as an actual parent.
Definition con.c:734
Config config
Definition config.c:19
void gaps_reapply_workspace_assignments(void)
Re-applies all workspace gap assignments to existing workspaces after reloading the configuration fil...
Definition gaps.c:166
gaps_t calculate_effective_gaps(Con *con)
Calculates the effective gap sizes for a container.
Definition gaps.c:16
bool gaps_has_adjacent_container(Con *con, direction_t direction)
Definition gaps.c:92
bool gaps_should_inset_con(Con *con, int children)
Definition gaps.c:51
gaps_t gaps_for_workspace(Con *ws)
Returns the configured gaps for this workspace based on the workspace name, number,...
Definition gaps.c:124
Con * output_get_content(Con *output)
Returns the output container below the given output container.
Definition output.c:16
bool resize_find_tiling_participants(Con **current, Con **other, direction_t direction, bool both_sides)
Definition resize.c:72
struct Con * croot
Definition tree.c:12
int ws_name_to_number(const char *name)
Parses the workspace name as a number.
Definition util.c:111
struct ws_assignments_head ws_assignments
Definition main.c:101
@ SMART_GAPS_INVERSE_OUTER
Definition data.h:86
@ SMART_GAPS_ON
Definition data.h:85
gaps_mask_t
Definition data.h:154
@ GAPS_LEFT
Definition data.h:159
@ GAPS_RIGHT
Definition data.h:157
@ GAPS_INNER
Definition data.h:155
@ GAPS_BOTTOM
Definition data.h:158
@ GAPS_TOP
Definition data.h:156
@ L_STACKED
Definition data.h:103
@ L_TABBED
Definition data.h:104
@ L_SPLITH
Definition data.h:108
@ L_SPLITV
Definition data.h:107
@ CF_OUTPUT
Definition data.h:630
@ CF_GLOBAL
Definition data.h:631
struct gaps_t gaps_t
Definition data.h:50
direction_t
Definition data.h:56
#define DLOG(fmt,...)
Definition libi3.h:105
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:347
#define TAILQ_FIRST(head)
Definition queue.h:336
gaps_t gaps
smart_gaps_t smart_gaps
Definition data.h:146
int inner
Definition data.h:147
int left
Definition data.h:151
int right
Definition data.h:149
int top
Definition data.h:148
int bottom
Definition data.h:150
Stores which workspace (by name or number) goes to which output and its gaps config.
Definition data.h:235
gaps_mask_t gaps_mask
Definition data.h:239
A 'Con' represents everything from the X11 root window down to a single X11 window.
Definition data.h:643
struct Con * parent
Definition data.h:678
enum Con::@18 type
gaps_t gaps
Only applicable for containers of type CT_WORKSPACE.
Definition data.h:676
layout_t layout
Definition data.h:755
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
Definition data.h:673
char * name
Definition data.h:692