diff options
Diffstat (limited to 'sway/commands/focus.c')
-rw-r--r-- | sway/commands/focus.c | 59 |
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 @@ | |||
1 | #include <strings.h> | ||
2 | #include <wlr/util/log.h> | ||
3 | #include "log.h" | ||
4 | #include "sway/input/input-manager.h" | ||
5 | #include "sway/input/seat.h" | ||
6 | #include "sway/view.h" | ||
7 | #include "sway/commands.h" | ||
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 | |||
33 | struct cmd_results *cmd_focus(int argc, char **argv) { | ||
34 | swayc_t *con = config->handler_context.current_container; | ||
35 | struct sway_seat *seat = config->handler_context.seat; | ||
36 | if (con->type < C_WORKSPACE) { | ||
37 | return cmd_results_new(CMD_FAILURE, "focus", | ||
38 | "Command 'focus' cannot be used above the workspace level"); | ||
39 | } | ||
40 | |||
41 | if (argc == 0) { | ||
42 | sway_seat_set_focus(seat, con); | ||
43 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
44 | } | ||
45 | |||
46 | // TODO mode_toggle | ||
47 | enum movement_direction direction = 0; | ||
48 | if (!parse_movement_direction(argv[0], &direction)) { | ||
49 | return cmd_results_new(CMD_INVALID, "focus", | ||
50 | "Expected 'focus <direction|parent|child|mode_toggle>' or 'focus output <direction|name>'"); | ||
51 | } | ||
52 | |||
53 | swayc_t *next_focus = get_swayc_in_direction(con, seat, direction); | ||
54 | if (next_focus) { | ||
55 | sway_seat_set_focus(seat, next_focus); | ||
56 | } | ||
57 | |||
58 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
59 | } | ||