comparison src/gui.c @ 8577:63dc856bd13d v7.4.1578

commit https://github.com/vim/vim/commit/975b5271eed4fa0500c24a8f37be0b1797cb9db7 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Mar 15 23:10:59 2016 +0100 patch 7.4.1578 Problem: There is no way to invoke a function later or periodically. Solution: Add timer support.
author Christian Brabandt <cb@256bit.org>
date Tue, 15 Mar 2016 23:15:05 +0100
parents 2f57bbe870ea
children eab968bf3ce7
comparison
equal deleted inserted replaced
8576:3fd90fff8ab5 8577:63dc856bd13d
2847 gui.cursor_is_valid = FALSE; 2847 gui.cursor_is_valid = FALSE;
2848 } 2848 }
2849 } 2849 }
2850 } 2850 }
2851 2851
2852 static int
2853 gui_wait_for_chars_or_timer(long wtime)
2854 {
2855 #ifdef FEAT_TIMERS
2856 int due_time;
2857 long remaining = wtime;
2858
2859 /* When waiting very briefly don't trigger timers. */
2860 if (wtime >= 0 && wtime < 10L)
2861 return gui_mch_wait_for_chars(wtime);
2862
2863 while (wtime < 0 || remaining > 0)
2864 {
2865 /* Trigger timers and then get the time in wtime until the next one is
2866 * due. Wait up to that time. */
2867 due_time = check_due_timer();
2868 if (due_time <= 0 || (wtime > 0 && due_time > remaining))
2869 due_time = remaining;
2870 if (gui_mch_wait_for_chars(due_time))
2871 return TRUE;
2872 if (wtime > 0)
2873 remaining -= due_time;
2874 }
2875 return FALSE;
2876 #else
2877 return gui_mch_wait_for_chars(wtime);
2878 #endif
2879 }
2880
2852 /* 2881 /*
2853 * The main GUI input routine. Waits for a character from the keyboard. 2882 * The main GUI input routine. Waits for a character from the keyboard.
2854 * wtime == -1 Wait forever. 2883 * wtime == -1 Wait forever.
2855 * wtime == 0 Don't wait. 2884 * wtime == 0 Don't wait.
2856 * wtime > 0 Wait wtime milliseconds for a character. 2885 * wtime > 0 Wait wtime milliseconds for a character.
2883 if (wtime > 0) 2912 if (wtime > 0)
2884 { 2913 {
2885 /* Blink when waiting for a character. Probably only does something 2914 /* Blink when waiting for a character. Probably only does something
2886 * for showmatch() */ 2915 * for showmatch() */
2887 gui_mch_start_blink(); 2916 gui_mch_start_blink();
2888 retval = gui_mch_wait_for_chars(wtime); 2917 retval = gui_wait_for_chars_or_timer(wtime);
2889 gui_mch_stop_blink(); 2918 gui_mch_stop_blink();
2890 return retval; 2919 return retval;
2891 } 2920 }
2892 2921
2893 /* 2922 /*
2899 /* 2928 /*
2900 * We may want to trigger the CursorHold event. First wait for 2929 * We may want to trigger the CursorHold event. First wait for
2901 * 'updatetime' and if nothing is typed within that time put the 2930 * 'updatetime' and if nothing is typed within that time put the
2902 * K_CURSORHOLD key in the input buffer. 2931 * K_CURSORHOLD key in the input buffer.
2903 */ 2932 */
2904 if (gui_mch_wait_for_chars(p_ut) == OK) 2933 if (gui_wait_for_chars_or_timer(p_ut) == OK)
2905 retval = OK; 2934 retval = OK;
2906 #ifdef FEAT_AUTOCMD 2935 #ifdef FEAT_AUTOCMD
2907 else if (trigger_cursorhold()) 2936 else if (trigger_cursorhold())
2908 { 2937 {
2909 char_u buf[3]; 2938 char_u buf[3];
2920 2949
2921 if (retval == FAIL) 2950 if (retval == FAIL)
2922 { 2951 {
2923 /* Blocking wait. */ 2952 /* Blocking wait. */
2924 before_blocking(); 2953 before_blocking();
2925 retval = gui_mch_wait_for_chars(-1L); 2954 retval = gui_wait_for_chars_or_timer(-1L);
2926 } 2955 }
2927 2956
2928 gui_mch_stop_blink(); 2957 gui_mch_stop_blink();
2929 return retval; 2958 return retval;
2930 } 2959 }