diff options
| author | Daniel Colascione | 2014-03-23 04:45:17 -0700 |
|---|---|---|
| committer | Daniel Colascione | 2014-03-23 04:45:17 -0700 |
| commit | 577b2ffd2d787506261ed758b086fb4257116dba (patch) | |
| tree | 93edf0eb56438caf85d0663150fde4f1fdf0c67e /src | |
| parent | 4b0c9ad43c0f64d7dc120e2f24afed6488c78997 (diff) | |
| parent | d2933655023701a8f994d0887ea07b5fef5066c2 (diff) | |
| download | emacs-577b2ffd2d787506261ed758b086fb4257116dba.tar.gz emacs-577b2ffd2d787506261ed758b086fb4257116dba.zip | |
Further improve XIM init
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 7 | ||||
| -rw-r--r-- | src/xfns.c | 143 |
2 files changed, 84 insertions, 66 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 509875d87ea..dc07ba0b320 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -2,7 +2,12 @@ | |||
| 2 | 2 | ||
| 3 | * xfns.c (create_frame_xic): Pass XNStatusAttributes to XCreateIC | 3 | * xfns.c (create_frame_xic): Pass XNStatusAttributes to XCreateIC |
| 4 | only if xic_style calls for it. This change allows Emacs to work | 4 | only if xic_style calls for it. This change allows Emacs to work |
| 5 | with ibus. Also, don't leak resources if create_frame_xic fails. | 5 | with ibus. Also, don't leak resources if create_frame_xic fails, |
| 6 | and stop caching xic_style across different displays. | ||
| 7 | (supported_xim_styles): Make const. | ||
| 8 | (best_xim_style): Remove first parameter: it's always just | ||
| 9 | supported_xim_styles. Change to look at supported_xim_styles | ||
| 10 | directly. | ||
| 6 | 11 | ||
| 7 | 2014-03-23 Daniel Colascione <dancol@dancol.org> | 12 | 2014-03-23 Daniel Colascione <dancol@dancol.org> |
| 8 | 13 | ||
diff --git a/src/xfns.c b/src/xfns.c index 7f4fc365833..692504ef762 100644 --- a/src/xfns.c +++ b/src/xfns.c | |||
| @@ -1641,12 +1641,12 @@ hack_wm_protocols (struct frame *f, Widget widget) | |||
| 1641 | #ifdef HAVE_X_I18N | 1641 | #ifdef HAVE_X_I18N |
| 1642 | 1642 | ||
| 1643 | static XFontSet xic_create_xfontset (struct frame *); | 1643 | static XFontSet xic_create_xfontset (struct frame *); |
| 1644 | static XIMStyle best_xim_style (XIMStyles *, XIMStyles *); | 1644 | static XIMStyle best_xim_style (XIMStyles *); |
| 1645 | 1645 | ||
| 1646 | 1646 | ||
| 1647 | /* Supported XIM styles, ordered by preference. */ | 1647 | /* Supported XIM styles, ordered by preference. */ |
| 1648 | 1648 | ||
| 1649 | static XIMStyle supported_xim_styles[] = | 1649 | static const XIMStyle supported_xim_styles[] = |
| 1650 | { | 1650 | { |
| 1651 | XIMPreeditPosition | XIMStatusArea, | 1651 | XIMPreeditPosition | XIMStatusArea, |
| 1652 | XIMPreeditPosition | XIMStatusNothing, | 1652 | XIMPreeditPosition | XIMStatusNothing, |
| @@ -1941,14 +1941,16 @@ xic_free_xfontset (struct frame *f) | |||
| 1941 | input method XIM. */ | 1941 | input method XIM. */ |
| 1942 | 1942 | ||
| 1943 | static XIMStyle | 1943 | static XIMStyle |
| 1944 | best_xim_style (XIMStyles *user, XIMStyles *xim) | 1944 | best_xim_style (XIMStyles *xim) |
| 1945 | { | 1945 | { |
| 1946 | int i, j; | 1946 | int i, j; |
| 1947 | int nr_supported = | ||
| 1948 | sizeof (supported_xim_styles) / sizeof (supported_xim_styles[0]); | ||
| 1947 | 1949 | ||
| 1948 | for (i = 0; i < user->count_styles; ++i) | 1950 | for (i = 0; i < nr_supported; ++i) |
| 1949 | for (j = 0; j < xim->count_styles; ++j) | 1951 | for (j = 0; j < xim->count_styles; ++j) |
| 1950 | if (user->supported_styles[i] == xim->supported_styles[j]) | 1952 | if (supported_xim_styles[i] == xim->supported_styles[j]) |
| 1951 | return user->supported_styles[i]; | 1953 | return supported_xim_styles[i]; |
| 1952 | 1954 | ||
| 1953 | /* Return the default style. */ | 1955 | /* Return the default style. */ |
| 1954 | return XIMPreeditNothing | XIMStatusNothing; | 1956 | return XIMPreeditNothing | XIMStatusNothing; |
| @@ -1956,8 +1958,6 @@ best_xim_style (XIMStyles *user, XIMStyles *xim) | |||
| 1956 | 1958 | ||
| 1957 | /* Create XIC for frame F. */ | 1959 | /* Create XIC for frame F. */ |
| 1958 | 1960 | ||
| 1959 | static XIMStyle xic_style; | ||
| 1960 | |||
| 1961 | void | 1961 | void |
| 1962 | create_frame_xic (struct frame *f) | 1962 | create_frame_xic (struct frame *f) |
| 1963 | { | 1963 | { |
| @@ -1968,30 +1968,31 @@ create_frame_xic (struct frame *f) | |||
| 1968 | XVaNestedList preedit_attr = NULL; | 1968 | XVaNestedList preedit_attr = NULL; |
| 1969 | XRectangle s_area; | 1969 | XRectangle s_area; |
| 1970 | XPoint spot; | 1970 | XPoint spot; |
| 1971 | XIMStyles supported_list; | 1971 | XIMStyle xic_style; |
| 1972 | 1972 | ||
| 1973 | if (FRAME_XIC (f)) | 1973 | if (FRAME_XIC (f)) |
| 1974 | return; | 1974 | goto out; |
| 1975 | |||
| 1976 | /* Create X fontset. */ | ||
| 1977 | xfs = xic_create_xfontset (f); | ||
| 1978 | FRAME_XIC_FONTSET (f) = xfs; | ||
| 1979 | 1975 | ||
| 1980 | xim = FRAME_X_XIM (f); | 1976 | xim = FRAME_X_XIM (f); |
| 1981 | if (xim) | 1977 | if (!xim) |
| 1978 | goto out; | ||
| 1979 | |||
| 1980 | /* Determine XIC style. */ | ||
| 1981 | xic_style = best_xim_style (FRAME_X_XIM_STYLES (f)); | ||
| 1982 | |||
| 1983 | /* Create X fontset. */ | ||
| 1984 | if (xic_style & (XIMPreeditPosition | XIMStatusArea)) | ||
| 1982 | { | 1985 | { |
| 1983 | spot.x = 0; spot.y = 1; | 1986 | xfs = xic_create_xfontset (f); |
| 1987 | if (!xfs) | ||
| 1988 | goto out; | ||
| 1984 | 1989 | ||
| 1985 | /* Determine XIC style. */ | 1990 | FRAME_XIC_FONTSET (f) = xfs; |
| 1986 | if (xic_style == 0) | 1991 | } |
| 1987 | { | ||
| 1988 | supported_list.count_styles = (sizeof supported_xim_styles | ||
| 1989 | / sizeof supported_xim_styles[0]); | ||
| 1990 | supported_list.supported_styles = supported_xim_styles; | ||
| 1991 | xic_style = best_xim_style (&supported_list, | ||
| 1992 | FRAME_X_XIM_STYLES (f)); | ||
| 1993 | } | ||
| 1994 | 1992 | ||
| 1993 | if (xic_style & XIMPreeditPosition) | ||
| 1994 | { | ||
| 1995 | spot.x = 0; spot.y = 1; | ||
| 1995 | preedit_attr = XVaCreateNestedList (0, | 1996 | preedit_attr = XVaCreateNestedList (0, |
| 1996 | XNFontSet, xfs, | 1997 | XNFontSet, xfs, |
| 1997 | XNForeground, | 1998 | XNForeground, |
| @@ -2006,50 +2007,62 @@ create_frame_xic (struct frame *f) | |||
| 2006 | 2007 | ||
| 2007 | if (!preedit_attr) | 2008 | if (!preedit_attr) |
| 2008 | goto out; | 2009 | goto out; |
| 2010 | } | ||
| 2009 | 2011 | ||
| 2010 | if (xic_style & XIMStatusArea) | 2012 | if (xic_style & XIMStatusArea) |
| 2011 | { | 2013 | { |
| 2012 | s_area.x = 0; s_area.y = 0; s_area.width = 1; s_area.height = 1; | 2014 | s_area.x = 0; s_area.y = 0; s_area.width = 1; s_area.height = 1; |
| 2013 | status_attr = XVaCreateNestedList (0, | 2015 | status_attr = XVaCreateNestedList (0, |
| 2014 | XNArea, | 2016 | XNArea, |
| 2015 | &s_area, | 2017 | &s_area, |
| 2016 | XNFontSet, | 2018 | XNFontSet, |
| 2017 | xfs, | 2019 | xfs, |
| 2018 | XNForeground, | 2020 | XNForeground, |
| 2019 | FRAME_FOREGROUND_PIXEL (f), | 2021 | FRAME_FOREGROUND_PIXEL (f), |
| 2020 | XNBackground, | 2022 | XNBackground, |
| 2021 | FRAME_BACKGROUND_PIXEL (f), | 2023 | FRAME_BACKGROUND_PIXEL (f), |
| 2022 | NULL); | 2024 | NULL); |
| 2023 | 2025 | ||
| 2024 | if (!status_attr) | 2026 | if (!status_attr) |
| 2025 | goto out; | ||
| 2026 | |||
| 2027 | xic = XCreateIC (xim, | ||
| 2028 | XNInputStyle, xic_style, | ||
| 2029 | XNClientWindow, FRAME_X_WINDOW (f), | ||
| 2030 | XNFocusWindow, FRAME_X_WINDOW (f), | ||
| 2031 | XNStatusAttributes, status_attr, | ||
| 2032 | XNPreeditAttributes, preedit_attr, | ||
| 2033 | NULL); | ||
| 2034 | } | ||
| 2035 | else | ||
| 2036 | { | ||
| 2037 | xic = XCreateIC (xim, | ||
| 2038 | XNInputStyle, xic_style, | ||
| 2039 | XNClientWindow, FRAME_X_WINDOW (f), | ||
| 2040 | XNFocusWindow, FRAME_X_WINDOW (f), | ||
| 2041 | XNPreeditAttributes, preedit_attr, | ||
| 2042 | NULL); | ||
| 2043 | } | ||
| 2044 | |||
| 2045 | if (!xic) | ||
| 2046 | goto out; | 2027 | goto out; |
| 2047 | |||
| 2048 | FRAME_XIC (f) = xic; | ||
| 2049 | FRAME_XIC_STYLE (f) = xic_style; | ||
| 2050 | xfs = NULL; /* Don't free below. */ | ||
| 2051 | } | 2028 | } |
| 2052 | 2029 | ||
| 2030 | if (preedit_attr && status_attr) | ||
| 2031 | xic = XCreateIC (xim, | ||
| 2032 | XNInputStyle, xic_style, | ||
| 2033 | XNClientWindow, FRAME_X_WINDOW (f), | ||
| 2034 | XNFocusWindow, FRAME_X_WINDOW (f), | ||
| 2035 | XNStatusAttributes, status_attr, | ||
| 2036 | XNPreeditAttributes, preedit_attr, | ||
| 2037 | NULL); | ||
| 2038 | else if (preedit_attr) | ||
| 2039 | xic = XCreateIC (xim, | ||
| 2040 | XNInputStyle, xic_style, | ||
| 2041 | XNClientWindow, FRAME_X_WINDOW (f), | ||
| 2042 | XNFocusWindow, FRAME_X_WINDOW (f), | ||
| 2043 | XNPreeditAttributes, preedit_attr, | ||
| 2044 | NULL); | ||
| 2045 | else if (status_attr) | ||
| 2046 | xic = XCreateIC (xim, | ||
| 2047 | XNInputStyle, xic_style, | ||
| 2048 | XNClientWindow, FRAME_X_WINDOW (f), | ||
| 2049 | XNFocusWindow, FRAME_X_WINDOW (f), | ||
| 2050 | XNStatusAttributes, status_attr, | ||
| 2051 | NULL); | ||
| 2052 | else | ||
| 2053 | xic = XCreateIC (xim, | ||
| 2054 | XNInputStyle, xic_style, | ||
| 2055 | XNClientWindow, FRAME_X_WINDOW (f), | ||
| 2056 | XNFocusWindow, FRAME_X_WINDOW (f), | ||
| 2057 | NULL); | ||
| 2058 | |||
| 2059 | if (!xic) | ||
| 2060 | goto out; | ||
| 2061 | |||
| 2062 | FRAME_XIC (f) = xic; | ||
| 2063 | FRAME_XIC_STYLE (f) = xic_style; | ||
| 2064 | xfs = NULL; /* Don't free below. */ | ||
| 2065 | |||
| 2053 | out: | 2066 | out: |
| 2054 | 2067 | ||
| 2055 | if (xfs) | 2068 | if (xfs) |