From nobody@FreeBSD.org  Tue Jan 15 21:04:06 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	by hub.freebsd.org (Postfix) with ESMTP id D483A783
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 15 Jan 2013 21:04:06 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id F38BD844
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 15 Jan 2013 21:04:05 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r0FL45iM060043
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 15 Jan 2013 21:04:05 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id r0FL45o0060042;
	Tue, 15 Jan 2013 21:04:05 GMT
	(envelope-from nobody)
Message-Id: <201301152104.r0FL45o0060042@red.freebsd.org>
Date: Tue, 15 Jan 2013 21:04:05 GMT
From: Yamagi Burmeister <yamagi@yamagi.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] Implement ACPI battery monitoring for x11/tint
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         175332
>Category:       ports
>Synopsis:       [PATCH] Implement ACPI battery monitoring for x11/tint
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lme
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jan 15 21:10:02 UTC 2013
>Closed-Date:    Sun Jan 20 14:52:58 UTC 2013
>Last-Modified:  Sun Jan 20 15:00:00 UTC 2013
>Originator:     Yamagi Burmeister
>Release:        FreeBSD 8.3-RELEASE
>Organization:
>Environment:
FreeBSD maka.home.yamagi.org 8.3-RELEASE-p4 FreeBSD 8.3-RELEASE-p4 #0 r239214M: Sun Aug 12 20:32:17 CEST 2012     root@maka.home.yamagi.org:/usr/obj/usr/src/sys/MAKA  amd64
>Description:
A long time ago I implemented ACPI battery monitoring for x11/tint. Other than the included APM battery monitor it works on nearly all modern laptops. The patch was committed upstream and would have been part of the next release. But that release never came and so the patch never reached the ports collection. After a recent forum discussion I've digged it up again and here it is. Put the attached patch into the files/ directory of x11/tint and the panel grows ACPI battery monitoring.

The upstream changeset can be found here: http://code.google.com/p/tint2/source/diff?spec=svn515&r=515&format=side&path=/trunk/src/battery/battery.c
>How-To-Repeat:
-
>Fix:
Index: src/battery/battery.c
===================================================================
--- src/battery/battery.c	(Revision 514)
+++ src/battery/battery.c	(Revision 515)
@@ -24,13 +24,18 @@
 #include <cairo-xlib.h>
 #include <pango/pangocairo.h>
 
-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__OpenBSD__) || defined(__NetBSD__)
 #include <machine/apmvar.h>
 #include <err.h>
 #include <sys/ioctl.h>
 #include <unistd.h>
 #endif
 
+#if defined(__FreeBSD__)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
+
 #include "window.h"
 #include "server.h"
 #include "area.h"
@@ -59,11 +64,10 @@
 char *path_current_now;
 char *path_status;
 
-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__OpenBSD__) || defined(__NetBSD__)
 int apm_fd;
 #endif
 
-
 void update_batterys(void* arg)
 {
 	int i;
@@ -103,7 +107,7 @@
 	path_energy_full = 0;
 	path_current_now = 0;
 	path_status = 0;
-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__OpenBSD__) || defined(__NetBSD__)
 	apm_fd = -1;
 #endif
 }
@@ -118,7 +122,7 @@
 	if (path_status) g_free(path_status);
 	if (battery_low_cmd) g_free(battery_low_cmd);
 
-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__OpenBSD__) || defined(__NetBSD__)
 	if ((apm_fd != -1) && (close(apm_fd) == -1))
 		warn("cannot close /dev/apm");
 #endif
@@ -129,7 +133,7 @@
 {
 	if (!battery_enabled) return;
 
-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__OpenBSD__) || defined(__NetBSD__)
 	apm_fd = open("/dev/apm", O_RDONLY);
 	if (apm_fd < 0) {
 		warn("init_battery: failed to open /dev/apm.");
@@ -137,7 +141,7 @@
 		return;
 	}
 
-#else
+#elif !defined(__FreeBSD__)
 	// check battery
 	GDir *directory = 0;
 	GError *error = NULL;
@@ -258,17 +262,21 @@
 
 
 void update_battery() {
-#if !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
+#if !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__FreeBSD__)
 	// unused on OpenBSD, silence compiler warnings
 	FILE *fp;
 	char tmp[25];
 	int64_t current_now = 0;
 #endif
+#if defined(__FreeBSD__)
+	int sysctl_out =  0;
+	size_t len = 0;
+#endif
 	int64_t energy_now = 0, energy_full = 0;
 	int seconds = 0;
 	int8_t new_percentage = 0;
 
-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__OpenBSD__) || defined(__NetBSD__)
 	struct apm_power_info info;
 	if (ioctl(apm_fd, APM_IOC_GETPOWER, &(info)) < 0)
 		warn("power update: APM_IOC_GETPOWER");
@@ -298,6 +306,45 @@
 
 	new_percentage = info.battery_life;
 
+#elif defined(__FreeBSD__)
+	len = sizeof(sysctl_out);
+
+	if (sysctlbyname("hw.acpi.battery.state", &sysctl_out, &len, NULL, 0) != 0)
+		fprintf(stderr, "power update: no such sysctl");
+
+	// attemp to map the battery state to linux
+	battery_state.state = BATTERY_UNKNOWN;
+
+	switch(sysctl_out) {
+		case 1:
+			battery_state.state = BATTERY_DISCHARGING;
+			break;
+		case 2:
+			battery_state.state = BATTERY_CHARGING;
+			break;
+		default:
+			battery_state.state = BATTERY_FULL;
+			break;
+	}
+
+	// no mapping for freebsd
+	energy_full = 0;
+	energy_now = 0;
+
+	if (sysctlbyname("hw.acpi.battery.time", &sysctl_out, &len, NULL, 0) != 0)
+		seconds = -1;
+	else
+		seconds = sysctl_out * 60;
+
+	// charging or error
+	if (seconds < 0)
+		seconds = 0;
+
+	if (sysctlbyname("hw.acpi.battery.life", &sysctl_out, &len, NULL, 0) != 0)
+		new_percentage = -1;
+	else
+		new_percentage = sysctl_out;
+
 #else
 	fp = fopen(path_status, "r");
 	if(fp != NULL) { 

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->lme 
Responsible-Changed-By: lme 
Responsible-Changed-When: Sun Jan 20 11:18:35 UTC 2013 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=175332 
State-Changed-From-To: open->closed 
State-Changed-By: lme 
State-Changed-When: Sun Jan 20 14:52:57 UTC 2013 
State-Changed-Why:  
Committed, with minor changes. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=175332 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/175332: commit references a PR
Date: Sun, 20 Jan 2013 14:52:00 +0000 (UTC)

 Author: lme
 Date: Sun Jan 20 14:51:52 2013
 New Revision: 310690
 URL: http://svnweb.freebsd.org/changeset/ports/310690
 
 Log:
   - Add a patch to enable battery support [1]
   - Don't depend depend on a specific library version
   - Quiet install
   - Bump PORTREVISION
   - Pass maintainership to submitter
   
   PR:		ports/175332 [1]
   Submitted by:	Yamagi Burmeister <yamagi@yamagi.org>
 
 Added:
   head/x11/tint/files/
   head/x11/tint/files/patch-src-battery-battery.c   (contents, props changed)
 Modified:
   head/x11/tint/Makefile   (contents, props changed)
 
 Modified: head/x11/tint/Makefile
 ==============================================================================
 --- head/x11/tint/Makefile	Sun Jan 20 13:58:51 2013	(r310689)
 +++ head/x11/tint/Makefile	Sun Jan 20 14:51:52 2013	(r310690)
 @@ -2,16 +2,16 @@
  
  PORTNAME=	tint2
  PORTVERSION=	0.11
 -PORTREVISION=	1
 +PORTREVISION=	2
  CATEGORIES=	x11
  MASTER_SITES=	${MASTER_SITE_GOOGLE_CODE}
  
 -MAINTAINER=	ports@FreeBSD.org
 +MAINTAINER=	yamagi@yamagi.org
  COMMENT=	Lightweight freedesktop-compliant panel/taskbar/systray/clock
  
 -MAKE_JOBS_SAFE=	yes
 +LIB_DEPENDS=	cairo:${PORTSDIR}/graphics/cairo
  
 -LIB_DEPENDS=	cairo.2:${PORTSDIR}/graphics/cairo
 +MAKE_JOBS_SAFE=	yes
  
  PROJECTHOST=	tint2
  USE_BZIP2=	yes
 @@ -20,7 +20,7 @@ USE_GNOME=	pango glib20
  USE_XORG=	xinerama xrandr xdamage xcomposite
  USE_EFL=	imlib2
  
 -CMAKE_ARGS=	-DENABLE_BATTERY:BOOL=OFF -DMANDIR:PATH=man
 +CMAKE_ARGS=	-DENABLE_BATTERY:BOOL=ON -DMANDIR:PATH=man
  
  PLIST_FILES=	bin/tint2 \
  		share/tint2/default_icon.png
 @@ -57,32 +57,32 @@ post-patch:
  .endif
  
  do-install:
 -	${INSTALL_PROGRAM} ${WRKSRC}/tint2 ${PREFIX}/bin
 -	${MKDIR} ${PREFIX}/share/tint2
 -	${INSTALL_DATA} ${WRKSRC}/default_icon.png ${PREFIX}/share/tint2
 -	${INSTALL_MAN} ${WRKSRC}/doc/tint2.1 ${MANPREFIX}/man/man1
 +	@${INSTALL_PROGRAM} ${WRKSRC}/tint2 ${PREFIX}/bin
 +	@${MKDIR} ${PREFIX}/share/tint2
 +	@${INSTALL_DATA} ${WRKSRC}/default_icon.png ${PREFIX}/share/tint2
 +	@${INSTALL_MAN} ${WRKSRC}/doc/tint2.1 ${MANPREFIX}/man/man1
  .if ${PORT_OPTIONS:MPYCONF}
 -	${INSTALL_PROGRAM} ${PYCONF_SRC}/tint2conf ${PREFIX}/bin
 -	${INSTALL_SCRIPT} ${PYCONF_SRC}/tintwizard.py ${PREFIX}/bin
 -	${MKDIR} ${PREFIX}/share/applications
 -	${INSTALL_DATA} ${PYCONF_SRC}/tint2conf.desktop ${PREFIX}/share/applications
 -	${INSTALL_DATA} ${PYCONF_SRC}/tint2conf.png ${PREFIX}/share/pixmaps
 -	${INSTALL_DATA} ${PYCONF_SRC}/tint2conf.svg ${PREFIX}/share/pixmaps
 +	@${INSTALL_PROGRAM} ${PYCONF_SRC}/tint2conf ${PREFIX}/bin
 +	@${INSTALL_SCRIPT} ${PYCONF_SRC}/tintwizard.py ${PREFIX}/bin
 +	@${MKDIR} ${PREFIX}/share/applications
 +	@${INSTALL_DATA} ${PYCONF_SRC}/tint2conf.desktop ${PREFIX}/share/applications
 +	@${INSTALL_DATA} ${PYCONF_SRC}/tint2conf.png ${PREFIX}/share/pixmaps
 +	@${INSTALL_DATA} ${PYCONF_SRC}/tint2conf.svg ${PREFIX}/share/pixmaps
  .endif
  .if ${PORT_OPTIONS:MDOCS}
 -	${MKDIR} ${DOCSDIR}
 -.for file in ${PORTDOCS}
 -	${INSTALL_DATA} ${WRKSRC}/${file} ${DOCSDIR}
 +	@${MKDIR} ${DOCSDIR}
 +.for f in ${PORTDOCS}
 +	@${INSTALL_DATA} ${WRKSRC}/${f} ${DOCSDIR}
  .endfor
  .endif
  .if ${PORT_OPTIONS:MEXAMPLES}
 -	${MKDIR} ${EXAMPLESDIR}
 -	@for file in ${RCS}; do \
 -	${INSTALL_DATA} ${WRKSRC}/sample/$${file} ${EXAMPLESDIR}; \
 +	@${MKDIR} ${EXAMPLESDIR}
 +	@for f in ${RCS}; do \
 +	${INSTALL_DATA} ${WRKSRC}/sample/$${f} ${EXAMPLESDIR}; \
  	done
  RCS=	icon_and_text_1.tint2rc icon_and_text_2.tint2rc icon_and_text_3.tint2rc icon_and_text_4.tint2rc icon_only_1.tint2rc icon_only_2.tint2rc icon_only_3.tint2rc icon_only_4.tint2rc icon_only_6.tint2rc icon_only_7.tint2rc text_only_1.tint2rc text_only_2.tint2rc text_only_3.tint2rc text_only_4.tint2rc text_only_5.tint2rc text_only_6.tint2rc tint2rc
 -.for file in ${RCS}
 -PLIST_FILES+=	${EXAMPLESDIR_REL}/${file}
 +.for f in ${RCS}
 +PLIST_FILES+=	${EXAMPLESDIR_REL}/${f}
  .endfor
  PLIST_DIRS+=	${EXAMPLESDIR_REL}
  .endif
 
 Added: head/x11/tint/files/patch-src-battery-battery.c
 ==============================================================================
 --- /dev/null	00:00:00 1970	(empty, because file is newly added)
 +++ head/x11/tint/files/patch-src-battery-battery.c	Sun Jan 20 14:51:52 2013	(r310690)
 @@ -0,0 +1,144 @@
 +Index: src/battery/battery.c
 +===================================================================
 +--- src/battery/battery.c	(Revision 514)
 ++++ src/battery/battery.c	(Revision 515)
 +@@ -24,13 +24,18 @@
 + #include <cairo-xlib.h>
 + #include <pango/pangocairo.h>
 + 
 +-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
 ++#if defined(__OpenBSD__) || defined(__NetBSD__)
 + #include <machine/apmvar.h>
 + #include <err.h>
 + #include <sys/ioctl.h>
 + #include <unistd.h>
 + #endif
 + 
 ++#if defined(__FreeBSD__)
 ++#include <sys/types.h>
 ++#include <sys/sysctl.h>
 ++#endif
 ++
 + #include "window.h"
 + #include "server.h"
 + #include "area.h"
 +@@ -59,11 +64,10 @@
 + char *path_current_now;
 + char *path_status;
 + 
 +-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
 ++#if defined(__OpenBSD__) || defined(__NetBSD__)
 + int apm_fd;
 + #endif
 + 
 +-
 + void update_batterys(void* arg)
 + {
 + 	int i;
 +@@ -103,7 +107,7 @@
 + 	path_energy_full = 0;
 + 	path_current_now = 0;
 + 	path_status = 0;
 +-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
 ++#if defined(__OpenBSD__) || defined(__NetBSD__)
 + 	apm_fd = -1;
 + #endif
 + }
 +@@ -118,7 +122,7 @@
 + 	if (path_status) g_free(path_status);
 + 	if (battery_low_cmd) g_free(battery_low_cmd);
 + 
 +-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
 ++#if defined(__OpenBSD__) || defined(__NetBSD__)
 + 	if ((apm_fd != -1) && (close(apm_fd) == -1))
 + 		warn("cannot close /dev/apm");
 + #endif
 +@@ -129,7 +133,7 @@
 + {
 + 	if (!battery_enabled) return;
 + 
 +-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
 ++#if defined(__OpenBSD__) || defined(__NetBSD__)
 + 	apm_fd = open("/dev/apm", O_RDONLY);
 + 	if (apm_fd < 0) {
 + 		warn("init_battery: failed to open /dev/apm.");
 +@@ -137,7 +141,7 @@
 + 		return;
 + 	}
 + 
 +-#else
 ++#elif !defined(__FreeBSD__)
 + 	// check battery
 + 	GDir *directory = 0;
 + 	GError *error = NULL;
 +@@ -258,17 +262,21 @@
 + 
 + 
 + void update_battery() {
 +-#if !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
 ++#if !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__FreeBSD__)
 + 	// unused on OpenBSD, silence compiler warnings
 + 	FILE *fp;
 + 	char tmp[25];
 + 	int64_t current_now = 0;
 + #endif
 ++#if defined(__FreeBSD__)
 ++	int sysctl_out =  0;
 ++	size_t len = 0;
 ++#endif
 + 	int64_t energy_now = 0, energy_full = 0;
 + 	int seconds = 0;
 + 	int8_t new_percentage = 0;
 + 
 +-#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__)
 ++#if defined(__OpenBSD__) || defined(__NetBSD__)
 + 	struct apm_power_info info;
 + 	if (ioctl(apm_fd, APM_IOC_GETPOWER, &(info)) < 0)
 + 		warn("power update: APM_IOC_GETPOWER");
 +@@ -298,6 +306,45 @@
 + 
 + 	new_percentage = info.battery_life;
 + 
 ++#elif defined(__FreeBSD__)
 ++	len = sizeof(sysctl_out);
 ++
 ++	if (sysctlbyname("hw.acpi.battery.state", &sysctl_out, &len, NULL, 0) != 0)
 ++		fprintf(stderr, "power update: no such sysctl");
 ++
 ++	// attemp to map the battery state to linux
 ++	battery_state.state = BATTERY_UNKNOWN;
 ++
 ++	switch(sysctl_out) {
 ++		case 1:
 ++			battery_state.state = BATTERY_DISCHARGING;
 ++			break;
 ++		case 2:
 ++			battery_state.state = BATTERY_CHARGING;
 ++			break;
 ++		default:
 ++			battery_state.state = BATTERY_FULL;
 ++			break;
 ++	}
 ++
 ++	// no mapping for freebsd
 ++	energy_full = 0;
 ++	energy_now = 0;
 ++
 ++	if (sysctlbyname("hw.acpi.battery.time", &sysctl_out, &len, NULL, 0) != 0)
 ++		seconds = -1;
 ++	else
 ++		seconds = sysctl_out * 60;
 ++
 ++	// charging or error
 ++	if (seconds < 0)
 ++		seconds = 0;
 ++
 ++	if (sysctlbyname("hw.acpi.battery.life", &sysctl_out, &len, NULL, 0) != 0)
 ++		new_percentage = -1;
 ++	else
 ++		new_percentage = sysctl_out;
 ++
 + #else
 + 	fp = fopen(path_status, "r");
 + 	if(fp != NULL) { 
 +
 _______________________________________________
 svn-ports-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-ports-all
 To unsubscribe, send any mail to "svn-ports-all-unsubscribe@freebsd.org"
 
>Unformatted:
