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

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