Add basic FIFO

This commit is contained in:
Jacob 2023-08-08 20:53:56 +02:00
parent d88ecbc2c9
commit b4286559a1
8 changed files with 82 additions and 2 deletions

View file

@ -16,6 +16,7 @@ can be themed to look identical to dmenu.
- Reading entries from standard input and file
- Image and icon support
- Run launcher, supporting both .desktop entries and $PATH
- FIFO, allowing programs to communicate with spmenu
- fzf-like Fuzzy matching
- Vi-like modes (see docs/binds-vim.conf)
- History buffer

60
libs/fifo.c Normal file
View file

@ -0,0 +1,60 @@
/* See LICENSE file for copyright and license details. */
#if FIFO
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;
}
if (!strcmp(fifot, "drawmenu")) {
drawmenu();
} else if (!strcmp(fifot, "match")) {
match();
} else if (!strcmp(fifot, "test")) {
fprintf(stderr, "Test print\n");
} else if (!strcmp(fifot, "die")) {
close(fd);
die("FIFO told me to die.");
} 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 (;;) {
sleep(1);
if (done) {
execute_fifo_cmd();
}
}
}
void init_fifo(void) {
mkfifo(fifofile, 0666);
pthread_t tid;
pthread_create(&tid, NULL, &fifocmd, NULL);
}
#endif

View file

@ -60,6 +60,9 @@ static int generatecache = 1; /* Generate image cache by default *
static int maxcache = 512; /* Max image size to cache */
static char *cachedir = "default"; /* Cache directory. Default means spmenu will determine automatically */
/* Fifo options */
static char *fifofile = "/tmp/spmenu.fifo"; /* spmenu FIFO path */
/* Screenshot options */
static char *screenshotfile = NULL; /* Screenshot file path. If set to NULL, the default path will be used. */
static char *screenshotname = NULL; /* Screenshot file name. If set to NULL, the default name will be used. */

View file

@ -86,6 +86,10 @@ if get_option('regex')
build_args += [ '-DREGEX' ]
endif
if get_option('fifo')
build_args += [ '-DFIFO' ]
endif
project_target = executable(
meson.project_name(),
project_source_files, install : true,

View file

@ -7,6 +7,7 @@ option('xresources', type : 'boolean', value : true, description : 'Enable .Xres
option('fribidi', type : 'boolean', value : true, description : 'Enable Right-to-left language support')
option('libconfig', type : 'boolean', value : true, description : 'Enable configuration file support')
option('regex', type : 'boolean', value : true, description : 'Enable regex matching')
option('fifo', type : 'boolean', value : true, description : 'Enable FIFO')
option('run', type : 'boolean', value : true, description : 'Install spmenu_run')
option('test', type : 'boolean', value : true, description : 'Install spmenu_test')
option('man', type : 'boolean', value : true, description : 'Install man page')

View file

@ -17,7 +17,7 @@ fi
LICENSE="MIT"
SLOT="0"
IUSE="+X +wayland +imlib2 +ssl +regex +fribidi +config +xinerama +xrdb +doc +run +test +man"
IUSE="+X +wayland +imlib2 +ssl +regex +fribidi +config +xinerama +xrdb +fifo +doc +run +test +man"
REQUIRED_USE="
!wayland? ( X )
!X? ( wayland )

View file

@ -10,6 +10,7 @@ xresources=${xresources:-true}
wayland=${wayland:-true}
x11=${x11:-true}
regex=${regex:-true}
fifo=${fifo:-true}
prefix="${prefix:-/usr}"
@ -307,6 +308,7 @@ build() {
-Dwayland="$wayland" \
-Dx11="$x11" \
-Dregex="$regex" \
-Dfifo="$fifo" \
--prefix "$prefix" \
build || exit 1
else
@ -320,6 +322,7 @@ build() {
-Dwayland="$wayland" \
-Dx11="$x11" \
-Dregex="$regex" \
-Dfifo="$fifo" \
--prefix "$prefix" \
build || exit 1
fi

View file

@ -181,7 +181,6 @@ static size_t listsize;
static char *fonts[] = { font };
// include functions
#include "libs/img.c"
#include "libs/icon.c"
#include "libs/rtl.c"
@ -194,6 +193,7 @@ static char *fonts[] = { font };
#include "libs/argv.c"
#include "libs/history.c"
#include "libs/arg.c"
#include "libs/fifo.c"
#if X11
static Key keys[] = {
@ -555,6 +555,10 @@ void handle(void) {
init_appearance(); // init colorschemes by reading arrays
#if FIFO
init_fifo();
#endif
setupdisplay_x11(); // set up display and create window
eventloop_x11(); // function is a loop which checks X11 events and calls other functions accordingly
#endif
@ -582,6 +586,10 @@ void handle(void) {
set_mode();
init_appearance();
#if FIFO
init_fifo();
#endif
handle_wl();
#endif
}