diff options
| author | Martin Dørum <martid0311@gmail.com> | 2020-06-19 22:02:23 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-19 23:02:23 +0200 |
| commit | a99afe6a7075c962da72b140f02e18318052d833 (patch) | |
| tree | 50681eb07cf9faaa89462cd0838a29a96413a665 /loop.c | |
| parent | a6b3a0956b2fe53b291abe01433a4cea2c88e35a (diff) | |
Implement key repeat
Diffstat (limited to 'loop.c')
| -rw-r--r-- | loop.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -21,6 +21,7 @@ struct loop_timer { void (*callback)(void *data); void *data; struct timespec expiry; + bool removed; struct wl_list link; // struct loop_timer::link }; @@ -104,12 +105,19 @@ void loop_poll(struct loop *loop) { clock_gettime(CLOCK_MONOTONIC, &now); struct loop_timer *timer = NULL, *tmp_timer = NULL; wl_list_for_each_safe(timer, tmp_timer, &loop->timers, link) { + if (timer->removed) { + wl_list_remove(&timer->link); + free(timer); + continue; + } + bool expired = timer->expiry.tv_sec < now.tv_sec || (timer->expiry.tv_sec == now.tv_sec && timer->expiry.tv_nsec < now.tv_nsec); if (expired) { timer->callback(timer->data); - loop_remove_timer(loop, timer); + wl_list_remove(&timer->link); + free(timer); } } } @@ -184,8 +192,7 @@ bool loop_remove_timer(struct loop *loop, struct loop_timer *remove) { struct loop_timer *timer = NULL, *tmp_timer = NULL; wl_list_for_each_safe(timer, tmp_timer, &loop->timers, link) { if (timer == remove) { - wl_list_remove(&timer->link); - free(timer); + timer->removed = true; return true; } } |
