diff options
author | Dave Davenport <qball@gmpclient.org> | 2015-07-31 12:23:41 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2015-07-31 12:23:41 +0200 |
commit | dffc27e5aa13dd5e5ada9cee24e4a7151d82f8b6 (patch) | |
tree | 2e8c5ab572490c248cda718682ed8a690591626b /source/x11-helper.c | |
parent | 69c75971f38fa9be1c09df4a1dc0cd6003b857a9 (diff) |
Try to make things more robust, e.g. try to recover before giving up.
Diffstat (limited to 'source/x11-helper.c')
-rw-r--r-- | source/x11-helper.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/source/x11-helper.c b/source/x11-helper.c index 2c574e3e..395b176a 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -447,9 +447,10 @@ void create_visual_and_colormap ( Display *display ) map = DefaultColormap ( display, screen ); } } -unsigned int color_get ( Display *display, const char *const name ) +unsigned int color_get ( Display *display, const char *const name, const char * const defn ) { 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 ); @@ -461,17 +462,25 @@ unsigned int color_get ( Display *display, const char *const name ) Status st = XAllocColor ( display, map, &color ); if ( st == None ) { fprintf ( stderr, "Failed to parse color: '%s'\n", name ); - exit ( EXIT_FAILURE ); + 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, &color ); + Status st = XAllocNamedColor ( display, map, name, &color, &def ); if ( st == None ) { fprintf ( stderr, "Failed to parse color: '%s'\n", name ); - exit ( EXIT_FAILURE ); + st = XAllocNamedColor ( display, map, defn, &color, &def ); + if ( st == None ) { + fprintf ( stderr, "Failed to allocate fallback color\n" ); + exit ( EXIT_FAILURE ); + } } return color.pixel; } @@ -480,14 +489,14 @@ unsigned int color_get ( Display *display, const char *const name ) unsigned int color_background ( Display *display ) { if ( !config.color_enabled ) { - return color_get ( display, config.menu_bg ); + return color_get ( display, config.menu_bg, "black" ); } else { unsigned int retv = 0; gchar **vals = g_strsplit ( config.color_window, ",", 2 ); if ( vals != NULL && vals[0] != NULL ) { - retv = color_get ( display, g_strstrip ( vals[0] ) ); + retv = color_get ( display, g_strstrip ( vals[0] ), "black" ); } g_strfreev ( vals ); return retv; @@ -497,14 +506,14 @@ unsigned int color_background ( Display *display ) unsigned int color_border ( Display *display ) { if ( !config.color_enabled ) { - return color_get ( display, config.menu_bc ); + return color_get ( display, config.menu_bc, "white" ); } else { unsigned int retv = 0; gchar **vals = g_strsplit ( config.color_window, ",", 2 ); if ( vals != NULL && vals[0] != NULL && vals[1] != NULL ) { - retv = color_get ( display, vals[1] ); + retv = color_get ( display, vals[1], "white" ); } g_strfreev ( vals ); return retv; |