aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Djärv2014-07-04 17:15:02 +0200
committerJan Djärv2014-07-04 17:15:02 +0200
commit8069993ef72ba8578a84091dae1994f4d19140be (patch)
treeea40b30acb28938634b91d5774e3ca7f1ecd5dbd /src
parent5b5953c070455773f3bdfb9ebcc7ecc15dde0611 (diff)
downloademacs-8069993ef72ba8578a84091dae1994f4d19140be.tar.gz
emacs-8069993ef72ba8578a84091dae1994f4d19140be.zip
Backport from trunk.
* xfns.c (create_frame_xic): Pass XNStatusAttributes to XCreateIC only if xic_style calls for it. This change allows Emacs to work with ibus. Also, don't leak resources if create_frame_xic fails, and stop caching xic_style across different displays. (supported_xim_styles): Make const. (best_xim_style): Remove first parameter: it's always just supported_xim_styles. Change to look at supported_xim_styles directly. Fixes: debbugs:17928
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog12
-rw-r--r--src/xfns.c143
2 files changed, 106 insertions, 49 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index a88c6caacfd..3d6311c765b 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,15 @@
12014-07-04 Daniel Colascione <dancol@dancol.org>
2
3 Backport from trunk.
4 * xfns.c (create_frame_xic): Pass XNStatusAttributes to XCreateIC
5 only if xic_style calls for it. This change allows Emacs to work
6 with ibus. Also, don't leak resources if create_frame_xic fails,
7 and stop caching xic_style across different displays (Bug#17928).
8 (supported_xim_styles): Make const.
9 (best_xim_style): Remove first parameter: it's always just
10 supported_xim_styles. Change to look at supported_xim_styles
11 directly.
12
12014-07-04 Eli Zaretskii <eliz@gnu.org> 132014-07-04 Eli Zaretskii <eliz@gnu.org>
2 14
3 * xdisp.c (redisplay_window): If redisplay of a window ends up 15 * xdisp.c (redisplay_window): If redisplay of a window ends up
diff --git a/src/xfns.c b/src/xfns.c
index 5dbc7053fd9..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
1643static XFontSet xic_create_xfontset (struct frame *); 1643static XFontSet xic_create_xfontset (struct frame *);
1644static XIMStyle best_xim_style (XIMStyles *, XIMStyles *); 1644static 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
1649static XIMStyle supported_xim_styles[] = 1649static 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
1943static XIMStyle 1943static XIMStyle
1944best_xim_style (XIMStyles *user, XIMStyles *xim) 1944best_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,42 +1958,41 @@ best_xim_style (XIMStyles *user, XIMStyles *xim)
1956 1958
1957/* Create XIC for frame F. */ 1959/* Create XIC for frame F. */
1958 1960
1959static XIMStyle xic_style;
1960
1961void 1961void
1962create_frame_xic (struct frame *f) 1962create_frame_xic (struct frame *f)
1963{ 1963{
1964 XIM xim; 1964 XIM xim;
1965 XIC xic = NULL; 1965 XIC xic = NULL;
1966 XFontSet xfs = NULL; 1966 XFontSet xfs = NULL;
1967 XVaNestedList status_attr = NULL;
1968 XVaNestedList preedit_attr = NULL;
1969 XRectangle s_area;
1970 XPoint spot;
1971 XIMStyle xic_style;
1967 1972
1968 if (FRAME_XIC (f)) 1973 if (FRAME_XIC (f))
1969 return; 1974 goto out;
1970 1975
1971 /* Create X fontset. */
1972 xfs = xic_create_xfontset (f);
1973 xim = FRAME_X_XIM (f); 1976 xim = FRAME_X_XIM (f);
1974 if (xim) 1977 if (!xim)
1975 { 1978 goto out;
1976 XRectangle s_area;
1977 XPoint spot;
1978 XVaNestedList preedit_attr;
1979 XVaNestedList status_attr;
1980 1979
1981 s_area.x = 0; s_area.y = 0; s_area.width = 1; s_area.height = 1; 1980 /* Determine XIC style. */
1982 spot.x = 0; spot.y = 1; 1981 xic_style = best_xim_style (FRAME_X_XIM_STYLES (f));
1983 1982
1984 /* Determine XIC style. */ 1983 /* Create X fontset. */
1985 if (xic_style == 0) 1984 if (xic_style & (XIMPreeditPosition | XIMStatusArea))
1986 { 1985 {
1987 XIMStyles supported_list; 1986 xfs = xic_create_xfontset (f);
1988 supported_list.count_styles = (sizeof supported_xim_styles 1987 if (!xfs)
1989 / sizeof supported_xim_styles[0]); 1988 goto out;
1990 supported_list.supported_styles = supported_xim_styles;
1991 xic_style = best_xim_style (&supported_list,
1992 FRAME_X_XIM_STYLES (f));
1993 }
1994 1989
1990 FRAME_XIC_FONTSET (f) = xfs;
1991 }
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,
@@ -2003,31 +2004,75 @@ create_frame_xic (struct frame *f)
2003 : NULL), 2004 : NULL),
2004 &spot, 2005 &spot,
2005 NULL); 2006 NULL);
2007
2008 if (!preedit_attr)
2009 goto out;
2010 }
2011
2012 if (xic_style & XIMStatusArea)
2013 {
2014 s_area.x = 0; s_area.y = 0; s_area.width = 1; s_area.height = 1;
2006 status_attr = XVaCreateNestedList (0, 2015 status_attr = XVaCreateNestedList (0,
2007 XNArea, 2016 XNArea,
2008 &s_area, 2017 &s_area,
2009 XNFontSet, 2018 XNFontSet,
2010 xfs, 2019 xfs,
2011 XNForeground, 2020 XNForeground,
2012 FRAME_FOREGROUND_PIXEL (f), 2021 FRAME_FOREGROUND_PIXEL (f),
2013 XNBackground, 2022 XNBackground,
2014 FRAME_BACKGROUND_PIXEL (f), 2023 FRAME_BACKGROUND_PIXEL (f),
2015 NULL); 2024 NULL);
2016 2025
2017 xic = XCreateIC (xim, 2026 if (!status_attr)
2018 XNInputStyle, xic_style, 2027 goto out;
2019 XNClientWindow, FRAME_X_WINDOW (f),
2020 XNFocusWindow, FRAME_X_WINDOW (f),
2021 XNStatusAttributes, status_attr,
2022 XNPreeditAttributes, preedit_attr,
2023 NULL);
2024 XFree (preedit_attr);
2025 XFree (status_attr);
2026 } 2028 }
2027 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
2028 FRAME_XIC (f) = xic; 2062 FRAME_XIC (f) = xic;
2029 FRAME_XIC_STYLE (f) = xic_style; 2063 FRAME_XIC_STYLE (f) = xic_style;
2030 FRAME_XIC_FONTSET (f) = xfs; 2064 xfs = NULL; /* Don't free below. */
2065
2066 out:
2067
2068 if (xfs)
2069 free_frame_xic (f);
2070
2071 if (preedit_attr)
2072 XFree (preedit_attr);
2073
2074 if (status_attr)
2075 XFree (status_attr);
2031} 2076}
2032 2077
2033 2078