From 228a1021630dacd892d4bc9263689193374d0894 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Mon, 5 Feb 2018 13:29:53 +0100 Subject: [PATCH] Disable controls when the underlying device disappears --- src/control.c | 14 ++++++++++++++ src/control.h | 4 ++++ src/mixer.c | 22 +++++++++++++++++----- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/control.c b/src/control.c index 8dbe195..56f11cd 100644 --- a/src/control.c +++ b/src/control.c @@ -209,6 +209,20 @@ void mixercontrol_set_icon(MixerControl * control, String const * icon) GTK_ICON_SIZE_MENU); } +/* useful */ +/* mixercontrol_disable */ +void mixercontrol_disable(MixerControl * control) +{ + gtk_widget_set_sensitive(control->frame, FALSE); +} + + +/* mixercontrol_enable */ +void mixercontrol_enable(MixerControl * control) +{ + gtk_widget_set_sensitive(control->frame, TRUE); +} + /* private */ /* mixercontrol_helper_set */ diff --git a/src/control.h b/src/control.h index cbd68b4..fcda0c3 100644 --- a/src/control.h +++ b/src/control.h @@ -57,4 +57,8 @@ GtkWidget * mixercontrol_get_widget(MixerControl * control); void mixercontrol_set_icon(MixerControl * control, String const * icon); +/* useful */ +void mixercontrol_disable(MixerControl * control); +void mixercontrol_enable(MixerControl * control); + #endif /* !MIXER_CONTROL_H */ diff --git a/src/mixer.c b/src/mixer.c index 15920cd..61f6aa5 100644 --- a/src/mixer.c +++ b/src/mixer.c @@ -995,7 +995,11 @@ static int _mixer_get_control(Mixer * mixer, MixerControl2 * control) md.index = control->index; if(ioctl(mixer->fd, AUDIO_MIXER_DEVINFO, &md) != 0) - return -_mixer_error(mixer, "AUDIO_MIXER_DEVINFO", 1); + { + if(errno == ENXIO) + return -errno; + return _mixer_error(mixer, "AUDIO_MIXER_DEVINFO", -errno); + } p.dev = control->index; /* XXX this is necessary for some drivers and I don't like it */ if((p.type = md.type) == AUDIO_MIXER_VALUE) @@ -1071,7 +1075,7 @@ static int _mixer_get_control(Mixer * mixer, MixerControl2 * control) uint16_t u16; if(ioctl(mixer->fd, MIXER_READ(control->index), &value) != 0) - return -_mixer_error(NULL, "MIXER_READ", 1); + return _mixer_error(NULL, "MIXER_READ", -errno); control->type = 0; control->un.level.delta = 1; control->un.level.channels_cnt = 2; @@ -1233,9 +1237,17 @@ static int _set_control_widget_set(MixerControl2 * control) /* mixer_refresh_control */ static int _mixer_refresh_control(Mixer * mixer, MixerControl2 * control) { - if(_mixer_get_control(mixer, control) != 0) - return -1; - return _mixer_set_control_widget(mixer, control); + int ret; + + if((ret = _mixer_get_control(mixer, control)) != 0) + { + if(ret == -ENXIO) + mixercontrol_disable(control->control); + return ret; + } + if((ret = _mixer_set_control_widget(mixer, control)) == 0) + mixercontrol_enable(control->control); + return ret; }