Skip to content
This repository has been archived by the owner on Jan 5, 2018. It is now read-only.

Commit

Permalink
implement clock
Browse files Browse the repository at this point in the history
  • Loading branch information
Unia committed Apr 12, 2014
1 parent 1bf9a76 commit 85c4379
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 18 additions & 2 deletions dwmst.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <unistd.h>
#include <time.h>
#include <X11/Xlib.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -164,6 +165,20 @@ get_batt(void) {
}
}

char *
get_time(void) {
char clock[38];
time_t current;

memset(clock, 0, sizeof(clock));
time(&current);

if(!strftime(clock, sizeof(clock) - 1, CLK_STR, localtime(&current)))
return smprintf("%s", "strftime == 0");

return smprintf("%s", clock);
}

void
setstatus(char *str) {
XStoreName(dpy, DefaultRootWindow(dpy), str);
Expand All @@ -177,7 +192,7 @@ main(void) {
DBusGProxy *session = NULL;
DBusGConnection *conn = NULL;
int sockfd, netloops = 60, musicloops = 60;
char *status, *aud, *skype, *net, *vol, *batt;
char *status, *aud, *skype, *net, *vol, *batt, *clk;

if(!(dpy = XOpenDisplay(NULL))) {
fprintf(stderr, "dwmst: cannot open display.\n");
Expand All @@ -204,7 +219,8 @@ main(void) {
net = get_net(wreq, sockfd);
vol = get_vol(handle);
batt = get_batt();
status = smprintf("%s %s %s %s %s", aud, skype, net, vol, batt);
clk = get_time();
status = smprintf("%s %s %s %s %s %s", aud, skype, net, vol, batt, clk);
setstatus(status);
if(++musicloops > 60 && session != NULL)
free(aud);
Expand Down
2 changes: 2 additions & 0 deletions dwmst.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@
#define BAT_CHRG_STR "C %d%%, %02d:%02d"
#define BAT_UNK_STR "U"
#define NO_BAT_STR "N"

#define CLK_STR "%a %d %b, %R"

0 comments on commit 85c4379

Please sign in to comment.