i3 - improved tiling WM


Make absolute floating move work with criteria

Patch status: merged

Patch by Tony Crisci

Long description:

Make commands of type `move [window|container] [to] [absolute] position
<px> [px] <px> [px]` work with command selection criteria.

fixes #1301

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

b/src/commands.c

18
@@ -1810,34 +1810,46 @@ void cmd_focus_output(I3_CMD, char *name) {
19
 void cmd_move_window_to_position(I3_CMD, char *method, char *cx, char *cy) {
20
     int x = atoi(cx);
21
     int y = atoi(cy);
22
+    bool has_error = false;
23
 
24
-    if (!con_is_floating(focused)) {
25
-        ELOG("Cannot change position. The window/container is not floating\n");
26
-        yerror("Cannot change position. The window/container is not floating.");
27
-        return;
28
-    }
29
+    owindow *current;
30
+    HANDLE_EMPTY_MATCH;
31
 
32
-    if (strcmp(method, "absolute") == 0) {
33
-        focused->parent->rect.x = x;
34
-        focused->parent->rect.y = y;
35
+    TAILQ_FOREACH(current, &owindows, owindows) {
36
+        if (!con_is_floating(current->con)) {
37
+            ELOG("Cannot change position. The window/container is not floating\n");
38
 
39
-        DLOG("moving to absolute position %d %d\n", x, y);
40
-        floating_maybe_reassign_ws(focused->parent);
41
-        cmd_output->needs_tree_render = true;
42
-    }
43
+            if (!has_error) {
44
+                yerror("Cannot change position of a window/container because it is not floating.");
45
+                has_error = true;
46
+            }
47
 
48
-    if (strcmp(method, "position") == 0) {
49
-        Rect newrect = focused->parent->rect;
50
+            continue;
51
+        }
52
 
53
-        DLOG("moving to position %d %d\n", x, y);
54
-        newrect.x = x;
55
-        newrect.y = y;
56
+        if (strcmp(method, "absolute") == 0) {
57
+            current->con->parent->rect.x = x;
58
+            current->con->parent->rect.y = y;
59
 
60
-        floating_reposition(focused->parent, newrect);
61
+            DLOG("moving to absolute position %d %d\n", x, y);
62
+            floating_maybe_reassign_ws(current->con->parent);
63
+            cmd_output->needs_tree_render = true;
64
+        }
65
+
66
+        if (strcmp(method, "position") == 0) {
67
+            Rect newrect = current->con->parent->rect;
68
+
69
+            DLOG("moving to position %d %d\n", x, y);
70
+            newrect.x = x;
71
+            newrect.y = y;
72
+
73
+            floating_reposition(current->con->parent, newrect);
74
+        }
75
     }
76
 
77
     // XXX: default reply for now, make this a better reply
78
-    ysuccess(true);
79
+    if (!has_error)
80
+        ysuccess(true);
81
 }
82
 
83
 /*

b/testcases/t/124-move.t

88
@@ -245,4 +245,20 @@ my $center_y = int($x->root->rect->height/2) - int($floatcon[0]->{rect}->{height
89
 is($floatcon[0]->{rect}->{x}, $center_x, "moved to center at position $center_x x");
90
 is($floatcon[0]->{rect}->{y}, $center_y, "moved to center at position $center_y y");
91
 
92
+# Make sure the command works with criteria
93
+open_floating_window;
94
+
95
+@floatcon = @{get_ws($tmp)->{floating_nodes}};
96
+
97
+cmd '[con_id="' . $floatcon[0]->{nodes}[0]->{id} . '"] move position 25 px 30 px';
98
+cmd '[con_id="' . $floatcon[1]->{nodes}[0]->{id} . '"] move position 35 px 40 px';
99
+
100
+@floatcon = @{get_ws($tmp)->{floating_nodes}};
101
+
102
+is($floatcon[0]->{rect}->{x}, 25, 'moved to position 25 x with criteria');
103
+is($floatcon[0]->{rect}->{y}, 30, 'moved to position 30 y with criteria');
104
+
105
+is($floatcon[1]->{rect}->{x}, 35, 'moved to position 35 x with criteria');
106
+is($floatcon[1]->{rect}->{y}, 40, 'moved to position 40 y with criteria');
107
+
108
 done_testing;