|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
[PATCH] NetBSD support for xfce4-battery-pluginHello,
I've switched my notebook to NetBSD, and when I found out that the XFCE battery plugin had no support for NetBSD, I decided to add support myself. The attached patch makes it work with APM on NetBSD. In fact things work very similar to OpenBSD, so the patch is quite small. The only problem that I've found so far is that the panel crashes if I tick "Display power" in the configuration dialogue. I don't really understand why that tickbox exists if the plugin is running in APM mode, since the code that runs when the display_power flag is set seems to be interested only in things like fan speed and temperature. Which I always thought were ACPI-only features. Somebody else with more knowledge of the code should take a look at this. I don't know if the same crash occurs on OpenBSD, too... thanks, -- stefan http://stsp.in-berlin.de PGP Key: 0xF59D25F0 diff -urN xfce4-battery-plugin-0.3.0.orig/panel-plugin/battmon.c xfce4-battery-plugin-0.3.0/panel-plugin/battmon.c --- xfce4-battery-plugin-0.3.0.orig/panel-plugin/battmon.c 2005-08-06 11:30:51.000000000 +0200 +++ xfce4-battery-plugin-0.3.0/panel-plugin/battmon.c 2006-03-20 17:41:18.000000000 +0100 @@ -37,6 +37,11 @@ #elif __OpenBSD__ #include <sys/param.h> #include <machine/apmvar.h> +#elif __NetBSD__ +#include <sys/param.h> +#include <sys/ioctl.h> +#include <machine/apmvar.h> +#define APMDEVICE "/dev/apm" #elif __linux__ #include <apm.h> #endif @@ -152,12 +157,6 @@ gboolean detect_battery_info(t_battmon *battmon) { -#ifdef __OpenBSD__ - struct apm_power_info apm; -#else - struct apm_info apm; -#endif - #ifdef __FreeBSD__ /* This is how I read the information from the APM subsystem under FreeBSD. Each time this functions is called (once every second) @@ -166,7 +165,7 @@ except that is does not work on FreeBSD */ - + struct apm_info apm; int fd; /* First check to see if ACPI is available */ @@ -193,27 +192,32 @@ fd = open(APMDEVICE, O_RDONLY); if (fd == -1) return FALSE; - if (ioctl(fd, APMIO_GETINFO, &apm) == -1) + if (ioctl(fd, APMIO_GETINFO, &apm) == -1) { + close(fd); return FALSE; - + } close(fd); battmon->method = BM_USE_APM; #endif return TRUE; -#elif __OpenBSD__ +#elif defined(__OpenBSD__) || defined(__NetBSD__) /* Code for OpenBSD by Joe Ammond <jra@...>. Using the same procedure as for FreeBSD. + Made to work on NetBSD by Stefan Sperling <stsp@...> */ + struct apm_power_info apm; int fd; 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; + } close(fd); battmon->method = BM_USE_APM; - + return TRUE; #elif __linux__ /* First check to see if ACPI is available */ @@ -250,11 +254,6 @@ static gboolean update_apm_status(t_battmon *battmon) { -#ifdef __OpenBSD__ - struct apm_power_info apm; -#else - struct apm_info apm; -#endif int charge=0; gboolean fan=FALSE; const char *temp; @@ -262,24 +261,27 @@ gboolean acline; gchar buffer[128]; - -#ifdef __OpenBSD__ +#if defined(__OpenBSD__) || defined(__NetBSD__) /* Code for OpenBSD by Joe Ammond <jra@...>. Using the same procedure as for FreeBSD. + Made to work on NetBSD by Stefan Sperling <stsp@...> */ + struct apm_power_info apm; int fd; 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) { + close(fd); return TRUE; - close(fd); + } + close(fd); charge = apm.battery_life; time_remaining = apm.minutes_left; acline = apm.ac_state ? TRUE : FALSE; - #else + struct apm_info apm; #ifdef DEBUG printf("updating battery status...\n"); #endif @@ -347,9 +349,10 @@ fd = open(APMDEVICE, O_RDONLY); if (fd == -1) return TRUE; - if (ioctl(fd, APMIO_GETINFO, &apm) == -1) - return TRUE; - + if (ioctl(fd, APMIO_GETINFO, &apm) == -1) { + close(fd); + return TRUE; + } close(fd); acline = apm.ai_acline ? TRUE : FALSE; diff -urN xfce4-battery-plugin-0.3.0.orig/panel-plugin/libacpi.c xfce4-battery-plugin-0.3.0/panel-plugin/libacpi.c --- xfce4-battery-plugin-0.3.0.orig/panel-plugin/libacpi.c 2003-09-09 15:49:16.000000000 +0200 +++ xfce4-battery-plugin-0.3.0/panel-plugin/libacpi.c 2006-03-20 17:25:30.000000000 +0100 @@ -42,6 +42,14 @@ #include <dirent.h> #if HAVE_SYSCTL + +#ifdef __NetBSD__ +#include <sys/param.h> +/* CTLTYPE does not exist in NetBSD headers. + * Defining it to 0x0f here won't do any harm though. */ +#define CTLTYPE 0x0f +#endif + #include <sys/sysctl.h> #include <err.h> #include <errno.h> |
|
|
Re: [PATCH] NetBSD support for xfce4-battery-pluginProbably the fastest replay you've ever had ;-). Patch is applied in
the 0.4.90.2 release. Thanks. Nick _______________________________________________ xfce-goodies-dev mailing list xfce-goodies-dev@... https://lists.berlios.de/mailman/listinfo/xfce-goodies-dev |
| Free embeddable forum powered by Nabble | Forum Help |