[gnome-settings-daemon] media-keys: Fix battery key handling



commit 79ce8533b0b7d406744fc5b1732fcc67ebc74b4f
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Dec 9 16:00:03 2013 +0100

    media-keys: Fix battery key handling
    
    Since commit 5bbe63ff22, the power plugin DBus interface doesn't have the
    properties that media-keys plugin expects here. So keep an UPower display
    device to fetch icon/percentage for the OSD.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=720198

 configure.ac                                |    2 +-
 plugins/media-keys/gsd-media-keys-manager.c |   34 ++++++++++++++++++--------
 2 files changed, 24 insertions(+), 12 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a907591..f33e1e1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -205,7 +205,7 @@ dnl ---------------------------------------------------------------------------
 dnl - media-keys plugin stuff
 dnl ---------------------------------------------------------------------------
 
-PKG_CHECK_MODULES(MEDIA_KEYS, [gio-unix-2.0 libpulse >= $PA_REQUIRED_VERSION $GUDEV_PKG 
libpulse-mainloop-glib >= $PA_REQUIRED_VERSION libcanberra-gtk3])
+PKG_CHECK_MODULES(MEDIA_KEYS, [gio-unix-2.0 libpulse >= $PA_REQUIRED_VERSION $GUDEV_PKG 
libpulse-mainloop-glib >= $PA_REQUIRED_VERSION libcanberra-gtk3 upower-glib >= $UPOWER_REQUIRED_VERSION])
 PKG_CHECK_MODULES(GVC, [gobject-2.0 libpulse >= $PA_REQUIRED_VERSION libpulse-mainloop-glib >= 
$PA_REQUIRED_VERSION])
 AM_CONDITIONAL(HAVE_INTROSPECTION, false)
 
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index 98b10a1..ee38adc 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -40,6 +40,8 @@
 #include <gio/gdesktopappinfo.h>
 #include <gio/gunixfdlist.h>
 
+#include <libupower-glib/upower.h>
+
 #ifdef HAVE_GUDEV
 #include <gudev/gudev.h>
 #endif
@@ -161,6 +163,7 @@ struct GsdMediaKeysManagerPrivate
         GDBusProxy      *power_proxy;
         GDBusProxy      *power_screen_proxy;
         GDBusProxy      *power_keyboard_proxy;
+        UpDevice        *composite_device;
 
         /* Shell stuff */
         GsdShell        *shell_proxy;
@@ -1920,21 +1923,24 @@ do_brightness_action (GsdMediaKeysManager *manager,
 static void
 do_battery_action (GsdMediaKeysManager *manager)
 {
-        GVariant *icon_var, *percentage;
-        char *label = NULL;
+        gdouble percentage;
+        UpDeviceKind kind;
+        gchar *icon_name;
 
-        if (manager->priv->power_proxy == NULL)
-                return;
+        g_return_if_fail (manager->priv->composite_device != NULL);
 
-        icon_var = g_dbus_proxy_get_cached_property (manager->priv->power_proxy, "Icon");
-        percentage = g_dbus_proxy_get_cached_property (manager->priv->power_proxy, "Percentage");
+        g_object_get (manager->priv->composite_device,
+                      "kind", &kind,
+                      "icon-name", &icon_name,
+                      "percentage", &percentage,
+                      NULL);
 
-        if (g_variant_get_double (percentage) >= 0.0)
-                label = g_strdup_printf ("%d %%", (int) g_variant_get_double (percentage));
+        if (kind == UP_DEVICE_KIND_UPS || kind == UP_DEVICE_KIND_BATTERY) {
+                g_debug ("showing battery level OSD");
+                show_osd (manager, icon_name, NULL, percentage);
+        }
 
-        show_osd (manager, g_variant_get_string (icon_var, NULL),
-                  label, g_variant_get_double (percentage));
-        g_free (label);
+        g_free (icon_name);
 }
 
 static void
@@ -2439,6 +2445,7 @@ gsd_media_keys_manager_stop (GsdMediaKeysManager *manager)
         g_clear_object (&priv->power_proxy);
         g_clear_object (&priv->power_screen_proxy);
         g_clear_object (&priv->power_keyboard_proxy);
+        g_clear_object (&priv->composite_device);
         g_clear_object (&priv->mpris_controller);
         g_clear_object (&priv->screencast_proxy);
 
@@ -2662,6 +2669,7 @@ on_bus_gotten (GObject             *source_object,
 {
         GDBusConnection *connection;
         GError *error = NULL;
+        UpClient *up_client;
 
         if (manager->priv->bus_cancellable == NULL ||
             g_cancellable_is_cancelled (manager->priv->bus_cancellable)) {
@@ -2724,6 +2732,10 @@ on_bus_gotten (GObject             *source_object,
                           NULL,
                           (GAsyncReadyCallback) power_keyboard_ready_cb,
                           manager);
+
+        up_client = up_client_new ();
+        manager->priv->composite_device = up_client_get_display_device (up_client);
+        g_object_unref (up_client);
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]