diff options
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | binstatus.c | 43 |
2 files changed, 46 insertions, 8 deletions
@@ -1,4 +1,11 @@ -By default this program will set your root windows name to the time in binary, however if you run with -d it will display the time in decimal (HH:MM). +This program sets your X servers root window name as the current time in 12-hour binary. This allows dwm (and possibly other) window managers use it in their status bar. I use it with dwm as a clock to practice recognising binary numbers quickly. + +argumewnts: + +````-d: display time in decimal format (HH:MM)```` + + +````-m: Use the 24-hour time format```` compile: @@ -9,4 +16,4 @@ run: ````./binstatus &```` -You may prefer to put this in your .xinitrc file. +You may prefer to put this in your .xinitrc file and move the binary to somewhere like /usr/bin. diff --git a/binstatus.c b/binstatus.c index a5b1d33..860529c 100644 --- a/binstatus.c +++ b/binstatus.c @@ -22,6 +22,7 @@ #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) @@ -56,16 +57,44 @@ formatstring(char *status, int *time) } int +converthour(int hour) +{ + // is there a better way? + switch (hour) + { + case 0:return 12; + case 13: return 1; + case 14: return 2; + case 15: return 3; + case 16: return 5; + case 17: return 6; + case 18: return 7; + case 19: return 8; + case 20: return 9; + case 21: return 10; + case 22: return 11; + case 23: return 12; + default: return 0; + } +} + +int main(int argc, char *argv[]) { - if (argc >= 2) + for (int c = 1; c < argc; c++) { - if (strcmp(argv[1], "-d") == 0) - binary = 0; - else + if (argc >= 2) { - printf("usage: %s [-d]\n", argv[0]); - exit(EXIT_SUCCESS); + 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; @@ -80,6 +109,8 @@ main(int argc, char *argv[]) while (1) { gettime(time); + if (!miltime) + time[0] = converthour(time[0]); formatstring(status, time); XStoreName(dsp, DefaultRootWindow(dsp), status); XFlush(dsp); |