diff options
author | Calvin Lee <cyrus296@gmail.com> | 2017-02-27 20:30:58 -0700 |
---|---|---|
committer | Calvin Lee <cyrus296@gmail.com> | 2017-03-01 11:00:16 -0700 |
commit | b35782bcade4eb21b8e7dab455dad64ab721438d (patch) | |
tree | 18dd68d4a4f06da3dc069cfde54a3ebd2fe64f77 | |
parent | Fix #1087 (diff) | |
download | sway-b35782bcade4eb21b8e7dab455dad64ab721438d.tar.gz sway-b35782bcade4eb21b8e7dab455dad64ab721438d.tar.zst sway-b35782bcade4eb21b8e7dab455dad64ab721438d.zip |
i3 feature support: Moving flotaing containers
This commit lets the 'move' command apply to floating containers as well
as tiled ones. The command may be appended with a number of pixels and
then optionally the string `px` (like '10 px') in order to move the
container more or fewer than the standard ten pixels.
-rw-r--r-- | include/sway/layout.h | 2 | ||||
-rw-r--r-- | sway/commands/move.c | 26 | ||||
-rw-r--r-- | sway/layout.c | 25 | ||||
-rw-r--r-- | sway/sway.5.txt | 13 |
4 files changed, 50 insertions, 16 deletions
diff --git a/include/sway/layout.h b/include/sway/layout.h index fbedcdb3..f0791588 100644 --- a/include/sway/layout.h +++ b/include/sway/layout.h | |||
@@ -48,7 +48,7 @@ void swap_container(swayc_t *a, swayc_t *b); | |||
48 | // 2 Containers geometry are swapped, used with `swap_container` | 48 | // 2 Containers geometry are swapped, used with `swap_container` |
49 | void swap_geometry(swayc_t *a, swayc_t *b); | 49 | void swap_geometry(swayc_t *a, swayc_t *b); |
50 | 50 | ||
51 | void move_container(swayc_t* container, enum movement_direction direction); | 51 | void move_container(swayc_t* container, enum movement_direction direction, int move_amt); |
52 | void move_container_to(swayc_t* container, swayc_t* destination); | 52 | void move_container_to(swayc_t* container, swayc_t* destination); |
53 | void move_workspace_to(swayc_t* workspace, swayc_t* destination); | 53 | void move_workspace_to(swayc_t* workspace, swayc_t* destination); |
54 | 54 | ||
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 @@ | |||
9 | 9 | ||
10 | struct cmd_results *cmd_move(int argc, char **argv) { | 10 | struct cmd_results *cmd_move(int argc, char **argv) { |
11 | struct cmd_results *error = NULL; | 11 | struct cmd_results *error = NULL; |
12 | int move_amt = 10; | ||
13 | |||
12 | if (config->reading) return cmd_results_new(CMD_FAILURE, "move", "Can't be used in config file."); | 14 | if (config->reading) return cmd_results_new(CMD_FAILURE, "move", "Can't be used in config file."); |
13 | if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) { | 15 | if ((error = checkarg(argc, "move", EXPECTED_AT_LEAST, 1))) { |
14 | return error; | 16 | return error; |
15 | } | 17 | } |
16 | const char* expected_syntax = "Expected 'move <left|right|up|down|next|prev|first>' or " | 18 | const char* expected_syntax = "Expected 'move <left|right|up|down|next|prev|first> <[px] px>' or " |
17 | "'move <container|window> to workspace <name>' or " | 19 | "'move <container|window> to workspace <name>' or " |
18 | "'move <container|window|workspace> to output <name|direction>' or " | 20 | "'move <container|window|workspace> to output <name|direction>' or " |
19 | "'move position mouse'"; | 21 | "'move position mouse'"; |
20 | swayc_t *view = get_focused_container(&root_container); | 22 | swayc_t *view = get_focused_container(&root_container); |
21 | 23 | ||
24 | if (argc == 2 || (argc == 3 && strcasecmp(argv[2], "px") == 0 )) { | ||
25 | char *inv; | ||
26 | move_amt = (int)strtol(argv[1], &inv, 10); | ||
27 | if (*inv != '\0' && strcasecmp(inv, "px") != 0) { | ||
28 | move_amt = 10; | ||
29 | } | ||
30 | } | ||
31 | |||
22 | if (strcasecmp(argv[0], "left") == 0) { | 32 | if (strcasecmp(argv[0], "left") == 0) { |
23 | move_container(view, MOVE_LEFT); | 33 | move_container(view, MOVE_LEFT, move_amt); |
24 | } else if (strcasecmp(argv[0], "right") == 0) { | 34 | } else if (strcasecmp(argv[0], "right") == 0) { |
25 | move_container(view, MOVE_RIGHT); | 35 | move_container(view, MOVE_RIGHT, move_amt); |
26 | } else if (strcasecmp(argv[0], "up") == 0) { | 36 | } else if (strcasecmp(argv[0], "up") == 0) { |
27 | move_container(view, MOVE_UP); | 37 | move_container(view, MOVE_UP, move_amt); |
28 | } else if (strcasecmp(argv[0], "down") == 0) { | 38 | } else if (strcasecmp(argv[0], "down") == 0) { |
29 | move_container(view, MOVE_DOWN); | 39 | move_container(view, MOVE_DOWN, move_amt); |
30 | } else if (strcasecmp(argv[0], "next") == 0) { | 40 | } else if (strcasecmp(argv[0], "next") == 0) { |
31 | move_container(view, MOVE_NEXT); | 41 | move_container(view, MOVE_NEXT, move_amt); |
32 | } else if (strcasecmp(argv[0], "prev") == 0) { | 42 | } else if (strcasecmp(argv[0], "prev") == 0) { |
33 | move_container(view, MOVE_PREV); | 43 | move_container(view, MOVE_PREV, move_amt); |
34 | } else if (strcasecmp(argv[0], "first") == 0) { | 44 | } else if (strcasecmp(argv[0], "first") == 0) { |
35 | move_container(view, MOVE_FIRST); | 45 | move_container(view, MOVE_FIRST, move_amt); |
36 | } else if (strcasecmp(argv[0], "container") == 0 || strcasecmp(argv[0], "window") == 0) { | 46 | } else if (strcasecmp(argv[0], "container") == 0 || strcasecmp(argv[0], "window") == 0) { |
37 | // "move container ... | 47 | // "move container ... |
38 | if ((error = checkarg(argc, "move container/window", EXPECTED_AT_LEAST, 4))) { | 48 | 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) { | |||
349 | } | 349 | } |
350 | } | 350 | } |
351 | 351 | ||
352 | void move_container(swayc_t *container, enum movement_direction dir) { | 352 | void move_container(swayc_t *container, enum movement_direction dir, int move_amt) { |
353 | enum swayc_layouts layout = L_NONE; | 353 | enum swayc_layouts layout = L_NONE; |
354 | swayc_t *parent = container->parent; | 354 | swayc_t *parent = container->parent; |
355 | if (container->is_floating || (container->type != C_VIEW && container->type != C_CONTAINER)) { | 355 | if (container->is_floating) { |
356 | swayc_t *output = swayc_parent_by_type(container, C_OUTPUT); | ||
357 | switch(dir) { | ||
358 | case MOVE_LEFT: | ||
359 | container->x = MAX(0, container->x - move_amt); | ||
360 | break; | ||
361 | case MOVE_RIGHT: | ||
362 | container->x = MIN(output->width - container->width, container->x + move_amt); | ||
363 | break; | ||
364 | case MOVE_UP: | ||
365 | container->y = MAX(0, container->y - move_amt); | ||
366 | break; | ||
367 | case MOVE_DOWN: | ||
368 | container->y = MIN(output->height - container->height, container->y + move_amt); | ||
369 | break; | ||
370 | default: | ||
371 | break; | ||
372 | } | ||
373 | update_geometry(container); | ||
374 | return; | ||
375 | } | ||
376 | if (container->type != C_VIEW && container->type != C_CONTAINER) { | ||
356 | return; | 377 | return; |
357 | } | 378 | } |
358 | if (dir == MOVE_UP || dir == MOVE_DOWN) { | 379 | if (dir == MOVE_UP || dir == MOVE_DOWN) { |
diff --git a/sway/sway.5.txt b/sway/sway.5.txt index 19f7eb1d..e403165f 100644 --- a/sway/sway.5.txt +++ b/sway/sway.5.txt | |||
@@ -100,11 +100,14 @@ They are expected to be used with **bindsym** or at runtime through **swaymsg**( | |||
100 | **layout** toggle split:: | 100 | **layout** toggle split:: |
101 | Cycles between available split layouts. | 101 | Cycles between available split layouts. |
102 | 102 | ||
103 | **move** <left|right|up|down|next|prev|first>:: | 103 | **move** <left|right|up|down> <[px] px>:: |
104 | Moves the focused container _left_, _right_, _up_, or _down_. Moving to _prev_ | 104 | Moves the focused container _left_, _right_, _up_, or _down_. If the window |
105 | or _next_ swaps the container with its sibling in the same container. Move | 105 | is floating it moves it _px_ in that direction. |
106 | _first_ exchanges the focused element in an auto layout with the first | 106 | |
107 | element, i.e. promotes the focused element to master position. | 107 | **move** <next|prev|first>:: |
108 | Moving to _prev_ or _next_ swaps the container with its sibling in the same | ||
109 | container. Move _first_ exchanges the focused element in an auto layout with | ||
110 | the first element, i.e. promotes the focused element to master position. | ||
108 | 111 | ||
109 | **move** <container|window> to workspace <name>:: | 112 | **move** <container|window> to workspace <name>:: |
110 | Moves the focused container to the workspace identified by _name_. | 113 | Moves the focused container to the workspace identified by _name_. |