2 * vim:ts=4:sw=4:expandtab
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;
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
19 void render_con(Con *con) {
20 printf("currently rendering node %p / %s / layout %d\n",
21 con, con->name, con->layout);
24 TAILQ_FOREACH(child, &(con->nodes_head), nodes)
26 printf("children: %d, orientation = %d\n", children, con->orientation);
28 /* Copy container rect, subtract container border */
29 /* This is the actually usable space inside this container for clients */
30 Rect rect = con->rect;
32 /* Display a border if this is a leaf node. For container nodes, we don’t
33 * draw borders (except when in debug mode) */
34 if (show_debug_borders) {
46 printf("mapped = true\n");
49 /* if this container contains a window, set the coordinates */
51 /* depending on the border style, the rect of the child window
52 * needs to be smaller */
53 Rect *inset = &(con->window_rect);
54 *inset = (Rect){0, 0, con->rect.width, con->rect.height};
55 /* TODO: different border styles */
57 inset->width -= 2 * 2;
60 /* Obey the aspect ratio, if any */
61 if (con->proportional_height != 0 &&
62 con->proportional_width != 0) {
63 DLOG("proportional height = %d, width = %d\n", con->proportional_height, con->proportional_width);
64 double new_height = inset->height + 1;
65 int new_width = inset->width;
67 while (new_height > inset->height) {
68 new_height = ((double)con->proportional_height / con->proportional_width) * new_width;
70 if (new_height > inset->height)
73 /* Center the window */
74 inset->y += ceil(inset->height / 2) - floor(new_height / 2);
75 inset->x += ceil(inset->width / 2) - floor(new_width / 2);
77 inset->height = new_height;
78 inset->width = new_width;
79 DLOG("new_height = %f, new_width = %d\n", new_height, new_width);
82 if (con->height_increment > 1) {
83 int old_height = inset->height;
84 inset->height -= (inset->height - con->base_height) % con->height_increment;
85 DLOG("Lost %d pixel due to client's height_increment (%d px, base_height = %d)\n",
86 old_height - inset->height, con->height_increment, con->base_height);
89 if (con->width_increment > 1) {
90 int old_width = inset->width;
91 inset->width -= (inset->width - con->base_width) % con->width_increment;
92 DLOG("Lost %d pixel due to client's width_increment (%d px, base_width = %d)\n",
93 old_width - inset->width, con->width_increment, con->base_width);
96 DLOG("child will be at %dx%d with size %dx%d\n", inset->x, inset->y, inset->width, inset->height);
99 /* Check for fullscreen nodes */
100 Con *fullscreen = con_get_fullscreen_con(con);
102 LOG("got fs node: %p\n", fullscreen);
103 fullscreen->rect = rect;
104 x_raise_con(fullscreen);
105 render_con(fullscreen);
109 TAILQ_FOREACH(child, &(con->nodes_head), nodes) {
112 if (con->layout == L_DEFAULT) {
113 double percentage = 1.0 / children;
114 if (child->percent > 0.0)
115 percentage = child->percent;
116 printf("child %p / %s requests percentage %f\n",
117 child, child->name, percentage);
119 if (con->orientation == HORIZ) {
122 child->rect.width = percentage * rect.width;
123 child->rect.height = rect.height;
124 x += child->rect.width;
128 child->rect.width = rect.width;
129 child->rect.height = percentage * rect.height;
130 y += child->rect.height;
133 /* first we have the decoration, if this is a leaf node */
134 if (con_is_leaf(child)) {
135 printf("that child is a leaf node, subtracting deco\n");
136 /* TODO: make a function for relative coords? */
137 child->deco_rect.x = child->rect.x - con->rect.x;
138 child->deco_rect.y = child->rect.y - con->rect.y;
141 child->rect.height -= 17;
143 child->deco_rect.width = child->rect.width;
144 child->deco_rect.height = 17;
148 if (con->layout == L_STACKED) {
149 printf("stacked con\n");
152 child->rect.width = rect.width;
153 child->rect.height = rect.height;
155 child->rect.y += (17 * children);
156 child->rect.height -= (17 * children);
158 child->deco_rect.x = x - con->rect.x;
159 child->deco_rect.y = y - con->rect.y + (i * 17);
160 child->deco_rect.width = child->rect.width;
161 child->deco_rect.height = 17;
164 printf("child at (%d, %d) with (%d x %d)\n",
165 child->rect.x, child->rect.y, child->rect.width, child->rect.height);
166 printf("x now %d, y now %d\n", x, y);
172 /* in a stacking container, we ensure the focused client is raised */
173 if (con->layout == L_STACKED) {
174 Con *foc = TAILQ_FIRST(&(con->focus_head));
175 if (foc != TAILQ_END(&(con->focus_head)))
179 TAILQ_FOREACH(child, &(con->floating_head), floating_windows) {
180 LOG("render floating:\n");
181 LOG("floating child at (%d,%d) with %d x %d\n", child->rect.x, child->rect.y, child->rect.width, child->rect.height);
186 printf("-- level up\n");