aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/seat.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-05-30 13:20:02 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-06-02 08:07:44 -0400
commit7c810dc344c28d1876c5ee158cb0806289d0f813 (patch)
treedbe756bceca42ea6f9a6cf5e5771037417bb64c3 /sway/commands/seat.c
parentMerge pull request #2080 from frsfnrrg/keyboard-remodeling (diff)
downloadsway-7c810dc344c28d1876c5ee158cb0806289d0f813.tar.gz
sway-7c810dc344c28d1876c5ee158cb0806289d0f813.tar.zst
sway-7c810dc344c28d1876c5ee158cb0806289d0f813.zip
Make command block implementation generic
Diffstat (limited to 'sway/commands/seat.c')
-rw-r--r--sway/commands/seat.c61
1 files changed, 17 insertions, 44 deletions
diff --git a/sway/commands/seat.c b/sway/commands/seat.c
index 5916015f..6080bf64 100644
--- a/sway/commands/seat.c
+++ b/sway/commands/seat.c
@@ -3,59 +3,32 @@
3#include "sway/commands.h" 3#include "sway/commands.h"
4#include "sway/input/input-manager.h" 4#include "sway/input/input-manager.h"
5#include "log.h" 5#include "log.h"
6#include "stringop.h"
7
8// must be in order for the bsearch
9static struct cmd_handler seat_handlers[] = {
10 { "attach", seat_cmd_attach },
11 { "cursor", seat_cmd_cursor },
12 { "fallback", seat_cmd_fallback },
13};
6 14
7struct cmd_results *cmd_seat(int argc, char **argv) { 15struct cmd_results *cmd_seat(int argc, char **argv) {
8 struct cmd_results *error = NULL; 16 struct cmd_results *error = NULL;
9 if ((error = checkarg(argc, "seat", EXPECTED_AT_LEAST, 2))) { 17 if ((error = checkarg(argc, "seat", EXPECTED_AT_LEAST, 1))) {
10 return error; 18 return error;
11 } 19 }
12 20
13 if (config->reading && strcmp("{", argv[1]) == 0) { 21 config->handler_context.seat_config = new_seat_config(argv[0]);
14 free_seat_config(config->handler_context.seat_config); 22 if (!config->handler_context.seat_config) {
15 config->handler_context.seat_config = new_seat_config(argv[0]); 23 return cmd_results_new(CMD_FAILURE, NULL,
16 if (!config->handler_context.seat_config) { 24 "Couldn't allocate 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 } 25 }
23 26
24 if ((error = checkarg(argc, "seat", EXPECTED_AT_LEAST, 3))) { 27 struct cmd_results *res = subcommand(argv + 1, argc - 1, seat_handlers,
25 return error; 28 sizeof(seat_handlers));
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 29
37 int argc_new = argc-2; 30 free_seat_config(config->handler_context.seat_config);
38 char **argv_new = argv+2; 31 config->handler_context.seat_config = NULL;
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 32
60 return res; 33 return res;
61} 34}