e mixer - discovered bug as a lack of feature - does not remember volume

i have never seen this before until last night. on some systems audio
starts up volume 0 and muted (either or) and thus on login the volume
is not where you left it and you have to manually fix it every time.
this fixes this by having mixer remember the last volume and mute
state you set (option to enable/disable too) and handles "upgrading"
to remember by default if you have old config

@feature / @fix
This commit is contained in:
Carsten Haitzler 2015-09-02 12:49:42 +09:00
parent bdcbf06b0f
commit f18d9258fc
3 changed files with 93 additions and 1 deletions

View File

@ -9,6 +9,10 @@ typedef struct _Emix_Config
int notify;
int mute;
int save;
int save_mute;
int save_volume;
emix_config_backend_changed cb;
const void *userdata;
} Emix_Config;
@ -31,6 +35,10 @@ _emix_config_dd_new(void)
E_CONFIG_VAL(result, Emix_Config, notify, INT);
E_CONFIG_VAL(result, Emix_Config, mute, INT);
E_CONFIG_VAL(result, Emix_Config, save, INT);
E_CONFIG_VAL(result, Emix_Config, save_mute, INT);
E_CONFIG_VAL(result, Emix_Config, save_volume, INT);
return result;
}
@ -68,6 +76,9 @@ _config_set(Emix_Config *config)
_config->notify = config->notify;
_config->mute = config->mute;
if (config->save == 0) _config->save = -1;
else if (config->save == 1) _config->save = 1;
DBG("SAVING CONFIG %s %d %d", _config->backend, config->notify,
config->mute);
e_config_domain_save("module.emix", cd, config);
@ -89,6 +100,13 @@ emix_config_init(emix_config_backend_changed cb, const void *userdata)
_config->backend = eina_stringshare_add(l->data);
}
if (_config->save == 0)
{
_config->save = 1;
_config->save_mute = 0;
_config->save_volume = 100;
}
_config->cb = cb;
_config->userdata = userdata;
DBG("Config loaded, backend to use: %s", _config->backend);
@ -104,6 +122,46 @@ emix_config_shutdown(void)
emix_shutdown();
}
void
emix_config_save(void)
{
if ((_config) && (cd))
e_config_domain_save("module.emix", cd, _config);
}
Eina_Bool
emix_config_save_get(void)
{
if (_config->save == 1) return EINA_TRUE;
return EINA_FALSE;
}
Eina_Bool
emix_config_save_mute_get(void)
{
return _config->save_mute;
}
void
emix_config_save_mute_set(Eina_Bool mute)
{
_config->save_mute = mute;
if (_config->save == 1) e_config_save_queue();
}
int
emix_config_save_volume_get(void)
{
return _config->save_volume;
}
void
emix_config_save_volume_set(int volume)
{
_config->save_volume = volume;
if (_config->save == 1) e_config_save_queue();
}
static void*
_create_data(E_Config_Dialog *cfg EINA_UNUSED)
{
@ -114,6 +172,10 @@ _create_data(E_Config_Dialog *cfg EINA_UNUSED)
d->config.notify = _config->notify;
d->config.mute = _config->mute;
if (_config->save == -1) d->config.save = 0;
else if (_config->save == 1) d->config.save = 1;
else d->config.save = 1;
return d;
}
@ -141,6 +203,9 @@ _basic_create_widgets(E_Config_Dialog *cfd EINA_UNUSED, Evas *evas,
l = e_widget_check_add(evas, "Mute on lock", &cfdata->config.mute);
e_widget_list_object_append(o, l, 0, 0, 0);
l = e_widget_check_add(evas, "Remember", &cfdata->config.save);
e_widget_list_object_append(o, l, 0, 0, 0);
l = e_widget_label_add(evas, "Backend to use:");
e_widget_list_object_append(o, l, 0, 0, 0);

View File

@ -8,6 +8,14 @@ typedef void (*emix_config_meter_changed)(Eina_Bool enable, void *data);
void emix_config_init(emix_config_backend_changed cb, const void *userdata);
void emix_config_shutdown(void);
void emix_config_save(void);
Eina_Bool emix_config_save_get(void);
Eina_Bool emix_config_save_mute_get(void);
void emix_config_save_mute_set(Eina_Bool mute);
int emix_config_save_volume_get(void);
void emix_config_save_volume_set(int volume);
const char *emix_config_backend_get(void);
void emix_config_backend_set(const char *backend);
Eina_Bool emix_config_desklock_mute_get(void);

View File

@ -187,6 +187,7 @@ _volume_increase_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
}
emix_sink_volume_set(s, volume);
if (volume.volumes) emix_config_save_volume_set(volume.volumes[0]);
free(volume.volumes);
}
@ -211,6 +212,7 @@ _volume_decrease_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
}
emix_sink_volume_set(s, volume);
if (volume.volumes) emix_config_save_volume_set(volume.volumes[0]);
free(volume.volumes);
}
@ -222,6 +224,7 @@ _volume_mute_cb(E_Object *obj EINA_UNUSED, const char *params EINA_UNUSED)
Emix_Sink *s = (Emix_Sink *)mixer_context->sink_default;
Eina_Bool mute = !s->mute;
emix_sink_mute_set(s, mute);
emix_config_save_mute_set(mute);
}
static void
@ -341,6 +344,7 @@ _check_changed_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
{
Emix_Sink *s = (Emix_Sink *)mixer_context->sink_default;
emix_sink_mute_set(s, !s->mute);
emix_config_save_mute_set(!s->mute);
/*
*TODO: is it really necessary ? or it will be update
* with the sink changed hanlder
@ -357,13 +361,13 @@ _slider_changed_cb(void *data EINA_UNUSED, Evas_Object *obj,
unsigned int i;
Emix_Sink *s = (Emix_Sink *)mixer_context->sink_default;
val = (int)elm_slider_value_get(obj);
v.volumes = calloc(s->volume.channel_count, sizeof(int));
v.channel_count = s->volume.channel_count;
for (i = 0; i < s->volume.channel_count; i++) v.volumes[i] = val;
emix_sink_volume_set(s, v);
elm_slider_value_set(obj, val);
if (v.volumes) emix_config_save_volume_set(v.volumes[0]);
free(v.volumes);
}
@ -678,6 +682,20 @@ _ready(void)
mixer_context->sink_default = emix_sinks_get()->data;
}
if (emix_config_save_get())
{
Emix_Volume v;
unsigned int i;
Emix_Sink *s = (Emix_Sink *)mixer_context->sink_default;
v.volumes = calloc(s->volume.channel_count, sizeof(int));
v.channel_count = s->volume.channel_count;
for (i = 0; i < s->volume.channel_count; i++) v.volumes[i] = 100;
emix_sink_volume_set(s, v);
free(v.volumes);
emix_sink_mute_set(s, emix_config_save_mute_get());
}
_mixer_gadget_update();
}
@ -833,6 +851,7 @@ e_modapi_shutdown(E_Module *m EINA_UNUSED)
E_API int
e_modapi_save(E_Module *m EINA_UNUSED)
{
emix_config_save();
return 1;
}