aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2015-03-20 10:20:45 +0100
committerGravatar Christian Hesse <mail@eworm.de>2015-03-20 10:20:45 +0100
commit3a942fea6c4fc10175933d804ab02354635813e5 (patch)
treeec4349b8372290ad9a8a94c8130b9eb5b93d7829
parentaafd09a9dafa666da0a4699c4cbaa81ed6e79ee4 (diff)
downloadjournal-notify-3a942fea6c4fc10175933d804ab02354635813e5.tar.gz
journal-notify-3a942fea6c4fc10175933d804ab02354635813e5.tar.zst
allow to specify notification display timeout
-rw-r--r--README.md1
-rw-r--r--journal-notify.c20
-rw-r--r--journal-notify.h2
3 files changed, 18 insertions, 5 deletions
diff --git a/README.md b/README.md
index 05d3a38..8b8652b 100644
--- a/README.md
+++ b/README.md
@@ -59,6 +59,7 @@ Be warned: This can flood your disktop with notifications.
* *-n*: no case sensitive regular expressions
* *-o*: combine matches with a logical OR
* *-r REGEX*: This add a regular expression match for the message field.
+* *-t SECONDS*: seconds to show the notification, 0 is forever
* *-v* verbose output, can be specified multiple times
The screenshot shown above resulted from this command:
diff --git a/journal-notify.c b/journal-notify.c
index ef4fd83..1cf12e9 100644
--- a/journal-notify.c
+++ b/journal-notify.c
@@ -9,7 +9,7 @@
const char * program = NULL;
-const static char optstring[] = "aehi:m:nor:v";
+const static char optstring[] = "aehi:m:nor:t:v";
const static struct option options_long[] = {
/* name has_arg flag val */
{ "and", no_argument, NULL, 'a' },
@@ -20,12 +20,13 @@ const static struct option options_long[] = {
{ "no-case", no_argument, NULL, 'n' },
{ "or", no_argument, NULL, 'o' },
{ "regex", required_argument, NULL, 'r' },
+ { "timeout", required_argument, NULL, 't' },
{ "verbose", no_argument, NULL, 'v' },
{ 0, 0, 0, 0 }
};
/*** notify ***/
-int notify(const char * summary, const char * body, const char * icon) {
+int notify(const char * summary, const char * body, const char * icon, int timeout) {
NotifyNotification * notification;
int rc = -1;
@@ -39,6 +40,10 @@ int notify(const char * summary, const char * body, const char * icon) {
if (notification == NULL)
return rc;
+ /* NOTIFY_EXPIRES_NEVER == 0 */
+ if (timeout >= 0)
+ notify_notification_set_timeout(notification, timeout * 1000);
+
if (notify_notification_show(notification, NULL) == FALSE)
goto out;
@@ -65,6 +70,7 @@ int main(int argc, char **argv) {
char * summary, * message;
const char * icon = DEFAULTICON;
+ int timeout = -1;
program = argv[0];
@@ -76,7 +82,7 @@ int main(int argc, char **argv) {
regex_flags |= REG_EXTENDED;
break;
case 'h':
- fprintf(stderr, "usage: %s [-e] [-h] [-i ICON] [-m MATCH] [-o -m MATCH] [-a -m MATCH] [-n] [-r REGEX] [-vv]\n", program);
+ fprintf(stderr, "usage: %s [-e] [-h] [-i ICON] [-m MATCH] [-o -m MATCH] [-a -m MATCH] [-n] [-r REGEX] [-t SECONDS] [-vv]\n", program);
return EXIT_SUCCESS;
case 'n':
regex_flags |= REG_ICASE;
@@ -165,6 +171,12 @@ int main(int argc, char **argv) {
have_regex++;
break;
+ case 't':
+ timeout = atoi(optarg);
+ if (verbose > 1)
+ printf("Notifications will be displayed for %d seconds.\n", timeout);
+
+ break;
}
}
@@ -211,7 +223,7 @@ int main(int argc, char **argv) {
if (verbose > 0)
printf("Showing notification: %s: %s\n", summary, message);
- if ((rc = notify(summary, message, icon)) == 0)
+ if ((rc = notify(summary, message, icon, timeout)) == 0)
break;
fprintf(stderr, "Failed to show notification, reinitializing libnotify.\n");
diff --git a/journal-notify.h b/journal-notify.h
index af69f58..fee950f 100644
--- a/journal-notify.h
+++ b/journal-notify.h
@@ -26,7 +26,7 @@
#define DEFAULTICON "dialog-information"
/*** notify ***/
-int notify(const char * summary, const char * body, const char * icon);
+int notify(const char * summary, const char * body, const char * icon, int timeout);
/*** main ***/
int main(int argc, char **argv);