Subject: pkg/10421: the gnome battery applet used to work but dosn't now. (patch included).
To: None <gnats-bugs@gnats.netbsd.org>
From: None <jasper@pointless.net>
List: netbsd-bugs
Date: 06/22/2000 17:47:20
>Number:         10421
>Category:       pkg
>Synopsis:       The gnome battery (apm) applet has stoped working
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jun 22 17:48:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Jasper Wallace
>Release:        <NetBSD-current source date>
>Organization:
-- 
http://pointless.net/     : Another Great waste of bandwidth!
http://advogato.com/      : nothing to do with me, but worth a look.
http://www.ivision.co.uk/ : I pretend to work for these people.
2ECA0975     ::     45 52 65 E9 33 C7 72 4B  96 F4 44 2D 79 27 BF 08
>Environment:

Makefile:# $NetBSD: Makefile,v 1.2 2000/06/03 17:31:44 rh Exp $
patches/patch-aa:$NetBSD: patch-aa,v 1.1.1.1 2000/06/02 13:08:31 drochner Exp $

System: NetBSD jellycat 1.4ZD NetBSD 1.4ZD (JELLYCAT.pnpbios) #2: Tue Jun 20 18:31:08 BST 2000 jasper@jellycat:/usr/src/sys/arch/i386/compile/JELLYCAT.pnpbios i386


>Description:

	The gnome battery applet used to work under NetBSD with a patch in
pkgsrc, but since the move from gnome-core to gnome-applets the patch
appears to have got lost.

>How-To-Repeat:

	compile gnome-applets from a recent pkgsrc, add the battery applet
to the panel and remove the ac powersupply from your laptop, observe that
the applet stubbonly refusees to change. sulk.

>Fix:

apply patch: 

(i forgot to backup read-battery.h before i editied it, so the patch below
is generated from what i can rember what it was like before it changed. easy
to fix if it dosn't apply tho).

--- read-battery.c.pre-jgw	Fri Feb 11 16:27:56 2000
+++ read-battery.c	Fri Jun 23 01:26:01 2000
@@ -157,40 +157,40 @@
   
   return TRUE;
 
-#elif __FreeBSD__  /* was #ifdef __linux__ */
+#elif __NetBSD__  /* was #ifdef __linux__ */
 
-  struct apm_info aip;
+  struct apm_power_info aip;
   int fd;
+  u_int mins;
 
-  fd = open(APMDEV, O_RDWR);
+  fd = open(APMDEV, O_RDONLY);
   if (fd == -1)
     {
       g_error (_("Cannot open /dev/apm; can't get data."));
       return FALSE;
     }
 
-  if (ioctl(fd, APMIO_GETINFO, &aip) == -1) {
+  if (ioctl(fd, APM_IOC_GETPOWER, &aip) == -1) {
     g_error(_("ioctl failed on /dev/apm."));
     return FALSE;
   }
 
-  /* We cannot read these under FreeBSD. */
-  *hours_remaining = -1;
-  *minutes_remaining = 1;
-
-  /* if APM is not turned on */
-  if (!aip.ai_status)
-    {
-      g_error(_("APM is disabled!  Cannot read battery charge information."));
-    }
-
-  *ac_online = aip.ai_acline;
-  *percentage = aip.ai_batt_life;
+  /* We can read these under NetBSD. */
+  mins = aip.minutes_left;
+  *hours_remaining = mins / 60;
+  *minutes_remaining = mins % 60;
+
+  if ( aip.ac_state == APM_AC_ON )
+  	*ac_online = 1;
+  else if (aip.ac_state == APM_AC_OFF)
+	*ac_online = 0;
+	
+  *percentage = aip.battery_life;
 
   close(fd);
   return TRUE;
 
-#else /* ! ( __linux__ || __FreeBSD__) */
+#else /* ! ( __linux__ || __NetBSD__) */
 
   /* Assume always connected to power.  */
   *ac_online = 1;
--- read-battery.h.orig	Fri Jun 23 01:28:21 2000
+++ read-battery.h	Fri Jun 23 01:25:33 2000
@@ -14,9 +14,10 @@
   int        battery_time;
   int        using_minutes;
 } apm_info;
-#elif __FreeBSD__
+#elif __NetBSD__
 #include <fcntl.h>
-#include <machine/apm_bios.h>
+#include <sys/ioctl.h>
+#include <machine/apmvar.h>
 #define APMDEV "/dev/apm"
 #endif
 
>Release-Note:
>Audit-Trail:
>Unformatted: