]>
Commit | Line | Data |
---|---|---|
2975f168 AG |
1 | To: vim-dev@vim.org |
2 | Subject: Patch 6.2.328 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=ISO-8859-1 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 6.2.328 | |
11 | Problem: XIM with GTK: It is hard to understand what XIM is doing. | |
12 | Solution: Add xim_log() to log XIM events and help with debugging. | |
13 | Files: src/mbyte.c | |
14 | ||
15 | ||
16 | *** ../vim-6.2.327/src/mbyte.c Mon Mar 1 17:11:04 2004 | |
17 | --- src/mbyte.c Fri Mar 5 15:57:24 2004 | |
18 | *************** | |
19 | *** 133,138 **** | |
20 | --- 133,169 ---- | |
21 | 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1, | |
22 | }; | |
23 | ||
24 | + /* | |
25 | + * XIM often causes trouble. Define XIM_DEBUG to get a log of XIM callbacks | |
26 | + * in the "xim.log" file. | |
27 | + */ | |
28 | + /* #define XIM_DEBUG */ | |
29 | + #ifdef XIM_DEBUG | |
30 | + static void | |
31 | + xim_log(char *s, ...) | |
32 | + { | |
33 | + va_list arglist; | |
34 | + static FILE *fd = NULL; | |
35 | + | |
36 | + if (fd == (FILE *)-1) | |
37 | + return; | |
38 | + if (fd == NULL) | |
39 | + { | |
40 | + fd = fopen("xim.log", "w"); | |
41 | + if (fd == NULL) | |
42 | + { | |
43 | + EMSG("Cannot open xim.log"); | |
44 | + fd = (FILE *)-1; | |
45 | + return; | |
46 | + } | |
47 | + } | |
48 | + | |
49 | + va_start(arglist, s); | |
50 | + vfprintf(fd, s, arglist); | |
51 | + va_end(arglist); | |
52 | + } | |
53 | + #endif | |
54 | + | |
55 | #endif | |
56 | ||
57 | #if defined(FEAT_MBYTE) || defined(FEAT_POSTSCRIPT) || defined(PROTO) | |
58 | *************** | |
59 | *** 3007,3012 **** | |
60 | --- 3038,3057 ---- | |
61 | ||
62 | #if defined(FEAT_XIM) || defined(PROTO) | |
63 | ||
64 | + # ifdef FEAT_GUI_GTK | |
65 | + /* | |
66 | + * Set preedit_start_col to the current cursor position. | |
67 | + */ | |
68 | + static void | |
69 | + init_preedit_start_col(void) | |
70 | + { | |
71 | + if (State & CMDLINE) | |
72 | + preedit_start_col = cmdline_getvcol_cursor(); | |
73 | + else if (curwin != NULL) | |
74 | + getvcol(curwin, &curwin->w_cursor, &preedit_start_col, NULL, NULL); | |
75 | + } | |
76 | + # endif | |
77 | + | |
78 | # if defined(HAVE_GTK2) && !defined(PROTO) | |
79 | ||
80 | static int im_is_active = FALSE; /* IM is enabled for current mode */ | |
81 | *************** | |
82 | *** 3128,3135 **** | |
83 | static void | |
84 | im_commit_cb(GtkIMContext *context, const gchar *str, gpointer data) | |
85 | { | |
86 | ! int slen = (int)strlen(str); | |
87 | ! int add_to_input = TRUE; | |
88 | ||
89 | /* The imhangul module doesn't reset the preedit string before | |
90 | * committing. Call im_delete_preedit() to work around that. */ | |
91 | --- 3173,3184 ---- | |
92 | static void | |
93 | im_commit_cb(GtkIMContext *context, const gchar *str, gpointer data) | |
94 | { | |
95 | ! int slen = (int)STRLEN(str); | |
96 | ! int add_to_input = TRUE; | |
97 | ! | |
98 | ! #ifdef XIM_DEBUG | |
99 | ! xim_log("im_commit_cb(): %s\n", str); | |
100 | ! #endif | |
101 | ||
102 | /* The imhangul module doesn't reset the preedit string before | |
103 | * committing. Call im_delete_preedit() to work around that. */ | |
104 | *************** | |
105 | *** 3141,3166 **** | |
106 | /* Is this a single character that matches a keypad key that's just | |
107 | * been pressed? If so, we don't want it to be entered as such - let | |
108 | * us carry on processing the raw keycode so that it may be used in | |
109 | ! * mappings as <kSomething> | |
110 | ! */ | |
111 | if (xim_expected_char != NUL) | |
112 | { | |
113 | ! /* We're currently processing a keypad or other special key */ | |
114 | ! if (slen == 1 && str[0] == xim_expected_char) | |
115 | ! { | |
116 | ! /* It's a match - don't do it here */ | |
117 | ! xim_ignored_char = TRUE; | |
118 | ! add_to_input = FALSE; | |
119 | ! } | |
120 | ! else | |
121 | ! { | |
122 | ! /* Not a match */ | |
123 | ! xim_ignored_char = FALSE; | |
124 | ! } | |
125 | } | |
126 | ||
127 | if (add_to_input) | |
128 | ! im_add_to_input((char_u *)str, slen); | |
129 | ||
130 | if (gtk_main_level() > 0) | |
131 | gtk_main_quit(); | |
132 | --- 3190,3214 ---- | |
133 | /* Is this a single character that matches a keypad key that's just | |
134 | * been pressed? If so, we don't want it to be entered as such - let | |
135 | * us carry on processing the raw keycode so that it may be used in | |
136 | ! * mappings as <kSomething>. */ | |
137 | if (xim_expected_char != NUL) | |
138 | { | |
139 | ! /* We're currently processing a keypad or other special key */ | |
140 | ! if (slen == 1 && str[0] == xim_expected_char) | |
141 | ! { | |
142 | ! /* It's a match - don't do it here */ | |
143 | ! xim_ignored_char = TRUE; | |
144 | ! add_to_input = FALSE; | |
145 | ! } | |
146 | ! else | |
147 | ! { | |
148 | ! /* Not a match */ | |
149 | ! xim_ignored_char = FALSE; | |
150 | ! } | |
151 | } | |
152 | ||
153 | if (add_to_input) | |
154 | ! im_add_to_input((char_u *)str, slen); | |
155 | ||
156 | if (gtk_main_level() > 0) | |
157 | gtk_main_quit(); | |
158 | *************** | |
159 | *** 3173,3181 **** | |
160 | --- 3221,3234 ---- | |
161 | static void | |
162 | im_preedit_start_cb(GtkIMContext *context, gpointer data) | |
163 | { | |
164 | + #ifdef XIM_DEBUG | |
165 | + xim_log("im_preedit_start_cb()\n"); | |
166 | + #endif | |
167 | + | |
168 | im_is_active = TRUE; | |
169 | gui_update_cursor(TRUE, FALSE); | |
170 | } | |
171 | + | |
172 | /* | |
173 | * Callback invoked after end to the preedit. | |
174 | */ | |
175 | *************** | |
176 | *** 3183,3188 **** | |
177 | --- 3236,3244 ---- | |
178 | static void | |
179 | im_preedit_end_cb(GtkIMContext *context, gpointer data) | |
180 | { | |
181 | + #ifdef XIM_DEBUG | |
182 | + xim_log("im_preedit_end_cb()\n"); | |
183 | + #endif | |
184 | im_is_active = FALSE; | |
185 | gui_update_cursor(TRUE, FALSE); | |
186 | } | |
187 | *************** | |
188 | *** 3239,3244 **** | |
189 | --- 3295,3304 ---- | |
190 | &preedit_string, NULL, | |
191 | &cursor_index); | |
192 | ||
193 | + #ifdef XIM_DEBUG | |
194 | + xim_log("im_preedit_changed_cb(): %s\n", preedit_string); | |
195 | + #endif | |
196 | + | |
197 | g_return_if_fail(preedit_string != NULL); /* just in case */ | |
198 | ||
199 | /* If at the start position (after typing backspace) preedit_start_col | |
200 | *************** | |
201 | *** 3246,3258 **** | |
202 | if (cursor_index == 0) | |
203 | preedit_start_col = MAXCOL; | |
204 | ||
205 | if (preedit_start_col == MAXCOL && preedit_string[0] != '\0') | |
206 | { | |
207 | /* Urgh, this breaks if the input buffer isn't empty now */ | |
208 | ! if (State & CMDLINE) | |
209 | ! preedit_start_col = cmdline_getvcol_cursor(); | |
210 | ! else if (curwin != NULL) | |
211 | ! getvcol(curwin, &curwin->w_cursor, &preedit_start_col, NULL, NULL); | |
212 | } | |
213 | ||
214 | im_delete_preedit(); | |
215 | --- 3306,3316 ---- | |
216 | if (cursor_index == 0) | |
217 | preedit_start_col = MAXCOL; | |
218 | ||
219 | + /* If preedit_start_col is MAXCOL set it to the current cursor position. */ | |
220 | if (preedit_start_col == MAXCOL && preedit_string[0] != '\0') | |
221 | { | |
222 | /* Urgh, this breaks if the input buffer isn't empty now */ | |
223 | ! init_preedit_start_col(); | |
224 | } | |
225 | ||
226 | im_delete_preedit(); | |
227 | *************** | |
228 | *** 3396,3401 **** | |
229 | --- 3454,3463 ---- | |
230 | void | |
231 | xim_init(void) | |
232 | { | |
233 | + #ifdef XIM_DEBUG | |
234 | + xim_log("xim_init()\n"); | |
235 | + #endif | |
236 | + | |
237 | g_return_if_fail(gui.drawarea != NULL); | |
238 | g_return_if_fail(gui.drawarea->window != NULL); | |
239 | ||
240 | *************** | |
241 | *** 3416,3421 **** | |
242 | --- 3478,3487 ---- | |
243 | void | |
244 | im_shutdown(void) | |
245 | { | |
246 | + #ifdef XIM_DEBUG | |
247 | + xim_log("im_shutdown()\n"); | |
248 | + #endif | |
249 | + | |
250 | if (xic != NULL) | |
251 | { | |
252 | gtk_im_context_focus_out(xic); | |
253 | *************** | |
254 | *** 3559,3564 **** | |
255 | --- 3625,3631 ---- | |
256 | im_synthesize_keypress(GDK_Escape, 0U); | |
257 | ||
258 | gtk_im_context_reset(xic); | |
259 | + | |
260 | /* | |
261 | * HACK for Ami: This sequence of function calls makes Ami handle | |
262 | * the IM reset gratiously, without breaking loads of other stuff. | |
263 | *************** | |
264 | *** 3677,3685 **** | |
265 | if (xim_expected_char != NUL && xim_ignored_char) | |
266 | /* We had a keypad key, and XIM tried to thieve it */ | |
267 | return FALSE; | |
268 | ! else | |
269 | ! /* Normal processing */ | |
270 | ! return imresult; | |
271 | } | |
272 | } | |
273 | ||
274 | --- 3744,3752 ---- | |
275 | if (xim_expected_char != NUL && xim_ignored_char) | |
276 | /* We had a keypad key, and XIM tried to thieve it */ | |
277 | return FALSE; | |
278 | ! | |
279 | ! /* Normal processing */ | |
280 | ! return imresult; | |
281 | } | |
282 | } | |
283 | ||
284 | *************** | |
285 | *** 3959,3968 **** | |
286 | if (xim_input_style & XIMPreeditCallbacks) | |
287 | { | |
288 | preedit_buf_len = 0; | |
289 | ! if (State & CMDLINE) | |
290 | ! preedit_start_col = cmdline_getvcol_cursor(); | |
291 | ! else | |
292 | ! getvcol(curwin, &curwin->w_cursor, &preedit_start_col, NULL, NULL); | |
293 | } | |
294 | #else | |
295 | # if 0 | |
296 | --- 4026,4032 ---- | |
297 | if (xim_input_style & XIMPreeditCallbacks) | |
298 | { | |
299 | preedit_buf_len = 0; | |
300 | ! init_preedit_start_col(); | |
301 | } | |
302 | #else | |
303 | # if 0 | |
304 | *************** | |
305 | *** 4352,4357 **** | |
306 | --- 4416,4425 ---- | |
307 | Window x11_window; | |
308 | Display *x11_display; | |
309 | ||
310 | + #ifdef XIM_DEBUG | |
311 | + xim_log("xim_instantiate_cb()\n"); | |
312 | + #endif | |
313 | + | |
314 | gui_get_x11_windis(&x11_window, &x11_display); | |
315 | if (display != x11_display) | |
316 | return; | |
317 | *************** | |
318 | *** 4373,4378 **** | |
319 | --- 4441,4449 ---- | |
320 | Window x11_window; | |
321 | Display *x11_display; | |
322 | ||
323 | + #ifdef XIM_DEBUG | |
324 | + xim_log("xim_destroy_cb()\n"); | |
325 | + #endif | |
326 | gui_get_x11_windis(&x11_window, &x11_display); | |
327 | ||
328 | xic = NULL; | |
329 | *************** | |
330 | *** 4391,4396 **** | |
331 | --- 4462,4471 ---- | |
332 | Window x11_window; | |
333 | Display *x11_display; | |
334 | ||
335 | + #ifdef XIM_DEBUG | |
336 | + xim_log("xim_init()\n"); | |
337 | + #endif | |
338 | + | |
339 | gui_get_x11_windis(&x11_window, &x11_display); | |
340 | ||
341 | xic = NULL; | |
342 | *************** | |
343 | *** 4643,4648 **** | |
344 | --- 4718,4727 ---- | |
345 | (int)GDK_IM_STATUS_NONE | | |
346 | (int)GDK_IM_STATUS_NOTHING; | |
347 | ||
348 | + #ifdef XIM_DEBUG | |
349 | + xim_log("xim_decide_input_style()\n"); | |
350 | + #endif | |
351 | + | |
352 | if (!gdk_im_ready()) | |
353 | xim_input_style = 0; | |
354 | else | |
355 | *************** | |
356 | *** 4672,4677 **** | |
357 | --- 4751,4760 ---- | |
358 | static void | |
359 | preedit_start_cbproc(XIC xic, XPointer client_data, XPointer call_data) | |
360 | { | |
361 | + #ifdef XIM_DEBUG | |
362 | + xim_log("xim_decide_input_style()\n"); | |
363 | + #endif | |
364 | + | |
365 | draw_feedback = NULL; | |
366 | xim_preediting = TRUE; | |
367 | gui_update_cursor(TRUE, FALSE); | |
368 | *************** | |
369 | *** 4706,4721 **** | |
370 | char *src; | |
371 | GSList *event_queue; | |
372 | ||
373 | draw_data = (XIMPreeditDrawCallbackStruct *) call_data; | |
374 | text = (XIMText *) draw_data->text; | |
375 | ||
376 | if ((text == NULL && draw_data->chg_length == preedit_buf_len) | |
377 | ! || preedit_buf_len == 0) | |
378 | { | |
379 | ! if (State & CMDLINE) | |
380 | ! preedit_start_col = cmdline_getvcol_cursor(); | |
381 | ! else | |
382 | ! getvcol(curwin, &curwin->w_cursor, &preedit_start_col, NULL, NULL); | |
383 | vim_free(draw_feedback); | |
384 | draw_feedback = NULL; | |
385 | } | |
386 | --- 4789,4805 ---- | |
387 | char *src; | |
388 | GSList *event_queue; | |
389 | ||
390 | + #ifdef XIM_DEBUG | |
391 | + xim_log("preedit_draw_cbproc()\n"); | |
392 | + #endif | |
393 | + | |
394 | draw_data = (XIMPreeditDrawCallbackStruct *) call_data; | |
395 | text = (XIMText *) draw_data->text; | |
396 | ||
397 | if ((text == NULL && draw_data->chg_length == preedit_buf_len) | |
398 | ! || preedit_buf_len == 0) | |
399 | { | |
400 | ! init_preedit_start_col(); | |
401 | vim_free(draw_feedback); | |
402 | draw_feedback = NULL; | |
403 | } | |
404 | *************** | |
405 | *** 4840,4851 **** | |
406 | --- 4924,4942 ---- | |
407 | static void | |
408 | preedit_caret_cbproc(XIC xic, XPointer client_data, XPointer call_data) | |
409 | { | |
410 | + #ifdef XIM_DEBUG | |
411 | + xim_log("preedit_caret_cbproc()\n"); | |
412 | + #endif | |
413 | } | |
414 | ||
415 | /*ARGSUSED*/ | |
416 | static void | |
417 | preedit_done_cbproc(XIC xic, XPointer client_data, XPointer call_data) | |
418 | { | |
419 | + #ifdef XIM_DEBUG | |
420 | + xim_log("preedit_done_cbproc()\n"); | |
421 | + #endif | |
422 | + | |
423 | vim_free(draw_feedback); | |
424 | draw_feedback = NULL; | |
425 | xim_preediting = FALSE; | |
426 | *************** | |
427 | *** 4862,4867 **** | |
428 | --- 4953,4962 ---- | |
429 | { | |
430 | char *text; | |
431 | ||
432 | + #ifdef XIM_DEBUG | |
433 | + xim_log("xim_reset()\n"); | |
434 | + #endif | |
435 | + | |
436 | if (xic != NULL) | |
437 | { | |
438 | text = XmbResetIC(((GdkICPrivate *)xic)->xic); | |
439 | *************** | |
440 | *** 4878,4883 **** | |
441 | --- 4973,4982 ---- | |
442 | int | |
443 | xim_queue_key_press_event(GdkEventKey *event, int down) | |
444 | { | |
445 | + #ifdef XIM_DEBUG | |
446 | + xim_log("xim_queue_key_press_event()\n"); | |
447 | + #endif | |
448 | + | |
449 | if (preedit_buf_len <= 0) | |
450 | return FALSE; | |
451 | if (processing_queued_event) | |
452 | *************** | |
453 | *** 4928,4933 **** | |
454 | --- 5027,5036 ---- | |
455 | void | |
456 | xim_init(void) | |
457 | { | |
458 | + #ifdef XIM_DEBUG | |
459 | + xim_log("xim_init()\n"); | |
460 | + #endif | |
461 | + | |
462 | xic = NULL; | |
463 | xic_attr = NULL; | |
464 | ||
465 | *************** | |
466 | *** 5031,5036 **** | |
467 | --- 5134,5143 ---- | |
468 | void | |
469 | im_shutdown(void) | |
470 | { | |
471 | + #ifdef XIM_DEBUG | |
472 | + xim_log("im_shutdown()\n"); | |
473 | + #endif | |
474 | + | |
475 | if (xic != NULL) | |
476 | { | |
477 | gdk_im_end(); | |
478 | *** ../vim-6.2.327/src/version.c Mon Mar 8 12:27:39 2004 | |
479 | --- src/version.c Mon Mar 8 15:09:57 2004 | |
480 | *************** | |
481 | *** 639,640 **** | |
482 | --- 639,642 ---- | |
483 | { /* Add new patch number below this line */ | |
484 | + /**/ | |
485 | + 328, | |
486 | /**/ | |
487 | ||
488 | -- | |
489 | Mynd you, m00se bites Kan be pretty nasti ... | |
490 | "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD | |
491 | ||
492 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
493 | /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
494 | \\\ Project leader for A-A-P -- http://www.A-A-P.org /// | |
495 | \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html /// |