Merge pull request #965 from thejan2009/swaybar-colours

Fix some colour settings in swaybar
This commit is contained in:
Drew DeVault 2016-11-03 08:32:10 -06:00 committed by GitHub
commit e9ac0492b7
10 changed files with 236 additions and 162 deletions

View file

@ -160,12 +160,14 @@ sway_cmd bar_cmd_workspace_buttons;
sway_cmd bar_colors_cmd_active_workspace; sway_cmd bar_colors_cmd_active_workspace;
sway_cmd bar_colors_cmd_background; 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_binding_mode;
sway_cmd bar_colors_cmd_focused_workspace; sway_cmd bar_colors_cmd_focused_workspace;
sway_cmd bar_colors_cmd_inactive_workspace; sway_cmd bar_colors_cmd_inactive_workspace;
sway_cmd bar_colors_cmd_separator; sway_cmd bar_colors_cmd_separator;
sway_cmd bar_colors_cmd_focused_separator;
sway_cmd bar_colors_cmd_statusline; sway_cmd bar_colors_cmd_statusline;
sway_cmd bar_colors_cmd_focused_statusline;
sway_cmd bar_colors_cmd_urgent_workspace; sway_cmd bar_colors_cmd_urgent_workspace;
sway_cmd input_cmd_accel_profile; sway_cmd input_cmd_accel_profile;

View file

@ -145,24 +145,27 @@ struct bar_config {
bool verbose; bool verbose;
pid_t pid; pid_t pid;
struct { struct {
char background[10]; char *background;
char statusline[10]; char *statusline;
char separator[10]; char *separator;
char focused_workspace_border[10]; char *focused_background;
char focused_workspace_bg[10]; char *focused_statusline;
char focused_workspace_text[10]; char *focused_separator;
char active_workspace_border[10]; char *focused_workspace_border;
char active_workspace_bg[10]; char *focused_workspace_bg;
char active_workspace_text[10]; char *focused_workspace_text;
char inactive_workspace_border[10]; char *active_workspace_border;
char inactive_workspace_bg[10]; char *active_workspace_bg;
char inactive_workspace_text[10]; char *active_workspace_text;
char urgent_workspace_border[10]; char *inactive_workspace_border;
char urgent_workspace_bg[10]; char *inactive_workspace_bg;
char urgent_workspace_text[10]; char *inactive_workspace_text;
char binding_mode_border[10]; char *urgent_workspace_border;
char binding_mode_bg[10]; char *urgent_workspace_bg;
char binding_mode_text[10]; char *urgent_workspace_text;
char *binding_mode_border;
char *binding_mode_bg;
char *binding_mode_text;
} colors; } colors;
}; };

View file

@ -9,6 +9,7 @@ struct bar {
struct config *config; struct config *config;
struct status_line *status; struct status_line *status;
list_t *outputs; list_t *outputs;
struct output *focused_output;
int ipc_event_socketfd; int ipc_event_socketfd;
int ipc_socketfd; int ipc_socketfd;
@ -22,6 +23,7 @@ struct output {
list_t *workspaces; list_t *workspaces;
char *name; char *name;
int idx; int idx;
bool focused;
}; };
struct workspace { struct workspace {

View file

@ -40,6 +40,10 @@ struct config {
uint32_t statusline; uint32_t statusline;
uint32_t separator; uint32_t separator;
uint32_t focused_background;
uint32_t focused_statusline;
uint32_t focused_separator;
struct box_colors focused_workspace; struct box_colors focused_workspace;
struct box_colors active_workspace; struct box_colors active_workspace;
struct box_colors inactive_workspace; struct box_colors inactive_workspace;

View file

@ -255,6 +255,7 @@ struct cmd_results *add_color(const char *name, char *buffer, const char *color)
buffer[7] = 'f'; buffer[7] = 'f';
buffer[8] = 'f'; buffer[8] = 'f';
} }
buffer[9] = '\0';
return NULL; return NULL;
} }
@ -277,6 +278,9 @@ static struct cmd_handler bar_colors_handlers[] = {
{ "active_workspace", bar_colors_cmd_active_workspace }, { "active_workspace", bar_colors_cmd_active_workspace },
{ "background", bar_colors_cmd_background }, { "background", bar_colors_cmd_background },
{ "binding_mode", bar_colors_cmd_binding_mode }, { "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 }, { "focused_workspace", bar_colors_cmd_focused_workspace },
{ "inactive_workspace", bar_colors_cmd_inactive_workspace }, { "inactive_workspace", bar_colors_cmd_inactive_workspace },
{ "separator", bar_colors_cmd_separator }, { "separator", bar_colors_cmd_separator },

View file

@ -1,6 +1,44 @@
#include <string.h> #include <string.h>
#include "sway/commands.h" #include "sway/commands.h"
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, cmd_name, EXPECTED_EQUAL_TO, 1))) {
return error;
}
if (!*color) {
*color = malloc(10);
}
error = add_color(cmd_name, *color, argv[0]);
if (error) {
return error;
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
static struct cmd_results *parse_three_colors(char ***colors, const char *cmd_name, int argc, char **argv) {
struct cmd_results *error = NULL;
if (argc != 3) {
return cmd_results_new(CMD_INVALID, cmd_name, "Requires exactly three color values");
}
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_cmd_colors(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, "colors", EXPECTED_EQUAL_TO, 1))) { if ((error = checkarg(argc, "colors", EXPECTED_EQUAL_TO, 1))) {
@ -16,145 +54,70 @@ struct cmd_results *bar_cmd_colors(int argc, char **argv) {
} }
struct cmd_results *bar_colors_cmd_active_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, "active_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)
};
if ((error = add_color("active_workspace_border", config->current_bar->colors.active_workspace_border, argv[0]))) { return parse_three_colors(colors, "active_workspace", argc, argv);
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]))) {
return error;
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }
struct cmd_results *bar_colors_cmd_background(int argc, char **argv) { struct cmd_results *bar_colors_cmd_background(int argc, char **argv) {
struct cmd_results *error = NULL; return parse_single_color(&(config->current_bar->colors.background), "background", argc, argv);
if ((error = checkarg(argc, "background", EXPECTED_EQUAL_TO, 1))) { }
return error;
}
if ((error = add_color("background", config->current_bar->colors.background, argv[0]))) { 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);
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }
struct cmd_results *bar_colors_cmd_binding_mode(int argc, char **argv) { struct cmd_results *bar_colors_cmd_binding_mode(int argc, char **argv) {
struct cmd_results *error = NULL; char **colors[3] = {
if ((error = checkarg(argc, "binding_mode", EXPECTED_EQUAL_TO, 3))) { &(config->current_bar->colors.binding_mode_border),
return error; &(config->current_bar->colors.binding_mode_bg),
} &(config->current_bar->colors.binding_mode_text)
};
if ((error = add_color("binding_mode_border", config->current_bar->colors.binding_mode_border, argv[0]))) { return parse_three_colors(colors, "binding_mode", argc, argv);
return error;
}
if ((error = add_color("binding_mode_bg", config->current_bar->colors.binding_mode_bg, argv[1]))) {
return error;
}
if ((error = add_color("binding_mode_text", config->current_bar->colors.binding_mode_text, argv[2]))) {
return error;
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }
struct cmd_results *bar_colors_cmd_focused_workspace(int argc, char **argv) { struct cmd_results *bar_colors_cmd_focused_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.focused_workspace_border),
return error; &(config->current_bar->colors.focused_workspace_bg),
} &(config->current_bar->colors.focused_workspace_text)
};
if ((error = add_color("focused_workspace_border", config->current_bar->colors.focused_workspace_border, argv[0]))) { return parse_three_colors(colors, "focused_workspace", argc, argv);
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);
} }
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]))) { struct cmd_results *bar_colors_cmd_focused_separator(int argc, char **argv) {
return error; return parse_single_color(&(config->current_bar->colors.focused_separator), "focused_separator", argc, argv);
}
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]))) { struct cmd_results *bar_colors_cmd_focused_statusline(int argc, char **argv) {
return error; return parse_single_color(&(config->current_bar->colors.focused_separator), "focused_separator", argc, argv);
}
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);
} }

View file

@ -70,6 +70,28 @@ static void free_bar(struct bar_config *bar) {
terminate_swaybar(bar->pid); 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); free(bar);
} }
@ -1132,24 +1154,29 @@ struct bar_config *default_bar_config(void) {
bar->verbose = false; bar->verbose = false;
bar->pid = 0; bar->pid = 0;
// set default colors // set default colors
strcpy(bar->colors.background, "#000000ff"); bar->colors.background = strndup("#000000ff", 9);
strcpy(bar->colors.statusline, "#ffffffff"); bar->colors.statusline = strndup("#ffffffff", 9);
strcpy(bar->colors.separator, "#666666ff"); bar->colors.separator = strndup("#666666ff", 9);
strcpy(bar->colors.focused_workspace_border, "#4c7899ff"); bar->colors.focused_workspace_border = strndup("#4c7899ff", 9);
strcpy(bar->colors.focused_workspace_bg, "#285577ff"); bar->colors.focused_workspace_bg = strndup("#285577ff", 9);
strcpy(bar->colors.focused_workspace_text, "#ffffffff"); bar->colors.focused_workspace_text = strndup("#ffffffff", 9);
strcpy(bar->colors.active_workspace_border, "#333333ff"); bar->colors.active_workspace_border = strndup("#333333ff", 9);
strcpy(bar->colors.active_workspace_bg, "#5f676aff"); bar->colors.active_workspace_bg = strndup("#5f676aff", 9);
strcpy(bar->colors.active_workspace_text, "#ffffffff"); bar->colors.active_workspace_text = strndup("#ffffffff", 9);
strcpy(bar->colors.inactive_workspace_border, "#333333ff"); bar->colors.inactive_workspace_border = strndup("#333333ff", 9);
strcpy(bar->colors.inactive_workspace_bg,"#222222ff"); bar->colors.inactive_workspace_bg = strndup("#222222ff", 9);
strcpy(bar->colors.inactive_workspace_text, "#888888ff"); bar->colors.inactive_workspace_text = strndup("#888888ff", 9);
strcpy(bar->colors.urgent_workspace_border, "#2f343aff"); bar->colors.urgent_workspace_border = strndup("#2f343aff", 9);
strcpy(bar->colors.urgent_workspace_bg,"#900000ff"); bar->colors.urgent_workspace_bg = strndup("#900000ff", 9);
strcpy(bar->colors.urgent_workspace_text, "#ffffffff"); bar->colors.urgent_workspace_text = strndup("#ffffffff", 9);
strcpy(bar->colors.binding_mode_border, "#2f343aff"); // if the following colors stay undefined, they fall back to background,
strcpy(bar->colors.binding_mode_bg,"#900000ff"); // statusline, separator and urgent_workspace_*.
strcpy(bar->colors.binding_mode_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); list_add(config->bars, bar);

View file

@ -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, "statusline", json_object_new_string(bar->colors.statusline));
json_object_object_add(colors, "separator", json_object_new_string(bar->colors.separator)); 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_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_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)); 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_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, "urgent_workspace_text", json_object_new_string(bar->colors.urgent_workspace_text));
if (bar->colors.binding_mode_border) {
json_object_object_add(colors, "binding_mode_border", json_object_new_string(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)); 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)); 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); json_object_object_add(json, "colors", colors);

View file

@ -108,6 +108,7 @@ static void ipc_parse_config(struct config *config, const char *payload) {
if (colors) { if (colors) {
json_object *background, *statusline, *separator; 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 *focused_workspace_border, *focused_workspace_bg, *focused_workspace_text;
json_object *inactive_workspace_border, *inactive_workspace_bg, *inactive_workspace_text; json_object *inactive_workspace_border, *inactive_workspace_bg, *inactive_workspace_text;
json_object *active_workspace_border, *active_workspace_bg, *active_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, "background", &background);
json_object_object_get_ex(colors, "statusline", &statusline); json_object_object_get_ex(colors, "statusline", &statusline);
json_object_object_get_ex(colors, "separator", &separator); 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_border", &focused_workspace_border);
json_object_object_get_ex(colors, "focused_workspace_bg", &focused_workspace_bg); json_object_object_get_ex(colors, "focused_workspace_bg", &focused_workspace_bg);
json_object_object_get_ex(colors, "focused_workspace_text", &focused_workspace_text); 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)); 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) { if (focused_workspace_border) {
config->colors.focused_workspace.border = parse_color(json_object_get_string(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->name = strdup(json_object_get_string(name));
ws->visible = json_object_get_boolean(visible); ws->visible = json_object_get_boolean(visible);
ws->focused = json_object_get_boolean(focused); 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); ws->urgent = json_object_get_boolean(urgent);
list_add(output->workspaces, ws); list_add(output->workspaces, ws);
} }

View file

@ -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; int width, height, sep_width;
get_text_size(window->cairo, window->font, &width, &height, get_text_size(window->cairo, window->font, &width, &height,
window->scale, block->markup, "%s", block->full_text); 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 // render separator
if (!edge && block->separator) { if (!edge && block->separator) {
if (is_focused) {
cairo_set_source_u32(window->cairo, config->colors.focused_separator);
} else {
cairo_set_source_u32(window->cairo, config->colors.separator); cairo_set_source_u32(window->cairo, config->colors.separator);
}
if (config->sep_symbol) { if (config->sep_symbol) {
offset = pos + (block->separator_block_width - sep_width) / 2; offset = pos + (block->separator_block_width - sep_width) / 2;
cairo_move_to(window->cairo, offset, margin); 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; struct window *window = output->window;
cairo_t *cairo = window->cairo; cairo_t *cairo = window->cairo;
bool is_focused = output->focused;
// Clear // Clear
cairo_save(cairo); 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); cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
// Background // Background
if (is_focused) {
cairo_set_source_u32(cairo, config->colors.focused_background);
} else {
cairo_set_source_u32(cairo, config->colors.background); cairo_set_source_u32(cairo, config->colors.background);
}
cairo_paint(cairo); cairo_paint(cairo);
// Command output // Command output
if (is_focused) {
cairo_set_source_u32(cairo, config->colors.focused_statusline);
} else {
cairo_set_source_u32(cairo, config->colors.statusline); cairo_set_source_u32(cairo, config->colors.statusline);
}
int width, height; int width, height;
if (line->protocol == TEXT) { 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) { for (i = line->block_line->length - 1; i >= 0; --i) {
struct status_block *block = line->block_line->items[i]; struct status_block *block = line->block_line->items[i];
if (block->full_text && block->full_text[0]) { 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; edge = false;
} }
} }