[Xfce4-commits] [xfce/xfce4-power-manager] 01/01: Show inhibitors in the plugin menu (Bug #9090)

noreply at xfce.org noreply at xfce.org
Fri Feb 26 16:53:58 CET 2016


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository xfce/xfce4-power-manager.

commit 292d4c90535d54647c8759476d791fab4977ff41
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Fri Feb 26 18:53:15 2016 +0300

    Show inhibitors in the plugin menu (Bug #9090)
    
    This patch now displays the applications that are inhibiting xfpm
    from doing power management in the plugin/systray menu.
---
 .../power-manager-plugin/power-manager-button.c    | 99 ++++++++++++++++++++++
 src/xfpm-inhibit.c                                 | 16 +++-
 src/xfpm-inhibit.h                                 |  5 +-
 3 files changed, 118 insertions(+), 2 deletions(-)

diff --git a/panel-plugins/power-manager-plugin/power-manager-button.c b/panel-plugins/power-manager-plugin/power-manager-button.c
index 5135ba4..4fea515 100644
--- a/panel-plugins/power-manager-plugin/power-manager-button.c
+++ b/panel-plugins/power-manager-plugin/power-manager-button.c
@@ -61,6 +61,8 @@ struct PowerManagerButtonPrivate
 
     UpClient        *upower;
 
+    GDBusProxy      *inhibit_proxy;
+
     /* A list of BatteryDevices  */
     GList           *devices;
 
@@ -936,6 +938,23 @@ power_manager_button_init (PowerManagerButton *button)
         button->priv->channel = xfconf_channel_get ("xfce4-power-manager");
     }
 
+    button->priv->inhibit_proxy = g_dbus_proxy_new_sync (g_bus_get_sync (G_BUS_TYPE_SESSION,
+                                                                         NULL,
+                                                                         NULL),
+                                                         G_DBUS_PROXY_FLAGS_NONE,
+                                                         NULL,
+                                                         "org.freedesktop.PowerManagement",
+                                                         "/org/freedesktop/PowerManagement/Inhibit",
+                                                         "org.freedesktop.PowerManagement.Inhibit",
+                                                         NULL,
+                                                         &error);
+
+    if (error != NULL)
+    {
+        g_warning ("error getting inhibit proxy: %s", error->message);
+        g_clear_error (&error);
+    }
+
     /* Sane defaults for the systray and panel icon */
 #ifdef XFCE_PLUGIN
     button->priv->panel_icon_name = g_strdup (PANEL_DEFAULT_ICON_SYMBOLIC);
@@ -1303,6 +1322,83 @@ G_GNUC_END_IGNORE_DEPRECATIONS
 }
 
 static void
+display_inhibitors (PowerManagerButton *button, GtkWidget *menu)
+{
+    gboolean needs_seperator = FALSE;
+
+    g_return_if_fail (POWER_MANAGER_IS_BUTTON (button));
+    g_return_if_fail (GTK_IS_MENU (menu));
+
+    if (button->priv->inhibit_proxy)
+    {
+        GVariant *reply;
+        GError   *error = NULL;
+
+        reply = g_dbus_proxy_call_sync (button->priv->inhibit_proxy,
+                                        "GetInhibitors",
+                                        g_variant_new ("()"),
+                                        G_DBUS_CALL_FLAGS_NONE,
+                                        1000,
+                                        NULL,
+                                        &error);
+
+        if (reply != NULL)
+        {
+            GVariantIter *iter;
+            gchar        *value;
+            GtkWidget    *inhibit_mi;
+
+            g_variant_get (reply, "(as)", &iter);
+
+            if (g_variant_iter_n_children (iter) > 0)
+            {
+                needs_seperator = TRUE;
+            }
+
+            /* Add the list of programs to the menu */
+            while (g_variant_iter_next (iter, "s", &value))
+            {
+                GtkWidget *mi, *img;
+
+                /* Translators this is to display which app is inhibiting
+                 * power in the plugin menu. Example:
+                 * VLC is currently inhibiting power management
+                 */
+                gchar *label = g_strdup_printf (_("%s is currently inhibiting power management"), value);
+
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+                mi = gtk_image_menu_item_new_with_label(label);
+G_GNUC_END_IGNORE_DEPRECATIONS
+                /* add the image */
+                img = gtk_image_new_from_icon_name ("gtk-info", GTK_ICON_SIZE_MENU);
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+                gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), img);
+G_GNUC_END_IGNORE_DEPRECATIONS
+
+                gtk_widget_set_can_focus (mi, FALSE);
+                gtk_widget_show (mi);
+                gtk_menu_shell_append (GTK_MENU_SHELL(button->priv->menu), mi);
+                g_free (label);
+            }
+            g_variant_iter_free (iter);
+            g_variant_unref (reply);
+
+        } else {
+            g_warning ("failed calling GetInhibitors: %s", error->message);
+            g_clear_error (&error);
+        }
+
+        if (needs_seperator)
+        {
+            /* add a separator */
+            GtkWidget * separator_mi = gtk_separator_menu_item_new ();
+            gtk_widget_show (separator_mi);
+            gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator_mi);
+        }
+
+    }
+}
+static void
 decrease_brightness (PowerManagerButton *button)
 {
     gint32 level;
@@ -1492,6 +1588,9 @@ G_GNUC_END_IGNORE_DEPRECATIONS
                            PROPERTIES_PREFIX PRESENTATION_MODE,
                            G_TYPE_BOOLEAN, G_OBJECT(mi), "active");
 
+    /* Show any applications currently inhibiting now */
+    display_inhibitors (button, menu);
+
     /* Power manager settings */
     mi = gtk_menu_item_new_with_mnemonic (_("_Power manager settings..."));
     gtk_widget_show (mi);
diff --git a/src/xfpm-inhibit.c b/src/xfpm-inhibit.c
index b844041..a4ef386 100644
--- a/src/xfpm-inhibit.c
+++ b/src/xfpm-inhibit.c
@@ -65,6 +65,7 @@ typedef struct
 enum
 {
     HAS_INHIBIT_CHANGED,
+    INHIBIT_LIST_CHANGED,
     LAST_SIGNAL
 };
 
@@ -99,7 +100,11 @@ xfpm_inhibit_has_inhibit_changed (XfpmInhibit *inhibit)
 	inhibit->priv->inhibited = TRUE;
 	g_signal_emit (G_OBJECT(inhibit), signals[HAS_INHIBIT_CHANGED], 0, inhibit->priv->inhibited);
     }
-    
+
+    /* Always emite the INHIBIT_LIST_CHANGED for any change so the panel plugin
+     * stays in sync */
+    g_signal_emit (G_OBJECT(inhibit), signals[INHIBIT_LIST_CHANGED], 0, inhibit->priv->inhibited);
+
     return inhibit->priv->inhibited;
 }
 
@@ -218,6 +223,15 @@ xfpm_inhibit_class_init(XfpmInhibitClass *klass)
 			 g_cclosure_marshal_VOID__BOOLEAN,
 			 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
 
+    signals[INHIBIT_LIST_CHANGED] =
+	    g_signal_new ("inhibitors-list-changed",
+			 XFPM_TYPE_INHIBIT,
+			 G_SIGNAL_RUN_LAST,
+			 G_STRUCT_OFFSET(XfpmInhibitClass, inhibitors_list_changed),
+			 NULL, NULL,
+			 g_cclosure_marshal_VOID__BOOLEAN,
+			 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+
     object_class->finalize = xfpm_inhibit_finalize;
 
     g_type_class_add_private (klass, sizeof (XfpmInhibitPrivate));
diff --git a/src/xfpm-inhibit.h b/src/xfpm-inhibit.h
index 5b66fc0..7ad5f9e 100644
--- a/src/xfpm-inhibit.h
+++ b/src/xfpm-inhibit.h
@@ -41,9 +41,12 @@ typedef struct
 typedef struct
 {
     GObjectClass 	  parent_class;
-    
+
+    /* signals */
     void                  (*has_inhibit_changed)       (XfpmInhibit *inhibit,
 							gboolean is_inhibit);
+    void                  (*inhibitors_list_changed)   (XfpmInhibit *inhibit,
+							gboolean is_inhibit);
     
 } XfpmInhibitClass;
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list