diff --git a/src/org.freedesktop.UPower.xml b/src/org.freedesktop.UPower.xml index f972c1c..558d0e9 100644 --- a/src/org.freedesktop.UPower.xml +++ b/src/org.freedesktop.UPower.xml @@ -51,6 +51,52 @@ method return sender=:1.386 -> dest=:1.451 reply_serial=2 + + + + An object path for the "display device. + + + + + + Get the object to the "display device", a composite device that represents the + status icon to show in desktop environments. The following standard org.freedesktop.UPower.Device + properties will be defined (only IsPresent takes a special meaning): + + + Typethe type of the display device, UPS or Battery. Note that this value can change, as opposed to real devices. + + + Statethe power state of the display device, such as Charging or Discharging. + + + Percentagethe amount of energy left on the device. + + + EnergyAmount of energy (measured in Wh) currently available in the power source. + + + EnergyFullAmount of energy (measured in Wh) in the power source when it's considered full. + + + EnergyRateAmount of energy being drained from the source, measured in W. If positive, the source is being discharged, if negative it's being charged. + + + TimeToEmptyNumber of seconds until the power source is considered empty. + + + TimeToFullNumber of seconds until the power source is considered full. + + + IsPresentWhether a status icon using this information should be presented. + + + + + + + diff --git a/src/up-daemon.c b/src/up-daemon.c index ff173c5..c8da84c 100644 --- a/src/up-daemon.c +++ b/src/up-daemon.c @@ -89,6 +89,7 @@ struct UpDaemonPrivate guint props_idle_id; /* Display battery properties */ + UpDevice *display_device; UpDeviceKind kind; UpDeviceState state; gdouble percentage; @@ -199,6 +200,7 @@ up_daemon_update_display_battery (UpDaemon *daemon) gdouble energy_rate_total = 0.0; gint64 time_to_empty_total = 0; gint64 time_to_full_total = 0; + gboolean is_present_total = FALSE; guint num_batteries = 0; /* Gather state from each device */ @@ -239,6 +241,7 @@ up_daemon_update_display_battery (UpDaemon *daemon) time_to_empty_total = time_to_empty; time_to_full_total = time_to_full; percentage_total = percentage; + is_present_total = TRUE; break; } if (kind != UP_DEVICE_KIND_BATTERY) @@ -259,6 +262,7 @@ up_daemon_update_display_battery (UpDaemon *daemon) /* sum up composite */ kind_total = UP_DEVICE_KIND_BATTERY; + is_present_total = TRUE; energy_total += energy; energy_full_total += energy_full; energy_rate_total += energy_rate; @@ -298,6 +302,19 @@ out: daemon->priv->percentage = percentage_total; + g_object_set (daemon->priv->display_device, + "type", kind_total, + "state", state_total, + "energy", energy_total, + "energy-full", energy_full_total, + "energy-rate", energy_rate_total, + "time-to-empty", time_to_empty_total, + "time-to-full", time_to_full_total, + "percentage", percentage_total, + "is-present", is_present_total, + "power-supply", TRUE, + NULL); + /* FIXME: Return whether the above actually changed significantly */ return TRUE; } @@ -411,6 +428,17 @@ up_daemon_enumerate_devices (UpDaemon *daemon, DBusGMethodInvocation *context) return TRUE; } +/** + * up_daemon_get_display_device: + **/ +gboolean +up_daemon_get_display_device (UpDaemon *daemon, + DBusGMethodInvocation *context) +{ + dbus_g_method_return (context, up_device_get_object_path (daemon->priv->display_device)); + return TRUE; +} + /** * up_daemon_register_power_daemon: **/ @@ -430,6 +458,10 @@ up_daemon_register_power_daemon (UpDaemon *daemon) goto out; } + /* Register the display device */ + up_device_register_display_device (daemon->priv->display_device, + daemon); + /* connect to DBUS */ priv->proxy = dbus_g_proxy_new_for_name (priv->connection, DBUS_SERVICE_DBUS, @@ -1002,6 +1034,7 @@ up_daemon_init (UpDaemon *daemon) daemon->priv->polkit = up_polkit_new (); daemon->priv->config = up_config_new (); daemon->priv->power_devices = up_device_list_new (); + daemon->priv->display_device = up_device_new (); daemon->priv->use_percentage_for_policy = up_config_get_boolean (daemon->priv->config, "UsePercentageForPolicy"); load_percentage_policy (daemon, FALSE); diff --git a/src/up-daemon.h b/src/up-daemon.h index 6e5d8a7..43b534b 100644 --- a/src/up-daemon.h +++ b/src/up-daemon.h @@ -97,6 +97,8 @@ void up_daemon_emit_properties_changed (DBusGConnection *gconnection, /* exported */ gboolean up_daemon_enumerate_devices (UpDaemon *daemon, DBusGMethodInvocation *context); +gboolean up_daemon_get_display_device (UpDaemon *daemon, + DBusGMethodInvocation *context); G_END_DECLS diff --git a/src/up-device.c b/src/up-device.c index bfb9a2b..d2cae1e 100644 --- a/src/up-device.c +++ b/src/up-device.c @@ -717,6 +717,22 @@ out: return ret; } +/** + * up_device_register_display_device: + **/ +gboolean +up_device_register_display_device (UpDevice *device, + UpDaemon *daemon) +{ + g_return_val_if_fail (UP_IS_DEVICE (device), FALSE); + + device->priv->daemon = g_object_ref (daemon); + device->priv->object_path = g_build_filename (UP_DEVICES_DBUS_PATH, "DisplayDevice", NULL); + dbus_g_connection_register_g_object (device->priv->system_bus_connection, + device->priv->object_path, G_OBJECT (device)); + return TRUE; +} + /** * up_device_get_statistics: **/ diff --git a/src/up-device.h b/src/up-device.h index d4ba16b..34acf8c 100644 --- a/src/up-device.h +++ b/src/up-device.h @@ -76,6 +76,8 @@ UpDevice *up_device_new (void); gboolean up_device_coldplug (UpDevice *device, UpDaemon *daemon, GObject *native); +gboolean up_device_register_display_device (UpDevice *device, + UpDaemon *daemon); UpDaemon *up_device_get_daemon (UpDevice *device); GObject *up_device_get_native (UpDevice *device); const gchar *up_device_get_object_path (UpDevice *device);