]> git.sur5r.net Git - i3/i3/blobdiff - src/resize.c
Update comment for the con_toggle_fullscreen method
[i3/i3] / src / resize.c
index 9c465e183ea812700ab46236ad25306a49aab46c..764a485cb9a765c9aac54a4b53c93181bb651dd6 100644 (file)
@@ -1,5 +1,13 @@
+#undef I3__FILE__
+#define I3__FILE__ "resize.c"
 /*
  * vim:ts=4:sw=4:expandtab
+ *
+ * i3 - an improved dynamic tiling window manager
+ * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
+ *
+ * resize.c: Interactive resizing.
+ *
  */
 #include "all.h"
 
@@ -20,7 +28,7 @@ struct callback_params {
 };
 
 DRAGGING_CB(resize_callback) {
-    struct callback_params *params = extra;
+    const struct callback_params *params = extra;
     Con *output = params->output;
     DLOG("new x = %d, y = %d\n", new_x, new_y);
     if (params->orientation == HORIZ) {
@@ -43,7 +51,55 @@ DRAGGING_CB(resize_callback) {
     xcb_flush(conn);
 }
 
-int resize_graphical_handler(Con *first, Con *second, orientation_t orientation, xcb_button_press_event_t *event) {
+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");
 
     uint32_t new_position;
@@ -52,6 +108,9 @@ int resize_graphical_handler(Con *first, Con *second, orientation_t orientation,
     Con *output = con_get_output(first);
     DLOG("x = %d, width = %d\n", output->rect.x, output->rect.width);
 
+    x_mask_event_mask(~XCB_EVENT_MASK_ENTER_WINDOW);
+    xcb_flush(conn);
+
     uint32_t mask = 0;
     uint32_t values[2];
 
@@ -60,7 +119,8 @@ int resize_graphical_handler(Con *first, Con *second, orientation_t orientation,
 
     /* Open a new window, the resizebar. Grab the pointer and move the window around
        as the user moves the pointer. */
-    xcb_window_t grabwin = create_window(conn, output->rect, XCB_WINDOW_CLASS_INPUT_ONLY, XCURSOR_CURSOR_POINTER, true, mask, values);
+    xcb_window_t grabwin = create_window(conn, output->rect, XCB_COPY_FROM_PARENT, XCB_COPY_FROM_PARENT,
+            XCB_WINDOW_CLASS_INPUT_ONLY, XCURSOR_CURSOR_POINTER, true, mask, values);
 
     Rect helprect;
     if (orientation == HORIZ) {
@@ -83,8 +143,8 @@ int resize_graphical_handler(Con *first, Con *second, orientation_t orientation,
     mask |= XCB_CW_OVERRIDE_REDIRECT;
     values[1] = 1;
 
-    xcb_window_t helpwin = create_window(conn, helprect, XCB_WINDOW_CLASS_INPUT_OUTPUT,
-                                         (orientation == HORIZ ?
+    xcb_window_t helpwin = create_window(conn, helprect, XCB_COPY_FROM_PARENT, XCB_COPY_FROM_PARENT,
+            XCB_WINDOW_CLASS_INPUT_OUTPUT, (orientation == HORIZ ?
                                           XCURSOR_CURSOR_RESIZE_HORIZONTAL :
                                           XCURSOR_CURSOR_RESIZE_VERTICAL), true, mask, values);
 
@@ -92,14 +152,18 @@ int resize_graphical_handler(Con *first, Con *second, orientation_t orientation,
 
     xcb_flush(conn);
 
-    struct callback_params params = { orientation, output, helpwin, &new_position };
+    const struct callback_params params = { orientation, output, helpwin, &new_position };
 
-    drag_pointer(NULL, event, grabwin, BORDER_TOP, 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_CANCEL)
+        return 0;
+
     int pixels;
     if (orientation == HORIZ)
         pixels = (new_position - event->root_x);