From b1df89ed947503c74a61f36a1b3a92f5f424352e Mon Sep 17 00:00:00 2001 From: "Douglas B. Rumbaugh" Date: Sat, 31 Dec 2022 17:21:08 -0500 Subject: Applied plumber patch --- x.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'x.c') diff --git a/x.c b/x.c index 754f48c..fa2939f 100644 --- a/x.c +++ b/x.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -232,6 +233,7 @@ static void (*handler[LASTEvent])(XEvent *) = { }; /* Globals */ +static int plumbsel; static DC dc; static XWindow xw; static XSelection xsel; @@ -710,6 +712,37 @@ xsetsel(char *str) setsel(str, CurrentTime); } +void +plumbinit() +{ + for(plumbsel = 0; plumb_cmd[plumbsel]; plumbsel++); +} + +void +plumb(char *sel) { + if (sel == NULL) + return; + char cwd[PATH_MAX]; + pid_t child; + if (subprocwd(cwd) != 0) + return; + + plumb_cmd[plumbsel] = sel; + + switch(child = fork()) { + case -1: + return; + case 0: + if (chdir(cwd) != 0) + exit(1); + if (execvp(plumb_cmd[0], plumb_cmd) == -1) + exit(1); + exit(0); + default: + waitpid(child, NULL, 0); + } +} + void brelease(XEvent *e) { @@ -727,6 +760,8 @@ brelease(XEvent *e) return; if (btn == Button1) mousesel(e, 1); + else if (e->xbutton.button == Button3) + plumb(xsel.primary); } void @@ -2196,6 +2231,7 @@ main(int argc, char *argv[]) } ARGEND; run: + plumbinit(); if (argc > 0) /* eat all remaining arguments */ opt_cmd = argv; -- cgit v1.2.3