commit 3cb1da6eee93e7ff11ecccdfa0cd2aeab95675f0
parent b887c76fbf2f673f6777769965348106854e4fcb
Author: Christos Margiolis <christos@margiolis.net>
Date: Sun, 10 Apr 2022 17:52:18 +0300
added duration flag
Diffstat:
3 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/config.h b/config.h
@@ -12,7 +12,7 @@ static const char *fontcolor = "#e6e5e3"; /* Font color */
static const char *fonts = "monospace:size=12"; /* Fonts */
static const unsigned int padding = 10; /* Padding (pixels) */
static const unsigned int borderw = 3; /* Border width (pixels) */
-static const unsigned int duration = 3; /* Notification duration (seconds) */
+static unsigned int duration = 3; /* Notification duration (seconds) */
static const unsigned int pos = TOP_RIGHT; /* Window position */
static const unsigned int mx = 10; /* Margin X (pixels) */
static const unsigned int my = 25; /* Margin Y (pixels) */
diff --git a/nfy.1 b/nfy.1
@@ -6,6 +6,7 @@
.Nd a minimal and daemonless notification program for X
.Sh SYNOPSIS
.Nm
+.Op Fl d Ar duraton
.Op Fl v
.Sh DESCRIPTION
.Nm
@@ -24,6 +25,9 @@ This is especially useful inside scripts.
handles multiple notifications by queuing them using a lock file.
.Sh OPTIONS
.Bl -tag -width Ds
+.It Fl d Ar duration
+Specify the duration of the notification. The default duration value is \
+specified in 'config.h'.
.It Fl v
prints version to stdout and exits.
.El
diff --git a/nfy.c b/nfy.c
@@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */
#include <err.h>
+#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdarg.h>
@@ -60,7 +61,7 @@ sighandler(int sig)
static void
usage(void)
{
- fprintf(stderr, "usage: %s [-v]\n", argv0);
+ fprintf(stderr, "usage: %s [-d duration] [-v]\n", argv0);
exit(1);
}
@@ -88,8 +89,15 @@ main(int argc, char *argv[])
char buf[MAXLEN+1], ch;
argv0 = *argv;
- while ((ch = getopt(argc, argv, "v")) != -1) {
+ while ((ch = getopt(argc, argv, "d:v")) != -1) {
switch (ch) {
+ case 'd':
+ duration = strtol(optarg, NULL, 10);
+ if (errno == EINVAL || errno == ERANGE)
+ err(1, "strtol(%s)", optarg);
+ if (duration < 1)
+ errx(1, "duration has to be more than 1 second");
+ break;
case 'v':
fprintf(stderr, "%s-"VERSION"\n", argv0);
exit(1);