| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include "widget-dual.h" |
| 5 |
|
| 6 |
struct dual_button { |
| 7 |
struct alsa_elem *elem; |
| 8 |
GtkWidget *button1; |
| 9 |
GtkWidget *button2; |
| 10 |
const char *text[4]; |
| 11 |
}; |
| 12 |
|
| 13 |
static void dual_button_clicked(GtkWidget *widget, struct dual_button *data) { |
| 14 |
int value1 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->button1)); |
| 15 |
int value2 = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(data->button2)); |
| 16 |
|
| 17 |
int value = value1 ? value2 + 1 : 0; |
| 18 |
|
| 19 |
alsa_set_elem_value(data->elem, value); |
| 20 |
|
| 21 |
gtk_widget_set_sensitive(data->button2, value1); |
| 22 |
} |
| 23 |
|
| 24 |
static void dual_button_updated( |
| 25 |
struct alsa_elem *elem, |
| 26 |
void *private |
| 27 |
) { |
| 28 |
struct dual_button *data = private; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
int value = alsa_get_elem_value(elem); |
| 34 |
int value1 = !!value; |
| 35 |
|
| 36 |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->button1), value1); |
| 37 |
gtk_button_set_label(GTK_BUTTON(data->button1), data->text[value1]); |
| 38 |
gtk_widget_set_sensitive(data->button2, value1); |
| 39 |
if (value1) { |
| 40 |
int value2 = value - 1; |
| 41 |
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data->button2), value2); |
| 42 |
gtk_button_set_label( |
| 43 |
GTK_BUTTON(data->button2), data->text[value2 + 2] |
| 44 |
); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
GtkWidget *make_dual_boolean_alsa_elems( |
| 53 |
struct alsa_elem *elem, |
| 54 |
const char *label_text, |
| 55 |
const char *disabled_text_1, |
| 56 |
const char *enabled_text_1, |
| 57 |
const char *disabled_text_2, |
| 58 |
const char *enabled_text_2 |
| 59 |
) { |
| 60 |
struct dual_button *data = g_malloc(sizeof(struct dual_button)); |
| 61 |
data->elem = elem; |
| 62 |
data->button1 = gtk_toggle_button_new(); |
| 63 |
data->button2 = gtk_toggle_button_new(); |
| 64 |
|
| 65 |
g_signal_connect( |
| 66 |
data->button1, "clicked", G_CALLBACK(dual_button_clicked), data |
| 67 |
); |
| 68 |
g_signal_connect( |
| 69 |
data->button2, "clicked", G_CALLBACK(dual_button_clicked), data |
| 70 |
); |
| 71 |
alsa_elem_add_callback(elem, dual_button_updated, data, NULL); |
| 72 |
data->text[0] = disabled_text_1; |
| 73 |
data->text[1] = enabled_text_1; |
| 74 |
data->text[2] = disabled_text_2; |
| 75 |
data->text[3] = enabled_text_2; |
| 76 |
|
| 77 |
gtk_button_set_label(GTK_BUTTON(data->button2), disabled_text_2); |
| 78 |
|
| 79 |
dual_button_updated(elem, data); |
| 80 |
|
| 81 |
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); |
| 82 |
GtkWidget *label = gtk_label_new(label_text); |
| 83 |
gtk_box_append(GTK_BOX(box), label); |
| 84 |
gtk_box_append(GTK_BOX(box), GTK_WIDGET(data->button1)); |
| 85 |
gtk_box_append(GTK_BOX(box), GTK_WIDGET(data->button2)); |
| 86 |
|
| 87 |
return box; |
| 88 |
} |