sysutils/xbattbar patch to add time & date display

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

sysutils/xbattbar patch to add time & date display

Alexander Polakov-2
Brynet (maintainer) suggested to send this to ports@.

This patch adds an option (-T) to display time and date in
xbattbar's popup window.
Personally, I find this very useful: I don't have to run any
other panel anymore. While there, I added headers to fix some
of the the warnings. Not sure if it's okay to add functionality
like this to ports, though, but upstream is not responding to
mails.

The man page diff is especially bad, sorry for that.

Any comments, oks?

Index: Makefile
===================================================================
RCS file: /cvs/ports/sysutils/xbattbar/Makefile,v
retrieving revision 1.2
diff -u -p -u -r1.2 Makefile
--- Makefile 22 May 2011 13:44:47 -0000 1.2
+++ Makefile 3 Apr 2012 19:53:21 -0000
@@ -6,6 +6,7 @@ COMMENT = show battery status as a simpl
 
 DISTNAME = xbattbar_1.4.2
 PKGNAME = ${DISTNAME:S/_/-/}
+REVISION = 0
 WRKDIST = ${WRKDIR}/${DISTNAME:S/_/-/}
 CATEGORIES = sysutils x11
 
Index: patches/patch-xbattbar_c
===================================================================
RCS file: /cvs/ports/sysutils/xbattbar/patches/patch-xbattbar_c,v
retrieving revision 1.1.1.1
diff -u -p -u -r1.1.1.1 patch-xbattbar_c
--- patches/patch-xbattbar_c 22 May 2011 12:32:41 -0000 1.1.1.1
+++ patches/patch-xbattbar_c 3 Apr 2012 19:53:21 -0000
@@ -1,7 +1,101 @@
-$OpenBSD: patch-xbattbar_c,v 1.1.1.1 2011/05/22 12:32:41 schwarze Exp $
---- xbattbar.c.orig Tue May 17 12:29:19 2011
-+++ xbattbar.c Tue May 17 12:32:20 2011
-@@ -575,7 +575,7 @@ void battery_check(void)
+$OpenBSD$
+--- xbattbar.c.orig Tue Apr  3 23:30:11 2012
++++ xbattbar.c Tue Apr  3 23:30:17 2012
+@@ -29,6 +29,9 @@ static char *ReleaseVersion="1.4.2";
+ #include <sys/time.h>
+ #include <signal.h>
+ #include <stdio.h>
++#include <stdlib.h>
++#include <string.h>
++#include <time.h>
+ #include <unistd.h>
+ #include <sys/file.h>
+ #include <sys/ioctl.h>
+@@ -67,6 +70,8 @@ char *ONOUT_C  = "olive drab";
+ char *OFFIN_C  = "blue";
+ char *OFFOUT_C = "red";
+
++char *clockfmt = "%+";
++int displayclock = False;
+ int alwaysontop = False;
+
+ struct itimerval IntervalTimer;     /* APM polling interval timer */
+@@ -118,7 +123,7 @@ void usage(char **argv)
+   fprintf(stderr,
+     "\n"  
+     "usage:\t%s [-a] [-h|v] [-p sec] [-t thickness]\n"
+-    "\t\t[-I color] [-O color] [-i color] [-o color]\n"
++    "\t\t[-I color] [-O color] [-i color] [-o color] [-T time-format]\n"
+     "\t\t[ top | bottom | left | right ]\n"
+     "-a:     always on top.\n"
+     "-v, -h: show this message.\n"
+@@ -126,6 +131,7 @@ void usage(char **argv)
+     "-p:     polling interval. [def: 10 sec.]\n"
+     "-I, -O: bar colors in AC on-line. [def: \"green\" & \"olive drab\"]\n"
+     "-i, -o: bar colors in AC off-line. [def: \"blue\" and \"red\"]\n"
++    "-T:     show time in popup window. [def: %%+]\n"
+     "top, bottom, left, right: bar localtion. [def: \"bottom\"]\n",
+  argv[0]);
+   exit(0);
+@@ -223,7 +229,7 @@ main(int argc, char **argv)
+   int ch;
+
+   about_this_program();
+-  while ((ch = getopt(argc, argv, "at:f:hI:i:O:o:p:v")) != -1)
++  while ((ch = getopt(argc, argv, "at:f:hI:i:O:o:p:T::v")) != -1)
+     switch (ch) {
+     case 'a':
+       alwaysontop = True;
+@@ -251,6 +257,12 @@ main(int argc, char **argv)
+       bi_interval = atoi(optarg);
+       break;
+
++    case 'T':
++      if (optarg)
++        clockfmt = optarg;
++      displayclock = 1;
++      break;
++
+     case 'h':
+     case 'v':
+       usage(argv);
+@@ -339,7 +351,14 @@ void showdiagbox(void)
+   int pixw, pixh;
+   int boxw, boxh;
+   char diagmsg[64];
++  char timemsg[64];
++  time_t now;
+
++  /* compose time and date message */
++  if (displayclock) {
++    time(&now);
++    strftime(timemsg, 64, clockfmt, localtime(&now));
++  }
+   /* compose diag message and calculate its size in pixels */
+   sprintf(diagmsg,
+          "AC %s-line: battery level is %d%%",
+@@ -349,6 +368,8 @@ void showdiagbox(void)
+   pixh = fontp->ascent + fontp->descent;
+   boxw = pixw + DiagXMergin * 2;
+   boxh = pixh + DiagYMergin * 2;
++  if (displayclock)
++  boxh += pixh + DiagYMergin;
+
+   /* create status window */
+   if(winstat != -1) disposediagbox();
+@@ -367,6 +388,11 @@ void showdiagbox(void)
+              gcstat,
+              DiagXMergin, fontp->ascent+DiagYMergin,
+              diagmsg, strlen(diagmsg));
++  if (displayclock)
++    XDrawString(disp, winstat, gcstat,
++               boxw/2 - XTextWidth(fontp, timemsg, strlen(timemsg))/2,
++               2*fontp->ascent+2*DiagYMergin,
++               timemsg, strlen(timemsg));
+ }
+
+ void disposediagbox(void)
+@@ -575,7 +601,7 @@ void battery_check(void)
 
  #endif /* __FreeBSD__ */
 
Index: patches/patch-xbattbar_man
===================================================================
RCS file: patches/patch-xbattbar_man
diff -N patches/patch-xbattbar_man
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-xbattbar_man 3 Apr 2012 19:53:21 -0000
@@ -0,0 +1,21 @@
+$OpenBSD$
+--- xbattbar.man.orig Tue Apr  3 23:51:58 2012
++++ xbattbar.man Tue Apr  3 23:52:03 2012
+@@ -32,6 +32,7 @@
+ .Op Fl O Ar color
+ .Op Fl i Ar color
+ .Op Fl o Ar color
++.Op Fl T Ar time-format
+ .Op Ar top | bottom | left | right
+ .Sh DESCRIPTION
+ .Nm xbattbar
+@@ -88,6 +89,9 @@ option sets the polling interval in second.
+ If the mouse cursor enters in the status indicator,
+ the diagnosis window appears in the center of the display,
+ which shows both AC line status and battery remaining level.
++.Nm -T
++option adds time and date display to the popup window.
++It accepts an optional strftime(3) format string argument.
+ This diagnosis window disappears if the mouse cursor leaves from
+ the status indicator.
+ .Sh SEE ALSO

--
Alexander Polakov | plhk.ru

Reply | Threaded
Open this post in threaded view
|

Re: sysutils/xbattbar patch to add time & date display

Bryan Steele-2
On Wed, Apr 04, 2012 at 12:06:09AM +0400, Alexander Polakov wrote:
> Brynet (maintainer) suggested to send this to ports@.
>
> This patch adds an option (-T) to display time and date in
> xbattbar's popup window.
> Personally, I find this very useful: I don't have to run any
> other panel anymore. While there, I added headers to fix some
> of the the warnings. Not sure if it's okay to add functionality
> like this to ports, though, but upstream is not responding to
> mails.

Upstream hasn't released an update since 2000/2001.

If anyone has a laptop, you might want to check out xbattbar, it isn't
nearly as invasive as some other battery monitoring utilities. Alex's
addition doesn't change that.

It fits well with cwm.

> Any comments, oks?

-Bryan.

Reply | Threaded
Open this post in threaded view
|

Re: sysutils/xbattbar patch to add time & date display

Daniel Bolgheroni-8
On Tue, Apr 03, 2012 at 07:28:28PM -0400, Brynet wrote:
>
> If anyone has a laptop, you might want to check out xbattbar, it isn't
> nearly as invasive as some other battery monitoring utilities. Alex's
> addition doesn't change that.

Didn't know about it. Using.

Thank you.

Reply | Threaded
Open this post in threaded view
|

Re: sysutils/xbattbar patch to add time & date display

Daniel Bolgheroni-8
In reply to this post by Bryan Steele-2
On Tue, Apr 03, 2012 at 07:28:28PM -0400, Brynet wrote:
>
> If anyone has a laptop, you might want to check out xbattbar, it isn't
> nearly as invasive as some other battery monitoring utilities. Alex's
> addition doesn't change that.

BTW, it "breaks" xlock if used with -a option.