diff options
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | applets/Makefile.am | 2 | ||||
-rw-r--r-- | applets/battery/Makefile.am | 11 | ||||
-rw-r--r-- | applets/battery/battery-acpi.c | 87 | ||||
-rw-r--r-- | applets/battery/battery-apm.c | 62 | ||||
-rw-r--r-- | applets/battery/battery.c | 55 | ||||
-rw-r--r-- | applets/battery/battery.h | 17 | ||||
-rw-r--r-- | configure.ac | 25 |
8 files changed, 218 insertions, 51 deletions
@@ -1,3 +1,13 @@ +2008-09-30 Samuel Ortiz <sameo@linux.intel.com> + * configure.ac + * applets/Makefile.am + * applets/battery/battery.h + * applets/battery/battery-acpi.c + * applets/battery/battery-apm.c + * applets/battery/Makefile.am + * applets/battery/battery.c + Switch between ACPI and APM at configuration time. Default is APM. + 2008-09-25 Ross Burton <ross@linux.intel.com> * matchbox-panel/mb-panel.c: diff --git a/applets/Makefile.am b/applets/Makefile.am index aae9972..6a0fd21 100644 --- a/applets/Makefile.am +++ b/applets/Makefile.am @@ -1,6 +1,6 @@ SUBDIRS = brightness clock launcher notify systray showdesktop windowselector -if HAVE_LIBAPM +if HAVE_BATTERY SUBDIRS += battery endif diff --git a/applets/battery/Makefile.am b/applets/battery/Makefile.am index 20e2625..d6faab5 100644 --- a/applets/battery/Makefile.am +++ b/applets/battery/Makefile.am @@ -7,8 +7,17 @@ AM_CFLAGS = -Wall -g $(MATCHBOX_PANEL_CFLAGS) \ appletdir = $(pkglibdir) applet_LTLIBRARIES = libbattery.la -libbattery_la_SOURCES = battery.c +libbattery_la_SOURCES = battery.c battery.h + +if HAVE_LIBAPM libbattery_la_LIBADD = -lapm +libbattery_la_SOURCES += battery-apm.c +endif + +if HAVE_LIBACPI +libbattery_la_LIBADD = -lacpi +libbattery_la_SOURCES += battery-acpi.c +endif libbattery_la_LDFLAGS = -avoid-version MAINTAINERCLEANFILES = Makefile.in diff --git a/applets/battery/battery-acpi.c b/applets/battery/battery-acpi.c new file mode 100644 index 0000000..6515cb0 --- /dev/null +++ b/applets/battery/battery-acpi.c @@ -0,0 +1,87 @@ +/* + * (C) 2008 Intel. + * + * Licensed under the GPL v2 or greater. + */ + +#include "battery.h" +#include <libacpi.h> + +global_t global; +adapter_t *ac; +int batt_state, ac_state; + +int pm_support(void) +{ + if(check_acpi_support() == NOT_SUPPORTED){ + g_warning("No ACPI support\n"); + + return 0; + } + + ac = &global.adapt; + + batt_state = init_acpi_batt(&global); + ac_state = init_acpi_acadapt(&global); + + return 1; +} + +const char* pm_battery_icon(void) +{ + const char *icon; + battery_t *binfo; + + if (batt_state != SUCCESS) { + g_warning("Couldnt initialize ACPI battery\n"); + return NULL; + } + + read_acpi_batt(0); + read_acpi_acstate(&global); + + binfo = &batteries[0]; + + if (binfo->batt_state == B_ERR) { + g_warning("Couldn't read battery state\n"); + return NULL; + } + + if (!binfo->present) { + /* Battery is removed */ + icon = "ac-adapter.png"; + return icon; + } + + if(ac_state == SUCCESS && ac->ac_state == P_AC) { + /* We're charging */ + if (binfo->percentage < 10) + icon = "battery-charging-000.png"; + else if (binfo->percentage < 30) + icon = "battery-charging-020.png"; + else if (binfo->percentage < 50) + icon = "battery-charging-040.png"; + else if (binfo->percentage < 70) + icon = "battery-charging-060.png"; + else if (binfo->percentage < 90) + icon = "battery-charging-080.png"; + else + icon = "battery-charging-100.png"; + + } else { + if (binfo->percentage < 10) + icon = "battery-discharging-000.png"; + else if (binfo->percentage < 30) + icon = "battery-discharging-020.png"; + else if (binfo->percentage < 50) + icon = "battery-discharging-040.png"; + else if (binfo->percentage < 70) + icon = "battery-discharging-060.png"; + else if (binfo->percentage < 90) + icon = "battery-discharging-080.png"; + else + icon = "battery-discharging-100.png"; + } + + return icon; +} diff --git a/applets/battery/battery-apm.c b/applets/battery/battery-apm.c new file mode 100644 index 0000000..5467438 --- /dev/null +++ b/applets/battery/battery-apm.c @@ -0,0 +1,62 @@ +/* + * (C) 2008 Intel. + * + * Licensed under the GPL v2 or greater. + */ + +#include "battery.h" +#include <apm.h> + +int pm_support(void) +{ + if (1 == apm_exists ()) { + g_warning ("No APM support"); + + return 0; + } + + return 1; +} + +const char* pm_battery_icon(void) +{ + apm_info info; + const char *icon; + + memset (&info, 0, sizeof (apm_info)); + apm_read (&info); + + if (info.battery_status == BATTERY_STATUS_ABSENT) + icon = "ac-adapter.png"; + else { + if (info.ac_line_status == AC_LINE_STATUS_ON) { + if (info.battery_percentage < 10) + icon = "battery-charging-000.png"; + else if (info.battery_percentage < 30) + icon = "battery-charging-020.png"; + else if (info.battery_percentage < 50) + icon = "battery-charging-040.png"; + else if (info.battery_percentage < 70) + icon = "battery-charging-060.png"; + else if (info.battery_percentage < 90) + icon = "battery-charging-080.png"; + else + icon = "battery-charging-100.png"; + } else { + if (info.battery_percentage < 10) + icon = "battery-discharging-000.png"; + else if (info.battery_percentage < 30) + icon = "battery-discharging-020.png"; + else if (info.battery_percentage < 50) + icon = "battery-discharging-040.png"; + else if (info.battery_percentage < 70) + icon = "battery-discharging-060.png"; + else if (info.battery_percentage < 90) + icon = "battery-discharging-080.png"; + else + icon = "battery-discharging-100.png"; + } + } + + return icon; +} diff --git a/applets/battery/battery.c b/applets/battery/battery.c index 93ae126..41db42d 100644 --- a/applets/battery/battery.c +++ b/applets/battery/battery.c @@ -6,10 +6,7 @@ * Licensed under the GPL v2 or greater. */ -#include <string.h> -#include <apm.h> -#include <matchbox-panel/mb-panel.h> -#include <matchbox-panel/mb-panel-scaling-image.h> +#include "battery.h" typedef struct { MBPanelScalingImage *image; @@ -31,43 +28,12 @@ battery_applet_free (BatteryApplet *applet) static gboolean timeout (BatteryApplet *applet) { - apm_info info; - const char *icon; - - memset (&info, 0, sizeof (apm_info)); - apm_read (&info); - - if (info.battery_status == BATTERY_STATUS_ABSENT) - icon = "ac-adapter.png"; - else { - if (info.ac_line_status == AC_LINE_STATUS_ON) { - if (info.battery_percentage < 10) - icon = "battery-charging-000.png"; - else if (info.battery_percentage < 30) - icon = "battery-charging-020.png"; - else if (info.battery_percentage < 50) - icon = "battery-charging-040.png"; - else if (info.battery_percentage < 70) - icon = "battery-charging-060.png"; - else if (info.battery_percentage < 90) - icon = "battery-charging-080.png"; - else - icon = "battery-charging-100.png"; - } else { - if (info.battery_percentage < 10) - icon = "battery-discharging-000.png"; - else if (info.battery_percentage < 30) - icon = "battery-discharging-020.png"; - else if (info.battery_percentage < 50) - icon = "battery-discharging-040.png"; - else if (info.battery_percentage < 70) - icon = "battery-discharging-060.png"; - else if (info.battery_percentage < 90) - icon = "battery-discharging-080.png"; - else - icon = "battery-discharging-100.png"; - } - } + const char *icon; + + icon = pm_battery_icon(); + + if (!icon) + return FALSE; /* Don't recreate pixbuf if we will display the same image */ if (icon == applet->last_icon) @@ -89,12 +55,9 @@ mb_panel_applet_create (const char *id, BatteryApplet *applet; GtkWidget *image; - /* Check that we have APM support */ - if (1 == apm_exists ()) { - g_warning ("No APM support"); - + /* Check that we have PM support */ + if (!pm_support()) return NULL; - } /* Create applet data structure */ applet = g_slice_new (BatteryApplet); diff --git a/applets/battery/battery.h b/applets/battery/battery.h new file mode 100644 index 0000000..29a44ca --- /dev/null +++ b/applets/battery/battery.h @@ -0,0 +1,17 @@ +/* + * (C) 2008 Intel. + * + * Licensed under the GPL v2 or greater. + */ + +#ifndef MB_APPLET_BATTERY_H +#define MB_APPLET_BATTERY_H + +#include <string.h> +#include <matchbox-panel/mb-panel.h> +#include <matchbox-panel/mb-panel-scaling-image.h> + +int pm_support(void); +const char* pm_battery_icon(void); + +#endif diff --git a/configure.ac b/configure.ac index 03cc81c..79104d4 100644 --- a/configure.ac +++ b/configure.ac @@ -43,10 +43,29 @@ if test x$enable_dbus != xno; then fi AM_CONDITIONAL(HAVE_DBUS, test x$enable_dbus = xyes) -# apm -AC_CHECK_HEADERS(apm.h, enable_linux_apm=yes, enable_linux_apm=no) -AM_CONDITIONAL(HAVE_LIBAPM, test x$enable_linux_apm = xyes) +# Where to read battery state from +AC_ARG_WITH( + [battery], + AS_HELP_STRING([--with-battery], [where to read the battery state from]), + [], + [with_battery="apm"] +) + +case "$with_battery" in + "acpi") AC_CHECK_HEADERS(libacpi.h, enable_linux_acpi=yes, AC_MSG_FAILURE([You need to install libacpi])) + enable_battery=yes + ;; + ""|"apm") AC_CHECK_HEADERS(apm.h, enable_linux_apm=yes, AC_MSG_FAILURE([You need to install apmd])) + enable_battery=yes + ;; + "none"|*) enable_battery=no + ;; +esac + +AM_CONDITIONAL(HAVE_BATTERY, test x$enable_battery = xyes) +AM_CONDITIONAL(HAVE_LIBAPM, test x$enable_linux_apm = xyes) +AM_CONDITIONAL(HAVE_LIBACPI, test x$enable_linux_acpi = xyes) # glib-genmarshal GLIB_GENMARSHAL=`$PKG_CONFIG --variable=glib_genmarshal glib-2.0` |