1
0
Fork 0
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:
QC 2015-07-07 21:50:09 +02:00
parent b3bc620211
commit 1de8d448f7
2 changed files with 26 additions and 10 deletions

View file

@ -667,10 +667,16 @@ static void parse_color ( Visual *visual, Colormap colormap,
col.red = ( ( val & 0x00FF0000 ) >> 16 ) * 255; col.red = ( ( val & 0x00FF0000 ) >> 16 ) * 255;
col.green = ( ( val & 0x0000FF00 ) >> 8 ) * 255; col.green = ( ( val & 0x0000FF00 ) >> 8 ) * 255;
col.blue = ( ( val & 0x000000FF ) ) * 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 { 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 ) 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 ) switch ( index )
{ {
case 0: case 0:
parse_color ( visual->visual, colormap, token, &( color->bg ) ); parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->bg ) );
break; break;
case 1: case 1:
parse_color ( visual->visual, colormap, token, &( color->fg ) ); parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->fg ) );
break; break;
case 2: case 2:
parse_color ( visual->visual, colormap, token, &( color->bgalt ) ); parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->bgalt ) );
break; break;
case 3: case 3:
parse_color ( visual->visual, colormap, token, &( color->hlbg ) ); parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->hlbg ) );
break; break;
case 4: case 4:
parse_color ( visual->visual, colormap, token, &( color->hlfg ) ); parse_color ( visual->visual, colormap, g_strstrip ( token ), &( color->hlfg ) );
break; break;
} }
index++; index++;

View file

@ -443,12 +443,22 @@ unsigned int color_get ( Display *display, const char *const name )
color.blue = ( ( color.pixel & 0x000000FF ) ) * 255; color.blue = ( ( color.pixel & 0x000000FF ) ) * 255;
if ( !truecolor ) { if ( !truecolor ) {
// This will drop alpha part. // 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; return color.pixel;
} }
else { 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 ); gchar **vals = g_strsplit ( config.color_window, ",", 2 );
if ( vals != NULL && vals[0] != NULL ) { if ( vals != NULL && vals[0] != NULL ) {
retv = color_get ( display, vals[0] ); retv = color_get ( display, g_strstrip ( vals[0] ) );
} }
g_strfreev ( vals ); g_strfreev ( vals );
return retv; return retv;