mirror of
https://github.com/swaywm/sway.git
synced 2026-03-13 05:34:04 -04:00
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
9 changed files with 124 additions and 6 deletions
|
|
@ -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) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue