From 46f87587abb4cb73f17d8291669f36c214ded9f4 Mon Sep 17 00:00:00 2001 From: speedie Date: Sun, 23 Apr 2023 20:08:34 +0200 Subject: [PATCH] rewrite the way the profile script running works --- keybinds.h | 2 +- libs/arg.c | 13 ++++--------- libs/arg.h | 2 +- libs/define.c | 1 - 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/keybinds.h b/keybinds.h index 179dc7a..2b0014f 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, setprofile, {0} }, + { -1, CONTROL|SHIFT, XK_p, spawn, {.c = "spmenu_profile --spmenu-set-profile" } }, /* normal mode */ { 0, 0, XK_i, switchmode, {0} }, diff --git a/libs/arg.c b/libs/arg.c index d284451..3c38401 100644 --- a/libs/arg.c +++ b/libs/arg.c @@ -506,18 +506,13 @@ setcolumns(const Arg *arg) drawmenu(); } -void -setprofile(const Arg *arg) -{ - // this just runs an external shell script to set the profile - exit(system("command -v spmenu_profile > /dev/null && spmenu_profile --spmenu-set-profile > /dev/null")); -} - void spawn(const Arg *arg) { - if (!system(arg->v)) - fprintf(stderr, "spmenu: failed to execute command '%s'", ((char **)arg->v)[0]); + if (!system(arg->c)) + die("spmenu: failed to execute command '%s'", arg->c); + else + exit(0); } void diff --git a/libs/arg.h b/libs/arg.h index 8bac262..37d4f12 100644 --- a/libs/arg.h +++ b/libs/arg.h @@ -3,6 +3,7 @@ typedef union { unsigned int ui; // unsigned int float f; // float const void *v; // void + const char *c; // char } Arg; // declare keybind functions @@ -37,6 +38,5 @@ static void setimgpos(const Arg *arg); static void setimggaps(const Arg *arg); static void setlines(const Arg *arg); static void setcolumns(const Arg *arg); -static void setprofile(const Arg *arg); static void spawn(const Arg *arg); static void togglehighlight(const Arg *arg); diff --git a/libs/define.c b/libs/define.c index 388162b..7d8dd1c 100644 --- a/libs/define.c +++ b/libs/define.c @@ -24,4 +24,3 @@ // for running stuff #define shell "/bin/sh" -#define cmd( cmd ) {.v = (const char*[]){ shell, "-c", cmd, NULL } },