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 <christophe.curis@free.fr>

Conflicts:
	wmix/config.c
This commit is contained in:
Christophe CURIS 2014-06-07 21:21:51 +02:00 committed by Carlos R. Mafra
parent 546bc1e49b
commit b1fcdb1552
3 changed files with 18 additions and 4 deletions

View file

@ -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);

View file

@ -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"

View file

@ -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);