diff options
Diffstat (limited to 'rootston')
-rw-r--r-- | rootston/config.c | 50 | ||||
-rw-r--r-- | rootston/keyboard.c | 40 |
2 files changed, 82 insertions, 8 deletions
diff --git a/rootston/config.c b/rootston/config.c index 3280c6d1..5c889975 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -171,6 +171,45 @@ static int config_ini_handler(void *user, const char *section, const char *name, } else { wlr_log(L_ERROR, "got unknown device 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); + + if (strcmp(value, "quit") == 0) { + bc->action = BINDING_CONFIG_ACTION_QUIT; + } else { + wlr_log(L_ERROR, "got unknown key binding action: %s", value); + wl_list_remove(&bc->link); + free(bc); + return 1; + } + + bc->keysyms_len = 1; + char *symnames = strdup(name); + for (char *c = symnames; *c != '\0'; c++) { + if (*c == '+') { + *c = '\0'; + bc->keysyms_len++; + } + } + + bc->keysyms = calloc(1, bc->keysyms_len * sizeof(xkb_keysym_t)); + char *symname = symnames; + for (size_t i = 0; i < bc->keysyms_len; i++) { + 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[i] = sym; + symname += strlen(symname) + 1; + } + + free(symnames); } else { wlr_log(L_ERROR, "got unknown config section: %s", section); } @@ -182,6 +221,15 @@ struct roots_config *parse_args(int argc, char *argv[]) { struct roots_config *config = calloc(1, sizeof(struct roots_config)); wl_list_init(&config->outputs); wl_list_init(&config->devices); + wl_list_init(&config->bindings); + + // TEMPORARY, probably + struct binding_config *bc = calloc(1, sizeof(struct binding_config)); + wl_list_insert(&config->bindings, &bc->link); + bc->action = BINDING_CONFIG_ACTION_QUIT; + bc->keysyms_len = 1; + bc->keysyms = calloc(1, sizeof(xkb_keysym_t)); + bc->keysyms[0] = XKB_KEY_Escape; int c; while ((c = getopt(argc, argv, "C:h")) != -1) { @@ -238,6 +286,8 @@ void roots_config_destroy(struct roots_config *config) { free(dc); } + // TODO: free bindings + free(config->config_path); free(config->cursor.mapped_output); free(config->cursor.mapped_box); diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 81d564d5..79295ab4 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -20,23 +20,29 @@ static ssize_t keyboard_pressed_keysym_index(struct roots_keyboard *keyboard, return -1; } -static void keyboard_keysym_press(struct roots_keyboard *keyboard, - xkb_keysym_t keysym) { +static void keyboard_binding_execute(struct roots_keyboard *keyboard, + struct binding_config *bc) { struct roots_server *server = keyboard->input->server; + switch (bc->action) { + case BINDING_CONFIG_ACTION_QUIT: + wl_display_terminate(server->wl_display); + break; + } +} +static void keyboard_keysym_press(struct roots_keyboard *keyboard, + xkb_keysym_t keysym) { ssize_t i = keyboard_pressed_keysym_index(keyboard, keysym); if (i < 0) { - i = keyboard_pressed_keysym_index(keyboard, 0); + i = keyboard_pressed_keysym_index(keyboard, XKB_KEY_NoSymbol); if (i >= 0) { keyboard->pressed_keysyms[i] = keysym; } } - if (keysym == XKB_KEY_Escape) { - // TEMPORARY, probably - wl_display_terminate(server->wl_display); - } else if (keysym >= XKB_KEY_XF86Switch_VT_1 && + if (keysym >= XKB_KEY_XF86Switch_VT_1 && keysym <= XKB_KEY_XF86Switch_VT_12) { + struct roots_server *server = keyboard->input->server; if (wlr_backend_is_multi(server->backend)) { struct wlr_session *session = wlr_multi_get_session(server->backend); @@ -45,6 +51,24 @@ static void keyboard_keysym_press(struct roots_keyboard *keyboard, wlr_session_change_vt(session, vt); } } + return; + } + + struct wl_list *bindings = &keyboard->input->server->config->bindings; + struct binding_config *bc; + wl_list_for_each(bc, bindings, link) { + bool ok = true; + for (size_t i = 0; i < bc->keysyms_len; i++) { + ssize_t j = keyboard_pressed_keysym_index(keyboard, bc->keysyms[i]); + if (j < 0) { + ok = false; + break; + } + } + + if (ok) { + keyboard_binding_execute(keyboard, bc); + } } } @@ -52,7 +76,7 @@ static void keyboard_keysym_release(struct roots_keyboard *keyboard, xkb_keysym_t keysym) { ssize_t i = keyboard_pressed_keysym_index(keyboard, keysym); if (i >= 0) { - keyboard->pressed_keysyms[i] = 0; + keyboard->pressed_keysyms[i] = XKB_KEY_NoSymbol; } } |