Fix spt on OSX (no libnotify)

- Thanks for the person who reviewed my code & gave suggestion
    - Fork notify_send() directly
    - What's next? Parallel timer
This commit is contained in:
Ivan Tham 2016-05-13 23:13:23 +08:00
parent cafb6102db
commit 2502641ce2
3 changed files with 16 additions and 13 deletions

View File

@ -1,7 +1,7 @@
/* See LICENSE file for copyright and license details. */
/* Notification */
static char *notifycmd = "libnotify"; /* Use libnotify or given command */
/* Notification, replace libnotify if you don't want it */
static char *notifycmd = "libnotify"; /* Use libnotify or command given*/
static char *notifyext = ""; /* Notify with extra command (eg. play an alarm) */
/*

View File

@ -7,15 +7,14 @@ VERSION = 0.1
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man
# includes and libs
INCS = -I. -I/usr/include \
`pkg-config --cflags libnotify`
LIBS = -L/usr/lib \
`pkg-config --libs libnotify`
# libnotify - comment if you don't want it (config.h too)
INCS = -I. -I/usr/include `pkg-config --cflags libnotify`
LIBS = -L/usr/lib `pkg-config --libs libnotify`
DEFS = -DNOTIFY
# flags
CPPFLAGS = -DVERSION=\"${VERSION}\"
CFLAGS += -g -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
CFLAGS += -g -std=c99 -pedantic -Wall -Os ${INCS} ${DEFS} ${CPPFLAGS}
LDFLAGS += -g ${LIBS}
# compiler and linker

14
spt.c
View File

@ -5,8 +5,9 @@
#include <string.h>
#include <unistd.h>
#include <signal.h>
#ifdef NOTIFY
#include <libnotify/notify.h>
#endif /* NOTIFY */
#include "arg.h"
@ -59,20 +60,21 @@ void
notify_send(char *cmt)
{
if (!strcmp(notifycmd, "libnotify")) { /* use libnotify */
#ifdef NOTIFY
notify_init("spt");
NotifyNotification *n = notify_notification_new("spt", cmt, "dialog-information");
NotifyNotification *n = notify_notification_new("spt", cmt, \
"dialog-information");
notify_notification_show(n, NULL);
g_object_unref(G_OBJECT(n));
notify_uninit();
#endif /* NOTIFY */
} else if (strcmp(notifycmd, "")) {
/* TODO(pickfire): merge this into spawn() */
if (fork() == 0) {
setsid();
execlp(notifycmd, "spt", cmt, NULL);
fprintf(stderr, "spt: execlp %s", notifycmd);
perror(" failed");
exit(0);
}
}
if (strcmp(notifyext, "")) /* extra commands to use */
@ -123,7 +125,9 @@ main(int argc, char *argv[])
}
run:
notify_send(timers[i].cmt);
if (fork() == 0) {
notify_send(timers[i].cmt);
}
for (timecount = 0; timecount < timers[i].tmr; timecount++) {
sleep(1);