wmbattery: update upower support

* reuse dbus connection
* set delay to actually refresh values
This commit is contained in:
Ludwig Nussel 2015-01-17 08:41:13 -06:00 committed by Carlos R. Mafra
parent bdc9f33956
commit 9db8262d65
2 changed files with 4 additions and 7 deletions

View file

@ -9,7 +9,7 @@
#include <upower.h> #include <upower.h>
#include "apm.h" #include "apm.h"
int num_batteries = 0; static UpClient * up;
struct context { struct context {
int current; int current;
@ -54,7 +54,6 @@ static void get_devinfo(gpointer device, gpointer result)
int upower_supported(void) int upower_supported(void)
{ {
UpClient *up;
up = up_client_new(); up = up_client_new();
if (!up) { if (!up) {
@ -63,11 +62,9 @@ int upower_supported(void)
GPtrArray *devices = up_client_get_devices(up); GPtrArray *devices = up_client_get_devices(up);
if (!devices) { if (!devices) {
g_object_unref(up);
return 0; return 0;
} else { } else {
g_ptr_array_unref(devices); g_ptr_array_unref(devices);
g_object_unref(up);
return 1; return 1;
} }
} }
@ -76,7 +73,6 @@ int upower_supported(void)
/* Fill the passed apm_info struct. */ /* Fill the passed apm_info struct. */
int upower_read(int battery, apm_info *info) int upower_read(int battery, apm_info *info)
{ {
UpClient *up;
GPtrArray *devices = NULL; GPtrArray *devices = NULL;
up = up_client_new(); up = up_client_new();
@ -139,6 +135,5 @@ int upower_read(int battery, apm_info *info)
} }
g_ptr_array_free(devices, TRUE); g_ptr_array_free(devices, TRUE);
g_object_unref(up);
return 0; return 0;
} }

View file

@ -798,8 +798,10 @@ int main(int argc, char *argv[])
} }
#endif #endif
#ifdef UPOWER #ifdef UPOWER
else if (upower_supported()) else if (upower_supported()) {
use_upower = 1; use_upower = 1;
delay = 2;
}
#endif #endif
/* Check for ACPI support. */ /* Check for ACPI support. */
else if (acpi_supported() && acpi_batt_count > 0) { else if (acpi_supported() && acpi_batt_count > 0) {