sway/include/util.h
Brian Ashworth 97f9f0b699 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.
2019-12-28 10:07:25 +01:00

39 lines
1 KiB
C

#ifndef _SWAY_UTIL_H
#define _SWAY_UTIL_H
#include <stdint.h>
#include <stdbool.h>
#include <wayland-server-protocol.h>
/**
* Wrap i into the range [0, max[
*/
int wrap(int i, int max);
/**
* Given a string that represents an RGB(A) color, result will be set to a
* uint32_t version of the color, as long as it is valid. If it is invalid,
* then false will be returned and result will be untouched.
*/
bool parse_color(const char *color, uint32_t *result);
/**
* Given a string that represents a boolean, return the boolean value. This
* function also takes in the current boolean value to support toggling. If
* toggling is not desired, pass in true for current so that toggling values
* get parsed as not true.
*/
bool parse_boolean(const char *boolean, bool current);
/**
* Given a string that represents a floating point value, return a float.
* Returns NAN on error.
*/
float parse_float(const char *value);
const char *sway_wl_output_subpixel_to_string(enum wl_output_subpixel subpixel);
bool sway_set_cloexec(int fd, bool cloexec);
#endif