- if (n == NULL)
- return;
-
- n->rectangle = rect;
-
- if (is_leaf(n)) {
-
- if ((borderless_monocle && is_tiled(n->client) && d->layout == LAYOUT_MONOCLE)
- || n->client->fullscreen)
- n->client->border_width = 0;
- else
- n->client->border_width = d->border_width;
-
- xcb_rectangle_t r;
- if (!n->client->fullscreen) {
- if (!n->client->floating) {
- if (n->client->pseudo_tiled) {
- /* pseudo-tiled clients */
- r = n->client->floating_rectangle;
- center_rectangle(&r, rect);
- } else {
- /* tiled clients */
- r = rect;
- int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap);
- int bleed = wg + 2 * n->client->border_width;
- r.width = (bleed < r.width ? r.width - bleed : 1);
- r.height = (bleed < r.height ? r.height - bleed : 1);
- }
- n->client->tiled_rectangle = r;
- } else {
- /* floating clients */
- r = n->client->floating_rectangle;
- }
- } else {
- /* fullscreen clients */
- r = m->rectangle;
- }
-
- window_move_resize(n->client->window, r.x, r.y, r.width, r.height);
- window_border_width(n->client->window, n->client->border_width);
- window_draw_border(n, d->focus == n, m == mon);
-
- } else {
- xcb_rectangle_t first_rect;
- xcb_rectangle_t second_rect;
-
- if (d->layout == LAYOUT_MONOCLE || n->first_child->vacant || n->second_child->vacant) {
- first_rect = second_rect = rect;
- } else {
- unsigned int fence;
- if (n->split_type == TYPE_VERTICAL) {
- fence = rect.width * n->split_ratio;
- first_rect = (xcb_rectangle_t) {rect.x, rect.y, fence, rect.height};
- second_rect = (xcb_rectangle_t) {rect.x + fence, rect.y, rect.width - fence, rect.height};
- } else {
- fence = rect.height * n->split_ratio;
- first_rect = (xcb_rectangle_t) {rect.x, rect.y, rect.width, fence};
- second_rect = (xcb_rectangle_t) {rect.x, rect.y + fence, rect.width, rect.height - fence};
- }
- }
-
- apply_layout(m, d, n->first_child, first_rect, root_rect);
- apply_layout(m, d, n->second_child, second_rect, root_rect);
- }
-}
-
-void insert_node(monitor_t *m, desktop_t *d, node_t *n, node_t *f)
-{
- if (d == NULL || n == NULL)
- return;
-
- PRINTF("insert node %X\n", n->client->window);
-
- /* n: new leaf node */
- /* c: new container node */
- /* f: focus or insertion anchor */
- /* p: parent of focus */
- /* g: grand parent of focus */
-
- if (f == NULL)
- f = d->root;
-
- if (f == NULL) {
- d->root = n;
- } else {
- node_t *c = make_node();
- node_t *p = f->parent;
- if (p != NULL && f->split_mode == MODE_AUTOMATIC
- && (p->first_child->vacant || p->second_child->vacant)) {
- f = p;
- p = f->parent;
- }
- if (((f->client != NULL && f->client->private) || (p != NULL && p->privacy_level > 0))
- && f->split_mode == MODE_AUTOMATIC) {
- node_t *closest = NULL;
- node_t *public = NULL;
- closest_public(d, f, &closest, &public);
- if (public != NULL) {
- f = public;
- p = f->parent;
- } else {
- if (closest != NULL) {
- f = closest;
- p = f->parent;
- }
- f->split_mode = MODE_MANUAL;
- xcb_rectangle_t rect = f->client->tiled_rectangle;
- f->split_dir = (rect.width >= rect.height ? DIR_LEFT : DIR_UP);
- if (f->client->private) {
- get_opposite(f->split_dir, &f->split_dir);
- update_privacy_level(f, false);
- }
- }
- }
- n->parent = c;
- c->birth_rotation = f->birth_rotation;
- switch (f->split_mode) {
- case MODE_AUTOMATIC:
- if (p == NULL) {
- c->first_child = n;
- c->second_child = f;
- if (m->rectangle.width > m->rectangle.height)
- c->split_type = TYPE_VERTICAL;
- else
- c->split_type = TYPE_HORIZONTAL;
- f->parent = c;
- d->root = c;
- } else {
- node_t *g = p->parent;
- c->parent = g;
- if (g != NULL) {
- if (is_first_child(p))
- g->first_child = c;
- else
- g->second_child = c;
- } else {
- d->root = c;
- }
- c->split_type = p->split_type;
- c->split_ratio = p->split_ratio;
- p->parent = c;
- int rot;
- if (is_first_child(f)) {
- c->first_child = n;
- c->second_child = p;
- rot = 90;
- } else {
- c->first_child = p;
- c->second_child = n;
- rot = 270;
- }
- if (!is_floating(n->client))
- rotate_tree(p, rot);
- n->birth_rotation = rot;
- }
- break;
- case MODE_MANUAL:
- if (p != NULL) {
- if (is_first_child(f))
- p->first_child = c;
- else
- p->second_child = c;
- }
- c->split_ratio = f->split_ratio;
- c->parent = p;
- f->parent = c;
- f->birth_rotation = 0;
- switch (f->split_dir) {
- case DIR_LEFT:
- c->split_type = TYPE_VERTICAL;
- c->first_child = n;
- c->second_child = f;
- break;
- case DIR_RIGHT:
- c->split_type = TYPE_VERTICAL;
- c->first_child = f;
- c->second_child = n;
- break;
- case DIR_UP:
- c->split_type = TYPE_HORIZONTAL;
- c->first_child = n;
- c->second_child = f;
- break;
- case DIR_DOWN:
- c->split_type = TYPE_HORIZONTAL;
- c->first_child = f;
- c->second_child = n;
- break;
- }
- if (d->root == f)
- d->root = c;
- f->split_mode = MODE_AUTOMATIC;
- break;
- }
- if (f->vacant)
- update_vacant_state(f->parent);
- if (f->client != NULL && f->client->private)
- update_privacy_level(f, true);
- }
- if (n->client->private)
- update_privacy_level(n, true);
- if (d->focus == NULL)
- d->focus = n;
- if (n->client->sticky)
- m->num_sticky++;
- put_status();
-}
-
-void pseudo_focus(monitor_t *m, desktop_t *d, node_t *n)
-{
- if (n != NULL) {
- stack(n, STACK_ABOVE);
- if (d->focus != n) {
- window_draw_border(d->focus, false, m == mon);
- window_draw_border(n, true, m == mon);
- }
- }
- d->focus = n;
-}
-
-void focus_node(monitor_t *m, desktop_t *d, node_t *n)
-{
- if (mon->desk != d || n == NULL)
- clear_input_focus();
-
- if (m->num_sticky > 0 && d != m->desk) {
- node_t *a = first_extrema(m->desk->root);
- sticky_still = false;
- while (a != NULL) {
- node_t *b = next_leaf(a, m->desk->root);
- if (a->client->sticky)
- transfer_node(m, m->desk, a, m, d, d->focus);
- a = b;
- }
- sticky_still = true;
- if (n == NULL && d->focus != NULL)
- n = d->focus;
- }
-
- if (n != NULL && d->focus != NULL && n != d->focus && d->focus->client->fullscreen) {
- set_fullscreen(d->focus, false);
- arrange(m, d);
- }
-
- if (mon != m) {
- for (desktop_t *cd = mon->desk_head; cd != NULL; cd = cd->next)
- window_draw_border(cd->focus, true, false);
- for (desktop_t *cd = m->desk_head; cd != NULL; cd = cd->next)
- if (cd != d)
- window_draw_border(cd->focus, true, true);
- if (d->focus == n)
- window_draw_border(n, true, true);
- }
-
- if (d->focus != n) {
- window_draw_border(d->focus, false, true);
- window_draw_border(n, true, true);
- }
-
- focus_desktop(m, d);
-
- d->focus = n;
-
- if (n == NULL) {
- history_add(m, d, NULL);
- ewmh_update_active_window();
- return;
- } else {
- stack(n, STACK_ABOVE);
- }
-
- PRINTF("focus node %X\n", n->client->window);
-
- n->client->urgent = false;
-
- history_add(m, d, n);
- set_input_focus(n);
-
- if (focus_follows_pointer) {
- xcb_window_t win = XCB_NONE;
- query_pointer(&win, NULL);
- if (win != n->client->window)
- enable_motion_recorder();
- else
- disable_motion_recorder();
- }
-
- ewmh_update_active_window();
-}
-
-void update_current(void)
-{
- focus_node(mon, mon->desk, mon->desk->focus);
-}
-
-node_t *make_node(void)
-{
- node_t *n = malloc(sizeof(node_t));
- n->parent = n->first_child = n->second_child = NULL;
- n->split_ratio = split_ratio;
- n->split_mode = MODE_AUTOMATIC;
- n->split_type = TYPE_VERTICAL;
- n->birth_rotation = 0;
- n->privacy_level = 0;
- n->client = NULL;
- n->vacant = false;
- return n;
-}
-
-client_t *make_client(xcb_window_t win)
-{
- client_t *c = malloc(sizeof(client_t));
- c->window = win;
- snprintf(c->class_name, sizeof(c->class_name), "%s", MISSING_VALUE);
- snprintf(c->instance_name, sizeof(c->instance_name), "%s", MISSING_VALUE);
- c->border_width = BORDER_WIDTH;
- c->pseudo_tiled = c->floating = c->fullscreen = false;
- c->locked = c->sticky = c->urgent = c->private = c->icccm_focus = false;
- xcb_icccm_get_wm_protocols_reply_t protocols;
- if (xcb_icccm_get_wm_protocols_reply(dpy, xcb_icccm_get_wm_protocols(dpy, win, ewmh->WM_PROTOCOLS), &protocols, NULL) == 1) {
- if (has_proto(WM_TAKE_FOCUS, &protocols))
- c->icccm_focus = true;
- xcb_icccm_get_wm_protocols_reply_wipe(&protocols);
- }
- c->num_states = 0;
- xcb_ewmh_get_atoms_reply_t wm_state;
- if (xcb_ewmh_get_wm_state_reply(ewmh, xcb_ewmh_get_wm_state(ewmh, win), &wm_state, NULL) == 1) {
- for (unsigned int i = 0; i < wm_state.atoms_len && i < MAX_STATE; i++)
- ewmh_wm_state_add(c, wm_state.atoms[i]);
- xcb_ewmh_get_atoms_reply_wipe(&wm_state);
- }
- return c;
+ if (n == NULL) {
+ return;
+ }
+
+ n->rectangle = rect;
+
+ if (pointer_follows_focus && mon->desk->focus == n) {
+ xcb_rectangle_t r = rect;
+ r.width -= d->window_gap;
+ r.height -= d->window_gap;
+ center_pointer(r);
+ }
+
+ if (n->presel != NULL) {
+ draw_presel_feedback(m, d, n);
+ }
+
+ if (is_leaf(n)) {
+
+ if (n->client == NULL) {
+ return;
+ }
+
+ unsigned int bw;
+ if ((borderless_monocle && n->client->state == STATE_TILED && d->layout == LAYOUT_MONOCLE)
+ || n->client->state == STATE_FULLSCREEN) {
+ bw = 0;
+ } else {
+ bw = n->client->border_width;
+ }
+
+ xcb_rectangle_t r;
+ xcb_rectangle_t cr = get_window_rectangle(n);
+ client_state_t s = n->client->state;
+ if (s == STATE_TILED || s == STATE_PSEUDO_TILED) {
+ int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap);
+ /* tiled clients */
+ if (s == STATE_TILED) {
+ r = rect;
+ int bleed = wg + 2 * bw;
+ r.width = (bleed < r.width ? r.width - bleed : 1);
+ r.height = (bleed < r.height ? r.height - bleed : 1);
+ /* pseudo-tiled clients */
+ } else {
+ r = n->client->floating_rectangle;
+ if (center_pseudo_tiled) {
+ r.x = rect.x - bw + (rect.width - wg - r.width) / 2;
+ r.y = rect.y - bw + (rect.height - wg - r.height) / 2;
+ } else {
+ r.x = rect.x;
+ r.y = rect.y;
+ }
+ }
+ n->client->tiled_rectangle = r;
+ /* floating clients */
+ } else if (s == STATE_FLOATING) {
+ r = n->client->floating_rectangle;
+ /* fullscreen clients */
+ } else {
+ r = m->rectangle;
+ n->client->tiled_rectangle = r;
+ }
+
+ apply_size_hints(n->client, &r.width, &r.height);
+
+ if (!rect_eq(r, cr)) {
+ window_move_resize(n->id, r.x, r.y, r.width, r.height);
+ if (!grabbing) {
+ put_status(SBSC_MASK_NODE_GEOMETRY, "node_geometry 0x%08X 0x%08X 0x%08X %ux%u+%i+%i\n", m->id, d->id, n->id, r.width, r.height, r.x, r.y);
+ }
+ }
+
+ window_border_width(n->id, bw);
+
+ } else {
+ xcb_rectangle_t first_rect;
+ xcb_rectangle_t second_rect;
+
+ if (d->layout == LAYOUT_MONOCLE || n->first_child->vacant || n->second_child->vacant) {
+ first_rect = second_rect = rect;
+ } else {
+ unsigned int fence;
+ if (n->split_type == TYPE_VERTICAL) {
+ fence = rect.width * n->split_ratio;
+ first_rect = (xcb_rectangle_t) {rect.x, rect.y, fence, rect.height};
+ second_rect = (xcb_rectangle_t) {rect.x + fence, rect.y, rect.width - fence, rect.height};
+ } else {
+ fence = rect.height * n->split_ratio;
+ first_rect = (xcb_rectangle_t) {rect.x, rect.y, rect.width, fence};
+ second_rect = (xcb_rectangle_t) {rect.x, rect.y + fence, rect.width, rect.height - fence};
+ }
+ }
+
+ apply_layout(m, d, n->first_child, first_rect, root_rect);
+ apply_layout(m, d, n->second_child, second_rect, root_rect);
+ }