This commit removes has_* booleans from bar color struct. It also generalizes of functions in commands/bar/colors.c.master
parent
ad4d21d60b
commit
58eb7ac19f
@ -1,211 +1,123 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "sway/commands.h"
|
#include "sway/commands.h"
|
||||||
|
|
||||||
struct cmd_results *bar_cmd_colors(int argc, char **argv) {
|
static struct cmd_results *parse_single_color(char **color, const char *cmd_name, 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct cmd_results *bar_colors_cmd_active_workspace(int argc, char **argv) {
|
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
if ((error = checkarg(argc, "active_workspace", EXPECTED_EQUAL_TO, 3))) {
|
if ((error = checkarg(argc, cmd_name, EXPECTED_EQUAL_TO, 1))) {
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((error = add_color("active_workspace_border", config->current_bar->colors.active_workspace_border, argv[0]))) {
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((error = add_color("active_workspace_bg", config->current_bar->colors.active_workspace_bg, argv[1]))) {
|
if (!*color) {
|
||||||
return error;
|
*color = malloc(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((error = add_color("active_workspace_text", config->current_bar->colors.active_workspace_text, argv[2]))) {
|
error = add_color(cmd_name, *color, argv[0]);
|
||||||
|
if (error) {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmd_results *bar_colors_cmd_background(int argc, char **argv) {
|
static struct cmd_results *parse_three_colors(char ***colors, const char *cmd_name, int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
if ((error = checkarg(argc, "background", EXPECTED_EQUAL_TO, 1))) {
|
if (argc != 3) {
|
||||||
return error;
|
return cmd_results_new(CMD_INVALID, cmd_name, "Requires exactly three color values");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((error = add_color("background", config->current_bar->colors.background, argv[0]))) {
|
int i;
|
||||||
return error;
|
for (i = 0; i < 3; i++) {
|
||||||
|
if (!*colors[i]) {
|
||||||
|
*(colors[i]) = malloc(10);
|
||||||
}
|
}
|
||||||
|
error = add_color(cmd_name, *(colors[i]), argv[i]);
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
if (error) {
|
||||||
}
|
|
||||||
|
|
||||||
struct cmd_results *bar_colors_cmd_focused_background(int argc, char **argv) {
|
|
||||||
struct cmd_results *error = NULL;
|
|
||||||
if ((error = checkarg(argc, "focused_background", EXPECTED_EQUAL_TO, 1))) {
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((error = add_color("focused_background", config->current_bar->colors.focused_background, argv[0]))) {
|
|
||||||
return error;
|
|
||||||
}else {
|
|
||||||
config->current_bar->colors.has_focused_background = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmd_results *bar_colors_cmd_binding_mode(int argc, char **argv) {
|
struct cmd_results *bar_cmd_colors(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
if ((error = checkarg(argc, "binding_mode", EXPECTED_EQUAL_TO, 3))) {
|
if ((error = checkarg(argc, "colors", EXPECTED_EQUAL_TO, 1))) {
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((error = add_color("binding_mode_border", config->current_bar->colors.binding_mode_border, argv[0]))) {
|
|
||||||
return error;
|
|
||||||
} else {
|
|
||||||
config->current_bar->colors.has_binding_mode_border = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((error = add_color("binding_mode_bg", config->current_bar->colors.binding_mode_bg, argv[1]))) {
|
|
||||||
return error;
|
return error;
|
||||||
} else {
|
|
||||||
config->current_bar->colors.has_binding_mode_bg = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((error = add_color("binding_mode_text", config->current_bar->colors.binding_mode_text, argv[2]))) {
|
if (strcmp("{", argv[0]) != 0) {
|
||||||
return error;
|
return cmd_results_new(CMD_INVALID, "colors",
|
||||||
} else {
|
"Expected '{' at the start of colors config definition.");
|
||||||
config->current_bar->colors.has_binding_mode_text = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_BLOCK_BAR_COLORS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmd_results *bar_colors_cmd_focused_workspace(int argc, char **argv) {
|
struct cmd_results *bar_colors_cmd_active_workspace(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
char **colors[3] = {
|
||||||
if ((error = checkarg(argc, "focused_workspace", EXPECTED_EQUAL_TO, 3))) {
|
&(config->current_bar->colors.active_workspace_border),
|
||||||
return error;
|
&(config->current_bar->colors.active_workspace_bg),
|
||||||
}
|
&(config->current_bar->colors.active_workspace_text)
|
||||||
|
};
|
||||||
|
return parse_three_colors(colors, "active_workspace", argc, argv);
|
||||||
|
}
|
||||||
|
|
||||||
if ((error = add_color("focused_workspace_border", config->current_bar->colors.focused_workspace_border, argv[0]))) {
|
struct cmd_results *bar_colors_cmd_background(int argc, char **argv) {
|
||||||
return error;
|
return parse_single_color(&(config->current_bar->colors.background), "background", argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((error = add_color("focused_workspace_bg", config->current_bar->colors.focused_workspace_bg, argv[1]))) {
|
struct cmd_results *bar_colors_cmd_focused_background(int argc, char **argv) {
|
||||||
return error;
|
return parse_single_color(&(config->current_bar->colors.focused_background), "focused_background", argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((error = add_color("focused_workspace_text", config->current_bar->colors.focused_workspace_text, argv[2]))) {
|
struct cmd_results *bar_colors_cmd_binding_mode(int argc, char **argv) {
|
||||||
return error;
|
char **colors[3] = {
|
||||||
}
|
&(config->current_bar->colors.binding_mode_border),
|
||||||
|
&(config->current_bar->colors.binding_mode_bg),
|
||||||
|
&(config->current_bar->colors.binding_mode_text)
|
||||||
|
};
|
||||||
|
return parse_three_colors(colors, "binding_mode", argc, argv);
|
||||||
|
}
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
struct cmd_results *bar_colors_cmd_focused_workspace(int argc, char **argv) {
|
||||||
|
char **colors[3] = {
|
||||||
|
&(config->current_bar->colors.focused_workspace_border),
|
||||||
|
&(config->current_bar->colors.focused_workspace_bg),
|
||||||
|
&(config->current_bar->colors.focused_workspace_text)
|
||||||
|
};
|
||||||
|
return parse_three_colors(colors, "focused_workspace", argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmd_results *bar_colors_cmd_inactive_workspace(int argc, char **argv) {
|
struct cmd_results *bar_colors_cmd_inactive_workspace(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
char **colors[3] = {
|
||||||
if ((error = checkarg(argc, "inactive_workspace", EXPECTED_EQUAL_TO, 3))) {
|
&(config->current_bar->colors.inactive_workspace_border),
|
||||||
return error;
|
&(config->current_bar->colors.inactive_workspace_bg),
|
||||||
}
|
&(config->current_bar->colors.inactive_workspace_text)
|
||||||
|
};
|
||||||
if ((error = add_color("inactive_workspace_border", config->current_bar->colors.inactive_workspace_border, argv[0]))) {
|
return parse_three_colors(colors, "inactive_workspace", argc, argv);
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((error = add_color("inactive_workspace_bg", config->current_bar->colors.inactive_workspace_bg, argv[1]))) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((error = add_color("inactive_workspace_text", config->current_bar->colors.inactive_workspace_text, argv[2]))) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmd_results *bar_colors_cmd_separator(int argc, char **argv) {
|
struct cmd_results *bar_colors_cmd_separator(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
return parse_single_color(&(config->current_bar->colors.separator), "separator", argc, argv);
|
||||||
if ((error = checkarg(argc, "separator", EXPECTED_EQUAL_TO, 1))) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((error = add_color("separator", config->current_bar->colors.separator, argv[0]))) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmd_results *bar_colors_cmd_focused_separator(int argc, char **argv) {
|
struct cmd_results *bar_colors_cmd_focused_separator(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
return parse_single_color(&(config->current_bar->colors.focused_separator), "focused_separator", argc, argv);
|
||||||
if ((error = checkarg(argc, "focused_separator", EXPECTED_EQUAL_TO, 1))) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((error = add_color("focused_separator", config->current_bar->colors.focused_separator, argv[0]))) {
|
|
||||||
return error;
|
|
||||||
} else {
|
|
||||||
config->current_bar->colors.has_focused_separator = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmd_results *bar_colors_cmd_statusline(int argc, char **argv) {
|
struct cmd_results *bar_colors_cmd_statusline(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
return parse_single_color(&(config->current_bar->colors.statusline), "statusline", argc, argv);
|
||||||
if ((error = checkarg(argc, "statusline", EXPECTED_EQUAL_TO, 1))) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((error = add_color("statusline", config->current_bar->colors.statusline, argv[0]))) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmd_results *bar_colors_cmd_focused_statusline(int argc, char **argv) {
|
struct cmd_results *bar_colors_cmd_focused_statusline(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
return parse_single_color(&(config->current_bar->colors.focused_separator), "focused_separator", argc, argv);
|
||||||
if ((error = checkarg(argc, "focused_statusline", EXPECTED_EQUAL_TO, 1))) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((error = add_color("focused_statusline", config->current_bar->colors.focused_statusline, argv[0]))) {
|
|
||||||
return error;
|
|
||||||
} else {
|
|
||||||
config->current_bar->colors.has_focused_statusline = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmd_results *bar_colors_cmd_urgent_workspace(int argc, char **argv) {
|
struct cmd_results *bar_colors_cmd_urgent_workspace(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
char **colors[3] = {
|
||||||
if ((error = checkarg(argc, "urgent_workspace", EXPECTED_EQUAL_TO, 3))) {
|
&(config->current_bar->colors.urgent_workspace_border),
|
||||||
return error;
|
&(config->current_bar->colors.urgent_workspace_bg),
|
||||||
}
|
&(config->current_bar->colors.urgent_workspace_text)
|
||||||
|
};
|
||||||
if ((error = add_color("urgent_workspace_border", config->current_bar->colors.urgent_workspace_border, argv[0]))) {
|
return parse_three_colors(colors, "urgent_workspace", argc, argv);
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((error = add_color("urgent_workspace_bg", config->current_bar->colors.urgent_workspace_bg, argv[1]))) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((error = add_color("urgent_workspace_text", config->current_bar->colors.urgent_workspace_text, argv[2]))) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue