From 1c2d966763228bfc61da934db5ad0c7f3b912e6d Mon Sep 17 00:00:00 2001 From: "Geoffrey D. Bennett" Date: Sun, 28 Jan 2024 20:10:22 +1030 Subject: [PATCH] Add GtkDial:can_control property If the dial can't be controlled, it shouldn't be dimmed when it's not sensitive. --- src/gtkdial.c | 32 +++++++++++++++++++++++++++++++- src/gtkdial.h | 3 +++ src/iface-mixer.c | 10 +++++----- src/widget-gain.c | 5 ++++- src/widget-gain.h | 3 ++- src/window-levels.c | 1 + src/window-mixer.c | 2 +- 7 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/gtkdial.c b/src/gtkdial.c index a90ee45..82750f3 100644 --- a/src/gtkdial.c +++ b/src/gtkdial.c @@ -88,6 +88,7 @@ enum { PROP_ROUND_DIGITS, PROP_ZERO_DB, PROP_TAPER, + PROP_CAN_CONTROL, LAST_PROP }; @@ -113,6 +114,7 @@ struct _GtkDial { int round_digits; double zero_db; int taper; + gboolean can_control; // linear taper breakpoints array double *taper_breakpoints; @@ -274,7 +276,7 @@ static void get_dial_properties( props->slider_cx = cos(props->angle) * slider_radius + props->cx; props->slider_cy = sin(props->angle) * slider_radius + props->cy; - props->dim = !gtk_widget_is_sensitive(GTK_WIDGET(dial)); + props->dim = !gtk_widget_is_sensitive(GTK_WIDGET(dial)) && dial->can_control; } static double pdist2(double x1, double y1, double x2, double y2) { @@ -371,6 +373,20 @@ static void gtk_dial_class_init(GtkDialClass *klass) { G_PARAM_READWRITE | G_PARAM_CONSTRUCT ); + /** + * GtkDial:can-control: (attributes org.gtk.Method.get=gtk_dial_get_can_control org.gtk.Method.set=gtk_dial_set_can_control) + * + * Whether the dial can be controlled by the user (even though it + * might sometimes be insensitive). + */ + properties[PROP_CAN_CONTROL] = g_param_spec_boolean( + "can-control", + "CanControl", + "Whether the dial can be controlled by the user", + TRUE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT + ); + g_object_class_install_properties(g_class, LAST_PROP, properties); /** @@ -722,6 +738,9 @@ static void gtk_dial_set_property( case PROP_TAPER: gtk_dial_set_taper(dial, g_value_get_int(value)); break; + case PROP_CAN_CONTROL: + gtk_dial_set_can_control(dial, g_value_get_boolean(value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -749,6 +768,9 @@ static void gtk_dial_get_property( case PROP_TAPER: g_value_set_int(value, dial->taper); break; + case PROP_CAN_CONTROL: + g_value_set_boolean(value, dial->can_control); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; @@ -823,6 +845,14 @@ void gtk_dial_set_taper_linear_breakpoints( dial->taper_breakpoints_count = total_count; } +void gtk_dial_set_can_control(GtkDial *dial, gboolean can_control) { + dial->can_control = can_control; +} + +gboolean gtk_dial_get_can_control(GtkDial *dial) { + return dial->can_control; +} + void gtk_dial_set_adjustment(GtkDial *dial, GtkAdjustment *adj) { if (!(adj == NULL || GTK_IS_ADJUSTMENT(adj))) return; diff --git a/src/gtkdial.h b/src/gtkdial.h index 18a2d1f..b3c3774 100644 --- a/src/gtkdial.h +++ b/src/gtkdial.h @@ -81,6 +81,9 @@ void gtk_dial_set_taper_linear_breakpoints( int count ); +void gtk_dial_set_can_control(GtkDial *dial, gboolean can_control); +gboolean gtk_dial_get_can_control(GtkDial *dial); + G_END_DECLS #endif diff --git a/src/iface-mixer.c b/src/iface-mixer.c index ad91f6c..2616ffb 100644 --- a/src/iface-mixer.c +++ b/src/iface-mixer.c @@ -216,7 +216,7 @@ static void create_input_gain_control( int current_row, int column_num ) { - GtkWidget *w = make_gain_alsa_elem(elem, 0, WIDGET_GAIN_TAPER_LINEAR); + GtkWidget *w = make_gain_alsa_elem(elem, 0, WIDGET_GAIN_TAPER_LINEAR, 1); gtk_grid_attach(GTK_GRID(grid), w, column_num, current_row, 1, 1); } @@ -568,7 +568,7 @@ static void create_output_controls( // output controls if (strncmp(elem->name, "Line", 4) == 0) { if (strstr(elem->name, "Playback Volume")) { - w = make_gain_alsa_elem(elem, 1, WIDGET_GAIN_TAPER_LOG); + w = make_gain_alsa_elem(elem, 1, WIDGET_GAIN_TAPER_LOG, 1); gtk_grid_attach( GTK_GRID(output_grid), w, line_num - 1 + line_1_col, 1, 1, 1 ); @@ -608,9 +608,9 @@ static void create_output_controls( GtkWidget *l = gtk_label_new(gen4 ? "Line 1–2" : "HW"); gtk_grid_attach(GTK_GRID(output_grid), l, 0, 0, 1, 1); if (gen4) { - w = make_gain_alsa_elem(elem, 1, WIDGET_GAIN_TAPER_GEN4_VOLUME); + w = make_gain_alsa_elem(elem, 1, WIDGET_GAIN_TAPER_GEN4_VOLUME, 0); } else { - w = make_gain_alsa_elem(elem, 1, WIDGET_GAIN_TAPER_LOG); + w = make_gain_alsa_elem(elem, 1, WIDGET_GAIN_TAPER_LOG, 0); } gtk_widget_set_tooltip_text( w, @@ -630,7 +630,7 @@ static void create_output_controls( "This control shows the setting of the headphone volume knob." ); gtk_grid_attach(GTK_GRID(output_grid), l, 1, 0, 1, 1); - w = make_gain_alsa_elem(elem, 1, WIDGET_GAIN_TAPER_GEN4_VOLUME); + w = make_gain_alsa_elem(elem, 1, WIDGET_GAIN_TAPER_GEN4_VOLUME, 0); gtk_grid_attach(GTK_GRID(output_grid), w, 1, 1, 1, 1); } else if (strcmp(elem->name, "Mute Playback Switch") == 0) { w = make_boolean_alsa_elem( diff --git a/src/widget-gain.c b/src/widget-gain.c index e987d67..375f1a9 100644 --- a/src/widget-gain.c +++ b/src/widget-gain.c @@ -60,7 +60,8 @@ static void gain_updated( GtkWidget *make_gain_alsa_elem( struct alsa_elem *elem, int zero_is_off, - int widget_taper + int widget_taper, + int can_control ) { struct gain *data = g_malloc(sizeof(struct gain)); data->elem = elem; @@ -102,6 +103,8 @@ GtkWidget *make_gain_alsa_elem( 2 ); + gtk_dial_set_can_control(GTK_DIAL(data->dial), can_control); + data->label = gtk_label_new(NULL); gtk_widget_set_vexpand(data->dial, TRUE); diff --git a/src/widget-gain.h b/src/widget-gain.h index d9dbe67..65a622a 100644 --- a/src/widget-gain.h +++ b/src/widget-gain.h @@ -16,5 +16,6 @@ enum { GtkWidget *make_gain_alsa_elem( struct alsa_elem *elem, int zero_is_off, - int taper_type + int taper_type, + int can_control ); diff --git a/src/window-levels.c b/src/window-levels.c index 66d9cc8..71bd16f 100644 --- a/src/window-levels.c +++ b/src/window-levels.c @@ -103,6 +103,7 @@ GtkWidget *create_levels_controls(struct alsa_card *card) { // create the meter widget and attach to the grid GtkWidget *meter = gtk_dial_new_with_range(-80, 0, 0, 0); gtk_dial_set_taper(GTK_DIAL(meter), GTK_DIAL_TAPER_LINEAR); + gtk_dial_set_can_control(GTK_DIAL(meter), FALSE); gtk_widget_set_sensitive(meter, FALSE); card->meters[meter_num++] = meter; gtk_grid_attach(GTK_GRID(grid), meter, j + 1, i + 1, 1, 1); diff --git a/src/window-mixer.c b/src/window-mixer.c index 6446cd7..399b2f6 100644 --- a/src/window-mixer.c +++ b/src/window-mixer.c @@ -82,7 +82,7 @@ GtkWidget *create_mixer_controls(struct alsa_card *card) { } // create the gain control and attach to the grid - GtkWidget *w = make_gain_alsa_elem(elem, 1, WIDGET_GAIN_TAPER_LOG); + GtkWidget *w = make_gain_alsa_elem(elem, 1, WIDGET_GAIN_TAPER_LOG, 0); gtk_grid_attach(GTK_GRID(mixer_top), w, input_num + 1, mix_num + 2, 1, 1); // look up the r_snk entry for the mixer input number