# HG changeset patch # User Gerd Moellmann # Date 947027316 0 # Node ID 3dafddaefc2cd5f1d71ca95ed5073a69dc5074d3 # Parent 488f307b4f5969583d7c857853065cb91b0bda8a (x_create_im): New function to set IM and IC of a frame. Check that input style is supported before trying to create an IC for it. (x_window): Call x_create_im. diff -r 488f307b4f59 -r 3dafddaefc2c src/xfns.c --- a/src/xfns.c Tue Jan 04 22:14:58 2000 +0000 +++ b/src/xfns.c Tue Jan 04 23:08:36 2000 +0000 @@ -735,6 +735,7 @@ void (*setter) P_ ((struct frame *, Lisp_Object, Lisp_Object)); }; +static void x_create_im P_ ((struct frame *)); void x_set_foreground_color P_ ((struct frame *, Lisp_Object, Lisp_Object)); void x_set_background_color P_ ((struct frame *, Lisp_Object, Lisp_Object)); void x_set_mouse_color P_ ((struct frame *, Lisp_Object, Lisp_Object)); @@ -3043,6 +3044,72 @@ UNBLOCK_INPUT; } #endif + + +/* Create input method and input context for frame F. Set FRAME_XIM + (F) and FRAME_XIC (F). */ + +static void +x_create_im (f) + struct frame *f; +{ + FRAME_XIM (f) = 0; + FRAME_XIC (f) = 0; + +#ifdef HAVE_X_I18N +#ifndef X_I18N_INHIBITED + { + XIM xim; + XIC xic = NULL; + XIMStyles *styles; + XIMStyle input_style = XIMPreeditNothing | XIMStatusNothing; + int i, n; + + xim = XOpenIM (FRAME_X_DISPLAY(f), NULL, NULL, NULL); + if (!xim) + return; + + if (XGetIMValues (xim, XNQueryInputStyle, &styles, NULL) + || !styles) + { + /* Input method doesn't support any input style. */ + XCloseIM (xim); + return; + } + + /* See if input_style is supported. Give up if it isn't. */ + n = styles->count_styles; + for (i = 0; i < n; ++i) + if (styles->supported_styles[i] == input_style) + break; + + XFree (styles); + if (i == n) + { + XCloseIM (xim); + return; + } + + /* Create the input context. */ + xic = XCreateIC (xim, + XNInputStyle, input_style, + XNClientWindow, FRAME_X_WINDOW(f), + XNFocusWindow, FRAME_X_WINDOW(f), + NULL); + + if (!xic) + { + XCloseIM (xim); + return; + } + + FRAME_XIM (f) = xim; + FRAME_XIC (f) = xic; + } +#endif /* X_I18N_INHIBITED */ +#endif /* HAVE_X_I18N */ +} + #ifdef USE_X_TOOLKIT @@ -3198,37 +3265,7 @@ class_hints.res_name = (char *) XSTRING (Vx_resource_name)->data; class_hints.res_class = (char *) XSTRING (Vx_resource_class)->data; XSetClassHint (FRAME_X_DISPLAY (f), XtWindow (shell_widget), &class_hints); - -#ifdef HAVE_X_I18N -#ifndef X_I18N_INHIBITED - { - XIM xim; - XIC xic = NULL; - - xim = XOpenIM (FRAME_X_DISPLAY (f), NULL, NULL, NULL); - - if (xim) - { - xic = XCreateIC (xim, - XNInputStyle, XIMPreeditNothing | XIMStatusNothing, - XNClientWindow, FRAME_X_WINDOW(f), - XNFocusWindow, FRAME_X_WINDOW(f), - NULL); - - if (xic == 0) - { - XCloseIM (xim); - xim = NULL; - } - } - FRAME_XIM (f) = xim; - FRAME_XIC (f) = xic; - } -#else /* X_I18N_INHIBITED */ - FRAME_XIM (f) = 0; - FRAME_XIC (f) = 0; -#endif /* X_I18N_INHIBITED */ -#endif /* HAVE_X_I18N */ + x_create_im (f); f->output_data.x->wm_hints.input = True; f->output_data.x->wm_hints.flags |= InputHint; @@ -3319,38 +3356,7 @@ InputOutput, /* class */ FRAME_X_DISPLAY_INFO (f)->visual, attribute_mask, &attributes); -#ifdef HAVE_X_I18N -#ifndef X_I18N_INHIBITED - { - XIM xim; - XIC xic = NULL; - - xim = XOpenIM (FRAME_X_DISPLAY(f), NULL, NULL, NULL); - - if (xim) - { - xic = XCreateIC (xim, - XNInputStyle, XIMPreeditNothing | XIMStatusNothing, - XNClientWindow, FRAME_X_WINDOW(f), - XNFocusWindow, FRAME_X_WINDOW(f), - NULL); - - if (!xic) - { - XCloseIM (xim); - xim = NULL; - } - } - - FRAME_XIM (f) = xim; - FRAME_XIC (f) = xic; - } -#else /* X_I18N_INHIBITED */ - FRAME_XIM (f) = 0; - FRAME_XIC (f) = 0; -#endif /* X_I18N_INHIBITED */ -#endif /* HAVE_X_I18N */ - + x_create_im (f); validate_x_resource_name (); class_hints.res_name = (char *) XSTRING (Vx_resource_name)->data;