Oh hai there,

On Fri, Apr 16, 2010 at 09:00:53AM +0200, David Coppa wrote:
> >   * Hacked the battery code to map to OpenBSD. Works fine.
> 
> Isn't more elegant to protect code with 
> 
>       #if defined(__OpenBSD__)
>               ...
>       #else
>               ...
>       #endif
> 
> Instead of using #if 0/#endif ?

yes

> >   * Can someone check lib-depends-check on their system. I find it odd that 
> > I
> >     have to add -lX11 to the environment for the build to work, but then it 
> > is
> >     not needed in WANTLIB. Hmmm
> 
> Imho this is better:

Try this. OK?


Index: Makefile
===================================================================
RCS file: /cvs/ports/x11/tint/Makefile,v
retrieving revision 1.2
diff -u -p -u -r1.2 Makefile
--- Makefile    11 Aug 2009 08:42:09 -0000      1.2
+++ Makefile    16 Apr 2010 09:59:11 -0000
@@ -2,13 +2,13 @@
 
 COMMENT=       lightweight freedesktop-compliant panel/taskbar/clock
 
-DISTNAME=      tint-0.6.0
+DISTNAME=      tint2-0.9
+PKGNAME=       ${DISTNAME:S/tint2/tint/}
 CATEGORIES=    x11
-PKGNAME=       ${DISTNAME}p0
 
 HOMEPAGE=      http://code.google.com/p/tint2/
 
-MAINTAINER=    Pierre-Emmanuel Andre <[email protected]>
+MAINTAINER=    Edd Barrett <[email protected]>
 
 # MIT
 PERMIT_PACKAGE_CDROM=  Yes
@@ -16,28 +16,25 @@ PERMIT_PACKAGE_FTP= Yes
 PERMIT_DISTFILES_CDROM=        Yes
 PERMIT_DISTFILES_FTP=  Yes
 
-WANTLIB=       X11 Xau Xdmcp Xext Xinerama Xrender c cairo expat \
-               fontconfig freetype glib-2.0 glitz gmodule-2.0 \
-               gobject-2.0 m pixman-1 png z pthread-stubs xcb
+WANTLIB=       X11 Xinerama Xrender c cairo glib-2.0 gobject-2.0 \
+               Xcomposite Xdamage
 
 MASTER_SITES=  http://tint2.googlecode.com/files/
 
-MODULES=       devel/gettext
-
 LIB_DEPENDS=   Imlib2.>=2::graphics/imlib2 \
-               pango-1.0,pangoft2-1.0,pangocairo-1.0::devel/pango
+               pango-1.0,pangocairo-1.0::devel/pango
 
 USE_X11=       Yes
 USE_GMAKE=     Yes
 NO_REGRESS=    Yes
 
-WRKDIST=       ${WRKDIR}/tint
-WRKSRC=                ${WRKDIST}/src
-
-ALL_TARGET=    tint
+CONFIGURE_STYLE=gnu
+CONFIGURE_ENV+=        "LDFLAGS=-L${PREFIX}/lib -L${X11BASE}/lib"
 
+# set up for @sample in PLIST
 post-install:
-       ${INSTALL_DATA_DIR} ${PREFIX}/share/doc/tint
-       ${INSTALL_DATA} ${WRKDIST}/doc/tint-0.6.* ${PREFIX}/share/doc/tint/
+               ${INSTALL_DATA_DIR} ${PREFIX}/share/examples/tint2
+               mv ${WRKINST}/etc/xdg/tint2/tint2rc \
+                       ${PREFIX}/share/examples/tint2
 
 .include <bsd.port.mk>
Index: distinfo
===================================================================
RCS file: /cvs/ports/x11/tint/distinfo,v
retrieving revision 1.1.1.1
diff -u -p -u -r1.1.1.1 distinfo
--- distinfo    17 Sep 2008 15:39:51 -0000      1.1.1.1
+++ distinfo    16 Apr 2010 09:59:11 -0000
@@ -1,5 +1,5 @@
-MD5 (tint-0.6.0.tar.gz) = UKMncwQpNzoYKGsn+RX+/Q==
-RMD160 (tint-0.6.0.tar.gz) = cBWCOs7NvF0syGf+w29F/wvHAfo=
-SHA1 (tint-0.6.0.tar.gz) = diAOYtyXHYgwO9ZAh/hpFSbAtWk=
-SHA256 (tint-0.6.0.tar.gz) = 12IxHkvaFOpJ8wbLffG4N1kmpCeaSPRu5GprhqwqNgM=
-SIZE (tint-0.6.0.tar.gz) = 362794
+MD5 (tint2-0.9.tar.gz) = QR3mzLi4IImFLYyFSxLduQ==
+RMD160 (tint2-0.9.tar.gz) = lYpIUIV+K5D+pyxI0yyj1ofWvHQ=
+SHA1 (tint2-0.9.tar.gz) = +mmqqSS7WoXPp1OUbIpuvtedc9g=
+SHA256 (tint2-0.9.tar.gz) = X4sUlpx713WPY2H6rieeHQZZyb40ehKgcvjPk4VPRwM=
+SIZE (tint2-0.9.tar.gz) = 206491
Index: patches/patch-sample_tint2rc
===================================================================
RCS file: patches/patch-sample_tint2rc
diff -N patches/patch-sample_tint2rc
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-sample_tint2rc        16 Apr 2010 09:59:11 -0000
@@ -0,0 +1,114 @@
+$OpenBSD$
+--- sample/tint2rc.orig        Thu Jan 28 11:16:34 2010
++++ sample/tint2rc     Fri Apr 16 02:22:44 2010
+@@ -1,31 +1,33 @@
+ #---------------------------------------------
+ # TINT2 CONFIG FILE
++# Hacked for sensible OpenBSD defaults.
+ #---------------------------------------------
+ 
+ #---------------------------------------------
+ # BACKGROUND AND BORDER
+ #---------------------------------------------
+-rounded = 7
+-border_width = 2
+-background_color = #000000 60
+-border_color = #ffffff 18
+ 
+-rounded = 5
+-border_width = 0
+-background_color = #ffffff 40
+-border_color = #ffffff 50
++# id = 0
++# transparent
+ 
+-rounded = 5
++# id = 1
++rounded = 0
+ border_width = 0
+-background_color = #ffffff 18
+-border_color = #ffffff 70
++background_color = #ffffff 5
++border_color = #333333 
+ 
++# id = 2
++rounded = 0
++border_width = 1
++background_color = #424343 
++border_color = #333333
++
+ #---------------------------------------------
+ # PANEL
+ #---------------------------------------------
+ panel_monitor = all
+ panel_position = bottom center
+-panel_size = 94% 30
++panel_size = 100% 30
+ panel_margin = 0 0
+ panel_padding = 7 0
+ font_shadow = 0
+@@ -40,8 +42,8 @@ panel_layer = bottom
+ #taskbar_mode = multi_desktop
+ taskbar_mode = single_desktop
+ taskbar_padding = 2 3 2
+-taskbar_background_id = 0
+-#taskbar_active_background_id = 0
++taskbar_background_id = 1
++taskbar_active_background_id = 0
+ 
+ #---------------------------------------------
+ # TASKS
+@@ -51,9 +53,9 @@ task_text = 1
+ task_maximum_size = 140 35
+ task_centered = 1
+ task_padding = 6 3
+-task_font = sans 7
++task_font = sans 10 
+ task_font_color = #ffffff 70
+-task_background_id = 3
++task_background_id = 0
+ task_icon_asb = 100 0 0
+ # replace STATUS by 'urgent', 'active' or 'iconfied'
+ #task_STATUS_background_id = 2
+@@ -61,7 +63,7 @@ task_icon_asb = 100 0 0
+ #task_STATUS_icon_asb = 100 0 0
+ # example:
+ task_active_background_id = 2
+-task_active_font_color = #ffffff 85
++task_active_font_color = #ffffff
+ task_active_icon_asb = 100 0 0
+ urgent_nb_of_blink = 8
+ 
+@@ -95,8 +97,8 @@ clock_rclick_command = orage
+ #---------------------------------------------
+ # BATTERY
+ #---------------------------------------------
+-battery = 0
+-battery_hide = 98
++battery = 1
++battery_hide = never
+ battery_low_status = 10
+ battery_low_cmd = notify-send "battery low"
+ bat1_font = sans 8
+@@ -105,16 +107,17 @@ battery_font_color = #ffffff 76
+ battery_padding = 1 0
+ battery_background_id = 0
+ 
++
+ #---------------------------------------------
+ # TOOLTIP
+ #---------------------------------------------
+-tooltip = 0
++tooltip = 1
+ tooltip_padding = 2 2
+ tooltip_show_timeout = 0.7
+ tooltip_hide_timeout = 0.3
+-tooltip_background_id = 1
+-tooltip_font_color = #OOOOOO 80
+-tooltip_font = sans 10
++tooltip_background_id = 2
++tooltip_font_color = #ffffff 80
++tooltip_font = sans 10 
+ 
+ #---------------------------------------------
+ # MOUSE ACTION ON TASK
Index: patches/patch-src_Makefile
===================================================================
RCS file: patches/patch-src_Makefile
diff -N patches/patch-src_Makefile
--- patches/patch-src_Makefile  17 Sep 2008 15:39:51 -0000      1.1.1.1
+++ /dev/null   1 Jan 1970 00:00:00 -0000
@@ -1,14 +0,0 @@
-$OpenBSD: patch-src_Makefile,v 1.1.1.1 2008/09/17 15:39:51 ajacoutot Exp $
---- src/Makefile.orig  Sat Jul 19 15:43:41 2008
-+++ src/Makefile       Wed Sep 17 14:51:56 2008
-@@ -11,8 +11,8 @@ ifndef DESTDIR
-               XDG_CONFIG_DIR=/etc/xdg
-       endif
- else
--      BINDIR=$(DESTDIR)/usr/bin
--      XDG_CONFIG_DIR=$(DESTDIR)/etc/xdg
-+      BINDIR=$(PREFIX)/bin
-+      XDG_CONFIG_DIR=$(PREFIX)/share/examples/
- endif
- 
- 
Index: patches/patch-src_Makefile_in
===================================================================
RCS file: patches/patch-src_Makefile_in
diff -N patches/patch-src_Makefile_in
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_Makefile_in       16 Apr 2010 09:59:11 -0000
@@ -0,0 +1,12 @@
+$OpenBSD$
+--- src/Makefile.in.orig       Tue Apr 13 23:00:33 2010
++++ src/Makefile.in    Tue Apr 13 23:00:45 2010
+@@ -158,7 +158,7 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
+ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+ LDFLAGS = @LDFLAGS@
+ LIBOBJS = @LIBOBJS@
+-LIBS = @PANGOCAIRO_LIBS@ @PANGO_LIBS@ @CAIRO_LIBS@ @GLIB2_LIBS@ 
@GOBJECT2_LIBS@ @X11_LIBS@ @XINERAMA_LIBS@ @IMLIB2_LIBS@ -lrt
++LIBS = @PANGOCAIRO_LIBS@ @PANGO_LIBS@ @CAIRO_LIBS@ @GLIB2_LIBS@ 
@GOBJECT2_LIBS@ @X11_LIBS@ @XINERAMA_LIBS@ @IMLIB2_LIBS@
+ LTLIBOBJS = @LTLIBOBJS@
+ MAKEINFO = @MAKEINFO@
+ MKDIR_P = @MKDIR_P@
Index: patches/patch-src_battery_battery_c
===================================================================
RCS file: patches/patch-src_battery_battery_c
diff -N patches/patch-src_battery_battery_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_battery_battery_c 16 Apr 2010 09:59:12 -0000
@@ -0,0 +1,153 @@
+$OpenBSD$
+--- src/battery/battery.c.orig Tue Jan 19 19:29:28 2010
++++ src/battery/battery.c      Fri Apr 16 11:03:54 2010
+@@ -24,6 +24,13 @@
+ #include <cairo-xlib.h>
+ #include <pango/pangocairo.h>
+ 
++#if defined(__OpenBSD__)
++#include <machine/apmvar.h>
++#include <err.h>
++#include <sys/ioctl.h>
++#include <unistd.h>
++#endif
++
+ #include "window.h"
+ #include "server.h"
+ #include "area.h"
+@@ -51,6 +58,10 @@ char *path_energy_full=0;
+ char *path_current_now=0;
+ char *path_status=0;
+ 
++#if defined(__OpenBSD__)
++int apm_fd = NULL;
++#endif
++
+ void update_batterys(void* arg)
+ {
+       int i;
+@@ -80,6 +91,21 @@ void update_batterys(void* arg)
+ 
+ void init_battery()
+ {
++
++#if defined(__OpenBSD__)
++
++      apm_fd = open("/dev/apm", O_RDONLY, "r");
++      if (apm_fd < 0) {
++              warn("init_battery: failed to open /dev/apm.");
++              battery_enabled = 0;
++              return;
++      }
++
++      if (battery_enabled && battery_timeout==0)
++              battery_timeout = add_timeout(10, 10000, update_batterys, 0);
++
++#else
++
+       // check battery
+       GDir *directory = 0;
+       GError *error = NULL;
+@@ -150,9 +176,8 @@ void init_battery()
+ 
+       g_free(path1);
+       g_free(battery_dir);
++#endif
+ 
+-      if (battery_enabled && battery_timeout==0)
+-              battery_timeout = add_timeout(10, 10000, update_batterys, 0);
+ }
+ 
+ 
+@@ -176,6 +201,12 @@ void cleanup_battery()
+ 
+       battery_low_cmd = path_energy_now = path_energy_full = path_current_now 
= path_status = 0;
+       bat1_font_desc = bat2_font_desc = 0;
++
++#if defined(__OpenBSD__)
++      if (close(apm_fd) == -1)
++              warn("cannot close /dev/apm");
++#endif
++
+ }
+ 
+ 
+@@ -227,8 +258,43 @@ void update_battery() {
+       char tmp[25];
+       int64_t energy_now = 0, energy_full = 0, current_now = 0;
+       int seconds = 0;
+-      int8_t new_percentage = 0;
++      unsigned int new_percentage = 0;
+ 
++#if defined(__OpenBSD__)
++
++      /* OpenBSD */
++      struct apm_power_info info;
++      if (ioctl(apm_fd, APM_IOC_GETPOWER, &(info)) < 0)
++              warn("power update: APM_IOC_GETPOWER");
++
++      /* best attempt at mapping to linux battery states */
++      battery_state.state = BATTERY_UNKNOWN;
++      switch (info.battery_state) {
++              case APM_BATT_CHARGING:
++                      battery_state.state = BATTERY_CHARGING;
++                      break;
++              default:
++                      battery_state.state = BATTERY_DISCHARGING;
++                      break;
++      }
++
++      if (info.battery_life == 100)
++              battery_state.state = BATTERY_FULL;
++
++      /* no mapping for openbsd really */
++      energy_full = 0;
++      energy_now = 0;
++
++      if (info.minutes_left != -1)
++              seconds = info.minutes_left * 60;
++      else
++              seconds = -1;
++
++      new_percentage = info.battery_life;
++
++#else
++      /* original linuxesque code */
++
+       fp = fopen(path_status, "r");
+       if(fp != NULL) {
+               if (fgets(tmp, sizeof tmp, fp)) {
+@@ -240,6 +306,7 @@ void update_battery() {
+               fclose(fp);
+       }
+ 
++
+       fp = fopen(path_energy_now, "r");
+       if(fp != NULL) {
+               if (fgets(tmp, sizeof tmp, fp)) energy_now = atoi(tmp);
+@@ -272,20 +339,22 @@ void update_battery() {
+               }
+       } else seconds = 0;
+ 
++      if(energy_full > 0)
++              new_percentage = (energy_now*100)/energy_full;
++#endif
++
+       battery_state.time.hours = seconds / 3600;
+       seconds -= 3600 * battery_state.time.hours;
+       battery_state.time.minutes = seconds / 60;
+       seconds -= 60 * battery_state.time.minutes;
+       battery_state.time.seconds = seconds;
+ 
+-      if(energy_full > 0)
+-              new_percentage = (energy_now*100)/energy_full;
+-
+       if(battery_low_status > new_percentage && battery_state.state == 
BATTERY_DISCHARGING && !battery_low_cmd_send) {
+               if (battery_low_cmd)
+                       if (-1 != system(battery_low_cmd))
+                               battery_low_cmd_send = 1;
+       }
++
+       if(battery_low_status < new_percentage && battery_state.state == 
BATTERY_CHARGING && battery_low_cmd_send) {
+               battery_low_cmd_send = 0;
+       }
Index: patches/patch-src_battery_battery_h
===================================================================
RCS file: patches/patch-src_battery_battery_h
diff -N patches/patch-src_battery_battery_h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-src_battery_battery_h 16 Apr 2010 09:59:12 -0000
@@ -0,0 +1,12 @@
+$OpenBSD$
+--- src/battery/battery.h.orig Tue Jan 19 19:29:28 2010
++++ src/battery/battery.h      Fri Apr 16 01:40:55 2010
+@@ -42,7 +42,7 @@ typedef struct battime {
+ } battime;
+ 
+ typedef struct batstate {
+-      int percentage;
++      unsigned int percentage;
+       struct battime time;
+       enum chargestate state;
+ } batstate;
Index: pkg/PLIST
===================================================================
RCS file: /cvs/ports/x11/tint/pkg/PLIST,v
retrieving revision 1.1.1.1
diff -u -p -u -r1.1.1.1 PLIST
--- pkg/PLIST   17 Sep 2008 15:39:51 -0000      1.1.1.1
+++ pkg/PLIST   16 Apr 2010 09:59:12 -0000
@@ -1,10 +1,15 @@
-...@comment $OpenBSD: PLIST,v 1.1.1.1 2008/09/17 15:39:51 ajacoutot Exp $
-...@bin bin/tint
-share/doc/tint/
-share/doc/tint/tint-0.6.odt
-share/doc/tint/tint-0.6.pdf
-share/examples/tint/
+...@comment $OpenBSD$
+...@bin bin/tint2
+...@man man/man1/tint2.1
+share/doc/tint2/
 @sample ${SYSCONFDIR}/xdg/
-...@sample ${SYSCONFDIR}/xdg/tint/
-share/examples/tint/tintrc
-...@sample ${SYSCONFDIR}/xdg/tint/tintrc
+...@sample ${SYSCONFDIR}/xdg/tint2/
+share/doc/tint2/AUTHORS
+share/doc/tint2/ChangeLog
+share/doc/tint2/NEWS
+share/doc/tint2/README
+share/examples/tint2/
+share/examples/tint2/tint2rc
+...@sample ${SYSCONFDIR}/xdg/tint2/tint2rc
+share/tint2/
+share/tint2/default_icon.png

-- 
Best Regards
Edd Barrett

http://www.theunixzoo.co.uk

Reply via email to