[Xfce4-commits] [panel-plugins/xfce4-pulseaudio-plugin] 15/21: Replace mute checkbox with switch
noreply at xfce.org
noreply at xfce.org
Sat Sep 23 21:27:41 CEST 2017
This is an automated email from the git hooks/post-receive script.
b l u e s a b r e p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository panel-plugins/xfce4-pulseaudio-plugin.
commit 3df24e90b5737a51b3cef7c03227c5a061468109
Author: Sean Davis <smd.seandavis at gmail.com>
Date: Tue Sep 12 20:30:14 2017 -0400
Replace mute checkbox with switch
---
panel-plugin/pulseaudio-menu.c | 89 +++++++++-------------
panel-plugin/scalemenuitem.c | 166 +++++++++++++++++++++++++++++++++--------
panel-plugin/scalemenuitem.h | 14 +++-
3 files changed, 178 insertions(+), 91 deletions(-)
diff --git a/panel-plugin/pulseaudio-menu.c b/panel-plugin/pulseaudio-menu.c
index 6a22ae0..056dbdd 100644
--- a/panel-plugin/pulseaudio-menu.c
+++ b/panel-plugin/pulseaudio-menu.c
@@ -49,10 +49,9 @@ struct _PulseaudioMenu
PulseaudioConfig *config;
PulseaudioMpris *mpris;
GtkWidget *button;
- GtkWidget *range_output;
- GtkWidget *mute_output_item;
- GtkWidget *range_input;
- GtkWidget *mute_input_item;
+
+ GtkWidget *output_scale;
+ GtkWidget *input_scale;
gulong volume_changed_id;
gulong volume_mic_changed_id;
@@ -87,10 +86,8 @@ pulseaudio_menu_init (PulseaudioMenu *menu)
menu->config = NULL;
menu->mpris = NULL;
menu->button = NULL;
- menu->range_output = NULL;
- menu->mute_output_item = NULL;
- menu->range_input = NULL;
- menu->mute_input_item = NULL;
+ menu->output_scale = NULL;
+ menu->input_scale = NULL;
menu->volume_changed_id = 0;
menu->volume_mic_changed_id = 0;
}
@@ -113,10 +110,8 @@ pulseaudio_menu_finalize (GObject *object)
menu->config = NULL;
menu->mpris = NULL;
menu->button = NULL;
- menu->range_output = NULL;
- menu->mute_output_item = NULL;
- menu->range_input = NULL;
- menu->mute_input_item = NULL;
+ menu->output_scale = NULL;
+ menu->input_scale = NULL;
menu->volume_changed_id = 0;
menu->volume_mic_changed_id = 0;
@@ -155,7 +150,7 @@ pulseaudio_menu_output_range_value_changed (PulseaudioMenu *menu,
g_return_if_fail (IS_PULSEAUDIO_MENU (menu));
- new_volume = gtk_range_get_value (GTK_RANGE (menu->range_output)) / 100.0;
+ new_volume = scale_menu_item_get_value (SCALE_MENU_ITEM (menu->output_scale)) / 100.0;
pulseaudio_volume_set_volume (menu->volume, new_volume);
}
@@ -163,11 +158,11 @@ pulseaudio_menu_output_range_value_changed (PulseaudioMenu *menu,
static void
pulseaudio_menu_mute_output_item_toggled (PulseaudioMenu *menu,
- GtkCheckMenuItem *menu_item)
+ ScaleMenuItem *menu_item)
{
g_return_if_fail (IS_PULSEAUDIO_MENU (menu));
- pulseaudio_volume_set_muted (menu->volume, gtk_check_menu_item_get_active (menu_item));
+ pulseaudio_volume_set_muted (menu->volume, scale_menu_item_get_muted (menu_item));
}
@@ -226,7 +221,7 @@ pulseaudio_menu_input_range_value_changed (PulseaudioMenu *menu,
g_return_if_fail (IS_PULSEAUDIO_MENU (menu));
- new_volume_mic = gtk_range_get_value (GTK_RANGE (menu->range_input)) / 100.0;
+ new_volume_mic = scale_menu_item_get_value (SCALE_MENU_ITEM (menu->input_scale)) / 100.0;
pulseaudio_volume_set_volume_mic (menu->volume, new_volume_mic);
}
@@ -234,11 +229,11 @@ pulseaudio_menu_input_range_value_changed (PulseaudioMenu *menu,
static void
pulseaudio_menu_mute_input_item_toggled (PulseaudioMenu *menu,
- GtkCheckMenuItem *menu_item)
+ ScaleMenuItem *menu_item)
{
g_return_if_fail (IS_PULSEAUDIO_MENU (menu));
- pulseaudio_volume_set_muted_mic (menu->volume, gtk_check_menu_item_get_active (menu_item));
+ pulseaudio_volume_set_muted_mic (menu->volume, scale_menu_item_get_muted (menu_item));
}
@@ -280,27 +275,27 @@ pulseaudio_menu_volume_changed (PulseaudioMenu *menu,
g_return_if_fail (IS_PULSEAUDIO_MENU (menu));
g_return_if_fail (IS_PULSEAUDIO_VOLUME (volume));
- g_signal_handlers_block_by_func (G_OBJECT (menu->mute_output_item),
+ g_signal_handlers_block_by_func (G_OBJECT (menu->output_scale),
pulseaudio_menu_mute_output_item_toggled,
menu);
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu->mute_output_item),
+ scale_menu_item_set_muted (SCALE_MENU_ITEM (menu->output_scale),
pulseaudio_volume_get_muted (volume));
- g_signal_handlers_unblock_by_func (G_OBJECT (menu->mute_output_item),
+ g_signal_handlers_unblock_by_func (G_OBJECT (menu->output_scale),
pulseaudio_menu_mute_output_item_toggled,
menu);
- gtk_range_set_value (GTK_RANGE (menu->range_output), pulseaudio_volume_get_volume (menu->volume) * 100.0);
+ scale_menu_item_set_value (SCALE_MENU_ITEM (menu->output_scale), pulseaudio_volume_get_volume (menu->volume) * 100.0);
- g_signal_handlers_block_by_func (G_OBJECT (menu->mute_input_item),
+ g_signal_handlers_block_by_func (G_OBJECT (menu->input_scale),
pulseaudio_menu_mute_input_item_toggled,
menu);
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu->mute_input_item),
+ scale_menu_item_set_muted (SCALE_MENU_ITEM (menu->input_scale),
pulseaudio_volume_get_muted_mic (volume));
- g_signal_handlers_unblock_by_func (G_OBJECT (menu->mute_input_item),
+ g_signal_handlers_unblock_by_func (G_OBJECT (menu->input_scale),
pulseaudio_menu_mute_input_item_toggled,
menu);
- gtk_range_set_value (GTK_RANGE (menu->range_input), pulseaudio_volume_get_volume_mic (menu->volume) * 100.0);
+ scale_menu_item_set_value (SCALE_MENU_ITEM (menu->input_scale), pulseaudio_volume_get_volume_mic (menu->volume) * 100.0);
}
#ifdef HAVE_MPRIS2
@@ -463,22 +458,15 @@ pulseaudio_menu_new (PulseaudioVolume *volume,
gtk_menu_shell_append (GTK_MENU_SHELL (menu), device_mi);
/* output volume slider */
- mi = scale_menu_item_new_with_range (0.0, volume_max, 1.0);
- scale_menu_item_set_base_icon_name (SCALE_MENU_ITEM (mi), "audio-volume");
-
- /* range slider */
- menu->range_output = scale_menu_item_get_scale (SCALE_MENU_ITEM (mi));
-
- g_signal_connect_swapped (mi, "value-changed", G_CALLBACK (pulseaudio_menu_output_range_value_changed), menu);
- g_signal_connect (mi, "scroll-event", G_CALLBACK (pulseaudio_menu_output_range_scroll), menu);
+ menu->output_scale = scale_menu_item_new_with_range (0.0, volume_max, 1.0);
+ scale_menu_item_set_base_icon_name (SCALE_MENU_ITEM (menu->output_scale), "audio-volume");
- gtk_widget_show_all (mi);
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
+ g_signal_connect_swapped (menu->output_scale, "value-changed", G_CALLBACK (pulseaudio_menu_output_range_value_changed), menu);
+ g_signal_connect_swapped (menu->output_scale, "toggled", G_CALLBACK (pulseaudio_menu_mute_output_item_toggled), menu);
+ g_signal_connect (menu->output_scale, "scroll-event", G_CALLBACK (pulseaudio_menu_output_range_scroll), menu);
- menu->mute_output_item = gtk_check_menu_item_new_with_mnemonic (_("_Mute audio output"));
- gtk_widget_show_all (menu->mute_output_item);
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu->mute_output_item);
- g_signal_connect_swapped (G_OBJECT (menu->mute_output_item), "toggled", G_CALLBACK (pulseaudio_menu_mute_output_item_toggled), menu);
+ gtk_widget_show_all (menu->output_scale);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu->output_scale);
/* separator */
mi = gtk_separator_menu_item_new ();
@@ -505,22 +493,15 @@ pulseaudio_menu_new (PulseaudioVolume *volume,
gtk_menu_shell_append (GTK_MENU_SHELL (menu), device_mi);
/* input volume slider */
- mi = scale_menu_item_new_with_range (0.0, volume_max, 1.0);
- scale_menu_item_set_base_icon_name (SCALE_MENU_ITEM (mi), "microphone-sensitivity");
-
- /* range slider */
- menu->range_input = scale_menu_item_get_scale (SCALE_MENU_ITEM (mi));
-
- g_signal_connect_swapped (mi, "value-changed", G_CALLBACK (pulseaudio_menu_input_range_value_changed), menu);
- g_signal_connect (mi, "scroll-event", G_CALLBACK (pulseaudio_menu_input_range_scroll), menu);
+ menu->input_scale = scale_menu_item_new_with_range (0.0, volume_max, 1.0);
+ scale_menu_item_set_base_icon_name (SCALE_MENU_ITEM (menu->input_scale), "microphone-sensitivity");
- gtk_widget_show_all (mi);
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
+ g_signal_connect_swapped (menu->input_scale, "value-changed", G_CALLBACK (pulseaudio_menu_input_range_value_changed), menu);
+ g_signal_connect_swapped (menu->input_scale, "toggled", G_CALLBACK (pulseaudio_menu_mute_input_item_toggled), menu);
+ g_signal_connect (menu->input_scale, "scroll-event", G_CALLBACK (pulseaudio_menu_input_range_scroll), menu);
- menu->mute_input_item = gtk_check_menu_item_new_with_mnemonic (_("_Mute audio input"));
- gtk_widget_show_all (menu->mute_input_item);
- gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu->mute_input_item);
- g_signal_connect_swapped (G_OBJECT (menu->mute_input_item), "toggled", G_CALLBACK (pulseaudio_menu_mute_input_item_toggled), menu);
+ gtk_widget_show_all (menu->input_scale);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu->input_scale);
/* separator */
mi = gtk_separator_menu_item_new ();
diff --git a/panel-plugin/scalemenuitem.c b/panel-plugin/scalemenuitem.c
index db96a09..5f27bcd 100644
--- a/panel-plugin/scalemenuitem.c
+++ b/panel-plugin/scalemenuitem.c
@@ -52,7 +52,10 @@ static void scale_menu_item_parent_set (GtkWidget *ite
struct _ScaleMenuItemPrivate {
GtkWidget *scale;
+ GtkWidget *hbox;
+ GtkWidget *vbox;
GtkWidget *image;
+ GtkWidget *mute_toggle;
gchar *icon_name;
gboolean grabbed;
@@ -68,6 +71,7 @@ enum {
SLIDER_GRABBED,
SLIDER_RELEASED,
VALUE_CHANGED,
+ TOGGLED,
LAST_SIGNAL
};
@@ -85,38 +89,48 @@ G_GNUC_END_IGNORE_DEPRECATIONS
static void
-scale_menu_item_scale_value_changed (GtkRange *range,
- gpointer user_data)
+scale_menu_item_update_icon (ScaleMenuItem *self)
{
- ScaleMenuItem *self = SCALE_MENU_ITEM (user_data);
ScaleMenuItemPrivate *priv = GET_PRIVATE (self);
gchar *icon_name = NULL;
- gdouble value = gtk_range_get_value (range);
-
- g_signal_emit (self, signals[VALUE_CHANGED], 0, value);
+ gdouble value = gtk_range_get_value (GTK_RANGE (priv->scale));
/* Update the menuitem icon */
- if (value >= 70.0)
+ if (scale_menu_item_get_muted (self) || value <= 0.0)
{
- icon_name = g_strconcat(priv->icon_name, "-high-symbolic", NULL);
+ icon_name = g_strconcat(priv->icon_name, "-muted-symbolic", NULL);
}
- else if (value >= 30.0)
+ else if (value < 30.0)
{
- icon_name = g_strconcat(priv->icon_name, "-medium-symbolic", NULL);
+ icon_name = g_strconcat(priv->icon_name, "-low-symbolic", NULL);
}
- else if (value > 0.0)
+ else if (value < 70.0)
{
- icon_name = g_strconcat(priv->icon_name, "-low-symbolic", NULL);
+ icon_name = g_strconcat(priv->icon_name, "-medium-symbolic", NULL);
}
else
{
- icon_name = g_strconcat(priv->icon_name, "-muted-symbolic", NULL);
+ icon_name = g_strconcat(priv->icon_name, "-high-symbolic", NULL);
}
gtk_image_set_from_icon_name (GTK_IMAGE (priv->image), icon_name, GTK_ICON_SIZE_MENU);
g_free (icon_name);
}
+
+
+static void
+scale_menu_item_scale_value_changed (GtkRange *range,
+ gpointer user_data)
+{
+ ScaleMenuItem *self = SCALE_MENU_ITEM (user_data);
+ gdouble value = gtk_range_get_value (range);
+
+ g_signal_emit (self, signals[VALUE_CHANGED], 0, value);
+
+ scale_menu_item_update_icon (self);
+}
+
static void
scale_menu_item_class_init (ScaleMenuItemClass *item_class)
{
@@ -175,6 +189,20 @@ scale_menu_item_class_init (ScaleMenuItemClass *item_class)
G_TYPE_NONE,
1, G_TYPE_DOUBLE);
+ /**
+ * ScaleMenuItem::toggled:
+ * @menuitem: the #ScaleMenuItem emitting the signal.
+ * @value: the new value
+ *
+ * Emitted whenever the mute switch is toggled.
+ */
+ signals[TOGGLED] = g_signal_new ("toggled",
+ G_OBJECT_CLASS_TYPE (gobject_class),
+ G_SIGNAL_RUN_FIRST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
g_type_class_add_private (item_class, sizeof (ScaleMenuItemPrivate));
}
@@ -188,6 +216,9 @@ scale_menu_item_init (ScaleMenuItem *self)
priv->scale = NULL;
priv->image = NULL;
+ priv->hbox = NULL;
+ priv->vbox = NULL;
+ priv->mute_toggle = NULL;
priv->icon_name = NULL;
}
@@ -203,8 +234,11 @@ scale_menu_item_finalize (GObject *object)
if (priv->icon_name)
g_free (priv->icon_name);
- g_object_unref (priv->image);
g_object_unref (priv->scale);
+ g_object_unref (priv->image);
+ g_object_unref (priv->mute_toggle);
+ g_object_unref (priv->vbox);
+ g_object_unref (priv->hbox);
(*G_OBJECT_CLASS (scale_menu_item_parent_class)->finalize) (object);
}
@@ -223,9 +257,15 @@ scale_menu_item_button_press_event (GtkWidget *menuitem,
priv = GET_PRIVATE (menuitem);
+ gtk_widget_get_allocation (priv->mute_toggle, &alloc);
+ gtk_widget_translate_coordinates (GTK_WIDGET (menuitem), priv->mute_toggle, event->x, event->y, &x, &y);
+ if (x > 0 && x < alloc.width && y > 0 && y < alloc.height)
+ {
+ return TRUE;
+ }
+
gtk_widget_get_allocation (priv->scale, &alloc);
gtk_widget_translate_coordinates (menuitem, priv->scale, event->x, event->y, &x, &y);
-
if (x > 0 && x < alloc.width && y > 0 && y < alloc.height)
{
gtk_widget_event (priv->scale, (GdkEvent*) event);
@@ -245,6 +285,8 @@ scale_menu_item_button_release_event (GtkWidget *menuitem,
GdkEventButton *event)
{
ScaleMenuItemPrivate *priv;
+ GtkAllocation alloc;
+ gint x, y;
TRACE("entering");
@@ -252,7 +294,21 @@ scale_menu_item_button_release_event (GtkWidget *menuitem,
priv = GET_PRIVATE (menuitem);
- gtk_widget_event (priv->scale, (GdkEvent*)event);
+ gtk_widget_get_allocation (priv->mute_toggle, &alloc);
+ gtk_widget_translate_coordinates (GTK_WIDGET (menuitem), priv->mute_toggle, event->x, event->y, &x, &y);
+ if (x > 0 && x < alloc.width && y > 0 && y < alloc.height)
+ {
+ gtk_switch_set_active (GTK_SWITCH (priv->mute_toggle), !gtk_switch_get_active (GTK_SWITCH (priv->mute_toggle)));
+ g_signal_emit (menuitem, signals[TOGGLED], 0);
+ return TRUE;
+ }
+
+ gtk_widget_get_allocation (priv->scale, &alloc);
+ gtk_widget_translate_coordinates (menuitem, priv->scale, event->x, event->y, &x, &y);
+ if (x > 0 && x < alloc.width && y > 0 && y < alloc.height)
+ {
+ gtk_widget_event (priv->scale, (GdkEvent*) event);
+ }
if (priv->grabbed)
{
@@ -359,8 +415,17 @@ G_GNUC_END_IGNORE_DEPRECATIONS
if (max > 100.0)
gtk_scale_add_mark (GTK_SCALE (priv->scale), 100.0, GTK_POS_BOTTOM, NULL);
+ /* Configure the mute toggle */
+ priv->mute_toggle = gtk_switch_new ();
+
/* Pack the scale widget */
- gtk_container_add (GTK_CONTAINER (scale_item), priv->scale);
+ priv->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ priv->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ gtk_box_pack_start (GTK_BOX (priv->hbox), priv->scale, TRUE, TRUE, 0);
+ gtk_box_set_center_widget (GTK_BOX (priv->vbox), priv->mute_toggle);
+ gtk_box_pack_start (GTK_BOX (priv->hbox), priv->vbox, FALSE, FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (scale_item), priv->hbox);
+ gtk_widget_show_all (priv->hbox);
/* Connect events */
g_signal_connect (priv->scale, "value-changed", G_CALLBACK (scale_menu_item_scale_value_changed), scale_item);
@@ -369,33 +434,41 @@ G_GNUC_END_IGNORE_DEPRECATIONS
/* Keep references to the widgets */
g_object_ref (priv->image);
g_object_ref (priv->scale);
+ g_object_ref (priv->mute_toggle);
+ g_object_ref (priv->hbox);
+ g_object_ref (priv->vbox);
return GTK_WIDGET(scale_item);
}
-/**
- * scale_menu_item_get_scale:
- * @menuitem: The #ScaleMenuItem
- *
- * Retrieves the scale widget.
- *
- * Return Value: (transfer none)
- **/
-GtkWidget*
-scale_menu_item_get_scale (ScaleMenuItem *menuitem)
+void
+scale_menu_item_set_base_icon_name (ScaleMenuItem *item,
+ const gchar *base_icon_name)
+{
+ ScaleMenuItemPrivate *priv;
+
+ g_return_if_fail (IS_SCALE_MENU_ITEM (item));
+
+ priv = GET_PRIVATE (item);
+
+ priv->icon_name = g_strdup (base_icon_name);
+}
+
+gdouble
+scale_menu_item_get_value (ScaleMenuItem *item)
{
ScaleMenuItemPrivate *priv;
- g_return_val_if_fail (IS_SCALE_MENU_ITEM (menuitem), NULL);
+ g_return_val_if_fail (IS_SCALE_MENU_ITEM (item), 0.0);
- priv = GET_PRIVATE (menuitem);
+ priv = GET_PRIVATE (item);
- return priv->scale;
+ return gtk_range_get_value (GTK_RANGE (priv->scale));
}
void
-scale_menu_item_set_base_icon_name (ScaleMenuItem *item,
- const gchar *base_icon_name)
+scale_menu_item_set_value (ScaleMenuItem *item,
+ gdouble value)
{
ScaleMenuItemPrivate *priv;
@@ -403,5 +476,32 @@ scale_menu_item_set_base_icon_name (ScaleMenuItem *item,
priv = GET_PRIVATE (item);
- priv->icon_name = g_strdup (base_icon_name);
+ gtk_range_set_value (GTK_RANGE (priv->scale), value);
+}
+
+gboolean
+scale_menu_item_get_muted (ScaleMenuItem *menuitem)
+{
+ ScaleMenuItemPrivate *priv;
+
+ g_return_val_if_fail (IS_SCALE_MENU_ITEM (menuitem), TRUE);
+
+ priv = GET_PRIVATE (menuitem);
+
+ return !gtk_switch_get_active (GTK_SWITCH (priv->mute_toggle));
+}
+
+void
+scale_menu_item_set_muted (ScaleMenuItem *menuitem,
+ gboolean muted)
+{
+ ScaleMenuItemPrivate *priv;
+
+ g_return_if_fail (IS_SCALE_MENU_ITEM (menuitem));
+
+ priv = GET_PRIVATE (menuitem);
+
+ gtk_switch_set_active (GTK_SWITCH (priv->mute_toggle), !muted);
+
+ scale_menu_item_update_icon (menuitem);
}
diff --git a/panel-plugin/scalemenuitem.h b/panel-plugin/scalemenuitem.h
index 273aae3..c9d40b3 100644
--- a/panel-plugin/scalemenuitem.h
+++ b/panel-plugin/scalemenuitem.h
@@ -59,11 +59,17 @@ struct _ScaleMenuItemClass
GType scale_menu_item_get_type (void) G_GNUC_CONST;
-GtkWidget *scale_menu_item_new_with_range (gdouble min,
- gdouble max,
- gdouble step);
+GtkWidget *scale_menu_item_new_with_range (gdouble min,
+ gdouble max,
+ gdouble step);
-GtkWidget *scale_menu_item_get_scale (ScaleMenuItem *menuitem);
+gdouble scale_menu_item_get_value (ScaleMenuItem *item);
+void scale_menu_item_set_value (ScaleMenuItem *item,
+ gdouble value);
+
+gboolean scale_menu_item_get_muted (ScaleMenuItem *menuitem);
+void scale_menu_item_set_muted (ScaleMenuItem *menuitem,
+ gboolean muted);
void scale_menu_item_set_base_icon_name (ScaleMenuItem *item,
const gchar *base_icon_name);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list