Color: Remove alpha, it is unused
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
parent
0e819f2328
commit
ae8567bef3
39
color.c
39
color.c
|
@ -35,35 +35,18 @@
|
||||||
* \param red A pointer to the red color to fill.
|
* \param red A pointer to the red color to fill.
|
||||||
* \param green A pointer to the green color to fill.
|
* \param green A pointer to the green color to fill.
|
||||||
* \param blue A pointer to the blue color to fill.
|
* \param blue A pointer to the blue color to fill.
|
||||||
* \param alpha A pointer to the alpha color to fill.
|
|
||||||
* \return True if everything alright.
|
* \return True if everything alright.
|
||||||
*/
|
*/
|
||||||
static bool
|
static bool
|
||||||
color_parse(const char *colstr, ssize_t len,
|
color_parse(const char *colstr, ssize_t len,
|
||||||
uint8_t *red, uint8_t *green, uint8_t *blue, uint8_t *alpha)
|
uint8_t *red, uint8_t *green, uint8_t *blue)
|
||||||
{
|
{
|
||||||
unsigned long colnum;
|
unsigned long colnum;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if(len == 7)
|
colnum = strtoul(colstr + 1, &p, 16);
|
||||||
|
if(len != 7 || (p - colstr) != 7 || colstr[0] != '#')
|
||||||
{
|
{
|
||||||
colnum = strtoul(colstr + 1, &p, 16);
|
|
||||||
if(p - colstr != 7)
|
|
||||||
goto invalid;
|
|
||||||
*alpha = 0xff;
|
|
||||||
}
|
|
||||||
/* we have alpha */
|
|
||||||
else if(len == 9)
|
|
||||||
{
|
|
||||||
colnum = strtoul(colstr + 1, &p, 16);
|
|
||||||
if(p - colstr != 9)
|
|
||||||
goto invalid;
|
|
||||||
*alpha = colnum & 0xff;
|
|
||||||
colnum >>= 8;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
invalid:
|
|
||||||
warn("awesome: error, invalid color '%s'", colstr);
|
warn("awesome: error, invalid color '%s'", colstr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +70,7 @@ color_init_request_t
|
||||||
color_init_unchecked(color_t *color, const char *colstr, ssize_t len)
|
color_init_unchecked(color_t *color, const char *colstr, ssize_t len)
|
||||||
{
|
{
|
||||||
color_init_request_t req;
|
color_init_request_t req;
|
||||||
uint8_t red, green, blue, alpha;
|
uint8_t red, green, blue;
|
||||||
|
|
||||||
p_clear(&req, 1);
|
p_clear(&req, 1);
|
||||||
|
|
||||||
|
@ -97,19 +80,16 @@ color_init_unchecked(color_t *color, const char *colstr, ssize_t len)
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
req.alpha = 0xffff;
|
|
||||||
req.color = color;
|
req.color = color;
|
||||||
|
|
||||||
/* The color is given in RGB value */
|
/* The color is given in RGB value */
|
||||||
if(!color_parse(colstr, len, &red, &green, &blue, &alpha))
|
if(!color_parse(colstr, len, &red, &green, &blue))
|
||||||
{
|
{
|
||||||
warn("awesome: error, invalid color '%s'", colstr);
|
warn("awesome: error, invalid color '%s'", colstr);
|
||||||
req.has_error = true;
|
req.has_error = true;
|
||||||
return req;
|
return req;
|
||||||
}
|
}
|
||||||
|
|
||||||
req.alpha = RGB_8TO16(alpha);
|
|
||||||
|
|
||||||
req.cookie_hexa = xcb_alloc_color_unchecked(globalconf.connection,
|
req.cookie_hexa = xcb_alloc_color_unchecked(globalconf.connection,
|
||||||
globalconf.default_cmap,
|
globalconf.default_cmap,
|
||||||
RGB_8TO16(red),
|
RGB_8TO16(red),
|
||||||
|
@ -141,7 +121,6 @@ color_init_reply(color_init_request_t req)
|
||||||
req.color->red = hexa_color->red;
|
req.color->red = hexa_color->red;
|
||||||
req.color->green = hexa_color->green;
|
req.color->green = hexa_color->green;
|
||||||
req.color->blue = hexa_color->blue;
|
req.color->blue = hexa_color->blue;
|
||||||
req.color->alpha = req.alpha;
|
|
||||||
req.color->initialized = true;
|
req.color->initialized = true;
|
||||||
p_delete(&hexa_color);
|
p_delete(&hexa_color);
|
||||||
return true;
|
return true;
|
||||||
|
@ -162,14 +141,8 @@ luaA_pushcolor(lua_State *L, const color_t c)
|
||||||
uint8_t r = (unsigned) c.red * 0xff / 0xffff;
|
uint8_t r = (unsigned) c.red * 0xff / 0xffff;
|
||||||
uint8_t g = (unsigned) c.green * 0xff / 0xffff;
|
uint8_t g = (unsigned) c.green * 0xff / 0xffff;
|
||||||
uint8_t b = (unsigned) c.blue * 0xff / 0xffff;
|
uint8_t b = (unsigned) c.blue * 0xff / 0xffff;
|
||||||
uint8_t a = (unsigned) c.alpha * 0xff / 0xffff;
|
|
||||||
char s[10];
|
char s[10];
|
||||||
int len;
|
int len = snprintf(s, sizeof(s), "#%02x%02x%02x", r, g, b);
|
||||||
/* do not print alpha if it's full */
|
|
||||||
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);
|
lua_pushlstring(L, s, len);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
2
color.h
2
color.h
|
@ -33,14 +33,12 @@ typedef struct
|
||||||
uint16_t red;
|
uint16_t red;
|
||||||
uint16_t green;
|
uint16_t green;
|
||||||
uint16_t blue;
|
uint16_t blue;
|
||||||
uint16_t alpha;
|
|
||||||
bool initialized;
|
bool initialized;
|
||||||
} color_t;
|
} color_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
xcb_alloc_color_cookie_t cookie_hexa;
|
xcb_alloc_color_cookie_t cookie_hexa;
|
||||||
uint16_t alpha;
|
|
||||||
color_t *color;
|
color_t *color;
|
||||||
bool has_error;
|
bool has_error;
|
||||||
const char *colstr;
|
const char *colstr;
|
||||||
|
|
Loading…
Reference in New Issue