]> git.mdlowis.com Git - proto/anvil.git/commitdiff
added basic keyboard shortcuts
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 14 Mar 2020 19:36:12 +0000 (15:36 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 14 Mar 2020 19:36:12 +0000 (15:36 -0400)
anvil.h
keys.c

diff --git a/anvil.h b/anvil.h
index 075f8cec09466f1a346d83d54b0260aae7d28856..54ddd6ed84ed504ba06e47c2088d7385d4ee2219 100644 (file)
--- a/anvil.h
+++ b/anvil.h
@@ -76,6 +76,7 @@ typedef struct Location {
 
 typedef union {
     int i;
+    char** cmd;
 } Arg;
 
 typedef struct {
diff --git a/keys.c b/keys.c
index 2d5d377d9b02ec233bd26eacc188ba1b5656f9c6..18018d17d03476185a0a28465939958d77291cdb 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -1,4 +1,11 @@
 #include "anvil.h"
+#include <unistd.h>
+
+static void quit(Arg* arg)
+{
+    (void)arg;
+    exit(0);
+}
 
 static void set_workspace(Arg* arg)
 {
@@ -10,33 +17,62 @@ static void to_workspace(Arg* arg)
     mons_towspace(Focused, arg->i);
 }
 
+static void runcmd(Arg *arg)
+{
+    if (fork() == 0) {
+        if (X.disp)
+        {
+            close(ConnectionNumber(X.disp));
+        }
+        setsid();
+        exit(execvp(arg->cmd[0], arg->cmd));
+    }
+}
+
+static void killwin(Arg *arg)
+{
+    (void)arg;
+    client_close(Focused);
+}
+
 #ifdef __APPLE__
 #define MODKEY Mod1Mask
 #else
 #define MODKEY Mod4Mask
 #endif
 
+static char* pickexec[]  = { "pickexec", NULL };
+static char* terminal[]  = { "xterm", NULL };
+static char* locker[]  = { "slock", NULL };
+
 static Key keys[] = {
-    { MODKEY,   XK_1,   set_workspace,  {.i = 0 } },
-    { MODKEY,   XK_2,   set_workspace,  {.i = 1 } },
-    { MODKEY,   XK_3,   set_workspace,  {.i = 2 } },
-    { MODKEY,   XK_4,   set_workspace,  {.i = 3 } },
-    { MODKEY,   XK_5,   set_workspace,  {.i = 4 } },
-    { MODKEY,   XK_6,   set_workspace,  {.i = 5 } },
-    { MODKEY,   XK_7,   set_workspace,  {.i = 6 } },
-    { MODKEY,   XK_8,   set_workspace,  {.i = 7 } },
-    { MODKEY,   XK_9,   set_workspace,  {.i = 8 } },
-    { MODKEY,   XK_0,   set_workspace,  {.i = 9 } },
-    { MODKEY|ShiftMask,   XK_1,   to_workspace,  {.i = 0 } },
-    { MODKEY|ShiftMask,   XK_2,   to_workspace,  {.i = 1 } },
-    { MODKEY|ShiftMask,   XK_3,   to_workspace,  {.i = 2 } },
-    { MODKEY|ShiftMask,   XK_4,   to_workspace,  {.i = 3 } },
-    { MODKEY|ShiftMask,   XK_5,   to_workspace,  {.i = 4 } },
-    { MODKEY|ShiftMask,   XK_6,   to_workspace,  {.i = 5 } },
-    { MODKEY|ShiftMask,   XK_7,   to_workspace,  {.i = 6 } },
-    { MODKEY|ShiftMask,   XK_8,   to_workspace,  {.i = 7 } },
-    { MODKEY|ShiftMask,   XK_9,   to_workspace,  {.i = 8 } },
-    { MODKEY|ShiftMask,   XK_0,   to_workspace,  {.i = 9 } },
+    { MODKEY|ShiftMask, XK_q,      quit,    { 0 } },
+    { MODKEY,           XK_p,      runcmd,  { .cmd = pickexec } },
+    { MODKEY|ShiftMask, XK_Return, runcmd,  { .cmd = terminal } },
+    { MODKEY|ShiftMask, XK_l,      runcmd,  { .cmd = locker   } },
+    { MODKEY|ShiftMask, XK_c,      killwin, { 0 } },
+
+    { MODKEY,   XK_1,   set_workspace,  { .i = 0 } },
+    { MODKEY,   XK_2,   set_workspace,  { .i = 1 } },
+    { MODKEY,   XK_3,   set_workspace,  { .i = 2 } },
+    { MODKEY,   XK_4,   set_workspace,  { .i = 3 } },
+    { MODKEY,   XK_5,   set_workspace,  { .i = 4 } },
+    { MODKEY,   XK_6,   set_workspace,  { .i = 5 } },
+    { MODKEY,   XK_7,   set_workspace,  { .i = 6 } },
+    { MODKEY,   XK_8,   set_workspace,  { .i = 7 } },
+    { MODKEY,   XK_9,   set_workspace,  { .i = 8 } },
+    { MODKEY,   XK_0,   set_workspace,  { .i = 9 } },
+
+    { MODKEY|ShiftMask,   XK_1,   to_workspace,  { .i = 0 } },
+    { MODKEY|ShiftMask,   XK_2,   to_workspace,  { .i = 1 } },
+    { MODKEY|ShiftMask,   XK_3,   to_workspace,  { .i = 2 } },
+    { MODKEY|ShiftMask,   XK_4,   to_workspace,  { .i = 3 } },
+    { MODKEY|ShiftMask,   XK_5,   to_workspace,  { .i = 4 } },
+    { MODKEY|ShiftMask,   XK_6,   to_workspace,  { .i = 5 } },
+    { MODKEY|ShiftMask,   XK_7,   to_workspace,  { .i = 6 } },
+    { MODKEY|ShiftMask,   XK_8,   to_workspace,  { .i = 7 } },
+    { MODKEY|ShiftMask,   XK_9,   to_workspace,  { .i = 8 } },
+    { MODKEY|ShiftMask,   XK_0,   to_workspace,  { .i = 9 } },
 };
 
 void keys_init(void)