[Xfce4-commits] [panel-plugins/xfce4-pulseaudio-plugin] 01/01: Toggle MPRIS2 support at runtime
noreply at xfce.org
noreply at xfce.org
Tue Aug 29 04:16:38 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 41183009a027d2fbd76383377e40c9a887350777
Author: Sean Davis <smd.seandavis at gmail.com>
Date: Mon Aug 28 22:15:46 2017 -0400
Toggle MPRIS2 support at runtime
---
panel-plugin/pulseaudio-config.c | 48 +++++++++++++++
panel-plugin/pulseaudio-config.h | 1 +
panel-plugin/pulseaudio-dialog.c | 11 ++++
panel-plugin/pulseaudio-dialog.glade | 42 ++++++++++++++
panel-plugin/pulseaudio-menu.c | 109 ++++++++++++++++++-----------------
5 files changed, 158 insertions(+), 53 deletions(-)
diff --git a/panel-plugin/pulseaudio-config.c b/panel-plugin/pulseaudio-config.c
index 70e81c7..dbbffad 100644
--- a/panel-plugin/pulseaudio-config.c
+++ b/panel-plugin/pulseaudio-config.c
@@ -49,6 +49,13 @@
#define DEFAULT_SHOW_NOTIFICATIONS TRUE
#define DEFAULT_VOLUME_STEP 6
#define DEFAULT_VOLUME_MAX 153
+
+#ifdef HAVE_MPRIS2
+#define DEFAULT_ENABLE_MPRIS TRUE
+#else
+#define DEFAULT_ENABLE_MPRIS FALSE
+#endif
+
#define DEFAULT_MPRIS_PLAYERS ""
@@ -79,6 +86,7 @@ struct _PulseaudioConfig
guint volume_step;
guint volume_max;
gchar *mixer_command;
+ gboolean enable_mpris;
gchar *mpris_players;
};
@@ -92,6 +100,7 @@ enum
PROP_VOLUME_STEP,
PROP_VOLUME_MAX,
PROP_MIXER_COMMAND,
+ PROP_ENABLE_MPRIS,
PROP_MPRIS_PLAYERS,
N_PROPERTIES,
};
@@ -166,6 +175,15 @@ pulseaudio_config_class_init (PulseaudioConfigClass *klass)
g_object_class_install_property (gobject_class,
+ PROP_ENABLE_MPRIS,
+ g_param_spec_boolean ("enable-mpris", NULL, NULL,
+ DEFAULT_ENABLE_MPRIS,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+
+
+
+ g_object_class_install_property (gobject_class,
PROP_MPRIS_PLAYERS,
g_param_spec_string ("mpris-players",
NULL, NULL,
@@ -194,6 +212,7 @@ pulseaudio_config_init (PulseaudioConfig *config)
config->volume_step = DEFAULT_VOLUME_STEP;
config->volume_max = DEFAULT_VOLUME_MAX;
config->mixer_command = g_strdup (DEFAULT_MIXER_COMMAND);
+ config->enable_mpris = DEFAULT_ENABLE_MPRIS;
config->mpris_players = g_strdup (DEFAULT_MPRIS_PLAYERS);
}
@@ -242,6 +261,10 @@ pulseaudio_config_get_property (GObject *object,
g_value_set_string (value, config->mixer_command);
break;
+ case PROP_ENABLE_MPRIS:
+ g_value_set_boolean (value, config->enable_mpris);
+ break;
+
case PROP_MPRIS_PLAYERS:
g_value_set_string (value, config->mpris_players);
break;
@@ -311,6 +334,16 @@ pulseaudio_config_set_property (GObject *object,
config->mixer_command = g_value_dup_string (value);
break;
+ case PROP_ENABLE_MPRIS:
+ val_bool = g_value_get_boolean (value);
+ if (config->enable_mpris != val_bool)
+ {
+ config->enable_mpris = val_bool;
+ g_object_notify (G_OBJECT (config), "enable-mpris");
+ g_signal_emit (G_OBJECT (config), pulseaudio_config_signals [CONFIGURATION_CHANGED], 0);
+ }
+ break;
+
case PROP_MPRIS_PLAYERS:
g_free (config->mpris_players);
config->mpris_players = g_value_dup_string (value);
@@ -382,6 +415,17 @@ pulseaudio_config_get_mixer_command (PulseaudioConfig *config)
+gboolean
+pulseaudio_config_get_enable_mpris (PulseaudioConfig *config)
+{
+ g_return_val_if_fail (IS_PULSEAUDIO_CONFIG (config), DEFAULT_ENABLE_MPRIS);
+
+ return config->enable_mpris;
+}
+
+
+
+
gchar **
pulseaudio_config_get_mpris_players (PulseaudioConfig *config)
{
@@ -493,6 +537,10 @@ pulseaudio_config_new (const gchar *property_base)
xfconf_g_property_bind (channel, property, G_TYPE_STRING, config, "mixer-command");
g_free (property);
+ property = g_strconcat (property_base, "/enable-mpris", NULL);
+ xfconf_g_property_bind (channel, property, G_TYPE_BOOLEAN, config, "enable-mpris");
+ g_free (property);
+
property = g_strconcat (property_base, "/mpris-players", NULL);
xfconf_g_property_bind (channel, property, G_TYPE_STRING, config, "mpris-players");
g_free (property);
diff --git a/panel-plugin/pulseaudio-config.h b/panel-plugin/pulseaudio-config.h
index cad1054..f79994c 100644
--- a/panel-plugin/pulseaudio-config.h
+++ b/panel-plugin/pulseaudio-config.h
@@ -45,6 +45,7 @@ guint pulseaudio_config_get_volume_max (PulseaudioC
const gchar *pulseaudio_config_get_mixer_command (PulseaudioConfig *config);
gchar **pulseaudio_config_get_mpris_players (PulseaudioConfig *config);
+gboolean pulseaudio_config_get_enable_mpris (PulseaudioConfig *config);
void pulseaudio_config_set_mpris_players (PulseaudioConfig *config,
gchar **players);
void pulseaudio_config_add_mpris_player (PulseaudioConfig *config,
diff --git a/panel-plugin/pulseaudio-dialog.c b/panel-plugin/pulseaudio-dialog.c
index 7ca3a86..2b920d1 100644
--- a/panel-plugin/pulseaudio-dialog.c
+++ b/panel-plugin/pulseaudio-dialog.c
@@ -207,6 +207,17 @@ pulseaudio_dialog_build (PulseaudioDialog *dialog)
g_signal_connect_swapped (G_OBJECT (object), "clicked",
G_CALLBACK (pulseaudio_dialog_run_mixer), dialog);
+#ifdef HAVE_MPRIS2
+ object = gtk_builder_get_object (builder, "checkbutton-mpris-support");
+ g_return_if_fail (GTK_IS_CHECK_BUTTON (object));
+ g_object_bind_property (G_OBJECT (dialog->config), "enable-mpris",
+ G_OBJECT (object), "active",
+ G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+#else
+ object = gtk_builder_get_object (builder, "media-player-frame");
+ gtk_widget_set_visible (GTK_WIDGET (object));
+#endif
+
}
else
{
diff --git a/panel-plugin/pulseaudio-dialog.glade b/panel-plugin/pulseaudio-dialog.glade
index 4c71f29..2fd244a 100644
--- a/panel-plugin/pulseaudio-dialog.glade
+++ b/panel-plugin/pulseaudio-dialog.glade
@@ -227,6 +227,48 @@
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkFrame" id="media-player-frame">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label_xalign">0</property>
+ <property name="shadow_type">none</property>
+ <child>
+ <object class="GtkAlignment" id="alignment3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="top_padding">6</property>
+ <property name="left_padding">12</property>
+ <property name="right_padding">12</property>
+ <child>
+ <object class="GtkCheckButton" id="checkbutton-mpris-support">
+ <property name="label" translatable="yes">Control playback of media players</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="halign">start</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="label">
+ <object class="GtkLabel" id="label4">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Media Players</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
diff --git a/panel-plugin/pulseaudio-menu.c b/panel-plugin/pulseaudio-menu.c
index d00f8cb..906e84b 100644
--- a/panel-plugin/pulseaudio-menu.c
+++ b/panel-plugin/pulseaudio-menu.c
@@ -473,64 +473,67 @@ pulseaudio_menu_new (PulseaudioVolume *volume,
/* MPRIS2 */
#ifdef HAVE_MPRIS2
- players = pulseaudio_config_get_mpris_players (menu->config);
- if (players != NULL)
+ if (pulseaudio_config_get_enable_mpris (menu->config))
{
- for (guint i = 0; i < g_strv_length (players); i++)
+ players = pulseaudio_config_get_mpris_players (menu->config);
+ if (players != NULL)
{
- mi = mpris_menu_item_new_from_player_name (players[i]);
- if (mi != NULL)
+ for (guint i = 0; i < g_strv_length (players); i++)
{
- if (pulseaudio_mpris_get_player_snapshot (menu->mpris,
- players[i],
- &title,
- &artist,
- &is_running,
- &is_playing,
- &is_stopped,
- &can_play,
- &can_pause,
- &can_go_previous,
- &can_go_next,
- &can_raise))
+ mi = mpris_menu_item_new_from_player_name (players[i]);
+ if (mi != NULL)
{
- mpris_menu_item_set_is_running (MPRIS_MENU_ITEM (mi), is_running);
- mpris_menu_item_set_title (MPRIS_MENU_ITEM (mi), title);
- mpris_menu_item_set_artist (MPRIS_MENU_ITEM (mi), artist);
-
- mpris_menu_item_set_can_raise (MPRIS_MENU_ITEM (mi), can_raise);
-
- mpris_menu_item_set_can_play (MPRIS_MENU_ITEM (mi), can_play);
- mpris_menu_item_set_can_pause (MPRIS_MENU_ITEM (mi), can_pause);
-
- mpris_menu_item_set_can_go_previous (MPRIS_MENU_ITEM (mi), can_go_previous);
- mpris_menu_item_set_can_go_next (MPRIS_MENU_ITEM (mi), can_go_next);
-
- mpris_menu_item_set_is_playing (MPRIS_MENU_ITEM (mi), is_playing);
- mpris_menu_item_set_is_stopped (MPRIS_MENU_ITEM (mi), is_stopped);
-
- if (title != NULL)
- g_free (title);
- if (artist != NULL)
- g_free (artist);
+ if (pulseaudio_mpris_get_player_snapshot (menu->mpris,
+ players[i],
+ &title,
+ &artist,
+ &is_running,
+ &is_playing,
+ &is_stopped,
+ &can_play,
+ &can_pause,
+ &can_go_previous,
+ &can_go_next,
+ &can_raise))
+ {
+ mpris_menu_item_set_is_running (MPRIS_MENU_ITEM (mi), is_running);
+ mpris_menu_item_set_title (MPRIS_MENU_ITEM (mi), title);
+ mpris_menu_item_set_artist (MPRIS_MENU_ITEM (mi), artist);
+
+ mpris_menu_item_set_can_raise (MPRIS_MENU_ITEM (mi), can_raise);
+
+ mpris_menu_item_set_can_play (MPRIS_MENU_ITEM (mi), can_play);
+ mpris_menu_item_set_can_pause (MPRIS_MENU_ITEM (mi), can_pause);
+
+ mpris_menu_item_set_can_go_previous (MPRIS_MENU_ITEM (mi), can_go_previous);
+ mpris_menu_item_set_can_go_next (MPRIS_MENU_ITEM (mi), can_go_next);
+
+ mpris_menu_item_set_is_playing (MPRIS_MENU_ITEM (mi), is_playing);
+ mpris_menu_item_set_is_stopped (MPRIS_MENU_ITEM (mi), is_stopped);
+
+ if (title != NULL)
+ g_free (title);
+ if (artist != NULL)
+ g_free (artist);
+ }
+ else
+ {
+ mpris_menu_item_set_is_running (MPRIS_MENU_ITEM (mi), FALSE);
+ mpris_menu_item_set_is_stopped (MPRIS_MENU_ITEM (mi), TRUE);
+ }
+
+ g_signal_connect (mi, "media-notify", G_CALLBACK (media_notify_cb), menu);
+ g_signal_connect (menu->mpris, "update", G_CALLBACK (mpris_update_cb), mi);
+ g_signal_connect (mi, "destroy", G_CALLBACK(item_destroy_cb), menu);
+
+ gtk_widget_show (mi);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+
+ /* separator */
+ mi = gtk_separator_menu_item_new ();
+ gtk_widget_show (mi);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
}
- else
- {
- mpris_menu_item_set_is_running (MPRIS_MENU_ITEM (mi), FALSE);
- mpris_menu_item_set_is_stopped (MPRIS_MENU_ITEM (mi), TRUE);
- }
-
- g_signal_connect (mi, "media-notify", G_CALLBACK (media_notify_cb), menu);
- g_signal_connect (menu->mpris, "update", G_CALLBACK (mpris_update_cb), mi);
- g_signal_connect (mi, "destroy", G_CALLBACK(item_destroy_cb), menu);
-
- gtk_widget_show (mi);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
-
- /* separator */
- mi = gtk_separator_menu_item_new ();
- gtk_widget_show (mi);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
}
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list