diff options
Diffstat (limited to 'sway/input/keyboard.c')
-rw-r--r-- | sway/input/keyboard.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index 8dc8239c..160ef10b 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c | |||
@@ -264,6 +264,7 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
264 | } | 264 | } |
265 | 265 | ||
266 | // Identify and execute active pressed binding | 266 | // Identify and execute active pressed binding |
267 | struct sway_binding *next_repeat_binding = NULL; | ||
267 | if (event->state == WLR_KEY_PRESSED) { | 268 | if (event->state == WLR_KEY_PRESSED) { |
268 | struct sway_binding *binding_pressed = NULL; | 269 | struct sway_binding *binding_pressed = NULL; |
269 | get_active_binding(&keyboard->state_keycodes, | 270 | get_active_binding(&keyboard->state_keycodes, |
@@ -279,6 +280,21 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
279 | if (binding_pressed) { | 280 | if (binding_pressed) { |
280 | seat_execute_command(seat, binding_pressed); | 281 | seat_execute_command(seat, binding_pressed); |
281 | handled = true; | 282 | handled = true; |
283 | next_repeat_binding = binding_pressed; | ||
284 | } | ||
285 | } | ||
286 | |||
287 | // Set up (or clear) keyboard repeat for a pressed binding | ||
288 | if (next_repeat_binding && wlr_device->keyboard->repeat_info.delay > 0) { | ||
289 | keyboard->repeat_binding = next_repeat_binding; | ||
290 | if (wl_event_source_timer_update(keyboard->key_repeat_source, | ||
291 | wlr_device->keyboard->repeat_info.delay) < 0) { | ||
292 | wlr_log(WLR_DEBUG, "failed to set key repeat timer"); | ||
293 | } | ||
294 | } else if (keyboard->repeat_binding) { | ||
295 | keyboard->repeat_binding = NULL; | ||
296 | if (wl_event_source_timer_update(keyboard->key_repeat_source, 0) < 0) { | ||
297 | wlr_log(WLR_DEBUG, "failed to disarm key repeat timer"); | ||
282 | } | 298 | } |
283 | } | 299 | } |
284 | 300 | ||
@@ -303,6 +319,26 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
303 | transaction_commit_dirty(); | 319 | transaction_commit_dirty(); |
304 | } | 320 | } |
305 | 321 | ||
322 | static int handle_keyboard_repeat(void *data) { | ||
323 | struct sway_keyboard *keyboard = (struct sway_keyboard *)data; | ||
324 | struct wlr_keyboard *wlr_device = | ||
325 | keyboard->seat_device->input_device->wlr_device->keyboard; | ||
326 | if (keyboard->repeat_binding) { | ||
327 | if (wlr_device->repeat_info.rate > 0) { | ||
328 | // We queue the next event first, as the command might cancel it | ||
329 | if (wl_event_source_timer_update(keyboard->key_repeat_source, | ||
330 | 1000 / wlr_device->repeat_info.rate) < 0) { | ||
331 | wlr_log(WLR_DEBUG, "failed to update key repeat timer"); | ||
332 | } | ||
333 | } | ||
334 | |||
335 | seat_execute_command(keyboard->seat_device->sway_seat, | ||
336 | keyboard->repeat_binding); | ||
337 | transaction_commit_dirty(); | ||
338 | } | ||
339 | return 0; | ||
340 | } | ||
341 | |||
306 | static void handle_keyboard_modifiers(struct wl_listener *listener, | 342 | static void handle_keyboard_modifiers(struct wl_listener *listener, |
307 | void *data) { | 343 | void *data) { |
308 | struct sway_keyboard *keyboard = | 344 | struct sway_keyboard *keyboard = |
@@ -328,6 +364,9 @@ struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat, | |||
328 | wl_list_init(&keyboard->keyboard_key.link); | 364 | wl_list_init(&keyboard->keyboard_key.link); |
329 | wl_list_init(&keyboard->keyboard_modifiers.link); | 365 | wl_list_init(&keyboard->keyboard_modifiers.link); |
330 | 366 | ||
367 | keyboard->key_repeat_source = wl_event_loop_add_timer(server.wl_event_loop, | ||
368 | handle_keyboard_repeat, keyboard); | ||
369 | |||
331 | return keyboard; | 370 | return keyboard; |
332 | } | 371 | } |
333 | 372 | ||
@@ -441,5 +480,6 @@ void sway_keyboard_destroy(struct sway_keyboard *keyboard) { | |||
441 | } | 480 | } |
442 | wl_list_remove(&keyboard->keyboard_key.link); | 481 | wl_list_remove(&keyboard->keyboard_key.link); |
443 | wl_list_remove(&keyboard->keyboard_modifiers.link); | 482 | wl_list_remove(&keyboard->keyboard_modifiers.link); |
483 | wl_event_source_remove(keyboard->key_repeat_source); | ||
444 | free(keyboard); | 484 | free(keyboard); |
445 | } | 485 | } |