diff options
-rw-r--r-- | sway/commands/focus.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/sway/commands/focus.c b/sway/commands/focus.c index 5286851f..ba47d1e1 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c | |||
@@ -1,3 +1,4 @@ | |||
1 | #include <strings.h> | ||
1 | #include <wlr/util/log.h> | 2 | #include <wlr/util/log.h> |
2 | #include "log.h" | 3 | #include "log.h" |
3 | #include "sway/input/input-manager.h" | 4 | #include "sway/input/input-manager.h" |
@@ -5,6 +6,30 @@ | |||
5 | #include "sway/view.h" | 6 | #include "sway/view.h" |
6 | #include "sway/commands.h" | 7 | #include "sway/commands.h" |
7 | 8 | ||
9 | static bool parse_movement_direction(const char *name, enum movement_direction *out) { | ||
10 | if (strcasecmp(name, "left") == 0) { | ||
11 | *out = MOVE_LEFT; | ||
12 | } else if (strcasecmp(name, "right") == 0) { | ||
13 | *out = MOVE_RIGHT; | ||
14 | } else if (strcasecmp(name, "up") == 0) { | ||
15 | *out = MOVE_UP; | ||
16 | } else if (strcasecmp(name, "down") == 0) { | ||
17 | *out = MOVE_DOWN; | ||
18 | } else if (strcasecmp(name, "parent") == 0) { | ||
19 | *out = MOVE_PARENT; | ||
20 | } else if (strcasecmp(name, "child") == 0) { | ||
21 | *out = MOVE_CHILD; | ||
22 | } else if (strcasecmp(name, "next") == 0) { | ||
23 | *out = MOVE_NEXT; | ||
24 | } else if (strcasecmp(name, "prev") == 0) { | ||
25 | *out = MOVE_PREV; | ||
26 | } else { | ||
27 | return false; | ||
28 | } | ||
29 | |||
30 | return true; | ||
31 | } | ||
32 | |||
8 | struct cmd_results *cmd_focus(int argc, char **argv) { | 33 | struct cmd_results *cmd_focus(int argc, char **argv) { |
9 | swayc_t *con = config->handler_context.current_container; | 34 | swayc_t *con = config->handler_context.current_container; |
10 | struct sway_seat *seat = config->handler_context.seat; | 35 | struct sway_seat *seat = config->handler_context.seat; |
@@ -22,11 +47,27 @@ struct cmd_results *cmd_focus(int argc, char **argv) { | |||
22 | wlr_log(L_DEBUG, "no container to focus"); | 47 | wlr_log(L_DEBUG, "no container to focus"); |
23 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 48 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
24 | } | 49 | } |
50 | if (con->type < C_WORKSPACE) { | ||
51 | return cmd_results_new(CMD_FAILURE, "focus", | ||
52 | "Command 'focus' cannot be used above the workspace level"); | ||
53 | } | ||
25 | 54 | ||
26 | if (argc == 0) { | 55 | if (argc == 0) { |
27 | sway_seat_set_focus(seat, con); | 56 | sway_seat_set_focus(seat, con); |
28 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 57 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
29 | } | 58 | } |
30 | 59 | ||
60 | // TODO mode_toggle | ||
61 | enum movement_direction direction = 0; | ||
62 | if (!parse_movement_direction(argv[0], &direction)) { | ||
63 | return cmd_results_new(CMD_INVALID, "focus", | ||
64 | "Expected 'focus <direction|parent|child|mode_toggle>' or 'focus output <direction|name>'"); | ||
65 | } | ||
66 | |||
67 | swayc_t *next_focus = get_swayc_in_direction(con, seat, direction); | ||
68 | if (next_focus) { | ||
69 | sway_seat_set_focus(seat, next_focus); | ||
70 | } | ||
71 | |||
31 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 72 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
32 | } | 73 | } |