pomo

A simple pomodoro timer
Log | Files | Refs | README | LICENSE

commit 2502641ce2068dabd724099023025f14aad3513d
parent cafb6102dbf20da051ea75e028bbef7d12a4478e
Author: Ivan Tham <pickfire@riseup.net>
Date:   Fri, 13 May 2016 23:13:23 +0800

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

Diffstat:
Mconfig.def.h | 4++--
Mconfig.mk | 11+++++------
Mspt.c | 14+++++++++-----
3 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -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) */ /* diff --git a/config.mk b/config.mk @@ -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 diff --git a/spt.c b/spt.c @@ -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);