#include <xcb/xcb_event.h>
#include "settings.h"
#include "helpers.h"
-#include "utils.h"
+#include "misc.h"
#include "window.h"
#include "types.h"
#include "bspwm.h"
rotate_tree(n->second_child, rot);
}
+void magnetise_tree(node_t *n, corner_t corner)
+{
+ if (n == NULL || is_leaf(n))
+ return;
+
+ PUTS("magnetise tree");
+
+ switch (n->split_type) {
+ case TYPE_HORIZONTAL:
+ if (corner == TOP_LEFT || corner == TOP_RIGHT)
+ change_split_ratio(n, CHANGE_DECREASE);
+ else
+ change_split_ratio(n, CHANGE_INCREASE);
+ break;
+ case TYPE_VERTICAL:
+ if (corner == TOP_LEFT || corner == BOTTOM_LEFT)
+ change_split_ratio(n, CHANGE_DECREASE);
+ else
+ change_split_ratio(n, CHANGE_INCREASE);
+ break;
+ default:
+ break;
+ }
+
+ magnetise_tree(n->first_child, corner);
+ magnetise_tree(n->second_child, corner);
+}
+
void dump_tree(desktop_t *d, node_t *n, char *rsp, int depth)
{
if (n == NULL)
strcat(rsp, " ");
if (is_leaf(n))
- /* sprintf(line, "0x%X [%i %i %u %u]", n->client->window, n->rectangle.x, n->rectangle.y, n->rectangle.width, n->rectangle.height); */
- /* sprintf(line, "C %X [%i %i %u %u] (%s%s) [%i %i %u %u]", n->client->window, n->rectangle.x, n->rectangle.y, n->rectangle.width, n->rectangle.height, (n->client->floating ? "f" : "-"), (n->client->transient ? "t" : "-"), n->client->floating_rectangle.x, n->client->floating_rectangle.y, n->client->floating_rectangle.width, n->client->floating_rectangle.height); */
- sprintf(line, "C %X %s%s%s%s%s", n->client->window, (n->client->floating ? "f" : "-"), (n->client->transient ? "t" : "-"), (n->client->fullscreen ? "F" : "-"), (n->client->urgent ? "u" : "-"), (n->client->locked ? "l" : "-"));
+ sprintf(line, "%s %X %s%s%s%s%s", n->client->class_name, n->client->window, (n->client->floating ? "f" : "-"), (n->client->transient ? "t" : "-"), (n->client->fullscreen ? "F" : "-"), (n->client->urgent ? "u" : "-"), (n->client->locked ? "l" : "-"));
else
- /* sprintf(line, "%s %.2f [%i %i %u %u]", (n->split_type == TYPE_HORIZONTAL ? "H" : "V"), n->split_ratio, n->rectangle.x, n->rectangle.y, n->rectangle.width, n->rectangle.height); */
sprintf(line, "%s %.2f", (n->split_type == TYPE_HORIZONTAL ? "H" : "V"), n->split_ratio);
strcat(rsp, line);
if (is_leaf(n)) {
if (n->client->fullscreen)
return;
+
+ if (n == d->root || (d->layout == LAYOUT_MONOCLE && !is_floating(n->client)))
+ n->client->border_width = 0;
+ else
+ n->client->border_width = border_width;
+
xcb_rectangle_t r;
if (is_tiled(n->client)) {
if (d->layout == LAYOUT_TILED)
r = rect;
else if (d->layout == LAYOUT_MONOCLE)
r = root_rect;
- int bleed = window_gap + 2 * border_width;
+ int bleed = window_gap + 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;
}
window_move_resize(n->client->window, r.x, r.y, r.width, r.height);
- window_border_width(n->client->window, border_width);
+ window_border_width(n->client->window, n->client->border_width);
window_draw_border(n, n == d->focus);
if (d->layout == LAYOUT_MONOCLE && n == d->focus)
if (fopar == NULL) {
dad->first_child = n;
dad->second_child = focus;
- dad->split_type = TYPE_VERTICAL;
+ if (focus->rectangle.width > focus->rectangle.height)
+ dad->split_type = TYPE_VERTICAL;
+ else
+ dad->split_type = TYPE_HORIZONTAL;
focus->parent = dad;
d->root = dad;
} else {
split_mode = MODE_AUTOMATIC;
break;
}
+ if (focus->vacant)
+ update_vacant_state(fopar);
}
}
} else {
node_t *b;
node_t *g = p->parent;
- if (is_first_child(n)) {
+ bool n_first_child = is_first_child(n);
+ if (n_first_child) {
b = p->second_child;
if (n->born_as == MODE_AUTOMATIC)
rotate_tree(b, ROTATE_COUNTER_CLOCKWISE);
n->parent = NULL;
free(p);
- if (n == d->focus) {
- if (d->last_focus != NULL && d->last_focus != n)
+ if (n == d->last_focus) {
+ d->last_focus = NULL;
+ } else if (n == d->focus) {
+ if (d->last_focus != NULL)
d->focus = d->last_focus;
else
- d->focus = (is_first_child(b) ? second_extrema(b) : first_extrema(b));
+ d->focus = (n_first_child ? first_extrema(b) : second_extrema(b));
d->last_focus = NULL;
}
+
+ update_vacant_state(b->parent);
}
}
node_t *n = first_extrema(d->root);
while (n != NULL) {
- /* xcb_map_window(dpy, n->client->window); */
window_show(n->client->window);
n = next_leaf(n);
}
void cycle_desktop(cycle_dir_t dir)
{
- if (dir == DIR_NEXT)
+ if (dir == CYCLE_NEXT)
select_desktop((desk->next == NULL ? desk_head : desk->next));
- else if (dir == DIR_PREV)
+ else if (dir == CYCLE_PREV)
select_desktop((desk->prev == NULL ? desk_tail : desk->prev));
}
PUTS("cycle leaf");
- node_t *f = (dir == DIR_PREV ? prev_leaf(n) : next_leaf(n));
+ node_t *f = (dir == CYCLE_PREV ? prev_leaf(n) : next_leaf(n));
if (f == NULL)
- f = (dir == DIR_PREV ? second_extrema(d->root) : first_extrema(d->root));
+ f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
while (f != n) {
bool tiled = is_tiled(f->client);
- if (skip == SKIP_NONE || (skip == SKIP_TILED && !tiled) || (skip == SKIP_FLOATING && tiled)) {
+ if (skip == SKIP_NONE || (skip == SKIP_TILED && !tiled) || (skip == SKIP_FLOATING && tiled)
+ || (skip == SKIP_CLASS_DIFFER && strcmp(f->client->class_name, n->client->class_name) == 0)
+ || (skip == SKIP_CLASS_EQUAL && strcmp(f->client->class_name, n->client->class_name) != 0)) {
focus_node(d, f, true);
return;
}
- f = (dir == DIR_PREV ? prev_leaf(f) : next_leaf(f));
+ f = (dir == CYCLE_PREV ? prev_leaf(f) : next_leaf(f));
if (f == NULL)
- f = (dir == DIR_PREV ? second_extrema(d->root) : first_extrema(d->root));
+ f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
}
}