Skip to content

Commit

Permalink
options: support shadow-color as a commandline option
Browse files Browse the repository at this point in the history
Signed-off-by: Yuxuan Shui <[email protected]>
  • Loading branch information
yshui committed Aug 18, 2020
1 parent e90bd92 commit 2b677c8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
15 changes: 0 additions & 15 deletions src/config_libconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,6 @@

#pragma GCC diagnostic error "-Wunused-parameter"

/**
* Hex color to rgb
*/
struct color hex_to_rgb(const char *hex) {
struct color rgb;
// Ignore the # in front of the string
const char *sane_hex = hex + 1;
int hex_color = (int)strtol(sane_hex, NULL, 16);
rgb.red = (float)(hex_color >> 16) / 256;
rgb.green = (float)((hex_color & 0x00ff00) >> 8) / 256;
rgb.blue = (float)(hex_color & 0x0000ff) / 256;

return rgb;
}

/**
* Wrapper of libconfig's <code>config_lookup_int</code>.
*
Expand Down
12 changes: 12 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ static void usage(const char *argv0, int ret) {
"--write-pid-path path\n"
" Write process ID to a file.\n"
"\n"
"--shadow-color color\n"
" Color of shadow, as a hex RGB string (defaults to #000000)\n"
"\n"
"--shadow-red value\n"
" Red color value of shadow (0.0 - 1.0, defaults to 0).\n"
"\n"
Expand Down Expand Up @@ -435,6 +438,7 @@ static const struct option longopts[] = {
{"blur-method", required_argument, NULL, 328},
{"blur-size", required_argument, NULL, 329},
{"blur-deviation", required_argument, NULL, 330},
{"shadow-color", required_argument, NULL, 331},
{"experimental-backends", no_argument, NULL, 733},
{"monitor-repaint", no_argument, NULL, 800},
{"diagnostics", no_argument, NULL, 801},
Expand Down Expand Up @@ -604,6 +608,14 @@ bool get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
case 256:
// --config
break;
case 331:;
// --shadow-color
struct color rgb;
rgb = hex_to_rgb(optarg);
opt->shadow_red = rgb.red;
opt->shadow_green = rgb.green;
opt->shadow_blue = rgb.blue;
break;
case 257:
// --shadow-red
opt->shadow_red = atof(optarg);
Expand Down
16 changes: 16 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <test.h>

#include "compiler.h"
#include "types.h"

#define ARR_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))

Expand Down Expand Up @@ -165,6 +166,21 @@ static inline double attr_const normalize_d(double d) {
return normalize_d_range(d, 0.0, 1.0);
}

/**
* Convert a hex RGB string to RGB
*/
static inline struct color hex_to_rgb(const char *hex) {
struct color rgb;
// Ignore the # in front of the string
const char *sane_hex = hex + 1;
int hex_color = (int)strtol(sane_hex, NULL, 16);
rgb.red = (float)(hex_color >> 16) / 256;
rgb.green = (float)((hex_color & 0x00ff00) >> 8) / 256;
rgb.blue = (float)(hex_color & 0x0000ff) / 256;

return rgb;
}

attr_noret void
report_allocation_failure(const char *func, const char *file, unsigned int line);

Expand Down

0 comments on commit 2b677c8

Please sign in to comment.