From ba6e07a147c5a69076ca0f8781f2e11dfbcaec19 Mon Sep 17 00:00:00 2001 From: Johannes Bensmann Date: Sun, 9 Jun 2019 17:48:36 +0200 Subject: added bindings to execute shell commands --- config.h | 6 ++++++ xmouseless.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) 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 #include @@ -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) { -- cgit v1.2.3