summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--lib/util.c46
-rw-r--r--lib/util.h3
-rw-r--r--src/stclock.c39
4 files changed, 92 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index d8239c0..824b81d 100644
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,9 @@ BINDIR := $(HOME)/.local/bin/statusbar
SRCS := $(wildcard $(SRCDIR)/*.c)
PROGS := $(patsubst $(SRCDIR)/%.c,$(BINDIR)/%,$(SRCS))
+NOTIFY_CFLAGS := $(shell pkg-config --cflags libnotify)
+NOTIFY_LIBS := $(shell pkg-config --libs libnotify)
+
.PHONY: all clean
all: $(BINDIR) $(PROGS)
@@ -27,7 +30,7 @@ $(BINDIR)/stweath: $(SRCDIR)/stweath.c | $(BINDIR)
$(CC) $(CFLAGS) -o $@ lib/util.c lib/cjson/cJSON.c $< -lcurl
$(BINDIR)/%: $(SRCDIR)/%.c | $(BINDIR)
- $(CC) $(CFLAGS) -o $@ lib/util.c $<
+ $(CC) $(CFLAGS) $(NOTIFY_CFLAGS) -o $@ lib/util.c $< $(NOTIFY_LIBS)
clean:
rm -f $(PROGS)
diff --git a/lib/util.c b/lib/util.c
index 1fe30da..0c22adf 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <libnotify/notify.h>
#include "util.h"
@@ -23,3 +24,48 @@ die(const char *fmt, ...)
exit(1);
}
+
+void
+sendnotif(const char *appname, const char *title, const char *body)
+{
+ notify_init(appname);
+
+ NotifyNotification *n;
+ n = notify_notification_new(title, body, NULL);
+
+ notify_notification_show(n, NULL);
+
+ g_object_unref(G_OBJECT(n));
+ notify_uninit();
+}
+
+int
+getbtnint(const char *blkbtn)
+{
+ char *endptr;
+ int errno;
+ long val;
+
+ errno = 0;
+
+ if (blkbtn == NULL)
+ return 0;
+
+ val = strtol(blkbtn, &endptr, 10);
+
+ if (errno == 0 && *endptr == '\0' && val >= 1 && val <= 8)
+ return (int)val;
+
+ return 0;
+}
+
+void
+spawn(const char *const argv[])
+{
+ if (fork() == 0) {
+ dup2(STDERR_FILENO, STDOUT_FILENO);
+ setsid();
+ execvp(argv[0], (char * const *)argv);
+ die("spawn %s failed:", (argv)[0]);
+ }
+}
diff --git a/lib/util.h b/lib/util.h
index 9ecc499..84c5d36 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -1 +1,4 @@
void die(const char *, ...);
+void sendnotif(const char *, const char *, const char *);
+int getbtnint(const char *blkbtn);
+void spawn(const char *const argv[]);
diff --git a/src/stclock.c b/src/stclock.c
index 22dae6a..ef63fe6 100644
--- a/src/stclock.c
+++ b/src/stclock.c
@@ -14,17 +14,56 @@
License along with stclock. If not, see
<https://www.gnu.org/licenses/>. */
+#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include "../lib/util.h"
+void
+buttonhandler()
+{
+ char *term;
+ char *env;
+ int button;
+
+ button = 0;
+ if ((env = getenv("BLOCK_BUTTON")))
+ button = getbtnint(env);
+
+
+ if (!(term = getenv("TERMINAL")))
+ term = "footclient";
+
+ const char *termcmd[] = { term, "-e", "calcurse", NULL };
+
+ switch (button) {
+ case 1:
+ sendnotif("stclock", "This Month",
+ "there should be calendar but you know how we doing");
+ break;
+ case 2:
+ spawn(termcmd);
+ break;
+ case 3:
+ sendnotif("stclock", " Time/date module",
+ "- Left click to show upcoming \
+appointments for the next three days\
+via `calcurse -d3` and show the month via `cal`\n\
+- Middle click opens calcurse if installed");
+ break;
+ default: break;
+ }
+}
+
int
main(void)
{
time_t t;
char buf[64];
+ buttonhandler();
+
t = time(NULL);
if (!strftime(buf, sizeof(buf), "%F %T", localtime(&t)))
die("strftime: Result string exceeds buffer size");