2023-08-08 20:53:56 +02:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
|
|
|
|
#if FIFO
|
2023-08-08 21:06:59 +02:00
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2023-08-08 20:53:56 +02:00
|
|
|
static void init_fifo(void);
|
|
|
|
static void execute_fifo_cmd(void);
|
|
|
|
static int done = 1;
|
|
|
|
|
|
|
|
void execute_fifo_cmd(void) {
|
|
|
|
int fd;
|
|
|
|
char fifot[BUFSIZ];
|
|
|
|
|
|
|
|
done = 0;
|
|
|
|
|
|
|
|
fd = open(fifofile, O_RDONLY);
|
|
|
|
int r = read(fd, fifot, sizeof(fifot));
|
|
|
|
|
|
|
|
if (!r) {
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-09 20:33:17 +02:00
|
|
|
/* These are the different commands that we can run
|
|
|
|
* by outputting text to the FIFO.
|
|
|
|
*/
|
2023-08-08 20:53:56 +02:00
|
|
|
if (!strcmp(fifot, "drawmenu")) {
|
|
|
|
drawmenu();
|
|
|
|
} else if (!strcmp(fifot, "match")) {
|
|
|
|
match();
|
2023-08-08 22:14:29 +02:00
|
|
|
} else if (!strcmp(fifot, "update")) {
|
|
|
|
match();
|
|
|
|
drawmenu();
|
2023-08-08 20:53:56 +02:00
|
|
|
} else if (!strcmp(fifot, "test")) {
|
|
|
|
fprintf(stderr, "Test print\n");
|
|
|
|
} else if (!strcmp(fifot, "die")) {
|
|
|
|
close(fd);
|
|
|
|
die("FIFO told me to die.");
|
2023-08-08 22:32:24 +02:00
|
|
|
} else if (!strcmp(fifot, "loadconfig")) {
|
|
|
|
#if CONFIG
|
|
|
|
conf_init();
|
|
|
|
#endif
|
|
|
|
} else if (!strcmp(fifot, "output")) {
|
|
|
|
if (selecteditem) {
|
|
|
|
for (int i = 0; i < sel_size; i++) {
|
|
|
|
if (sel_index[i] != -1 && (!selecteditem || selecteditem->index != sel_index[i])) {
|
|
|
|
puts(items[sel_index[i]].text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!strcmp(fifot, "output_index")) {
|
|
|
|
if (printindex && selecteditem) {
|
|
|
|
fprintf(stdout, "%d\n", selecteditem->index);
|
|
|
|
}
|
2023-08-09 20:33:17 +02:00
|
|
|
} else if (!strcmp(fifot, "toggleinput")) {
|
2023-08-09 21:23:21 +02:00
|
|
|
Arg arg;
|
|
|
|
toggleinput(&arg);
|
2023-08-09 20:33:17 +02:00
|
|
|
} else if (!strcmp(fifot, "togglelarrow")) {
|
2023-08-09 21:23:21 +02:00
|
|
|
Arg arg;
|
|
|
|
togglelarrow(&arg);
|
2023-08-09 20:33:17 +02:00
|
|
|
} else if (!strcmp(fifot, "togglerarrow")) {
|
2023-08-09 21:23:21 +02:00
|
|
|
Arg arg;
|
|
|
|
togglerarrow(&arg);
|
2023-08-09 20:33:17 +02:00
|
|
|
} else if (!strcmp(fifot, "toggleitem")) {
|
2023-08-09 21:23:21 +02:00
|
|
|
Arg arg;
|
|
|
|
toggleitem(&arg);
|
2023-08-09 20:33:17 +02:00
|
|
|
} else if (!strcmp(fifot, "toggleprompt")) {
|
2023-08-09 21:23:21 +02:00
|
|
|
Arg arg;
|
|
|
|
toggleprompt(&arg);
|
2023-08-09 20:33:17 +02:00
|
|
|
} else if (!strcmp(fifot, "togglecaps")) {
|
2023-08-09 21:23:21 +02:00
|
|
|
Arg arg;
|
|
|
|
togglecaps(&arg);
|
2023-08-09 20:33:17 +02:00
|
|
|
} else if (!strcmp(fifot, "togglepowerline")) {
|
2023-08-09 21:23:21 +02:00
|
|
|
Arg arg;
|
|
|
|
togglepowerline(&arg);
|
2023-08-09 20:33:17 +02:00
|
|
|
} else if (!strcmp(fifot, "togglecaret")) {
|
2023-08-09 21:23:21 +02:00
|
|
|
Arg arg;
|
|
|
|
togglecaret(&arg);
|
2023-08-09 20:33:17 +02:00
|
|
|
} else if (!strcmp(fifot, "togglehighlight")) {
|
2023-08-09 21:23:21 +02:00
|
|
|
Arg arg;
|
|
|
|
togglehighlight(&arg);
|
2023-08-09 20:33:17 +02:00
|
|
|
} else if (!strcmp(fifot, "togglematchcount")) {
|
2023-08-09 21:23:21 +02:00
|
|
|
Arg arg;
|
|
|
|
togglematchcount(&arg);
|
2023-08-09 20:33:17 +02:00
|
|
|
} else if (!strcmp(fifot, "togglemode")) {
|
2023-08-09 21:23:21 +02:00
|
|
|
Arg arg;
|
|
|
|
togglemode(&arg);
|
2023-08-09 20:33:17 +02:00
|
|
|
} else if (!strcmp(fifot, "toggleregex")) {
|
2023-08-09 21:23:21 +02:00
|
|
|
Arg arg;
|
|
|
|
toggleregex(&arg);
|
2023-08-09 20:33:17 +02:00
|
|
|
} else if (!strcmp(fifot, "togglefuzzy")) {
|
2023-08-09 21:23:21 +02:00
|
|
|
Arg arg;
|
|
|
|
togglefuzzy(&arg);
|
2023-08-09 20:33:17 +02:00
|
|
|
} else if (!strcmp(fifot, "toggleimg")) {
|
2023-08-09 21:23:21 +02:00
|
|
|
Arg arg;
|
|
|
|
toggleimg(&arg);
|
2023-08-09 20:33:17 +02:00
|
|
|
} else if (!strcmp(fifot, "toggleimgtype")) {
|
2023-08-09 21:23:21 +02:00
|
|
|
Arg arg;
|
|
|
|
toggleimgtype(&arg);
|
|
|
|
} else if (!strcmp(fifot, "screenshot")) {
|
|
|
|
Arg arg;
|
|
|
|
screenshot(&arg);
|
|
|
|
} else if (!strcmp(fifot, "setprofile")) {
|
|
|
|
Arg arg;
|
|
|
|
setprofile(&arg);
|
|
|
|
} else if (!strcmp(fifot, "setlines+")) {
|
|
|
|
Arg arg;
|
|
|
|
arg.i = +1;
|
|
|
|
setlines(&arg);
|
|
|
|
} else if (!strcmp(fifot, "setlines-")) {
|
|
|
|
Arg arg;
|
|
|
|
arg.i = -1;
|
|
|
|
setlines(&arg);
|
|
|
|
} else if (!strcmp(fifot, "setcolumns+")) {
|
|
|
|
Arg arg;
|
|
|
|
arg.i = +1;
|
|
|
|
setcolumns(&arg);
|
|
|
|
} else if (!strcmp(fifot, "setcolumns-")) {
|
|
|
|
Arg arg;
|
|
|
|
arg.i = -1;
|
|
|
|
setcolumns(&arg);
|
|
|
|
} else if (!strcmp(fifot, "moveup")) {
|
|
|
|
Arg arg;
|
|
|
|
moveup(&arg);
|
|
|
|
} else if (!strcmp(fifot, "movedown")) {
|
|
|
|
Arg arg;
|
|
|
|
movedown(&arg);
|
|
|
|
} else if (!strcmp(fifot, "moveleft")) {
|
|
|
|
Arg arg;
|
|
|
|
moveleft(&arg);
|
|
|
|
} else if (!strcmp(fifot, "moveright")) {
|
|
|
|
Arg arg;
|
|
|
|
moveright(&arg);
|
|
|
|
} else if (!strcmp(fifot, "movestart")) {
|
|
|
|
Arg arg;
|
|
|
|
movestart(&arg);
|
|
|
|
} else if (!strcmp(fifot, "moveend")) {
|
|
|
|
Arg arg;
|
|
|
|
moveend(&arg);
|
|
|
|
} else if (!strcmp(fifot, "movenext")) {
|
|
|
|
Arg arg;
|
|
|
|
movenext(&arg);
|
|
|
|
} else if (!strcmp(fifot, "moveprev")) {
|
|
|
|
Arg arg;
|
|
|
|
moveprev(&arg);
|
|
|
|
} else if (!strcmp(fifot, "viewhist")) {
|
|
|
|
Arg arg;
|
|
|
|
viewhist(&arg);
|
|
|
|
} else if (!strcmp(fifot, "backspace")) {
|
|
|
|
Arg arg;
|
|
|
|
backspace(&arg);
|
|
|
|
} else if (!strcmp(fifot, "deleteword")) {
|
|
|
|
Arg arg;
|
|
|
|
deleteword(&arg);
|
|
|
|
} else if (!strcmp(fifot, "moveword+")) {
|
|
|
|
Arg arg;
|
|
|
|
arg.i = +1;
|
|
|
|
moveword(&arg);
|
|
|
|
} else if (!strcmp(fifot, "moveword-")) {
|
|
|
|
Arg arg;
|
|
|
|
arg.i = -1;
|
|
|
|
moveword(&arg);
|
|
|
|
} else if (!strcmp(fifot, "movecursor+")) {
|
|
|
|
Arg arg;
|
|
|
|
arg.i = +1;
|
|
|
|
movecursor(&arg);
|
|
|
|
} else if (!strcmp(fifot, "movecursor-")) {
|
|
|
|
Arg arg;
|
|
|
|
arg.i = -1;
|
|
|
|
movecursor(&arg);
|
|
|
|
} else if (!strcmp(fifot, "clear")) {
|
|
|
|
Arg arg;
|
|
|
|
clear(&arg);
|
2023-08-08 20:53:56 +02:00
|
|
|
} else if (!strcmp(fifot, "exit_0")) {
|
|
|
|
exit(0);
|
|
|
|
} else if (!strcmp(fifot, "exit_1")) {
|
|
|
|
exit(1);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "spmenu: Unknown command: %s\n", fifot);
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
done = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *fifocmd(void *n) {
|
|
|
|
for (;;) {
|
2023-08-08 22:14:29 +02:00
|
|
|
msleep(0.1);
|
2023-08-08 20:53:56 +02:00
|
|
|
|
|
|
|
if (done) {
|
|
|
|
execute_fifo_cmd();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_fifo(void) {
|
2023-08-09 20:33:17 +02:00
|
|
|
remove(fifofile);
|
2023-08-08 20:53:56 +02:00
|
|
|
mkfifo(fifofile, 0666);
|
|
|
|
|
|
|
|
pthread_t tid;
|
|
|
|
pthread_create(&tid, NULL, &fifocmd, NULL);
|
|
|
|
}
|
|
|
|
#endif
|