]> git.sur5r.net Git - i3/i3/blob - src/render.c
first step of the big refactoring ("tree" branch).
[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     /* Check for fullscreen nodes */
41     Con *fullscreen = con_get_fullscreen_con(con);
42     if (fullscreen) {
43         LOG("got fs node: %p\n", fullscreen);
44         fullscreen->rect = rect;
45         render_con(fullscreen);
46         return;
47     }
48
49
50     TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
51
52         /* default layout */
53         if (con->layout == L_DEFAULT) {
54             double percentage = 1.0 / children;
55             if (child->percent > 0.0)
56                 percentage = child->percent;
57             printf("child %p / %s requests percentage %f\n",
58                     child, child->name, percentage);
59
60             if (con->orientation == HORIZ) {
61                 child->rect.x = x;
62                 child->rect.y = y;
63                 child->rect.width = percentage * rect.width;
64                 child->rect.height = rect.height;
65                 x += child->rect.width;
66             } else {
67                 child->rect.x = x;
68                 child->rect.y = y;
69                 child->rect.width = rect.width;
70                 child->rect.height = percentage * rect.height;
71                 y += child->rect.height;
72             }
73
74             /* first we have the decoration, if this is a leaf node */
75             if (con_is_leaf(child)) {
76                 printf("that child is a leaf node, subtracting deco\n");
77                 /* TODO: make a function for relative coords? */
78                 child->deco_rect.x = child->rect.x - con->rect.x;
79                 child->deco_rect.y = child->rect.y - con->rect.y;
80
81                 child->rect.y += 17;
82                 child->rect.height -= 17;
83
84                 child->deco_rect.width = child->rect.width;
85                 child->deco_rect.height = 17;
86             }
87         }
88
89         if (con->layout == L_STACKED) {
90             printf("stacked con\n");
91             child->rect.x = x;
92             child->rect.y = y;
93             child->rect.width = rect.width;
94             child->rect.height = rect.height;
95
96             child->rect.y += (17 * children);
97             child->rect.height -= (17 * children);
98
99             child->deco_rect.x = x - con->rect.x;
100             child->deco_rect.y = y - con->rect.y + (i * 17);
101             child->deco_rect.width = child->rect.width;
102             child->deco_rect.height = 17;
103         }
104
105         printf("child at (%d, %d) with (%d x %d)\n",
106                 child->rect.x, child->rect.y, child->rect.width, child->rect.height);
107         printf("x now %d, y now %d\n", x, y);
108         if (child->window) {
109             /* depending on the border style, the rect of the child window
110              * needs to be smaller */
111             Rect *inset = &(child->window_rect);
112             *inset = (Rect){0, 0, child->rect.width, child->rect.height};
113             /* TODO: different border styles */
114             inset->x += 2;
115             inset->width -= 2 * 2;
116             inset->height -= 2;
117         }
118         x_raise_con(child);
119         render_con(child);
120         i++;
121     }
122
123     /* in a stacking container, we ensure the focused client is raised */
124     if (con->layout == L_STACKED) {
125         Con *foc = TAILQ_FIRST(&(con->focus_head));
126         x_raise_con(foc);
127     }
128
129     TAILQ_FOREACH(child, &(con->floating_head), floating_windows) {
130         LOG("render floating:\n");
131         LOG("floating child at (%d,%d) with %d x %d\n", child->rect.x, child->rect.y, child->rect.width, child->rect.height);
132         x_raise_con(child);
133         render_con(child);
134     }
135
136     printf("-- level up\n");
137 }