mirror of
https://github.com/swaywm/sway.git
synced 2025-11-09 13:29:49 -05:00
bar_cmd_colors: remove add_color
This is the third commit in a series of commits to refactor color handling in sway. This removes add_color from commands.c. It was only being used by bar_cmd_colors. This also changes the functions to use parse_color which is used to validate rgb(a) colors throughout the code base and is also what i3bar is using to parse the colors after they are passed over ipc. After parsing the color and ensuring it is valid, the rgba hex string is then generated using snprintf. This refactor also ensures that all the colors for the command are valid before applying any of them.
This commit is contained in:
parent
66dc33296c
commit
f898ca9a83
3 changed files with 33 additions and 49 deletions
|
|
@ -567,34 +567,3 @@ char *cmd_results_to_json(list_t *res_list) {
|
|||
json_object_put(result_array);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and add color to buffer.
|
||||
*
|
||||
* return error object, or NULL if color is valid.
|
||||
*/
|
||||
struct cmd_results *add_color(char *buffer, const char *color) {
|
||||
int len = strlen(color);
|
||||
if (len != 7 && len != 9) {
|
||||
return cmd_results_new(CMD_INVALID,
|
||||
"Invalid color definition %s", color);
|
||||
}
|
||||
if (color[0] != '#') {
|
||||
return cmd_results_new(CMD_INVALID,
|
||||
"Invalid color definition %s", color);
|
||||
}
|
||||
for (int i = 1; i < len; ++i) {
|
||||
if (!isxdigit(color[i])) {
|
||||
return cmd_results_new(CMD_INVALID,
|
||||
"Invalid color definition %s", color);
|
||||
}
|
||||
}
|
||||
strcpy(buffer, color);
|
||||
// add default alpha channel if color was defined without it
|
||||
if (len == 7) {
|
||||
buffer[7] = 'f';
|
||||
buffer[8] = 'f';
|
||||
}
|
||||
buffer[9] = '\0';
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue