diff options
author | Drew DeVault <sir@cmpwn.com> | 2017-12-08 15:47:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-08 15:47:11 -0500 |
commit | eb4e91f96d206ff05ac7f6bb1972bf48f45e5e5e (patch) | |
tree | eab75ecb0f188786cd78286d09ebffb525ae74e1 | |
parent | 381a646d2fbcb1b488e1551438444ac267f39138 (diff) | |
parent | 2c6e52c164cfd19bac642d3507fb8584a0201845 (diff) |
Merge pull request #474 from emersion/customize-repeat-info
Make keyboard repeat info configurable
-rw-r--r-- | include/rootston/config.h | 1 | ||||
-rw-r--r-- | include/wlr/types/wlr_keyboard.h | 12 | ||||
-rw-r--r-- | include/wlr/types/wlr_seat.h | 1 | ||||
-rw-r--r-- | rootston/config.c | 4 | ||||
-rw-r--r-- | rootston/keyboard.c | 13 | ||||
-rw-r--r-- | types/wlr_keyboard.c | 15 | ||||
-rw-r--r-- | types/wlr_seat.c | 33 |
7 files changed, 73 insertions, 6 deletions
diff --git a/include/rootston/config.h b/include/rootston/config.h index de20fb8e..233692dc 100644 --- a/include/rootston/config.h +++ b/include/rootston/config.h @@ -42,6 +42,7 @@ struct roots_keyboard_config { char *layout; char *variant; char *options; + int repeat_rate, repeat_delay; struct wl_list link; }; diff --git a/include/wlr/types/wlr_keyboard.h b/include/wlr/types/wlr_keyboard.h index e2d50b03..450cd473 100644 --- a/include/wlr/types/wlr_keyboard.h +++ b/include/wlr/types/wlr_keyboard.h @@ -52,9 +52,15 @@ struct wlr_keyboard { } 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,12 @@ struct wlr_event_keyboard_key { void wlr_keyboard_set_keymap(struct wlr_keyboard *kb, struct xkb_keymap *keymap); +/** + * Sets the keyboard repeat info. `rate` is in key repeats/second and delay is + * in milliseconds. + */ +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); diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 6d59315b..6c04380e 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -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; diff --git a/rootston/config.c b/rootston/config.c index 59adf13c..6e596852 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -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); } diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 85033613..4aaf2d48 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -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; } diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index c4f2ed52..c494b45d 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -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; diff --git a/types/wlr_seat.c b/types/wlr_seat.c index ff1cbf7f..ab3e990d 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -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; |