aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2016-11-03 08:32:10 -0600
committerGitHub <noreply@github.com>2016-11-03 08:32:10 -0600
commite9ac0492b7ec55d34d9209f2ff3e08de5c014d65 (patch)
treeee822e5e219275c84446709c349de630d7441055 /sway
parentd3e55f88ecaacf7c7017357e83f30f91ffc02bb0 (diff)
parent3d1b472b8312ec212b82b9a5c34af40272e9d995 (diff)
Merge pull request #965 from thejan2009/swaybar-colours
Fix some colour settings in swaybar
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c4
-rw-r--r--sway/commands/bar/colors.c183
-rw-r--r--sway/config.c63
-rw-r--r--sway/ipc-json.c38
4 files changed, 157 insertions, 131 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 3236ff6c..de29a7af 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -255,6 +255,7 @@ struct cmd_results *add_color(const char *name, char *buffer, const char *color)
buffer[7] = 'f';
buffer[8] = 'f';
}
+ buffer[9] = '\0';
return NULL;
}
@@ -277,6 +278,9 @@ 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 },
diff --git a/sway/commands/bar/colors.c b/sway/commands/bar/colors.c
index 9e374d88..f6fb520a 100644
--- a/sway/commands/bar/colors.c
+++ b/sway/commands/bar/colors.c
@@ -1,160 +1,123 @@
#include <string.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))) {
+ if ((error = checkarg(argc, cmd_name, 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;
- if ((error = checkarg(argc, "active_workspace", EXPECTED_EQUAL_TO, 3))) {
- return error;
+ if (!*color) {
+ *color = malloc(10);
}
- if ((error = add_color("active_workspace_border", config->current_bar->colors.active_workspace_border, argv[0]))) {
- return error;
- }
-
- if ((error = add_color("active_workspace_bg", config->current_bar->colors.active_workspace_bg, argv[1]))) {
- return error;
- }
-
- 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 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;
- if ((error = checkarg(argc, "background", EXPECTED_EQUAL_TO, 1))) {
- return error;
+ if (argc != 3) {
+ 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]))) {
- return error;
+ int i;
+ for (i = 0; i < 3; i++) {
+ if (!*colors[i]) {
+ *(colors[i]) = malloc(10);
+ }
+ error = add_color(cmd_name, *(colors[i]), argv[i]);
+ if (error) {
+ return error;
+ }
}
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;
- if ((error = checkarg(argc, "binding_mode", EXPECTED_EQUAL_TO, 3))) {
- return error;
- }
-
- if ((error = add_color("binding_mode_border", config->current_bar->colors.binding_mode_border, argv[0]))) {
- return error;
- }
-
- if ((error = add_color("binding_mode_bg", config->current_bar->colors.binding_mode_bg, argv[1]))) {
+ if ((error = checkarg(argc, "colors", EXPECTED_EQUAL_TO, 1))) {
return error;
}
- if ((error = add_color("binding_mode_text", config->current_bar->colors.binding_mode_text, argv[2]))) {
- 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_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 *error = NULL;
- if ((error = checkarg(argc, "focused_workspace", EXPECTED_EQUAL_TO, 3))) {
- return error;
- }
+struct cmd_results *bar_colors_cmd_active_workspace(int argc, char **argv) {
+ char **colors[3] = {
+ &(config->current_bar->colors.active_workspace_border),
+ &(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]))) {
- return error;
- }
+struct cmd_results *bar_colors_cmd_background(int argc, char **argv) {
+ 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]))) {
- return error;
- }
+struct cmd_results *bar_colors_cmd_focused_background(int argc, char **argv) {
+ 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]))) {
- return error;
- }
+struct cmd_results *bar_colors_cmd_binding_mode(int argc, char **argv) {
+ 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 *error = NULL;
- if ((error = checkarg(argc, "inactive_workspace", EXPECTED_EQUAL_TO, 3))) {
- return error;
- }
-
- if ((error = add_color("inactive_workspace_border", config->current_bar->colors.inactive_workspace_border, argv[0]))) {
- 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);
+ char **colors[3] = {
+ &(config->current_bar->colors.inactive_workspace_border),
+ &(config->current_bar->colors.inactive_workspace_bg),
+ &(config->current_bar->colors.inactive_workspace_text)
+ };
+ return parse_three_colors(colors, "inactive_workspace", argc, argv);
}
struct cmd_results *bar_colors_cmd_separator(int argc, char **argv) {
- struct cmd_results *error = NULL;
- 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 parse_single_color(&(config->current_bar->colors.separator), "separator", argc, argv);
+}
- return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+struct cmd_results *bar_colors_cmd_focused_separator(int argc, char **argv) {
+ return parse_single_color(&(config->current_bar->colors.focused_separator), "focused_separator", argc, argv);
}
struct cmd_results *bar_colors_cmd_statusline(int argc, char **argv) {
- struct cmd_results *error = NULL;
- 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 parse_single_color(&(config->current_bar->colors.statusline), "statusline", argc, argv);
+}
- return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+struct cmd_results *bar_colors_cmd_focused_statusline(int argc, char **argv) {
+ return parse_single_color(&(config->current_bar->colors.focused_separator), "focused_separator", argc, argv);
}
struct cmd_results *bar_colors_cmd_urgent_workspace(int argc, char **argv) {
- struct cmd_results *error = NULL;
- if ((error = checkarg(argc, "urgent_workspace", EXPECTED_EQUAL_TO, 3))) {
- return error;
- }
-
- if ((error = add_color("urgent_workspace_border", config->current_bar->colors.urgent_workspace_border, argv[0]))) {
- 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);
+ char **colors[3] = {
+ &(config->current_bar->colors.urgent_workspace_border),
+ &(config->current_bar->colors.urgent_workspace_bg),
+ &(config->current_bar->colors.urgent_workspace_text)
+ };
+ return parse_three_colors(colors, "urgent_workspace", argc, argv);
}
diff --git a/sway/config.c b/sway/config.c
index 7a41a3c8..7d5999d8 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -70,6 +70,28 @@ static void free_bar(struct bar_config *bar) {
terminate_swaybar(bar->pid);
}
+ free(bar->colors.background);
+ free(bar->colors.statusline);
+ free(bar->colors.separator);
+ free(bar->colors.focused_background);
+ free(bar->colors.focused_statusline);
+ free(bar->colors.focused_separator);
+ free(bar->colors.focused_workspace_border);
+ free(bar->colors.focused_workspace_bg);
+ free(bar->colors.focused_workspace_text);
+ free(bar->colors.active_workspace_border);
+ free(bar->colors.active_workspace_bg);
+ free(bar->colors.active_workspace_text);
+ free(bar->colors.inactive_workspace_border);
+ free(bar->colors.inactive_workspace_bg);
+ free(bar->colors.inactive_workspace_text);
+ free(bar->colors.urgent_workspace_border);
+ free(bar->colors.urgent_workspace_bg);
+ free(bar->colors.urgent_workspace_text);
+ free(bar->colors.binding_mode_border);
+ free(bar->colors.binding_mode_bg);
+ free(bar->colors.binding_mode_text);
+
free(bar);
}
@@ -1132,24 +1154,29 @@ struct bar_config *default_bar_config(void) {
bar->verbose = false;
bar->pid = 0;
// set default colors
- strcpy(bar->colors.background, "#000000ff");
- strcpy(bar->colors.statusline, "#ffffffff");
- strcpy(bar->colors.separator, "#666666ff");
- strcpy(bar->colors.focused_workspace_border, "#4c7899ff");
- strcpy(bar->colors.focused_workspace_bg, "#285577ff");
- strcpy(bar->colors.focused_workspace_text, "#ffffffff");
- strcpy(bar->colors.active_workspace_border, "#333333ff");
- strcpy(bar->colors.active_workspace_bg, "#5f676aff");
- strcpy(bar->colors.active_workspace_text, "#ffffffff");
- strcpy(bar->colors.inactive_workspace_border, "#333333ff");
- strcpy(bar->colors.inactive_workspace_bg,"#222222ff");
- strcpy(bar->colors.inactive_workspace_text, "#888888ff");
- strcpy(bar->colors.urgent_workspace_border, "#2f343aff");
- strcpy(bar->colors.urgent_workspace_bg,"#900000ff");
- strcpy(bar->colors.urgent_workspace_text, "#ffffffff");
- strcpy(bar->colors.binding_mode_border, "#2f343aff");
- strcpy(bar->colors.binding_mode_bg,"#900000ff");
- strcpy(bar->colors.binding_mode_text, "#ffffffff");
+ bar->colors.background = strndup("#000000ff", 9);
+ bar->colors.statusline = strndup("#ffffffff", 9);
+ bar->colors.separator = strndup("#666666ff", 9);
+ bar->colors.focused_workspace_border = strndup("#4c7899ff", 9);
+ bar->colors.focused_workspace_bg = strndup("#285577ff", 9);
+ bar->colors.focused_workspace_text = strndup("#ffffffff", 9);
+ bar->colors.active_workspace_border = strndup("#333333ff", 9);
+ bar->colors.active_workspace_bg = strndup("#5f676aff", 9);
+ bar->colors.active_workspace_text = strndup("#ffffffff", 9);
+ bar->colors.inactive_workspace_border = strndup("#333333ff", 9);
+ bar->colors.inactive_workspace_bg = strndup("#222222ff", 9);
+ bar->colors.inactive_workspace_text = strndup("#888888ff", 9);
+ bar->colors.urgent_workspace_border = strndup("#2f343aff", 9);
+ bar->colors.urgent_workspace_bg = strndup("#900000ff", 9);
+ bar->colors.urgent_workspace_text = strndup("#ffffffff", 9);
+ // if the following colors stay undefined, they fall back to background,
+ // statusline, separator and urgent_workspace_*.
+ bar->colors.focused_background = NULL;
+ bar->colors.focused_statusline = NULL;
+ bar->colors.focused_separator = NULL;
+ bar->colors.binding_mode_border = NULL;
+ bar->colors.binding_mode_bg = NULL;
+ bar->colors.binding_mode_text = NULL;
list_add(config->bars, bar);
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index eb77a654..e65e9de3 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -312,6 +312,24 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
json_object_object_add(colors, "statusline", json_object_new_string(bar->colors.statusline));
json_object_object_add(colors, "separator", json_object_new_string(bar->colors.separator));
+ if (bar->colors.focused_background) {
+ json_object_object_add(colors, "focused_background", json_object_new_string(bar->colors.focused_background));
+ } else {
+ json_object_object_add(colors, "focused_background", json_object_new_string(bar->colors.background));
+ }
+
+ if (bar->colors.focused_statusline) {
+ json_object_object_add(colors, "focused_statusline", json_object_new_string(bar->colors.focused_statusline));
+ } else {
+ json_object_object_add(colors, "focused_statusline", json_object_new_string(bar->colors.statusline));
+ }
+
+ if (bar->colors.focused_separator) {
+ json_object_object_add(colors, "focused_separator", json_object_new_string(bar->colors.focused_separator));
+ } else {
+ json_object_object_add(colors, "focused_separator", json_object_new_string(bar->colors.separator));
+ }
+
json_object_object_add(colors, "focused_workspace_border", json_object_new_string(bar->colors.focused_workspace_border));
json_object_object_add(colors, "focused_workspace_bg", json_object_new_string(bar->colors.focused_workspace_bg));
json_object_object_add(colors, "focused_workspace_text", json_object_new_string(bar->colors.focused_workspace_text));
@@ -328,9 +346,23 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
json_object_object_add(colors, "urgent_workspace_bg", json_object_new_string(bar->colors.urgent_workspace_bg));
json_object_object_add(colors, "urgent_workspace_text", json_object_new_string(bar->colors.urgent_workspace_text));
- json_object_object_add(colors, "binding_mode_border", json_object_new_string(bar->colors.binding_mode_border));
- json_object_object_add(colors, "binding_mode_bg", json_object_new_string(bar->colors.binding_mode_bg));
- json_object_object_add(colors, "binding_mode_text", json_object_new_string(bar->colors.binding_mode_text));
+ if (bar->colors.binding_mode_border) {
+ json_object_object_add(colors, "binding_mode_border", json_object_new_string(bar->colors.binding_mode_border));
+ } else {
+ json_object_object_add(colors, "binding_mode_border", json_object_new_string(bar->colors.urgent_workspace_border));
+ }
+
+ if (bar->colors.binding_mode_bg) {
+ json_object_object_add(colors, "binding_mode_bg", json_object_new_string(bar->colors.binding_mode_bg));
+ } else {
+ json_object_object_add(colors, "binding_mode_bg", json_object_new_string(bar->colors.urgent_workspace_bg));
+ }
+
+ if (bar->colors.binding_mode_text) {
+ json_object_object_add(colors, "binding_mode_text", json_object_new_string(bar->colors.binding_mode_text));
+ } else {
+ json_object_object_add(colors, "binding_mode_text", json_object_new_string(bar->colors.urgent_workspace_text));
+ }
json_object_object_add(json, "colors", colors);