Add support for customizing keyboard repeat info

This commit is contained in:
project-repo 2022-12-30 07:42:23 +01:00
commit 18e6569712
5 changed files with 61 additions and 22 deletions

View file

@ -29,6 +29,7 @@
#include <wlr/types/wlr_input_inhibitor.h>
#include <wlr/types/wlr_virtual_keyboard_v1.h>
#include <wlr/types/wlr_virtual_pointer_v1.h>
#include <wlr/types/wlr_keyboard_group.h>
#include <wlr/util/log.h>
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

View file

@ -103,6 +103,8 @@ struct cg_input_config {
/* Keyboards */
int enable_keybindings;
int repeat_delay;
int repeat_rate;
};
struct cg_input_device {

View file

@ -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, "}");

54
parse.c
View file

@ -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) {

1
seat.c
View file

@ -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;