From 39ee0ec552c05c7ab5031982a1104a0bae1910d3 Mon Sep 17 00:00:00 2001 From: "D.B" Date: Wed, 2 Nov 2016 17:09:34 +0100 Subject: [PATCH] use urgent_ws color in swaybar if binding_mode is undefined --- include/sway/config.h | 4 ++++ sway/commands/bar/colors.c | 6 ++++++ sway/config.c | 6 +++--- sway/ipc-json.c | 20 +++++++++++++++++--- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/include/sway/config.h b/include/sway/config.h index a14b7e488..c41bb8b32 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -163,6 +163,10 @@ struct bar_config { char binding_mode_border[10]; char binding_mode_bg[10]; char binding_mode_text[10]; + + bool has_binding_mode_border; + bool has_binding_mode_bg; + bool has_binding_mode_text; } colors; }; diff --git a/sway/commands/bar/colors.c b/sway/commands/bar/colors.c index 9e374d888..e91806041 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); diff --git a/sway/config.c b/sway/config.c index 7a41a3c85..6d4cf2ffd 100644 --- a/sway/config.c +++ b/sway/config.c @@ -1147,9 +1147,9 @@ struct bar_config *default_bar_config(void) { 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.has_binding_mode_border = false; + bar->colors.has_binding_mode_bg = false; + bar->colors.has_binding_mode_text = false; list_add(config->bars, bar); diff --git a/sway/ipc-json.c b/sway/ipc-json.c index eb77a6542..458dc7c29 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -328,9 +328,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.has_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) { + 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) { + 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);