Make keyboard repeat info configurable

master
emersion 7 years ago
parent 703df2a671
commit a3c0f97810
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

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

@ -51,10 +51,16 @@ struct wlr_keyboard {
xkb_mod_mask_t group;
} modifiers;
struct {
int32_t rate;
int32_t delay;
} repeat_info;
struct {
struct wl_signal key;
struct wl_signal modifiers;
struct wl_signal keymap;
struct wl_signal repeat_info;
} events;
void *data;
@ -74,6 +80,8 @@ struct wlr_event_keyboard_key {
void wlr_keyboard_set_keymap(struct wlr_keyboard *kb,
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);
uint32_t wlr_keyboard_get_modifiers(struct wlr_keyboard *keyboard);

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

@ -213,6 +213,10 @@ static void config_handle_keyboard(struct roots_config *config,
kc->variant = strdup(value);
} else if (strcmp(name, "options") == 0) {
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 {
wlr_log(L_ERROR, "got unknown keyboard config: %s", name);
}

@ -306,6 +306,12 @@ static void keyboard_config_merge(struct roots_keyboard_config *config,
if (config->name == NULL) {
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,
@ -337,8 +343,7 @@ struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device,
keyboard_config_merge(config, &env_config);
keyboard->config = config;
struct xkb_rule_names rules;
memset(&rules, 0, sizeof(rules));
struct xkb_rule_names rules = { 0 };
rules.rules = config->rules;
rules.model = config->model;
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));
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;
}

@ -102,6 +102,11 @@ void wlr_keyboard_init(struct wlr_keyboard *kb,
wl_signal_init(&kb->events.key);
wl_signal_init(&kb->events.modifiers);
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) {
@ -167,6 +172,16 @@ void wlr_keyboard_set_keymap(struct wlr_keyboard *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) {
xkb_mod_mask_t mask = kb->modifiers.depressed | kb->modifiers.latched;
uint32_t modifiers = 0;

@ -109,10 +109,18 @@ static void seat_client_send_keymap(struct wlr_seat_client *client,
wl_keyboard_send_keymap(client->keyboard,
WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keyboard->keymap_fd,
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) >=
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,
seat_client, &wl_keyboard_destroy);
seat_client_send_keymap(seat_client,
seat_client->seat->keyboard_state.keyboard);
struct wlr_keyboard *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
// 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) {
struct wlr_seat_keyboard_state *state =
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) {
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_repeat_info.link);
seat->keyboard_state.keyboard = NULL;
}
if (device) {
assert(device->type == WLR_INPUT_DEVICE_KEYBOARD);
wl_signal_add(&device->events.destroy,
&seat->keyboard_state.keyboard_destroy);
seat->keyboard_state.keyboard_destroy.notify = handle_keyboard_destroy;
wl_signal_add(&device->keyboard->events.keymap,
&seat->keyboard_state.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;
wl_list_for_each(client, &seat->clients, link) {
seat_client_send_keymap(client, device->keyboard);
seat_client_send_repeat_info(client, device->keyboard);
}
seat->keyboard_state.keyboard = device->keyboard;

Loading…
Cancel
Save