aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-03-01 13:24:47 -0500
committerGitHub <noreply@github.com>2017-03-01 13:24:47 -0500
commitd6ac3021ceafdf7e3a876a3764cc553f4df6b8cc (patch)
treee90c86a30595ed7a18713a19fe9d26e8fa30a2c4 /sway
parent21ad45b622eb1fc2c68d1036fd9763a37fec668b (diff)
parent032907e9d281ccfed0c881b5ae3e47dc6e8bf412 (diff)
Merge pull request #1092 from 4e554c4c/move_floating
i3 feature support: Moving flotaing containers
Diffstat (limited to 'sway')
-rw-r--r--sway/commands/move.c26
-rw-r--r--sway/layout.c25
-rw-r--r--sway/sway.5.txt14
3 files changed, 50 insertions, 15 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c
index 0b134494..1a8a321e 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -9,30 +9,40 @@
struct cmd_results *cmd_move(int argc, char **argv) {
struct cmd_results *error = NULL;
+ int move_amt = 10;
+
if (config->reading) return cmd_results_new(CMD_FAILURE, "move", "Can't be used in config file.");
if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) {
return error;
}
- const char* expected_syntax = "Expected 'move <left|right|up|down|next|prev|first>' or "
+ const char* expected_syntax = "Expected 'move <left|right|up|down|next|prev|first> <[px] px>' or "
"'move <container|window> to workspace <name>' or "
"'move <container|window|workspace> to output <name|direction>' or "
"'move position mouse'";
swayc_t *view = get_focused_container(&root_container);
+ if (argc == 2 || (argc == 3 && strcasecmp(argv[2], "px") == 0 )) {
+ char *inv;
+ move_amt = (int)strtol(argv[1], &inv, 10);
+ if (*inv != '\0' && strcasecmp(inv, "px") != 0) {
+ move_amt = 10;
+ }
+ }
+
if (strcasecmp(argv[0], "left") == 0) {
- move_container(view, MOVE_LEFT);
+ move_container(view, MOVE_LEFT, move_amt);
} else if (strcasecmp(argv[0], "right") == 0) {
- move_container(view, MOVE_RIGHT);
+ move_container(view, MOVE_RIGHT, move_amt);
} else if (strcasecmp(argv[0], "up") == 0) {
- move_container(view, MOVE_UP);
+ move_container(view, MOVE_UP, move_amt);
} else if (strcasecmp(argv[0], "down") == 0) {
- move_container(view, MOVE_DOWN);
+ move_container(view, MOVE_DOWN, move_amt);
} else if (strcasecmp(argv[0], "next") == 0) {
- move_container(view, MOVE_NEXT);
+ move_container(view, MOVE_NEXT, move_amt);
} else if (strcasecmp(argv[0], "prev") == 0) {
- move_container(view, MOVE_PREV);
+ move_container(view, MOVE_PREV, move_amt);
} else if (strcasecmp(argv[0], "first") == 0) {
- move_container(view, MOVE_FIRST);
+ move_container(view, MOVE_FIRST, move_amt);
} else if (strcasecmp(argv[0], "container") == 0 || strcasecmp(argv[0], "window") == 0) {
// "move container ...
if ((error = checkarg(argc, "move container/window", EXPECTED_AT_LEAST, 4))) {
diff --git a/sway/layout.c b/sway/layout.c
index 5e144cd8..e196ebd3 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -349,10 +349,31 @@ static void swap_children(swayc_t *container, int a, int b) {
}
}
-void move_container(swayc_t *container, enum movement_direction dir) {
+void move_container(swayc_t *container, enum movement_direction dir, int move_amt) {
enum swayc_layouts layout = L_NONE;
swayc_t *parent = container->parent;
- if (container->is_floating || (container->type != C_VIEW && container->type != C_CONTAINER)) {
+ if (container->is_floating) {
+ swayc_t *output = swayc_parent_by_type(container, C_OUTPUT);
+ switch(dir) {
+ case MOVE_LEFT:
+ container->x = MAX(0, container->x - move_amt);
+ break;
+ case MOVE_RIGHT:
+ container->x = MIN(output->width - container->width, container->x + move_amt);
+ break;
+ case MOVE_UP:
+ container->y = MAX(0, container->y - move_amt);
+ break;
+ case MOVE_DOWN:
+ container->y = MIN(output->height - container->height, container->y + move_amt);
+ break;
+ default:
+ break;
+ }
+ update_geometry(container);
+ return;
+ }
+ if (container->type != C_VIEW && container->type != C_CONTAINER) {
return;
}
if (dir == MOVE_UP || dir == MOVE_DOWN) {
diff --git a/sway/sway.5.txt b/sway/sway.5.txt
index 19f7eb1d..f425cfe7 100644
--- a/sway/sway.5.txt
+++ b/sway/sway.5.txt
@@ -100,11 +100,15 @@ They are expected to be used with **bindsym** or at runtime through **swaymsg**(
**layout** toggle split::
Cycles between available split layouts.
-**move** <left|right|up|down|next|prev|first>::
- Moves the focused container _left_, _right_, _up_, or _down_. Moving to _prev_
- or _next_ swaps the container with its sibling in the same container. Move
- _first_ exchanges the focused element in an auto layout with the first
- element, i.e. promotes the focused element to master position.
+**move** <left|right|up|down> <[px]>::
+ Moves the focused container _left_, _right_, _up_, or _down_. If the window
+ is floating it moves it _px_ in that direction, defaulting to 10. Tiled
+ containers are moved the same regardless of the _px_ argument.
+
+**move** <next|prev|first>::
+ Moving to _prev_ or _next_ swaps the container with its sibling in the same
+ container. Move _first_ exchanges the focused element in an auto layout with
+ the first element, i.e. promotes the focused element to master position.
**move** <container|window> to workspace <name>::
Moves the focused container to the workspace identified by _name_.