forked from salman-abedin/devour
-
Notifications
You must be signed in to change notification settings - Fork 0
/
devour.c
50 lines (39 loc) · 918 Bytes
/
devour.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* devour
* X11 window swallower
*/
#include <X11/Xlib.h>
#include <stdlib.h>
#include <string.h>
#define UNSAFE_CHARS "`\"'()[]& "
void run_command(char **argv) {
char arg_char;
char *arg;
char cmd[1024] = {0};
while ((arg = *++argv)) {
while ((arg_char = *arg++)) {
if (strchr(UNSAFE_CHARS, arg_char))
strcat(cmd, "\\");
strncat(cmd, &arg_char, 1);
}
strcat(cmd, " ");
}
system(cmd);
}
int main(int argc, char **argv) {
int rev;
unsigned nc;
Window win, root, *ch;
Display *dis = XOpenDisplay(0);
XGetInputFocus(dis, &win, &rev);
/* This is to ensure correct behavior with an embeded terminal window e.g. using Suckless' tabbed */
if(rev == RevertToParent)
XQueryTree(dis, win, &root, &win, &ch, &nc);
XUnmapWindow(dis, win);
XFlush(dis);
run_command(argv);
XMapWindow(dis, win);
XCloseDisplay(dis);
(void)argc;
return 0;
}