tAdd function to run a process - spkp - Stacking wayland compositor
 (HTM) git clone git://git.z3bra.org/spkp.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
 (DIR) commit 2d59a0706e0f4c00478a50b3b7e027a179bf7a78
 (DIR) parent b441298945c16788b62304a66c43a3ceb3204eb0
 (HTM) Author: Willy Goiffon <dev@z3bra.org>
       Date:   Fri, 13 Nov 2020 10:56:06 +0100
       
       Add function to run a process
       
       Diffstat:
         M compositor.c                        |      27 +++++++++++++++++++++++++--
         M config.def.h                        |       1 +
       
       2 files changed, 26 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/compositor.c b/compositor.c
       t@@ -1,9 +1,12 @@
       -#include <assert.h>
       +#include <signal.h>
        #include <stdio.h>
        #include <stdlib.h>
        #include <time.h>
       -#include <wayland-server.h>
       +#include <unistd.h>
       +
       +#include <sys/types.h>
        
       +#include <wayland-server.h>
        #include <wlr/backend.h>
        #include <wlr/render/wlr_renderer.h>
        #include <wlr/types/wlr_compositor.h>
       t@@ -191,6 +194,7 @@ static struct window *underneath(struct state *, double, double);
        /* keybinding functions, see config.h */
        static void kb_terminate(struct state *, union keyarg *);
        static void kb_alttab(struct state *, union keyarg *);
       +static void kb_exec(struct state *, union keyarg *);
        
        #include "config.h"
        
       t@@ -1010,6 +1014,25 @@ kb_alttab(struct state *server, union keyarg *arg)
                focus(w);
        }
        
       +/*
       + * Run the given command
       + */
       +void
       +kb_exec(struct state *server, union keyarg *arg)
       +{
       +        (void)server;
       +        if (!fork()) {
       +                setsid();
       +                sigset_t set;
       +                sigemptyset(&set);
       +                sigprocmask(SIG_SETMASK, &set, NULL);
       +                close(1);
       +                close(2);
       +                execl("/bin/sh", "/bin/sh", "-c", (char *)arg->v, (void *)NULL);
       +                exit(1); /* NOTREACHED */
       +        }
       +}
       +
        int
        main(int argc, char *argv[])
        {
 (DIR) diff --git a/config.def.h b/config.def.h
       t@@ -14,4 +14,5 @@ struct key keys[] = {
                { LOGO     , XKB_KEY_Escape, kb_terminate, {0     } },
                { ALT      , XKB_KEY_Tab   , kb_alttab   , {.i = 0} },
                { ALT|SHFT , XKB_KEY_Tab   , kb_alttab   , {.i = 1} },
       +        { LOGO     , XKB_KEY_Return, kb_exec     , {.v = "alacritty"} },
        };