diff --git a/color.c b/color.c index 6c1ce1de9..c2f105ea6 100644 --- a/color.c +++ b/color.c @@ -156,6 +156,7 @@ color_init_unchecked(color_t *color, const char *colstr, ssize_t len, xcb_visual req.color->red = RGB_8TO16(red); req.color->green = RGB_8TO16(green); req.color->blue = RGB_8TO16(blue); + req.color->alpha = RGB_8TO16(alpha); req.color->initialized = true; return req; } @@ -190,6 +191,7 @@ color_init_reply(color_init_request_t req) req.color->red = hexa_color->red; req.color->green = hexa_color->green; req.color->blue = hexa_color->blue; + req.color->alpha = 0xffff; req.color->initialized = true; p_delete(&hexa_color); return true; @@ -210,9 +212,14 @@ luaA_pushcolor(lua_State *L, const color_t c) uint8_t r = RGB_16TO8(c.red); uint8_t g = RGB_16TO8(c.green); uint8_t b = RGB_16TO8(c.blue); + uint8_t a = RGB_16TO8(c.alpha); - char s[10]; - int len = snprintf(s, sizeof(s), "#%02x%02x%02x", r, g, b); + char s[1 + 4*2 + 1]; + int len; + if (a >= 0xff) + len = snprintf(s, sizeof(s), "#%02x%02x%02x", r, g, b); + else + len = snprintf(s, sizeof(s), "#%02x%02x%02x%02x", r, g, b, a); lua_pushlstring(L, s, len); return 1; } diff --git a/color.h b/color.h index aaa2bccbf..59cda3fcb 100644 --- a/color.h +++ b/color.h @@ -33,6 +33,7 @@ typedef struct uint16_t red; uint16_t green; uint16_t blue; + uint16_t alpha; bool initialized; } color_t; diff --git a/tests/test-focus.lua b/tests/test-focus.lua index 7250f9964..e7fa09123 100644 --- a/tests/test-focus.lua +++ b/tests/test-focus.lua @@ -49,6 +49,22 @@ local steps = { end end + end, + + -- Test if alpha works as intended + function() + local c = client.get()[1] + + local function test(set, expected) + expected = expected or set + c.border_color = set + assert_equals(c.border_color, expected) + end + + test("#123456") + test("#12345678") + test("#123456ff", "#123456") + return true end }