From 18e6569712ef6f77a35ddc50899dc292f557a679 Mon Sep 17 00:00:00 2001 From: project-repo Date: Fri, 30 Dec 2022 07:42:23 +0100 Subject: [PATCH] Add support for customizing keyboard repeat info --- input_manager.c | 23 ++++++++++++++++++++- input_manager.h | 2 ++ keybinding.c | 3 ++- parse.c | 54 ++++++++++++++++++++++++++++++++----------------- seat.c | 1 - 5 files changed, 61 insertions(+), 22 deletions(-) diff --git a/input_manager.c b/input_manager.c index 016a52a..8e65e4d 100644 --- a/input_manager.c +++ b/input_manager.c @@ -29,6 +29,7 @@ #include #include #include +#include #include void @@ -124,6 +125,8 @@ input_manager_create_empty_input_config() { /* Keyboards */ cfg->enable_keybindings=-1; + cfg->repeat_delay=-1; + cfg->repeat_rate=-1; return cfg; } @@ -221,15 +224,33 @@ input_manager_merge_input_configs(struct cg_input_config* cfg1, struct cg_input_ } else { out_cfg->enable_keybindings=cfg1->enable_keybindings; } + if(cfg1->repeat_delay == -1) { + out_cfg->repeat_delay=cfg2->repeat_delay; + } else { + out_cfg->repeat_delay=cfg1->repeat_delay; + } + if(cfg1->repeat_rate == -1) { + out_cfg->repeat_rate=cfg2->repeat_rate; + } else { + out_cfg->repeat_rate=cfg1->repeat_rate; + } return out_cfg; } void apply_keyboard_group_config(struct cg_input_config *config, struct cg_keyboard_group *group) { - if(group->enable_keybindings!=-1) { + if(config->enable_keybindings!=-1) { group->enable_keybindings=config->enable_keybindings; } + int repeat_delay=600,repeat_rate=25; + if(config->repeat_delay != -1) { + repeat_delay=config->repeat_delay; + } + if(config->repeat_rate != -1) { + repeat_rate=config->repeat_rate; + } + wlr_keyboard_set_repeat_info(&group->wlr_group->keyboard, repeat_rate, repeat_delay); } void diff --git a/input_manager.h b/input_manager.h index c96998d..bf74a10 100644 --- a/input_manager.h +++ b/input_manager.h @@ -103,6 +103,8 @@ struct cg_input_config { /* Keyboards */ int enable_keybindings; + int repeat_delay; + int repeat_rate; }; struct cg_input_device { diff --git a/keybinding.c b/keybinding.c index a9047e5..0ee70a1 100644 --- a/keybinding.c +++ b/keybinding.c @@ -1026,13 +1026,14 @@ print_keyboard_group(struct cg_keyboard_group *grp) { struct dyn_str outp_str; outp_str.len = 0; outp_str.cur_pos = 0; - uint32_t nmemb = 4; + uint32_t nmemb = 5; outp_str.str_arr = calloc(nmemb, sizeof(char *)); if(grp->identifier!=NULL) { print_str(&outp_str, "\"%s\": {\n", grp->identifier); } else { print_str(&outp_str, "\"NULL\": {\n"); } + print_str(&outp_str, "\"commands_enabled\": %d,\n", grp->enable_keybindings); print_str(&outp_str, "\"repeat_delay\": %d,\n", grp->wlr_group->keyboard.repeat_info.delay); print_str(&outp_str, "\"repeat_rate\": %d\n", grp->wlr_group->keyboard.repeat_info.rate); print_str(&outp_str, "}"); diff --git a/parse.c b/parse.c index f08295b..a504dbf 100644 --- a/parse.c +++ b/parse.c @@ -117,6 +117,25 @@ parse_float(char **saveptr, const char *delim) { } } +int +parse_uint(char **saveptr, const char *delim) { + char *uint_str = strtok_r(NULL, delim, saveptr); + if(uint_str == NULL) { + wlr_log(WLR_ERROR, "Expected a non-negative integer, got nothing"); + return -1; + } + long uint = strtol(uint_str, NULL, 10); + if(uint >= 0 && uint <= INT_MAX) { + return uint; + } else { + wlr_log(WLR_ERROR, + "Error parsing non-negative integer. Must be a number larger " + "or equal to 0 and less or equal to %d", + INT_MAX); + return -1; + } +} + struct cg_input_config * parse_input_config(char **saveptr, char **errstr) { struct cg_input_config *cfg=input_manager_create_empty_input_config(); @@ -330,6 +349,22 @@ parse_input_config(char **saveptr, char **errstr) { "Invalid option \"%s\" to setting \"keybindings\"", value); goto error; } + } else if(strcmp(setting, "repeat_delay") == 0) { + cfg->repeat_delay = parse_uint(saveptr, " "); + if(cfg->repeat_delay < 0 ) { + *errstr = log_error("Invalid option \"%s\" to setting " + "\"repeat_delay\", expected positive integer", + value); + goto error; + } + } else if(strcmp(setting, "repeat_rate") == 0) { + cfg->repeat_rate = parse_uint(saveptr, " "); + if(cfg->repeat_rate < 0 ) { + *errstr = log_error("Invalid option \"%s\" to setting " + "\"repeat_rate\", expected positive integer", + value); + goto error; + } } else { *errstr = log_error("Invalid option to command \"input\""); goto error; @@ -470,25 +505,6 @@ parse_workspaces(char **saveptr, char **errstr) { return nws; } -int -parse_uint(char **saveptr, const char *delim) { - char *uint_str = strtok_r(NULL, delim, saveptr); - if(uint_str == NULL) { - wlr_log(WLR_ERROR, "Expected a non-negative integer, got nothing"); - return -1; - } - long uint = strtol(uint_str, NULL, 10); - if(uint >= 0 && uint <= INT_MAX) { - return uint; - } else { - wlr_log(WLR_ERROR, - "Error parsing non-negative integer. Must be a number larger " - "or equal to 0 and less or equal to %d", - INT_MAX); - return -1; - } -} - int parse_output_config_keyword(char *key_str, enum output_status *status) { if(key_str == NULL) { diff --git a/seat.c b/seat.c index 875287b..7fac95b 100644 --- a/seat.c +++ b/seat.c @@ -422,7 +422,6 @@ new_keyboard(struct cg_seat *seat, struct cg_input_device *input_device) { xkb_keymap_unref(keymap); xkb_context_unref(context); - wlr_keyboard_set_repeat_info(device->keyboard, 25, 600); cg_keyboard_group_add(input_device, seat); ++seat->num_keyboards;