diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-10-30 23:27:49 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-10-30 23:27:49 +1000 |
commit | 7be309710dcd679e0b570bc2f076ac00ae9ad65d (patch) | |
tree | 66f53dddfcd94217beedf25272fe427a34ab665f /sway/commands/move.c | |
parent | Merge pull request #3020 from emersion/swaymsg-return-status (diff) | |
download | sway-7be309710dcd679e0b570bc2f076ac00ae9ad65d.tar.gz sway-7be309710dcd679e0b570bc2f076ac00ae9ad65d.tar.zst sway-7be309710dcd679e0b570bc2f076ac00ae9ad65d.zip |
Remove enum movement_direction
There's no point having both movement_direction and wlr_direction. This
replaces the former with the latter.
As movement_direction also contained MOVE_PARENT and MOVE_CHILD items,
these are now checked specifically in the focus command and handled in
separate functions, just like the other focus variants.
Diffstat (limited to 'sway/commands/move.c')
-rw-r--r-- | sway/commands/move.c | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c index ffe12d41..30c198e4 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c | |||
@@ -81,14 +81,14 @@ static struct sway_output *output_in_direction(const char *direction_string, | |||
81 | } | 81 | } |
82 | 82 | ||
83 | static bool is_parallel(enum sway_container_layout layout, | 83 | static bool is_parallel(enum sway_container_layout layout, |
84 | enum movement_direction dir) { | 84 | enum wlr_direction dir) { |
85 | switch (layout) { | 85 | switch (layout) { |
86 | case L_TABBED: | 86 | case L_TABBED: |
87 | case L_HORIZ: | 87 | case L_HORIZ: |
88 | return dir == MOVE_LEFT || dir == MOVE_RIGHT; | 88 | return dir == WLR_DIRECTION_LEFT || dir == WLR_DIRECTION_RIGHT; |
89 | case L_STACKED: | 89 | case L_STACKED: |
90 | case L_VERT: | 90 | case L_VERT: |
91 | return dir == MOVE_UP || dir == MOVE_DOWN; | 91 | return dir == WLR_DIRECTION_UP || dir == WLR_DIRECTION_DOWN; |
92 | default: | 92 | default: |
93 | return false; | 93 | return false; |
94 | } | 94 | } |
@@ -115,7 +115,7 @@ static void workspace_focus_fullscreen(struct sway_workspace *workspace) { | |||
115 | 115 | ||
116 | static void container_move_to_container_from_direction( | 116 | static void container_move_to_container_from_direction( |
117 | struct sway_container *container, struct sway_container *destination, | 117 | struct sway_container *container, struct sway_container *destination, |
118 | enum movement_direction move_dir) { | 118 | enum wlr_direction move_dir) { |
119 | if (destination->view) { | 119 | if (destination->view) { |
120 | if (destination->parent == container->parent && | 120 | if (destination->parent == container->parent && |
121 | destination->workspace == container->workspace) { | 121 | destination->workspace == container->workspace) { |
@@ -126,7 +126,8 @@ static void container_move_to_container_from_direction( | |||
126 | list_swap(siblings, container_index, destination_index); | 126 | list_swap(siblings, container_index, destination_index); |
127 | } else { | 127 | } else { |
128 | wlr_log(WLR_DEBUG, "Promoting to sibling of cousin"); | 128 | wlr_log(WLR_DEBUG, "Promoting to sibling of cousin"); |
129 | int offset = move_dir == MOVE_LEFT || move_dir == MOVE_UP; | 129 | int offset = |
130 | move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_UP; | ||
130 | int index = container_sibling_index(destination) + offset; | 131 | int index = container_sibling_index(destination) + offset; |
131 | if (destination->parent) { | 132 | if (destination->parent) { |
132 | container_insert_child(destination->parent, container, index); | 133 | container_insert_child(destination->parent, container, index); |
@@ -141,7 +142,8 @@ static void container_move_to_container_from_direction( | |||
141 | 142 | ||
142 | if (is_parallel(destination->layout, move_dir)) { | 143 | if (is_parallel(destination->layout, move_dir)) { |
143 | wlr_log(WLR_DEBUG, "Reparenting container (parallel)"); | 144 | wlr_log(WLR_DEBUG, "Reparenting container (parallel)"); |
144 | int index = move_dir == MOVE_RIGHT || move_dir == MOVE_DOWN ? | 145 | int index = |
146 | move_dir == WLR_DIRECTION_RIGHT || move_dir == WLR_DIRECTION_DOWN ? | ||
145 | 0 : destination->children->length; | 147 | 0 : destination->children->length; |
146 | container_insert_child(destination, container, index); | 148 | container_insert_child(destination, container, index); |
147 | container->width = container->height = 0; | 149 | container->width = container->height = 0; |
@@ -164,10 +166,11 @@ static void container_move_to_container_from_direction( | |||
164 | 166 | ||
165 | static void container_move_to_workspace_from_direction( | 167 | static void container_move_to_workspace_from_direction( |
166 | struct sway_container *container, struct sway_workspace *workspace, | 168 | struct sway_container *container, struct sway_workspace *workspace, |
167 | enum movement_direction move_dir) { | 169 | enum wlr_direction move_dir) { |
168 | if (is_parallel(workspace->layout, move_dir)) { | 170 | if (is_parallel(workspace->layout, move_dir)) { |
169 | wlr_log(WLR_DEBUG, "Reparenting container (parallel)"); | 171 | wlr_log(WLR_DEBUG, "Reparenting container (parallel)"); |
170 | int index = move_dir == MOVE_RIGHT || move_dir == MOVE_DOWN ? | 172 | int index = |
173 | move_dir == WLR_DIRECTION_RIGHT || move_dir == WLR_DIRECTION_DOWN ? | ||
171 | 0 : workspace->tiling->length; | 174 | 0 : workspace->tiling->length; |
172 | workspace_insert_tiling(workspace, container, index); | 175 | workspace_insert_tiling(workspace, container, index); |
173 | return; | 176 | return; |
@@ -258,28 +261,31 @@ static void container_move_to_container(struct sway_container *container, | |||
258 | * container, switches the layout of the workspace, and drops the child back in. | 261 | * container, switches the layout of the workspace, and drops the child back in. |
259 | * In other words, rejigger it. */ | 262 | * In other words, rejigger it. */ |
260 | static void workspace_rejigger(struct sway_workspace *ws, | 263 | static void workspace_rejigger(struct sway_workspace *ws, |
261 | struct sway_container *child, enum movement_direction move_dir) { | 264 | struct sway_container *child, enum wlr_direction move_dir) { |
262 | if (!child->parent && ws->tiling->length == 1) { | 265 | if (!child->parent && ws->tiling->length == 1) { |
263 | ws->layout = | 266 | ws->layout = |
264 | move_dir == MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT; | 267 | move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_RIGHT ? |
268 | L_HORIZ : L_VERT; | ||
265 | workspace_update_representation(ws); | 269 | workspace_update_representation(ws); |
266 | return; | 270 | return; |
267 | } | 271 | } |
268 | container_detach(child); | 272 | container_detach(child); |
269 | struct sway_container *new_parent = workspace_wrap_children(ws); | 273 | struct sway_container *new_parent = workspace_wrap_children(ws); |
270 | 274 | ||
271 | int index = move_dir == MOVE_LEFT || move_dir == MOVE_UP ? 0 : 1; | 275 | int index = |
276 | move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_UP ? 0 : 1; | ||
272 | workspace_insert_tiling(ws, child, index); | 277 | workspace_insert_tiling(ws, child, index); |
273 | container_flatten(new_parent); | 278 | container_flatten(new_parent); |
274 | ws->layout = | 279 | ws->layout = |
275 | move_dir == MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT; | 280 | move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_RIGHT ? |
281 | L_HORIZ : L_VERT; | ||
276 | workspace_update_representation(ws); | 282 | workspace_update_representation(ws); |
277 | child->width = child->height = 0; | 283 | child->width = child->height = 0; |
278 | } | 284 | } |
279 | 285 | ||
280 | // Returns true if moved | 286 | // Returns true if moved |
281 | static bool container_move_in_direction(struct sway_container *container, | 287 | static bool container_move_in_direction(struct sway_container *container, |
282 | enum movement_direction move_dir) { | 288 | enum wlr_direction move_dir) { |
283 | // If moving a fullscreen view, only consider outputs | 289 | // If moving a fullscreen view, only consider outputs |
284 | if (container->is_fullscreen) { | 290 | if (container->is_fullscreen) { |
285 | struct sway_output *new_output = | 291 | struct sway_output *new_output = |
@@ -305,7 +311,8 @@ static bool container_move_in_direction(struct sway_container *container, | |||
305 | // The below loop stops once we hit the workspace because current->parent | 311 | // The below loop stops once we hit the workspace because current->parent |
306 | // is NULL for the topmost containers in a workspace. | 312 | // is NULL for the topmost containers in a workspace. |
307 | struct sway_container *current = container; | 313 | struct sway_container *current = container; |
308 | int offs = move_dir == MOVE_LEFT || move_dir == MOVE_UP ? -1 : 1; | 314 | int offs = |
315 | move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_UP ? -1 : 1; | ||
309 | 316 | ||
310 | while (current) { | 317 | while (current) { |
311 | list_t *siblings = container_get_siblings(current); | 318 | list_t *siblings = container_get_siblings(current); |
@@ -642,7 +649,7 @@ static struct cmd_results *cmd_move_workspace(int argc, char **argv) { | |||
642 | } | 649 | } |
643 | 650 | ||
644 | static struct cmd_results *cmd_move_in_direction( | 651 | static struct cmd_results *cmd_move_in_direction( |
645 | enum movement_direction direction, int argc, char **argv) { | 652 | enum wlr_direction direction, int argc, char **argv) { |
646 | int move_amt = 10; | 653 | int move_amt = 10; |
647 | if (argc > 1) { | 654 | if (argc > 1) { |
648 | char *inv; | 655 | char *inv; |
@@ -666,22 +673,18 @@ static struct cmd_results *cmd_move_in_direction( | |||
666 | double lx = container->x; | 673 | double lx = container->x; |
667 | double ly = container->y; | 674 | double ly = container->y; |
668 | switch (direction) { | 675 | switch (direction) { |
669 | case MOVE_LEFT: | 676 | case WLR_DIRECTION_LEFT: |
670 | lx -= move_amt; | 677 | lx -= move_amt; |
671 | break; | 678 | break; |
672 | case MOVE_RIGHT: | 679 | case WLR_DIRECTION_RIGHT: |
673 | lx += move_amt; | 680 | lx += move_amt; |
674 | break; | 681 | break; |
675 | case MOVE_UP: | 682 | case WLR_DIRECTION_UP: |
676 | ly -= move_amt; | 683 | ly -= move_amt; |
677 | break; | 684 | break; |
678 | case MOVE_DOWN: | 685 | case WLR_DIRECTION_DOWN: |
679 | ly += move_amt; | 686 | ly += move_amt; |
680 | break; | 687 | break; |
681 | case MOVE_PARENT: | ||
682 | case MOVE_CHILD: | ||
683 | return cmd_results_new(CMD_FAILURE, "move", | ||
684 | "Cannot move floating container to parent or child"); | ||
685 | } | 688 | } |
686 | container_floating_move_to(container, lx, ly); | 689 | container_floating_move_to(container, lx, ly); |
687 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 690 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
@@ -850,13 +853,13 @@ struct cmd_results *cmd_move(int argc, char **argv) { | |||
850 | } | 853 | } |
851 | 854 | ||
852 | if (strcasecmp(argv[0], "left") == 0) { | 855 | if (strcasecmp(argv[0], "left") == 0) { |
853 | return cmd_move_in_direction(MOVE_LEFT, argc, argv); | 856 | return cmd_move_in_direction(WLR_DIRECTION_LEFT, argc, argv); |
854 | } else if (strcasecmp(argv[0], "right") == 0) { | 857 | } else if (strcasecmp(argv[0], "right") == 0) { |
855 | return cmd_move_in_direction(MOVE_RIGHT, argc, argv); | 858 | return cmd_move_in_direction(WLR_DIRECTION_RIGHT, argc, argv); |
856 | } else if (strcasecmp(argv[0], "up") == 0) { | 859 | } else if (strcasecmp(argv[0], "up") == 0) { |
857 | return cmd_move_in_direction(MOVE_UP, argc, argv); | 860 | return cmd_move_in_direction(WLR_DIRECTION_UP, argc, argv); |
858 | } else if (strcasecmp(argv[0], "down") == 0) { | 861 | } else if (strcasecmp(argv[0], "down") == 0) { |
859 | return cmd_move_in_direction(MOVE_DOWN, argc, argv); | 862 | return cmd_move_in_direction(WLR_DIRECTION_DOWN, argc, argv); |
860 | } else if ((strcasecmp(argv[0], "container") == 0 | 863 | } else if ((strcasecmp(argv[0], "container") == 0 |
861 | || strcasecmp(argv[0], "window") == 0) || | 864 | || strcasecmp(argv[0], "window") == 0) || |
862 | (strcasecmp(argv[0], "--no-auto-back-and-forth") && argc >= 2 | 865 | (strcasecmp(argv[0], "--no-auto-back-and-forth") && argc >= 2 |