diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-12-27 23:33:55 -0500 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2019-12-28 10:07:25 +0100 |
commit | 97f9f0b699316ba60009b395948a712ec0b671d2 (patch) | |
tree | b5916b36f4161c1c4d670295254d0f3fd9e793df /swaynag | |
parent | 088b374b1a3e7ead08e1430d3d89649b1cd5a54b (diff) |
parse_color: return success + drop fallback color
This is the first in a series of commits to refactor the color handling
in sway. This changes parse_color to return whether it was success and
no longer uses 0xFFFFFFFF as the fallback color. This also verifies that
the string actually contains a valid hexadecimal number along with
the length checks.
In the process of altering the calls to parse_color, I also took the
opportunity to heavily refactor swaybar's ipc_parse_colors function.
This allowed for several lines of duplicated code to be removed.
Diffstat (limited to 'swaynag')
-rw-r--r-- | swaynag/config.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/swaynag/config.c b/swaynag/config.c index 2fa7cb61..f1161b39 100644 --- a/swaynag/config.c +++ b/swaynag/config.c @@ -221,28 +221,28 @@ int swaynag_parse_options(int argc, char **argv, struct swaynag *swaynag, fprintf(stdout, "swaynag version " SWAY_VERSION "\n"); return -1; case TO_COLOR_BACKGROUND: // Background color - if (type) { - type->background = parse_color(optarg); + if (type && !parse_color(optarg, &type->background)) { + fprintf(stderr, "Invalid background color: %s", optarg); } break; case TO_COLOR_BORDER: // Border color - if (type) { - type->border = parse_color(optarg); + if (type && !parse_color(optarg, &type->border)) { + fprintf(stderr, "Invalid border color: %s", optarg); } break; case TO_COLOR_BORDER_BOTTOM: // Bottom border color - if (type) { - type->border_bottom = parse_color(optarg); + if (type && !parse_color(optarg, &type->border_bottom)) { + fprintf(stderr, "Invalid border bottom color: %s", optarg); } break; case TO_COLOR_BUTTON: // Button background color - if (type) { - type->button_background = parse_color(optarg); + if (type && !parse_color(optarg, &type->button_background)) { + fprintf(stderr, "Invalid button background color: %s", optarg); } break; case TO_COLOR_TEXT: // Text color - if (type) { - type->text = parse_color(optarg); + if (type && !parse_color(optarg, &type->text)) { + fprintf(stderr, "Invalid text color: %s", optarg); } break; case TO_THICK_BAR_BORDER: // Bottom border thickness |