diff options
author | Don Stewart <dons@cse.unsw.edu.au> | 2007-06-09 10:04:35 +0200 |
---|---|---|
committer | Don Stewart <dons@cse.unsw.edu.au> | 2007-06-09 10:04:35 +0200 |
commit | 2bea3d632a6197b250969981b53dd709ccbeffd2 (patch) | |
tree | 4bd61a5febaf229aa86bcfb4600cd56df666a7c7 | |
parent | c39701cba088968695d996afb457164396eb3e0a (diff) | |
download | XMonadContrib-2bea3d632a6197b250969981b53dd709ccbeffd2.tar.gz XMonadContrib-2bea3d632a6197b250969981b53dd709ccbeffd2.tar.xz XMonadContrib-2bea3d632a6197b250969981b53dd709ccbeffd2.zip |
add tiny clock program (C) i'm using in the status bar
darcs-hash:20070609080435-9c5c1-4e1adf8a835568fa160fdd167047ecdb039b0953.gz
-rw-r--r-- | scripts/clock.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/scripts/clock.c b/scripts/clock.c new file mode 100644 index 0000000..77868d7 --- /dev/null +++ b/scripts/clock.c @@ -0,0 +1,64 @@ +/* +dwm status bar provider. use as ~/.xinitrc or call it in your xinitrc +or xsession in place of dwm. + +to compile: gcc -Os -s -o dwm-status dwm-status.c + +Copyright (c) 2007, Tom Menari <tom dot menari at googlemail dot com> +Copyright (c) 2007, Don Stewart + +Permission to use, copy, modify, and distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include <stdio.h> +#include <time.h> +#include <unistd.h> +#include <stdlib.h> +#include <signal.h> + +/* configuration */ +#define REFRESH_RATE 60 +#define TIME_FORMAT "%H.%M %a %b %d" +#define TIME_FORMAT2 "PDT %H.%M" + +int main(void) { + char b[34]; + char c[34]; + time_t epochtime; + struct tm *realtime; + + time_t pdttime; + struct tm *pdtrealtime; + + double load; + + signal(SIGPIPE, SIG_IGN); + + for(;;) { + getloadavg(&load, 1); + + epochtime = time(NULL); + realtime = localtime(&epochtime); + strftime(b, sizeof(b), TIME_FORMAT, realtime); + + setenv("TZ","America/Los_Angeles", 1); + pdttime = time(NULL); + pdtrealtime = localtime(&pdttime); + strftime(c, sizeof(c), TIME_FORMAT2, pdtrealtime); + + fprintf(stdout, "%s | %s | %.2f | xmonad 0.3 \n", b, c, load); + fflush(stdout); + sleep(REFRESH_RATE); + } + return EXIT_SUCCESS; +} |