mirror of
https://github.com/davatorium/rofi.git
synced 2025-01-27 15:25:24 -05:00
Strip color, should fix #233
This commit is contained in:
parent
b0ceccb93e
commit
d5549db384
2 changed files with 17 additions and 40 deletions
|
@ -574,38 +574,14 @@ int textbox_keypress ( textbox *tb, XIC xic, XEvent *ev )
|
|||
/***
|
||||
* Font setup.
|
||||
*/
|
||||
extern Colormap map;
|
||||
static void parse_color ( Display *display, char *bg, Color *col )
|
||||
{
|
||||
unsigned int val = 0;
|
||||
char *endptr = NULL;
|
||||
if ( bg == NULL ) {
|
||||
return;
|
||||
}
|
||||
if ( strncmp ( bg, "argb:", 5 ) == 0 ) {
|
||||
val = strtoul ( &bg[5], &endptr, 16 );
|
||||
col->alpha = ( ( val & 0xFF000000 ) >> 24 ) / 256.0;
|
||||
col->red = ( ( val & 0x00FF0000 ) >> 16 ) / 256.0;
|
||||
col->green = ( ( val & 0x0000FF00 ) >> 8 ) / 256.0;
|
||||
col->blue = ( ( val & 0x000000FF ) ) / 256.0;
|
||||
}
|
||||
else if ( bg[0] == '#' ) {
|
||||
val = strtoul ( &bg[1], &endptr, 16 );
|
||||
col->alpha = 1;
|
||||
col->red = ( ( val & 0x00FF0000 ) >> 16 ) / 256.0;
|
||||
col->green = ( ( val & 0x0000FF00 ) >> 8 ) / 256.0;
|
||||
col->blue = ( ( val & 0x000000FF ) ) / 256.0;
|
||||
}
|
||||
else {
|
||||
XColor def, color = { 0, 0, 0, 0, 0, 0 };
|
||||
Status st = XAllocNamedColor ( display, map, bg, &color, &def );
|
||||
if ( st != None ) {
|
||||
col->alpha = 1;
|
||||
col->red = ( ( def.pixel & 0x00FF0000 ) >> 16 ) / 256.0;
|
||||
col->green = ( ( def.pixel & 0x0000FF00 ) >> 8 ) / 256.0;
|
||||
col->blue = ( ( def.pixel & 0x000000FF ) ) / 256.0;
|
||||
}
|
||||
}
|
||||
unsigned int val = 0;
|
||||
val = color_get ( display, bg, "white" );
|
||||
col->alpha = ( ( val & 0xFF000000 ) >> 24 ) / 256.0;
|
||||
col->red = ( ( val & 0x00FF0000 ) >> 16 ) / 256.0;
|
||||
col->green = ( ( val & 0x0000FF00 ) >> 8 ) / 256.0;
|
||||
col->blue = ( ( val & 0x000000FF ) ) / 256.0;
|
||||
}
|
||||
static void textbox_parse_string ( Display *display, const char *str, RowColor *color )
|
||||
{
|
||||
|
|
|
@ -500,11 +500,13 @@ cairo_format_t get_format ( void )
|
|||
|
||||
unsigned int color_get ( Display *display, const char *const name, const char * const defn )
|
||||
{
|
||||
XColor color = { 0, 0, 0, 0, 0, 0 };
|
||||
char *copy = g_strdup ( name );
|
||||
char *cname = g_strstrip ( copy );
|
||||
XColor color = { 0, 0, 0, 0, 0, 0 };
|
||||
XColor def;
|
||||
// Special format.
|
||||
if ( strncmp ( name, "argb:", 5 ) == 0 ) {
|
||||
color.pixel = strtoul ( &name[5], NULL, 16 );
|
||||
if ( strncmp ( cname, "argb:", 5 ) == 0 ) {
|
||||
color.pixel = strtoul ( &cname[5], NULL, 16 );
|
||||
color.red = ( ( color.pixel & 0x00FF0000 ) >> 16 ) * 256;
|
||||
color.green = ( ( color.pixel & 0x0000FF00 ) >> 8 ) * 256;
|
||||
color.blue = ( ( color.pixel & 0x000000FF ) ) * 256;
|
||||
|
@ -512,29 +514,28 @@ unsigned int color_get ( Display *display, const char *const name, const char *
|
|||
// This will drop alpha part.
|
||||
Status st = XAllocColor ( display, map, &color );
|
||||
if ( st == None ) {
|
||||
fprintf ( stderr, "Failed to parse color: '%s'\n", name );
|
||||
fprintf ( stderr, "Failed to parse color: '%s'\n", cname );
|
||||
st = XAllocNamedColor ( display, map, defn, &color, &def );
|
||||
if ( st == None ) {
|
||||
fprintf ( stderr, "Failed to allocate fallback color\n" );
|
||||
exit ( EXIT_FAILURE );
|
||||
}
|
||||
}
|
||||
return color.pixel;
|
||||
}
|
||||
return color.pixel;
|
||||
}
|
||||
else {
|
||||
Status st = XAllocNamedColor ( display, map, name, &color, &def );
|
||||
Status st = XAllocNamedColor ( display, map, cname, &color, &def );
|
||||
if ( st == None ) {
|
||||
fprintf ( stderr, "Failed to parse color: '%s'\n", name );
|
||||
fprintf ( stderr, "Failed to parse color: '%s'\n", cname );
|
||||
st = XAllocNamedColor ( display, map, defn, &color, &def );
|
||||
if ( st == None ) {
|
||||
fprintf ( stderr, "Failed to allocate fallback color\n" );
|
||||
exit ( EXIT_FAILURE );
|
||||
}
|
||||
}
|
||||
return color.pixel;
|
||||
}
|
||||
g_free ( copy );
|
||||
return color.pixel;
|
||||
}
|
||||
void x11_helper_set_cairo_rgba ( cairo_t *d, unsigned int pixel )
|
||||
{
|
||||
|
@ -554,7 +555,7 @@ void color_background ( Display *display, cairo_t *d )
|
|||
else {
|
||||
gchar **vals = g_strsplit ( config.color_window, ",", 3 );
|
||||
if ( vals != NULL && vals[0] != NULL ) {
|
||||
pixel = color_get ( display, g_strstrip ( vals[0] ), "black" );
|
||||
pixel = color_get ( display, vals[0], "black" );
|
||||
}
|
||||
g_strfreev ( vals );
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue