From 7e0ace1f1e5334f13580facb53c253c94c6913f6 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Tue, 21 Mar 2023 22:44:57 +0100 Subject: add dmenu-wl_run and dmenu_path and config.mk --- Makefile | 31 ++++++++++++++++++++++--------- config.mk | 9 +++++++++ dmenu-wl.c | 3 +-- dmenu-wl_run | 2 ++ dmenu_path | 13 +++++++++++++ 5 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 config.mk create mode 100755 dmenu-wl_run create mode 100755 dmenu_path diff --git a/Makefile b/Makefile index 0d5a311..edeb705 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,11 @@ -WLR_LAYER_SHELL=protocol/wlr-layer-shell-unstable.xml -XDG_SHELL=/usr/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml -DWL_IPC=protocol/dwl-bar-ipc-unstable-v1.xml -PROTOCOLS=wlr-layer-shell-protocol.c xdg-shell-protocol.c dwl-bar-ipc-protocol.c -SRC=dmenu-wl.c drw.c util.c wayland.c -OBJ=${SRC:.c=.o} ${PROTOCOLS:.c=.o} -LDFLAGS=-lfreetype -lwayland-client -lrt -lxkbcommon -lm -lgrapheme -CFLAGS=-I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/sysprof-4 -pthread -CC=gcc + +include config.mk + +WLR_LAYER_SHELL = protocol/wlr-layer-shell-unstable.xml +DWL_IPC = protocol/dwl-bar-ipc-unstable-v1.xml +PROTOCOLS = wlr-layer-shell-protocol.c xdg-shell-protocol.c dwl-bar-ipc-protocol.c +SRC = dmenu-wl.c drw.c util.c wayland.c +OBJ = ${SRC:.c=.o} ${PROTOCOLS:.c=.o} default_target: options dmenu-wl @@ -39,5 +38,19 @@ ${OBJ}: ${PROTOCOLS} config.h dmenu-wl: ${OBJ} ${CC} -o $@ ${OBJ} ${LDFLAGS} +install: default_target + mkdir -p ${DESTDIR}${PREFIX}/bin + install dmenu-wl dmenu_path dmenu-wl_run ${DESTDIR}${PREFIX}/bin + chmod 755 ${DESTDIR}${PREFIX}/bin/dmenu + chmod 755 ${DESTDIR}${PREFIX}/bin/dmenu_path + chmod 755 ${DESTDIR}${PREFIX}/bin/dmenu_run + +uninstall: + rm -f ${DESTDIR}${PREFIX}/bin/dmenu-wl \ + ${DESTDIR}${PREFIX}/bin/dmenu_path \ + ${DESTDIR}${PREFIX}/bin/dmenu_run + clean: rm ${OBJ} dmenu-wl ${PROTOCOLS} ${PROTOCOLS:.c=.h} + +.PHONY: all options clean install uninstall diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..5db0147 --- /dev/null +++ b/config.mk @@ -0,0 +1,9 @@ +VERSION = 0.1 + +# paths +PREFIX = /usr/local + +LDFLAGS = -lfreetype -lwayland-client -lrt -lxkbcommon -lm -lgrapheme +CFLAGS = -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/sysprof-4 -pthread +XDG_SHELL = /usr/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml +CC = cc diff --git a/dmenu-wl.c b/dmenu-wl.c index 9debd69..252182c 100644 --- a/dmenu-wl.c +++ b/dmenu-wl.c @@ -425,8 +425,7 @@ readstdin() char *buf = malloc(MAX_LINE_LENGTH); Option *option; - while (fgets(buf, MAX_LINE_LENGTH, stdin) != 0) { - ++numitems; + for (;fgets(buf, MAX_LINE_LENGTH, stdin) != 0; ++numitems) { option = malloc(sizeof(Option)); option->name = buf; s = strlen(option->name); diff --git a/dmenu-wl_run b/dmenu-wl_run new file mode 100755 index 0000000..8594218 --- /dev/null +++ b/dmenu-wl_run @@ -0,0 +1,2 @@ +#!/bin/sh +dmenu_path | dmenu-wl "$@" | ${SHELL:-"/bin/sh"} & diff --git a/dmenu_path b/dmenu_path new file mode 100755 index 0000000..a8bfafe --- /dev/null +++ b/dmenu_path @@ -0,0 +1,13 @@ +#!/bin/sh + +cachedir="${XDG_CACHE_HOME:-"$HOME"/.cache}" +cache="$cachedir/dmenu_run" + +[ ! -e "$cachedir" ] && mkdir -p "$cachedir" + +IFS=: +if stest -dqr -n "$cache" $PATH; then + stest -flx $PATH | sort -u | tee "$cache" +else + cat "$cache" +fi -- cgit v1.2.3-70-g09d2