diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-10-12 20:00:04 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-12 20:00:04 -0400 |
commit | 1df9b0bc1374a517e81fa679f277da417dd14fda (patch) | |
tree | be4ecd24c0ca0ba6a275dbd171734cc597d330de /rootston | |
parent | 42ddeb6a5ee17eb7c1dcdf5c82ea070c0b040c9f (diff) | |
parent | 96079ff8979a1d6e788250cc18c46fe17b26c147 (diff) |
Merge pull request #266 from versusvoid/window-switching
Window switching binding
Diffstat (limited to 'rootston')
-rw-r--r-- | rootston/config.c | 89 | ||||
-rw-r--r-- | rootston/keyboard.c | 7 | ||||
-rw-r--r-- | rootston/rootston.ini.example | 1 |
3 files changed, 49 insertions, 48 deletions
diff --git a/rootston/config.c b/rootston/config.c index 4918c8dd..5e911e39 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -11,6 +11,7 @@ #include <wlr/util/log.h> #include <wlr/types/wlr_box.h> #include "rootston/config.h" +#include "rootston/input.h" #include "rootston/ini.h" static void usage(const char *name, int ret) { @@ -109,6 +110,42 @@ static uint32_t parse_modifier(const char *symname) { } } +void add_binding_config(struct wl_list *bindings, const char* combination, + const char* command) { + struct binding_config *bc = calloc(1, sizeof(struct binding_config)); + + xkb_keysym_t keysyms[ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP]; + char *symnames = strdup(combination); + char* symname = strtok(symnames, "+"); + while (symname) { + uint32_t modifier = parse_modifier(symname); + if (modifier != 0) { + bc->modifiers |= modifier; + } else { + xkb_keysym_t sym = xkb_keysym_from_name(symname, + XKB_KEYSYM_NO_FLAGS); + if (sym == XKB_KEY_NoSymbol) { + wlr_log(L_ERROR, "got unknown key binding symbol: %s", + symname); + free(bc); + bc = NULL; + break; + } + keysyms[bc->keysyms_len] = sym; + bc->keysyms_len++; + } + symname = strtok(NULL, "+"); + } + free(symnames); + + if (bc) { + wl_list_insert(bindings, &bc->link); + bc->command = strdup(command); + bc->keysyms = malloc(bc->keysyms_len * sizeof(xkb_keysym_t)); + memcpy(bc->keysyms, keysyms, bc->keysyms_len * sizeof(xkb_keysym_t)); + } +} + static const char *output_prefix = "output:"; static const char *device_prefix = "device:"; @@ -216,45 +253,7 @@ static int config_ini_handler(void *user, const char *section, const char *name, wlr_log(L_ERROR, "got unknown keyboard config: %s", name); } } else if (strcmp(section, "bindings") == 0) { - struct binding_config *bc = calloc(1, sizeof(struct binding_config)); - wl_list_insert(&config->bindings, &bc->link); - - bc->command = strdup(value); - - size_t keysyms_len = 1; - char *symnames = strdup(name); - for (char *c = symnames; *c != '\0'; c++) { - if (*c == '+') { - *c = '\0'; - keysyms_len++; - } - } - - // TODO: bc->keysyms is larger than needed - bc->keysyms = calloc(1, keysyms_len * sizeof(xkb_keysym_t)); - char *symname = symnames; - for (size_t i = 0; i < keysyms_len; i++) { - uint32_t modifier = parse_modifier(symname); - if (modifier != 0) { - bc->modifiers |= modifier; - } else { - xkb_keysym_t sym = xkb_keysym_from_name(symname, - XKB_KEYSYM_NO_FLAGS); - if (sym == XKB_KEY_NoSymbol) { - wlr_log(L_ERROR, "got unknown key binding symbol: %s", - symname); - wl_list_remove(&bc->link); - free(bc->keysyms); - free(bc); - break; - } - bc->keysyms[bc->keysyms_len] = sym; - bc->keysyms_len++; - } - symname += strlen(symname) + 1; - } - - free(symnames); + add_binding_config(&config->bindings, name, value); } else { wlr_log(L_ERROR, "got unknown config section: %s", section); } @@ -298,15 +297,9 @@ struct roots_config *parse_args(int argc, char *argv[]) { if (result == -1) { wlr_log(L_DEBUG, "No config file found. Using empty config."); - - struct binding_config *bc = calloc(1, sizeof(struct binding_config)); - wl_list_insert(&config->bindings, &bc->link); - bc->command = strdup("exit"); - bc->modifiers = WLR_MODIFIER_LOGO; - bc->keysyms_len = 2; - bc->keysyms = calloc(1, bc->keysyms_len * sizeof(xkb_keysym_t)); - bc->keysyms[0] = XKB_KEY_Meta_L; - bc->keysyms[1] = XKB_KEY_q; + add_binding_config(&config->bindings, "Logo+Shift+e", "exit"); + add_binding_config(&config->bindings, "Ctrl+q", "close"); + add_binding_config(&config->bindings, "Alt+Tab", "next_window"); } else if (result == -2) { wlr_log(L_ERROR, "Could not allocate memory to parse config file"); exit(1); diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 6f4334af..aee6b098 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -32,6 +32,13 @@ static void keyboard_binding_execute(struct roots_keyboard *keyboard, if (keyboard->input->last_active_view != NULL) { view_close(keyboard->input->last_active_view); } + } else if (strcmp(command, "next_window") == 0) { + if (server->desktop->views->length > 0) { + struct roots_view *view = server->desktop->views->items[0]; + set_view_focus(keyboard->input, server->desktop, view); + wlr_seat_keyboard_notify_enter(keyboard->input->wl_seat, + view->wlr_surface); + } } else if (strncmp(exec_prefix, command, strlen(exec_prefix)) == 0) { const char *shell_cmd = command + strlen(exec_prefix); pid_t pid = fork(); diff --git a/rootston/rootston.ini.example b/rootston/rootston.ini.example index 460efa13..4774108a 100644 --- a/rootston/rootston.ini.example +++ b/rootston/rootston.ini.example @@ -38,3 +38,4 @@ meta-key = Logo [bindings] Logo+Shift+e = exit # Stop the compositor Logo+q = close # Close the current view +Alt+Tab = next_window # Cycle through windows |