From b374c35758777f98e5ddbe4b0dc43bd7c80f36d7 Mon Sep 17 00:00:00 2001 From: Zandr Martin Date: Thu, 1 Sep 2016 21:39:08 -0500 Subject: refactor commands.c --- sway/commands/bar.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 sway/commands/bar.c (limited to 'sway/commands/bar.c') diff --git a/sway/commands/bar.c b/sway/commands/bar.c new file mode 100644 index 00000000..9e7d6c5c --- /dev/null +++ b/sway/commands/bar.c @@ -0,0 +1,51 @@ +#include +#include +#include "commands.h" +#include "config.h" +#include "log.h" +#include "util.h" + +struct cmd_results *cmd_bar(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "bar", EXPECTED_AT_LEAST, 1))) { + return error; + } + + if (config->reading && strcmp("{", argv[0]) != 0) { + return cmd_results_new(CMD_INVALID, "bar", + "Expected '{' at start of bar config definition."); + } + + if (!config->reading) { + if (argc > 1) { + if (strcasecmp("mode", argv[0]) == 0) { + return bar_cmd_mode(argc-1, argv + 1); + } + + if (strcasecmp("hidden_state", argv[0]) == 0) { + return bar_cmd_hidden_state(argc-1, argv + 1); + } + } + + return cmd_results_new(CMD_FAILURE, "bar", "Can only be used in config file."); + } + + // Create new bar with default values + struct bar_config *bar = default_bar_config(); + + // set bar id + int i; + for (i = 0; i < config->bars->length; ++i) { + if (bar == config->bars->items[i]) { + const int len = 5 + numlen(i); // "bar-" + i + \0 + bar->id = malloc(len * sizeof(char)); + snprintf(bar->id, len, "bar-%d", i); + break; + } + } + + // Set current bar + config->current_bar = bar; + sway_log(L_DEBUG, "Configuring bar %s", bar->id); + return cmd_results_new(CMD_BLOCK_BAR, NULL, NULL); +} -- cgit v1.2.3-54-g00ecf