mirror of
https://github.com/swaywm/sway.git
synced 2025-11-09 13:29:49 -05:00
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.
This commit is contained in:
parent
b90af33570
commit
7be309710d
7 changed files with 86 additions and 114 deletions
|
|
@ -81,14 +81,14 @@ static struct sway_output *output_in_direction(const char *direction_string,
|
|||
}
|
||||
|
||||
static bool is_parallel(enum sway_container_layout layout,
|
||||
enum movement_direction dir) {
|
||||
enum wlr_direction dir) {
|
||||
switch (layout) {
|
||||
case L_TABBED:
|
||||
case L_HORIZ:
|
||||
return dir == MOVE_LEFT || dir == MOVE_RIGHT;
|
||||
return dir == WLR_DIRECTION_LEFT || dir == WLR_DIRECTION_RIGHT;
|
||||
case L_STACKED:
|
||||
case L_VERT:
|
||||
return dir == MOVE_UP || dir == MOVE_DOWN;
|
||||
return dir == WLR_DIRECTION_UP || dir == WLR_DIRECTION_DOWN;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
@ -115,7 +115,7 @@ static void workspace_focus_fullscreen(struct sway_workspace *workspace) {
|
|||
|
||||
static void container_move_to_container_from_direction(
|
||||
struct sway_container *container, struct sway_container *destination,
|
||||
enum movement_direction move_dir) {
|
||||
enum wlr_direction move_dir) {
|
||||
if (destination->view) {
|
||||
if (destination->parent == container->parent &&
|
||||
destination->workspace == container->workspace) {
|
||||
|
|
@ -126,7 +126,8 @@ static void container_move_to_container_from_direction(
|
|||
list_swap(siblings, container_index, destination_index);
|
||||
} else {
|
||||
wlr_log(WLR_DEBUG, "Promoting to sibling of cousin");
|
||||
int offset = move_dir == MOVE_LEFT || move_dir == MOVE_UP;
|
||||
int offset =
|
||||
move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_UP;
|
||||
int index = container_sibling_index(destination) + offset;
|
||||
if (destination->parent) {
|
||||
container_insert_child(destination->parent, container, index);
|
||||
|
|
@ -141,7 +142,8 @@ static void container_move_to_container_from_direction(
|
|||
|
||||
if (is_parallel(destination->layout, move_dir)) {
|
||||
wlr_log(WLR_DEBUG, "Reparenting container (parallel)");
|
||||
int index = move_dir == MOVE_RIGHT || move_dir == MOVE_DOWN ?
|
||||
int index =
|
||||
move_dir == WLR_DIRECTION_RIGHT || move_dir == WLR_DIRECTION_DOWN ?
|
||||
0 : destination->children->length;
|
||||
container_insert_child(destination, container, index);
|
||||
container->width = container->height = 0;
|
||||
|
|
@ -164,10 +166,11 @@ static void container_move_to_container_from_direction(
|
|||
|
||||
static void container_move_to_workspace_from_direction(
|
||||
struct sway_container *container, struct sway_workspace *workspace,
|
||||
enum movement_direction move_dir) {
|
||||
enum wlr_direction move_dir) {
|
||||
if (is_parallel(workspace->layout, move_dir)) {
|
||||
wlr_log(WLR_DEBUG, "Reparenting container (parallel)");
|
||||
int index = move_dir == MOVE_RIGHT || move_dir == MOVE_DOWN ?
|
||||
int index =
|
||||
move_dir == WLR_DIRECTION_RIGHT || move_dir == WLR_DIRECTION_DOWN ?
|
||||
0 : workspace->tiling->length;
|
||||
workspace_insert_tiling(workspace, container, index);
|
||||
return;
|
||||
|
|
@ -258,28 +261,31 @@ static void container_move_to_container(struct sway_container *container,
|
|||
* container, switches the layout of the workspace, and drops the child back in.
|
||||
* In other words, rejigger it. */
|
||||
static void workspace_rejigger(struct sway_workspace *ws,
|
||||
struct sway_container *child, enum movement_direction move_dir) {
|
||||
struct sway_container *child, enum wlr_direction move_dir) {
|
||||
if (!child->parent && ws->tiling->length == 1) {
|
||||
ws->layout =
|
||||
move_dir == MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT;
|
||||
move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_RIGHT ?
|
||||
L_HORIZ : L_VERT;
|
||||
workspace_update_representation(ws);
|
||||
return;
|
||||
}
|
||||
container_detach(child);
|
||||
struct sway_container *new_parent = workspace_wrap_children(ws);
|
||||
|
||||
int index = move_dir == MOVE_LEFT || move_dir == MOVE_UP ? 0 : 1;
|
||||
int index =
|
||||
move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_UP ? 0 : 1;
|
||||
workspace_insert_tiling(ws, child, index);
|
||||
container_flatten(new_parent);
|
||||
ws->layout =
|
||||
move_dir == MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT;
|
||||
move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_RIGHT ?
|
||||
L_HORIZ : L_VERT;
|
||||
workspace_update_representation(ws);
|
||||
child->width = child->height = 0;
|
||||
}
|
||||
|
||||
// Returns true if moved
|
||||
static bool container_move_in_direction(struct sway_container *container,
|
||||
enum movement_direction move_dir) {
|
||||
enum wlr_direction move_dir) {
|
||||
// If moving a fullscreen view, only consider outputs
|
||||
if (container->is_fullscreen) {
|
||||
struct sway_output *new_output =
|
||||
|
|
@ -305,7 +311,8 @@ static bool container_move_in_direction(struct sway_container *container,
|
|||
// The below loop stops once we hit the workspace because current->parent
|
||||
// is NULL for the topmost containers in a workspace.
|
||||
struct sway_container *current = container;
|
||||
int offs = move_dir == MOVE_LEFT || move_dir == MOVE_UP ? -1 : 1;
|
||||
int offs =
|
||||
move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_UP ? -1 : 1;
|
||||
|
||||
while (current) {
|
||||
list_t *siblings = container_get_siblings(current);
|
||||
|
|
@ -642,7 +649,7 @@ static struct cmd_results *cmd_move_workspace(int argc, char **argv) {
|
|||
}
|
||||
|
||||
static struct cmd_results *cmd_move_in_direction(
|
||||
enum movement_direction direction, int argc, char **argv) {
|
||||
enum wlr_direction direction, int argc, char **argv) {
|
||||
int move_amt = 10;
|
||||
if (argc > 1) {
|
||||
char *inv;
|
||||
|
|
@ -666,22 +673,18 @@ static struct cmd_results *cmd_move_in_direction(
|
|||
double lx = container->x;
|
||||
double ly = container->y;
|
||||
switch (direction) {
|
||||
case MOVE_LEFT:
|
||||
case WLR_DIRECTION_LEFT:
|
||||
lx -= move_amt;
|
||||
break;
|
||||
case MOVE_RIGHT:
|
||||
case WLR_DIRECTION_RIGHT:
|
||||
lx += move_amt;
|
||||
break;
|
||||
case MOVE_UP:
|
||||
case WLR_DIRECTION_UP:
|
||||
ly -= move_amt;
|
||||
break;
|
||||
case MOVE_DOWN:
|
||||
case WLR_DIRECTION_DOWN:
|
||||
ly += move_amt;
|
||||
break;
|
||||
case MOVE_PARENT:
|
||||
case MOVE_CHILD:
|
||||
return cmd_results_new(CMD_FAILURE, "move",
|
||||
"Cannot move floating container to parent or child");
|
||||
}
|
||||
container_floating_move_to(container, lx, ly);
|
||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||
|
|
@ -850,13 +853,13 @@ struct cmd_results *cmd_move(int argc, char **argv) {
|
|||
}
|
||||
|
||||
if (strcasecmp(argv[0], "left") == 0) {
|
||||
return cmd_move_in_direction(MOVE_LEFT, argc, argv);
|
||||
return cmd_move_in_direction(WLR_DIRECTION_LEFT, argc, argv);
|
||||
} else if (strcasecmp(argv[0], "right") == 0) {
|
||||
return cmd_move_in_direction(MOVE_RIGHT, argc, argv);
|
||||
return cmd_move_in_direction(WLR_DIRECTION_RIGHT, argc, argv);
|
||||
} else if (strcasecmp(argv[0], "up") == 0) {
|
||||
return cmd_move_in_direction(MOVE_UP, argc, argv);
|
||||
return cmd_move_in_direction(WLR_DIRECTION_UP, argc, argv);
|
||||
} else if (strcasecmp(argv[0], "down") == 0) {
|
||||
return cmd_move_in_direction(MOVE_DOWN, argc, argv);
|
||||
return cmd_move_in_direction(WLR_DIRECTION_DOWN, argc, argv);
|
||||
} else if ((strcasecmp(argv[0], "container") == 0
|
||||
|| strcasecmp(argv[0], "window") == 0) ||
|
||||
(strcasecmp(argv[0], "--no-auto-back-and-forth") && argc >= 2
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue