Parse bindings in config, execute bindings
This commit is contained in:
parent
d32018f1ac
commit
97d0fe8976
|
@ -18,6 +18,17 @@ struct device_config {
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum binding_config_action {
|
||||||
|
BINDING_CONFIG_ACTION_QUIT,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct binding_config {
|
||||||
|
xkb_keysym_t *keysyms;
|
||||||
|
size_t keysyms_len;
|
||||||
|
enum binding_config_action action;
|
||||||
|
struct wl_list link;
|
||||||
|
};
|
||||||
|
|
||||||
struct roots_config {
|
struct roots_config {
|
||||||
// TODO: Multiple cursors, multiseat
|
// TODO: Multiple cursors, multiseat
|
||||||
struct {
|
struct {
|
||||||
|
@ -27,6 +38,7 @@ struct roots_config {
|
||||||
|
|
||||||
struct wl_list outputs;
|
struct wl_list outputs;
|
||||||
struct wl_list devices;
|
struct wl_list devices;
|
||||||
|
struct wl_list bindings;
|
||||||
char *config_path;
|
char *config_path;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -171,6 +171,45 @@ static int config_ini_handler(void *user, const char *section, const char *name,
|
||||||
} else {
|
} else {
|
||||||
wlr_log(L_ERROR, "got unknown device config: %s", name);
|
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 {
|
} else {
|
||||||
wlr_log(L_ERROR, "got unknown config section: %s", section);
|
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));
|
struct roots_config *config = calloc(1, sizeof(struct roots_config));
|
||||||
wl_list_init(&config->outputs);
|
wl_list_init(&config->outputs);
|
||||||
wl_list_init(&config->devices);
|
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;
|
int c;
|
||||||
while ((c = getopt(argc, argv, "C:h")) != -1) {
|
while ((c = getopt(argc, argv, "C:h")) != -1) {
|
||||||
|
@ -238,6 +286,8 @@ void roots_config_destroy(struct roots_config *config) {
|
||||||
free(dc);
|
free(dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: free bindings
|
||||||
|
|
||||||
free(config->config_path);
|
free(config->config_path);
|
||||||
free(config->cursor.mapped_output);
|
free(config->cursor.mapped_output);
|
||||||
free(config->cursor.mapped_box);
|
free(config->cursor.mapped_box);
|
||||||
|
|
|
@ -20,23 +20,29 @@ static ssize_t keyboard_pressed_keysym_index(struct roots_keyboard *keyboard,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
static void keyboard_keysym_press(struct roots_keyboard *keyboard,
|
||||||
xkb_keysym_t keysym) {
|
xkb_keysym_t keysym) {
|
||||||
struct roots_server *server = keyboard->input->server;
|
|
||||||
|
|
||||||
ssize_t i = keyboard_pressed_keysym_index(keyboard, keysym);
|
ssize_t i = keyboard_pressed_keysym_index(keyboard, keysym);
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
i = keyboard_pressed_keysym_index(keyboard, 0);
|
i = keyboard_pressed_keysym_index(keyboard, XKB_KEY_NoSymbol);
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
keyboard->pressed_keysyms[i] = keysym;
|
keyboard->pressed_keysyms[i] = keysym;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keysym == XKB_KEY_Escape) {
|
if (keysym >= XKB_KEY_XF86Switch_VT_1 &&
|
||||||
// TEMPORARY, probably
|
|
||||||
wl_display_terminate(server->wl_display);
|
|
||||||
} else if (keysym >= XKB_KEY_XF86Switch_VT_1 &&
|
|
||||||
keysym <= XKB_KEY_XF86Switch_VT_12) {
|
keysym <= XKB_KEY_XF86Switch_VT_12) {
|
||||||
|
struct roots_server *server = keyboard->input->server;
|
||||||
if (wlr_backend_is_multi(server->backend)) {
|
if (wlr_backend_is_multi(server->backend)) {
|
||||||
struct wlr_session *session =
|
struct wlr_session *session =
|
||||||
wlr_multi_get_session(server->backend);
|
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);
|
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) {
|
xkb_keysym_t keysym) {
|
||||||
ssize_t i = keyboard_pressed_keysym_index(keyboard, keysym);
|
ssize_t i = keyboard_pressed_keysym_index(keyboard, keysym);
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
keyboard->pressed_keysyms[i] = 0;
|
keyboard->pressed_keysyms[i] = XKB_KEY_NoSymbol;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue