4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: The FocusLost and FocusGained autocommands are triggered
12 asynchronously in the GUI. This may cause arbitrary problems.
13 Solution: Put the focus event in the input buffer and handle it when ready
15 Files: src/eval.c, src/getchar.c, src/gui.c, src/gui_gtk_x11.c,
19 *** ../vim-7.1.094/src/eval.c Thu Aug 30 11:10:38 2007
20 --- src/eval.c Mon Sep 3 22:48:09 2007
26 ! if (argvars[0].v_type == VAR_UNKNOWN)
27 ! /* getchar(): blocking wait. */
29 ! else if (get_tv_number_chk(&argvars[0], &error) == 1)
30 ! /* getchar(1): only check if char avail */
32 ! else if (error || vpeekc() == NUL)
33 ! /* illegal argument or getchar(0) and no char avail: return zero */
36 ! /* getchar(0) and char avail: return char */
47 ! if (argvars[0].v_type == VAR_UNKNOWN)
48 ! /* getchar(): blocking wait. */
50 ! else if (get_tv_number_chk(&argvars[0], &error) == 1)
51 ! /* getchar(1): only check if char avail */
53 ! else if (error || vpeekc() == NUL)
54 ! /* illegal argument or getchar(0) and no char avail: return zero */
57 ! /* getchar(0) and char avail: return char */
66 *** ../vim-7.1.094/src/getchar.c Thu May 10 18:43:02 2007
67 --- src/getchar.c Wed Aug 29 22:38:49 2007
75 /* Translate K_CSI to CSI. The special key is only used to avoid
76 * it being recognized as the start of a special key. */
83 + /* The caller doesn't need to know that the focus event is delayed
84 + * until getting a character. */
85 + if (c == K_FOCUSGAINED || c == K_FOCUSLOST)
87 + ui_focus_change(c == K_FOCUSGAINED);
91 /* Translate K_CSI to CSI. The special key is only used to avoid
92 * it being recognized as the start of a special key. */
94 *** ../vim-7.1.094/src/gui.c Thu Aug 30 13:51:52 2007
95 --- src/gui.c Thu Aug 30 14:10:48 2007
98 xim_set_focus(in_focus);
101 ! ui_focus_change(in_focus);
106 xim_set_focus(in_focus);
109 ! /* Put events in the input queue only when allowed.
110 ! * ui_focus_change() isn't called directly, because it invokes
111 ! * autocommands and that must not happen asynchronously. */
112 ! if (!hold_gui_events)
117 ! bytes[1] = KS_EXTRA;
118 ! bytes[2] = in_focus ? (int)KE_FOCUSGAINED : (int)KE_FOCUSLOST;
119 ! add_to_input_buf(bytes, 3);
124 *** ../vim-7.1.094/src/gui_gtk_x11.c Tue Jun 19 18:07:52 2007
125 --- src/gui_gtk_x11.c Wed Aug 29 22:43:34 2007
128 if (blink_state == BLINK_NONE)
129 gui_mch_start_blink();
131 ! /* make sure keyboard input goes to the draw area (if this is focus for a window) */
132 if (widget != gui.drawarea)
133 gtk_widget_grab_focus(gui.drawarea);
139 if (blink_state == BLINK_NONE)
140 gui_mch_start_blink();
142 ! /* make sure keyboard input goes to the draw area (if this is focus for a
144 if (widget != gui.drawarea)
145 gtk_widget_grab_focus(gui.drawarea);
147 + /* make sure the input buffer is read */
148 + if (gtk_main_level() > 0)
158 if (blink_state != BLINK_NONE)
159 gui_mch_stop_blink();
161 + /* make sure the input buffer is read */
162 + if (gtk_main_level() > 0)
167 *** ../vim-7.1.094/src/keymap.h Sat May 5 19:34:22 2007
168 --- src/keymap.h Wed Aug 29 22:17:51 2007
172 , KE_DROP /* DnD data is available */
173 , KE_CURSORHOLD /* CursorHold event */
174 , KE_NOP /* doesn't do something */
175 + , KE_FOCUSGAINED /* focus gained */
176 + , KE_FOCUSLOST /* focus lost */
183 #define K_CMDWIN TERMCAP2KEY(KS_EXTRA, KE_CMDWIN)
185 #define K_DROP TERMCAP2KEY(KS_EXTRA, KE_DROP)
186 + #define K_FOCUSGAINED TERMCAP2KEY(KS_EXTRA, KE_FOCUSGAINED)
187 + #define K_FOCUSLOST TERMCAP2KEY(KS_EXTRA, KE_FOCUSLOST)
189 #define K_CURSORHOLD TERMCAP2KEY(KS_EXTRA, KE_CURSORHOLD)
191 *** ../vim-7.1.094/src/version.c Thu Aug 30 19:36:52 2007
192 --- src/version.c Wed Sep 5 21:42:41 2007
196 { /* Add new patch number below this line */
203 TALL KNIGHT: We are the Knights Who Say "Ni"!
204 BEDEVERE: No! Not the Knights Who Say "Ni"!
205 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
207 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
208 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
209 \\\ download, build and distribute -- http://www.A-A-P.org ///
210 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///