aboutsummaryrefslogtreecommitdiffstats
path: root/swaynag
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-12-27 23:33:55 -0500
committerLibravatar Simon Ser <contact@emersion.fr>2019-12-28 10:07:25 +0100
commit97f9f0b699316ba60009b395948a712ec0b671d2 (patch)
treeb5916b36f4161c1c4d670295254d0f3fd9e793df /swaynag
parentlayer-shell: refocus if keyboard interactive lost (diff)
downloadsway-97f9f0b699316ba60009b395948a712ec0b671d2.tar.gz
sway-97f9f0b699316ba60009b395948a712ec0b671d2.tar.zst
sway-97f9f0b699316ba60009b395948a712ec0b671d2.zip
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.c20
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,
221 fprintf(stdout, "swaynag version " SWAY_VERSION "\n"); 221 fprintf(stdout, "swaynag version " SWAY_VERSION "\n");
222 return -1; 222 return -1;
223 case TO_COLOR_BACKGROUND: // Background color 223 case TO_COLOR_BACKGROUND: // Background color
224 if (type) { 224 if (type && !parse_color(optarg, &type->background)) {
225 type->background = parse_color(optarg); 225 fprintf(stderr, "Invalid background color: %s", optarg);
226 } 226 }
227 break; 227 break;
228 case TO_COLOR_BORDER: // Border color 228 case TO_COLOR_BORDER: // Border color
229 if (type) { 229 if (type && !parse_color(optarg, &type->border)) {
230 type->border = parse_color(optarg); 230 fprintf(stderr, "Invalid border color: %s", optarg);
231 } 231 }
232 break; 232 break;
233 case TO_COLOR_BORDER_BOTTOM: // Bottom border color 233 case TO_COLOR_BORDER_BOTTOM: // Bottom border color
234 if (type) { 234 if (type && !parse_color(optarg, &type->border_bottom)) {
235 type->border_bottom = parse_color(optarg); 235 fprintf(stderr, "Invalid border bottom color: %s", optarg);
236 } 236 }
237 break; 237 break;
238 case TO_COLOR_BUTTON: // Button background color 238 case TO_COLOR_BUTTON: // Button background color
239 if (type) { 239 if (type && !parse_color(optarg, &type->button_background)) {
240 type->button_background = parse_color(optarg); 240 fprintf(stderr, "Invalid button background color: %s", optarg);
241 } 241 }
242 break; 242 break;
243 case TO_COLOR_TEXT: // Text color 243 case TO_COLOR_TEXT: // Text color
244 if (type) { 244 if (type && !parse_color(optarg, &type->text)) {
245 type->text = parse_color(optarg); 245 fprintf(stderr, "Invalid text color: %s", optarg);
246 } 246 }
247 break; 247 break;
248 case TO_THICK_BAR_BORDER: // Bottom border thickness 248 case TO_THICK_BAR_BORDER: // Bottom border thickness