]> git.sur5r.net Git - i3/i3/commitdiff
Make absolute floating move work with criteria
authorTony Crisci <tony@dubstepdish.com>
Tue, 1 Jul 2014 06:12:28 +0000 (02:12 -0400)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 2 Jul 2014 17:07:08 +0000 (19:07 +0200)
Make commands of type `move [window|container] [to] [absolute] position
<px> [px] <px> [px]` work with command selection criteria.

fixes #1301

src/commands.c
testcases/t/124-move.t

index 7803c984c209b55794721f8048d18853ea8ca50c..7a6502684948a0012fd251805a5e4226decb6ae1 100644 (file)
@@ -1810,34 +1810,46 @@ void cmd_focus_output(I3_CMD, char *name) {
 void cmd_move_window_to_position(I3_CMD, char *method, char *cx, char *cy) {
     int x = atoi(cx);
     int y = atoi(cy);
+    bool has_error = false;
 
-    if (!con_is_floating(focused)) {
-        ELOG("Cannot change position. The window/container is not floating\n");
-        yerror("Cannot change position. The window/container is not floating.");
-        return;
-    }
+    owindow *current;
+    HANDLE_EMPTY_MATCH;
 
-    if (strcmp(method, "absolute") == 0) {
-        focused->parent->rect.x = x;
-        focused->parent->rect.y = y;
+    TAILQ_FOREACH(current, &owindows, owindows) {
+        if (!con_is_floating(current->con)) {
+            ELOG("Cannot change position. The window/container is not floating\n");
 
-        DLOG("moving to absolute position %d %d\n", x, y);
-        floating_maybe_reassign_ws(focused->parent);
-        cmd_output->needs_tree_render = true;
-    }
+            if (!has_error) {
+                yerror("Cannot change position of a window/container because it is not floating.");
+                has_error = true;
+            }
 
-    if (strcmp(method, "position") == 0) {
-        Rect newrect = focused->parent->rect;
+            continue;
+        }
 
-        DLOG("moving to position %d %d\n", x, y);
-        newrect.x = x;
-        newrect.y = y;
+        if (strcmp(method, "absolute") == 0) {
+            current->con->parent->rect.x = x;
+            current->con->parent->rect.y = y;
 
-        floating_reposition(focused->parent, newrect);
+            DLOG("moving to absolute position %d %d\n", x, y);
+            floating_maybe_reassign_ws(current->con->parent);
+            cmd_output->needs_tree_render = true;
+        }
+
+        if (strcmp(method, "position") == 0) {
+            Rect newrect = current->con->parent->rect;
+
+            DLOG("moving to position %d %d\n", x, y);
+            newrect.x = x;
+            newrect.y = y;
+
+            floating_reposition(current->con->parent, newrect);
+        }
     }
 
     // XXX: default reply for now, make this a better reply
-    ysuccess(true);
+    if (!has_error)
+        ysuccess(true);
 }
 
 /*
index 28207a3c607b8e553cbc4ceddaf573effa0b4350..88a36a5b333fc67d38da8019247a4fa5662b3b4a 100644 (file)
@@ -245,4 +245,20 @@ my $center_y = int($x->root->rect->height/2) - int($floatcon[0]->{rect}->{height
 is($floatcon[0]->{rect}->{x}, $center_x, "moved to center at position $center_x x");
 is($floatcon[0]->{rect}->{y}, $center_y, "moved to center at position $center_y y");
 
+# Make sure the command works with criteria
+open_floating_window;
+
+@floatcon = @{get_ws($tmp)->{floating_nodes}};
+
+cmd '[con_id="' . $floatcon[0]->{nodes}[0]->{id} . '"] move position 25 px 30 px';
+cmd '[con_id="' . $floatcon[1]->{nodes}[0]->{id} . '"] move position 35 px 40 px';
+
+@floatcon = @{get_ws($tmp)->{floating_nodes}};
+
+is($floatcon[0]->{rect}->{x}, 25, 'moved to position 25 x with criteria');
+is($floatcon[0]->{rect}->{y}, 30, 'moved to position 30 y with criteria');
+
+is($floatcon[1]->{rect}->{x}, 35, 'moved to position 35 x with criteria');
+is($floatcon[1]->{rect}->{y}, 40, 'moved to position 40 y with criteria');
+
 done_testing;