summaryrefslogtreecommitdiffstats
path: root/src/gui.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-03-15 23:10:59 +0100
committerBram Moolenaar <Bram@vim.org>2016-03-15 23:10:59 +0100
commit975b5271eed4fa0500c24a8f37be0b1797cb9db7 (patch)
treee2f73f9ae91f1fce55de8757dc1599fcc169c3fe /src/gui.c
parentab1fa3955f25dfdb7e329c3bd76e175c93c8cb5e (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.c35
1 files changed, 32 insertions, 3 deletions
diff --git a/src/gui.c b/src/gui.c
index 2701265f1d..f52d217aa8 100644
--- a/src/gui.c
+++ b/src/gui.c
@@ -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();