From 5b2cbc0c7ebf4dff6ef7d0c4711e19543f173d56 Mon Sep 17 00:00:00 2001 From: speedie Date: Wed, 26 Apr 2023 10:01:11 +0200 Subject: [PATCH] fix keybind for setprofile, fix mac support --- Makefile | 19 ++++++++++++++++++- build.sh | 22 +++++++++++++++++----- buildconf | 1 + docs/spmenu.conf | 6 +++--- keybinds.h | 2 +- libs/arg.c | 9 +++++++++ libs/arg.h | 2 +- libs/history.h | 1 + libs/key.h | 6 ++---- 9 files changed, 53 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index bdf3701..4782521 100644 --- a/Makefile +++ b/Makefile @@ -63,6 +63,22 @@ install: spmenu rm -f *.o rm -f spmenu +install_mac: spmenu + rm -rf $(DESTDIR)$(PREFIX)/share/spmenu/ + mkdir -p $(DESTDIR)$(PREFIX)/bin + mkdir -p $(DESTDIR)$(PREFIX)/share/spmenu + cp -r docs/* $(DESTDIR)$(PREFIX)/share/spmenu/ + echo "$(VERSION)" > $(DESTDIR)$(PREFIX)/share/spmenu/version + echo "$(CC)" > $(DESTDIR)$(PREFIX)/share/spmenu/cc + echo "$(CFLAGS)" > $(DESTDIR)$(PREFIX)/share/spmenu/cflags + echo "$$(date "+%D %T")" > $(DESTDIR)$(PREFIX)/share/spmenu/compile-date + cp -r spmenu scripts/spmenu* $(DESTDIR)$(PREFIX)/bin + [ -f spmenu.1 ] && mkdir -p $(DESTDIR)$(MANPREFIX)/man1 || : + [ -f spmenu.1 ] && cp spmenu.1 $(DESTDIR)$(MANPREFIX)/man1/spmenu.1 || : + chmod 755 $(DESTDIR)$(PREFIX)/bin/spmenu* + rm -f *.o + rm -f spmenu + compat: rm -f $(DESTDIR)$(PREFIX)/bin/dmenu rm -f $(DESTDIR)$(PREFIX)/bin/dmenu_run @@ -77,6 +93,7 @@ help: @echo spmenu Makefile help @echo @echo install: Installs spmenu. You may need to run this as root. + @echo install_mac: Installs spmenu on a Mac. You may need to run this as root. @echo uninstall: Uninstalls spmenu. You may need to run this as root. @echo install_arch: Uses the PKGBUILD to install spmenu using pacman. @echo dist: Creates a release for spmenu. @@ -126,4 +143,4 @@ commit: docs git add * git commit -a || : -.PHONY: all options clean dist install install_arch uninstall pkg_arch help man docs commit +.PHONY: all options clean dist install install_mac install_arch uninstall pkg_arch help man docs commit diff --git a/build.sh b/build.sh index 1fd6c79..6eeb951 100755 --- a/build.sh +++ b/build.sh @@ -2,6 +2,7 @@ PREFIX="${PREFIX:-/usr}" DESTDIR="${DESTDIR:-}" INCDIR="${INCDIR:-/usr/include}" +makebin="${makebin:-$(command -v make)}" cc="${cc:-${CC:-gcc}}" opt="${opt:-${OPT:--O2}}" warn="${warn:-true}" @@ -13,6 +14,7 @@ check_dist() { } check() { + if [ "$mac" != "true" ]; then [ ! -x "$(command -v ldconfig)" ] && printf "ldconfig not found in %s. Please make sure your system is set up properly." "\$PATH" && exit 1 [ ! -x "$(command -v make)" ] && printf "make not found in %s. Please make sure your system is set up properly." "\$PATH" && exit 1 [ ! -x "$(command -v "$cc")" ] && printf "%s not found in %s. Please make sure your system is set up properly." "$cc" "\$PATH" @@ -27,6 +29,10 @@ check() { [ -n "$(ldconfig -p | grep fribidi)" ] && printf "fribidi found\n" && fribidi=true || fribidi=false [ -n "$(ldconfig -p | grep freetype)" ] && printf "freetype found\n" && freetype=true || freetype=false [ -n "$(ldconfig -p | grep libconfig)" ] && printf "libconfig found\n" && libconfig=true || libconfig=false + else + makebin="gnumake" + GEN_MANUAL="false" + fi } loadconf() { @@ -101,10 +107,10 @@ build() { bdtoggle="" fi - make clean - [ "$GEN_MANUAL" != "false" ] && make man + $makebin clean + [ "$GEN_MANUAL" != "false" ] && $makebin man - make \ + $makebin \ CC="$cc" \ PREFIX="$PREFIX" \ DISTDIR="$DISTDIR" \ @@ -128,7 +134,13 @@ build() { } install() { - make install \ + if [ "$mac" = "true" ]; then + RULE="install_mac" + else + RULE="install" + fi + + $makebin $RULE \ CC="$cc" \ PREFIX="$PREFIX" \ OPT="$opt" \ @@ -150,7 +162,7 @@ install() { X11INC="$X11INC" } -[ "$1" = "--no-install" ] && INSTALL=false +[ "$1" = "--no-install" ] && install=false check_dist check diff --git a/buildconf b/buildconf index c9de7d5..c6c0849 100755 --- a/buildconf +++ b/buildconf @@ -11,3 +11,4 @@ libconfig=true cc=gcc opt=-O2 warn=true +install=true diff --git a/docs/spmenu.conf b/docs/spmenu.conf index c8c2ba0..dada416 100644 --- a/docs/spmenu.conf +++ b/docs/spmenu.conf @@ -315,10 +315,10 @@ spmenu = argument = "+1"; }, { mode = -1; - modifier = "Control+Shift"; + modifier = "Ctrl+Shift"; key = "p"; - function = "spawn"; - argument = "setprofile"; + function = "setprofile"; + argument = "0"; }, { mode = 1; modifier = "None"; diff --git a/keybinds.h b/keybinds.h index 2b0014f..179dc7a 100644 --- a/keybinds.h +++ b/keybinds.h @@ -50,7 +50,7 @@ static Key keys[] = { { -1, CONTROL, XK_Right, moveword, {.i = +1 } }, { -1, 0, XK_Left, movecursor, {.i = -1 } }, { -1, 0, XK_Right, movecursor, {.i = +1 } }, - { -1, CONTROL|SHIFT, XK_p, spawn, {.c = "spmenu_profile --spmenu-set-profile" } }, + { -1, CONTROL|SHIFT, XK_p, setprofile, {0} }, /* normal mode */ { 0, 0, XK_i, switchmode, {0} }, diff --git a/libs/arg.c b/libs/arg.c index f8ffd01..8cb0745 100644 --- a/libs/arg.c +++ b/libs/arg.c @@ -521,3 +521,12 @@ togglehighlight(Arg *arg) hidehighlight = !hidehighlight; drawmenu(); } + +void +setprofile(Arg *arg) +{ + if (!system("spmenu_profile --spmenu-set-profile")) + die("spmenu: failed to run profile menu\n"); + else + exit(0); +} diff --git a/libs/arg.h b/libs/arg.h index f6abaf0..0cc20bd 100644 --- a/libs/arg.h +++ b/libs/arg.h @@ -28,7 +28,6 @@ static void backspace(Arg *arg); static void selectitem(Arg *arg); static void quit(Arg *arg); static void complete(Arg *arg); -static void savehistory(char *input); static void setimgsize(Arg *arg); static void toggleimg(Arg *arg); static void defaultimg(Arg *arg); @@ -40,3 +39,4 @@ static void setlines(Arg *arg); static void setcolumns(Arg *arg); static void spawn(Arg *arg); static void togglehighlight(Arg *arg); +static void setprofile(Arg *arg); diff --git a/libs/history.h b/libs/history.h index f39232f..58ba603 100644 --- a/libs/history.h +++ b/libs/history.h @@ -1,3 +1,4 @@ static char *histfile; static char **history; static size_t histsz, histpos; +static void savehistory(char *input); diff --git a/libs/key.h b/libs/key.h index 31eb995..cc85573 100644 --- a/libs/key.h +++ b/libs/key.h @@ -136,7 +136,6 @@ static ArgList al[] = { { "98", {.i = 98 } }, { "99", {.i = 99 } }, { "100", {.i = 100 } }, - { "+0", {.i = +0 } }, { "+1", {.i = +1 } }, { "+2", {.i = +2 } }, @@ -238,7 +237,6 @@ static ArgList al[] = { { "+98", {.i = +98 } }, { "+99", {.i = +99 } }, { "+100", {.i = +100 } }, - { "-0", {.i = -0 } }, { "-1", {.i = -1 } }, { "-2", {.i = -2 } }, @@ -340,7 +338,6 @@ static ArgList al[] = { { "-98", {.i = -98 } }, { "-99", {.i = -99 } }, { "-100", {.i = -100 } }, - { "setprofile", {.c = "spmenu_profile --spmenu-set-profile" } }, }; static FuncList fl[] = { @@ -383,8 +380,9 @@ static FuncList fl[] = { { "setlines", setlines }, { "setcolumns", setcolumns }, { "togglehighlight",togglehighlight }, - { "setprofile", spawn }, + { "setprofile", setprofile }, { "switchmode", switchmode }, + { "spawn", spawn }, }; // list of modifiers that can be used in the config file