X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=tree.c;h=628f7700554d79254f080831a03869cf8c9e9111;hb=84cb0e0c29e94029daef36673397e4c87cd75f1a;hp=2c74337bfb036df863547b77bf014797af8bc1f1;hpb=286fb33dfde43f5fd6e48410285d13acaa024133;p=bspwm.git diff --git a/tree.c b/tree.c index 2c74337..628f770 100644 --- a/tree.c +++ b/tree.c @@ -166,34 +166,6 @@ void rotate_tree(node_t *n, rotate_t rot) 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, unsigned int depth) { if (n == NULL) @@ -220,13 +192,6 @@ void dump_tree(desktop_t *d, node_t *n, char *rsp, unsigned int depth) dump_tree(d, n->second_child, rsp, depth + 1); } -void refresh_current(void) { - if (mon->desk->focus == NULL) - ewmh_update_active_window(); - else - focus_node(mon, mon->desk, mon->desk->focus, true); -} - void list_monitors(list_option_t opt, char *rsp) { monitor_t *m = mon_head; @@ -263,11 +228,16 @@ void list_desktops(monitor_t *m, list_option_t opt, unsigned int depth, char *rs void arrange(monitor_t *m, desktop_t *d) { + PRINTF("arrange %s%s%s\n", (num_monitors > 1 ? m->name : ""), (num_monitors > 1 ? " " : ""), d->name); + xcb_rectangle_t rect = m->rectangle; - rect.x += left_padding + window_gap; - rect.y += top_padding + window_gap; - rect.width -= left_padding + right_padding + window_gap; - rect.height -= top_padding + bottom_padding + window_gap; + int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : window_gap); + rect.x += m->left_padding + wg; + rect.y += m->top_padding + wg; + rect.width -= m->left_padding + m->right_padding + wg; + rect.height -= m->top_padding + m->bottom_padding + wg; + if (focus_follows_mouse) + get_pointer_position(&pointer_position); apply_layout(m, d, d->root, rect, rect); } @@ -299,7 +269,8 @@ void apply_layout(monitor_t *m, desktop_t *d, node_t *n, xcb_rectangle_t rect, x r = rect; else if (d->layout == LAYOUT_MONOCLE) r = root_rect; - int bleed = window_gap + 2 * n->client->border_width; + int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : 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; @@ -311,9 +282,6 @@ void apply_layout(monitor_t *m, desktop_t *d, node_t *n, xcb_rectangle_t rect, x window_border_width(n->client->window, n->client->border_width); window_draw_border(n, n == d->focus, m == mon); - if (d->layout == LAYOUT_MONOCLE && n == d->focus) - window_raise(n->client->window); - } else { xcb_rectangle_t first_rect; xcb_rectangle_t second_rect; @@ -339,7 +307,7 @@ void apply_layout(monitor_t *m, desktop_t *d, node_t *n, xcb_rectangle_t rect, x } } -void insert_node(desktop_t *d, node_t *n) +void insert_node(monitor_t *m, desktop_t *d, node_t *n) { if (d == NULL || n == NULL) return; @@ -360,7 +328,7 @@ void insert_node(desktop_t *d, node_t *n) if (fopar == NULL) { dad->first_child = n; dad->second_child = focus; - if (focus->rectangle.width > focus->rectangle.height) + if (m->rectangle.width > m->rectangle.height) dad->split_type = TYPE_VERTICAL; else dad->split_type = TYPE_HORIZONTAL; @@ -448,13 +416,17 @@ void focus_node(monitor_t *m, desktop_t *d, node_t *n, bool is_mapped) window_draw_border(d->focus, m != mon, m == mon); window_draw_border(n, true, true); } + if (focus_follows_mouse) + get_pointer_position(&pointer_position); xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT, n->client->window, XCB_CURRENT_TIME); } - if (!is_tiled(n->client) || d->layout == LAYOUT_MONOCLE) - window_raise(n->client->window); - else if (is_tiled(n->client)) - window_lower(n->client->window); + if (!is_tiled(n->client)) { + if (!adaptative_raise || !might_cover(d, n)) + window_raise(n->client->window); + } else { + window_pseudo_raise(d, n->client->window); + } if (d->focus != n) { d->last_focus = d->focus; @@ -581,23 +553,17 @@ void swap_nodes(node_t *n1, node_t *n2) void fit_monitor(monitor_t *m, client_t *c) { - xcb_rectangle_t cr = c->floating_rectangle; - xcb_rectangle_t mr = m->rectangle; - if (cr.x < mr.x) - cr.x += mr.x; - if (cr.y < mr.y) - cr.y += mr.y; -} - -void translate_coordinates(monitor_t *ms, monitor_t *md, client_t *c) -{ - if (ms == md) - return; - - uint32_t vx = md->rectangle.x - ms->rectangle.x; - uint32_t vy = md->rectangle.y - ms->rectangle.y; - c->floating_rectangle.x += vx; - c->floating_rectangle.y += vy; + xcb_rectangle_t crect = c->floating_rectangle; + xcb_rectangle_t mrect = m->rectangle; + while (crect.x < mrect.x) + crect.x += mrect.width; + while (crect.x > (mrect.x + mrect.width - 1)) + crect.x -= mrect.width; + while (crect.y < mrect.y) + crect.y += mrect.height; + while (crect.y > (mrect.y + mrect.height - 1)) + crect.y -= mrect.height; + c->floating_rectangle = crect; } void transfer_node(monitor_t *ms, desktop_t *ds, monitor_t *md, desktop_t *dd, node_t *n) @@ -608,14 +574,15 @@ void transfer_node(monitor_t *ms, desktop_t *ds, monitor_t *md, desktop_t *dd, n PRINTF("transfer node %X\n", n->client->window); unlink_node(ds, n); - insert_node(dd, n); + insert_node(md, dd, n); ewmh_set_wm_desktop(n, dd); if (ds == ms->desk && dd != md->desk) { window_hide(n->client->window); } - translate_coordinates(ms, md, n->client); + fit_monitor(md, n->client); + if (n->client->fullscreen) window_move_resize(n->client->window, md->rectangle.x, md->rectangle.y, md->rectangle.width, md->rectangle.height); @@ -681,19 +648,27 @@ void cycle_monitor(cycle_dir_t dir) select_monitor((mon->prev == NULL ? mon_tail : mon->prev)); } -void cycle_desktop(cycle_dir_t dir) +void cycle_desktop(monitor_t *m, desktop_t *d, cycle_dir_t dir, skip_desktop_t skip) { - if (dir == CYCLE_NEXT) - select_desktop((mon->desk->next == NULL ? mon->desk_head : mon->desk->next)); - else if (dir == CYCLE_PREV) - select_desktop((mon->desk->prev == NULL ? mon->desk_tail : mon->desk->prev)); + desktop_t *f = (dir == CYCLE_PREV ? d->prev : d->next); + if (f == NULL) + f = (dir == CYCLE_PREV ? m->desk_tail : m->desk_head); + + while (f != d) { + if (skip == DESKTOP_SKIP_NONE + || (skip == DESKTOP_SKIP_FREE && f->root != NULL) + || (skip == DESKTOP_SKIP_OCCUPIED && f->root == NULL)) { + select_desktop(f); + return; + } + f = (dir == CYCLE_PREV ? f->prev : f->next); + if (f == NULL) + f = (dir == CYCLE_PREV ? m->desk_tail : m->desk_head); + } } -void cycle_leaf(cycle_dir_t dir, skip_client_t skip) +void cycle_leaf(monitor_t *m, desktop_t *d, node_t *n, cycle_dir_t dir, skip_client_t skip) { - desktop_t *d = mon->desk; - node_t *n = mon->desk->focus; - if (n == NULL) return; @@ -705,10 +680,10 @@ void cycle_leaf(cycle_dir_t dir, skip_client_t skip) while (f != n) { bool tiled = is_tiled(f->client); - 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(mon, d, f, true); + if (skip == CLIENT_SKIP_NONE || (skip == CLIENT_SKIP_TILED && !tiled) || (skip == CLIENT_SKIP_FLOATING && tiled) + || (skip == CLIENT_SKIP_CLASS_DIFFER && strcmp(f->client->class_name, n->client->class_name) == 0) + || (skip == CLIENT_SKIP_CLASS_EQUAL && strcmp(f->client->class_name, n->client->class_name) != 0)) { + focus_node(m, d, f, true); return; } f = (dir == CYCLE_PREV ? prev_leaf(f) : next_leaf(f)); @@ -717,6 +692,47 @@ void cycle_leaf(cycle_dir_t dir, skip_client_t skip) } } +void nearest_leaf(monitor_t *m, desktop_t *d, node_t *n, nearest_arg_t dir, skip_client_t skip) +{ + if (n == NULL) + return; + + PUTS("nearest leaf"); + + node_t *x = NULL; + + for (node_t *f = first_extrema(d->root); f != NULL; f = next_leaf(f)) + if (skip == CLIENT_SKIP_NONE || (skip == CLIENT_SKIP_TILED && !is_tiled(f->client)) || (skip == CLIENT_SKIP_FLOATING && is_tiled(f->client)) + || (skip == CLIENT_SKIP_CLASS_DIFFER && strcmp(f->client->class_name, n->client->class_name) == 0) + || (skip == CLIENT_SKIP_CLASS_EQUAL && strcmp(f->client->class_name, n->client->class_name) != 0)) + if ((dir == NEAREST_OLDER + && (f->client->uid < n->client->uid) + && (x == NULL || f->client->uid > x->client->uid)) + || (dir == NEAREST_NEWER + && (f->client->uid > n->client->uid) + && (x == NULL || f->client->uid < x->client->uid))) + x = f; + + focus_node(m, d, x, true); +} + +void circulate_leaves(monitor_t *m, desktop_t *d, circulate_dir_t dir) { + if (d == NULL || d->root == NULL || is_leaf(d->root)) + return; + node_t *par = d->focus->parent; + bool focus_first_child = is_first_child(d->focus); + if (dir == CIRCULATE_FORWARD) + for (node_t *s = second_extrema(d->root), *f = prev_leaf(s); f != NULL; s = prev_leaf(f), f = prev_leaf(s)) + swap_nodes(f, s); + else + for (node_t *f = first_extrema(d->root), *s = next_leaf(f); s != NULL; f = next_leaf(s), s = next_leaf(f)) + swap_nodes(f, s); + if (focus_first_child) + focus_node(m, d, par->first_child, true); + else + focus_node(m, d, par->second_child, true); +} + void update_vacant_state(node_t *n) { if (n == NULL)