Add rgba support for bar colors

This commit is contained in:
Mikkel Oscar Lyderik 2015-12-15 13:45:04 +01:00
parent 8c1d56812b
commit de1f625c27
3 changed files with 46 additions and 40 deletions

View file

@ -99,24 +99,24 @@ struct bar_config {
bool binding_mode_indicator; bool binding_mode_indicator;
bool verbose; bool verbose;
struct { struct {
char background[8]; char background[10];
char statusline[8]; char statusline[10];
char separator[8]; char separator[10];
char focused_workspace_border[8]; char focused_workspace_border[10];
char focused_workspace_bg[8]; char focused_workspace_bg[10];
char focused_workspace_text[8]; char focused_workspace_text[10];
char active_workspace_border[8]; char active_workspace_border[10];
char active_workspace_bg[8]; char active_workspace_bg[10];
char active_workspace_text[8]; char active_workspace_text[10];
char inactive_workspace_border[8]; char inactive_workspace_border[10];
char inactive_workspace_bg[8]; char inactive_workspace_bg[10];
char inactive_workspace_text[8]; char inactive_workspace_text[10];
char urgent_workspace_border[8]; char urgent_workspace_border[10];
char urgent_workspace_bg[8]; char urgent_workspace_bg[10];
char urgent_workspace_text[8]; char urgent_workspace_text[10];
char binding_mode_border[8]; char binding_mode_border[10];
char binding_mode_bg[8]; char binding_mode_bg[10];
char binding_mode_text[8]; char binding_mode_text[10];
} colors; } colors;
}; };

View file

@ -1851,7 +1851,8 @@ static struct cmd_handler bar_handlers[] = {
* return error object, or NULL if color is valid. * return error object, or NULL if color is valid.
*/ */
static struct cmd_results *add_color(const char *name, char *buffer, const char *color) { static struct cmd_results *add_color(const char *name, char *buffer, const char *color) {
if (strlen(color) != 7) { int len = strlen(color);
if (len != 7 && len != 9 ) {
return cmd_results_new(CMD_INVALID, name, "Invalid color definition %s", color); return cmd_results_new(CMD_INVALID, name, "Invalid color definition %s", color);
} }
@ -1860,15 +1861,20 @@ static struct cmd_results *add_color(const char *name, char *buffer, const char
} }
int i; int i;
for (i = 1; i < 7; ++i) { for (i = 1; i < len; ++i) {
if (!isxdigit(color[i])) { if (!isxdigit(color[i])) {
return cmd_results_new(CMD_INVALID, name, "Invalid color definition %s", color); return cmd_results_new(CMD_INVALID, name, "Invalid color definition %s", color);
} }
} }
// copy color to buffer // copy color to buffer
strncpy(buffer, color, 7); strncpy(buffer, color, len);
sway_log(L_DEBUG, "Setting %s color %s for bar: %s", name, color, config->current_bar->id); // add default alpha channel if color was defined without it
if (len == 7) {
buffer[7] = 'f';
buffer[8] = 'f';
}
sway_log(L_DEBUG, "Setting %s color %s for bar: %s", name, buffer, config->current_bar->id);
return NULL; return NULL;
} }

View file

@ -568,24 +568,24 @@ struct bar_config *default_bar_config(void) {
bar->binding_mode_indicator = true; bar->binding_mode_indicator = true;
bar->tray_padding = 2; bar->tray_padding = 2;
// set default colors // set default colors
strcpy(bar->colors.background, "#000000"); strcpy(bar->colors.background, "#000000ff");
strcpy(bar->colors.statusline, "#ffffff"); strcpy(bar->colors.statusline, "#ffffffff");
strcpy(bar->colors.separator, "#666666"); strcpy(bar->colors.separator, "#666666ff");
strcpy(bar->colors.focused_workspace_border, "#4c7899"); strcpy(bar->colors.focused_workspace_border, "#4c7899ff");
strcpy(bar->colors.focused_workspace_bg, "#285577"); strcpy(bar->colors.focused_workspace_bg, "#285577ff");
strcpy(bar->colors.focused_workspace_text, "#ffffff"); strcpy(bar->colors.focused_workspace_text, "#ffffffff");
strcpy(bar->colors.active_workspace_border, "333333"); strcpy(bar->colors.active_workspace_border, "333333ff");
strcpy(bar->colors.active_workspace_bg, "#5f676a"); strcpy(bar->colors.active_workspace_bg, "#5f676aff");
strcpy(bar->colors.active_workspace_text, "#ffffff"); strcpy(bar->colors.active_workspace_text, "#ffffffff");
strcpy(bar->colors.inactive_workspace_border, "#333333"); strcpy(bar->colors.inactive_workspace_border, "#333333ff");
strcpy(bar->colors.inactive_workspace_bg,"#222222"); strcpy(bar->colors.inactive_workspace_bg,"#222222ff");
strcpy(bar->colors.inactive_workspace_text, "#888888"); strcpy(bar->colors.inactive_workspace_text, "#888888ff");
strcpy(bar->colors.urgent_workspace_border, "#2f343a"); strcpy(bar->colors.urgent_workspace_border, "#2f343aff");
strcpy(bar->colors.urgent_workspace_bg,"#900000"); strcpy(bar->colors.urgent_workspace_bg,"#900000ff");
strcpy(bar->colors.urgent_workspace_text, "#ffffff"); strcpy(bar->colors.urgent_workspace_text, "#ffffffff");
strcpy(bar->colors.binding_mode_border, "#2f343a"); strcpy(bar->colors.binding_mode_border, "#2f343aff");
strcpy(bar->colors.binding_mode_bg,"#900000"); strcpy(bar->colors.binding_mode_bg,"#900000ff");
strcpy(bar->colors.binding_mode_text, "#ffffff"); strcpy(bar->colors.binding_mode_text, "#ffffffff");
list_add(config->bars, bar); list_add(config->bars, bar);