diff options
Diffstat (limited to 'sway/commands/seat.c')
-rw-r--r-- | sway/commands/seat.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/sway/commands/seat.c b/sway/commands/seat.c new file mode 100644 index 00000000..5916015f --- /dev/null +++ b/sway/commands/seat.c | |||
@@ -0,0 +1,61 @@ | |||
1 | #include <string.h> | ||
2 | #include <strings.h> | ||
3 | #include "sway/commands.h" | ||
4 | #include "sway/input/input-manager.h" | ||
5 | #include "log.h" | ||
6 | |||
7 | struct cmd_results *cmd_seat(int argc, char **argv) { | ||
8 | struct cmd_results *error = NULL; | ||
9 | if ((error = checkarg(argc, "seat", EXPECTED_AT_LEAST, 2))) { | ||
10 | return error; | ||
11 | } | ||
12 | |||
13 | if (config->reading && strcmp("{", argv[1]) == 0) { | ||
14 | free_seat_config(config->handler_context.seat_config); | ||
15 | config->handler_context.seat_config = new_seat_config(argv[0]); | ||
16 | if (!config->handler_context.seat_config) { | ||
17 | return cmd_results_new(CMD_FAILURE, NULL, | ||
18 | "Couldn't allocate config"); | ||
19 | } | ||
20 | wlr_log(L_DEBUG, "entering seat block: %s", argv[0]); | ||
21 | return cmd_results_new(CMD_BLOCK_SEAT, NULL, NULL); | ||
22 | } | ||
23 | |||
24 | if ((error = checkarg(argc, "seat", EXPECTED_AT_LEAST, 3))) { | ||
25 | return error; | ||
26 | } | ||
27 | |||
28 | bool has_context = (config->handler_context.seat_config != NULL); | ||
29 | if (!has_context) { | ||
30 | config->handler_context.seat_config = new_seat_config(argv[0]); | ||
31 | if (!config->handler_context.seat_config) { | ||
32 | return cmd_results_new(CMD_FAILURE, NULL, | ||
33 | "Couldn't allocate config"); | ||
34 | } | ||
35 | } | ||
36 | |||
37 | int argc_new = argc-2; | ||
38 | char **argv_new = argv+2; | ||
39 | |||
40 | struct cmd_results *res; | ||
41 | if (strcasecmp("attach", argv[1]) == 0) { | ||
42 | res = seat_cmd_attach(argc_new, argv_new); | ||
43 | } else if (strcasecmp("cursor", argv[1]) == 0) { | ||
44 | res = seat_cmd_cursor(argc_new, argv_new); | ||
45 | } else if (strcasecmp("fallback", argv[1]) == 0) { | ||
46 | res = seat_cmd_fallback(argc_new, argv_new); | ||
47 | } else { | ||
48 | res = | ||
49 | cmd_results_new(CMD_INVALID, | ||
50 | "seat <name>", "Unknown command %s", | ||
51 | argv[1]); | ||
52 | } | ||
53 | |||
54 | if (!has_context) { | ||
55 | // clean up the context we created earlier | ||
56 | free_seat_config(config->handler_context.seat_config); | ||
57 | config->handler_context.seat_config = NULL; | ||
58 | } | ||
59 | |||
60 | return res; | ||
61 | } | ||