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