To: vim_dev@googlegroups.com Subject: Patch 7.4.1873 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.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. Files: src/ex_cmds2.c, src/gui_gtk_x11.c, src/gui_w32.c, src/gui_x11.c, src/globals.h *** ../vim-7.4.1872/src/ex_cmds2.c 2016-05-31 21:37:32.962685143 +0200 --- src/ex_cmds2.c 2016-06-02 14:08:06.816679082 +0200 *************** *** 1101,1106 **** --- 1101,1107 ---- if (first_timer != NULL) first_timer->tr_prev = timer; first_timer = timer; + did_add_timer = TRUE; } /* *** ../vim-7.4.1872/src/gui_gtk_x11.c 2016-04-17 20:49:46.133819400 +0200 --- src/gui_gtk_x11.c 2016-06-02 14:11:35.104676217 +0200 *************** *** 6535,6549 **** int gui_mch_wait_for_chars(long wtime) { ! int focus; ! guint timer; ! static int timed_out; 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); --- 6535,6549 ---- int gui_mch_wait_for_chars(long wtime) { ! 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,6574 **** --- 6568,6582 ---- } #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,6594 **** /* 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; } } while (wtime < 0 || !timed_out); --- 6590,6597 ---- /* Got char, return immediately */ if (input_available()) { ! retval = OK; ! goto theend; } } while (wtime < 0 || !timed_out); *************** *** 6597,6603 **** */ gui_mch_update(); ! return FAIL; } --- 6600,6614 ---- */ gui_mch_update(); ! 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; } *** ../vim-7.4.1872/src/gui_w32.c 2016-04-26 21:51:45.014007644 +0200 --- src/gui_w32.c 2016-06-02 14:21:55.296667686 +0200 *************** *** 2022,2027 **** --- 2022,2043 ---- 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,2078 **** --- 2089,2097 ---- s_need_activate = FALSE; } + #ifdef FEAT_TIMERS + did_add_timer = FALSE; + #endif #ifdef MESSAGE_QUEUE /* Check channel while waiting message. */ for (;;) *************** *** 2098,2112 **** 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; ! } allow_scrollbar = FALSE; /* Clear pending mouse button, the release event may have been --- 2117,2123 ---- if (input_available()) { ! remove_any_timer(); allow_scrollbar = FALSE; /* Clear pending mouse button, the release event may have been *************** *** 2117,2122 **** --- 2128,2142 ---- 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; *** ../vim-7.4.1872/src/gui_x11.c 2016-02-27 18:13:05.236593109 +0100 --- src/gui_x11.c 2016-06-02 14:24:32.900665518 +0200 *************** *** 2368,2374 **** for (i = 0; i < cmap_size; i++) colortable[i].pixel = (unsigned long)i; ! XQueryColors (gui.dpy, colormap, colortable, cmap_size); /* * Find the color that best approximates the desired one, then --- 2368,2374 ---- for (i = 0; i < cmap_size; i++) colortable[i].pixel = (unsigned long)i; ! XQueryColors(gui.dpy, colormap, colortable, cmap_size); /* * Find the color that best approximates the desired one, then *************** *** 2792,2798 **** int gui_mch_wait_for_chars(long wtime) { ! int focus; /* * Make this static, in case gui_x11_timer_cb is called after leaving --- 2792,2799 ---- int gui_mch_wait_for_chars(long wtime) { ! int focus; ! int retval = FAIL; /* * Make this static, in case gui_x11_timer_cb is called after leaving *************** *** 2828,2834 **** --- 2829,2843 ---- } #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,2854 **** if (input_available()) { ! if (timer != (XtIntervalId)0 && !timed_out) ! XtRemoveTimeOut(timer); ! return OK; } } ! return FAIL; } /* --- 2852,2866 ---- if (input_available()) { ! retval = OK; ! break; } } ! ! if (timer != (XtIntervalId)0 && !timed_out) ! XtRemoveTimeOut(timer); ! ! return retval; } /* *** ../vim-7.4.1872/src/globals.h 2016-06-01 23:08:35.241421504 +0200 --- src/globals.h 2016-06-02 14:07:55.776679234 +0200 *************** *** 1635,1640 **** --- 1635,1644 ---- 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. */ *** ../vim-7.4.1872/src/version.c 2016-06-02 13:54:45.144690110 +0200 --- src/version.c 2016-06-02 14:11:52.968675971 +0200 *************** *** 755,756 **** --- 755,758 ---- { /* Add new patch number below this line */ + /**/ + 1873, /**/ -- hundred-and-one symptoms of being an internet addict: 35. Your husband tells you he's had the beard for 2 months. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///