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

View File

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

14
spt.c
View File

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