summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-06-02 14:30:04 +0200
committerBram Moolenaar <Bram@vim.org>2016-06-02 14:30:04 +0200
commit4231da403e3c879dd6ac261e51f4ca60813935e3 (patch)
treed0c43a8b05ae0a727db41ac821ffc36df6d37880
parentc4bc0e6542185b659d2a165b635f9561549071ea (diff)
downloadvim-git-4231da403e3c879dd6ac261e51f4ca60813935e3.tar.gz
patch 7.4.1873v7.4.1873
Problem: When a callback adds a timer the GUI doesn't use it until later. (Ramel Eshed) Solution: Return early if a callback adds a timer.
-rw-r--r--src/ex_cmds2.c1
-rw-r--r--src/globals.h4
-rw-r--r--src/gui_gtk_x11.c35
-rw-r--r--src/gui_w32.c38
-rw-r--r--src/gui_x11.c24
-rw-r--r--src/version.c2
6 files changed, 77 insertions, 27 deletions
diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c
index 5efe0ec15..e0a392dee 100644
--- a/src/ex_cmds2.c
+++ b/src/ex_cmds2.c
@@ -1101,6 +1101,7 @@ insert_timer(timer_T *timer)
if (first_timer != NULL)
first_timer->tr_prev = timer;
first_timer = timer;
+ did_add_timer = TRUE;
}
/*
diff --git a/src/globals.h b/src/globals.h
index 369eb546e..2e84e579c 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -1635,6 +1635,10 @@ EXTERN int disable_char_avail_for_testing INIT(= 0);
EXTERN int in_free_unref_items INIT(= FALSE);
#endif
+#ifdef FEAT_TIMERS
+EXTERN int did_add_timer INIT(= FALSE);
+#endif
+
/*
* Optional Farsi support. Include it here, so EXTERN and INIT are defined.
*/
diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c
index 77e84c1be..d497c7530 100644
--- a/src/gui_gtk_x11.c
+++ b/src/gui_gtk_x11.c
@@ -6535,15 +6535,15 @@ input_timer_cb(gpointer data)
int
gui_mch_wait_for_chars(long wtime)
{
- int focus;
- guint timer;
- static int timed_out;
+ int focus;
+ guint timer;
+ static int timed_out;
+ int retval = FAIL;
timed_out = FALSE;
/* this timeout makes sure that we will return if no characters arrived in
* time */
-
if (wtime > 0)
#if GTK_CHECK_VERSION(3,0,0)
timer = g_timeout_add((guint)wtime, input_timer_cb, &timed_out);
@@ -6568,7 +6568,15 @@ gui_mch_wait_for_chars(long wtime)
}
#ifdef MESSAGE_QUEUE
+# ifdef FEAT_TIMERS
+ did_add_timer = FALSE;
+# endif
parse_queued_messages();
+# ifdef FEAT_TIMERS
+ if (did_add_timer)
+ /* Need to recompute the waiting time. */
+ goto theend;
+# endif
#endif
/*
@@ -6582,13 +6590,8 @@ gui_mch_wait_for_chars(long wtime)
/* Got char, return immediately */
if (input_available())
{
- if (timer != 0 && !timed_out)
-#if GTK_CHECK_VERSION(3,0,0)
- g_source_remove(timer);
-#else
- gtk_timeout_remove(timer);
-#endif
- return OK;
+ retval = OK;
+ goto theend;
}
} while (wtime < 0 || !timed_out);
@@ -6597,7 +6600,15 @@ gui_mch_wait_for_chars(long wtime)
*/
gui_mch_update();
- return FAIL;
+theend:
+ if (timer != 0 && !timed_out)
+#if GTK_CHECK_VERSION(3,0,0)
+ g_source_remove(timer);
+#else
+ gtk_timeout_remove(timer);
+#endif
+
+ return retval;
}
diff --git a/src/gui_w32.c b/src/gui_w32.c
index 10c14c9d9..82ca7de5d 100644
--- a/src/gui_w32.c
+++ b/src/gui_w32.c
@@ -2022,6 +2022,22 @@ gui_mch_update(void)
process_message();
}
+ static void
+remove_any_timer(void)
+{
+ MSG msg;
+
+ if (s_wait_timer != 0 && !s_timed_out)
+ {
+ KillTimer(NULL, s_wait_timer);
+
+ /* Eat spurious WM_TIMER messages */
+ while (pPeekMessage(&msg, s_hwnd, WM_TIMER, WM_TIMER, PM_REMOVE))
+ ;
+ s_wait_timer = 0;
+ }
+}
+
/*
* GUI input routine called by gui_wait_for_chars(). Waits for a character
* from the keyboard.
@@ -2073,6 +2089,9 @@ gui_mch_wait_for_chars(int wtime)
s_need_activate = FALSE;
}
+#ifdef FEAT_TIMERS
+ did_add_timer = FALSE;
+#endif
#ifdef MESSAGE_QUEUE
/* Check channel while waiting message. */
for (;;)
@@ -2098,15 +2117,7 @@ gui_mch_wait_for_chars(int wtime)
if (input_available())
{
- if (s_wait_timer != 0 && !s_timed_out)
- {
- KillTimer(NULL, s_wait_timer);
-
- /* Eat spurious WM_TIMER messages */
- while (pPeekMessage(&msg, s_hwnd, WM_TIMER, WM_TIMER, PM_REMOVE))
- ;
- s_wait_timer = 0;
- }
+ remove_any_timer();
allow_scrollbar = FALSE;
/* Clear pending mouse button, the release event may have been
@@ -2117,6 +2128,15 @@ gui_mch_wait_for_chars(int wtime)
return OK;
}
+
+#ifdef FEAT_TIMERS
+ if (did_add_timer)
+ {
+ /* Need to recompute the waiting time. */
+ remove_any_timer();
+ break;
+ }
+#endif
}
allow_scrollbar = FALSE;
return FAIL;
diff --git a/src/gui_x11.c b/src/gui_x11.c
index b525cf7a6..7d01e79dc 100644
--- a/src/gui_x11.c
+++ b/src/gui_x11.c
@@ -2368,7 +2368,7 @@ find_closest_color(Colormap colormap, XColor *colorPtr)
for (i = 0; i < cmap_size; i++)
colortable[i].pixel = (unsigned long)i;
- XQueryColors (gui.dpy, colormap, colortable, cmap_size);
+ XQueryColors(gui.dpy, colormap, colortable, cmap_size);
/*
* Find the color that best approximates the desired one, then
@@ -2792,7 +2792,8 @@ gui_mch_update(void)
int
gui_mch_wait_for_chars(long wtime)
{
- int focus;
+ int focus;
+ int retval = FAIL;
/*
* Make this static, in case gui_x11_timer_cb is called after leaving
@@ -2828,7 +2829,15 @@ gui_mch_wait_for_chars(long wtime)
}
#ifdef MESSAGE_QUEUE
+# ifdef FEAT_TIMERS
+ did_add_timer = FALSE;
+# endif
parse_queued_messages();
+# ifdef FEAT_TIMERS
+ if (did_add_timer)
+ /* Need to recompute the waiting time. */
+ break;
+# endif
#endif
/*
@@ -2843,12 +2852,15 @@ gui_mch_wait_for_chars(long wtime)
if (input_available())
{
- if (timer != (XtIntervalId)0 && !timed_out)
- XtRemoveTimeOut(timer);
- return OK;
+ retval = OK;
+ break;
}
}
- return FAIL;
+
+ if (timer != (XtIntervalId)0 && !timed_out)
+ XtRemoveTimeOut(timer);
+
+ return retval;
}
/*
diff --git a/src/version.c b/src/version.c
index b87300af3..3c0419586 100644
--- a/src/version.c
+++ b/src/version.c
@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1873,
+/**/
1872,
/**/
1871,