diff options
author | Gordon Norman Squash <[email protected]> | 2022-07-28 21:28:22 -0400 |
---|---|---|
committer | Luke from DC <[email protected]> | 2022-08-14 00:08:54 +0000 |
commit | 44df49d11121858b4235a427376410eb091c31c5 (patch) | |
tree | 5fd4afa99858745805e2299a0cfa8822d8c50478 | |
parent | 3499a5ffe1ea234e3beedd9615a66470026ae2dc (diff) | |
download | mate-media-44df49d11121858b4235a427376410eb091c31c5.tar.bz2 mate-media-44df49d11121858b4235a427376410eb091c31c5.tar.xz |
Add setting for adjustment of audio volume above 100 per cent: Part 2
There is often a need for the user to increase the audio playback volume above
the volume level known as "100% volume". While increasing the audio volume
above 100% can result in degraded audio quality, sometimes the audio was, for
example, originally recorded at an extremely low volume, and the user has no
other option to clearly hear the audio. Unfortunately, most MATE applications
with volume controls do not allow the user to set the volume level above 100%.
For example, the main MATE Sound Preferences dialog lets you set the audio
volume beyond 100% (when possible), whereas the Volume Control Applet, Volume
Control status icon, and special "multimedia" volume control keys do not. In
fact, if the user even tries to change the volume using any of the latter
methods, and the current volume level is above 100%, these latter methods will
all reduce the volume to 100%, even if the user tried to increase the volume!
This is part 2 of a patch to change this situation. This patch adds this
capability to the MATE Volume Control Applet and the MATE Volume Control
status icon. It also adds a check box to the MATE Volume Control Preferences
dialog to enable or disable this capability, and for consistency, the main
volume control at the top of that dialog also obeys the current setting of
that check box. This commit is by far the largest one, and is the main part
of the patch.
-rw-r--r-- | mate-volume-control/gvc-channel-bar.c | 75 | ||||
-rw-r--r-- | mate-volume-control/gvc-channel-bar.h | 4 | ||||
-rw-r--r-- | mate-volume-control/gvc-mixer-dialog.c | 65 | ||||
-rw-r--r-- | mate-volume-control/gvc-stream-applet-icon.c | 16 | ||||
-rw-r--r-- | mate-volume-control/gvc-stream-status-icon.c | 16 |
5 files changed, 169 insertions, 7 deletions
diff --git a/mate-volume-control/gvc-channel-bar.c b/mate-volume-control/gvc-channel-bar.c index e787474..7feb0dd 100644 --- a/mate-volume-control/gvc-channel-bar.c +++ b/mate-volume-control/gvc-channel-bar.c @@ -52,6 +52,7 @@ struct _GvcChannelBarPrivate gboolean show_icons; gboolean show_mute; gboolean show_marks; + gboolean show_mark_text; gboolean extended; GtkSizeGroup *size_group; gboolean symmetric; @@ -67,6 +68,7 @@ enum { PROP_SHOW_ICONS, PROP_SHOW_MUTE, PROP_SHOW_MARKS, + PROP_SHOW_MARK_TEXT, PROP_EXTENDED, PROP_NAME, PROP_ICON_NAME, @@ -287,6 +289,28 @@ update_layout (GvcChannelBar *bar) } static void +update_scale_size (GvcChannelBar *bar) +{ + gdouble normal_volume; + gdouble maximum_volume; + int calculated_scale_size = SCALE_SIZE; + + if (bar->priv->extended && bar->priv->control != NULL) + { + normal_volume = mate_mixer_stream_control_get_normal_volume (bar->priv->control); + maximum_volume = mate_mixer_stream_control_get_max_volume (bar->priv->control); + calculated_scale_size = (maximum_volume / normal_volume) * SCALE_SIZE; + } + + if (bar->priv->orientation == GTK_ORIENTATION_VERTICAL) + gtk_widget_set_size_request (bar->priv->scale, + -1, calculated_scale_size); + else + gtk_widget_set_size_request (bar->priv->scale, + calculated_scale_size, -1); +} + +static void update_marks (GvcChannelBar *bar) { gdouble base; @@ -307,7 +331,11 @@ update_marks (GvcChannelBar *bar) return; if (base < normal) { - gchar *str = g_strdup_printf ("<small>%s</small>", C_("volume", "Unamplified")); + gchar *str = NULL; + + if (bar->priv->show_mark_text) + str = g_strdup_printf ("<small>%s</small>", + C_("volume", "Unamplified")); gtk_scale_add_mark (GTK_SCALE (bar->priv->scale), base, @@ -320,7 +348,11 @@ update_marks (GvcChannelBar *bar) /* Only show 100% mark if the scale is extended beyond 100% and * there is no unamplified mark or it is below the normal volume */ if (bar->priv->extended && (base == normal || base < normal)) { - gchar *str = g_strdup_printf ("<small>%s</small>", C_("volume", "100%")); + gchar *str = NULL; + + if (bar->priv->show_mark_text) + str = g_strdup_printf ("<small>%s</small>", + C_("volume", "100%")); gtk_scale_add_mark (GTK_SCALE (bar->priv->scale), normal, @@ -584,6 +616,7 @@ gvc_channel_bar_set_control (GvcChannelBar *bar, MateMixerStreamControl *control update_mute_button (bar); update_adjustment_limits (bar); update_adjustment_value (bar); + update_scale_size (bar); } GtkOrientation @@ -683,6 +716,28 @@ gvc_channel_bar_set_show_marks (GvcChannelBar *bar, gboolean show_marks) } gboolean +gvc_channel_bar_get_show_mark_text (GvcChannelBar *bar) +{ + g_return_val_if_fail (GVC_IS_CHANNEL_BAR (bar), FALSE); + + return bar->priv->show_mark_text; +} + +void +gvc_channel_bar_set_show_mark_text (GvcChannelBar *bar, gboolean show_mark_text) +{ + g_return_if_fail (GVC_IS_CHANNEL_BAR (bar)); + + if (show_mark_text == bar->priv->show_mark_text) + return; + + bar->priv->show_mark_text = show_mark_text; + update_marks (bar); + + g_object_notify_by_pspec (G_OBJECT (bar), properties[PROP_SHOW_MARK_TEXT]); +} + +gboolean gvc_channel_bar_get_extended (GvcChannelBar *bar) { g_return_val_if_fail (GVC_IS_CHANNEL_BAR (bar), FALSE); @@ -704,6 +759,7 @@ gvc_channel_bar_set_extended (GvcChannelBar *bar, gboolean extended) * limit at the end of the scale */ update_marks (bar); update_adjustment_limits (bar); + update_scale_size (bar); g_object_notify_by_pspec (G_OBJECT (bar), properties[PROP_EXTENDED]); } @@ -940,6 +996,9 @@ gvc_channel_bar_set_property (GObject *object, case PROP_SHOW_MARKS: gvc_channel_bar_set_show_marks (self, g_value_get_boolean (value)); break; + case PROP_SHOW_MARK_TEXT: + gvc_channel_bar_set_show_mark_text (self, g_value_get_boolean (value)); + break; case PROP_EXTENDED: gvc_channel_bar_set_extended (self, g_value_get_boolean (value)); break; @@ -985,6 +1044,9 @@ gvc_channel_bar_get_property (GObject *object, case PROP_SHOW_MARKS: g_value_set_boolean (value, self->priv->show_marks); break; + case PROP_SHOW_MARK_TEXT: + g_value_set_boolean (value, self->priv->show_mark_text); + break; case PROP_EXTENDED: g_value_set_boolean (value, self->priv->extended); break; @@ -1050,6 +1112,15 @@ gvc_channel_bar_class_init (GvcChannelBarClass *klass) G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); + properties[PROP_SHOW_MARK_TEXT] = + g_param_spec_boolean ("show-mark-text", + "Show mark-text", + "Whether to show a volume level label next to each scale mark", + TRUE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT | + G_PARAM_STATIC_STRINGS); + properties[PROP_EXTENDED] = g_param_spec_boolean ("extended", "Extended", diff --git a/mate-volume-control/gvc-channel-bar.h b/mate-volume-control/gvc-channel-bar.h index d7a0cbc..7fc0ed2 100644 --- a/mate-volume-control/gvc-channel-bar.h +++ b/mate-volume-control/gvc-channel-bar.h @@ -95,6 +95,10 @@ gboolean gvc_channel_bar_get_show_marks (GvcChannelBar *bar void gvc_channel_bar_set_show_marks (GvcChannelBar *bar, gboolean show_marks); +gboolean gvc_channel_bar_get_show_mark_text (GvcChannelBar *bar); +void gvc_channel_bar_set_show_mark_text (GvcChannelBar *bar, + gboolean show_mark_text); + gboolean gvc_channel_bar_get_extended (GvcChannelBar *bar); void gvc_channel_bar_set_extended (GvcChannelBar *bar, gboolean extended); diff --git a/mate-volume-control/gvc-mixer-dialog.c b/mate-volume-control/gvc-mixer-dialog.c index 759995b..a71a12f 100644 --- a/mate-volume-control/gvc-mixer-dialog.c +++ b/mate-volume-control/gvc-mixer-dialog.c @@ -41,9 +41,11 @@ struct _GvcMixerDialogPrivate { + GSettings *sound_settings; MateMixerContext *context; MateMixerBackendFlags backend_flags; GHashTable *bars; + GtkWidget *volume_overamplifiable_button; GtkWidget *notebook; GtkWidget *output_bar; GtkWidget *input_bar; @@ -369,6 +371,39 @@ update_output_settings (GvcMixerDialog *dialog) gtk_widget_hide (dialog->priv->output_settings_frame); } +/* + * Enable or disable the checkbox allowing the user to set the volume above + * 100%, depending on whether the maximum volume is greater than the + * "normal" volume. If the maximum volume is greater than the normal + * volume, then enable the checkbox; otherwise, over-amplification is not + * possible with this control, so disable the checkbox. + */ +static void +update_overamplify_sensitivity (GvcMixerDialog *dialog) +{ + MateMixerStreamControl *control; + guint normal_volume; + guint maximum_volume; + + control = gvc_channel_bar_get_control (GVC_CHANNEL_BAR (dialog->priv->output_bar)); + if (control == NULL) + { + gtk_widget_set_sensitive (dialog->priv->volume_overamplifiable_button, + FALSE); + return; + } + + normal_volume = mate_mixer_stream_control_get_normal_volume (control); + maximum_volume = mate_mixer_stream_control_get_max_volume (control); + + if (maximum_volume > normal_volume) + gtk_widget_set_sensitive (dialog->priv->volume_overamplifiable_button, + TRUE); + else + gtk_widget_set_sensitive (dialog->priv->volume_overamplifiable_button, + FALSE); +} + static void set_output_stream (GvcMixerDialog *dialog, MateMixerStream *stream) { @@ -420,6 +455,7 @@ set_output_stream (GvcMixerDialog *dialog, MateMixerStream *stream) update_default_tree_item (dialog, model, stream); update_output_settings (dialog); + update_overamplify_sensitivity (dialog); } static void @@ -628,8 +664,7 @@ create_bar (GvcMixerDialog *dialog, gboolean use_size_group, gboolean symmetric) "orientation", GTK_ORIENTATION_HORIZONTAL, "show-mute", TRUE, "show-icons", TRUE, - "show-marks", TRUE, - "extended", TRUE, NULL); + "show-marks", TRUE, NULL); return bar; } @@ -861,6 +896,7 @@ add_stream (GvcMixerDialog *dialog, MateMixerStream *stream) bar_set_stream (dialog, dialog->priv->output_bar, stream); update_output_settings (dialog); + update_overamplify_sensitivity (dialog); is_default = TRUE; } model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->priv->output_treeview)); @@ -1954,6 +1990,8 @@ gvc_mixer_dialog_constructor (GType type, self = GVC_MIXER_DIALOG (object); + self->priv->sound_settings = g_settings_new ("org.mate.sound"); + gtk_dialog_add_button (GTK_DIALOG (self), "gtk-close", GTK_RESPONSE_OK); main_vbox = gtk_dialog_get_content_area (GTK_DIALOG (self)); @@ -1961,8 +1999,8 @@ gvc_mixer_dialog_constructor (GType type, gtk_container_set_border_width (GTK_CONTAINER (self), 6); - self->priv->output_stream_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12); - gtk_widget_set_margin_top (self->priv->output_stream_box, 12); + self->priv->output_stream_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12); + gtk_container_set_border_width (GTK_CONTAINER (self->priv->output_stream_box), 12); gtk_box_pack_start (GTK_BOX (main_vbox), self->priv->output_stream_box, @@ -1972,11 +2010,26 @@ gvc_mixer_dialog_constructor (GType type, gvc_channel_bar_set_name (GVC_CHANNEL_BAR (self->priv->output_bar), _("_Output volume: ")); + g_settings_bind (self->priv->sound_settings, "volume-overamplifiable", + self->priv->output_bar, "extended", + G_SETTINGS_BIND_GET); + gtk_widget_show (self->priv->output_bar); gtk_widget_set_sensitive (self->priv->output_bar, FALSE); gtk_box_pack_start (GTK_BOX (self->priv->output_stream_box), - self->priv->output_bar, TRUE, TRUE, 12); + self->priv->output_bar, TRUE, TRUE, 0); + + self->priv->volume_overamplifiable_button = + gtk_check_button_new_with_mnemonic (_("Allow volume to e_xceed 100%")); + + g_settings_bind (self->priv->sound_settings, "volume-overamplifiable", + self->priv->volume_overamplifiable_button, "active", + G_SETTINGS_BIND_GET|G_SETTINGS_BIND_SET); + + gtk_box_pack_start (GTK_BOX (self->priv->output_stream_box), + self->priv->volume_overamplifiable_button, + FALSE, FALSE, 0); self->priv->notebook = gtk_notebook_new (); @@ -2346,6 +2399,8 @@ gvc_mixer_dialog_dispose (GObject *object) g_clear_object (&dialog->priv->context); } + g_clear_object (&dialog->priv->sound_settings); + G_OBJECT_CLASS (gvc_mixer_dialog_parent_class)->dispose (object); } diff --git a/mate-volume-control/gvc-stream-applet-icon.c b/mate-volume-control/gvc-stream-applet-icon.c index d2b7337..c910150 100644 --- a/mate-volume-control/gvc-stream-applet-icon.c +++ b/mate-volume-control/gvc-stream-applet-icon.c @@ -37,6 +37,7 @@ struct _GvcStreamAppletIconPrivate { + GSettings *sound_settings; gchar **icon_names; GtkImage *image; GtkWidget *dock; @@ -680,6 +681,8 @@ gvc_stream_applet_icon_init (GvcStreamAppletIcon *icon) icon->priv = gvc_stream_applet_icon_get_instance_private (icon); + icon->priv->sound_settings = g_settings_new ("org.mate.sound"); + icon->priv->image = GTK_IMAGE (gtk_image_new ()); gtk_container_add (GTK_CONTAINER (icon), GTK_WIDGET (icon->priv->image)); @@ -731,6 +734,17 @@ gvc_stream_applet_icon_init (GvcStreamAppletIcon *icon) gvc_channel_bar_set_orientation (GVC_CHANNEL_BAR (icon->priv->bar), GTK_ORIENTATION_VERTICAL); + gvc_channel_bar_set_show_mark_text (GVC_CHANNEL_BAR (icon->priv->bar), + FALSE); + + g_settings_bind (icon->priv->sound_settings, "volume-overamplifiable", + icon->priv->bar, "show-marks", + G_SETTINGS_BIND_GET); + + g_settings_bind (icon->priv->sound_settings, "volume-overamplifiable", + icon->priv->bar, "extended", + G_SETTINGS_BIND_GET); + /* Set volume control frame, slider and toplevel window to follow panel theme */ GtkWidget *toplevel = gtk_widget_get_toplevel (icon->priv->dock); GtkStyleContext *context; @@ -769,6 +783,8 @@ gvc_stream_applet_icon_finalize (GObject *object) on_icon_theme_change, icon); + g_clear_object (&icon->priv->sound_settings); + G_OBJECT_CLASS (gvc_stream_applet_icon_parent_class)->finalize (object); } diff --git a/mate-volume-control/gvc-stream-status-icon.c b/mate-volume-control/gvc-stream-status-icon.c index 8ca2849..ef1124a 100644 --- a/mate-volume-control/gvc-stream-status-icon.c +++ b/mate-volume-control/gvc-stream-status-icon.c @@ -35,6 +35,7 @@ struct _GvcStreamStatusIconPrivate { + GSettings *sound_settings; gchar **icon_names; GtkWidget *dock; GtkWidget *bar; @@ -689,6 +690,8 @@ gvc_stream_status_icon_init (GvcStreamStatusIcon *icon) icon->priv = gvc_stream_status_icon_get_instance_private (icon); + icon->priv->sound_settings = g_settings_new ("org.mate.sound"); + g_signal_connect (G_OBJECT (icon), "activate", G_CALLBACK (on_status_icon_activate), @@ -745,6 +748,17 @@ gvc_stream_status_icon_init (GvcStreamStatusIcon *icon) gvc_channel_bar_set_orientation (GVC_CHANNEL_BAR (icon->priv->bar), GTK_ORIENTATION_VERTICAL); + gvc_channel_bar_set_show_mark_text (GVC_CHANNEL_BAR (icon->priv->bar), + FALSE); + + g_settings_bind (icon->priv->sound_settings, "volume-overamplifiable", + icon->priv->bar, "show-marks", + G_SETTINGS_BIND_GET); + + g_settings_bind (icon->priv->sound_settings, "volume-overamplifiable", + icon->priv->bar, "extended", + G_SETTINGS_BIND_GET); + /* Set volume control frame, slider and toplevel window to follow panel theme */ GtkWidget *toplevel = gtk_widget_get_toplevel (icon->priv->dock); GtkStyleContext *context; @@ -781,6 +795,8 @@ gvc_stream_status_icon_finalize (GObject *object) on_icon_theme_change, icon); + g_clear_object (&icon->priv->sound_settings); + G_OBJECT_CLASS (gvc_stream_status_icon_parent_class)->finalize (object); } |