]> git.sur5r.net Git - i3/i3/blob - src/render.c
943ec895c2429eb28a044be3e3c222a52d23c41c
[i3/i3] / src / render.c
1 /*
2  * vim:ts=4:sw=4:expandtab
3  */
4
5 #include "all.h"
6
7 /*
8  * "Renders" the given container (and its children), meaning that all rects are
9  * updated correctly. Note that this function does not call any xcb_*
10  * functions, so the changes are completely done in memory only (and
11  * side-effect free). As soon as you call x_push_changes(), the changes will be
12  * updated in X11.
13  *
14  */
15 void render_con(Con *con) {
16     printf("currently rendering node %p / %s / layout %d\n",
17             con, con->name, con->layout);
18     int children = 0;
19     Con *child;
20     TAILQ_FOREACH(child, &(con->nodes_head), nodes)
21         children++;
22     printf("children: %d, orientation = %d\n", children, con->orientation);
23
24     /* Copy container rect, subtract container border */
25     /* This is the actually usable space inside this container for clients */
26     Rect rect = con->rect;
27     rect.x += 2;
28     rect.y += 2;
29     rect.width -= 2 * 2;
30     rect.height -= 2 * 2;
31
32     int x = rect.x;
33     int y = rect.y;
34
35     int i = 0;
36
37     printf("mapped = true\n");
38     con->mapped = true;
39
40     /* if this container contains a window, set the coordinates */
41     if (con->window) {
42         /* depending on the border style, the rect of the child window
43          * needs to be smaller */
44         Rect *inset = &(con->window_rect);
45         *inset = (Rect){0, 0, con->rect.width, con->rect.height};
46         /* TODO: different border styles */
47         inset->x += 2;
48         inset->width -= 2 * 2;
49         inset->height -= 2;
50     }
51
52     /* Check for fullscreen nodes */
53     Con *fullscreen = con_get_fullscreen_con(con);
54     if (fullscreen) {
55         LOG("got fs node: %p\n", fullscreen);
56         fullscreen->rect = rect;
57         x_raise_con(fullscreen);
58         render_con(fullscreen);
59         return;
60     }
61
62     TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
63
64         /* default layout */
65         if (con->layout == L_DEFAULT) {
66             double percentage = 1.0 / children;
67             if (child->percent > 0.0)
68                 percentage = child->percent;
69             printf("child %p / %s requests percentage %f\n",
70                     child, child->name, percentage);
71
72             if (con->orientation == HORIZ) {
73                 child->rect.x = x;
74                 child->rect.y = y;
75                 child->rect.width = percentage * rect.width;
76                 child->rect.height = rect.height;
77                 x += child->rect.width;
78             } else {
79                 child->rect.x = x;
80                 child->rect.y = y;
81                 child->rect.width = rect.width;
82                 child->rect.height = percentage * rect.height;
83                 y += child->rect.height;
84             }
85
86             /* first we have the decoration, if this is a leaf node */
87             if (con_is_leaf(child)) {
88                 printf("that child is a leaf node, subtracting deco\n");
89                 /* TODO: make a function for relative coords? */
90                 child->deco_rect.x = child->rect.x - con->rect.x;
91                 child->deco_rect.y = child->rect.y - con->rect.y;
92
93                 child->rect.y += 17;
94                 child->rect.height -= 17;
95
96                 child->deco_rect.width = child->rect.width;
97                 child->deco_rect.height = 17;
98             }
99         }
100
101         if (con->layout == L_STACKED) {
102             printf("stacked con\n");
103             child->rect.x = x;
104             child->rect.y = y;
105             child->rect.width = rect.width;
106             child->rect.height = rect.height;
107
108             child->rect.y += (17 * children);
109             child->rect.height -= (17 * children);
110
111             child->deco_rect.x = x - con->rect.x;
112             child->deco_rect.y = y - con->rect.y + (i * 17);
113             child->deco_rect.width = child->rect.width;
114             child->deco_rect.height = 17;
115         }
116
117         printf("child at (%d, %d) with (%d x %d)\n",
118                 child->rect.x, child->rect.y, child->rect.width, child->rect.height);
119         printf("x now %d, y now %d\n", x, y);
120         x_raise_con(child);
121         render_con(child);
122         i++;
123     }
124
125     /* in a stacking container, we ensure the focused client is raised */
126     if (con->layout == L_STACKED) {
127         Con *foc = TAILQ_FIRST(&(con->focus_head));
128         if (foc != TAILQ_END(&(con->focus_head)))
129             x_raise_con(foc);
130     }
131
132     TAILQ_FOREACH(child, &(con->floating_head), floating_windows) {
133         LOG("render floating:\n");
134         LOG("floating child at (%d,%d) with %d x %d\n", child->rect.x, child->rect.y, child->rect.width, child->rect.height);
135         x_raise_con(child);
136         render_con(child);
137     }
138
139     printf("-- level up\n");
140 }