mirror of
https://github.com/davatorium/rofi.git
synced 2025-01-27 15:25:24 -05:00
Make color parsing more robust, report failing of parsing color.
Involves: #181
This commit is contained in:
parent
b3bc620211
commit
1de8d448f7
2 changed files with 26 additions and 10 deletions
|
@ -667,10 +667,16 @@ static void parse_color ( Visual *visual, Colormap colormap,
|
|||
col.red = ( ( val & 0x00FF0000 ) >> 16 ) * 255;
|
||||
col.green = ( ( val & 0x0000FF00 ) >> 8 ) * 255;
|
||||
col.blue = ( ( val & 0x000000FF ) ) * 255;
|
||||
XftColorAllocValue ( display, visual, colormap, &col, color );
|
||||
if ( !XftColorAllocValue ( display, visual, colormap, &col, color ) ) {
|
||||
fprintf ( stderr, "Failed to parse color: '%s'\n", bg );
|
||||
exit ( EXIT_FAILURE );
|
||||
}
|
||||
}
|
||||
else {
|
||||
XftColorAllocName ( display, visual, colormap, bg, color );
|
||||
if ( !XftColorAllocName ( display, visual, colormap, bg, color ) ) {
|
||||
fprintf ( stderr, "Failed to parse color: '%s'\n", bg );
|
||||
exit ( EXIT_FAILURE );
|
||||
}
|
||||
}
|
||||
}
|
||||
static void textbox_parse_string ( XVisualInfo *visual, Colormap colormap, const char *str, RowColor *color )
|
||||
|
@ -686,19 +692,19 @@ static void textbox_parse_string ( XVisualInfo *visual, Colormap colormap, const
|
|||
switch ( index )
|
||||
{
|
||||
case 0:
|
||||
parse_color ( visual->visual, colormap, token, &( color->bg ) );
|
||||
parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->bg ) );
|
||||
break;
|
||||
case 1:
|
||||
parse_color ( visual->visual, colormap, token, &( color->fg ) );
|
||||
parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->fg ) );
|
||||
break;
|
||||
case 2:
|
||||
parse_color ( visual->visual, colormap, token, &( color->bgalt ) );
|
||||
parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->bgalt ) );
|
||||
break;
|
||||
case 3:
|
||||
parse_color ( visual->visual, colormap, token, &( color->hlbg ) );
|
||||
parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->hlbg ) );
|
||||
break;
|
||||
case 4:
|
||||
parse_color ( visual->visual, colormap, token, &( color->hlfg ) );
|
||||
parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->hlfg ) );
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
|
|
|
@ -443,12 +443,22 @@ unsigned int color_get ( Display *display, const char *const name )
|
|||
color.blue = ( ( color.pixel & 0x000000FF ) ) * 255;
|
||||
if ( !truecolor ) {
|
||||
// This will drop alpha part.
|
||||
return XAllocColor ( display, map, &color ) ? color.pixel : None;
|
||||
Status st = XAllocColor ( display, map, &color );
|
||||
if ( st == None ) {
|
||||
fprintf ( stderr, "Failed to parse color: '%s'\n", name );
|
||||
exit ( EXIT_FAILURE );
|
||||
}
|
||||
return color.pixel;
|
||||
}
|
||||
return color.pixel;
|
||||
}
|
||||
else {
|
||||
return XAllocNamedColor ( display, map, name, &color, &color ) ? color.pixel : None;
|
||||
Status st = XAllocNamedColor ( display, map, name, &color, &color );
|
||||
if ( st == None ) {
|
||||
fprintf ( stderr, "Failed to parse color: '%s'\n", name );
|
||||
exit ( EXIT_FAILURE );
|
||||
}
|
||||
return color.pixel;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -462,7 +472,7 @@ unsigned int color_background ( Display *display )
|
|||
|
||||
gchar **vals = g_strsplit ( config.color_window, ",", 2 );
|
||||
if ( vals != NULL && vals[0] != NULL ) {
|
||||
retv = color_get ( display, vals[0] );
|
||||
retv = color_get ( display, g_strstrip ( vals[0] ) );
|
||||
}
|
||||
g_strfreev ( vals );
|
||||
return retv;
|
||||
|
|
Loading…
Add table
Reference in a new issue