Add support for volatile buttons to widget-boolean.c

Will be used by Gen 1 support.
This commit is contained in:
Geoffrey D. Bennett
2024-03-31 03:22:38 +10:30
parent db0929bd08
commit 111ec1154d
4 changed files with 35 additions and 3 deletions

View File

@@ -133,7 +133,7 @@ static void alsa_parse_comment_node(
if (err < 0)
fatal_alsa_error("snd_config_get_string error", err);
if (strstr(access, "write"))
elem->writable = 1;
elem->is_writable = 1;
} else if (strcmp(key, "type") == 0) {
if (type != SND_CONFIG_TYPE_STRING) {
printf("type type not string\n");

View File

@@ -262,7 +262,7 @@ void alsa_set_elem_value(struct alsa_elem *elem, long value) {
// return whether the element can be modified (is writable)
int alsa_get_elem_writable(struct alsa_elem *elem) {
if (elem->card->num == SIMULATED_CARD_NUM)
return elem->writable;
return elem->is_writable;
snd_ctl_elem_info_t *elem_info;
@@ -273,6 +273,21 @@ int alsa_get_elem_writable(struct alsa_elem *elem) {
return snd_ctl_elem_info_is_writable(elem_info);
}
// return whether the element is volatile (can change without
// notification)
int alsa_get_elem_volatile(struct alsa_elem *elem) {
if (elem->card->num == SIMULATED_CARD_NUM)
return elem->is_volatile;
snd_ctl_elem_info_t *elem_info;
snd_ctl_elem_info_alloca(&elem_info);
snd_ctl_elem_info_set_numid(elem_info, elem->numid);
snd_ctl_elem_info(elem->card->handle, elem_info);
return snd_ctl_elem_info_is_volatile(elem_info);
}
// get the number of values this element has
// (most are just 1; the levels element is the exception)
int alsa_get_elem_count(struct alsa_elem *elem) {

View File

@@ -141,7 +141,8 @@ struct alsa_elem {
GList *callbacks;
// for simulated elements, the current state
int writable;
int is_writable;
int is_volatile;
long value;
// for simulated enumerated elements, the items
@@ -219,6 +220,7 @@ long alsa_get_elem_value(struct alsa_elem *elem);
int *alsa_get_elem_int_values(struct alsa_elem *elem);
void alsa_set_elem_value(struct alsa_elem *elem, long value);
int alsa_get_elem_writable(struct alsa_elem *elem);
int alsa_get_elem_volatile(struct alsa_elem *elem);
int alsa_get_elem_count(struct alsa_elem *elem);
int alsa_get_item_count(struct alsa_elem *elem);
char *alsa_get_item_name(struct alsa_elem *elem, int i);

View File

@@ -6,6 +6,7 @@
struct boolean {
struct alsa_elem *elem;
GtkWidget *button;
guint source;
const char *text[2];
};
@@ -42,7 +43,16 @@ static void toggle_button_updated(
toggle_button_set_text(data->button, data->text[value]);
}
static gboolean update_toggle_button(struct boolean *data) {
toggle_button_updated(data->elem, data);
return G_SOURCE_CONTINUE;
}
static void on_destroy(struct boolean *data) {
if (data->source)
g_source_remove(data->source);
g_free(data);
}
@@ -82,6 +92,11 @@ GtkWidget *make_boolean_alsa_elem(
toggle_button_updated(elem, data);
// periodically update volatile controls
if (alsa_get_elem_volatile(elem))
data->source =
g_timeout_add_seconds(1, (GSourceFunc)update_toggle_button, data);
g_object_weak_ref(G_OBJECT(data->button), (GWeakNotify)on_destroy, data);
return data->button;