summaryrefslogtreecommitdiff
path: root/mate-volume-control/gvc-stream-status-icon.c
diff options
context:
space:
mode:
Diffstat (limited to 'mate-volume-control/gvc-stream-status-icon.c')
-rw-r--r--mate-volume-control/gvc-stream-status-icon.c61
1 files changed, 45 insertions, 16 deletions
diff --git a/mate-volume-control/gvc-stream-status-icon.c b/mate-volume-control/gvc-stream-status-icon.c
index 217eea5..dccd20d 100644
--- a/mate-volume-control/gvc-stream-status-icon.c
+++ b/mate-volume-control/gvc-stream-status-icon.c
@@ -2,6 +2,7 @@
*
* Copyright (C) 2008 William Jon McCann
* Copyright (C) 2014 Michal Ratajsky <[email protected]>
+ * Copyright (C) 2014-2021 MATE Developers
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -28,12 +29,14 @@
#define MATE_DESKTOP_USE_UNSTABLE_API
#include <libmate-desktop/mate-desktop-utils.h>
+#include <libmate-desktop/mate-image-menu-item.h>
#include "gvc-channel-bar.h"
#include "gvc-stream-status-icon.h"
struct _GvcStreamStatusIconPrivate
{
+ GSettings *sound_settings;
gchar **icon_names;
GtkWidget *dock;
GtkWidget *bar;
@@ -174,11 +177,7 @@ on_status_icon_button_press (GtkStatusIcon *status_icon,
static void
on_menu_mute_toggled (GtkMenuItem *item, GvcStreamStatusIcon *icon)
{
- gboolean is_muted;
-
- is_muted = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item));
-
- mate_mixer_stream_control_set_mute (icon->priv->control, is_muted);
+ mate_mixer_stream_control_set_mute (icon->priv->control, !mate_mixer_stream_control_get_mute (icon->priv->control));
}
static void
@@ -218,10 +217,11 @@ on_status_icon_popup_menu (GtkStatusIcon *status_icon,
GtkWidget *menu;
GtkWidget *item;
GtkWidget *image;
+ g_autofree char *label = NULL;
menu = gtk_menu_new ();
- /*Set up theme and transparency support*/
+ /* Set up theme and transparency support */
GtkWidget *toplevel = gtk_widget_get_toplevel (menu);
/* Fix any failures of compiz/other wm's to communicate with gtk for transparency */
GdkScreen *screen = gtk_widget_get_screen(GTK_WIDGET(toplevel));
@@ -233,20 +233,31 @@ on_status_icon_popup_menu (GtkStatusIcon *status_icon,
gtk_style_context_add_class(context,"gnome-panel-menu-bar");
gtk_style_context_add_class(context,"mate-panel-menu-bar");
- item = gtk_check_menu_item_new_with_mnemonic (_("_Mute"));
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
- mate_mixer_stream_control_get_mute (icon->priv->control));
+ if (mate_mixer_stream_control_get_mute (icon->priv->control))
+ {
+ label = g_strdup_printf ("%s %s", _("Unmute"), icon->priv->display_name);
+ /* Set icon to medium*/
+ image = gtk_image_new_from_icon_name(icon->priv->icon_names[2], GTK_ICON_SIZE_MENU);
+ }
+ else
+ {
+ label = g_strdup_printf ("%s %s", _("Mute"), icon->priv->display_name);
+ /* Set icon to muted*/
+ image = gtk_image_new_from_icon_name(icon->priv->icon_names[0], GTK_ICON_SIZE_MENU);
+ }
+ item = mate_image_menu_item_new_with_mnemonic(label);
+ mate_image_menu_item_set_image (MATE_IMAGE_MENU_ITEM (item), image);
g_signal_connect (G_OBJECT (item),
- "toggled",
+ "activate",
G_CALLBACK (on_menu_mute_toggled),
icon);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- item = gtk_image_menu_item_new_with_mnemonic (_("_Sound Preferences"));
+ item = mate_image_menu_item_new_with_mnemonic (_("_Sound Preferences"));
image = gtk_image_new_from_icon_name ("multimedia-volume-control",
GTK_ICON_SIZE_MENU);
- gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
+ mate_image_menu_item_set_image (MATE_IMAGE_MENU_ITEM (item), image);
g_signal_connect (G_OBJECT (item),
"activate",
@@ -371,6 +382,7 @@ static void
update_icon (GvcStreamStatusIcon *icon)
{
guint volume = 0;
+ guint volume_percent = 0;
gdouble decibel = 0;
guint normal = 0;
gboolean muted = FALSE;
@@ -398,7 +410,7 @@ update_icon (GvcStreamStatusIcon *icon)
/* Select an icon, they are expected to be sorted, the lowest index being
* the mute icon and the rest being volume increments */
- if (volume <= 0 || muted)
+ if (volume == 0 || muted)
n = 0;
else
n = CLAMP (3 * volume / normal + 1, 1, 3);
@@ -415,7 +427,9 @@ update_icon (GvcStreamStatusIcon *icon)
description = mate_mixer_stream_control_get_label (icon->priv->control);
- guint volume_percent = (guint) round (100.0 * volume / normal);
+ if (normal != 0)
+ volume_percent = (guint) (100.0 * ((double) volume) / ((double) normal));
+
if (muted) {
markup = g_strdup_printf ("<b>%s: %s %u%%</b>\n<small>%s</small>",
icon->priv->display_name,
@@ -499,7 +513,7 @@ void
gvc_stream_status_icon_set_display_name (GvcStreamStatusIcon *icon,
const gchar *name)
{
- g_return_if_fail (GVC_STREAM_STATUS_ICON (icon));
+ g_return_if_fail (GVC_IS_STREAM_STATUS_ICON (icon));
g_free (icon->priv->display_name);
@@ -513,7 +527,7 @@ void
gvc_stream_status_icon_set_control (GvcStreamStatusIcon *icon,
MateMixerStreamControl *control)
{
- g_return_if_fail (GVC_STREAM_STATUS_ICON (icon));
+ g_return_if_fail (GVC_IS_STREAM_STATUS_ICON (icon));
if (icon->priv->control == control)
return;
@@ -680,6 +694,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),
@@ -736,6 +752,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;
@@ -772,6 +799,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);
}