aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/exit.c3
-rw-r--r--sway/commands/focus.c59
-rw-r--r--sway/commands/kill.c7
-rw-r--r--sway/commands/layout.c56
-rw-r--r--sway/commands/reload.c3
-rw-r--r--sway/commands/set.c1
-rw-r--r--sway/commands/workspace.c3
7 files changed, 119 insertions, 13 deletions
diff --git a/sway/commands/exit.c b/sway/commands/exit.c
index 4bb6a97b..d5353c20 100644
--- a/sway/commands/exit.c
+++ b/sway/commands/exit.c
@@ -6,9 +6,6 @@ void sway_terminate(int exit_code);
struct cmd_results *cmd_exit(int argc, char **argv) {
struct cmd_results *error = NULL;
- if (config->reading) {
- return cmd_results_new(CMD_FAILURE, "exit", "Can't be used in config file.");
- }
if ((error = checkarg(argc, "exit", EXPECTED_EQUAL_TO, 0))) {
return error;
}
diff --git a/sway/commands/focus.c b/sway/commands/focus.c
new file mode 100644
index 00000000..f1a8078f
--- /dev/null
+++ b/sway/commands/focus.c
@@ -0,0 +1,59 @@
+#include <strings.h>
+#include <wlr/util/log.h>
+#include "log.h"
+#include "sway/input/input-manager.h"
+#include "sway/input/seat.h"
+#include "sway/view.h"
+#include "sway/commands.h"
+
+static bool parse_movement_direction(const char *name, enum movement_direction *out) {
+ if (strcasecmp(name, "left") == 0) {
+ *out = MOVE_LEFT;
+ } else if (strcasecmp(name, "right") == 0) {
+ *out = MOVE_RIGHT;
+ } else if (strcasecmp(name, "up") == 0) {
+ *out = MOVE_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;
+ } else if (strcasecmp(name, "next") == 0) {
+ *out = MOVE_NEXT;
+ } else if (strcasecmp(name, "prev") == 0) {
+ *out = MOVE_PREV;
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+struct cmd_results *cmd_focus(int argc, char **argv) {
+ swayc_t *con = config->handler_context.current_container;
+ struct sway_seat *seat = config->handler_context.seat;
+ if (con->type < C_WORKSPACE) {
+ return cmd_results_new(CMD_FAILURE, "focus",
+ "Command 'focus' cannot be used above the workspace level");
+ }
+
+ if (argc == 0) {
+ sway_seat_set_focus(seat, con);
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+ }
+
+ // TODO mode_toggle
+ enum movement_direction direction = 0;
+ if (!parse_movement_direction(argv[0], &direction)) {
+ return cmd_results_new(CMD_INVALID, "focus",
+ "Expected 'focus <direction|parent|child|mode_toggle>' or 'focus output <direction|name>'");
+ }
+
+ swayc_t *next_focus = get_swayc_in_direction(con, seat, direction);
+ if (next_focus) {
+ sway_seat_set_focus(seat, next_focus);
+ }
+
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/kill.c b/sway/commands/kill.c
index cebf7f3c..f408ce2a 100644
--- a/sway/commands/kill.c
+++ b/sway/commands/kill.c
@@ -6,15 +6,12 @@
#include "sway/commands.h"
struct cmd_results *cmd_kill(int argc, char **argv) {
- if (config->reading) {
- return cmd_results_new(CMD_FAILURE, "kill",
- "Command 'kill' cannot be used in the config file");
- }
enum swayc_types type = config->handler_context.current_container->type;
- if (type != C_VIEW || type != C_CONTAINER) {
+ if (type != C_VIEW && type != C_CONTAINER) {
return cmd_results_new(CMD_INVALID, NULL,
"Can only kill views and containers with this command");
}
+
// TODO close arbitrary containers without a view
struct sway_view *view =
config->handler_context.current_container->sway_view;
diff --git a/sway/commands/layout.c b/sway/commands/layout.c
new file mode 100644
index 00000000..b0fc5d66
--- /dev/null
+++ b/sway/commands/layout.c
@@ -0,0 +1,56 @@
+#include <string.h>
+#include <strings.h>
+#include "sway/commands.h"
+#include "sway/container.h"
+#include "sway/layout.h"
+#include "log.h"
+
+struct cmd_results *cmd_layout(int argc, char **argv) {
+ struct cmd_results *error = NULL;
+ if ((error = checkarg(argc, "layout", EXPECTED_MORE_THAN, 0))) {
+ return error;
+ }
+ swayc_t *parent = config->handler_context.current_container;
+
+ // TODO: floating
+ /*
+ if (parent->is_floating) {
+ return cmd_results_new(CMD_FAILURE, "layout", "Unable to change layout of floating windows");
+ }
+ */
+
+ while (parent->type == C_VIEW) {
+ parent = parent->parent;
+ }
+
+ // TODO: stacks and tabs
+
+ if (strcasecmp(argv[0], "default") == 0) {
+ swayc_change_layout(parent, parent->prev_layout);
+ if (parent->layout == L_NONE) {
+ swayc_t *output = swayc_parent_by_type(parent, C_OUTPUT);
+ swayc_change_layout(parent, default_layout(output));
+ }
+ } else {
+ if (parent->layout != L_TABBED && parent->layout != L_STACKED) {
+ parent->prev_layout = parent->layout;
+ }
+
+ if (strcasecmp(argv[0], "splith") == 0) {
+ swayc_change_layout(parent, L_HORIZ);
+ } else if (strcasecmp(argv[0], "splitv") == 0) {
+ swayc_change_layout(parent, L_VERT);
+ } else if (strcasecmp(argv[0], "toggle") == 0 && argc == 2 && strcasecmp(argv[1], "split") == 0) {
+ if (parent->layout == L_HORIZ && (parent->workspace_layout == L_NONE
+ || parent->workspace_layout == L_HORIZ)) {
+ swayc_change_layout(parent, L_VERT);
+ } else {
+ swayc_change_layout(parent, L_HORIZ);
+ }
+ }
+ }
+
+ arrange_windows(parent, parent->width, parent->height);
+
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
diff --git a/sway/commands/reload.c b/sway/commands/reload.c
index 419c7de3..d54d40db 100644
--- a/sway/commands/reload.c
+++ b/sway/commands/reload.c
@@ -4,9 +4,6 @@
struct cmd_results *cmd_reload(int argc, char **argv) {
struct cmd_results *error = NULL;
- if (config->reading) {
- return cmd_results_new(CMD_FAILURE, "reload", "Can't be used in config file.");
- }
if ((error = checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0))) {
return error;
}
diff --git a/sway/commands/set.c b/sway/commands/set.c
index 856c73e7..84e9b792 100644
--- a/sway/commands/set.c
+++ b/sway/commands/set.c
@@ -27,7 +27,6 @@ void free_sway_variable(struct sway_variable *var) {
struct cmd_results *cmd_set(int argc, char **argv) {
char *tmp;
struct cmd_results *error = NULL;
- if (!config->reading) return cmd_results_new(CMD_FAILURE, "set", "Can only be used in config file.");
if ((error = checkarg(argc, "set", EXPECTED_AT_LEAST, 2))) {
return error;
}
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index 12984ed4..fa891398 100644
--- a/sway/commands/workspace.c
+++ b/sway/commands/workspace.c
@@ -90,7 +90,8 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
free(name);
}
workspace_switch(ws);
- current_container = config->handler_context.seat->focus;
+ current_container =
+ sway_seat_get_focus(config->handler_context.seat);
swayc_t *new_output = swayc_parent_by_type(current_container, C_OUTPUT);
if (config->mouse_warping && old_output != new_output) {