]> git.lizzy.rs Git - bspwm.git/blobdiff - tree.c
Merge branch 'master' into history
[bspwm.git] / tree.c
diff --git a/tree.c b/tree.c
index f79663f17a33590f53cb109ac2d1ee1df71e279e..44772e378af9bcff0a88c86c5880584a0dc1d7b0 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -167,6 +167,33 @@ void rotate_tree(node_t *n, rotate_t rot)
     rotate_tree(n->second_child, rot);
 }
 
+void flip_tree(node_t *n, flip_t flp)
+{
+    if (n == NULL || is_leaf(n))
+        return;
+
+    node_t *tmp;
+
+    if ((flp == FLIP_HORIZONTAL && n->split_type == TYPE_HORIZONTAL)
+            || (flp == FLIP_VERTICAL && n->split_type == TYPE_VERTICAL)) {
+        tmp = n->first_child;
+        n->first_child = n->second_child;
+        n->second_child = tmp;
+        n->split_ratio = 1.0 - n->split_ratio;
+    }
+
+    flip_tree(n->first_child, flp);
+    flip_tree(n->second_child, flp);
+}
+
+void list_history(desktop_t *d, char *rsp)
+{
+    char line[MAXLEN];
+    for (node_list_t *a = d->history->head; a != NULL; a = a->next) {
+        snprintf(line, sizeof(line), "%s %X\n", a->node->client->class_name, a->node->client->window);
+        strncat(rsp, line, REMLEN(rsp));
+    }
+}
 
 void arrange(monitor_t *m, desktop_t *d)
 {
@@ -178,8 +205,6 @@ void arrange(monitor_t *m, desktop_t *d)
     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)
-        update_pointer_position(&pointer_position);
     apply_layout(m, d, d->root, rect, rect);
 }
 
@@ -367,11 +392,18 @@ void focus_node(monitor_t *m, desktop_t *d, node_t *n, bool is_mapped)
             window_draw_border(d->focus, false, true);
             window_draw_border(n, true, true);
         }
-        if (focus_follows_mouse)
-            update_pointer_position(&pointer_position);
         xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT, n->client->window, XCB_CURRENT_TIME);
     }
 
+    if (focus_follows_pointer) {
+        xcb_window_t win = XCB_NONE;
+        get_pointed_window(&win);
+        if (win != n->client->window)
+            enable_motion_recorder();
+        else
+            disable_motion_recorder();
+    }
+
     if (!is_tiled(n->client)) {
         if (!adaptative_raise || !might_cover(d, n))
             window_raise(n->client->window);
@@ -380,8 +412,8 @@ void focus_node(monitor_t *m, desktop_t *d, node_t *n, bool is_mapped)
     }
 
     if (d->focus != n) {
-        d->last_focus = d->focus;
         d->focus = n;
+        history_add(d->history, n);
     }
 
     ewmh_update_active_window();
@@ -409,7 +441,6 @@ void unlink_node(desktop_t *d, node_t *n)
     if (p == NULL) {
         d->root = NULL;
         d->focus = NULL;
-        d->last_focus = NULL;
     } else {
         node_t *b;
         node_t *g = p->parent;
@@ -436,18 +467,20 @@ void unlink_node(desktop_t *d, node_t *n)
         n->parent = NULL;
         free(p);
 
-        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
+        if (n == d->focus) {
+            node_t *last_focus = history_get(d->history, 1);
+            if (last_focus != NULL) {
+                d->focus = last_focus;
+            } else {
                 d->focus = (n_first_child ? first_extrema(b) : second_extrema(b));
-            d->last_focus = NULL;
+                history_add(d->history, d->focus);
+            }
         }
 
         update_vacant_state(b->parent);
     }
+
+    history_remove(d->history, n);
 }
 
 void remove_node(desktop_t *d, node_t *n)
@@ -793,8 +826,6 @@ void list(desktop_t *d, node_t *n, char *rsp, unsigned int depth)
 
     if (n == d->focus)
         strncat(rsp, " *\n", REMLEN(rsp));
-    else if (n == d->last_focus)
-        strncat(rsp, " ~\n", REMLEN(rsp));
     else
         strncat(rsp, "\n", REMLEN(rsp));
 
@@ -907,15 +938,8 @@ void restore(char *file_path)
                 if (c->uid > max_uid)
                     max_uid = c->uid;
                 n->client = c;
-                if (len >= 2)
-                    switch (line[len - 2]) {
-                        case '*':
-                            d->focus = n;
-                            break;
-                        case '~':
-                            d->last_focus = n;
-                            break;
-                    }
+                if (len >= 2 && line[len -2] == '*')
+                    d->focus = n;
             }
         }
         last_level = level;
@@ -926,7 +950,7 @@ void restore(char *file_path)
         for (monitor_t *m = mon_head; m != NULL; m = m->next)
             for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
                 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n)) {
-                    uint32_t values[] = {CLIENT_EVENT_MASK};
+                    uint32_t values[] = {(focus_follows_pointer ? CLIENT_EVENT_MASK_FFP : CLIENT_EVENT_MASK)};
                     xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
                     if (n->client->floating) {
                         n->vacant = true;