[Xfce4-commits] [panel-plugins/xfce4-pulseaudio-plugin] 06/21: Initial device widget, still need to adjust the other widgets
noreply at xfce.org
noreply at xfce.org
Sat Sep 23 21:27:32 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 2e32b7055f0d6177741fd12ae74613498efea744
Author: Sean Davis <smd.seandavis at gmail.com>
Date: Sun Sep 10 23:20:29 2017 -0400
Initial device widget, still need to adjust the other widgets
---
panel-plugin/Makefile.am | 4 +-
panel-plugin/devicemenuitem.c | 195 +++++++++++++++++++++++++++++++++++++++++
panel-plugin/devicemenuitem.h | 71 +++++++++++++++
panel-plugin/pulseaudio-menu.c | 112 ++++++++---------------
4 files changed, 307 insertions(+), 75 deletions(-)
diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index c6d1c17..d7b5835 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -44,7 +44,9 @@ libpulseaudio_plugin_la_SOURCES = \
scalemenuitem.c \
scalemenuitem.h \
mprismenuitem.c \
- mprismenuitem.h
+ mprismenuitem.h \
+ devicemenuitem.c \
+ devicemenuitem.h
libpulseaudio_plugin_la_CFLAGS = \
diff --git a/panel-plugin/devicemenuitem.c b/panel-plugin/devicemenuitem.c
new file mode 100644
index 0000000..0d7f6d2
--- /dev/null
+++ b/panel-plugin/devicemenuitem.c
@@ -0,0 +1,195 @@
+/* -*- c-basic-offset: 2 -*- vi:set ts=2 sts=2 sw=2:
+ * * Copyright (C) 2017 Sean Davis <bluesabre at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "devicemenuitem.h"
+
+/* for DBG/TRACE */
+#include <libxfce4util/libxfce4util.h>
+
+
+
+struct _DeviceMenuItemPrivate {
+ GtkWidget *submenu;
+ GtkWidget *label_widget;
+ GSList *group;
+ gchar *label;
+};
+
+
+
+enum {
+ DEVICE_CHANGED,
+ LAST_SIGNAL
+};
+
+
+
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+G_DEFINE_TYPE (DeviceMenuItem, device_menu_item, GTK_TYPE_IMAGE_MENU_ITEM)
+G_GNUC_END_IGNORE_DEPRECATIONS
+
+#define GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_DEVICE_MENU_ITEM, DeviceMenuItemPrivate))
+
+
+
+static void
+device_menu_item_class_init (DeviceMenuItemClass *item_class)
+{
+ /**
+ * DeviceMenuItem::value-changed:
+ * @menuitem: the #DeviceMenuItem for which the value changed
+ * @value: the new value
+ *
+ * Emitted whenever the value of the contained scale changes because
+ * of user input.
+ */
+ signals[DEVICE_CHANGED] = g_signal_new ("device-changed",
+ TYPE_DEVICE_MENU_ITEM,
+ G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL,
+ g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE,
+ 1, G_TYPE_STRING);
+
+
+ g_type_class_add_private (item_class, sizeof (DeviceMenuItemPrivate));
+}
+
+static void
+device_menu_item_init (DeviceMenuItem *self)
+{
+}
+
+GtkWidget*
+device_menu_item_new_with_label (const gchar *label)
+{
+ DeviceMenuItem *device_item;
+ DeviceMenuItemPrivate *priv;
+
+ TRACE("entering");
+
+ device_item = DEVICE_MENU_ITEM (g_object_new (TYPE_DEVICE_MENU_ITEM, NULL));
+
+ priv = GET_PRIVATE (device_item);
+
+ priv->submenu = gtk_menu_new ();
+ priv->label = g_strdup (label);
+ priv->group = NULL;
+
+ gtk_menu_item_set_label (GTK_MENU_ITEM (device_item), priv->label);
+ priv->label_widget = gtk_bin_get_child (GTK_BIN (device_item));
+ gtk_label_set_width_chars (GTK_LABEL (priv->label_widget), 30);
+ gtk_label_set_max_width_chars (GTK_LABEL (priv->label_widget), 30);
+ gtk_label_set_ellipsize (GTK_LABEL (priv->label_widget), PANGO_ELLIPSIZE_MIDDLE);
+
+ g_object_ref (priv->submenu);
+
+ return GTK_WIDGET(device_item);
+}
+
+static void
+device_menu_item_device_toggled (DeviceMenuItem *self,
+ GtkCheckMenuItem *menu_item)
+{
+ g_return_if_fail (IS_DEVICE_MENU_ITEM (self));
+
+ if (gtk_check_menu_item_get_active (menu_item))
+ {
+ g_signal_emit (self, signals[DEVICE_CHANGED], 0, (gchar *)g_object_get_data (G_OBJECT(menu_item), "name"));
+ }
+}
+
+void
+device_menu_item_add_device (DeviceMenuItem *item,
+ const gchar *name,
+ const gchar *description)
+{
+ DeviceMenuItemPrivate *priv;
+ GtkWidget *mi;
+
+ priv = GET_PRIVATE (item);
+
+ mi = gtk_radio_menu_item_new_with_label (priv->group, description);
+ g_object_set_data (G_OBJECT (mi), "name", g_strdup (name));
+
+ priv->group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (mi));
+
+ if (g_slist_length (priv->group) > 1)
+ {
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), priv->submenu);
+ gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
+ }
+
+ gtk_widget_show (mi);
+ gtk_menu_shell_append (GTK_MENU_SHELL (priv->submenu), mi);
+
+ g_signal_connect_swapped (G_OBJECT (mi), "toggled", G_CALLBACK (device_menu_item_device_toggled), item);
+}
+
+void
+device_menu_item_set_device_by_name (DeviceMenuItem *item,
+ const gchar *name)
+{
+ DeviceMenuItemPrivate *priv;
+ GList *children = NULL;
+ GList *iter = NULL;
+
+ g_return_if_fail (IS_DEVICE_MENU_ITEM (item));
+
+ priv = GET_PRIVATE (item);
+
+ children = gtk_container_get_children (GTK_CONTAINER (priv->submenu));
+
+ for (iter = children; iter != NULL; iter = g_list_next (iter)) {
+ if (g_strcmp0 (name, (gchar *)g_object_get_data (G_OBJECT(iter->data), "name")) == 0)
+ {
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (iter->data), TRUE);
+ gtk_label_set_markup (GTK_LABEL (priv->label_widget), g_strconcat ("<b>", priv->label, " (", gtk_menu_item_get_label (GTK_MENU_ITEM (iter->data)), ")</b>", NULL));
+ } else {
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (iter->data), FALSE);
+ }
+ }
+}
+
+void
+device_menu_item_set_image_from_icon_name (DeviceMenuItem *item,
+ const gchar *icon_name)
+{
+ GtkWidget *img = NULL;
+
+ g_return_if_fail (IS_DEVICE_MENU_ITEM (item));
+
+ img = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), img);
+G_GNUC_END_IGNORE_DEPRECATIONS
+ gtk_image_set_pixel_size (GTK_IMAGE (img), 16);
+}
diff --git a/panel-plugin/devicemenuitem.h b/panel-plugin/devicemenuitem.h
new file mode 100644
index 0000000..8392dc6
--- /dev/null
+++ b/panel-plugin/devicemenuitem.h
@@ -0,0 +1,71 @@
+/* -*- c-basic-offset: 2 -*- vi:set ts=2 sts=2 sw=2:
+ * * Copyright (C) 2017 Sean Davis <bluesabre at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+#ifndef _DEVICE_MENU_ITEM_H_
+#define _DEVICE_MENU_ITEM_H_
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define TYPE_DEVICE_MENU_ITEM (device_menu_item_get_type ())
+#define DEVICE_MENU_ITEM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TYPE_DEVICE_MENU_ITEM, DeviceMenuItem))
+#define DEVICE_MENU_ITEM_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), TYPE_DEVICE_MENU_ITEM, DeviceMenuItemClass))
+#define IS_DEVICE_MENU_ITEM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TYPE_DEVICE_MENU_ITEM))
+#define IS_DEVICE_MENU_ITEM_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), TYPE_DEVICE_MENU_ITEM))
+#define DEVICE_MENU_ITEM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TYPE_DEVICE_MENU_ITEM, DeviceMenuItemClass))
+
+
+typedef struct _DeviceMenuItem DeviceMenuItem;
+typedef struct _DeviceMenuItemClass DeviceMenuItemClass;
+typedef struct _DeviceMenuItemPrivate DeviceMenuItemPrivate;
+
+struct _DeviceMenuItem
+{
+ GtkImageMenuItem parent_instance;
+
+ DeviceMenuItemPrivate *priv;
+};
+
+struct _DeviceMenuItemClass
+{
+ GtkImageMenuItemClass parent_class;
+};
+
+
+GType device_menu_item_get_type (void) G_GNUC_CONST;
+
+GtkWidget *device_menu_item_new_with_label (const gchar *label);
+
+void device_menu_item_set_image_from_icon_name (DeviceMenuItem *menuitem,
+ const gchar *icon_name);
+
+void device_menu_item_add_device (DeviceMenuItem *menuitem,
+ const gchar *name,
+ const gchar *description);
+
+void device_menu_item_set_device_by_name (DeviceMenuItem *menuitem,
+ const gchar *name);
+
+
+G_END_DECLS
+
+#endif /* _DEVICE_MENU_ITEM_H_ */
diff --git a/panel-plugin/pulseaudio-menu.c b/panel-plugin/pulseaudio-menu.c
index 1bfee9a..b942113 100644
--- a/panel-plugin/pulseaudio-menu.c
+++ b/panel-plugin/pulseaudio-menu.c
@@ -36,6 +36,7 @@
#include "pulseaudio-menu.h"
#include "pulseaudio-mpris.h"
+#include "devicemenuitem.h"
#include "mprismenuitem.h"
#include "scalemenuitem.h"
@@ -172,29 +173,25 @@ pulseaudio_menu_mute_output_item_toggled (PulseaudioMenu *menu,
static void
-pulseaudio_menu_default_output_item_toggled (PulseaudioMenu *menu,
- GtkCheckMenuItem *menu_item)
+pulseaudio_menu_default_output_changed (PulseaudioMenu *menu,
+ gchar *name,
+ DeviceMenuItem *menu_item)
{
g_return_if_fail (IS_PULSEAUDIO_MENU (menu));
- if (gtk_check_menu_item_get_active (menu_item))
- {
- pulseaudio_volume_set_default_output (menu->volume, (gchar *)g_object_get_data (G_OBJECT(menu_item), "name"));
- }
+ pulseaudio_volume_set_default_output (menu->volume, name);
}
static void
-pulseaudio_menu_default_input_item_toggled (PulseaudioMenu *menu,
- GtkCheckMenuItem *menu_item)
+pulseaudio_menu_default_input_changed (PulseaudioMenu *menu,
+ gchar *name,
+ DeviceMenuItem *menu_item)
{
g_return_if_fail (IS_PULSEAUDIO_MENU (menu));
- if (gtk_check_menu_item_get_active (menu_item))
- {
- pulseaudio_volume_set_default_input (menu->volume, (gchar *)g_object_get_data (G_OBJECT(menu_item), "name"));
- }
+ pulseaudio_volume_set_default_input (menu->volume, name);
}
@@ -404,11 +401,10 @@ pulseaudio_menu_new (PulseaudioVolume *volume,
PulseaudioMenu *menu;
GdkScreen *gscreen;
GtkWidget *mi;
+ GtkWidget *device_mi;
gdouble volume_max;
- GtkWidget *submenu;
GList *sources = NULL;
- GSList *group = NULL;
#ifdef HAVE_MPRIS2
gchar **players;
@@ -452,6 +448,20 @@ pulseaudio_menu_new (PulseaudioVolume *volume,
/* Output Devices */
sources = pulseaudio_volume_get_output_list (menu->volume);
if (g_list_length (sources) > 0) {
+ device_mi = device_menu_item_new_with_label (_("Audio Output"));
+ device_menu_item_set_image_from_icon_name (DEVICE_MENU_ITEM (device_mi), "audio-speakers-symbolic");
+
+ for (GList *list = sources; list != NULL; list = g_list_next (list)) {
+ device_menu_item_add_device (DEVICE_MENU_ITEM (device_mi), (gchar *)list->data, pulseaudio_volume_get_output_by_name (menu->volume, list->data));
+ }
+
+ device_menu_item_set_device_by_name (DEVICE_MENU_ITEM (device_mi), pulseaudio_volume_get_default_output (menu->volume));
+ gtk_widget_show (device_mi);
+
+ g_signal_connect_swapped (G_OBJECT (device_mi), "device-changed", G_CALLBACK (pulseaudio_menu_default_output_changed), menu);
+
+ 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_image_from_icon_name (SCALE_MENU_ITEM (mi), "audio-volume-high-symbolic");
@@ -471,35 +481,6 @@ pulseaudio_menu_new (PulseaudioVolume *volume,
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);
- if (g_list_length (sources) > 1) {
- submenu = gtk_menu_new ();
-
- for (GList *list = sources; list != NULL; list = g_list_next (list)) {
- mi = gtk_radio_menu_item_new_with_label (group, pulseaudio_volume_get_output_by_name (menu->volume, list->data));
- g_object_set_data (G_OBJECT (mi), "name", g_strdup ((gchar *)list->data));
-
- group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (mi));
- if (g_strcmp0 (list->data, pulseaudio_volume_get_default_output (menu->volume)) == 0)
- {
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), TRUE);
- }
- else
- {
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), FALSE);
- }
- gtk_widget_show (mi);
- gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mi);
-
- g_signal_connect_swapped (G_OBJECT (mi), "toggled", G_CALLBACK (pulseaudio_menu_default_output_item_toggled), menu);
- }
-
- mi = gtk_menu_item_new_with_label ("Output Device");
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), submenu);
- gtk_widget_show (mi);
-
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
- }
-
/* separator */
mi = gtk_separator_menu_item_new ();
gtk_widget_show (mi);
@@ -507,11 +488,23 @@ pulseaudio_menu_new (PulseaudioVolume *volume,
}
g_list_free (sources);
- group = NULL;
-
/* Input Devices */
sources = pulseaudio_volume_get_input_list (menu->volume);
if (g_list_length (sources) > 0) {
+ device_mi = device_menu_item_new_with_label (_("Audio Input"));
+ device_menu_item_set_image_from_icon_name (DEVICE_MENU_ITEM (device_mi), "audio-input-microphone-symbolic");
+
+ for (GList *list = sources; list != NULL; list = g_list_next (list)) {
+ device_menu_item_add_device (DEVICE_MENU_ITEM (device_mi), (gchar *)list->data, pulseaudio_volume_get_input_by_name (menu->volume, list->data));
+ }
+
+ device_menu_item_set_device_by_name (DEVICE_MENU_ITEM (device_mi), pulseaudio_volume_get_default_input (menu->volume));
+ gtk_widget_show (device_mi);
+
+ g_signal_connect_swapped (G_OBJECT (device_mi), "device-changed", G_CALLBACK (pulseaudio_menu_default_input_changed), menu);
+
+ 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_image_from_icon_name (SCALE_MENU_ITEM (mi), "microphone-sensitivity-high-symbolic");
@@ -531,35 +524,6 @@ pulseaudio_menu_new (PulseaudioVolume *volume,
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);
- if (g_list_length (sources) > 1) {
- submenu = gtk_menu_new ();
-
- for (GList *list = sources; list != NULL; list = g_list_next (list)) {
- mi = gtk_radio_menu_item_new_with_label (group, pulseaudio_volume_get_input_by_name (menu->volume, list->data));
- g_object_set_data (G_OBJECT (mi), "name", g_strdup ((gchar *)list->data));
-
- group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (mi));
- if (g_strcmp0 (list->data, pulseaudio_volume_get_default_input (menu->volume)) == 0)
- {
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), TRUE);
- }
- else
- {
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), FALSE);
- }
- gtk_widget_show (mi);
- gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mi);
-
- g_signal_connect_swapped (G_OBJECT (mi), "toggled", G_CALLBACK (pulseaudio_menu_default_input_item_toggled), menu);
- }
-
- mi = gtk_menu_item_new_with_label ("Input Device");
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), submenu);
- gtk_widget_show (mi);
-
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
- }
-
/* separator */
mi = gtk_separator_menu_item_new ();
gtk_widget_show (mi);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list