diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-12-27 23:56:11 -0500 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2019-12-28 10:07:25 +0100 |
commit | 66dc33296ca97b10f60daaff8c5e4b3f95fac8cd (patch) | |
tree | 95cb83ff86cf43d096df4f10a3cfb402d34315f7 /common | |
parent | parse_color: return success + drop fallback color (diff) | |
download | sway-66dc33296ca97b10f60daaff8c5e4b3f95fac8cd.tar.gz sway-66dc33296ca97b10f60daaff8c5e4b3f95fac8cd.tar.zst sway-66dc33296ca97b10f60daaff8c5e4b3f95fac8cd.zip |
cmd_client_*: refactor duplicated code
This is the second in a series of commits to refactor the color handling
in sway. This removes the duplicated color parsing code in
sway/commands/client.c. Additionally, this combines the parsing of
colors to float arrays with that in sway/config.c and introduces a
color_to_rgba function in commom/util.c.
As an added bonus, this also makes it so non of the colors in a border
color class will be changed unless all of the colors specified are
valid. This ensures that an invalid command does not get partially
applied.
Diffstat (limited to 'common')
-rw-r--r-- | common/util.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/common/util.c b/common/util.c index 84ebab99..c7ef2ac4 100644 --- a/common/util.c +++ b/common/util.c | |||
@@ -31,6 +31,13 @@ bool parse_color(const char *color, uint32_t *result) { | |||
31 | return true; | 31 | return true; |
32 | } | 32 | } |
33 | 33 | ||
34 | void color_to_rgba(float dest[static 4], uint32_t color) { | ||
35 | dest[0] = ((color >> 24) & 0xff) / 255.0; | ||
36 | dest[1] = ((color >> 16) & 0xff) / 255.0; | ||
37 | dest[2] = ((color >> 8) & 0xff) / 255.0; | ||
38 | dest[3] = (color & 0xff) / 255.0; | ||
39 | } | ||
40 | |||
34 | bool parse_boolean(const char *boolean, bool current) { | 41 | bool parse_boolean(const char *boolean, bool current) { |
35 | if (strcasecmp(boolean, "1") == 0 | 42 | if (strcasecmp(boolean, "1") == 0 |
36 | || strcasecmp(boolean, "yes") == 0 | 43 | || strcasecmp(boolean, "yes") == 0 |