diff options
author | Quentin Glidic <sardemff7+git@sardemff7.net> | 2016-02-21 19:27:53 +0100 |
---|---|---|
committer | Quentin Glidic <sardemff7+git@sardemff7.net> | 2016-02-23 12:13:44 +0100 |
commit | 88ddb7f04ef66b8ae320411db462fc624a580ca8 (patch) | |
tree | 7577c0de6e1d9472a3338cb22cc70e9740741930 /source | |
parent | f39f5bb0cb1f296feae08152f2c30f2156c2aa58 (diff) |
x11-helper: Directly store the useful value
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
Diffstat (limited to 'source')
-rw-r--r-- | source/textbox.c | 7 | ||||
-rw-r--r-- | source/x11-helper.c | 32 |
2 files changed, 17 insertions, 22 deletions
diff --git a/source/textbox.c b/source/textbox.c index 26d57b6a..b9f4b0a9 100644 --- a/source/textbox.c +++ b/source/textbox.c @@ -623,12 +623,7 @@ int textbox_keypress ( textbox *tb, xcb_key_press_event_t *ev, char *pad, int pa */ static void parse_color ( Display *display, char *bg, Color *col ) { - unsigned int val = 0; - val = color_get ( display, bg, "white" ); - col->alpha = ( ( val & 0xFF000000 ) >> 24 ) / 255.0; - col->red = ( ( val & 0x00FF0000 ) >> 16 ) / 255.0; - col->green = ( ( val & 0x0000FF00 ) >> 8 ) / 255.0; - col->blue = ( ( val & 0x000000FF ) ) / 255.0; + *col = color_get ( display, bg, "white" ); } static void textbox_parse_string ( Display *display, const char *str, RowColor *color ) { diff --git a/source/x11-helper.c b/source/x11-helper.c index 6171d673..aebee547 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -600,7 +600,7 @@ void create_visual_and_colormap ( Display *display ) } } -unsigned int color_get ( Display *display, const char *const name, const char * const defn ) +Color color_get ( Display *display, const char *const name, const char * const defn ) { char *copy = g_strdup ( name ); char *cname = g_strstrip ( copy ); @@ -637,16 +637,19 @@ unsigned int color_get ( Display *display, const char *const name, const char * } } g_free ( copy ); - return color.pixel; + + Color ret = { + .red = color.red / 65535.0, + .green = color.green / 65535.0, + .blue = color.blue / 65535.0, + .alpha = ( ( color.pixel & 0xFF000000 ) >> 24 ) / 255.0, + }; + return ret; } -void x11_helper_set_cairo_rgba ( cairo_t *d, unsigned int pixel ) + +void x11_helper_set_cairo_rgba ( cairo_t *d, Color col ) { - cairo_set_source_rgba ( d, - ( ( pixel & 0x00FF0000 ) >> 16 ) / 255.0, - ( ( pixel & 0x0000FF00 ) >> 8 ) / 255.0, - ( ( pixel & 0x000000FF ) >> 0 ) / 255.0, - ( ( pixel & 0xFF000000 ) >> 24 ) / 255.0 - ); + cairo_set_source_rgba ( d, col.red, col.green, col.blue, col.alpha ); } /** * Color cache. @@ -659,15 +662,12 @@ enum BORDER, SEPARATOR }; -struct +static struct { - unsigned int color; + Color color; unsigned int set; -} color_cache[3] = { - { 0, FALSE }, - { 0, FALSE }, - { 0, FALSE } -}; +} color_cache[3]; + void color_cache_reset ( void ) { color_cache[BACKGROUND].set = FALSE; |