]> git.sur5r.net Git - i3/i3/blob - src/render.c
Bugfix: Don’t draw borders for fullscreen windows
[i3/i3] / src / render.c
1 /*
2  * vim:ts=4:sw=4:expandtab
3  */
4
5 #include "all.h"
6
7 /* change this to 'true' if you want to have additional borders around every
8  * container (for debugging purposes) */
9 static bool show_debug_borders = false;
10
11 /*
12  * "Renders" the given container (and its children), meaning that all rects are
13  * updated correctly. Note that this function does not call any xcb_*
14  * functions, so the changes are completely done in memory only (and
15  * side-effect free). As soon as you call x_push_changes(), the changes will be
16  * updated in X11.
17  *
18  */
19 void render_con(Con *con, bool render_fullscreen) {
20     printf("currently rendering node %p / %s / layout %d\n",
21             con, con->name, con->layout);
22     int children = con_num_children(con);
23     printf("children: %d, orientation = %d\n", children, con->orientation);
24
25     /* Copy container rect, subtract container border */
26     /* This is the actually usable space inside this container for clients */
27     Rect rect = con->rect;
28
29     /* Display a border if this is a leaf node. For container nodes, we don’t
30      * draw borders (except when in debug mode) */
31     if (show_debug_borders) {
32         rect.x += 2;
33         rect.y += 2;
34         rect.width -= 2 * 2;
35         rect.height -= 2 * 2;
36     }
37
38     int x = rect.x;
39     int y = rect.y;
40
41     int i = 0;
42
43     printf("mapped = true\n");
44     con->mapped = true;
45
46     /* if this container contains a window, set the coordinates */
47     if (con->window) {
48         /* depending on the border style, the rect of the child window
49          * needs to be smaller */
50         Rect *inset = &(con->window_rect);
51         *inset = (Rect){0, 0, con->rect.width, con->rect.height};
52         if (!render_fullscreen)
53             *inset = rect_add(*inset, con_border_style_rect(con));
54
55         /* Obey x11 border */
56         inset->width -= (2 * con->border_width);
57         inset->height -= (2 * con->border_width);
58
59         /* Obey the aspect ratio, if any */
60         if (con->proportional_height != 0 &&
61             con->proportional_width != 0) {
62             DLOG("proportional height = %d, width = %d\n", con->proportional_height, con->proportional_width);
63             double new_height = inset->height + 1;
64             int new_width = inset->width;
65
66             while (new_height > inset->height) {
67                 new_height = ((double)con->proportional_height / con->proportional_width) * new_width;
68
69                 if (new_height > inset->height)
70                     new_width--;
71             }
72             /* Center the window */
73             inset->y += ceil(inset->height / 2) - floor(new_height / 2);
74             inset->x += ceil(inset->width / 2) - floor(new_width / 2);
75
76             inset->height = new_height;
77             inset->width = new_width;
78             DLOG("new_height = %f, new_width = %d\n", new_height, new_width);
79         }
80
81         if (con->height_increment > 1) {
82             int old_height = inset->height;
83             inset->height -= (inset->height - con->base_height) % con->height_increment;
84             DLOG("Lost %d pixel due to client's height_increment (%d px, base_height = %d)\n",
85                 old_height - inset->height, con->height_increment, con->base_height);
86         }
87
88         if (con->width_increment > 1) {
89             int old_width = inset->width;
90             inset->width -= (inset->width - con->base_width) % con->width_increment;
91             DLOG("Lost %d pixel due to client's width_increment (%d px, base_width = %d)\n",
92                 old_width - inset->width, con->width_increment, con->base_width);
93         }
94
95         DLOG("child will be at %dx%d with size %dx%d\n", inset->x, inset->y, inset->width, inset->height);
96     }
97
98     /* Check for fullscreen nodes */
99     Con *fullscreen = con_get_fullscreen_con(con);
100     if (fullscreen) {
101         LOG("got fs node: %p\n", fullscreen);
102         fullscreen->rect = rect;
103         x_raise_con(fullscreen);
104         render_con(fullscreen, true);
105         return;
106     }
107
108     /* find the height for the decorations */
109     i3Font *font = load_font(conn, config.font);
110     int deco_height = font->height + 5;
111
112     Con *child;
113     TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
114
115         /* default layout */
116         if (con->layout == L_DEFAULT) {
117             double percentage = 1.0 / children;
118             if (child->percent > 0.0)
119                 percentage = child->percent;
120             printf("child %p / %s requests percentage %f\n",
121                     child, child->name, percentage);
122
123             if (con->orientation == HORIZ) {
124                 child->rect.x = x;
125                 child->rect.y = y;
126                 child->rect.width = percentage * rect.width;
127                 child->rect.height = rect.height;
128                 x += child->rect.width;
129             } else {
130                 child->rect.x = x;
131                 child->rect.y = y;
132                 child->rect.width = rect.width;
133                 child->rect.height = percentage * rect.height;
134                 y += child->rect.height;
135             }
136
137             /* first we have the decoration, if this is a leaf node */
138             if (con_is_leaf(child) && child->border_style == BS_NORMAL) {
139                 printf("that child is a leaf node, subtracting deco\n");
140                 /* TODO: make a function for relative coords? */
141                 child->deco_rect.x = child->rect.x - con->rect.x;
142                 child->deco_rect.y = child->rect.y - con->rect.y;
143
144                 child->rect.y += deco_height;
145                 child->rect.height -= deco_height;
146
147                 child->deco_rect.width = child->rect.width;
148                 child->deco_rect.height = deco_height;
149             }
150         }
151
152         /* stacked layout */
153         else if (con->layout == L_STACKED) {
154             printf("stacked con\n");
155             child->rect.x = x;
156             child->rect.y = y;
157             child->rect.width = rect.width;
158             child->rect.height = rect.height;
159
160             child->rect.y += (deco_height * children);
161             child->rect.height -= (deco_height * children);
162
163             child->deco_rect.x = x - con->rect.x;
164             child->deco_rect.y = y - con->rect.y + (i * deco_height);
165             child->deco_rect.width = child->rect.width;
166             child->deco_rect.height = deco_height;
167         }
168
169         /* tabbed layout */
170         else if (con->layout == L_TABBED) {
171             printf("tabbed con\n");
172             child->rect.x = x;
173             child->rect.y = y;
174             child->rect.width = rect.width;
175             child->rect.height = rect.height;
176
177             child->deco_rect.width = child->rect.width / children;
178             child->deco_rect.height = deco_height;
179             child->deco_rect.x = x - con->rect.x + i * child->deco_rect.width;
180             child->deco_rect.y = y - con->rect.y;
181
182             child->rect.y += deco_height;
183             child->rect.height -= deco_height;
184         }
185
186         printf("child at (%d, %d) with (%d x %d)\n",
187                 child->rect.x, child->rect.y, child->rect.width, child->rect.height);
188         printf("x now %d, y now %d\n", x, y);
189         x_raise_con(child);
190         render_con(child, false);
191         i++;
192     }
193
194     /* in a stacking or tabbed container, we ensure the focused client is raised */
195     if (con->layout == L_STACKED || con->layout == L_TABBED) {
196         Con *foc = TAILQ_FIRST(&(con->focus_head));
197         if (foc != TAILQ_END(&(con->focus_head))) {
198             LOG("con %p is stacking, raising %p\n", con, foc);
199             x_raise_con(foc);
200             /* by rendering the stacked container again, we handle the case
201              * that we have a non-leaf-container inside the stack. */
202             render_con(foc, false);
203         }
204     }
205
206     TAILQ_FOREACH(child, &(con->floating_head), floating_windows) {
207         LOG("render floating:\n");
208         LOG("floating child at (%d,%d) with %d x %d\n", child->rect.x, child->rect.y, child->rect.width, child->rect.height);
209         x_raise_con(child);
210         render_con(child, false);
211     }
212
213     printf("-- level up\n");
214 }