aboutsummaryrefslogtreecommitdiff
path: root/rootston/keyboard.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-10-06 11:13:37 -0400
committerGitHub <noreply@github.com>2017-10-06 11:13:37 -0400
commitb351e0a95063114f8ff06c90c21d76cb9d26834e (patch)
treed6b2a838d1388bc404a1c5813d3fa3b84ab98daa /rootston/keyboard.c
parent6aafc2f61a395cf72b204f487e74bd83965a41e6 (diff)
parentf402598ee115e06a9d7595042495e9b061d7530a (diff)
Merge pull request #224 from emersion/rootston-commands
Add command to close views
Diffstat (limited to 'rootston/keyboard.c')
-rw-r--r--rootston/keyboard.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/rootston/keyboard.c b/rootston/keyboard.c
index 6f6fa0e8..6f4334af 100644
--- a/rootston/keyboard.c
+++ b/rootston/keyboard.c
@@ -21,19 +21,28 @@ static ssize_t keyboard_pressed_keysym_index(struct roots_keyboard *keyboard,
return -1;
}
+static const char *exec_prefix = "exec ";
+
static void keyboard_binding_execute(struct roots_keyboard *keyboard,
- char *command) {
+ const char *command) {
struct roots_server *server = keyboard->input->server;
if (strcmp(command, "exit") == 0) {
wl_display_terminate(server->wl_display);
- } else {
+ } else if (strcmp(command, "close") == 0) {
+ if (keyboard->input->last_active_view != NULL) {
+ view_close(keyboard->input->last_active_view);
+ }
+ } else if (strncmp(exec_prefix, command, strlen(exec_prefix)) == 0) {
+ const char *shell_cmd = command + strlen(exec_prefix);
pid_t pid = fork();
if (pid < 0) {
wlr_log(L_ERROR, "cannot execute binding command: fork() failed");
return;
} else if (pid == 0) {
- execl("/bin/sh", "/bin/sh", "-c", command, (void *)NULL);
+ execl("/bin/sh", "/bin/sh", "-c", shell_cmd, (void *)NULL);
}
+ } else {
+ wlr_log(L_ERROR, "unknown binding command: %s", command);
}
}