diff options
author | awy <awy@awy.one> | 2025-09-11 17:35:32 +0300 |
---|---|---|
committer | awy <awy@awy.one> | 2025-09-11 17:35:32 +0300 |
commit | 75a1408e9d4e54af9695bc4eca650b35c22bcff2 (patch) | |
tree | e3efd40aa56b7b4d2f6fc1286ff9ac3e1ecc543a /lib/util.c | |
parent | 796c9495a537b17bb985e9950ae0fdec123c12f1 (diff) | |
download | statusbar-75a1408e9d4e54af9695bc4eca650b35c22bcff2.tar.gz |
BIG HAPPENING: notifications and spawn functionality
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]); + } +} |