i3 - improved tiling WM


Implement drag cancel for moving floating windows

Patch status: needinfo

Patch by Tony Crisci

Long description:

Hi, I am a new developer and this is my first code submission to a
project. If I do anything wrong, please let me know.

The patches I've submitted implement #1074 "Add ability to escape
out of a mouse-resize operation".

To apply this patch, use:
curl http://cr.i3wm.org/patch/234/raw.patch | git am

b/src/floating.c

18
@@ -441,8 +441,16 @@ void floating_drag_window(Con *con, const xcb_button_press_event_t *event) {
19
      * after the user releases the mouse button */
20
     tree_render();
21
 
22
+    /* Store the initial rect in case of user cancel */
23
+    struct Rect initial_rect = con->rect;
24
+
25
     /* Drag the window */
26
-    drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, XCURSOR_CURSOR_MOVE, drag_window_callback, event);
27
+    int drag_result = drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, XCURSOR_CURSOR_MOVE, drag_window_callback, event);
28
+
29
+    /* If the user cancelled, undo the changes. */
30
+    if (drag_result == 1) {
31
+        floating_reposition(con, initial_rect);
32
+    }
33
 
34
     /* If this is a scratchpad window, don't auto center it from now on. */
35
     if (con->scratchpad_state == SCRATCHPAD_FRESH)