diff options
Diffstat (limited to 'lib/util.c')
-rw-r--r-- | lib/util.c | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -2,6 +2,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <libnotify/notify.h> #include "util.h" @@ -23,3 +24,48 @@ die(const char *fmt, ...) exit(1); } + +void +sendnotif(const char *appname, const char *title, const char *body) +{ + notify_init(appname); + + NotifyNotification *n; + n = notify_notification_new(title, body, NULL); + + notify_notification_show(n, NULL); + + g_object_unref(G_OBJECT(n)); + notify_uninit(); +} + +int +getbtnint(const char *blkbtn) +{ + char *endptr; + int errno; + long val; + + errno = 0; + + if (blkbtn == NULL) + return 0; + + val = strtol(blkbtn, &endptr, 10); + + if (errno == 0 && *endptr == '\0' && val >= 1 && val <= 8) + return (int)val; + + return 0; +} + +void +spawn(const char *const argv[]) +{ + if (fork() == 0) { + dup2(STDERR_FILENO, STDOUT_FILENO); + setsid(); + execvp(argv[0], (char * const *)argv); + die("spawn %s failed:", (argv)[0]); + } +} |