diff options
author | frsfnrrg <frsfnrrg@users.noreply.github.com> | 2018-07-29 18:50:20 -0400 |
---|---|---|
committer | frsfnrrg <frsfnrrg@users.noreply.github.com> | 2018-07-29 19:15:10 -0400 |
commit | 8dbbfa5965ca8bfe4bc023100387dd657bafe48e (patch) | |
tree | 53bf8301475a9250c2e5ebaa131086ede883ffc5 /sway | |
parent | Implement key repeat for pressed key bindings (diff) | |
download | sway-8dbbfa5965ca8bfe4bc023100387dd657bafe48e.tar.gz sway-8dbbfa5965ca8bfe4bc023100387dd657bafe48e.tar.zst sway-8dbbfa5965ca8bfe4bc023100387dd657bafe48e.zip |
Bindings use advised keyboard repeat parameters
Now 'repeat_delay' and 'repeat_rate' control the initial delay
and rate (per second) of repeated binding invocations.
If the repeat delay is zero, binding repetition is disabled.
When the repeat rate is zero, the binding is repeated exactly
once, assuming no other key events intervene.
Diffstat (limited to 'sway')
-rw-r--r-- | sway/input/keyboard.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/sway/input/keyboard.c b/sway/input/keyboard.c index be000fb9..160ef10b 100644 --- a/sway/input/keyboard.c +++ b/sway/input/keyboard.c | |||
@@ -285,10 +285,10 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
285 | } | 285 | } |
286 | 286 | ||
287 | // Set up (or clear) keyboard repeat for a pressed binding | 287 | // Set up (or clear) keyboard repeat for a pressed binding |
288 | if (next_repeat_binding) { | 288 | if (next_repeat_binding && wlr_device->keyboard->repeat_info.delay > 0) { |
289 | keyboard->repeat_binding = next_repeat_binding; | 289 | keyboard->repeat_binding = next_repeat_binding; |
290 | if (wl_event_source_timer_update(keyboard->key_repeat_source, | 290 | if (wl_event_source_timer_update(keyboard->key_repeat_source, |
291 | keyboard->key_repeat_initial_delay) < 0) { | 291 | wlr_device->keyboard->repeat_info.delay) < 0) { |
292 | wlr_log(WLR_DEBUG, "failed to set key repeat timer"); | 292 | wlr_log(WLR_DEBUG, "failed to set key repeat timer"); |
293 | } | 293 | } |
294 | } else if (keyboard->repeat_binding) { | 294 | } else if (keyboard->repeat_binding) { |
@@ -321,11 +321,15 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) { | |||
321 | 321 | ||
322 | static int handle_keyboard_repeat(void *data) { | 322 | static int handle_keyboard_repeat(void *data) { |
323 | struct sway_keyboard *keyboard = (struct sway_keyboard *)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; | ||
324 | if (keyboard->repeat_binding) { | 326 | if (keyboard->repeat_binding) { |
325 | // We queue the next event first, as the command might cancel it | 327 | if (wlr_device->repeat_info.rate > 0) { |
326 | if (wl_event_source_timer_update(keyboard->key_repeat_source, | 328 | // We queue the next event first, as the command might cancel it |
327 | keyboard->key_repeat_step_delay) < 0) { | 329 | if (wl_event_source_timer_update(keyboard->key_repeat_source, |
328 | wlr_log(WLR_DEBUG, "failed to update key repeat timer"); | 330 | 1000 / wlr_device->repeat_info.rate) < 0) { |
331 | wlr_log(WLR_DEBUG, "failed to update key repeat timer"); | ||
332 | } | ||
329 | } | 333 | } |
330 | 334 | ||
331 | seat_execute_command(keyboard->seat_device->sway_seat, | 335 | seat_execute_command(keyboard->seat_device->sway_seat, |
@@ -362,8 +366,6 @@ struct sway_keyboard *sway_keyboard_create(struct sway_seat *seat, | |||
362 | 366 | ||
363 | keyboard->key_repeat_source = wl_event_loop_add_timer(server.wl_event_loop, | 367 | keyboard->key_repeat_source = wl_event_loop_add_timer(server.wl_event_loop, |
364 | handle_keyboard_repeat, keyboard); | 368 | handle_keyboard_repeat, keyboard); |
365 | keyboard->key_repeat_initial_delay = 660; | ||
366 | keyboard->key_repeat_step_delay = 40; | ||
367 | 369 | ||
368 | return keyboard; | 370 | return keyboard; |
369 | } | 371 | } |