aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/config.c8
-rw-r--r--src/config.h1
-rw-r--r--src/util.c26
-rw-r--r--src/util.h7
4 files changed, 34 insertions, 8 deletions
diff --git a/src/config.c b/src/config.c
index 93b4f53..1488a55 100644
--- a/src/config.c
+++ b/src/config.c
@@ -101,10 +101,6 @@ static bool config_read_bool(const char *value, bool *result)
static bool config_read_color(const char *value, color_t *result)
{
- if (!strcmp(value, "rgb")) {
- log_panic("TODO");
- }
-
if (value[0] == '#') {
char *end;
unsigned long n = strtoul(value + 1, &end, 16);
@@ -212,7 +208,9 @@ static bool config_entry(config_t *config, int line, const char *section, const
case CONFIG_COLOR:
if (config_read_color(value, (color_t *)result)) {
- log_debug("Config '%s' set to '%s'", key, value);
+ char *color = color_to_string((color_t *)result);
+ log_debug("Config '%s' set to '%s'", key, color);
+ free(color);
return true;
}
break;
diff --git a/src/config.h b/src/config.h
index 11c4053..4edc59d 100644
--- a/src/config.h
+++ b/src/config.h
@@ -12,6 +12,7 @@ typedef struct {
unsigned int height;
unsigned int width;
bool override_redirect;
+ color_t background;
} config_t;
void config_init(config_t *config);
diff --git a/src/util.c b/src/util.c
index b658769..303942e 100644
--- a/src/util.c
+++ b/src/util.c
@@ -5,6 +5,28 @@
#include "util.h"
+char *color_to_string(color_t *color)
+{
+ unsigned int r = color->r * 255,
+ g = color->g * 255,
+ b = color->b * 255,
+ a = color->a * 255;
+
+ char buffer[32];
+ int n = snprintf(buffer, 32, "#%02x%02x%02x%02x", r, g, b, a);
+ return strslice(buffer, 0, n);
+}
+
+void color_print(FILE *stream, color_t *color)
+{
+ unsigned int r = color->r * 255,
+ g = color->g * 255,
+ b = color->b * 255,
+ a = color->a * 255;
+
+ fprintf(stream, "#%02x%02x%02x%02x", r, g, b, a);
+}
+
struct timespec timespec_diff(struct timespec a, struct timespec b)
{
bool over = (b.tv_nsec - a.tv_nsec) < 0;
@@ -21,9 +43,9 @@ bool timespec_greater(struct timespec a, struct timespec b)
|| (a.tv_sec == b.tv_sec && a.tv_nsec > b.tv_nsec);
}
-void timespec_print(struct timespec *ts)
+void timespec_print(FILE *stream, struct timespec *ts)
{
- printf("%ld.%.9ld", ts->tv_sec, ts->tv_nsec);
+ fprintf(stream, "%ld.%.9ld", ts->tv_sec, ts->tv_nsec);
}
bool check_rect(int px, int py, int x, int y, int w, int h)
diff --git a/src/util.h b/src/util.h
index e7a7863..b9c84f2 100644
--- a/src/util.h
+++ b/src/util.h
@@ -4,6 +4,7 @@
#include <time.h>
#include <stddef.h>
#include <stdbool.h>
+#include <stdio.h>
// Color representation normalized to [0, 1]
//
@@ -22,11 +23,15 @@ static inline color_t color_rgb(int r, int g, int b)
return color_rgba(r, g, b, 255);
}
+char *color_to_string(color_t *color);
+
+void color_print(FILE *stream, color_t *color);
+
struct timespec timespec_diff(struct timespec a, struct timespec b);
bool timespec_greater(struct timespec a, struct timespec b);
-void timespec_print(struct timespec *ts);
+void timespec_print(FILE *stream, struct timespec *ts);
// Check if point (px, py) is inside a rectangle in (x, y), (x+w, y), (x, y+h) and (w+h, y+h)
bool check_rect(int px, int py, int x, int y, int w, int h);