aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/util.c21
-rw-r--r--include/sway/output.h2
-rw-r--r--include/sway/tree/container.h3
-rw-r--r--include/util.h11
-rw-r--r--sway/commands/focus.c98
-rw-r--r--sway/commands/move.c57
-rw-r--r--sway/tree/output.c8
7 files changed, 86 insertions, 114 deletions
diff --git a/common/util.c b/common/util.c
index 561b3804..467aa4b5 100644
--- a/common/util.c
+++ b/common/util.c
@@ -175,24 +175,3 @@ failed:
free(current);
return NULL;
}
-
-bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out) {
- switch (dir) {
- case MOVE_UP:
- *out = WLR_DIRECTION_UP;
- break;
- case MOVE_DOWN:
- *out = WLR_DIRECTION_DOWN;
- break;
- case MOVE_LEFT:
- *out = WLR_DIRECTION_LEFT;
- break;
- case MOVE_RIGHT:
- *out = WLR_DIRECTION_RIGHT;
- break;
- default:
- return false;
- }
-
- return true;
-}
diff --git a/include/sway/output.h b/include/sway/output.h
index 22cb352a..5efe1660 100644
--- a/include/sway/output.h
+++ b/include/sway/output.h
@@ -62,7 +62,7 @@ void output_begin_destroy(struct sway_output *output);
struct sway_output *output_from_wlr_output(struct wlr_output *output);
struct sway_output *output_get_in_direction(struct sway_output *reference,
- enum movement_direction direction);
+ enum wlr_direction direction);
void output_add_workspace(struct sway_output *output,
struct sway_workspace *workspace);
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index 920ef038..1dd23341 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -36,7 +36,6 @@ struct sway_output;
struct sway_workspace;
struct sway_view;
-enum movement_direction;
enum wlr_direction;
struct sway_container_state {
@@ -287,8 +286,6 @@ void container_detach(struct sway_container *child);
void container_replace(struct sway_container *container,
struct sway_container *replacement);
-bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out);
-
struct sway_container *container_split(struct sway_container *child,
enum sway_container_layout layout);
diff --git a/include/util.h b/include/util.h
index 19d2e7cf..c39c92b1 100644
--- a/include/util.h
+++ b/include/util.h
@@ -7,15 +7,6 @@
#include <wlr/types/wlr_output_layout.h>
#include <xkbcommon/xkbcommon.h>
-enum movement_direction {
- MOVE_LEFT,
- MOVE_RIGHT,
- MOVE_UP,
- MOVE_DOWN,
- MOVE_PARENT,
- MOVE_CHILD,
-};
-
/**
* Wrap i into the range [0, max[
*/
@@ -77,6 +68,4 @@ bool parse_boolean(const char *boolean, bool current);
*/
char* resolve_path(const char* path);
-bool sway_dir_to_wlr(enum movement_direction dir, enum wlr_direction *out);
-
#endif
diff --git a/sway/commands/focus.c b/sway/commands/focus.c
index 2204f722..521b2427 100644
--- a/sway/commands/focus.c
+++ b/sway/commands/focus.c
@@ -1,4 +1,5 @@
#include <strings.h>
+#include <wlr/types/wlr_output_layout.h>
#include <wlr/util/log.h>
#include "log.h"
#include "sway/commands.h"
@@ -13,20 +14,16 @@
#include "stringop.h"
#include "util.h"
-static bool parse_movement_direction(const char *name,
- enum movement_direction *out) {
+static bool parse_direction(const char *name,
+ enum wlr_direction *out) {
if (strcasecmp(name, "left") == 0) {
- *out = MOVE_LEFT;
+ *out = WLR_DIRECTION_LEFT;
} else if (strcasecmp(name, "right") == 0) {
- *out = MOVE_RIGHT;
+ *out = WLR_DIRECTION_RIGHT;
} else if (strcasecmp(name, "up") == 0) {
- *out = MOVE_UP;
+ *out = WLR_DIRECTION_UP;
} else if (strcasecmp(name, "down") == 0) {
- *out = MOVE_DOWN;
- } else if (strcasecmp(name, "parent") == 0) {
- *out = MOVE_PARENT;
- } else if (strcasecmp(name, "child") == 0) {
- *out = MOVE_CHILD;
+ *out = WLR_DIRECTION_DOWN;
} else {
return false;
}
@@ -38,7 +35,7 @@ static bool parse_movement_direction(const char *name,
* Get node in the direction of newly entered output.
*/
static struct sway_node *get_node_in_output_direction(
- struct sway_output *output, enum movement_direction dir) {
+ struct sway_output *output, enum wlr_direction dir) {
struct sway_seat *seat = config->handler_context.seat;
struct sway_workspace *ws = output_get_active_workspace(output);
if (ws->fullscreen) {
@@ -48,7 +45,7 @@ static struct sway_node *get_node_in_output_direction(
if (ws->tiling->length > 0) {
switch (dir) {
- case MOVE_LEFT:
+ case WLR_DIRECTION_LEFT:
if (ws->layout == L_HORIZ || ws->layout == L_TABBED) {
// get most right child of new output
container = ws->tiling->items[ws->tiling->length-1];
@@ -56,7 +53,7 @@ static struct sway_node *get_node_in_output_direction(
container = seat_get_focus_inactive_tiling(seat, ws);
}
break;
- case MOVE_RIGHT:
+ case WLR_DIRECTION_RIGHT:
if (ws->layout == L_HORIZ || ws->layout == L_TABBED) {
// get most left child of new output
container = ws->tiling->items[0];
@@ -64,7 +61,7 @@ static struct sway_node *get_node_in_output_direction(
container = seat_get_focus_inactive_tiling(seat, ws);
}
break;
- case MOVE_UP:
+ case WLR_DIRECTION_UP:
if (ws->layout == L_VERT || ws->layout == L_STACKED) {
// get most bottom child of new output
container = ws->tiling->items[ws->tiling->length-1];
@@ -72,7 +69,7 @@ static struct sway_node *get_node_in_output_direction(
container = seat_get_focus_inactive_tiling(seat, ws);
}
break;
- case MOVE_DOWN: {
+ case WLR_DIRECTION_DOWN:
if (ws->layout == L_VERT || ws->layout == L_STACKED) {
// get most top child of new output
container = ws->tiling->items[0];
@@ -81,9 +78,6 @@ static struct sway_node *get_node_in_output_direction(
}
break;
}
- default:
- break;
- }
}
if (container) {
@@ -95,11 +89,8 @@ static struct sway_node *get_node_in_output_direction(
}
static struct sway_node *node_get_in_direction(struct sway_container *container,
- struct sway_seat *seat, enum movement_direction dir) {
+ struct sway_seat *seat, enum wlr_direction dir) {
if (container->is_fullscreen) {
- if (dir == MOVE_PARENT) {
- return NULL;
- }
// Fullscreen container with a direction - go straight to outputs
struct sway_output *output = container->workspace->output;
struct sway_output *new_output = output_get_in_direction(output, dir);
@@ -108,9 +99,6 @@ static struct sway_node *node_get_in_direction(struct sway_container *container,
}
return get_node_in_output_direction(new_output, dir);
}
- if (dir == MOVE_PARENT) {
- return node_get_parent(&container->node);
- }
struct sway_container *wrap_candidate = NULL;
struct sway_container *current = container;
@@ -122,15 +110,15 @@ static struct sway_node *node_get_in_direction(struct sway_container *container,
container_parent_layout(current);
list_t *siblings = container_get_siblings(current);
- if (dir == MOVE_LEFT || dir == MOVE_RIGHT) {
+ if (dir == WLR_DIRECTION_LEFT || dir == WLR_DIRECTION_RIGHT) {
if (parent_layout == L_HORIZ || parent_layout == L_TABBED) {
can_move = true;
- desired = idx + (dir == MOVE_LEFT ? -1 : 1);
+ desired = idx + (dir == WLR_DIRECTION_LEFT ? -1 : 1);
}
} else {
if (parent_layout == L_VERT || parent_layout == L_STACKED) {
can_move = true;
- desired = idx + (dir == MOVE_UP ? -1 : 1);
+ desired = idx + (dir == WLR_DIRECTION_UP ? -1 : 1);
}
}
@@ -200,9 +188,8 @@ static struct cmd_results *focus_output(struct sway_seat *seat,
struct sway_output *output = output_by_name(identifier);
if (!output) {
- enum movement_direction direction;
- if (!parse_movement_direction(identifier, &direction) ||
- direction == MOVE_PARENT || direction == MOVE_CHILD) {
+ enum wlr_direction direction;
+ if (!parse_direction(identifier, &direction)) {
free(identifier);
return cmd_results_new(CMD_INVALID, "focus",
"There is no output with that name");
@@ -220,6 +207,31 @@ static struct cmd_results *focus_output(struct sway_seat *seat,
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
+static struct cmd_results *focus_parent(void) {
+ struct sway_seat *seat = config->handler_context.seat;
+ struct sway_container *con = config->handler_context.container;
+ if (!con || con->is_fullscreen) {
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+ }
+ struct sway_node *parent = node_get_parent(&con->node);
+ if (parent) {
+ seat_set_focus(seat, parent);
+ seat_consider_warp_to_focus(seat);
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
+
+static struct cmd_results *focus_child(void) {
+ struct sway_seat *seat = config->handler_context.seat;
+ struct sway_node *node = config->handler_context.node;
+ struct sway_node *focus = seat_get_active_tiling_child(seat, node);
+ if (focus) {
+ seat_set_focus(seat, focus);
+ seat_consider_warp_to_focus(seat);
+ }
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
+
struct cmd_results *cmd_focus(int argc, char **argv) {
if (config->reading || !config->active) {
return cmd_results_new(CMD_DEFER, NULL, NULL);
@@ -257,27 +269,21 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
return focus_output(seat, argc, argv);
}
- enum movement_direction direction = 0;
- if (!parse_movement_direction(argv[0], &direction)) {
+ if (strcasecmp(argv[0], "parent") == 0) {
+ return focus_parent();
+ }
+ if (strcasecmp(argv[0], "child") == 0) {
+ return focus_child();
+ }
+
+ enum wlr_direction direction = 0;
+ if (!parse_direction(argv[0], &direction)) {
return cmd_results_new(CMD_INVALID, "focus",
"Expected 'focus <direction|parent|child|mode_toggle|floating|tiling>' "
"or 'focus output <direction|name>'");
}
- if (direction == MOVE_CHILD) {
- struct sway_node *focus = seat_get_active_tiling_child(seat, node);
- if (focus) {
- seat_set_focus(seat, focus);
- seat_consider_warp_to_focus(seat);
- }
- return cmd_results_new(CMD_SUCCESS, NULL, NULL);
- }
-
if (node->type == N_WORKSPACE) {
- if (direction == MOVE_PARENT) {
- return cmd_results_new(CMD_SUCCESS, NULL, NULL);
- }
-
// Jump to the next output
struct sway_output *new_output =
output_get_in_direction(workspace->output, direction);
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,
}
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
diff --git a/sway/tree/output.c b/sway/tree/output.c
index 632501e1..b84053d9 100644
--- a/sway/tree/output.c
+++ b/sway/tree/output.c
@@ -274,16 +274,14 @@ struct sway_output *output_from_wlr_output(struct wlr_output *output) {
}
struct sway_output *output_get_in_direction(struct sway_output *reference,
- enum movement_direction direction) {
- enum wlr_direction wlr_dir = 0;
- if (!sway_assert(sway_dir_to_wlr(direction, &wlr_dir),
- "got invalid direction: %d", direction)) {
+ enum wlr_direction direction) {
+ if (!sway_assert(direction, "got invalid direction: %d", direction)) {
return NULL;
}
int lx = reference->wlr_output->lx + reference->width / 2;
int ly = reference->wlr_output->ly + reference->height / 2;
struct wlr_output *wlr_adjacent = wlr_output_layout_adjacent_output(
- root->output_layout, wlr_dir, reference->wlr_output, lx, ly);
+ root->output_layout, direction, reference->wlr_output, lx, ly);
if (!wlr_adjacent) {
return NULL;
}