summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--binstatus.c78
-rw-r--r--components.c30
-rw-r--r--components.h1
-rw-r--r--config.h2
4 files changed, 41 insertions, 70 deletions
diff --git a/binstatus.c b/binstatus.c
index edce1ec..6211c07 100644
--- a/binstatus.c
+++ b/binstatus.c
@@ -19,71 +19,13 @@
#include <unistd.h>
#include <time.h>
#include <X11/Xlib.h>
-
-#define MAXLENGTH 256
-int binary = 1; /* 0 = decimal display, 1 = binary display */
-int miltime = 0; /* 0 = 12 hour time, 1 = 24 hour time */
-
-int
-dectobin(int dec)
-{
- if (dec == 0) return 0;
- if (dec == 1) return 1;
- return (dec % 2) + 10 * dectobin(dec / 2);
-}
-
-void
-gettime(int *store)
-{
- time_t t = time(NULL);
- struct tm *tm = localtime(&t);
- store[0] = tm->tm_hour;
- store[1] = tm->tm_min;
-}
-
-void
-formatstring(char *status, int *time)
-{
- if (binary)
- {
-
- snprintf(status, MAXLENGTH, "%05d %06d", dectobin(time[0]),
- dectobin(time[1]));
- }
- else
- {
- snprintf(status, MAXLENGTH, "%02d:%02d", time[0], time[1]);
- }
-}
-
-int
-converthour(int hour)
-{
- return (hour - 12 < 0) ? 0 : hour - 12;
-}
+#include "components.h"
+#include "config.h"
int
-main(int argc, char *argv[])
+main(void)
{
- for (int c = 1; c < argc; c++)
- {
- if (argc >= 2)
- {
- if (strcmp(argv[c], "-d") == 0)
- binary = 0;
- else if (strcmp(argv[c], "-m") == 0)
- miltime = 1;
- else
- {
- printf("usage: %s [-d] [-m]\n-d: decimal output\n"
- "-m: 24-hour format\n", argv[0]);
- exit(EXIT_SUCCESS);
- }
- }
- }
- int exitflag = EXIT_SUCCESS;
- char status[MAXLENGTH];
- int time[2];
+ char status[MAXLENGTH] = "";
Display *dsp = XOpenDisplay(NULL);
if(!dsp)
{
@@ -92,14 +34,16 @@ main(int argc, char *argv[])
}
while (1)
{
- gettime(time);
- if (!miltime && time[0] > 12)
- time[0] = converthour(time[0]);
- formatstring(status, time);
+ memset(status, 0, sizeof(status));
+ for (size_t i = 0; i < sizeof(components)/sizeof(components[0]); i++)
+ {
+ char store[20];
+ strncat(status, components[i].function(store, sizeof(store), components[i].flag), sizeof(store));
+ }
XStoreName(dsp, DefaultRootWindow(dsp), status);
XFlush(dsp);
sleep(1);
}
XCloseDisplay(dsp);
- return exitflag;
+ return 0;
}
diff --git a/components.c b/components.c
index a8a27db..09c1fc0 100644
--- a/components.c
+++ b/components.c
@@ -14,6 +14,8 @@
*/
#include "components.h"
+#include "config.h"
+
int
dectobin(int dec)
{
@@ -51,8 +53,22 @@ char *currenttime(char *store, size_t size, int flag)
{
int time[2];
gettime(time);
- snprintf(store, size, "%02d:%02d ", time[0], time[1]);
- return store;
+ if (flag & NORMALTIME)
+ {
+ if (time[0] > 12)
+ time[0] = converthour(time[0]);
+ }
+ if (flag & BINARYTIME)
+ {
+ snprintf(store, size, "%05d:%05d ", dectobin(time[0]),
+ dectobin(time[1]));
+ }
+ /* military time is the default, so we need not do anything */
+ else
+ {
+ snprintf(store, size, "%02d:%02d ", time[0], time[1]);
+ }
+ return store;
}
char *battery(char *store, size_t size, int flag)
@@ -83,7 +99,17 @@ char *charging(char *store, size_t size, int flag)
}
fgets(cap, 15, state);
eat(cap, strlen(cap));
+ /* my thinkpad says "Unknown" when charged ... */
+ if (strcmp(cap, "Unknown") == 0) strcpy(cap, "⚡F");
+ if (strcmp(cap, "Charged") == 0) strcpy(cap, "⚡F");
+ if (strcmp(cap, "Charging") == 0) strcpy(cap, "⚡C");
+ if (strcmp(cap, "Discharging") == 0) strcpy(cap, "⚡D");
fclose(state);
snprintf(store, size, "%s ", cap);
return store;
}
+
+char *remainingtime(char *store, size_t size, int flag)
+{
+ return store;
+}
diff --git a/components.h b/components.h
index bf3bc79..8af712e 100644
--- a/components.h
+++ b/components.h
@@ -25,5 +25,6 @@
char *currenttime(char *store, size_t size, int flag);
char *battery(char *store, size_t size, int flag);
char *charging(char *store, size_t size, int flag);
+char *remainingtime(char *store, size_t size, int flag);
#endif
diff --git a/config.h b/config.h
index bb0e59a..b006afd 100644
--- a/config.h
+++ b/config.h
@@ -35,7 +35,7 @@ struct component
* add or remove components as desired
* components are shown in the order of this array
*/
-struct component components[] ={
+static const struct component components[] ={
/* function flag */
{currenttime, NORMALTIME},
{battery, 0},