]> git.sur5r.net Git - i3/i3/blobdiff - src/resize.c
Merge branch 'master' into next
[i3/i3] / src / resize.c
index 268dc3fbd119b69780bcbee89f7d47cc195829d2..cc4ba841f8b34377d353ad4eea46787dca3be4dd 100644 (file)
@@ -51,6 +51,54 @@ DRAGGING_CB(resize_callback) {
     xcb_flush(conn);
 }
 
+bool resize_find_tiling_participants(Con **current, Con **other, direction_t direction) {
+    DLOG("Find two participants for resizing container=%p in direction=%i\n", other, direction);
+    Con *first = *current;
+    Con *second = NULL;
+    if (first == NULL) {
+        DLOG("Current container is NULL, aborting.\n");
+        return false;
+    }
+
+    /* Go up in the tree and search for a container to resize */
+    const orientation_t search_orientation = ((direction == D_LEFT || direction == D_RIGHT) ? HORIZ : VERT);
+    const bool dir_backwards = (direction == D_UP || direction == D_LEFT);
+    while (first->type != CT_WORKSPACE &&
+           first->type != CT_FLOATING_CON &&
+           second == NULL) {
+        /* get the appropriate first container with the matching
+         * orientation (skip stacked/tabbed cons) */
+        if ((con_orientation(first->parent) != search_orientation) ||
+            (first->parent->layout == L_STACKED) ||
+            (first->parent->layout == L_TABBED)) {
+            first = first->parent;
+            continue;
+        }
+
+        /* get the counterpart for this resizement */
+        if (dir_backwards) {
+            second = TAILQ_PREV(first, nodes_head, nodes);
+        } else {
+            second = TAILQ_NEXT(first, nodes);
+        }
+
+        if (second == NULL) {
+            DLOG("No second container in this direction found, trying to look further up in the tree...\n");
+            first = first->parent;
+        }
+    }
+
+    DLOG("Found participants: first=%p and second=%p.", first, second);
+    *current = first;
+    *other = second;
+    if (first == NULL || second == NULL) {
+        DLOG("Could not find two participants for this resize request.\n");
+        return false;
+    }
+
+    return true;
+}
+
 int resize_graphical_handler(Con *first, Con *second, orientation_t orientation, const xcb_button_press_event_t *event) {
     DLOG("resize handler\n");
 
@@ -106,12 +154,16 @@ int resize_graphical_handler(Con *first, Con *second, orientation_t orientation,
 
     const struct callback_params params = { orientation, output, helpwin, &new_position };
 
-    drag_pointer(NULL, event, grabwin, BORDER_TOP, 0, resize_callback, &params);
+    drag_result_t drag_result = drag_pointer(NULL, event, grabwin, BORDER_TOP, 0, resize_callback, &params);
 
     xcb_destroy_window(conn, helpwin);
     xcb_destroy_window(conn, grabwin);
     xcb_flush(conn);
 
+    /* User cancelled the drag so no action should be taken. */
+    if (drag_result == DRAG_REVERT)
+        return 0;
+
     int pixels;
     if (orientation == HORIZ)
         pixels = (new_position - event->root_x);