xbattmon

simple battery monitor for X
git clone git://git.2f30.org/xbattmon.git
Log | Files | Refs | README | LICENSE

commit 6c3be656d2419700868788263fc36f533daa1a4a
parent d7ee2967d11f673af4d45ac8edaf2a5f4e690d44
Author: sin <sin@2f30.org>
Date:   Sun Nov  9 17:51:17 +0000

Add support for left/right placement

Diffstat:
xbattmon.1 | 6+++---
xbattmon.c | 57++++++++++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 49 insertions(+), 14 deletions(-)
diff --git a/xbattmon.1 b/xbattmon.1 @@ -1,4 +1,4 @@ -.Dd Nov 2, 2014 +.Dd Nov 9, 2014 .Dt XBATTMON 1 .Os .Sh NAME @@ -8,7 +8,7 @@ .Nm xbattmon .Op Fl c Ar capacity .Op Fl i Ar interval -.Op Fl p Ar bottom | top +.Op Fl p Ar bottom | top | left | right .Op Fl t Ar thickness .Sh DESCRIPTION .Nm @@ -22,7 +22,7 @@ a bar thickness of 2 pixels and a bottom placement. Set the maximum battery capacity. .It Fl i Ar interval Set the battery poll interval in seconds. -.It Fl p Ar bottom | top +.It Fl p Ar bottom | top | left | right Set the bar placement. .It Fl t Ar thickness Set the bar thickness. diff --git a/xbattmon.c b/xbattmon.c @@ -26,7 +26,9 @@ enum { enum { BOTTOM, - TOP + TOP, + LEFT, + RIGHT }; char *argv0; @@ -78,6 +80,18 @@ setup(void) barwidth = width; barheight = thickness; break; + case LEFT: + barx = 0; + bary = 0; + barwidth = thickness; + barheight = height; + break; + case RIGHT: + barx = width - thickness; + bary = 0; + barwidth = thickness; + barheight = height; + break; } winbar = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), barx, bary, barwidth, @@ -109,19 +123,36 @@ redraw(void) { int pos; - pos = barwidth * batcap / maxcap; + if (placement == BOTTOM || placement == TOP) + pos = barwidth * batcap / maxcap; + else + pos = barheight * batcap / maxcap; switch (state) { case AC_ON: - XSetForeground(dpy, gcbar, cmap[COLOR_BAT_CHARGED]); - XFillRectangle(dpy, winbar, gcbar, 0, 0, pos, thickness); - XSetForeground(dpy, gcbar, cmap[COLOR_BAT_LEFT2CHARGE]); - XFillRectangle(dpy, winbar, gcbar, pos, 0, barwidth, thickness); + if (placement == BOTTOM || placement == TOP) { + XSetForeground(dpy, gcbar, cmap[COLOR_BAT_CHARGED]); + XFillRectangle(dpy, winbar, gcbar, 0, 0, pos, thickness); + XSetForeground(dpy, gcbar, cmap[COLOR_BAT_LEFT2CHARGE]); + XFillRectangle(dpy, winbar, gcbar, pos, 0, barwidth, thickness); + } else { + XSetForeground(dpy, gcbar, cmap[COLOR_BAT_CHARGED]); + XFillRectangle(dpy, winbar, gcbar, 0, barheight - pos, thickness, barheight); + XSetForeground(dpy, gcbar, cmap[COLOR_BAT_LEFT2CHARGE]); + XFillRectangle(dpy, winbar, gcbar, 0, 0, thickness, barheight - pos); + } break; case AC_OFF: - XSetForeground(dpy, gcbar, cmap[COLOR_BAT_LEFT2DRAIN]); - XFillRectangle(dpy, winbar, gcbar, 0, 0, pos, thickness); - XSetForeground(dpy, gcbar, cmap[COLOR_BAT_DRAINED]); - XFillRectangle(dpy, winbar, gcbar, pos, 0, barwidth, thickness); + if (placement == BOTTOM || placement == TOP) { + XSetForeground(dpy, gcbar, cmap[COLOR_BAT_LEFT2DRAIN]); + XFillRectangle(dpy, winbar, gcbar, 0, 0, pos, thickness); + XSetForeground(dpy, gcbar, cmap[COLOR_BAT_DRAINED]); + XFillRectangle(dpy, winbar, gcbar, pos, 0, barwidth, thickness); + } else { + XSetForeground(dpy, gcbar, cmap[COLOR_BAT_LEFT2DRAIN]); + XFillRectangle(dpy, winbar, gcbar, 0, barheight - pos, thickness, barheight); + XSetForeground(dpy, gcbar, cmap[COLOR_BAT_DRAINED]); + XFillRectangle(dpy, winbar, gcbar, 0, 0, thickness, barheight - pos); + } break; } XFlush(dpy); @@ -235,7 +266,7 @@ loop(void) void usage(void) { - fprintf(stderr, "usage: %s [-c capacity] [-i interval] [-p bottom | top] [-t thickness]\n", argv0); + fprintf(stderr, "usage: %s [-c capacity] [-i interval] [-p bottom | top | left | right] [-t thickness]\n", argv0); fprintf(stderr, " -c\tspecify battery capacity\n"); fprintf(stderr, " -i\tbattery poll interval in seconds\n"); fprintf(stderr, " -p\tbar placement\n"); @@ -268,6 +299,10 @@ main(int argc, char *argv[]) placement = BOTTOM; else if (strcmp(arg, "top") == 0) placement = TOP; + else if (strcmp(arg, "left") == 0) + placement = LEFT; + else if (strcmp(arg, "right") == 0) + placement = RIGHT; else errx(1, "%s: invalid placement", arg); break;