aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/bar
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/bar
parent2d480e754e8287ba747faf1b21d8ecb927d565a1 (diff)
Make command block implementation generic
Diffstat (limited to 'sway/commands/bar')
-rw-r--r--sway/commands/bar/colors.c26
-rw-r--r--sway/commands/bar/id.c3
2 files changed, 20 insertions, 9 deletions
diff --git a/sway/commands/bar/colors.c b/sway/commands/bar/colors.c
index 17ba9b7c..6d3c09b8 100644
--- a/sway/commands/bar/colors.c
+++ b/sway/commands/bar/colors.c
@@ -1,6 +1,21 @@
#include <string.h>
#include "sway/commands.h"
+// Must be in alphabetical order for bsearch
+static struct cmd_handler bar_colors_handlers[] = {
+ { "active_workspace", bar_colors_cmd_active_workspace },
+ { "background", bar_colors_cmd_background },
+ { "binding_mode", bar_colors_cmd_binding_mode },
+ { "focused_background", bar_colors_cmd_focused_background },
+ { "focused_separator", bar_colors_cmd_focused_separator },
+ { "focused_statusline", bar_colors_cmd_focused_statusline },
+ { "focused_workspace", bar_colors_cmd_focused_workspace },
+ { "inactive_workspace", bar_colors_cmd_inactive_workspace },
+ { "separator", bar_colors_cmd_separator },
+ { "statusline", bar_colors_cmd_statusline },
+ { "urgent_workspace", bar_colors_cmd_urgent_workspace },
+};
+
static struct cmd_results *parse_single_color(char **color,
const char *cmd_name, int argc, char **argv) {
struct cmd_results *error = NULL;
@@ -37,15 +52,8 @@ static struct cmd_results *parse_three_colors(char ***colors,
}
struct cmd_results *bar_cmd_colors(int argc, char **argv) {
- struct cmd_results *error = NULL;
- if ((error = checkarg(argc, "colors", EXPECTED_EQUAL_TO, 1))) {
- return error;
- }
- if (strcmp("{", argv[0]) != 0) {
- return cmd_results_new(CMD_INVALID, "colors",
- "Expected '{' at the start of colors config definition.");
- }
- return cmd_results_new(CMD_BLOCK_BAR_COLORS, NULL, NULL);
+ return subcommand(argv, argc, bar_colors_handlers,
+ sizeof(bar_colors_handlers));
}
struct cmd_results *bar_colors_cmd_active_workspace(int argc, char **argv) {
diff --git a/sway/commands/bar/id.c b/sway/commands/bar/id.c
index c1e56f03..6ce86fef 100644
--- a/sway/commands/bar/id.c
+++ b/sway/commands/bar/id.c
@@ -11,6 +11,9 @@ struct cmd_results *bar_cmd_id(int argc, char **argv) {
const char *name = argv[0];
const char *oldname = config->current_bar->id;
+ if (strcmp(name, oldname) == 0) {
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL); // NOP
+ }
// check if id is used by a previously defined bar
for (int i = 0; i < config->bars->length; ++i) {
struct bar_config *find = config->bars->items[i];