Make keyboard repeat info configurable

This commit is contained in:
emersion 2017-12-08 17:03:05 +01:00
parent 703df2a671
commit a3c0f97810
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
7 changed files with 69 additions and 6 deletions

View File

@ -42,6 +42,7 @@ struct roots_keyboard_config {
char *layout; char *layout;
char *variant; char *variant;
char *options; char *options;
int repeat_rate, repeat_delay;
struct wl_list link; struct wl_list link;
}; };

View File

@ -51,10 +51,16 @@ struct wlr_keyboard {
xkb_mod_mask_t group; xkb_mod_mask_t group;
} modifiers; } modifiers;
struct {
int32_t rate;
int32_t delay;
} repeat_info;
struct { struct {
struct wl_signal key; struct wl_signal key;
struct wl_signal modifiers; struct wl_signal modifiers;
struct wl_signal keymap; struct wl_signal keymap;
struct wl_signal repeat_info;
} events; } events;
void *data; void *data;
@ -74,6 +80,8 @@ struct wlr_event_keyboard_key {
void wlr_keyboard_set_keymap(struct wlr_keyboard *kb, void wlr_keyboard_set_keymap(struct wlr_keyboard *kb,
struct xkb_keymap *keymap); struct xkb_keymap *keymap);
void wlr_keyboard_set_repeat_info(struct wlr_keyboard *kb, int32_t rate,
int32_t delay);
void wlr_keyboard_led_update(struct wlr_keyboard *keyboard, uint32_t leds); void wlr_keyboard_led_update(struct wlr_keyboard *keyboard, uint32_t leds);
uint32_t wlr_keyboard_get_modifiers(struct wlr_keyboard *keyboard); uint32_t wlr_keyboard_get_modifiers(struct wlr_keyboard *keyboard);

View File

@ -146,6 +146,7 @@ struct wlr_seat_keyboard_state {
struct wl_listener keyboard_destroy; struct wl_listener keyboard_destroy;
struct wl_listener keyboard_keymap; struct wl_listener keyboard_keymap;
struct wl_listener keyboard_repeat_info;
struct wl_listener surface_destroy; struct wl_listener surface_destroy;
struct wl_listener resource_destroy; struct wl_listener resource_destroy;

View File

@ -213,6 +213,10 @@ static void config_handle_keyboard(struct roots_config *config,
kc->variant = strdup(value); kc->variant = strdup(value);
} else if (strcmp(name, "options") == 0) { } else if (strcmp(name, "options") == 0) {
kc->options = strdup(value); kc->options = strdup(value);
} else if (strcmp(name, "repeat-rate") == 0) {
kc->repeat_rate = strtol(value, NULL, 10);
} else if (strcmp(name, "repeat-delay") == 0) {
kc->repeat_delay = strtol(value, NULL, 10);
} else { } else {
wlr_log(L_ERROR, "got unknown keyboard config: %s", name); wlr_log(L_ERROR, "got unknown keyboard config: %s", name);
} }

View File

@ -306,6 +306,12 @@ static void keyboard_config_merge(struct roots_keyboard_config *config,
if (config->name == NULL) { if (config->name == NULL) {
config->name = fallback->name; config->name = fallback->name;
} }
if (config->repeat_rate <= 0) {
config->repeat_rate = fallback->repeat_rate;
}
if (config->repeat_delay <= 0) {
config->repeat_delay = fallback->repeat_delay;
}
} }
struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device, struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device,
@ -337,8 +343,7 @@ struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device,
keyboard_config_merge(config, &env_config); keyboard_config_merge(config, &env_config);
keyboard->config = config; keyboard->config = config;
struct xkb_rule_names rules; struct xkb_rule_names rules = { 0 };
memset(&rules, 0, sizeof(rules));
rules.rules = config->rules; rules.rules = config->rules;
rules.model = config->model; rules.model = config->model;
rules.layout = config->layout; rules.layout = config->layout;
@ -353,6 +358,10 @@ struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device,
&rules, XKB_KEYMAP_COMPILE_NO_FLAGS)); &rules, XKB_KEYMAP_COMPILE_NO_FLAGS));
xkb_context_unref(context); xkb_context_unref(context);
int repeat_rate = (config->repeat_rate > 0) ? config->repeat_rate : 25;
int repeat_delay = (config->repeat_delay > 0) ? config->repeat_delay : 600;
wlr_keyboard_set_repeat_info(device->keyboard, repeat_rate, repeat_delay);
return keyboard; return keyboard;
} }

View File

@ -102,6 +102,11 @@ void wlr_keyboard_init(struct wlr_keyboard *kb,
wl_signal_init(&kb->events.key); wl_signal_init(&kb->events.key);
wl_signal_init(&kb->events.modifiers); wl_signal_init(&kb->events.modifiers);
wl_signal_init(&kb->events.keymap); wl_signal_init(&kb->events.keymap);
wl_signal_init(&kb->events.repeat_info);
// Sane defaults
kb->repeat_info.rate = 25;
kb->repeat_info.delay = 600;
} }
void wlr_keyboard_destroy(struct wlr_keyboard *kb) { void wlr_keyboard_destroy(struct wlr_keyboard *kb) {
@ -167,6 +172,16 @@ void wlr_keyboard_set_keymap(struct wlr_keyboard *kb,
wl_signal_emit(&kb->events.keymap, kb); wl_signal_emit(&kb->events.keymap, kb);
} }
void wlr_keyboard_set_repeat_info(struct wlr_keyboard *kb, int32_t rate,
int32_t delay) {
if (kb->repeat_info.rate == rate && kb->repeat_info.delay == delay) {
return;
}
kb->repeat_info.rate = rate;
kb->repeat_info.delay = delay;
wl_signal_emit(&kb->events.repeat_info, kb);
}
uint32_t wlr_keyboard_get_modifiers(struct wlr_keyboard *kb) { uint32_t wlr_keyboard_get_modifiers(struct wlr_keyboard *kb) {
xkb_mod_mask_t mask = kb->modifiers.depressed | kb->modifiers.latched; xkb_mod_mask_t mask = kb->modifiers.depressed | kb->modifiers.latched;
uint32_t modifiers = 0; uint32_t modifiers = 0;

View File

@ -109,10 +109,18 @@ static void seat_client_send_keymap(struct wlr_seat_client *client,
wl_keyboard_send_keymap(client->keyboard, wl_keyboard_send_keymap(client->keyboard,
WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keyboard->keymap_fd, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keyboard->keymap_fd,
keyboard->keymap_size); keyboard->keymap_size);
}
static void seat_client_send_repeat_info(struct wlr_seat_client *client,
struct wlr_keyboard *keyboard) {
if (!keyboard || !client->keyboard) {
return;
}
if (wl_resource_get_version(client->keyboard) >= if (wl_resource_get_version(client->keyboard) >=
WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) { WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) {
wl_keyboard_send_repeat_info(client->keyboard, 25, 600); wl_keyboard_send_repeat_info(client->keyboard,
keyboard->repeat_info.rate, keyboard->repeat_info.delay);
} }
} }
@ -138,8 +146,9 @@ static void wl_seat_get_keyboard(struct wl_client *client,
wl_resource_set_implementation(seat_client->keyboard, &wl_keyboard_impl, wl_resource_set_implementation(seat_client->keyboard, &wl_keyboard_impl,
seat_client, &wl_keyboard_destroy); seat_client, &wl_keyboard_destroy);
seat_client_send_keymap(seat_client, struct wlr_keyboard *keyboard = seat_client->seat->keyboard_state.keyboard;
seat_client->seat->keyboard_state.keyboard); seat_client_send_keymap(seat_client, keyboard);
seat_client_send_repeat_info(seat_client, keyboard);
// TODO possibly handle the case where this keyboard needs an enter // TODO possibly handle the case where this keyboard needs an enter
// right away // right away
@ -695,6 +704,16 @@ static void handle_keyboard_keymap(struct wl_listener *listener, void *data) {
} }
} }
static void handle_keyboard_repeat_info(struct wl_listener *listener,
void *data) {
struct wlr_seat_keyboard_state *state =
wl_container_of(listener, state, keyboard_repeat_info);
struct wlr_seat_client *client;
wl_list_for_each(client, &state->seat->clients, link) {
seat_client_send_repeat_info(client, state->keyboard);
}
}
static void handle_keyboard_destroy(struct wl_listener *listener, void *data) { static void handle_keyboard_destroy(struct wl_listener *listener, void *data) {
struct wlr_seat_keyboard_state *state = struct wlr_seat_keyboard_state *state =
wl_container_of(listener, state, keyboard_destroy); wl_container_of(listener, state, keyboard_destroy);
@ -713,22 +732,28 @@ void wlr_seat_set_keyboard(struct wlr_seat *seat,
if (seat->keyboard_state.keyboard) { if (seat->keyboard_state.keyboard) {
wl_list_remove(&seat->keyboard_state.keyboard_destroy.link); wl_list_remove(&seat->keyboard_state.keyboard_destroy.link);
wl_list_remove(&seat->keyboard_state.keyboard_keymap.link); wl_list_remove(&seat->keyboard_state.keyboard_keymap.link);
wl_list_remove(&seat->keyboard_state.keyboard_repeat_info.link);
seat->keyboard_state.keyboard = NULL; seat->keyboard_state.keyboard = NULL;
} }
if (device) { if (device) {
assert(device->type == WLR_INPUT_DEVICE_KEYBOARD); assert(device->type == WLR_INPUT_DEVICE_KEYBOARD);
wl_signal_add(&device->events.destroy, wl_signal_add(&device->events.destroy,
&seat->keyboard_state.keyboard_destroy); &seat->keyboard_state.keyboard_destroy);
seat->keyboard_state.keyboard_destroy.notify = handle_keyboard_destroy; seat->keyboard_state.keyboard_destroy.notify = handle_keyboard_destroy;
wl_signal_add(&device->keyboard->events.keymap, wl_signal_add(&device->keyboard->events.keymap,
&seat->keyboard_state.keyboard_keymap); &seat->keyboard_state.keyboard_keymap);
seat->keyboard_state.keyboard_keymap.notify = handle_keyboard_keymap; seat->keyboard_state.keyboard_keymap.notify = handle_keyboard_keymap;
wl_signal_add(&device->keyboard->events.repeat_info,
&seat->keyboard_state.keyboard_repeat_info);
seat->keyboard_state.keyboard_repeat_info.notify =
handle_keyboard_repeat_info;
struct wlr_seat_client *client; struct wlr_seat_client *client;
wl_list_for_each(client, &seat->clients, link) { wl_list_for_each(client, &seat->clients, link) {
seat_client_send_keymap(client, device->keyboard); seat_client_send_keymap(client, device->keyboard);
seat_client_send_repeat_info(client, device->keyboard);
} }
seat->keyboard_state.keyboard = device->keyboard; seat->keyboard_state.keyboard = device->keyboard;