Bug 175332 - [PATCH] Implement ACPI battery monitoring for x11/tint
Summary: [PATCH] Implement ACPI battery monitoring for x11/tint
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Lars Engels
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-15 21:10 UTC by yamagi
Modified: 2013-01-20 15:00 UTC (History)
0 users

See Also:


Attachments
file.diff (3.54 KB, patch)
2013-01-15 21:10 UTC, yamagi
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description yamagi 2013-01-15 21:10:02 UTC
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: -
Comment 1 Lars Engels freebsd_committer freebsd_triage 2013-01-20 11:18:35 UTC
Responsible Changed
From-To: freebsd-ports-bugs->lme

I'll take it.
Comment 2 dfilter service freebsd_committer freebsd_triage 2013-01-20 14:52:00 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"
Comment 3 Lars Engels freebsd_committer freebsd_triage 2013-01-20 14:52:57 UTC
State Changed
From-To: open->closed

Committed, with minor changes. Thanks!