systems that have neither those nor /usr/include/machine/apmvar.h. Mark as DESTDIR ready.
101 lines
3.4 KiB
Text
101 lines
3.4 KiB
Text
$NetBSD: patch-aa,v 1.8 2010/03/22 15:46:03 joerg Exp $
|
|
|
|
--- panel-plugin/battery.c.orig 2008-09-05 05:53:40.000000000 +0900
|
|
+++ panel-plugin/battery.c 2008-11-27 22:16:05.000000000 +0900
|
|
@@ -25,7 +25,7 @@
|
|
#include <config.h>
|
|
#endif
|
|
|
|
-#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
|
+#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
|
|
#include <machine/apm_bios.h>
|
|
#elif __OpenBSD__
|
|
#include <sys/param.h>
|
|
@@ -33,8 +33,18 @@
|
|
#elif __NetBSD__
|
|
#include <sys/param.h>
|
|
#include <sys/ioctl.h>
|
|
+#if defined(__sparc64__)
|
|
+/* On NetBSD/sparc64, apmvar.h is not exist in /usr/include/machine. */
|
|
+/* Reported in PR port-sparc64/36735. */
|
|
+#include <sparc/apmvar.h>
|
|
+#elif defined(__x86_64__)
|
|
+#include <dev/apm/apmbios.h>
|
|
+#include <dev/apm/apmio.h>
|
|
+#else
|
|
#include <machine/apmvar.h>
|
|
+#endif
|
|
#define APMDEVICE "/dev/apm"
|
|
+#define _ACPI_APM_BATT_UNKNOWN 0xffff /* from sys/dev/acpi/acpi_apm.c */
|
|
#elif __linux__
|
|
#include <libapm.h>
|
|
#endif
|
|
@@ -155,7 +165,7 @@
|
|
gboolean
|
|
detect_battery_info(t_battmon *battmon)
|
|
{
|
|
-#ifdef __FreeBSD__
|
|
+#if defined(__FreeBSD__) || defined(__DragonFly__)
|
|
/* This is how I read the information from the APM subsystem under
|
|
FreeBSD. Each time this functions is called (once every second)
|
|
the APM device is opened, read from and then closed.
|
|
@@ -209,7 +217,7 @@
|
|
battmon->method = BM_BROKEN;
|
|
fd = open(APMDEVICE, O_RDONLY);
|
|
if (fd == -1) return FALSE;
|
|
- + if (ioctl(fd, APM_IOC_GETPOWER, &apm) == -1) {
|
|
+ if (ioctl(fd, APM_IOC_GETPOWER, &apm) == -1) {
|
|
close(fd);
|
|
return FALSE;
|
|
}
|
|
@@ -302,13 +312,16 @@
|
|
battmon->method = BM_BROKEN;
|
|
fd = open(APMDEVICE, O_RDONLY);
|
|
if (fd == -1) return TRUE;
|
|
- if (ioctl(fd, APM_IOC_GETPOWER, &apminfo) == -1)
|
|
+ if (ioctl(fd, APM_IOC_GETPOWER, &apm) == -1)
|
|
return TRUE;
|
|
close(fd);
|
|
charge = apm.battery_life;
|
|
time_remaining = apm.minutes_left;
|
|
acline = apm.ac_state ? TRUE : FALSE;
|
|
|
|
+ if(battmon->timeoutid != 0) g_source_remove(battmon->timeoutid);
|
|
+ battmon->timeoutid = g_timeout_add(2 * 1024,
|
|
+ (GSourceFunc) update_apm_status, battmon);
|
|
#else
|
|
struct apm_info apm;
|
|
DBG ("Updating battery status...");
|
|
@@ -404,7 +417,7 @@
|
|
acline = apm.ac_line_status ? TRUE : FALSE;
|
|
|
|
}
|
|
-#elif __FreeBSD__
|
|
+#elif defined(__FreeBSD__) || defined(__DragonFly__)
|
|
else {
|
|
/* This is how I read the information from the APM subsystem under
|
|
FreeBSD. Each time this functions is called (once every second)
|
|
@@ -464,6 +475,11 @@
|
|
|
|
if(battmon->options.display_percentage && !(battmon->options.hide_when_full && acline && charge >= 99)){
|
|
gtk_widget_show((GtkWidget *)battmon->charge);
|
|
+#if defined(__NetBSD__) || defined(__OpenBSD__)
|
|
+ if (apm.battery_state == APM_BATT_ABSENT)
|
|
+ g_snprintf(buffer, sizeof(buffer),"--%% ");
|
|
+ else
|
|
+#endif
|
|
g_snprintf(buffer, sizeof(buffer),"%d%% ", charge);
|
|
gtk_label_set_text(battmon->charge,buffer);
|
|
} else {
|
|
@@ -481,6 +501,11 @@
|
|
}
|
|
|
|
gtk_widget_show((GtkWidget *)active_label);
|
|
+#if defined(__NetBSD__)
|
|
+ if (acline || time_remaining == _ACPI_APM_BATT_UNKNOWN)
|
|
+ g_snprintf(buffer, sizeof(buffer), "--:--");
|
|
+ else
|
|
+#endif
|
|
g_snprintf(buffer, sizeof(buffer),"%02d:%02d ",time_remaining/60,time_remaining%60);
|
|
gtk_label_set_text(active_label,buffer);
|
|
|