From b1fcdb1552cb42cd9dde1327acc776de65382dd1 Mon Sep 17 00:00:00 2001 From: Christophe CURIS Date: Sat, 7 Jun 2014 21:21:51 +0200 Subject: [PATCH] wmix: added appropriate message and fall back if user's color for OSD failed It is generally not considered a good behaviour to leave user puzzled on non-working request. With a little message at least he will know where to look at. Signed-off-by: Christophe CURIS Conflicts: wmix/config.c --- wmix/config.c | 7 +++++-- wmix/include/config.h | 3 +++ wmix/ui_x.c | 12 ++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/wmix/config.c b/wmix/config.c index 317033a..f335df9 100644 --- a/wmix/config.c +++ b/wmix/config.c @@ -45,6 +45,9 @@ /* The global configuration */ struct _Config config; +/* Default color for OSD */ +const char default_osd_color[] = "green"; + /* * Sets the default values in configuration @@ -59,7 +62,7 @@ void config_init(void) config.wheel_button_down = 5; config.scrollstep = 0.03; config.osd = 1; - config.osd_color = strdup("green"); + config.osd_color = (char *) default_osd_color; } /* @@ -242,7 +245,7 @@ void config_read(void) config.osd = atoi(value); } else if (strcmp(keyword, "osdcolor") == 0) { - if (config.osd_color) + if (config.osd_color != default_osd_color) free(config.osd_color); config.osd_color = strdup(value); diff --git a/wmix/include/config.h b/wmix/include/config.h index 72e4cc4..602d400 100644 --- a/wmix/include/config.h +++ b/wmix/include/config.h @@ -44,6 +44,9 @@ extern struct _Config { char *exclude_channel[SOUND_MIXER_NRDEVICES + 1]; /* Devices to exclude from GUI's list */ } config; +/* Default color for OSD */ +extern const char default_osd_color[]; + /* Current version of WMixer */ #define VERSION "3.0" diff --git a/wmix/ui_x.c b/wmix/ui_x.c index 31a818a..1425f5c 100644 --- a/wmix/ui_x.c +++ b/wmix/ui_x.c @@ -589,12 +589,20 @@ unsigned long get_color(Display *display, char *color_name) { XColor color; XWindowAttributes winattr; + Status status; XGetWindowAttributes(display, RootWindow(display, DefaultScreen(display)), &winattr); - color.pixel = 0; - XParseColor(display, winattr.colormap, color_name, &color); + status = XParseColor(display, winattr.colormap, color_name, &color); + if (status == 0) { + fprintf(stderr, "wmix:warning: Could not get color \"%s\" for OSD, falling back to default\n", color_name); + + if (color_name != default_osd_color) + status = XParseColor(display, winattr.colormap, default_osd_color, &color); + if (status == 0) + return WhitePixel(display, DefaultScreen(display)); + } color.flags = DoRed | DoGreen | DoBlue; XAllocColor(display, winattr.colormap, &color);