aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/focus.c
diff options
context:
space:
mode:
authoremersion <contact@emersion.fr>2018-02-24 23:29:08 +0100
committerGitHub <noreply@github.com>2018-02-24 23:29:08 +0100
commit583c30dbe3e3249ec1b753fddbfa982db56dce31 (patch)
treece07d65ab79287280f1f5468e2e62eb5cbef4089 /sway/commands/focus.c
parentb28602aa7425cf435150e6008624429737e037d3 (diff)
parent1cca3965f395f624f698cc162946c6cbd6b10673 (diff)
downloadsway-583c30dbe3e3249ec1b753fddbfa982db56dce31.tar.xz
Merge pull request #1585 from acrisci/focus-overhaul
focus overhaul
Diffstat (limited to 'sway/commands/focus.c')
-rw-r--r--sway/commands/focus.c59
1 files changed, 59 insertions, 0 deletions
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);
+}