summaryrefslogtreecommitdiff
path: root/slstatus.c
diff options
context:
space:
mode:
authorAaron Marcher <info@nulltime.net>2016-09-16 23:31:24 +0200
committerAaron Marcher (drkhsh) <info@nulltime.net>2016-09-16 23:31:24 +0200
commit87eae6db0398ec1ddb98d67fea36339ff58eb2a5 (patch)
treeed09f2b08a26f360cc1c9bb27a83feca635dcf82 /slstatus.c
parent887b9bd3e37304d469845454f390cbf13198799d (diff)
added daemonization, output possibility to console (for other programs) and moved the code to set WM_NAME to its own function as it is needed two times
Diffstat (limited to 'slstatus.c')
-rw-r--r--slstatus.c56
1 files changed, 50 insertions, 6 deletions
diff --git a/slstatus.c b/slstatus.c
index 7dee542..be124f3 100644
--- a/slstatus.c
+++ b/slstatus.c
@@ -26,6 +26,7 @@
#undef strlcat
#undef strlcpy
+#include "arg.h"
#include "strlcat.h"
#include "strlcpy.h"
#include "concat.h"
@@ -64,9 +65,12 @@ static char *username(void);
static char *vol_perc(const char *);
static char *wifi_perc(const char *);
static char *wifi_essid(const char *);
+static void set_status(const char *);
static void sighandler(const int);
+static void usage(void);
-static unsigned short int delay, done;
+char *argv0;
+static unsigned short int delay, done, dflag, oflag;
static Display *dpy;
#include "config.h"
@@ -580,14 +584,33 @@ wifi_essid(const char *wificard)
}
static void
+set_status(const char *str)
+{
+ XStoreName(dpy, DefaultRootWindow(dpy), str);
+ XSync(dpy, False);
+}
+
+static void
sighandler(const int signo)
{
if (signo == SIGTERM || signo == SIGINT)
done = 1;
}
+static void
+usage(void)
+{
+ fprintf(stderr,
+ "slstatus (c) 2016, drkhsh\n"
+ "usage: %s [-dho]\n",
+ argv0);
+ exit(1);
+}
+
+
+
int
-main(void)
+main(int argc, char *argv[])
{
unsigned short int i;
char status_string[4096];
@@ -595,6 +618,22 @@ main(void)
struct arg argument;
struct sigaction act;
+ ARGBEGIN {
+ case 'd':
+ dflag = 1;
+ break;
+ case 'o':
+ oflag = 1;
+ break;
+ default:
+ usage();
+ } ARGEND
+
+ if (dflag && oflag)
+ usage();
+ if (dflag)
+ (void)daemon(1, 1);
+
memset(&act, 0, sizeof(act));
act.sa_handler = sighandler;
sigaction(SIGINT, &act, 0);
@@ -604,6 +643,7 @@ main(void)
while (!done) {
status_string[0] = '\0';
+
for (i = 0; i < sizeof(args) / sizeof(args[0]); ++i) {
argument = args[i];
if (argument.args == NULL)
@@ -619,8 +659,12 @@ main(void)
free(res);
free(element);
}
- XStoreName(dpy, DefaultRootWindow(dpy), status_string);
- XSync(dpy, False);
+
+ if (!oflag)
+ set_status(status_string);
+ else
+ printf("%s\n", status_string);
+
/*
* subtract delay time spend in function
* calls from the actual global delay time
@@ -629,8 +673,8 @@ main(void)
delay = 0;
}
- XStoreName(dpy, DefaultRootWindow(dpy), NULL);
- XSync(dpy, False);
+ if (!oflag)
+ set_status(NULL);
XCloseDisplay(dpy);