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.
This commit is contained in:
parent
39ee0ec552
commit
ad4d21d60b
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 },
|
||||
|
|
|
@ -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))) {
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
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
|
||||
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
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue