aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa2000-07-21 02:06:49 +0000
committerKenichi Handa2000-07-21 02:06:49 +0000
commit96db09e41093ed1ddc0e90fb581166b9b7f899e1 (patch)
tree414b236beffe7e8148f8facdc721f08c8eef9aee /src
parente8bea4c03e9db68d836f90e7ac562ec740ed9d77 (diff)
downloademacs-96db09e41093ed1ddc0e90fb581166b9b7f899e1.tar.gz
emacs-96db09e41093ed1ddc0e90fb581166b9b7f899e1.zip
(x_encode_text): New function.
(x_set_name): Use x_encode_text. (x_set_title): Likewise.
Diffstat (limited to 'src')
-rw-r--r--src/xfns.c120
1 files changed, 100 insertions, 20 deletions
diff --git a/src/xfns.c b/src/xfns.c
index e5ba6113e56..7387d7165f8 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -39,6 +39,7 @@ Boston, MA 02111-1307, USA. */
39#include "blockinput.h" 39#include "blockinput.h"
40#include <epaths.h> 40#include <epaths.h>
41#include "charset.h" 41#include "charset.h"
42#include "coding.h"
42#include "fontset.h" 43#include "fontset.h"
43#include "systime.h" 44#include "systime.h"
44#include "termhooks.h" 45#include "termhooks.h"
@@ -237,6 +238,7 @@ Lisp_Object Quser_size;
237extern Lisp_Object Qdisplay; 238extern Lisp_Object Qdisplay;
238Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background; 239Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
239Lisp_Object Qscreen_gamma, Qline_spacing, Qcenter; 240Lisp_Object Qscreen_gamma, Qline_spacing, Qcenter;
241Lisp_Object Qcompound_text;
240 242
241/* The below are defined in frame.c. */ 243/* The below are defined in frame.c. */
242 244
@@ -2076,6 +2078,56 @@ x_set_scroll_bar_background (f, value, oldval)
2076} 2078}
2077 2079
2078 2080
2081/* Encode Lisp string STRINT as a text in a format appropriate for
2082 XICCC (X Inter Client Communication Conventions).
2083
2084 If STRING contains only ASCII characters, do no conversion and
2085 return the string data of STRING. Otherwise, encode the text by
2086 CODING_SYSTEM, and return a newly allocated memory area which
2087 should be freed by `xfree' by a caller.
2088
2089 Store the byte length of resulting text in *TEXT_BYTES.
2090
2091 If the text contains only ASCII and Latin-1, store 1 in *LATIN1_P,
2092 which means that the `encoding' of the result can be `STRING'.
2093 Otherwise store 0 in *LATIN1_P, which means that the `encoding' of
2094 the result should be `COMPOUND_TEXT'. */
2095
2096unsigned char *
2097x_encode_text (string, coding_system, text_bytes, latin1_p)
2098 Lisp_Object string, coding_system;
2099 int *text_bytes, *latin1_p;
2100{
2101 unsigned char *str = XSTRING (string)->data;
2102 int chars = XSTRING (string)->size;
2103 int bytes = STRING_BYTES (XSTRING (string));
2104 int charset_info;
2105 int bufsize;
2106 unsigned char *buf;
2107 struct coding_system coding;
2108
2109 charset_info = find_charset_in_text (str, chars, bytes, NULL, Qnil);
2110 if (charset_info == 0)
2111 {
2112 /* No multibyte character in OBJ. We need not encode it. */
2113 *text_bytes = bytes;
2114 *latin1_p = 1;
2115 return str;
2116 }
2117
2118 setup_coding_system (coding_system, &coding);
2119 coding.src_multibyte = 1;
2120 coding.dst_multibyte = 0;
2121 coding.mode |= CODING_MODE_LAST_BLOCK;
2122 bufsize = encoding_buffer_size (&coding, bytes);
2123 buf = (unsigned char *) xmalloc (bufsize);
2124 encode_coding (&coding, str, buf, bytes, bufsize);
2125 *text_bytes = coding.produced;
2126 *latin1_p = (charset_info == 1);
2127 return buf;
2128}
2129
2130
2079/* Change the name of frame F to NAME. If NAME is nil, set F's name to 2131/* Change the name of frame F to NAME. If NAME is nil, set F's name to
2080 x_id_name. 2132 x_id_name.
2081 2133
@@ -2137,19 +2189,27 @@ x_set_name (f, name, explicit)
2137#ifdef HAVE_X11R4 2189#ifdef HAVE_X11R4
2138 { 2190 {
2139 XTextProperty text, icon; 2191 XTextProperty text, icon;
2140 Lisp_Object icon_name; 2192 int bytes, latin1_p;
2141 2193
2142 text.value = XSTRING (name)->data; 2194 text.value = x_encode_text (name, Qcompound_text, &bytes, &latin1_p);
2143 text.encoding = XA_STRING; 2195 text.encoding = (latin1_p ? XA_STRING
2196 : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
2144 text.format = 8; 2197 text.format = 8;
2145 text.nitems = STRING_BYTES (XSTRING (name)); 2198 text.nitems = bytes;
2146 2199
2147 icon_name = (!NILP (f->icon_name) ? f->icon_name : name); 2200 if (NILP (f->icon_name))
2148 2201 {
2149 icon.value = XSTRING (icon_name)->data; 2202 icon = text;
2150 icon.encoding = XA_STRING; 2203 }
2151 icon.format = 8; 2204 else
2152 icon.nitems = STRING_BYTES (XSTRING (icon_name)); 2205 {
2206 icon.value = x_encode_text (f->icon_name, Qcompound_text,
2207 &bytes, &latin1_p);
2208 icon.encoding = (latin1_p ? XA_STRING
2209 : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
2210 icon.format = 8;
2211 icon.nitems = bytes;
2212 }
2153#ifdef USE_X_TOOLKIT 2213#ifdef USE_X_TOOLKIT
2154 XSetWMName (FRAME_X_DISPLAY (f), 2214 XSetWMName (FRAME_X_DISPLAY (f),
2155 XtWindow (f->output_data.x->widget), &text); 2215 XtWindow (f->output_data.x->widget), &text);
@@ -2159,6 +2219,11 @@ x_set_name (f, name, explicit)
2159 XSetWMName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &text); 2219 XSetWMName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &text);
2160 XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &icon); 2220 XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &icon);
2161#endif /* not USE_X_TOOLKIT */ 2221#endif /* not USE_X_TOOLKIT */
2222 if (!NILP (f->icon_name)
2223 && icon.value != XSTRING (f->icon_name)->data)
2224 xfree (icon.value);
2225 if (text.value != XSTRING (name)->data)
2226 xfree (text.value);
2162 } 2227 }
2163#else /* not HAVE_X11R4 */ 2228#else /* not HAVE_X11R4 */
2164 XSetIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 2229 XSetIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
@@ -2227,19 +2292,27 @@ x_set_title (f, name, old_name)
2227#ifdef HAVE_X11R4 2292#ifdef HAVE_X11R4
2228 { 2293 {
2229 XTextProperty text, icon; 2294 XTextProperty text, icon;
2230 Lisp_Object icon_name; 2295 int bytes, latin1_p;
2231 2296
2232 text.value = XSTRING (name)->data; 2297 text.value = x_encode_text (name, Qcompound_text, &bytes, &latin1_p);
2233 text.encoding = XA_STRING; 2298 text.encoding = (latin1_p ? XA_STRING
2299 : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
2234 text.format = 8; 2300 text.format = 8;
2235 text.nitems = STRING_BYTES (XSTRING (name)); 2301 text.nitems = bytes;
2236 2302
2237 icon_name = (!NILP (f->icon_name) ? f->icon_name : name); 2303 if (NILP (f->icon_name))
2238 2304 {
2239 icon.value = XSTRING (icon_name)->data; 2305 icon = text;
2240 icon.encoding = XA_STRING; 2306 }
2241 icon.format = 8; 2307 else
2242 icon.nitems = STRING_BYTES (XSTRING (icon_name)); 2308 {
2309 icon.value = x_encode_text (f->icon_name, Qcompound_text,
2310 &bytes, &latin1_p);
2311 icon.encoding = (latin1_p ? XA_STRING
2312 : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
2313 icon.format = 8;
2314 icon.nitems = bytes;
2315 }
2243#ifdef USE_X_TOOLKIT 2316#ifdef USE_X_TOOLKIT
2244 XSetWMName (FRAME_X_DISPLAY (f), 2317 XSetWMName (FRAME_X_DISPLAY (f),
2245 XtWindow (f->output_data.x->widget), &text); 2318 XtWindow (f->output_data.x->widget), &text);
@@ -2249,6 +2322,11 @@ x_set_title (f, name, old_name)
2249 XSetWMName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &text); 2322 XSetWMName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &text);
2250 XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &icon); 2323 XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &icon);
2251#endif /* not USE_X_TOOLKIT */ 2324#endif /* not USE_X_TOOLKIT */
2325 if (!NILP (f->icon_name)
2326 && icon.value != XSTRING (f->icon_name)->data)
2327 xfree (icon.value);
2328 if (text.value != XSTRING (name)->data)
2329 xfree (text.value);
2252 } 2330 }
2253#else /* not HAVE_X11R4 */ 2331#else /* not HAVE_X11R4 */
2254 XSetIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 2332 XSetIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
@@ -10297,6 +10375,8 @@ syms_of_xfns ()
10297 staticpro (&Qline_spacing); 10375 staticpro (&Qline_spacing);
10298 Qcenter = intern ("center"); 10376 Qcenter = intern ("center");
10299 staticpro (&Qcenter); 10377 staticpro (&Qcenter);
10378 Qcompound_text = intern ("compound-text");
10379 staticpro (&Qcompound_text);
10300 /* This is the end of symbol initialization. */ 10380 /* This is the end of symbol initialization. */
10301 10381
10302 /* Text property `display' should be nonsticky by default. */ 10382 /* Text property `display' should be nonsticky by default. */