2 * vim:ts=4:sw=4:expandtab
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
15 void render_con(Con *con) {
16 printf("currently rendering node %p / %s / layout %d\n",
17 con, con->name, con->layout);
20 TAILQ_FOREACH(child, &(con->nodes_head), nodes)
22 printf("children: %d, orientation = %d\n", children, con->orientation);
24 /* Copy container rect, subtract container border */
25 /* This is the actually usable space inside this container for clients */
26 Rect rect = con->rect;
37 printf("mapped = true\n");
40 /* if this container contains a window, set the coordinates */
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 */
48 inset->width -= 2 * 2;
51 /* Obey the aspect ratio, if any */
52 if (con->proportional_height != 0 &&
53 con->proportional_width != 0) {
54 DLOG("proportional height = %d, width = %d\n", con->proportional_height, con->proportional_width);
55 double new_height = inset->height + 1;
56 int new_width = inset->width;
58 while (new_height > inset->height) {
59 new_height = ((double)con->proportional_height / con->proportional_width) * new_width;
61 if (new_height > inset->height)
64 /* Center the window */
65 inset->y += ceil(inset->height / 2) - floor(new_height / 2);
66 inset->x += ceil(inset->width / 2) - floor(new_width / 2);
68 inset->height = new_height;
69 inset->width = new_width;
70 DLOG("new_height = %f, new_width = %d\n", new_height, new_width);
73 if (con->height_increment > 1) {
74 int old_height = inset->height;
75 inset->height -= (inset->height - con->base_height) % con->height_increment;
76 DLOG("Lost %d pixel due to client's height_increment (%d px, base_height = %d)\n",
77 old_height - inset->height, con->height_increment, con->base_height);
80 if (con->width_increment > 1) {
81 int old_width = inset->width;
82 inset->width -= (inset->width - con->base_width) % con->width_increment;
83 DLOG("Lost %d pixel due to client's width_increment (%d px, base_width = %d)\n",
84 old_width - inset->width, con->width_increment, con->base_width);
87 DLOG("child will be at %dx%d with size %dx%d\n", inset->x, inset->y, inset->width, inset->height);
90 /* Check for fullscreen nodes */
91 Con *fullscreen = con_get_fullscreen_con(con);
93 LOG("got fs node: %p\n", fullscreen);
94 fullscreen->rect = rect;
95 x_raise_con(fullscreen);
96 render_con(fullscreen);
100 TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
103 if (con->layout == L_DEFAULT) {
104 double percentage = 1.0 / children;
105 if (child->percent > 0.0)
106 percentage = child->percent;
107 printf("child %p / %s requests percentage %f\n",
108 child, child->name, percentage);
110 if (con->orientation == HORIZ) {
113 child->rect.width = percentage * rect.width;
114 child->rect.height = rect.height;
115 x += child->rect.width;
119 child->rect.width = rect.width;
120 child->rect.height = percentage * rect.height;
121 y += child->rect.height;
124 /* first we have the decoration, if this is a leaf node */
125 if (con_is_leaf(child)) {
126 printf("that child is a leaf node, subtracting deco\n");
127 /* TODO: make a function for relative coords? */
128 child->deco_rect.x = child->rect.x - con->rect.x;
129 child->deco_rect.y = child->rect.y - con->rect.y;
132 child->rect.height -= 17;
134 child->deco_rect.width = child->rect.width;
135 child->deco_rect.height = 17;
139 if (con->layout == L_STACKED) {
140 printf("stacked con\n");
143 child->rect.width = rect.width;
144 child->rect.height = rect.height;
146 child->rect.y += (17 * children);
147 child->rect.height -= (17 * children);
149 child->deco_rect.x = x - con->rect.x;
150 child->deco_rect.y = y - con->rect.y + (i * 17);
151 child->deco_rect.width = child->rect.width;
152 child->deco_rect.height = 17;
155 printf("child at (%d, %d) with (%d x %d)\n",
156 child->rect.x, child->rect.y, child->rect.width, child->rect.height);
157 printf("x now %d, y now %d\n", x, y);
163 /* in a stacking container, we ensure the focused client is raised */
164 if (con->layout == L_STACKED) {
165 Con *foc = TAILQ_FIRST(&(con->focus_head));
166 if (foc != TAILQ_END(&(con->focus_head)))
170 TAILQ_FOREACH(child, &(con->floating_head), floating_windows) {
171 LOG("render floating:\n");
172 LOG("floating child at (%d,%d) with %d x %d\n", child->rect.x, child->rect.y, child->rect.width, child->rect.height);
177 printf("-- level up\n");