commit fe45e94f33176e1f80a5e6ad0fd8eb1e2a42b59e
parent 6c3be656d2419700868788263fc36f533daa1a4a
Author: sin <sin@2f30.org>
Date: Sun, 9 Nov 2014 17:56:48 +0000
Simplify redraw()
Diffstat:
M | xbattmon.c | | | 48 | +++++++++++++++++++++--------------------------- |
1 file changed, 21 insertions(+), 27 deletions(-)
diff --git a/xbattmon.c b/xbattmon.c
@@ -122,39 +122,33 @@ void
redraw(void)
{
int pos;
+ unsigned long *done, *left;
if (placement == BOTTOM || placement == TOP)
pos = barwidth * batcap / maxcap;
else
pos = barheight * batcap / maxcap;
- switch (state) {
- case AC_ON:
- 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:
- 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;
+
+ if (state == AC_ON) {
+ done = &cmap[COLOR_BAT_CHARGED];
+ left = &cmap[COLOR_BAT_LEFT2CHARGE];
+ } else {
+ done = &cmap[COLOR_BAT_LEFT2DRAIN];
+ left = &cmap[COLOR_BAT_DRAINED];
+ }
+
+ if (placement == BOTTOM || placement == TOP) {
+ XSetForeground(dpy, gcbar, *done);
+ XFillRectangle(dpy, winbar, gcbar, 0, 0, pos, thickness);
+ XSetForeground(dpy, gcbar, *left);
+ XFillRectangle(dpy, winbar, gcbar, pos, 0, barwidth, thickness);
+ } else {
+ XSetForeground(dpy, gcbar, *done);
+ XFillRectangle(dpy, winbar, gcbar, 0, barheight - pos, thickness, barheight);
+ XSetForeground(dpy, gcbar, *left);
+ XFillRectangle(dpy, winbar, gcbar, 0, 0, thickness, barheight - pos);
}
+
XFlush(dpy);
}