| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include <gtk/gtk.h> |
| 5 |
|
| 6 |
#include "alsa.h" |
| 7 |
#include "gtkhelper.h" |
| 8 |
#include "optional-controls.h" |
| 9 |
#include "optional-state.h" |
| 10 |
#include "custom-names.h" |
| 11 |
#include "device-port-names.h" |
| 12 |
#include "port-enable.h" |
| 13 |
#include "widget-text-entry.h" |
| 14 |
#include "window-configuration.h" |
| 15 |
#include "config-autogain.h" |
| 16 |
#include "config-device-name.h" |
| 17 |
#include "config-device-settings.h" |
| 18 |
#include "config-front-panel.h" |
| 19 |
#include "config-io.h" |
| 20 |
#include "config-monitor-groups.h" |
| 21 |
|
| 22 |
struct configuration_window { |
| 23 |
struct alsa_card *card; |
| 24 |
GtkWidget *top; |
| 25 |
}; |
| 26 |
|
| 27 |
static void on_destroy( |
| 28 |
struct configuration_window *data, |
| 29 |
GtkWidget *widget |
| 30 |
) { |
| 31 |
g_free(data); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
#define CONFIG_TAB_KEY "configuration-tab" |
| 36 |
#define CONFIG_IO_TAB_KEY "configuration-io-tab" |
| 37 |
|
| 38 |
|
| 39 |
struct notebook_tab_data { |
| 40 |
struct alsa_card *card; |
| 41 |
const char *key; |
| 42 |
}; |
| 43 |
|
| 44 |
|
| 45 |
static void on_tab_changed( |
| 46 |
GtkNotebook *notebook, |
| 47 |
GtkWidget *page, |
| 48 |
guint page_num, |
| 49 |
gpointer user_data |
| 50 |
) { |
| 51 |
|
| 52 |
|
| 53 |
if (!gtk_widget_get_root(GTK_WIDGET(notebook))) |
| 54 |
return; |
| 55 |
|
| 56 |
struct notebook_tab_data *data = user_data; |
| 57 |
|
| 58 |
const char *page_id = g_object_get_data(G_OBJECT(page), PAGE_ID_KEY); |
| 59 |
if (page_id) |
| 60 |
optional_state_save(data->card, CONFIG_SECTION_UI, data->key, page_id); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
static void free_notebook_tab_data(gpointer data) { |
| 65 |
g_free(data); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
static int find_page_by_id(GtkNotebook *notebook, const char *page_id) { |
| 70 |
int n_pages = gtk_notebook_get_n_pages(notebook); |
| 71 |
|
| 72 |
for (int i = 0; i < n_pages; i++) { |
| 73 |
GtkWidget *page = gtk_notebook_get_nth_page(notebook, i); |
| 74 |
const char *id = g_object_get_data(G_OBJECT(page), PAGE_ID_KEY); |
| 75 |
if (id && strcmp(id, page_id) == 0) |
| 76 |
return i; |
| 77 |
} |
| 78 |
|
| 79 |
return -1; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
void setup_notebook_tab_persistence( |
| 84 |
GtkNotebook *notebook, |
| 85 |
struct alsa_card *card, |
| 86 |
const char *key |
| 87 |
) { |
| 88 |
|
| 89 |
GHashTable *state = optional_state_load(card, CONFIG_SECTION_UI); |
| 90 |
if (state) { |
| 91 |
const char *value = g_hash_table_lookup(state, key); |
| 92 |
if (value) { |
| 93 |
int page_num = find_page_by_id(notebook, value); |
| 94 |
if (page_num >= 0) |
| 95 |
gtk_notebook_set_current_page(notebook, page_num); |
| 96 |
} |
| 97 |
g_hash_table_destroy(state); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
struct notebook_tab_data *data = g_malloc(sizeof(struct notebook_tab_data)); |
| 102 |
data->card = card; |
| 103 |
data->key = key; |
| 104 |
|
| 105 |
g_signal_connect_data( |
| 106 |
notebook, "switch-page", G_CALLBACK(on_tab_changed), data, |
| 107 |
(GClosureNotify)free_notebook_tab_data, 0 |
| 108 |
); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
GtkWidget *wrap_tab_content_scrolled(GtkWidget *content) { |
| 113 |
GtkWidget *scrolled = gtk_scrolled_window_new(); |
| 114 |
gtk_scrolled_window_set_policy( |
| 115 |
GTK_SCROLLED_WINDOW(scrolled), |
| 116 |
GTK_POLICY_NEVER, |
| 117 |
GTK_POLICY_AUTOMATIC |
| 118 |
); |
| 119 |
gtk_scrolled_window_set_propagate_natural_height( |
| 120 |
GTK_SCROLLED_WINDOW(scrolled), TRUE |
| 121 |
); |
| 122 |
gtk_widget_set_vexpand(scrolled, TRUE); |
| 123 |
gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(scrolled), content); |
| 124 |
return scrolled; |
| 125 |
} |
| 126 |
|
| 127 |
GtkWidget *create_configuration_controls(struct alsa_card *card) { |
| 128 |
struct configuration_window *data = |
| 129 |
g_malloc0(sizeof(struct configuration_window)); |
| 130 |
data->card = card; |
| 131 |
|
| 132 |
|
| 133 |
GtkWidget *top = gtk_box_new(GTK_ORIENTATION_VERTICAL, 20); |
| 134 |
gtk_widget_add_css_class(top, "window-frame"); |
| 135 |
GtkWidget *vbox = top; |
| 136 |
|
| 137 |
data->top = top; |
| 138 |
|
| 139 |
|
| 140 |
GtkWidget *top_notebook = gtk_notebook_new(); |
| 141 |
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(top_notebook), GTK_POS_TOP); |
| 142 |
gtk_widget_add_css_class(top_notebook, "outer-notebook"); |
| 143 |
|
| 144 |
|
| 145 |
add_device_name_tab(top_notebook, card); |
| 146 |
|
| 147 |
|
| 148 |
add_device_settings_tab(top_notebook, card); |
| 149 |
|
| 150 |
|
| 151 |
add_front_panel_tab(top_notebook, card); |
| 152 |
|
| 153 |
|
| 154 |
add_io_tab(top_notebook, card); |
| 155 |
|
| 156 |
|
| 157 |
add_autogain_tab(top_notebook, card); |
| 158 |
|
| 159 |
|
| 160 |
add_monitor_groups_tab(top_notebook, card); |
| 161 |
|
| 162 |
|
| 163 |
if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(top_notebook)) > 0) { |
| 164 |
gtk_widget_set_vexpand(top_notebook, TRUE); |
| 165 |
gtk_box_append(GTK_BOX(vbox), top_notebook); |
| 166 |
|
| 167 |
|
| 168 |
setup_notebook_tab_persistence( |
| 169 |
GTK_NOTEBOOK(top_notebook), card, CONFIG_TAB_KEY |
| 170 |
); |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
g_object_weak_ref( |
| 175 |
G_OBJECT(data->top), |
| 176 |
(GWeakNotify)on_destroy, |
| 177 |
data |
| 178 |
); |
| 179 |
|
| 180 |
return data->top; |
| 181 |
} |