From 39ee0ec552c05c7ab5031982a1104a0bae1910d3 Mon Sep 17 00:00:00 2001 From: "D.B" Date: Wed, 2 Nov 2016 17:09:34 +0100 Subject: use urgent_ws color in swaybar if binding_mode is undefined --- sway/commands/bar/colors.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'sway/commands/bar') diff --git a/sway/commands/bar/colors.c b/sway/commands/bar/colors.c index 9e374d88..e9180604 100644 --- a/sway/commands/bar/colors.c +++ b/sway/commands/bar/colors.c @@ -57,14 +57,20 @@ struct cmd_results *bar_colors_cmd_binding_mode(int argc, char **argv) { 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; + } 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]))) { return error; + } else { + config->current_bar->colors.has_binding_mode_text = true; } return cmd_results_new(CMD_SUCCESS, NULL, NULL); -- cgit v1.2.3 From ad4d21d60b36ba39e2090fa052a29bf7ea8a3395 Mon Sep 17 00:00:00 2001 From: "D.B" Date: Wed, 2 Nov 2016 18:48:43 +0100 Subject: add bar colours for focused_(workspace|statusline|separator) If these aren't defined in config, color settings without 'focused_' prefix are used as a fallback. --- include/sway/commands.h | 4 +++- include/sway/config.h | 7 +++++++ include/swaybar/bar.h | 2 ++ include/swaybar/config.h | 4 ++++ sway/commands.c | 3 +++ sway/commands/bar/colors.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ sway/ipc-json.c | 18 ++++++++++++++++++ swaybar/ipc.c | 23 +++++++++++++++++++++++ swaybar/render.c | 24 +++++++++++++++++++----- 9 files changed, 124 insertions(+), 6 deletions(-) (limited to 'sway/commands/bar') diff --git a/include/sway/commands.h b/include/sway/commands.h index a46f41a3..db5e94d9 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -160,12 +160,14 @@ sway_cmd bar_cmd_workspace_buttons; sway_cmd bar_colors_cmd_active_workspace; sway_cmd bar_colors_cmd_background; -sway_cmd bar_colors_cmd_background; +sway_cmd bar_colors_cmd_focused_background; sway_cmd bar_colors_cmd_binding_mode; sway_cmd bar_colors_cmd_focused_workspace; sway_cmd bar_colors_cmd_inactive_workspace; sway_cmd bar_colors_cmd_separator; +sway_cmd bar_colors_cmd_focused_separator; sway_cmd bar_colors_cmd_statusline; +sway_cmd bar_colors_cmd_focused_statusline; sway_cmd bar_colors_cmd_urgent_workspace; sway_cmd input_cmd_accel_profile; diff --git a/include/sway/config.h b/include/sway/config.h index c41bb8b3..9b3cc60c 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -148,6 +148,9 @@ struct bar_config { char background[10]; char statusline[10]; char separator[10]; + char focused_background[10]; + char focused_statusline[10]; + char focused_separator[10]; char focused_workspace_border[10]; char focused_workspace_bg[10]; char focused_workspace_text[10]; @@ -164,6 +167,10 @@ struct bar_config { char binding_mode_bg[10]; char binding_mode_text[10]; + bool has_focused_background; + bool has_focused_statusline; + bool has_focused_separator; + bool has_binding_mode_border; bool has_binding_mode_bg; bool has_binding_mode_text; diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index a3c511d9..697a48c2 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h @@ -9,6 +9,7 @@ struct bar { struct config *config; struct status_line *status; list_t *outputs; + struct output *focused_output; int ipc_event_socketfd; int ipc_socketfd; @@ -22,6 +23,7 @@ struct output { list_t *workspaces; char *name; int idx; + bool focused; }; struct workspace { diff --git a/include/swaybar/config.h b/include/swaybar/config.h index 934116ca..04b12cd4 100644 --- a/include/swaybar/config.h +++ b/include/swaybar/config.h @@ -40,6 +40,10 @@ struct config { uint32_t statusline; uint32_t separator; + uint32_t focused_background; + uint32_t focused_statusline; + uint32_t focused_separator; + struct box_colors focused_workspace; struct box_colors active_workspace; struct box_colors inactive_workspace; diff --git a/sway/commands.c b/sway/commands.c index 3236ff6c..872e9fc3 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -277,6 +277,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 e9180604..8fb7fe27 100644 --- a/sway/commands/bar/colors.c +++ b/sway/commands/bar/colors.c @@ -49,6 +49,21 @@ struct cmd_results *bar_colors_cmd_background(int argc, char **argv) { return cmd_results_new(CMD_SUCCESS, NULL, NULL); } +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; + } + + 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); +} + struct cmd_results *bar_colors_cmd_binding_mode(int argc, char **argv) { struct cmd_results *error = NULL; if ((error = checkarg(argc, "binding_mode", EXPECTED_EQUAL_TO, 3))) { @@ -131,6 +146,21 @@ struct cmd_results *bar_colors_cmd_separator(int argc, char **argv) { return cmd_results_new(CMD_SUCCESS, NULL, NULL); } +struct cmd_results *bar_colors_cmd_focused_separator(int argc, char **argv) { + struct cmd_results *error = NULL; + 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 *error = NULL; if ((error = checkarg(argc, "statusline", EXPECTED_EQUAL_TO, 1))) { @@ -144,6 +174,21 @@ struct cmd_results *bar_colors_cmd_statusline(int argc, char **argv) { return cmd_results_new(CMD_SUCCESS, NULL, NULL); } +struct cmd_results *bar_colors_cmd_focused_statusline(int argc, char **argv) { + struct cmd_results *error = NULL; + 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 *error = NULL; if ((error = checkarg(argc, "urgent_workspace", EXPECTED_EQUAL_TO, 3))) { diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 458dc7c2..c21d28af 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.has_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.has_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.has_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)); diff --git a/swaybar/ipc.c b/swaybar/ipc.c index 2c092853..8d2f4e9a 100644 --- a/swaybar/ipc.c +++ b/swaybar/ipc.c @@ -108,6 +108,7 @@ static void ipc_parse_config(struct config *config, const char *payload) { if (colors) { json_object *background, *statusline, *separator; + json_object *focused_background, *focused_statusline, *focused_separator; json_object *focused_workspace_border, *focused_workspace_bg, *focused_workspace_text; json_object *inactive_workspace_border, *inactive_workspace_bg, *inactive_workspace_text; json_object *active_workspace_border, *active_workspace_bg, *active_workspace_text; @@ -116,6 +117,9 @@ static void ipc_parse_config(struct config *config, const char *payload) { json_object_object_get_ex(colors, "background", &background); json_object_object_get_ex(colors, "statusline", &statusline); json_object_object_get_ex(colors, "separator", &separator); + json_object_object_get_ex(colors, "focused_background", &focused_background); + json_object_object_get_ex(colors, "focused_statusline", &focused_statusline); + json_object_object_get_ex(colors, "focused_separator", &focused_separator); json_object_object_get_ex(colors, "focused_workspace_border", &focused_workspace_border); json_object_object_get_ex(colors, "focused_workspace_bg", &focused_workspace_bg); json_object_object_get_ex(colors, "focused_workspace_text", &focused_workspace_text); @@ -143,6 +147,18 @@ static void ipc_parse_config(struct config *config, const char *payload) { config->colors.separator = parse_color(json_object_get_string(separator)); } + if (focused_background) { + config->colors.focused_background = parse_color(json_object_get_string(focused_background)); + } + + if (focused_statusline) { + config->colors.focused_statusline = parse_color(json_object_get_string(focused_statusline)); + } + + if (focused_separator) { + config->colors.focused_separator = parse_color(json_object_get_string(focused_separator)); + } + if (focused_workspace_border) { config->colors.focused_workspace.border = parse_color(json_object_get_string(focused_workspace_border)); } @@ -235,6 +251,13 @@ static void ipc_update_workspaces(struct bar *bar) { ws->name = strdup(json_object_get_string(name)); ws->visible = json_object_get_boolean(visible); ws->focused = json_object_get_boolean(focused); + if (ws->focused) { + if (bar->focused_output) { + bar->focused_output->focused = false; + } + bar->focused_output = output; + output->focused = true; + } ws->urgent = json_object_get_boolean(urgent); list_add(output->workspaces, ws); } diff --git a/swaybar/render.c b/swaybar/render.c index a9f1991d..2eae997f 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -49,7 +49,7 @@ static void render_sharp_line(cairo_t *cairo, uint32_t color, double x, double y } } -static void render_block(struct window *window, struct config *config, struct status_block *block, double *x, bool edge) { +static void render_block(struct window *window, struct config *config, struct status_block *block, double *x, bool edge, bool is_focused) { int width, height, sep_width; get_text_size(window->cairo, window->font, &width, &height, window->scale, block->markup, "%s", block->full_text); @@ -159,7 +159,11 @@ static void render_block(struct window *window, struct config *config, struct st // render separator if (!edge && block->separator) { - cairo_set_source_u32(window->cairo, config->colors.separator); + if (is_focused) { + cairo_set_source_u32(window->cairo, config->colors.focused_separator); + } else { + cairo_set_source_u32(window->cairo, config->colors.separator); + } if (config->sep_symbol) { offset = pos + (block->separator_block_width - sep_width) / 2; cairo_move_to(window->cairo, offset, margin); @@ -275,6 +279,7 @@ void render(struct output *output, struct config *config, struct status_line *li struct window *window = output->window; cairo_t *cairo = window->cairo; + bool is_focused = output->focused; // Clear cairo_save(cairo); @@ -285,11 +290,20 @@ void render(struct output *output, struct config *config, struct status_line *li cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE); // Background - cairo_set_source_u32(cairo, config->colors.background); + if (is_focused) { + cairo_set_source_u32(cairo, config->colors.focused_background); + } else { + cairo_set_source_u32(cairo, config->colors.background); + } cairo_paint(cairo); // Command output - cairo_set_source_u32(cairo, config->colors.statusline); + if (is_focused) { + cairo_set_source_u32(cairo, config->colors.focused_statusline); + } else { + cairo_set_source_u32(cairo, config->colors.statusline); + } + int width, height; if (line->protocol == TEXT) { @@ -305,7 +319,7 @@ void render(struct output *output, struct config *config, struct status_line *li for (i = line->block_line->length - 1; i >= 0; --i) { struct status_block *block = line->block_line->items[i]; if (block->full_text && block->full_text[0]) { - render_block(window, config, block, &pos, edge); + render_block(window, config, block, &pos, edge, is_focused); edge = false; } } -- cgit v1.2.3 From 58eb7ac19fe436737babcbd1effd41ef96af6632 Mon Sep 17 00:00:00 2001 From: "D.B" Date: Wed, 2 Nov 2016 21:07:04 +0100 Subject: change bar colors from char[10] to *char This commit removes has_* booleans from bar color struct. It also generalizes of functions in commands/bar/colors.c. --- include/sway/config.h | 50 +++++----- sway/commands.c | 1 + sway/commands/bar/colors.c | 222 ++++++++++++++------------------------------- sway/config.c | 68 ++++++++++---- sway/ipc-json.c | 12 +-- 5 files changed, 145 insertions(+), 208 deletions(-) (limited to 'sway/commands/bar') diff --git a/include/sway/config.h b/include/sway/config.h index 9b3cc60c..8d077ee7 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -145,35 +145,27 @@ struct bar_config { bool verbose; pid_t pid; struct { - char background[10]; - char statusline[10]; - char separator[10]; - char focused_background[10]; - char focused_statusline[10]; - char focused_separator[10]; - char focused_workspace_border[10]; - char focused_workspace_bg[10]; - char focused_workspace_text[10]; - char active_workspace_border[10]; - char active_workspace_bg[10]; - char active_workspace_text[10]; - char inactive_workspace_border[10]; - char inactive_workspace_bg[10]; - char inactive_workspace_text[10]; - char urgent_workspace_border[10]; - char urgent_workspace_bg[10]; - char urgent_workspace_text[10]; - char binding_mode_border[10]; - char binding_mode_bg[10]; - char binding_mode_text[10]; - - bool has_focused_background; - bool has_focused_statusline; - bool has_focused_separator; - - bool has_binding_mode_border; - bool has_binding_mode_bg; - bool has_binding_mode_text; + char *background; + char *statusline; + char *separator; + char *focused_background; + char *focused_statusline; + char *focused_separator; + char *focused_workspace_border; + char *focused_workspace_bg; + char *focused_workspace_text; + char *active_workspace_border; + char *active_workspace_bg; + char *active_workspace_text; + char *inactive_workspace_border; + char *inactive_workspace_bg; + char *inactive_workspace_text; + char *urgent_workspace_border; + char *urgent_workspace_bg; + char *urgent_workspace_text; + char *binding_mode_border; + char *binding_mode_bg; + char *binding_mode_text; } colors; }; diff --git a/sway/commands.c b/sway/commands.c index 872e9fc3..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; } diff --git a/sway/commands/bar/colors.c b/sway/commands/bar/colors.c index 8fb7fe27..f6fb520a 100644 --- a/sway/commands/bar/colors.c +++ b/sway/commands/bar/colors.c @@ -1,211 +1,123 @@ #include #include "sway/commands.h" -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); -} - -struct cmd_results *bar_colors_cmd_active_workspace(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, "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; + if (!*color) { + *color = malloc(10); } - 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_focused_background(int argc, char **argv) { +struct cmd_results *bar_cmd_colors(int argc, char **argv) { struct cmd_results *error = NULL; - if ((error = checkarg(argc, "focused_background", EXPECTED_EQUAL_TO, 1))) { + if ((error = checkarg(argc, "colors", EXPECTED_EQUAL_TO, 1))) { 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; + 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_binding_mode(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; - } else { - config->current_bar->colors.has_binding_mode_border = true; - } +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("binding_mode_bg", config->current_bar->colors.binding_mode_bg, argv[1]))) { - return error; - } else { - config->current_bar->colors.has_binding_mode_bg = true; - } +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("binding_mode_text", config->current_bar->colors.binding_mode_text, argv[2]))) { - return error; - } else { - config->current_bar->colors.has_binding_mode_text = true; - } +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); +} - return cmd_results_new(CMD_SUCCESS, NULL, NULL); +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); } 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; - } - - if ((error = add_color("focused_workspace_border", config->current_bar->colors.focused_workspace_border, argv[0]))) { - return error; - } - - if ((error = add_color("focused_workspace_bg", config->current_bar->colors.focused_workspace_bg, argv[1]))) { - return error; - } - - if ((error = add_color("focused_workspace_text", config->current_bar->colors.focused_workspace_text, argv[2]))) { - return error; - } - - return cmd_results_new(CMD_SUCCESS, NULL, NULL); + 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 cmd_results_new(CMD_SUCCESS, NULL, NULL); + return parse_single_color(&(config->current_bar->colors.separator), "separator", argc, argv); } struct cmd_results *bar_colors_cmd_focused_separator(int argc, char **argv) { - struct cmd_results *error = NULL; - 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); + 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 cmd_results_new(CMD_SUCCESS, NULL, NULL); + return parse_single_color(&(config->current_bar->colors.statusline), "statusline", argc, argv); } struct cmd_results *bar_colors_cmd_focused_statusline(int argc, char **argv) { - struct cmd_results *error = NULL; - 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); + 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 6d4cf2ff..d790afa2 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); } @@ -1109,6 +1131,12 @@ struct sway_binding *sway_binding_dup(struct sway_binding *sb) { return new_sb; } +static void set_bar_color(char **name, char *value) { + // every color has 9 characters plus \0 + *name = malloc(10); + strcpy(*name, value); +} + struct bar_config *default_bar_config(void) { struct bar_config *bar = NULL; bar = malloc(sizeof(struct bar_config)); @@ -1132,24 +1160,28 @@ 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"); - bar->colors.has_binding_mode_border = false; - bar->colors.has_binding_mode_bg = false; - bar->colors.has_binding_mode_text = false; + set_bar_color(&(bar->colors.background), "#000000ff"); + set_bar_color(&(bar->colors.statusline), "#ffffffff"); + set_bar_color(&(bar->colors.separator), "#666666ff"); + set_bar_color(&(bar->colors.focused_workspace_border), "#4c7899ff"); + set_bar_color(&(bar->colors.focused_workspace_bg), "#285577ff"); + set_bar_color(&(bar->colors.focused_workspace_text), "#ffffffff"); + set_bar_color(&(bar->colors.active_workspace_border), "#333333ff"); + set_bar_color(&(bar->colors.active_workspace_bg), "#5f676aff"); + set_bar_color(&(bar->colors.active_workspace_text), "#ffffffff"); + set_bar_color(&(bar->colors.inactive_workspace_border), "#333333ff"); + set_bar_color(&(bar->colors.inactive_workspace_bg),"#222222ff"); + set_bar_color(&(bar->colors.inactive_workspace_text), "#888888ff"); + set_bar_color(&(bar->colors.urgent_workspace_border), "#2f343aff"); + set_bar_color(&(bar->colors.urgent_workspace_bg),"#900000ff"); + set_bar_color(&(bar->colors.urgent_workspace_text), "#ffffffff"); + + 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 c21d28af..e65e9de3 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -312,19 +312,19 @@ 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.has_focused_background) { + 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.has_focused_statusline) { + 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.has_focused_separator) { + 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)); @@ -346,19 +346,19 @@ 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)); - if (bar->colors.has_binding_mode_border) { + 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.has_binding_mode_bg) { + 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.has_binding_mode_text) { + 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)); -- cgit v1.2.3