circo

claudio's IRC oasis
git clone git://git.bitsmanent.org/circo
Log | Files | Refs | README | LICENSE

commit 26773aca068667bd054884f578c85d23bba548ee
parent fa6bdd1cca5a833f2ca7a0564472c6d3956f4aed
Author: Claudio Alessi <smoppy@gmail.com>
Date:   Wed, 27 Apr 2022 16:16:07 +0200

Spawn a custom script as notify occurs.

Diffstat:
Mcirco.c | 47+++++++++++++++++++++++++++++++++++++++++------
Acirco_notify.ogg | 0
Acirco_notify.sh | 16++++++++++++++++
Mconfig.def.h | 3+++
4 files changed, 60 insertions(+), 6 deletions(-)

diff --git a/circo.c b/circo.c @@ -24,6 +24,8 @@ #include <sys/ioctl.h> #include <sys/select.h> #include <sys/socket.h> +#include <sys/types.h> +#include <sys/wait.h> #include <termios.h> #include <time.h> #include <unistd.h> @@ -147,7 +149,7 @@ void cmdln_submit(const Arg *arg); void cmdln_wdel(const Arg *arg); void detach(Buffer *b); int dial(char *host, char *port); -void die(const char *errstr, ...); +void die(const char *fmt, ...); void draw(void); void drawbar(void); void drawbuf(void); @@ -196,9 +198,11 @@ void recv_topicrpl(char *usr, char *par, char *txt); void resize(int x, int y); void scroll(const Arg *arg); void setup(void); +void sigchld(int unused); void sigwinch(int unused); char *skip(char *s, char c); void sout(char *fmt, ...); +void spawn(const char **cmd); void strip_ctrlseqs(char *s); void trim(char *s); void usage(void); @@ -697,15 +701,23 @@ dial(char *host, char *port) { } void -die(const char *errstr, ...) { +die(const char *fmt, ...) { va_list ap; - - va_start(ap, errstr); - vfprintf(stderr, errstr, ap); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); va_end(ap); - exit(1); + + if (fmt[0] && fmt[strlen(fmt)-1] == ':') { + fputc(' ', stderr); + perror(NULL); + } else { + fputc('\n', stderr); + } + + exit(0); } + void draw(void) { printf(CURSOFF); @@ -1373,6 +1385,8 @@ recv_privmsg(char *from, char *to, char *txt) { if(b != sel && (mention || query)) { ++b->notify; sel->need_redraw |= REDRAW_BAR; + if(NOTIFY_SCRIPT) + spawn((const char *[]){ NOTIFY_SCRIPT, from, to, txt, NULL }); } bprintf(b, "%C%s%..0C: %s\n", mention ? colors[NickMention] : colors[NickNormal], from, txt); } @@ -1498,6 +1512,9 @@ setup(void) { struct sigaction sa; struct winsize ws; + /* clean up any zombies immediately */ + sigchld(0); + setlocale(LC_CTYPE, ""); sa.sa_flags = 0; sigemptyset(&sa.sa_mask); @@ -1514,6 +1531,13 @@ setup(void) { } void +sigchld(int unused) { + if (signal(SIGCHLD, sigchld) == SIG_ERR) + die("can't install SIGCHLD handler:"); + while(0 < waitpid(-1, NULL, WNOHANG)); +} + +void sigwinch(int unused) { struct winsize ws; @@ -1545,6 +1569,17 @@ sout(char *fmt, ...) { } void +spawn(const char **cmd) { + if(fork() == 0) { + setsid(); + execvp(cmd[0], (char **)cmd); + fprintf(stderr, "%s: execvp %s", argv0, cmd[0]); + perror(" failed"); + exit(0); + } +} + +void strip_ctrlseqs(char *s) { int i = 0; char *c; diff --git a/circo_notify.ogg b/circo_notify.ogg Binary files differ. diff --git a/circo_notify.sh b/circo_notify.sh @@ -0,0 +1,16 @@ +#!/bin/sh +# Sound from https://notificationsounds.com/ + +export DISPLAY=:0 + +from=$1 +to=$2 +txt=$3 +[ "$from" = "$to" ] && to="private" + +btn="Read" + +mpv circo_notify.ogg >/dev/null 2>&1 & +xmessage -geom 250x100 -button "$btn" -default "$btn" -timeout 3 -center "$from in $to + +$txt" diff --git a/config.def.h b/config.def.h @@ -12,6 +12,9 @@ char logfile[64] = "/tmp/circo.log"; /* Used if no message is specified */ #define QUIT_MESSAGE "circo" +/* Called for background mentions */ +#define NOTIFY_SCRIPT "" + /* color scheme */ static int colors[ColorLast][5] = { [NickNormal] = {4, -1},