summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Bensmann <johannesbensmann@gmx.de>2019-06-09 17:48:36 +0200
committerJohannes Bensmann <johannesbensmann@gmx.de>2019-06-09 17:48:36 +0200
commitba6e07a147c5a69076ca0f8781f2e11dfbcaec19 (patch)
tree06b3f21beead48e5a22338da3a10ad23b9698fe4
parent130540cbbf154f349cd1afaa837c07e3a69d3e28 (diff)
added bindings to execute shell commands
-rw-r--r--config.h6
-rw-r--r--xmouseless.c17
2 files changed, 23 insertions, 0 deletions
diff --git a/config.h b/config.h
index a9eabba..75c6222 100644
--- a/config.h
+++ b/config.h
@@ -39,6 +39,12 @@ static ClickBinding click_bindings[] = {
{ XK_minus, 5 },
};
+static ShellBinding shell_bindings[] = {
+ /* key command */
+ { XK_b, "wmctrl -a firefox" },
+ { XK_t, "echo $0 >> ~/test" },
+};
+
/* exits on key release which allows click and exit with one key */
static unsigned int exit_keys[] = {
XK_Escape, XK_q, XK_space
diff --git a/xmouseless.c b/xmouseless.c
index 90dd4b1..e6acd29 100644
--- a/xmouseless.c
+++ b/xmouseless.c
@@ -1,4 +1,5 @@
/*
+ * xmouseless
*/
#include <stdio.h>
#include <stdlib.h>
@@ -30,6 +31,11 @@ typedef struct {
int speed;
} SpeedBindings;
+typedef struct {
+ KeySym keysym;
+ char *command;
+} ShellBinding;
+
/* load configuration */
#include "config.h"
@@ -171,6 +177,17 @@ void handle_keyrelease(XKeyEvent event) {
}
}
+ /* shell bindings */
+ for (i = 0; i < LENGTH(shell_bindings); i++) {
+ if (shell_bindings[i].keysym == keysym) {
+ printf("executing: %s\n", shell_bindings[i].command);
+ if (fork() == 0) {
+ system(shell_bindings[i].command);
+ exit(EXIT_SUCCESS);
+ }
+ }
+ }
+
/* exit */
for (i = 0; i < LENGTH(exit_keys); i++) {
if (exit_keys[i] == keysym) {