diff options
author | Bram Moolenaar <Bram@vim.org> | 2016-03-15 23:10:59 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2016-03-15 23:10:59 +0100 |
commit | 975b5271eed4fa0500c24a8f37be0b1797cb9db7 (patch) | |
tree | e2f73f9ae91f1fce55de8757dc1599fcc169c3fe /src/gui.c | |
parent | ab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e (diff) |
patch 7.4.1578v7.4.1578
Problem: There is no way to invoke a function later or periodically.
Solution: Add timer support.
Diffstat (limited to 'src/gui.c')
-rw-r--r-- | src/gui.c | 35 |
1 files changed, 32 insertions, 3 deletions
@@ -2849,6 +2849,35 @@ gui_insert_lines(int row, int count) } } + static int +gui_wait_for_chars_or_timer(long wtime) +{ +#ifdef FEAT_TIMERS + int due_time; + long remaining = wtime; + + /* When waiting very briefly don't trigger timers. */ + if (wtime >= 0 && wtime < 10L) + return gui_mch_wait_for_chars(wtime); + + while (wtime < 0 || remaining > 0) + { + /* Trigger timers and then get the time in wtime until the next one is + * due. Wait up to that time. */ + due_time = check_due_timer(); + if (due_time <= 0 || (wtime > 0 && due_time > remaining)) + due_time = remaining; + if (gui_mch_wait_for_chars(due_time)) + return TRUE; + if (wtime > 0) + remaining -= due_time; + } + return FALSE; +#else + return gui_mch_wait_for_chars(wtime); +#endif +} + /* * The main GUI input routine. Waits for a character from the keyboard. * wtime == -1 Wait forever. @@ -2885,7 +2914,7 @@ gui_wait_for_chars(long wtime) /* Blink when waiting for a character. Probably only does something * for showmatch() */ gui_mch_start_blink(); - retval = gui_mch_wait_for_chars(wtime); + retval = gui_wait_for_chars_or_timer(wtime); gui_mch_stop_blink(); return retval; } @@ -2901,7 +2930,7 @@ gui_wait_for_chars(long wtime) * 'updatetime' and if nothing is typed within that time put the * K_CURSORHOLD key in the input buffer. */ - if (gui_mch_wait_for_chars(p_ut) == OK) + if (gui_wait_for_chars_or_timer(p_ut) == OK) retval = OK; #ifdef FEAT_AUTOCMD else if (trigger_cursorhold()) @@ -2922,7 +2951,7 @@ gui_wait_for_chars(long wtime) { /* Blocking wait. */ before_blocking(); - retval = gui_mch_wait_for_chars(-1L); + retval = gui_wait_for_chars_or_timer(-1L); } gui_mch_stop_blink(); |