aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/seat.c
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2018-05-30 13:20:02 -0400
committerBrian Ashworth <bosrsf04@gmail.com>2018-06-02 08:07:44 -0400
commit7c810dc344c28d1876c5ee158cb0806289d0f813 (patch)
treedbe756bceca42ea6f9a6cf5e5771037417bb64c3 /sway/commands/seat.c
parent2d480e754e8287ba747faf1b21d8ecb927d565a1 (diff)
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 @@
#include "sway/commands.h"
#include "sway/input/input-manager.h"
#include "log.h"
+#include "stringop.h"
+
+// must be in order for the bsearch
+static struct cmd_handler seat_handlers[] = {
+ { "attach", seat_cmd_attach },
+ { "cursor", seat_cmd_cursor },
+ { "fallback", seat_cmd_fallback },
+};
struct cmd_results *cmd_seat(int argc, char **argv) {
struct cmd_results *error = NULL;
- if ((error = checkarg(argc, "seat", EXPECTED_AT_LEAST, 2))) {
+ if ((error = checkarg(argc, "seat", EXPECTED_AT_LEAST, 1))) {
return error;
}
- if (config->reading && strcmp("{", argv[1]) == 0) {
- free_seat_config(config->handler_context.seat_config);
- config->handler_context.seat_config = new_seat_config(argv[0]);
- if (!config->handler_context.seat_config) {
- return cmd_results_new(CMD_FAILURE, NULL,
- "Couldn't allocate config");
- }
- wlr_log(L_DEBUG, "entering seat block: %s", argv[0]);
- return cmd_results_new(CMD_BLOCK_SEAT, NULL, NULL);
+ config->handler_context.seat_config = new_seat_config(argv[0]);
+ if (!config->handler_context.seat_config) {
+ return cmd_results_new(CMD_FAILURE, NULL,
+ "Couldn't allocate config");
}
- if ((error = checkarg(argc, "seat", EXPECTED_AT_LEAST, 3))) {
- return error;
- }
-
- bool has_context = (config->handler_context.seat_config != NULL);
- if (!has_context) {
- config->handler_context.seat_config = new_seat_config(argv[0]);
- if (!config->handler_context.seat_config) {
- return cmd_results_new(CMD_FAILURE, NULL,
- "Couldn't allocate config");
- }
- }
+ struct cmd_results *res = subcommand(argv + 1, argc - 1, seat_handlers,
+ sizeof(seat_handlers));
- int argc_new = argc-2;
- char **argv_new = argv+2;
-
- struct cmd_results *res;
- if (strcasecmp("attach", argv[1]) == 0) {
- res = seat_cmd_attach(argc_new, argv_new);
- } else if (strcasecmp("cursor", argv[1]) == 0) {
- res = seat_cmd_cursor(argc_new, argv_new);
- } else if (strcasecmp("fallback", argv[1]) == 0) {
- res = seat_cmd_fallback(argc_new, argv_new);
- } else {
- res =
- cmd_results_new(CMD_INVALID,
- "seat <name>", "Unknown command %s",
- argv[1]);
- }
-
- if (!has_context) {
- // clean up the context we created earlier
- free_seat_config(config->handler_context.seat_config);
- config->handler_context.seat_config = NULL;
- }
+ free_seat_config(config->handler_context.seat_config);
+ config->handler_context.seat_config = NULL;
return res;
}