Commit | Line | Data |
---|---|---|
01f1ba30 | 1 | /* Functions for the X window system. |
e9bffc61 | 2 | |
ab422c4d | 3 | Copyright (C) 1989, 1992-2013 Free Software Foundation, Inc. |
01f1ba30 JB |
4 | |
5 | This file is part of GNU Emacs. | |
6 | ||
9ec0b715 | 7 | GNU Emacs is free software: you can redistribute it and/or modify |
01f1ba30 | 8 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
9 | the Free Software Foundation, either version 3 of the License, or |
10 | (at your option) any later version. | |
01f1ba30 JB |
11 | |
12 | GNU Emacs is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
9ec0b715 | 18 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
01f1ba30 | 19 | |
c389a86d | 20 | #include <config.h> |
333b20bb | 21 | #include <stdio.h> |
d62c8769 | 22 | #include <math.h> |
3ecaf7e5 | 23 | #include <unistd.h> |
3ecaf7e5 | 24 | |
01f1ba30 JB |
25 | #include "lisp.h" |
26 | #include "xterm.h" | |
f676886a | 27 | #include "frame.h" |
01f1ba30 | 28 | #include "window.h" |
e5560ff7 | 29 | #include "character.h" |
01f1ba30 | 30 | #include "buffer.h" |
58cad5ed | 31 | #include "intervals.h" |
01f1ba30 | 32 | #include "dispextern.h" |
1f98fa48 | 33 | #include "keyboard.h" |
9ac0d9e0 | 34 | #include "blockinput.h" |
57bda87a | 35 | #include <epaths.h> |
942ea06d | 36 | #include "charset.h" |
96db09e4 | 37 | #include "coding.h" |
942ea06d | 38 | #include "fontset.h" |
333b20bb GM |
39 | #include "systime.h" |
40 | #include "termhooks.h" | |
4ae9a85e | 41 | #include "atimer.h" |
28d440ab | 42 | #include "termchar.h" |
02ed2ea8 | 43 | #include "font.h" |
02ed2ea8 | 44 | |
63cec32f GM |
45 | #include <sys/types.h> |
46 | #include <sys/stat.h> | |
01f1ba30 | 47 | |
0505a740 | 48 | #if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */ |
ef493a27 RS |
49 | #include "bitmaps/gray.xbm" |
50 | #else | |
dbc4e1c1 | 51 | #include <X11/bitmaps/gray> |
ef493a27 | 52 | #endif |
dbc4e1c1 | 53 | |
1b9ac145 AS |
54 | #include "xsettings.h" |
55 | ||
4e3f9230 YM |
56 | #ifdef HAVE_XRANDR |
57 | #include <X11/extensions/Xrandr.h> | |
58 | #endif | |
59 | #ifdef HAVE_XINERAMA | |
60 | #include <X11/extensions/Xinerama.h> | |
61 | #endif | |
62 | ||
488dd4c4 JD |
63 | #ifdef USE_GTK |
64 | #include "gtkutil.h" | |
65 | #endif | |
66 | ||
9ef48a9d RS |
67 | #ifdef USE_X_TOOLKIT |
68 | #include <X11/Shell.h> | |
69 | ||
398ffa92 | 70 | #ifndef USE_MOTIF |
8ab9202e CY |
71 | #ifdef HAVE_XAW3D |
72 | #include <X11/Xaw3d/Paned.h> | |
a6ec6cfb | 73 | #include <X11/Xaw3d/Label.h> |
8ab9202e | 74 | #else /* !HAVE_XAW3D */ |
9ef48a9d RS |
75 | #include <X11/Xaw/Paned.h> |
76 | #include <X11/Xaw/Label.h> | |
8ab9202e | 77 | #endif /* HAVE_XAW3D */ |
398ffa92 | 78 | #endif /* USE_MOTIF */ |
9ef48a9d RS |
79 | |
80 | #ifdef USG | |
81 | #undef USG /* ####KLUDGE for Solaris 2.2 and up */ | |
82 | #include <X11/Xos.h> | |
83 | #define USG | |
dc5ddd85 PE |
84 | #ifdef USG /* Pacify gcc -Wunused-macros. */ |
85 | #endif | |
9ef48a9d RS |
86 | #else |
87 | #include <X11/Xos.h> | |
88 | #endif | |
89 | ||
90 | #include "widget.h" | |
91 | ||
92 | #include "../lwlib/lwlib.h" | |
93 | ||
333b20bb GM |
94 | #ifdef USE_MOTIF |
95 | #include <Xm/Xm.h> | |
96 | #include <Xm/DialogS.h> | |
97 | #include <Xm/FileSB.h> | |
dee186b6 J |
98 | #include <Xm/List.h> |
99 | #include <Xm/TextF.h> | |
333b20bb GM |
100 | #endif |
101 | ||
eec47d6b DN |
102 | #ifdef USE_LUCID |
103 | #include "../lwlib/xlwmenu.h" | |
104 | #endif | |
105 | ||
5e617bc2 | 106 | #if !defined (NO_EDITRES) |
6c32dd68 | 107 | #define HACK_EDITRES |
764430a3 | 108 | extern void _XEditResCheckMessages (Widget, XtPointer, XEvent *, Boolean *); |
ee6bacd4 | 109 | #endif /* not defined NO_EDITRES */ |
6c32dd68 | 110 | |
333b20bb GM |
111 | /* Unique id counter for widgets created by the Lucid Widget Library. */ |
112 | ||
6c32dd68 PR |
113 | extern LWLIB_ID widget_id_tick; |
114 | ||
fc2cdd9a GM |
115 | #ifdef USE_MOTIF |
116 | ||
fc2cdd9a GM |
117 | #endif /* USE_MOTIF */ |
118 | ||
9ef48a9d RS |
119 | #endif /* USE_X_TOOLKIT */ |
120 | ||
6b61353c KH |
121 | #ifdef USE_GTK |
122 | ||
6b61353c KH |
123 | #endif /* USE_GTK */ |
124 | ||
9d317b2c | 125 | #define MAXREQUEST(dpy) (XMaxRequestSize (dpy)) |
9d317b2c | 126 | |
955cbe7b PE |
127 | static Lisp_Object Qsuppress_icon; |
128 | static Lisp_Object Qundefined_color; | |
129 | static Lisp_Object Qcompound_text, Qcancel_timer; | |
581e51e8 | 130 | Lisp_Object Qfont_param; |
01f1ba30 | 131 | |
e509cfa6 | 132 | #ifdef GLYPH_DEBUG |
13464394 PE |
133 | static ptrdiff_t image_cache_refcount; |
134 | static int dpyinfo_refcount; | |
eaf1eea9 GM |
135 | #endif |
136 | ||
e4cebfca PE |
137 | static struct x_display_info *x_display_info_for_name (Lisp_Object); |
138 | ||
7e59217d | 139 | /* Let the user specify an X display with a Lisp object. |
708e05dc | 140 | OBJECT may be nil, a frame or a terminal object. |
b9dc4443 RS |
141 | nil stands for the selected frame--or, if that is not an X frame, |
142 | the first X display on the list. */ | |
143 | ||
7c0d3ed8 | 144 | struct x_display_info * |
971de7fb | 145 | check_x_display_info (Lisp_Object object) |
b9dc4443 | 146 | { |
8ec8a5ec | 147 | struct x_display_info *dpyinfo = NULL; |
177c0ea7 | 148 | |
7e59217d | 149 | if (NILP (object)) |
b9dc4443 | 150 | { |
0fe92f72 | 151 | struct frame *sf = XFRAME (selected_frame); |
177c0ea7 | 152 | |
0fe92f72 | 153 | if (FRAME_X_P (sf) && FRAME_LIVE_P (sf)) |
aad3612f | 154 | dpyinfo = FRAME_DISPLAY_INFO (sf); |
b9dc4443 | 155 | else if (x_display_list != 0) |
8ec8a5ec | 156 | dpyinfo = x_display_list; |
b9dc4443 RS |
157 | else |
158 | error ("X windows are not in use or not initialized"); | |
159 | } | |
708e05dc | 160 | else if (TERMINALP (object)) |
b6660415 | 161 | { |
fd0f53a9 | 162 | struct terminal *t = get_terminal (object, 1); |
b6660415 | 163 | |
6ed8eeff | 164 | if (t->type != output_x_window) |
5ba8bf35 | 165 | error ("Terminal %d is not an X display", t->id); |
b6660415 | 166 | |
6ed8eeff | 167 | dpyinfo = t->display_info.x; |
b6660415 | 168 | } |
7e59217d KL |
169 | else if (STRINGP (object)) |
170 | dpyinfo = x_display_info_for_name (object); | |
b9dc4443 RS |
171 | else |
172 | { | |
a10c8269 | 173 | struct frame *f = decode_window_system_frame (object); |
aad3612f | 174 | dpyinfo = FRAME_DISPLAY_INFO (f); |
b9dc4443 | 175 | } |
8ec8a5ec GM |
176 | |
177 | return dpyinfo; | |
b9dc4443 | 178 | } |
333b20bb | 179 | |
08a90d6a | 180 | /* Store the screen positions of frame F into XPTR and YPTR. |
e9445337 RS |
181 | These are the positions of the containing window manager window, |
182 | not Emacs's own window. */ | |
183 | ||
184 | void | |
a10c8269 | 185 | x_real_positions (struct frame *f, int *xptr, int *yptr) |
e9445337 | 186 | { |
8ffc96f5 | 187 | int win_x, win_y, outer_x IF_LINT (= 0), outer_y IF_LINT (= 0); |
49d41073 EZ |
188 | int real_x = 0, real_y = 0; |
189 | int had_errors = 0; | |
190 | Window win = f->output_data.x->parent_desc; | |
d75c9992 JD |
191 | Atom actual_type; |
192 | unsigned long actual_size, bytes_remaining; | |
06b0c8a0 | 193 | int rc, actual_format; |
aad3612f | 194 | struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); |
d75c9992 JD |
195 | long max_len = 400; |
196 | Display *dpy = FRAME_X_DISPLAY (f); | |
197 | unsigned char *tmp_data = NULL; | |
198 | Atom target_type = XA_CARDINAL; | |
e9445337 | 199 | |
4d7e6e51 | 200 | block_input (); |
49d41073 | 201 | |
d75c9992 | 202 | x_catch_errors (dpy); |
043835a3 | 203 | |
31887d45 | 204 | if (win == dpyinfo->root_window) |
49d41073 EZ |
205 | win = FRAME_OUTER_WINDOW (f); |
206 | ||
207 | /* This loop traverses up the containment tree until we hit the root | |
208 | window. Window managers may intersect many windows between our window | |
209 | and the root window. The window we find just before the root window | |
210 | should be the outer WM window. */ | |
211 | for (;;) | |
e9445337 | 212 | { |
49d41073 EZ |
213 | Window wm_window, rootw; |
214 | Window *tmp_children; | |
215 | unsigned int tmp_nchildren; | |
e7161ad9 | 216 | int success; |
ca7bac79 | 217 | |
e7161ad9 RS |
218 | success = XQueryTree (FRAME_X_DISPLAY (f), win, &rootw, |
219 | &wm_window, &tmp_children, &tmp_nchildren); | |
08a90d6a | 220 | |
49d41073 | 221 | had_errors = x_had_errors_p (FRAME_X_DISPLAY (f)); |
08a90d6a | 222 | |
e7161ad9 RS |
223 | /* Don't free tmp_children if XQueryTree failed. */ |
224 | if (! success) | |
225 | break; | |
226 | ||
98c6f1e3 | 227 | XFree (tmp_children); |
e7161ad9 | 228 | |
49d41073 EZ |
229 | if (wm_window == rootw || had_errors) |
230 | break; | |
08a90d6a | 231 | |
49d41073 EZ |
232 | win = wm_window; |
233 | } | |
177c0ea7 | 234 | |
49d41073 EZ |
235 | if (! had_errors) |
236 | { | |
47c53789 | 237 | unsigned int ign; |
49d41073 | 238 | Window child, rootw; |
177c0ea7 | 239 | |
49d41073 EZ |
240 | /* Get the real coordinates for the WM window upper left corner */ |
241 | XGetGeometry (FRAME_X_DISPLAY (f), win, | |
242 | &rootw, &real_x, &real_y, &ign, &ign, &ign, &ign); | |
243 | ||
244 | /* Translate real coordinates to coordinates relative to our | |
245 | window. For our window, the upper left corner is 0, 0. | |
246 | Since the upper left corner of the WM window is outside | |
247 | our window, win_x and win_y will be negative: | |
248 | ||
249 | ------------------ ---> x | |
250 | | title | | |
251 | | ----------------- v y | |
252 | | | our window | |
253 | */ | |
8a07bba0 | 254 | XTranslateCoordinates (FRAME_X_DISPLAY (f), |
e9445337 | 255 | |
8a07bba0 | 256 | /* From-window, to-window. */ |
aad3612f | 257 | FRAME_DISPLAY_INFO (f)->root_window, |
49d41073 | 258 | FRAME_X_WINDOW (f), |
e9445337 | 259 | |
8a07bba0 | 260 | /* From-position, to-position. */ |
49d41073 | 261 | real_x, real_y, &win_x, &win_y, |
08a90d6a | 262 | |
8a07bba0 RS |
263 | /* Child of win. */ |
264 | &child); | |
e9445337 | 265 | |
49d41073 | 266 | if (FRAME_X_WINDOW (f) == FRAME_OUTER_WINDOW (f)) |
845e9d85 | 267 | { |
49d41073 EZ |
268 | outer_x = win_x; |
269 | outer_y = win_y; | |
845e9d85 | 270 | } |
49d41073 EZ |
271 | else |
272 | { | |
273 | XTranslateCoordinates (FRAME_X_DISPLAY (f), | |
ca7bac79 | 274 | |
49d41073 | 275 | /* From-window, to-window. */ |
aad3612f | 276 | FRAME_DISPLAY_INFO (f)->root_window, |
49d41073 | 277 | FRAME_OUTER_WINDOW (f), |
177c0ea7 | 278 | |
49d41073 EZ |
279 | /* From-position, to-position. */ |
280 | real_x, real_y, &outer_x, &outer_y, | |
177c0ea7 | 281 | |
49d41073 EZ |
282 | /* Child of win. */ |
283 | &child); | |
be786000 | 284 | } |
08a90d6a | 285 | |
49d41073 EZ |
286 | had_errors = x_had_errors_p (FRAME_X_DISPLAY (f)); |
287 | } | |
177c0ea7 | 288 | |
31887d45 JD |
289 | |
290 | if (dpyinfo->root_window == f->output_data.x->parent_desc) | |
291 | { | |
292 | /* Try _NET_FRAME_EXTENTS if our parent is the root window. */ | |
293 | rc = XGetWindowProperty (dpy, win, dpyinfo->Xatom_net_frame_extents, | |
294 | 0, max_len, False, target_type, | |
295 | &actual_type, &actual_format, &actual_size, | |
296 | &bytes_remaining, &tmp_data); | |
297 | ||
298 | if (rc == Success && actual_type == target_type && !x_had_errors_p (dpy) | |
299 | && actual_size == 4 && actual_format == 32) | |
300 | { | |
717c30e0 | 301 | unsigned int ign; |
31887d45 | 302 | Window rootw; |
c0098065 | 303 | long *fe = (long *)tmp_data; |
31887d45 JD |
304 | |
305 | XGetGeometry (FRAME_X_DISPLAY (f), win, | |
306 | &rootw, &real_x, &real_y, &ign, &ign, &ign, &ign); | |
31887d45 JD |
307 | outer_x = -fe[0]; |
308 | outer_y = -fe[2]; | |
309 | real_x -= fe[0]; | |
310 | real_y -= fe[2]; | |
311 | } | |
312 | } | |
313 | ||
314 | if (tmp_data) XFree (tmp_data); | |
315 | ||
4545fa20 | 316 | x_uncatch_errors (); |
177c0ea7 | 317 | |
4d7e6e51 | 318 | unblock_input (); |
49d41073 EZ |
319 | |
320 | if (had_errors) return; | |
177c0ea7 | 321 | |
be786000 KS |
322 | f->x_pixels_diff = -win_x; |
323 | f->y_pixels_diff = -win_y; | |
324 | ||
325 | FRAME_X_OUTPUT (f)->x_pixels_outer_diff = -outer_x; | |
326 | FRAME_X_OUTPUT (f)->y_pixels_outer_diff = -outer_y; | |
49d41073 EZ |
327 | |
328 | *xptr = real_x; | |
329 | *yptr = real_y; | |
e9445337 RS |
330 | } |
331 | ||
01f1ba30 | 332 | \f |
82978295 | 333 | |
d62c8769 GM |
334 | |
335 | /* Gamma-correct COLOR on frame F. */ | |
336 | ||
337 | void | |
971de7fb | 338 | gamma_correct (struct frame *f, XColor *color) |
d62c8769 GM |
339 | { |
340 | if (f->gamma) | |
341 | { | |
342 | color->red = pow (color->red / 65535.0, f->gamma) * 65535.0 + 0.5; | |
343 | color->green = pow (color->green / 65535.0, f->gamma) * 65535.0 + 0.5; | |
344 | color->blue = pow (color->blue / 65535.0, f->gamma) * 65535.0 + 0.5; | |
345 | } | |
346 | } | |
347 | ||
348 | ||
7b746c38 | 349 | /* Decide if color named COLOR_NAME is valid for use on frame F. If |
578098f3 PE |
350 | so, return the RGB values in COLOR. If ALLOC_P, |
351 | allocate the color. Value is false if COLOR_NAME is invalid, or | |
7b746c38 | 352 | no color could be allocated. */ |
e12d55b2 | 353 | |
578098f3 | 354 | bool |
eec47d6b | 355 | x_defined_color (struct frame *f, const char *color_name, |
578098f3 | 356 | XColor *color, bool alloc_p) |
01f1ba30 | 357 | { |
578098f3 | 358 | bool success_p = 0; |
7b746c38 GM |
359 | Display *dpy = FRAME_X_DISPLAY (f); |
360 | Colormap cmap = FRAME_X_COLORMAP (f); | |
01f1ba30 | 361 | |
4d7e6e51 | 362 | block_input (); |
3a46642b J |
363 | #ifdef USE_GTK |
364 | success_p = xg_check_special_colors (f, color_name, color); | |
365 | #endif | |
366 | if (!success_p) | |
578098f3 | 367 | success_p = XParseColor (dpy, cmap, color_name, color) != 0; |
7b746c38 GM |
368 | if (success_p && alloc_p) |
369 | success_p = x_alloc_nearest_color (f, cmap, color); | |
4d7e6e51 | 370 | unblock_input (); |
01f1ba30 | 371 | |
7b746c38 | 372 | return success_p; |
01f1ba30 JB |
373 | } |
374 | ||
9b2956e2 GM |
375 | |
376 | /* Return the pixel color value for color COLOR_NAME on frame F. If F | |
377 | is a monochrome frame, return MONO_COLOR regardless of what ARG says. | |
378 | Signal an error if color can't be allocated. */ | |
01f1ba30 | 379 | |
f78faa98 | 380 | static int |
a10c8269 | 381 | x_decode_color (struct frame *f, Lisp_Object color_name, int mono_color) |
01f1ba30 | 382 | { |
b9dc4443 | 383 | XColor cdef; |
01f1ba30 | 384 | |
b7826503 | 385 | CHECK_STRING (color_name); |
01f1ba30 | 386 | |
9b2956e2 GM |
387 | #if 0 /* Don't do this. It's wrong when we're not using the default |
388 | colormap, it makes freeing difficult, and it's probably not | |
389 | an important optimization. */ | |
d5db4077 | 390 | if (strcmp (SDATA (color_name), "black") == 0) |
b9dc4443 | 391 | return BLACK_PIX_DEFAULT (f); |
d5db4077 | 392 | else if (strcmp (SDATA (color_name), "white") == 0) |
b9dc4443 | 393 | return WHITE_PIX_DEFAULT (f); |
9b2956e2 | 394 | #endif |
01f1ba30 | 395 | |
9b2956e2 | 396 | /* Return MONO_COLOR for monochrome frames. */ |
aad3612f | 397 | if (FRAME_DISPLAY_INFO (f)->n_planes == 1) |
9b2956e2 | 398 | return mono_color; |
01f1ba30 | 399 | |
2d764c78 | 400 | /* x_defined_color is responsible for coping with failures |
95626e11 | 401 | by looking for a near-miss. */ |
42a5b22f | 402 | if (x_defined_color (f, SSDATA (color_name), &cdef, 1)) |
95626e11 RS |
403 | return cdef.pixel; |
404 | ||
93217cef | 405 | signal_error ("Undefined color", color_name); |
01f1ba30 | 406 | } |
9b2956e2 GM |
407 | |
408 | ||
01f1ba30 | 409 | \f |
ea0a1f53 GM |
410 | /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is |
411 | the previous value of that parameter, NEW_VALUE is the new value. | |
412 | See also the comment of wait_for_wm in struct x_output. */ | |
413 | ||
414 | static void | |
971de7fb | 415 | x_set_wait_for_wm (struct frame *f, Lisp_Object new_value, Lisp_Object old_value) |
ea0a1f53 GM |
416 | { |
417 | f->output_data.x->wait_for_wm = !NILP (new_value); | |
418 | } | |
419 | ||
bfeabdc3 JD |
420 | static void |
421 | x_set_tool_bar_position (struct frame *f, | |
422 | Lisp_Object new_value, | |
423 | Lisp_Object old_value) | |
424 | { | |
425 | if (! EQ (new_value, Qleft) && ! EQ (new_value, Qright) | |
426 | && ! EQ (new_value, Qbottom) && ! EQ (new_value, Qtop)) | |
427 | return; | |
428 | if (EQ (new_value, old_value)) return; | |
429 | ||
430 | #ifdef USE_GTK | |
18e27ea8 PE |
431 | xg_change_toolbar_position (f, new_value); |
432 | fset_tool_bar_position (f, new_value); | |
bfeabdc3 JD |
433 | #endif |
434 | } | |
435 | ||
993d0721 JB |
436 | #ifdef USE_GTK |
437 | ||
465aa50a JD |
438 | /* Set icon from FILE for frame F. By using GTK functions the icon |
439 | may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */ | |
993d0721 JB |
440 | |
441 | int | |
a10c8269 | 442 | xg_set_icon (struct frame *f, Lisp_Object file) |
993d0721 | 443 | { |
465aa50a JD |
444 | int result = 0; |
445 | Lisp_Object found; | |
993d0721 | 446 | |
465aa50a JD |
447 | found = x_find_image_file (file); |
448 | ||
449 | if (! NILP (found)) | |
450 | { | |
451 | GdkPixbuf *pixbuf; | |
452 | GError *err = NULL; | |
51b59d79 | 453 | char *filename = SSDATA (found); |
4d7e6e51 | 454 | block_input (); |
465aa50a JD |
455 | |
456 | pixbuf = gdk_pixbuf_new_from_file (filename, &err); | |
457 | ||
458 | if (pixbuf) | |
459 | { | |
460 | gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), | |
461 | pixbuf); | |
462 | g_object_unref (pixbuf); | |
463 | ||
464 | result = 1; | |
465 | } | |
466 | else | |
467 | g_error_free (err); | |
468 | ||
4d7e6e51 | 469 | unblock_input (); |
465aa50a JD |
470 | } |
471 | ||
465aa50a | 472 | return result; |
993d0721 | 473 | } |
9f7b984b CY |
474 | |
475 | int | |
a10c8269 | 476 | xg_set_icon_from_xpm_data (struct frame *f, const char **data) |
9f7b984b | 477 | { |
648801d1 | 478 | GdkPixbuf *pixbuf = gdk_pixbuf_new_from_xpm_data (data); |
9f7b984b CY |
479 | |
480 | if (!pixbuf) | |
47c53789 | 481 | return 0; |
9f7b984b | 482 | |
47c53789 | 483 | gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), pixbuf); |
9f7b984b CY |
484 | g_object_unref (pixbuf); |
485 | return 1; | |
486 | } | |
993d0721 JB |
487 | #endif /* USE_GTK */ |
488 | ||
ea0a1f53 | 489 | |
f676886a | 490 | /* Functions called only from `x_set_frame_param' |
01f1ba30 JB |
491 | to set individual parameters. |
492 | ||
fe24a618 | 493 | If FRAME_X_WINDOW (f) is 0, |
f676886a | 494 | the frame is being created and its X-window does not exist yet. |
01f1ba30 JB |
495 | In that case, just record the parameter's new value |
496 | in the standard place; do not attempt to change the window. */ | |
497 | ||
e4cebfca | 498 | static void |
971de7fb | 499 | x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
01f1ba30 | 500 | { |
09393d07 GM |
501 | struct x_output *x = f->output_data.x; |
502 | unsigned long fg, old_fg; | |
a76206dc | 503 | |
09393d07 | 504 | fg = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); |
ce593f6e KL |
505 | old_fg = FRAME_FOREGROUND_PIXEL (f); |
506 | FRAME_FOREGROUND_PIXEL (f) = fg; | |
a76206dc | 507 | |
fe24a618 | 508 | if (FRAME_X_WINDOW (f) != 0) |
01f1ba30 | 509 | { |
09393d07 | 510 | Display *dpy = FRAME_X_DISPLAY (f); |
177c0ea7 | 511 | |
4d7e6e51 | 512 | block_input (); |
09393d07 GM |
513 | XSetForeground (dpy, x->normal_gc, fg); |
514 | XSetBackground (dpy, x->reverse_gc, fg); | |
36d42089 | 515 | |
09393d07 GM |
516 | if (x->cursor_pixel == old_fg) |
517 | { | |
518 | unload_color (f, x->cursor_pixel); | |
519 | x->cursor_pixel = x_copy_color (f, fg); | |
520 | XSetBackground (dpy, x->cursor_gc, x->cursor_pixel); | |
521 | } | |
177c0ea7 | 522 | |
4d7e6e51 | 523 | unblock_input (); |
177c0ea7 | 524 | |
05c8abbe | 525 | update_face_from_frame_parameter (f, Qforeground_color, arg); |
177c0ea7 | 526 | |
179956b9 | 527 | if (FRAME_VISIBLE_P (f)) |
f676886a | 528 | redraw_frame (f); |
01f1ba30 | 529 | } |
177c0ea7 | 530 | |
09393d07 | 531 | unload_color (f, old_fg); |
01f1ba30 JB |
532 | } |
533 | ||
e4cebfca | 534 | static void |
971de7fb | 535 | x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
01f1ba30 | 536 | { |
09393d07 GM |
537 | struct x_output *x = f->output_data.x; |
538 | unsigned long bg; | |
01f1ba30 | 539 | |
09393d07 | 540 | bg = x_decode_color (f, arg, WHITE_PIX_DEFAULT (f)); |
ce593f6e KL |
541 | unload_color (f, FRAME_BACKGROUND_PIXEL (f)); |
542 | FRAME_BACKGROUND_PIXEL (f) = bg; | |
a76206dc | 543 | |
fe24a618 | 544 | if (FRAME_X_WINDOW (f) != 0) |
01f1ba30 | 545 | { |
09393d07 | 546 | Display *dpy = FRAME_X_DISPLAY (f); |
177c0ea7 | 547 | |
4d7e6e51 | 548 | block_input (); |
09393d07 GM |
549 | XSetBackground (dpy, x->normal_gc, bg); |
550 | XSetForeground (dpy, x->reverse_gc, bg); | |
551 | XSetWindowBackground (dpy, FRAME_X_WINDOW (f), bg); | |
552 | XSetForeground (dpy, x->cursor_gc, bg); | |
553 | ||
488dd4c4 JD |
554 | #ifdef USE_GTK |
555 | xg_set_background_color (f, bg); | |
556 | #endif | |
557 | ||
f76e0368 GM |
558 | #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with |
559 | toolkit scroll bars. */ | |
560 | { | |
561 | Lisp_Object bar; | |
562 | for (bar = FRAME_SCROLL_BARS (f); | |
563 | !NILP (bar); | |
564 | bar = XSCROLL_BAR (bar)->next) | |
565 | { | |
056ce195 | 566 | Window window = XSCROLL_BAR (bar)->x_window; |
f76e0368 GM |
567 | XSetWindowBackground (dpy, window, bg); |
568 | } | |
569 | } | |
570 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | |
01f1ba30 | 571 | |
4d7e6e51 | 572 | unblock_input (); |
05c8abbe | 573 | update_face_from_frame_parameter (f, Qbackground_color, arg); |
ea96210c | 574 | |
179956b9 | 575 | if (FRAME_VISIBLE_P (f)) |
f676886a | 576 | redraw_frame (f); |
01f1ba30 JB |
577 | } |
578 | } | |
579 | ||
e044e4fc | 580 | static Cursor |
971de7fb | 581 | make_invisible_cursor (struct frame *f) |
e044e4fc JD |
582 | { |
583 | Display *dpy = FRAME_X_DISPLAY (f); | |
584 | static char const no_data[] = { 0 }; | |
585 | Pixmap pix; | |
586 | XColor col; | |
8664db06 | 587 | Cursor c = 0; |
e044e4fc JD |
588 | |
589 | x_catch_errors (dpy); | |
aad3612f | 590 | pix = XCreateBitmapFromData (dpy, FRAME_DISPLAY_INFO (f)->root_window, |
e044e4fc JD |
591 | no_data, 1, 1); |
592 | if (! x_had_errors_p (dpy) && pix != None) | |
593 | { | |
8664db06 | 594 | Cursor pixc; |
e044e4fc JD |
595 | col.pixel = 0; |
596 | col.red = col.green = col.blue = 0; | |
597 | col.flags = DoRed | DoGreen | DoBlue; | |
8664db06 PE |
598 | pixc = XCreatePixmapCursor (dpy, pix, pix, &col, &col, 0, 0); |
599 | if (! x_had_errors_p (dpy) && pixc != None) | |
600 | c = pixc; | |
e044e4fc JD |
601 | XFreePixmap (dpy, pix); |
602 | } | |
603 | ||
604 | x_uncatch_errors (); | |
605 | ||
606 | return c; | |
607 | } | |
608 | ||
e4cebfca | 609 | static void |
971de7fb | 610 | x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
01f1ba30 | 611 | { |
09393d07 GM |
612 | struct x_output *x = f->output_data.x; |
613 | Display *dpy = FRAME_X_DISPLAY (f); | |
3d970f28 | 614 | Cursor cursor, nontext_cursor, mode_cursor, hand_cursor; |
0af913d7 | 615 | Cursor hourglass_cursor, horizontal_drag_cursor; |
51a1d2d8 | 616 | unsigned long pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); |
ce593f6e | 617 | unsigned long mask_color = FRAME_BACKGROUND_PIXEL (f); |
a76206dc | 618 | |
51a1d2d8 | 619 | /* Don't let pointers be invisible. */ |
09393d07 | 620 | if (mask_color == pixel) |
bcf26b38 GM |
621 | { |
622 | x_free_colors (f, &pixel, 1); | |
ce593f6e | 623 | pixel = x_copy_color (f, FRAME_FOREGROUND_PIXEL (f)); |
bcf26b38 | 624 | } |
a76206dc | 625 | |
09393d07 GM |
626 | unload_color (f, x->mouse_pixel); |
627 | x->mouse_pixel = pixel; | |
01f1ba30 | 628 | |
4d7e6e51 | 629 | block_input (); |
fe24a618 | 630 | |
eb8c3be9 | 631 | /* It's not okay to crash if the user selects a screwy cursor. */ |
9ba8e10d | 632 | x_catch_errors (dpy); |
fe24a618 | 633 | |
09393d07 | 634 | if (!NILP (Vx_pointer_shape)) |
01f1ba30 | 635 | { |
b7826503 | 636 | CHECK_NUMBER (Vx_pointer_shape); |
09393d07 | 637 | cursor = XCreateFontCursor (dpy, XINT (Vx_pointer_shape)); |
01f1ba30 JB |
638 | } |
639 | else | |
09393d07 GM |
640 | cursor = XCreateFontCursor (dpy, XC_xterm); |
641 | x_check_errors (dpy, "bad text pointer cursor: %s"); | |
01f1ba30 | 642 | |
09393d07 | 643 | if (!NILP (Vx_nontext_pointer_shape)) |
01f1ba30 | 644 | { |
b7826503 | 645 | CHECK_NUMBER (Vx_nontext_pointer_shape); |
09393d07 GM |
646 | nontext_cursor |
647 | = XCreateFontCursor (dpy, XINT (Vx_nontext_pointer_shape)); | |
01f1ba30 JB |
648 | } |
649 | else | |
09393d07 GM |
650 | nontext_cursor = XCreateFontCursor (dpy, XC_left_ptr); |
651 | x_check_errors (dpy, "bad nontext pointer cursor: %s"); | |
01f1ba30 | 652 | |
09393d07 | 653 | if (!NILP (Vx_hourglass_pointer_shape)) |
333b20bb | 654 | { |
b7826503 | 655 | CHECK_NUMBER (Vx_hourglass_pointer_shape); |
09393d07 GM |
656 | hourglass_cursor |
657 | = XCreateFontCursor (dpy, XINT (Vx_hourglass_pointer_shape)); | |
333b20bb GM |
658 | } |
659 | else | |
09393d07 GM |
660 | hourglass_cursor = XCreateFontCursor (dpy, XC_watch); |
661 | x_check_errors (dpy, "bad hourglass pointer cursor: %s"); | |
177c0ea7 | 662 | |
09393d07 | 663 | if (!NILP (Vx_mode_pointer_shape)) |
01f1ba30 | 664 | { |
b7826503 | 665 | CHECK_NUMBER (Vx_mode_pointer_shape); |
09393d07 | 666 | mode_cursor = XCreateFontCursor (dpy, XINT (Vx_mode_pointer_shape)); |
01f1ba30 JB |
667 | } |
668 | else | |
09393d07 GM |
669 | mode_cursor = XCreateFontCursor (dpy, XC_xterm); |
670 | x_check_errors (dpy, "bad modeline pointer cursor: %s"); | |
95f80c78 | 671 | |
09393d07 | 672 | if (!NILP (Vx_sensitive_text_pointer_shape)) |
95f80c78 | 673 | { |
b7826503 | 674 | CHECK_NUMBER (Vx_sensitive_text_pointer_shape); |
3d970f28 | 675 | hand_cursor |
09393d07 | 676 | = XCreateFontCursor (dpy, XINT (Vx_sensitive_text_pointer_shape)); |
95f80c78 FP |
677 | } |
678 | else | |
3d970f28 | 679 | hand_cursor = XCreateFontCursor (dpy, XC_hand2); |
01f1ba30 | 680 | |
8fb4ec9c GM |
681 | if (!NILP (Vx_window_horizontal_drag_shape)) |
682 | { | |
b7826503 | 683 | CHECK_NUMBER (Vx_window_horizontal_drag_shape); |
8fb4ec9c | 684 | horizontal_drag_cursor |
09393d07 | 685 | = XCreateFontCursor (dpy, XINT (Vx_window_horizontal_drag_shape)); |
8fb4ec9c GM |
686 | } |
687 | else | |
688 | horizontal_drag_cursor | |
09393d07 | 689 | = XCreateFontCursor (dpy, XC_sb_h_double_arrow); |
8fb4ec9c | 690 | |
fe24a618 | 691 | /* Check and report errors with the above calls. */ |
09393d07 | 692 | x_check_errors (dpy, "can't set cursor shape: %s"); |
4545fa20 | 693 | x_uncatch_errors (); |
fe24a618 | 694 | |
01f1ba30 JB |
695 | { |
696 | XColor fore_color, back_color; | |
697 | ||
09393d07 | 698 | fore_color.pixel = x->mouse_pixel; |
a31fedb7 | 699 | x_query_color (f, &fore_color); |
01f1ba30 | 700 | back_color.pixel = mask_color; |
a31fedb7 | 701 | x_query_color (f, &back_color); |
177c0ea7 | 702 | |
09393d07 GM |
703 | XRecolorCursor (dpy, cursor, &fore_color, &back_color); |
704 | XRecolorCursor (dpy, nontext_cursor, &fore_color, &back_color); | |
705 | XRecolorCursor (dpy, mode_cursor, &fore_color, &back_color); | |
3d970f28 | 706 | XRecolorCursor (dpy, hand_cursor, &fore_color, &back_color); |
09393d07 GM |
707 | XRecolorCursor (dpy, hourglass_cursor, &fore_color, &back_color); |
708 | XRecolorCursor (dpy, horizontal_drag_cursor, &fore_color, &back_color); | |
01f1ba30 | 709 | } |
01f1ba30 | 710 | |
fe24a618 | 711 | if (FRAME_X_WINDOW (f) != 0) |
e044e4fc JD |
712 | XDefineCursor (dpy, FRAME_X_WINDOW (f), |
713 | f->output_data.x->current_cursor = cursor); | |
09393d07 | 714 | |
aad3612f DA |
715 | if (FRAME_DISPLAY_INFO (f)->invisible_cursor == 0) |
716 | FRAME_DISPLAY_INFO (f)->invisible_cursor = make_invisible_cursor (f); | |
f5f6c0e0 | 717 | |
09393d07 GM |
718 | if (cursor != x->text_cursor |
719 | && x->text_cursor != 0) | |
720 | XFreeCursor (dpy, x->text_cursor); | |
721 | x->text_cursor = cursor; | |
722 | ||
723 | if (nontext_cursor != x->nontext_cursor | |
724 | && x->nontext_cursor != 0) | |
725 | XFreeCursor (dpy, x->nontext_cursor); | |
726 | x->nontext_cursor = nontext_cursor; | |
727 | ||
728 | if (hourglass_cursor != x->hourglass_cursor | |
729 | && x->hourglass_cursor != 0) | |
730 | XFreeCursor (dpy, x->hourglass_cursor); | |
731 | x->hourglass_cursor = hourglass_cursor; | |
732 | ||
733 | if (mode_cursor != x->modeline_cursor | |
734 | && x->modeline_cursor != 0) | |
735 | XFreeCursor (dpy, f->output_data.x->modeline_cursor); | |
736 | x->modeline_cursor = mode_cursor; | |
177c0ea7 | 737 | |
3d970f28 KS |
738 | if (hand_cursor != x->hand_cursor |
739 | && x->hand_cursor != 0) | |
740 | XFreeCursor (dpy, x->hand_cursor); | |
741 | x->hand_cursor = hand_cursor; | |
01f1ba30 | 742 | |
09393d07 GM |
743 | if (horizontal_drag_cursor != x->horizontal_drag_cursor |
744 | && x->horizontal_drag_cursor != 0) | |
745 | XFreeCursor (dpy, x->horizontal_drag_cursor); | |
746 | x->horizontal_drag_cursor = horizontal_drag_cursor; | |
8fb4ec9c | 747 | |
09393d07 | 748 | XFlush (dpy); |
4d7e6e51 | 749 | unblock_input (); |
05c8abbe GM |
750 | |
751 | update_face_from_frame_parameter (f, Qmouse_color, arg); | |
01f1ba30 JB |
752 | } |
753 | ||
e4cebfca | 754 | static void |
971de7fb | 755 | x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
01f1ba30 | 756 | { |
a76206dc | 757 | unsigned long fore_pixel, pixel; |
d7e6881a | 758 | bool fore_pixel_allocated_p = 0, pixel_allocated_p = 0; |
09393d07 | 759 | struct x_output *x = f->output_data.x; |
01f1ba30 | 760 | |
10168ebb GM |
761 | if (!NILP (Vx_cursor_fore_pixel)) |
762 | { | |
763 | fore_pixel = x_decode_color (f, Vx_cursor_fore_pixel, | |
764 | WHITE_PIX_DEFAULT (f)); | |
765 | fore_pixel_allocated_p = 1; | |
766 | } | |
01f1ba30 | 767 | else |
ce593f6e | 768 | fore_pixel = FRAME_BACKGROUND_PIXEL (f); |
177c0ea7 | 769 | |
a76206dc | 770 | pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); |
10168ebb | 771 | pixel_allocated_p = 1; |
a76206dc | 772 | |
f9942c9e | 773 | /* Make sure that the cursor color differs from the background color. */ |
ce593f6e | 774 | if (pixel == FRAME_BACKGROUND_PIXEL (f)) |
01f1ba30 | 775 | { |
10168ebb GM |
776 | if (pixel_allocated_p) |
777 | { | |
778 | x_free_colors (f, &pixel, 1); | |
779 | pixel_allocated_p = 0; | |
780 | } | |
177c0ea7 | 781 | |
09393d07 | 782 | pixel = x->mouse_pixel; |
a76206dc | 783 | if (pixel == fore_pixel) |
10168ebb GM |
784 | { |
785 | if (fore_pixel_allocated_p) | |
786 | { | |
787 | x_free_colors (f, &fore_pixel, 1); | |
788 | fore_pixel_allocated_p = 0; | |
789 | } | |
ce593f6e | 790 | fore_pixel = FRAME_BACKGROUND_PIXEL (f); |
10168ebb | 791 | } |
01f1ba30 | 792 | } |
a76206dc | 793 | |
09393d07 | 794 | unload_color (f, x->cursor_foreground_pixel); |
10168ebb GM |
795 | if (!fore_pixel_allocated_p) |
796 | fore_pixel = x_copy_color (f, fore_pixel); | |
09393d07 | 797 | x->cursor_foreground_pixel = fore_pixel; |
01f1ba30 | 798 | |
09393d07 | 799 | unload_color (f, x->cursor_pixel); |
10168ebb GM |
800 | if (!pixel_allocated_p) |
801 | pixel = x_copy_color (f, pixel); | |
09393d07 | 802 | x->cursor_pixel = pixel; |
a76206dc | 803 | |
fe24a618 | 804 | if (FRAME_X_WINDOW (f) != 0) |
01f1ba30 | 805 | { |
4d7e6e51 | 806 | block_input (); |
09393d07 GM |
807 | XSetBackground (FRAME_X_DISPLAY (f), x->cursor_gc, x->cursor_pixel); |
808 | XSetForeground (FRAME_X_DISPLAY (f), x->cursor_gc, fore_pixel); | |
4d7e6e51 | 809 | unblock_input (); |
01f1ba30 | 810 | |
179956b9 | 811 | if (FRAME_VISIBLE_P (f)) |
01f1ba30 | 812 | { |
cedadcfa RS |
813 | x_update_cursor (f, 0); |
814 | x_update_cursor (f, 1); | |
01f1ba30 JB |
815 | } |
816 | } | |
05c8abbe GM |
817 | |
818 | update_face_from_frame_parameter (f, Qcursor_color, arg); | |
01f1ba30 | 819 | } |
943b580d | 820 | \f |
f676886a | 821 | /* Set the border-color of frame F to pixel value PIX. |
01f1ba30 | 822 | Note that this does not fully take effect if done before |
f676886a | 823 | F has an x-window. */ |
01f1ba30 | 824 | |
e4cebfca | 825 | static void |
971de7fb | 826 | x_set_border_pixel (struct frame *f, int pix) |
01f1ba30 | 827 | { |
a76206dc | 828 | unload_color (f, f->output_data.x->border_pixel); |
7556890b | 829 | f->output_data.x->border_pixel = pix; |
01f1ba30 | 830 | |
be786000 | 831 | if (FRAME_X_WINDOW (f) != 0 && f->border_width > 0) |
01f1ba30 | 832 | { |
4d7e6e51 | 833 | block_input (); |
578c21e6 | 834 | XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), pix); |
4d7e6e51 | 835 | unblock_input (); |
01f1ba30 | 836 | |
179956b9 | 837 | if (FRAME_VISIBLE_P (f)) |
f676886a | 838 | redraw_frame (f); |
01f1ba30 JB |
839 | } |
840 | } | |
841 | ||
7c0d3ed8 KS |
842 | /* Set the border-color of frame F to value described by ARG. |
843 | ARG can be a string naming a color. | |
844 | The border-color is used for the border that is drawn by the X server. | |
845 | Note that this does not fully take effect if done before | |
846 | F has an x-window; it must be redone when the window is created. | |
847 | ||
848 | Note: this is done in two routines because of the way X10 works. | |
849 | ||
850 | Note: under X11, this is normally the province of the window manager, | |
5ec0337a | 851 | and so emacs's border colors may be overridden. */ |
7c0d3ed8 | 852 | |
e4cebfca | 853 | static void |
971de7fb | 854 | x_set_border_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
7c0d3ed8 KS |
855 | { |
856 | int pix; | |
857 | ||
858 | CHECK_STRING (arg); | |
859 | pix = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f)); | |
860 | x_set_border_pixel (f, pix); | |
861 | update_face_from_frame_parameter (f, Qborder_color, arg); | |
862 | } | |
0d1469d6 | 863 | |
0d1469d6 | 864 | |
e4cebfca | 865 | static void |
a10c8269 | 866 | x_set_cursor_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
0d1469d6 | 867 | { |
33b2311e | 868 | set_frame_cursor_types (f, arg); |
dbc4e1c1 | 869 | } |
9cda66e4 | 870 | |
e4cebfca | 871 | static void |
971de7fb | 872 | x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
01f1ba30 | 873 | { |
01f1ba30 JB |
874 | int result; |
875 | ||
203c1d73 RS |
876 | if (STRINGP (arg)) |
877 | { | |
878 | if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt)) | |
879 | return; | |
880 | } | |
881 | else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil)) | |
01f1ba30 JB |
882 | return; |
883 | ||
4d7e6e51 | 884 | block_input (); |
265a9e55 | 885 | if (NILP (arg)) |
80534dd6 | 886 | result = x_text_icon (f, |
e69b0960 DA |
887 | SSDATA ((!NILP (f->icon_name) |
888 | ? f->icon_name | |
889 | : f->name))); | |
f1c7b5a6 RS |
890 | else |
891 | result = x_bitmap_icon (f, arg); | |
01f1ba30 JB |
892 | |
893 | if (result) | |
894 | { | |
4d7e6e51 | 895 | unblock_input (); |
0fb53770 | 896 | error ("No icon window available"); |
01f1ba30 JB |
897 | } |
898 | ||
b9dc4443 | 899 | XFlush (FRAME_X_DISPLAY (f)); |
4d7e6e51 | 900 | unblock_input (); |
01f1ba30 JB |
901 | } |
902 | ||
e4cebfca | 903 | static void |
971de7fb | 904 | x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
80534dd6 | 905 | { |
80534dd6 KH |
906 | int result; |
907 | ||
908 | if (STRINGP (arg)) | |
909 | { | |
910 | if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt)) | |
911 | return; | |
912 | } | |
56f41f98 | 913 | else if (!NILP (arg) || NILP (oldval)) |
80534dd6 KH |
914 | return; |
915 | ||
f00af5b1 | 916 | fset_icon_name (f, arg); |
80534dd6 | 917 | |
7556890b | 918 | if (f->output_data.x->icon_bitmap != 0) |
80534dd6 KH |
919 | return; |
920 | ||
4d7e6e51 | 921 | block_input (); |
80534dd6 KH |
922 | |
923 | result = x_text_icon (f, | |
e69b0960 DA |
924 | SSDATA ((!NILP (f->icon_name) |
925 | ? f->icon_name | |
926 | : !NILP (f->title) | |
927 | ? f->title | |
928 | : f->name))); | |
80534dd6 KH |
929 | |
930 | if (result) | |
931 | { | |
4d7e6e51 | 932 | unblock_input (); |
80534dd6 KH |
933 | error ("No icon window available"); |
934 | } | |
935 | ||
80534dd6 | 936 | XFlush (FRAME_X_DISPLAY (f)); |
4d7e6e51 | 937 | unblock_input (); |
80534dd6 | 938 | } |
7c0d3ed8 | 939 | |
943b580d | 940 | \f |
01f1ba30 | 941 | void |
971de7fb | 942 | x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) |
01f1ba30 | 943 | { |
7c0d3ed8 | 944 | int nlines; |
6b61353c | 945 | #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK) |
7c0d3ed8 KS |
946 | int olines = FRAME_MENU_BAR_LINES (f); |
947 | #endif | |
177c0ea7 | 948 | |
7c0d3ed8 KS |
949 | /* Right now, menu bars don't work properly in minibuf-only frames; |
950 | most of the commands try to apply themselves to the minibuffer | |
951 | frame itself, and get an error because you can't switch buffers | |
952 | in or split the minibuffer window. */ | |
953 | if (FRAME_MINIBUF_ONLY_P (f)) | |
954 | return; | |
177c0ea7 | 955 | |
d311d28c | 956 | if (TYPE_RANGED_INTEGERP (int, value)) |
7c0d3ed8 | 957 | nlines = XINT (value); |
ea96210c | 958 | else |
7c0d3ed8 | 959 | nlines = 0; |
a367641f | 960 | |
7c0d3ed8 KS |
961 | /* Make sure we redisplay all windows in this frame. */ |
962 | windows_or_buffers_changed++; | |
3d09b6be | 963 | |
488dd4c4 | 964 | #if defined (USE_X_TOOLKIT) || defined (USE_GTK) |
9ef48a9d RS |
965 | FRAME_MENU_BAR_LINES (f) = 0; |
966 | if (nlines) | |
0d8ef3f4 RS |
967 | { |
968 | FRAME_EXTERNAL_MENU_BAR (f) = 1; | |
97a1ff91 | 969 | if (FRAME_X_P (f) && f->output_data.x->menubar_widget == 0) |
0d8ef3f4 | 970 | /* Make sure next redisplay shows the menu bar. */ |
c98ff5dd | 971 | XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = 1; |
0d8ef3f4 | 972 | } |
9ef48a9d RS |
973 | else |
974 | { | |
6bc20398 FP |
975 | if (FRAME_EXTERNAL_MENU_BAR (f) == 1) |
976 | free_frame_menubar (f); | |
9ef48a9d | 977 | FRAME_EXTERNAL_MENU_BAR (f) = 0; |
97a1ff91 RS |
978 | if (FRAME_X_P (f)) |
979 | f->output_data.x->menubar_widget = 0; | |
9ef48a9d | 980 | } |
488dd4c4 | 981 | #else /* not USE_X_TOOLKIT && not USE_GTK */ |
d043f1a4 | 982 | FRAME_MENU_BAR_LINES (f) = nlines; |
562dd5e9 | 983 | resize_frame_windows (f, FRAME_LINES (f), 0); |
1df47e38 YM |
984 | |
985 | /* If the menu bar height gets changed, the internal border below | |
986 | the top margin has to be cleared. Also, if the menu bar gets | |
987 | larger, the area for the added lines has to be cleared except for | |
988 | the first menu bar line that is to be drawn later. */ | |
989 | if (nlines != olines) | |
990 | { | |
991 | int height = FRAME_INTERNAL_BORDER_WIDTH (f); | |
992 | int width = FRAME_PIXEL_WIDTH (f); | |
993 | int y; | |
994 | ||
995 | /* height can be zero here. */ | |
996 | if (height > 0 && width > 0) | |
997 | { | |
998 | y = FRAME_TOP_MARGIN_HEIGHT (f); | |
999 | ||
4d7e6e51 | 1000 | block_input (); |
1df47e38 | 1001 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
1f5cf200 | 1002 | 0, y, width, height); |
4d7e6e51 | 1003 | unblock_input (); |
1df47e38 YM |
1004 | } |
1005 | ||
1006 | if (nlines > 1 && nlines > olines) | |
1007 | { | |
1008 | y = (olines == 0 ? 1 : olines) * FRAME_LINE_HEIGHT (f); | |
1009 | height = nlines * FRAME_LINE_HEIGHT (f) - y; | |
1010 | ||
4d7e6e51 | 1011 | block_input (); |
1df47e38 | 1012 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
1f5cf200 | 1013 | 0, y, width, height); |
4d7e6e51 | 1014 | unblock_input (); |
1df47e38 YM |
1015 | } |
1016 | ||
e69b0960 DA |
1017 | if (nlines == 0 && WINDOWP (f->menu_bar_window)) |
1018 | clear_glyph_matrix (XWINDOW (f->menu_bar_window)->current_matrix); | |
1df47e38 YM |
1019 | } |
1020 | #endif /* not USE_X_TOOLKIT && not USE_GTK */ | |
bd0443bb | 1021 | adjust_frame_glyphs (f); |
562dd5e9 | 1022 | run_window_configuration_change_hook (f); |
333b20bb GM |
1023 | } |
1024 | ||
1025 | ||
1026 | /* Set the number of lines used for the tool bar of frame F to VALUE. | |
1027 | VALUE not an integer, or < 0 means set the lines to zero. OLDVAL | |
1028 | is the old number of tool bar lines. This function changes the | |
1029 | height of all windows on frame F to match the new tool bar height. | |
1030 | The frame's height doesn't change. */ | |
1031 | ||
1032 | void | |
971de7fb | 1033 | x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) |
333b20bb | 1034 | { |
742516e0 DA |
1035 | int nlines; |
1036 | #if ! defined (USE_GTK) | |
1037 | int delta, root_height; | |
52de7ce9 | 1038 | Lisp_Object root_window; |
742516e0 | 1039 | #endif |
333b20bb | 1040 | |
e870b7ba GM |
1041 | /* Treat tool bars like menu bars. */ |
1042 | if (FRAME_MINIBUF_ONLY_P (f)) | |
1043 | return; | |
1044 | ||
d311d28c PE |
1045 | /* Use VALUE only if an int >= 0. */ |
1046 | if (RANGED_INTEGERP (0, value, INT_MAX)) | |
333b20bb GM |
1047 | nlines = XFASTINT (value); |
1048 | else | |
1049 | nlines = 0; | |
1050 | ||
488dd4c4 | 1051 | #ifdef USE_GTK |
742516e0 | 1052 | |
488dd4c4 JD |
1053 | FRAME_TOOL_BAR_LINES (f) = 0; |
1054 | if (nlines) | |
1055 | { | |
1056 | FRAME_EXTERNAL_TOOL_BAR (f) = 1; | |
1057 | if (FRAME_X_P (f) && f->output_data.x->toolbar_widget == 0) | |
1058 | /* Make sure next redisplay shows the tool bar. */ | |
5fceba1d | 1059 | XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = 1; |
488dd4c4 JD |
1060 | update_frame_tool_bar (f); |
1061 | } | |
1062 | else | |
1063 | { | |
1064 | if (FRAME_EXTERNAL_TOOL_BAR (f)) | |
1065 | free_frame_tool_bar (f); | |
1066 | FRAME_EXTERNAL_TOOL_BAR (f) = 0; | |
1067 | } | |
1068 | ||
742516e0 | 1069 | #else /* !USE_GTK */ |
177c0ea7 | 1070 | |
488dd4c4 | 1071 | /* Make sure we redisplay all windows in this frame. */ |
333b20bb GM |
1072 | ++windows_or_buffers_changed; |
1073 | ||
9ea173e8 | 1074 | delta = nlines - FRAME_TOOL_BAR_LINES (f); |
52de7ce9 GM |
1075 | |
1076 | /* Don't resize the tool-bar to more than we have room for. */ | |
1077 | root_window = FRAME_ROOT_WINDOW (f); | |
be786000 | 1078 | root_height = WINDOW_TOTAL_LINES (XWINDOW (root_window)); |
52de7ce9 GM |
1079 | if (root_height - delta < 1) |
1080 | { | |
1081 | delta = root_height - 1; | |
1082 | nlines = FRAME_TOOL_BAR_LINES (f) + delta; | |
1083 | } | |
1084 | ||
9ea173e8 | 1085 | FRAME_TOOL_BAR_LINES (f) = nlines; |
562dd5e9 | 1086 | resize_frame_windows (f, FRAME_LINES (f), 0); |
bd0443bb | 1087 | adjust_frame_glyphs (f); |
177c0ea7 | 1088 | |
ccba751c GM |
1089 | /* We also have to make sure that the internal border at the top of |
1090 | the frame, below the menu bar or tool bar, is redrawn when the | |
1091 | tool bar disappears. This is so because the internal border is | |
1092 | below the tool bar if one is displayed, but is below the menu bar | |
1093 | if there isn't a tool bar. The tool bar draws into the area | |
1094 | below the menu bar. */ | |
1095 | if (FRAME_X_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0) | |
1096 | { | |
385ed61f | 1097 | clear_frame (f); |
fb3cd89b | 1098 | clear_current_matrices (f); |
ccba751c | 1099 | } |
b6f91066 GM |
1100 | |
1101 | /* If the tool bar gets smaller, the internal border below it | |
1102 | has to be cleared. It was formerly part of the display | |
1103 | of the larger tool bar, and updating windows won't clear it. */ | |
1104 | if (delta < 0) | |
1105 | { | |
1106 | int height = FRAME_INTERNAL_BORDER_WIDTH (f); | |
be786000 | 1107 | int width = FRAME_PIXEL_WIDTH (f); |
4b00d3b1 | 1108 | int y = (FRAME_MENU_BAR_LINES (f) + nlines) * FRAME_LINE_HEIGHT (f); |
b6f91066 | 1109 | |
caacfeb8 JD |
1110 | /* height can be zero here. */ |
1111 | if (height > 0 && width > 0) | |
1112 | { | |
4d7e6e51 | 1113 | block_input (); |
1f5cf200 DA |
1114 | x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
1115 | 0, y, width, height); | |
4d7e6e51 | 1116 | unblock_input (); |
caacfeb8 | 1117 | } |
ddc24747 | 1118 | |
e69b0960 DA |
1119 | if (WINDOWP (f->tool_bar_window)) |
1120 | clear_glyph_matrix (XWINDOW (f->tool_bar_window)->current_matrix); | |
b6f91066 | 1121 | } |
562dd5e9 MR |
1122 | |
1123 | run_window_configuration_change_hook (f); | |
742516e0 | 1124 | #endif /* USE_GTK */ |
333b20bb GM |
1125 | } |
1126 | ||
1127 | ||
1128 | /* Set the foreground color for scroll bars on frame F to VALUE. | |
1129 | VALUE should be a string, a color name. If it isn't a string or | |
1130 | isn't a valid color name, do nothing. OLDVAL is the old value of | |
1131 | the frame parameter. */ | |
1132 | ||
e4cebfca | 1133 | static void |
971de7fb | 1134 | x_set_scroll_bar_foreground (struct frame *f, Lisp_Object value, Lisp_Object oldval) |
333b20bb GM |
1135 | { |
1136 | unsigned long pixel; | |
177c0ea7 | 1137 | |
333b20bb GM |
1138 | if (STRINGP (value)) |
1139 | pixel = x_decode_color (f, value, BLACK_PIX_DEFAULT (f)); | |
1140 | else | |
1141 | pixel = -1; | |
1142 | ||
1143 | if (f->output_data.x->scroll_bar_foreground_pixel != -1) | |
1144 | unload_color (f, f->output_data.x->scroll_bar_foreground_pixel); | |
177c0ea7 | 1145 | |
333b20bb GM |
1146 | f->output_data.x->scroll_bar_foreground_pixel = pixel; |
1147 | if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f)) | |
1148 | { | |
1149 | /* Remove all scroll bars because they have wrong colors. */ | |
6ed8eeff KL |
1150 | if (FRAME_TERMINAL (f)->condemn_scroll_bars_hook) |
1151 | (*FRAME_TERMINAL (f)->condemn_scroll_bars_hook) (f); | |
1152 | if (FRAME_TERMINAL (f)->judge_scroll_bars_hook) | |
1153 | (*FRAME_TERMINAL (f)->judge_scroll_bars_hook) (f); | |
05c8abbe GM |
1154 | |
1155 | update_face_from_frame_parameter (f, Qscroll_bar_foreground, value); | |
333b20bb GM |
1156 | redraw_frame (f); |
1157 | } | |
1158 | } | |
1159 | ||
1160 | ||
1161 | /* Set the background color for scroll bars on frame F to VALUE VALUE | |
1162 | should be a string, a color name. If it isn't a string or isn't a | |
1163 | valid color name, do nothing. OLDVAL is the old value of the frame | |
1164 | parameter. */ | |
1165 | ||
e4cebfca | 1166 | static void |
971de7fb | 1167 | x_set_scroll_bar_background (struct frame *f, Lisp_Object value, Lisp_Object oldval) |
333b20bb GM |
1168 | { |
1169 | unsigned long pixel; | |
1170 | ||
1171 | if (STRINGP (value)) | |
1172 | pixel = x_decode_color (f, value, WHITE_PIX_DEFAULT (f)); | |
1173 | else | |
1174 | pixel = -1; | |
177c0ea7 | 1175 | |
333b20bb GM |
1176 | if (f->output_data.x->scroll_bar_background_pixel != -1) |
1177 | unload_color (f, f->output_data.x->scroll_bar_background_pixel); | |
177c0ea7 | 1178 | |
f15340b7 MB |
1179 | #ifdef USE_TOOLKIT_SCROLL_BARS |
1180 | /* Scrollbar shadow colors. */ | |
1181 | if (f->output_data.x->scroll_bar_top_shadow_pixel != -1) | |
1182 | { | |
1183 | unload_color (f, f->output_data.x->scroll_bar_top_shadow_pixel); | |
1184 | f->output_data.x->scroll_bar_top_shadow_pixel = -1; | |
1185 | } | |
1186 | if (f->output_data.x->scroll_bar_bottom_shadow_pixel != -1) | |
1187 | { | |
1188 | unload_color (f, f->output_data.x->scroll_bar_bottom_shadow_pixel); | |
1189 | f->output_data.x->scroll_bar_bottom_shadow_pixel = -1; | |
1190 | } | |
1191 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | |
1192 | ||
333b20bb GM |
1193 | f->output_data.x->scroll_bar_background_pixel = pixel; |
1194 | if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f)) | |
1195 | { | |
1196 | /* Remove all scroll bars because they have wrong colors. */ | |
6ed8eeff KL |
1197 | if (FRAME_TERMINAL (f)->condemn_scroll_bars_hook) |
1198 | (*FRAME_TERMINAL (f)->condemn_scroll_bars_hook) (f); | |
1199 | if (FRAME_TERMINAL (f)->judge_scroll_bars_hook) | |
1200 | (*FRAME_TERMINAL (f)->judge_scroll_bars_hook) (f); | |
177c0ea7 | 1201 | |
05c8abbe | 1202 | update_face_from_frame_parameter (f, Qscroll_bar_background, value); |
333b20bb GM |
1203 | redraw_frame (f); |
1204 | } | |
d043f1a4 | 1205 | } |
333b20bb | 1206 | |
943b580d | 1207 | \f |
3a258507 | 1208 | /* Encode Lisp string STRING as a text in a format appropriate for |
96db09e4 KH |
1209 | XICCC (X Inter Client Communication Conventions). |
1210 | ||
6f103132 RS |
1211 | This can call Lisp code, so callers must GCPRO. |
1212 | ||
96db09e4 KH |
1213 | If STRING contains only ASCII characters, do no conversion and |
1214 | return the string data of STRING. Otherwise, encode the text by | |
1215 | CODING_SYSTEM, and return a newly allocated memory area which | |
1216 | should be freed by `xfree' by a caller. | |
1217 | ||
37323f34 EZ |
1218 | SELECTIONP non-zero means the string is being encoded for an X |
1219 | selection, so it is safe to run pre-write conversions (which | |
1220 | may run Lisp code). | |
1221 | ||
96db09e4 KH |
1222 | Store the byte length of resulting text in *TEXT_BYTES. |
1223 | ||
d60660d6 | 1224 | If the text contains only ASCII and Latin-1, store 1 in *STRING_P, |
96db09e4 | 1225 | which means that the `encoding' of the result can be `STRING'. |
d60660d6 | 1226 | Otherwise store 0 in *STRINGP, which means that the `encoding' of |
96db09e4 KH |
1227 | the result should be `COMPOUND_TEXT'. */ |
1228 | ||
df630496 | 1229 | static unsigned char * |
c678c835 PE |
1230 | x_encode_text (Lisp_Object string, Lisp_Object coding_system, int selectionp, |
1231 | ptrdiff_t *text_bytes, int *stringp, int *freep) | |
96db09e4 | 1232 | { |
0f8c4c4f | 1233 | int result = string_xstring_p (string); |
96db09e4 KH |
1234 | struct coding_system coding; |
1235 | ||
0f8c4c4f | 1236 | if (result == 0) |
96db09e4 KH |
1237 | { |
1238 | /* No multibyte character in OBJ. We need not encode it. */ | |
8f924df7 | 1239 | *text_bytes = SBYTES (string); |
d60660d6 | 1240 | *stringp = 1; |
df630496 | 1241 | *freep = 0; |
8f924df7 | 1242 | return SDATA (string); |
96db09e4 KH |
1243 | } |
1244 | ||
1245 | setup_coding_system (coding_system, &coding); | |
0f8c4c4f | 1246 | coding.mode |= (CODING_MODE_SAFE_ENCODING | CODING_MODE_LAST_BLOCK); |
35bc5887 | 1247 | /* We suppress producing escape sequences for composition. */ |
0f8c4c4f | 1248 | coding.common_flags &= ~CODING_ANNOTATION_MASK; |
0065d054 | 1249 | coding.destination = xnmalloc (SCHARS (string), 2); |
8f924df7 | 1250 | coding.dst_bytes = SCHARS (string) * 2; |
0f8c4c4f | 1251 | encode_coding_object (&coding, string, 0, 0, |
8f924df7 | 1252 | SCHARS (string), SBYTES (string), Qnil); |
96db09e4 | 1253 | *text_bytes = coding.produced; |
0f8c4c4f | 1254 | *stringp = (result == 1 || !EQ (coding_system, Qcompound_text)); |
df630496 | 1255 | *freep = 1; |
b954d586 | 1256 | return coding.destination; |
96db09e4 KH |
1257 | } |
1258 | ||
1259 | \f | |
b10daec7 JD |
1260 | /* Set the WM name to NAME for frame F. Also set the icon name. |
1261 | If the frame already has an icon name, use that, otherwise set the | |
1262 | icon name to NAME. */ | |
f945b920 | 1263 | |
b10daec7 | 1264 | static void |
a10c8269 | 1265 | x_set_name_internal (struct frame *f, Lisp_Object name) |
f945b920 | 1266 | { |
fe24a618 | 1267 | if (FRAME_X_WINDOW (f)) |
01f1ba30 | 1268 | { |
4d7e6e51 | 1269 | block_input (); |
fe24a618 | 1270 | { |
80534dd6 | 1271 | XTextProperty text, icon; |
c678c835 PE |
1272 | ptrdiff_t bytes; |
1273 | int stringp; | |
b10daec7 | 1274 | int do_free_icon_value = 0, do_free_text_value = 0; |
11270583 | 1275 | Lisp_Object coding_system; |
c2915ced | 1276 | Lisp_Object encoded_name; |
00be444c | 1277 | Lisp_Object encoded_icon_name; |
c2915ced CY |
1278 | struct gcpro gcpro1; |
1279 | ||
1280 | /* As ENCODE_UTF_8 may cause GC and relocation of string data, | |
1281 | we use it before x_encode_text that may return string data. */ | |
1282 | GCPRO1 (name); | |
1283 | encoded_name = ENCODE_UTF_8 (name); | |
1284 | UNGCPRO; | |
80534dd6 | 1285 | |
b10daec7 | 1286 | coding_system = Qcompound_text; |
3201ea57 KH |
1287 | /* Note: Encoding strategy |
1288 | ||
1289 | We encode NAME by compound-text and use "COMPOUND-TEXT" in | |
1290 | text.encoding. But, there are non-internationalized window | |
1291 | managers which don't support that encoding. So, if NAME | |
1292 | contains only ASCII and 8859-1 characters, encode it by | |
1293 | iso-latin-1, and use "STRING" in text.encoding hoping that | |
34e8c597 | 1294 | such window managers at least analyze this format correctly, |
3201ea57 KH |
1295 | i.e. treat 8-bit bytes as 8859-1 characters. |
1296 | ||
1297 | We may also be able to use "UTF8_STRING" in text.encoding | |
34e8c597 | 1298 | in the future which can encode all Unicode characters. |
3201ea57 | 1299 | But, for the moment, there's no way to know that the |
00be444c J |
1300 | current window manager supports it or not. |
1301 | ||
1302 | Either way, we also set the _NET_WM_NAME and _NET_WM_ICON_NAME | |
1303 | properties. Per the EWMH specification, those two properties | |
1304 | are always UTF8_STRING. This matches what gtk_window_set_title() | |
1305 | does in the USE_GTK case. */ | |
df630496 KS |
1306 | text.value = x_encode_text (name, coding_system, 0, &bytes, &stringp, |
1307 | &do_free_text_value); | |
d60660d6 | 1308 | text.encoding = (stringp ? XA_STRING |
aad3612f | 1309 | : FRAME_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT); |
fe24a618 | 1310 | text.format = 8; |
96db09e4 | 1311 | text.nitems = bytes; |
c678c835 PE |
1312 | if (text.nitems != bytes) |
1313 | error ("Window name too large"); | |
80534dd6 | 1314 | |
e69b0960 | 1315 | if (!STRINGP (f->icon_name)) |
96db09e4 KH |
1316 | { |
1317 | icon = text; | |
00be444c | 1318 | encoded_icon_name = encoded_name; |
96db09e4 KH |
1319 | } |
1320 | else | |
1321 | { | |
3201ea57 | 1322 | /* See the above comment "Note: Encoding strategy". */ |
e69b0960 | 1323 | icon.value = x_encode_text (f->icon_name, coding_system, 0, |
df630496 | 1324 | &bytes, &stringp, &do_free_icon_value); |
d60660d6 | 1325 | icon.encoding = (stringp ? XA_STRING |
aad3612f | 1326 | : FRAME_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT); |
96db09e4 KH |
1327 | icon.format = 8; |
1328 | icon.nitems = bytes; | |
c678c835 PE |
1329 | if (icon.nitems != bytes) |
1330 | error ("Icon name too large"); | |
00be444c | 1331 | |
e69b0960 | 1332 | encoded_icon_name = ENCODE_UTF_8 (f->icon_name); |
96db09e4 | 1333 | } |
b10daec7 | 1334 | |
488dd4c4 JD |
1335 | #ifdef USE_GTK |
1336 | gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), | |
51b59d79 | 1337 | SSDATA (encoded_name)); |
488dd4c4 | 1338 | #else /* not USE_GTK */ |
2436a4e4 | 1339 | XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text); |
00be444c | 1340 | XChangeProperty (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), |
aad3612f DA |
1341 | FRAME_DISPLAY_INFO (f)->Xatom_net_wm_name, |
1342 | FRAME_DISPLAY_INFO (f)->Xatom_UTF8_STRING, | |
00be444c | 1343 | 8, PropModeReplace, |
42a5b22f | 1344 | SDATA (encoded_name), |
00be444c | 1345 | SBYTES (encoded_name)); |
7c0d3ed8 | 1346 | #endif /* not USE_GTK */ |
abb4b7ec | 1347 | |
7c0d3ed8 | 1348 | XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &icon); |
00be444c | 1349 | XChangeProperty (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), |
aad3612f DA |
1350 | FRAME_DISPLAY_INFO (f)->Xatom_net_wm_icon_name, |
1351 | FRAME_DISPLAY_INFO (f)->Xatom_UTF8_STRING, | |
00be444c | 1352 | 8, PropModeReplace, |
42a5b22f | 1353 | SDATA (encoded_icon_name), |
00be444c | 1354 | SBYTES (encoded_icon_name)); |
abb4b7ec | 1355 | |
b10daec7 | 1356 | if (do_free_icon_value) |
7c0d3ed8 | 1357 | xfree (icon.value); |
b10daec7 | 1358 | if (do_free_text_value) |
7c0d3ed8 KS |
1359 | xfree (text.value); |
1360 | } | |
4d7e6e51 | 1361 | unblock_input (); |
7c0d3ed8 | 1362 | } |
abb4b7ec RS |
1363 | } |
1364 | ||
b10daec7 JD |
1365 | /* Change the name of frame F to NAME. If NAME is nil, set F's name to |
1366 | x_id_name. | |
1367 | ||
1368 | If EXPLICIT is non-zero, that indicates that lisp code is setting the | |
1369 | name; if NAME is a string, set F's name to NAME and set | |
1370 | F->explicit_name; if NAME is Qnil, then clear F->explicit_name. | |
1371 | ||
1372 | If EXPLICIT is zero, that indicates that Emacs redisplay code is | |
1373 | suggesting a new name, which lisp code should override; if | |
1374 | F->explicit_name is set, ignore the new name; otherwise, set it. */ | |
1375 | ||
f78faa98 | 1376 | static void |
971de7fb | 1377 | x_set_name (struct frame *f, Lisp_Object name, int explicit) |
b10daec7 JD |
1378 | { |
1379 | /* Make sure that requests from lisp code override requests from | |
1380 | Emacs redisplay code. */ | |
1381 | if (explicit) | |
1382 | { | |
1383 | /* If we're switching from explicit to implicit, we had better | |
1384 | update the mode lines and thereby update the title. */ | |
1385 | if (f->explicit_name && NILP (name)) | |
1386 | update_mode_lines = 1; | |
1387 | ||
1388 | f->explicit_name = ! NILP (name); | |
1389 | } | |
1390 | else if (f->explicit_name) | |
1391 | return; | |
1392 | ||
1393 | /* If NAME is nil, set the name to the x_id_name. */ | |
1394 | if (NILP (name)) | |
1395 | { | |
1396 | /* Check for no change needed in this very common case | |
1397 | before we do any consing. */ | |
aad3612f | 1398 | if (!strcmp (FRAME_DISPLAY_INFO (f)->x_id_name, |
e69b0960 | 1399 | SSDATA (f->name))) |
b10daec7 | 1400 | return; |
aad3612f | 1401 | name = build_string (FRAME_DISPLAY_INFO (f)->x_id_name); |
b10daec7 JD |
1402 | } |
1403 | else | |
1404 | CHECK_STRING (name); | |
1405 | ||
1406 | /* Don't change the name if it's already NAME. */ | |
e69b0960 | 1407 | if (! NILP (Fstring_equal (name, f->name))) |
b10daec7 JD |
1408 | return; |
1409 | ||
f00af5b1 | 1410 | fset_name (f, name); |
b10daec7 JD |
1411 | |
1412 | /* For setting the frame title, the title parameter should override | |
1413 | the name parameter. */ | |
e69b0960 DA |
1414 | if (! NILP (f->title)) |
1415 | name = f->title; | |
b10daec7 JD |
1416 | |
1417 | x_set_name_internal (f, name); | |
1418 | } | |
1419 | ||
7c0d3ed8 KS |
1420 | /* This function should be called when the user's lisp code has |
1421 | specified a name for the frame; the name will override any set by the | |
1422 | redisplay code. */ | |
e4cebfca | 1423 | static void |
a10c8269 | 1424 | x_explicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
3402e1a4 | 1425 | { |
7c0d3ed8 | 1426 | x_set_name (f, arg, 1); |
3402e1a4 RS |
1427 | } |
1428 | ||
7c0d3ed8 KS |
1429 | /* This function should be called by Emacs redisplay code to set the |
1430 | name; names set this way will never override names set by the user's | |
1431 | lisp code. */ | |
1432 | void | |
a10c8269 | 1433 | x_implicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval) |
333b20bb | 1434 | { |
7c0d3ed8 KS |
1435 | x_set_name (f, arg, 0); |
1436 | } | |
1437 | \f | |
1438 | /* Change the title of frame F to NAME. | |
40aa4c27 | 1439 | If NAME is nil, use the frame name as the title. */ |
01f1ba30 | 1440 | |
e4cebfca | 1441 | static void |
971de7fb | 1442 | x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name) |
01f1ba30 | 1443 | { |
7c0d3ed8 | 1444 | /* Don't change the title if it's already NAME. */ |
e69b0960 | 1445 | if (EQ (name, f->title)) |
7c0d3ed8 | 1446 | return; |
01f1ba30 | 1447 | |
7c0d3ed8 | 1448 | update_mode_lines = 1; |
60fb3ee1 | 1449 | |
f00af5b1 | 1450 | fset_title (f, name); |
f9942c9e | 1451 | |
7c0d3ed8 | 1452 | if (NILP (name)) |
e69b0960 | 1453 | name = f->name; |
7c0d3ed8 KS |
1454 | else |
1455 | CHECK_STRING (name); | |
f9942c9e | 1456 | |
b10daec7 | 1457 | x_set_name_internal (f, name); |
01f1ba30 JB |
1458 | } |
1459 | ||
7c0d3ed8 | 1460 | void |
971de7fb | 1461 | x_set_scroll_bar_default_width (struct frame *f) |
e4f79258 | 1462 | { |
be786000 | 1463 | int wid = FRAME_COLUMN_WIDTH (f); |
7c0d3ed8 | 1464 | #ifdef USE_TOOLKIT_SCROLL_BARS |
a059fe24 | 1465 | #ifdef USE_GTK |
c195f2de | 1466 | int minw = xg_get_default_scrollbar_width (); |
4a1b9832 PE |
1467 | #else |
1468 | int minw = 16; | |
a059fe24 | 1469 | #endif |
7c0d3ed8 | 1470 | /* A minimum width of 14 doesn't look good for toolkit scroll bars. */ |
0eed0355 DA |
1471 | FRAME_CONFIG_SCROLL_BAR_COLS (f) = (minw + wid - 1) / wid; |
1472 | FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = minw; | |
7c0d3ed8 KS |
1473 | #else |
1474 | /* Make the actual width at least 14 pixels and a multiple of a | |
1475 | character width. */ | |
be786000 | 1476 | FRAME_CONFIG_SCROLL_BAR_COLS (f) = (14 + wid - 1) / wid; |
01f1ba30 | 1477 | |
7c0d3ed8 KS |
1478 | /* Use all of that space (aside from required margins) for the |
1479 | scroll bar. */ | |
be786000 | 1480 | FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = 0; |
7c0d3ed8 | 1481 | #endif |
01f1ba30 | 1482 | } |
333b20bb | 1483 | |
7c0d3ed8 | 1484 | \f |
333b20bb GM |
1485 | /* Record in frame F the specified or default value according to ALIST |
1486 | of the parameter named PROP (a Lisp symbol). If no value is | |
1487 | specified for PROP, look for an X default for XPROP on the frame | |
1488 | named NAME. If that is not found either, use the value DEFLT. */ | |
1489 | ||
1490 | static Lisp_Object | |
d5a3eaaf AS |
1491 | x_default_scroll_bar_color_parameter (struct frame *f, |
1492 | Lisp_Object alist, Lisp_Object prop, | |
675e2c69 | 1493 | const char *xprop, const char *xclass, |
d5a3eaaf | 1494 | int foreground_p) |
333b20bb | 1495 | { |
aad3612f | 1496 | struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); |
333b20bb GM |
1497 | Lisp_Object tem; |
1498 | ||
1499 | tem = x_get_arg (dpyinfo, alist, prop, xprop, xclass, RES_TYPE_STRING); | |
1500 | if (EQ (tem, Qunbound)) | |
1501 | { | |
1502 | #ifdef USE_TOOLKIT_SCROLL_BARS | |
1503 | ||
1504 | /* See if an X resource for the scroll bar color has been | |
1505 | specified. */ | |
1506 | tem = display_x_get_resource (dpyinfo, | |
1507 | build_string (foreground_p | |
1508 | ? "foreground" | |
1509 | : "background"), | |
6ecd75be | 1510 | empty_unibyte_string, |
333b20bb | 1511 | build_string ("verticalScrollBar"), |
6ecd75be | 1512 | empty_unibyte_string); |
333b20bb GM |
1513 | if (!STRINGP (tem)) |
1514 | { | |
1515 | /* If nothing has been specified, scroll bars will use a | |
1516 | toolkit-dependent default. Because these defaults are | |
1517 | difficult to get at without actually creating a scroll | |
1518 | bar, use nil to indicate that no color has been | |
1519 | specified. */ | |
1520 | tem = Qnil; | |
1521 | } | |
177c0ea7 | 1522 | |
333b20bb | 1523 | #else /* not USE_TOOLKIT_SCROLL_BARS */ |
177c0ea7 | 1524 | |
333b20bb | 1525 | tem = Qnil; |
177c0ea7 | 1526 | |
333b20bb GM |
1527 | #endif /* not USE_TOOLKIT_SCROLL_BARS */ |
1528 | } | |
1529 | ||
6c6f1994 | 1530 | x_set_frame_parameters (f, list1 (Fcons (prop, tem))); |
333b20bb GM |
1531 | return tem; |
1532 | } | |
1533 | ||
1534 | ||
01f1ba30 | 1535 | |
9ef48a9d RS |
1536 | \f |
1537 | #ifdef USE_X_TOOLKIT | |
1538 | ||
8e3d10a9 RS |
1539 | /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS, |
1540 | WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may | |
59aa6c90 RS |
1541 | already be present because of the toolkit (Motif adds some of them, |
1542 | for example, but Xt doesn't). */ | |
9ef48a9d RS |
1543 | |
1544 | static void | |
a10c8269 | 1545 | hack_wm_protocols (struct frame *f, Widget widget) |
9ef48a9d RS |
1546 | { |
1547 | Display *dpy = XtDisplay (widget); | |
1548 | Window w = XtWindow (widget); | |
1549 | int need_delete = 1; | |
1550 | int need_focus = 1; | |
59aa6c90 | 1551 | int need_save = 1; |
9ef48a9d | 1552 | |
4d7e6e51 | 1553 | block_input (); |
9ef48a9d | 1554 | { |
a3db4b26 AS |
1555 | Atom type; |
1556 | unsigned char *catoms; | |
9ef48a9d RS |
1557 | int format = 0; |
1558 | unsigned long nitems = 0; | |
1559 | unsigned long bytes_after; | |
1560 | ||
270958e8 | 1561 | if ((XGetWindowProperty (dpy, w, |
aad3612f | 1562 | FRAME_DISPLAY_INFO (f)->Xatom_wm_protocols, |
34d5ae1e | 1563 | (long)0, (long)100, False, XA_ATOM, |
270958e8 | 1564 | &type, &format, &nitems, &bytes_after, |
a3db4b26 | 1565 | &catoms) |
270958e8 | 1566 | == Success) |
9ef48a9d | 1567 | && format == 32 && type == XA_ATOM) |
a3db4b26 AS |
1568 | { |
1569 | Atom *atoms = (Atom *) catoms; | |
1570 | while (nitems > 0) | |
1571 | { | |
1572 | nitems--; | |
1573 | if (atoms[nitems] | |
aad3612f | 1574 | == FRAME_DISPLAY_INFO (f)->Xatom_wm_delete_window) |
a3db4b26 AS |
1575 | need_delete = 0; |
1576 | else if (atoms[nitems] | |
aad3612f | 1577 | == FRAME_DISPLAY_INFO (f)->Xatom_wm_take_focus) |
a3db4b26 AS |
1578 | need_focus = 0; |
1579 | else if (atoms[nitems] | |
aad3612f | 1580 | == FRAME_DISPLAY_INFO (f)->Xatom_wm_save_yourself) |
a3db4b26 AS |
1581 | need_save = 0; |
1582 | } | |
1583 | } | |
1584 | if (catoms) | |
1585 | XFree (catoms); | |
9ef48a9d RS |
1586 | } |
1587 | { | |
1588 | Atom props [10]; | |
1589 | int count = 0; | |
b9dc4443 | 1590 | if (need_delete) |
aad3612f | 1591 | props[count++] = FRAME_DISPLAY_INFO (f)->Xatom_wm_delete_window; |
b9dc4443 | 1592 | if (need_focus) |
aad3612f | 1593 | props[count++] = FRAME_DISPLAY_INFO (f)->Xatom_wm_take_focus; |
b9dc4443 | 1594 | if (need_save) |
aad3612f | 1595 | props[count++] = FRAME_DISPLAY_INFO (f)->Xatom_wm_save_yourself; |
9ef48a9d | 1596 | if (count) |
aad3612f | 1597 | XChangeProperty (dpy, w, FRAME_DISPLAY_INFO (f)->Xatom_wm_protocols, |
b9dc4443 | 1598 | XA_ATOM, 32, PropModeAppend, |
9ef48a9d RS |
1599 | (unsigned char *) props, count); |
1600 | } | |
4d7e6e51 | 1601 | unblock_input (); |
9ef48a9d RS |
1602 | } |
1603 | #endif | |
86779fac GM |
1604 | |
1605 | ||
5a7df7d7 GM |
1606 | \f |
1607 | /* Support routines for XIC (X Input Context). */ | |
86779fac | 1608 | |
5a7df7d7 GM |
1609 | #ifdef HAVE_X_I18N |
1610 | ||
f57e2426 J |
1611 | static XFontSet xic_create_xfontset (struct frame *); |
1612 | static XIMStyle best_xim_style (XIMStyles *, XIMStyles *); | |
5a7df7d7 GM |
1613 | |
1614 | ||
1576f1ad | 1615 | /* Supported XIM styles, ordered by preference. */ |
5a7df7d7 GM |
1616 | |
1617 | static XIMStyle supported_xim_styles[] = | |
1618 | { | |
1619 | XIMPreeditPosition | XIMStatusArea, | |
1620 | XIMPreeditPosition | XIMStatusNothing, | |
1621 | XIMPreeditPosition | XIMStatusNone, | |
1622 | XIMPreeditNothing | XIMStatusArea, | |
1623 | XIMPreeditNothing | XIMStatusNothing, | |
1624 | XIMPreeditNothing | XIMStatusNone, | |
1625 | XIMPreeditNone | XIMStatusArea, | |
1626 | XIMPreeditNone | XIMStatusNothing, | |
1627 | XIMPreeditNone | XIMStatusNone, | |
1628 | 0, | |
1629 | }; | |
1630 | ||
1631 | ||
e4cebfca | 1632 | #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT |
c27ed90a | 1633 | /* Create an X fontset on frame F with base font name BASE_FONTNAME. */ |
5a7df7d7 | 1634 | |
333f9019 | 1635 | static const char xic_default_fontset[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*"; |
bb07fa29 | 1636 | |
c28e7ae8 SM |
1637 | /* Create an Xt fontset spec from the name of a base font. |
1638 | If `motif' is True use the Motif syntax. */ | |
bb07fa29 | 1639 | char * |
e6cba650 | 1640 | xic_create_fontsetname (const char *base_fontname, int motif) |
bb07fa29 | 1641 | { |
c28e7ae8 SM |
1642 | const char *sep = motif ? ";" : ","; |
1643 | char *fontsetname; | |
1644 | ||
bb07fa29 | 1645 | /* Make a fontset name from the base font name. */ |
333f9019 | 1646 | if (xic_default_fontset == base_fontname) |
38182d90 | 1647 | { |
afa2ffd8 DA |
1648 | /* There is no base font name, use the default. */ |
1649 | fontsetname = xmalloc (strlen (base_fontname) + 2); | |
c28e7ae8 SM |
1650 | strcpy (fontsetname, base_fontname); |
1651 | } | |
bb07fa29 SM |
1652 | else |
1653 | { | |
1654 | /* Make a fontset name from the base font name. | |
1655 | The font set will be made of the following elements: | |
1656 | - the base font. | |
1657 | - the base font where the charset spec is replaced by -*-*. | |
1658 | - the same but with the family also replaced with -*-*-. */ | |
e6cba650 | 1659 | const char *p = base_fontname; |
25ed6cc3 | 1660 | ptrdiff_t i; |
df630496 | 1661 | |
bb07fa29 SM |
1662 | for (i = 0; *p; p++) |
1663 | if (*p == '-') i++; | |
1664 | if (i != 14) | |
afa2ffd8 DA |
1665 | { |
1666 | /* As the font name doesn't conform to XLFD, we can't | |
bb07fa29 SM |
1667 | modify it to generalize it to allcs and allfamilies. |
1668 | Use the specified font plus the default. */ | |
afa2ffd8 DA |
1669 | fontsetname = xmalloc (strlen (base_fontname) |
1670 | + strlen (xic_default_fontset) + 3); | |
bb07fa29 | 1671 | strcpy (fontsetname, base_fontname); |
c28e7ae8 | 1672 | strcat (fontsetname, sep); |
333f9019 | 1673 | strcat (fontsetname, xic_default_fontset); |
bb07fa29 SM |
1674 | } |
1675 | else | |
1676 | { | |
25ed6cc3 | 1677 | ptrdiff_t len; |
e6cba650 | 1678 | const char *p1 = NULL, *p2 = NULL, *p3 = NULL; |
bb07fa29 SM |
1679 | char *font_allcs = NULL; |
1680 | char *font_allfamilies = NULL; | |
968a6679 | 1681 | char *font_all = NULL; |
e6cba650 DN |
1682 | const char *allcs = "*-*-*-*-*-*-*"; |
1683 | const char *allfamilies = "-*-*-"; | |
1684 | const char *all = "*-*-*-*-"; | |
cd987aaa | 1685 | char *base; |
df630496 | 1686 | |
bb07fa29 SM |
1687 | for (i = 0, p = base_fontname; i < 8; p++) |
1688 | { | |
1689 | if (*p == '-') | |
1690 | { | |
1691 | i++; | |
1692 | if (i == 3) | |
1693 | p1 = p + 1; | |
968a6679 SM |
1694 | else if (i == 7) |
1695 | p2 = p + 1; | |
cd987aaa KH |
1696 | else if (i == 6) |
1697 | p3 = p + 1; | |
bb07fa29 SM |
1698 | } |
1699 | } | |
cd987aaa KH |
1700 | /* If base_fontname specifies ADSTYLE, make it a |
1701 | wildcard. */ | |
1702 | if (*p3 != '*') | |
1703 | { | |
25ed6cc3 | 1704 | ptrdiff_t diff = (p2 - p3) - 2; |
cd987aaa KH |
1705 | |
1706 | base = alloca (strlen (base_fontname) + 1); | |
72af86bd | 1707 | memcpy (base, base_fontname, p3 - base_fontname); |
cd987aaa KH |
1708 | base[p3 - base_fontname] = '*'; |
1709 | base[(p3 - base_fontname) + 1] = '-'; | |
1710 | strcpy (base + (p3 - base_fontname) + 2, p2); | |
1711 | p = base + (p - base_fontname) - diff; | |
1712 | p1 = base + (p1 - base_fontname); | |
1713 | p2 = base + (p2 - base_fontname) - diff; | |
1714 | base_fontname = base; | |
1715 | } | |
1716 | ||
bb07fa29 SM |
1717 | /* Build the font spec that matches all charsets. */ |
1718 | len = p - base_fontname + strlen (allcs) + 1; | |
38182d90 | 1719 | font_allcs = alloca (len); |
72af86bd | 1720 | memcpy (font_allcs, base_fontname, p - base_fontname); |
bb07fa29 SM |
1721 | strcat (font_allcs, allcs); |
1722 | ||
cd987aaa KH |
1723 | /* Build the font spec that matches all families and |
1724 | add-styles. */ | |
bb07fa29 | 1725 | len = p - p1 + strlen (allcs) + strlen (allfamilies) + 1; |
38182d90 | 1726 | font_allfamilies = alloca (len); |
bb07fa29 | 1727 | strcpy (font_allfamilies, allfamilies); |
72af86bd | 1728 | memcpy (font_allfamilies + strlen (allfamilies), p1, p - p1); |
bb07fa29 SM |
1729 | strcat (font_allfamilies, allcs); |
1730 | ||
968a6679 SM |
1731 | /* Build the font spec that matches all. */ |
1732 | len = p - p2 + strlen (allcs) + strlen (all) + strlen (allfamilies) + 1; | |
38182d90 | 1733 | font_all = alloca (len); |
968a6679 SM |
1734 | strcpy (font_all, allfamilies); |
1735 | strcat (font_all, all); | |
72af86bd | 1736 | memcpy (font_all + strlen (all) + strlen (allfamilies), p2, p - p2); |
968a6679 SM |
1737 | strcat (font_all, allcs); |
1738 | ||
bb07fa29 SM |
1739 | /* Build the actual font set name. */ |
1740 | len = strlen (base_fontname) + strlen (font_allcs) | |
968a6679 | 1741 | + strlen (font_allfamilies) + strlen (font_all) + 5; |
bb07fa29 | 1742 | fontsetname = xmalloc (len); |
bb07fa29 | 1743 | strcpy (fontsetname, base_fontname); |
c28e7ae8 | 1744 | strcat (fontsetname, sep); |
bb07fa29 | 1745 | strcat (fontsetname, font_allcs); |
c28e7ae8 | 1746 | strcat (fontsetname, sep); |
bb07fa29 | 1747 | strcat (fontsetname, font_allfamilies); |
968a6679 SM |
1748 | strcat (fontsetname, sep); |
1749 | strcat (fontsetname, font_all); | |
bb07fa29 | 1750 | } |
bb07fa29 | 1751 | } |
c28e7ae8 SM |
1752 | if (motif) |
1753 | strcat (fontsetname, ":"); | |
1754 | return fontsetname; | |
bb07fa29 | 1755 | } |
e4cebfca | 1756 | #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */ |
bb07fa29 | 1757 | |
2da34f50 KH |
1758 | #ifdef DEBUG_XIC_FONTSET |
1759 | static void | |
1dae0f0a AS |
1760 | print_fontset_result (XFontSet xfs, char *name, char **missing_list, |
1761 | int missing_count) | |
2da34f50 KH |
1762 | { |
1763 | if (xfs) | |
1764 | fprintf (stderr, "XIC Fontset created: %s\n", name); | |
1765 | else | |
1766 | { | |
1767 | fprintf (stderr, "XIC Fontset failed: %s\n", name); | |
1768 | while (missing_count-- > 0) | |
1769 | { | |
1770 | fprintf (stderr, " missing: %s\n", *missing_list); | |
1771 | missing_list++; | |
1772 | } | |
1773 | } | |
1774 | ||
1775 | } | |
1776 | #endif | |
1777 | ||
5a7df7d7 | 1778 | static XFontSet |
971de7fb | 1779 | xic_create_xfontset (struct frame *f) |
86779fac | 1780 | { |
c27ed90a | 1781 | XFontSet xfs = NULL; |
b51238f5 | 1782 | struct font *font = FRAME_FONT (f); |
a32f056c KH |
1783 | int pixel_size = font->pixel_size; |
1784 | Lisp_Object rest, frame; | |
1785 | ||
1786 | /* See if there is another frame already using same fontset. */ | |
1787 | FOR_EACH_FRAME (rest, frame) | |
1788 | { | |
1789 | struct frame *cf = XFRAME (frame); | |
1790 | ||
1791 | if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf) | |
aad3612f | 1792 | && FRAME_DISPLAY_INFO (cf) == FRAME_DISPLAY_INFO (f) |
b51238f5 KH |
1793 | && FRAME_FONT (f) |
1794 | && FRAME_FONT (f)->pixel_size == pixel_size) | |
a32f056c KH |
1795 | { |
1796 | xfs = FRAME_XIC_FONTSET (cf); | |
1797 | break; | |
1798 | } | |
1799 | } | |
1800 | ||
1801 | if (! xfs) | |
1802 | { | |
1803 | char buf[256]; | |
1804 | char **missing_list; | |
1805 | int missing_count; | |
1806 | char *def_string; | |
e6cba650 | 1807 | const char *xlfd_format = "-*-*-medium-r-normal--%d-*-*-*-*-*"; |
a32f056c KH |
1808 | |
1809 | sprintf (buf, xlfd_format, pixel_size); | |
1810 | missing_list = NULL; | |
1811 | xfs = XCreateFontSet (FRAME_X_DISPLAY (f), buf, | |
1812 | &missing_list, &missing_count, &def_string); | |
d3483d71 | 1813 | #ifdef DEBUG_XIC_FONTSET |
22a8f595 | 1814 | print_fontset_result (xfs, buf, missing_list, missing_count); |
d3483d71 | 1815 | #endif |
a32f056c KH |
1816 | if (missing_list) |
1817 | XFreeStringList (missing_list); | |
1818 | if (! xfs) | |
1819 | { | |
1820 | /* List of pixel sizes most likely available. Find one that | |
1821 | is closest to pixel_size. */ | |
1822 | int sizes[] = {0, 8, 10, 11, 12, 14, 17, 18, 20, 24, 26, 34, 0}; | |
1823 | int *smaller, *larger; | |
1824 | ||
1825 | for (smaller = sizes; smaller[1]; smaller++) | |
1826 | if (smaller[1] >= pixel_size) | |
1827 | break; | |
1828 | larger = smaller + 1; | |
1829 | if (*larger == pixel_size) | |
1830 | larger++; | |
1831 | while (*smaller || *larger) | |
1832 | { | |
1833 | int this_size; | |
1834 | ||
1835 | if (! *larger) | |
1836 | this_size = *smaller--; | |
1837 | else if (! *smaller) | |
1838 | this_size = *larger++; | |
1839 | else if (pixel_size - *smaller < *larger - pixel_size) | |
1840 | this_size = *smaller--; | |
1841 | else | |
1842 | this_size = *larger++; | |
1843 | sprintf (buf, xlfd_format, this_size); | |
1844 | missing_list = NULL; | |
1845 | xfs = XCreateFontSet (FRAME_X_DISPLAY (f), buf, | |
1846 | &missing_list, &missing_count, &def_string); | |
d3483d71 | 1847 | #ifdef DEBUG_XIC_FONTSET |
22a8f595 | 1848 | print_fontset_result (xfs, buf, missing_list, missing_count); |
d3483d71 | 1849 | #endif |
a32f056c KH |
1850 | if (missing_list) |
1851 | XFreeStringList (missing_list); | |
1852 | if (xfs) | |
1853 | break; | |
1854 | } | |
1855 | } | |
2da34f50 KH |
1856 | if (! xfs) |
1857 | { | |
675e2c69 | 1858 | const char *last_resort = "-*-*-*-r-normal--*-*-*-*-*-*"; |
2da34f50 KH |
1859 | |
1860 | missing_list = NULL; | |
1861 | xfs = XCreateFontSet (FRAME_X_DISPLAY (f), last_resort, | |
1862 | &missing_list, &missing_count, &def_string); | |
1863 | #ifdef DEBUG_XIC_FONTSET | |
1864 | print_fontset_result (xfs, last_resort, missing_list, missing_count); | |
1865 | #endif | |
1866 | if (missing_list) | |
1867 | XFreeStringList (missing_list); | |
1868 | } | |
1869 | ||
a32f056c KH |
1870 | } |
1871 | ||
1872 | return xfs; | |
1873 | } | |
a32f056c | 1874 | |
c27ed90a JD |
1875 | /* Free the X fontset of frame F if it is the last frame using it. */ |
1876 | ||
1877 | void | |
971de7fb | 1878 | xic_free_xfontset (struct frame *f) |
c27ed90a JD |
1879 | { |
1880 | Lisp_Object rest, frame; | |
d7e6881a | 1881 | bool shared_p = 0; |
c27ed90a JD |
1882 | |
1883 | if (!FRAME_XIC_FONTSET (f)) | |
1884 | return; | |
1885 | ||
1886 | /* See if there is another frame sharing the same fontset. */ | |
1887 | FOR_EACH_FRAME (rest, frame) | |
1888 | { | |
1889 | struct frame *cf = XFRAME (frame); | |
1890 | if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf) | |
aad3612f | 1891 | && FRAME_DISPLAY_INFO (cf) == FRAME_DISPLAY_INFO (f) |
c27ed90a JD |
1892 | && FRAME_XIC_FONTSET (cf) == FRAME_XIC_FONTSET (f)) |
1893 | { | |
1894 | shared_p = 1; | |
1895 | break; | |
1896 | } | |
1897 | } | |
1898 | ||
1899 | if (!shared_p) | |
1900 | /* The fontset is not used anymore. It is safe to free it. */ | |
1901 | XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f)); | |
1902 | ||
c27ed90a JD |
1903 | FRAME_XIC_FONTSET (f) = NULL; |
1904 | } | |
1905 | ||
5a7df7d7 GM |
1906 | |
1907 | /* Value is the best input style, given user preferences USER (already | |
1908 | checked to be supported by Emacs), and styles supported by the | |
1909 | input method XIM. */ | |
1910 | ||
1911 | static XIMStyle | |
971de7fb | 1912 | best_xim_style (XIMStyles *user, XIMStyles *xim) |
5a7df7d7 GM |
1913 | { |
1914 | int i, j; | |
1915 | ||
1916 | for (i = 0; i < user->count_styles; ++i) | |
1917 | for (j = 0; j < xim->count_styles; ++j) | |
1918 | if (user->supported_styles[i] == xim->supported_styles[j]) | |
1919 | return user->supported_styles[i]; | |
1920 | ||
1921 | /* Return the default style. */ | |
1922 | return XIMPreeditNothing | XIMStatusNothing; | |
1923 | } | |
1924 | ||
1925 | /* Create XIC for frame F. */ | |
1926 | ||
5df79d3d GM |
1927 | static XIMStyle xic_style; |
1928 | ||
5a7df7d7 | 1929 | void |
971de7fb | 1930 | create_frame_xic (struct frame *f) |
5a7df7d7 | 1931 | { |
5a7df7d7 GM |
1932 | XIM xim; |
1933 | XIC xic = NULL; | |
1934 | XFontSet xfs = NULL; | |
86779fac | 1935 | |
5a7df7d7 GM |
1936 | if (FRAME_XIC (f)) |
1937 | return; | |
177c0ea7 | 1938 | |
bb07fa29 | 1939 | /* Create X fontset. */ |
b51238f5 | 1940 | xfs = xic_create_xfontset (f); |
5a7df7d7 GM |
1941 | xim = FRAME_X_XIM (f); |
1942 | if (xim) | |
1943 | { | |
d9d57cb2 DL |
1944 | XRectangle s_area; |
1945 | XPoint spot; | |
5a7df7d7 GM |
1946 | XVaNestedList preedit_attr; |
1947 | XVaNestedList status_attr; | |
5a7df7d7 | 1948 | |
d9d57cb2 DL |
1949 | s_area.x = 0; s_area.y = 0; s_area.width = 1; s_area.height = 1; |
1950 | spot.x = 0; spot.y = 1; | |
86779fac | 1951 | |
5a7df7d7 GM |
1952 | /* Determine XIC style. */ |
1953 | if (xic_style == 0) | |
1954 | { | |
1955 | XIMStyles supported_list; | |
1956 | supported_list.count_styles = (sizeof supported_xim_styles | |
1957 | / sizeof supported_xim_styles[0]); | |
1958 | supported_list.supported_styles = supported_xim_styles; | |
1959 | xic_style = best_xim_style (&supported_list, | |
1960 | FRAME_X_XIM_STYLES (f)); | |
1961 | } | |
86779fac | 1962 | |
5a7df7d7 GM |
1963 | preedit_attr = XVaCreateNestedList (0, |
1964 | XNFontSet, xfs, | |
1965 | XNForeground, | |
1966 | FRAME_FOREGROUND_PIXEL (f), | |
1967 | XNBackground, | |
1968 | FRAME_BACKGROUND_PIXEL (f), | |
1969 | (xic_style & XIMPreeditPosition | |
1970 | ? XNSpotLocation | |
1971 | : NULL), | |
1972 | &spot, | |
1973 | NULL); | |
1974 | status_attr = XVaCreateNestedList (0, | |
1975 | XNArea, | |
1976 | &s_area, | |
1977 | XNFontSet, | |
1978 | xfs, | |
1979 | XNForeground, | |
1980 | FRAME_FOREGROUND_PIXEL (f), | |
1981 | XNBackground, | |
1982 | FRAME_BACKGROUND_PIXEL (f), | |
1983 | NULL); | |
1984 | ||
1985 | xic = XCreateIC (xim, | |
1986 | XNInputStyle, xic_style, | |
6b61353c KH |
1987 | XNClientWindow, FRAME_X_WINDOW (f), |
1988 | XNFocusWindow, FRAME_X_WINDOW (f), | |
5a7df7d7 GM |
1989 | XNStatusAttributes, status_attr, |
1990 | XNPreeditAttributes, preedit_attr, | |
1991 | NULL); | |
1992 | XFree (preedit_attr); | |
1993 | XFree (status_attr); | |
1994 | } | |
177c0ea7 | 1995 | |
5a7df7d7 GM |
1996 | FRAME_XIC (f) = xic; |
1997 | FRAME_XIC_STYLE (f) = xic_style; | |
1998 | FRAME_XIC_FONTSET (f) = xfs; | |
86779fac GM |
1999 | } |
2000 | ||
5a7df7d7 GM |
2001 | |
2002 | /* Destroy XIC and free XIC fontset of frame F, if any. */ | |
2003 | ||
2004 | void | |
971de7fb | 2005 | free_frame_xic (struct frame *f) |
5a7df7d7 GM |
2006 | { |
2007 | if (FRAME_XIC (f) == NULL) | |
2008 | return; | |
177c0ea7 | 2009 | |
5a7df7d7 | 2010 | XDestroyIC (FRAME_XIC (f)); |
c27ed90a | 2011 | xic_free_xfontset (f); |
5a7df7d7 GM |
2012 | |
2013 | FRAME_XIC (f) = NULL; | |
5a7df7d7 GM |
2014 | } |
2015 | ||
2016 | ||
2017 | /* Place preedit area for XIC of window W's frame to specified | |
2018 | pixel position X/Y. X and Y are relative to window W. */ | |
2019 | ||
2020 | void | |
971de7fb | 2021 | xic_set_preeditarea (struct window *w, int x, int y) |
5a7df7d7 | 2022 | { |
d3d50620 | 2023 | struct frame *f = XFRAME (w->frame); |
5a7df7d7 GM |
2024 | XVaNestedList attr; |
2025 | XPoint spot; | |
177c0ea7 | 2026 | |
17e6d491 | 2027 | spot.x = WINDOW_TO_FRAME_PIXEL_X (w, x) + WINDOW_LEFT_FRINGE_WIDTH (w); |
5a7df7d7 GM |
2028 | spot.y = WINDOW_TO_FRAME_PIXEL_Y (w, y) + FONT_BASE (FRAME_FONT (f)); |
2029 | attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL); | |
2030 | XSetICValues (FRAME_XIC (f), XNPreeditAttributes, attr, NULL); | |
2031 | XFree (attr); | |
2032 | } | |
2033 | ||
2034 | ||
2035 | /* Place status area for XIC in bottom right corner of frame F.. */ | |
2036 | ||
2037 | void | |
971de7fb | 2038 | xic_set_statusarea (struct frame *f) |
5a7df7d7 GM |
2039 | { |
2040 | XIC xic = FRAME_XIC (f); | |
2041 | XVaNestedList attr; | |
2042 | XRectangle area; | |
2043 | XRectangle *needed; | |
2044 | ||
2045 | /* Negotiate geometry of status area. If input method has existing | |
2046 | status area, use its current size. */ | |
2047 | area.x = area.y = area.width = area.height = 0; | |
2048 | attr = XVaCreateNestedList (0, XNAreaNeeded, &area, NULL); | |
2049 | XSetICValues (xic, XNStatusAttributes, attr, NULL); | |
2050 | XFree (attr); | |
177c0ea7 | 2051 | |
5a7df7d7 GM |
2052 | attr = XVaCreateNestedList (0, XNAreaNeeded, &needed, NULL); |
2053 | XGetICValues (xic, XNStatusAttributes, attr, NULL); | |
2054 | XFree (attr); | |
2055 | ||
2056 | if (needed->width == 0) /* Use XNArea instead of XNAreaNeeded */ | |
2057 | { | |
2058 | attr = XVaCreateNestedList (0, XNArea, &needed, NULL); | |
2059 | XGetICValues (xic, XNStatusAttributes, attr, NULL); | |
2060 | XFree (attr); | |
2061 | } | |
2062 | ||
2063 | area.width = needed->width; | |
2064 | area.height = needed->height; | |
be786000 KS |
2065 | area.x = FRAME_PIXEL_WIDTH (f) - area.width - FRAME_INTERNAL_BORDER_WIDTH (f); |
2066 | area.y = (FRAME_PIXEL_HEIGHT (f) - area.height | |
488dd4c4 | 2067 | - FRAME_MENUBAR_HEIGHT (f) |
bfeabdc3 | 2068 | - FRAME_TOOLBAR_TOP_HEIGHT (f) |
488dd4c4 | 2069 | - FRAME_INTERNAL_BORDER_WIDTH (f)); |
5a7df7d7 GM |
2070 | XFree (needed); |
2071 | ||
2072 | attr = XVaCreateNestedList (0, XNArea, &area, NULL); | |
6b61353c | 2073 | XSetICValues (xic, XNStatusAttributes, attr, NULL); |
5a7df7d7 GM |
2074 | XFree (attr); |
2075 | } | |
2076 | ||
2077 | ||
2078 | /* Set X fontset for XIC of frame F, using base font name | |
2079 | BASE_FONTNAME. Called when a new Emacs fontset is chosen. */ | |
2080 | ||
2081 | void | |
eec47d6b | 2082 | xic_set_xfontset (struct frame *f, const char *base_fontname) |
5a7df7d7 GM |
2083 | { |
2084 | XVaNestedList attr; | |
2085 | XFontSet xfs; | |
2086 | ||
c27ed90a JD |
2087 | xic_free_xfontset (f); |
2088 | ||
b51238f5 | 2089 | xfs = xic_create_xfontset (f); |
5a7df7d7 GM |
2090 | |
2091 | attr = XVaCreateNestedList (0, XNFontSet, xfs, NULL); | |
2092 | if (FRAME_XIC_STYLE (f) & XIMPreeditPosition) | |
2093 | XSetICValues (FRAME_XIC (f), XNPreeditAttributes, attr, NULL); | |
2094 | if (FRAME_XIC_STYLE (f) & XIMStatusArea) | |
2095 | XSetICValues (FRAME_XIC (f), XNStatusAttributes, attr, NULL); | |
2096 | XFree (attr); | |
177c0ea7 | 2097 | |
5a7df7d7 GM |
2098 | FRAME_XIC_FONTSET (f) = xfs; |
2099 | } | |
2100 | ||
2101 | #endif /* HAVE_X_I18N */ | |
2102 | ||
2103 | ||
9ef48a9d | 2104 | \f |
8fc2766b RS |
2105 | #ifdef USE_X_TOOLKIT |
2106 | ||
2107 | /* Create and set up the X widget for frame F. */ | |
f58534a3 | 2108 | |
01f1ba30 | 2109 | static void |
ebd15611 | 2110 | x_window (struct frame *f, long window_prompting, int minibuffer_only) |
01f1ba30 | 2111 | { |
9ef48a9d | 2112 | XClassHint class_hints; |
31ac8d8c FP |
2113 | XSetWindowAttributes attributes; |
2114 | unsigned long attribute_mask; | |
9ef48a9d RS |
2115 | Widget shell_widget; |
2116 | Widget pane_widget; | |
6c32dd68 | 2117 | Widget frame_widget; |
9ef48a9d RS |
2118 | Arg al [25]; |
2119 | int ac; | |
2120 | ||
4d7e6e51 | 2121 | block_input (); |
9ef48a9d | 2122 | |
b7975ee4 KH |
2123 | /* Use the resource name as the top-level widget name |
2124 | for looking up resources. Make a non-Lisp copy | |
2125 | for the window manager, so GC relocation won't bother it. | |
2126 | ||
2127 | Elsewhere we specify the window name for the window manager. */ | |
309f24d1 | 2128 | f->namebuf = xstrdup (SSDATA (Vx_resource_name)); |
9ef48a9d RS |
2129 | |
2130 | ac = 0; | |
2131 | XtSetArg (al[ac], XtNallowShellResize, 1); ac++; | |
2132 | XtSetArg (al[ac], XtNinput, 1); ac++; | |
97787173 | 2133 | XtSetArg (al[ac], XtNmappedWhenManaged, 0); ac++; |
be786000 | 2134 | XtSetArg (al[ac], XtNborderWidth, f->border_width); ac++; |
9b2956e2 | 2135 | XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++; |
aad3612f | 2136 | XtSetArg (al[ac], XtNdepth, FRAME_DISPLAY_INFO (f)->n_planes); ac++; |
9b2956e2 | 2137 | XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++; |
cca176a0 | 2138 | shell_widget = XtAppCreateShell (f->namebuf, EMACS_CLASS, |
7a994728 | 2139 | applicationShellWidgetClass, |
82c90203 | 2140 | FRAME_X_DISPLAY (f), al, ac); |
9ef48a9d | 2141 | |
7556890b | 2142 | f->output_data.x->widget = shell_widget; |
9ef48a9d RS |
2143 | /* maybe_set_screen_title_format (shell_widget); */ |
2144 | ||
6c32dd68 | 2145 | pane_widget = lw_create_widget ("main", "pane", widget_id_tick++, |
7d652d97 PE |
2146 | NULL, shell_widget, False, |
2147 | NULL, NULL, NULL, NULL); | |
9ef48a9d | 2148 | |
9b2956e2 GM |
2149 | ac = 0; |
2150 | XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++; | |
aad3612f | 2151 | XtSetArg (al[ac], XtNdepth, FRAME_DISPLAY_INFO (f)->n_planes); ac++; |
9b2956e2 | 2152 | XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++; |
723f5a07 | 2153 | XtSetArg (al[ac], XtNborderWidth, 0); ac++; |
9b2956e2 | 2154 | XtSetValues (pane_widget, al, ac); |
7556890b | 2155 | f->output_data.x->column_widget = pane_widget; |
a7f7d550 | 2156 | |
177c0ea7 | 2157 | /* mappedWhenManaged to false tells to the paned window to not map/unmap |
5e65b9ab | 2158 | the emacs screen when changing menubar. This reduces flickering. */ |
9ef48a9d RS |
2159 | |
2160 | ac = 0; | |
2161 | XtSetArg (al[ac], XtNmappedWhenManaged, 0); ac++; | |
2162 | XtSetArg (al[ac], XtNshowGrip, 0); ac++; | |
2163 | XtSetArg (al[ac], XtNallowResize, 1); ac++; | |
2164 | XtSetArg (al[ac], XtNresizeToPreferred, 1); ac++; | |
2165 | XtSetArg (al[ac], XtNemacsFrame, f); ac++; | |
9b2956e2 | 2166 | XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++; |
aad3612f | 2167 | XtSetArg (al[ac], XtNdepth, FRAME_DISPLAY_INFO (f)->n_planes); ac++; |
9b2956e2 | 2168 | XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++; |
723f5a07 | 2169 | XtSetArg (al[ac], XtNborderWidth, 0); ac++; |
9b2956e2 GM |
2170 | frame_widget = XtCreateWidget (f->namebuf, emacsFrameClass, pane_widget, |
2171 | al, ac); | |
177c0ea7 | 2172 | |
7556890b | 2173 | f->output_data.x->edit_widget = frame_widget; |
177c0ea7 JB |
2174 | |
2175 | XtManageChild (frame_widget); | |
a7f7d550 FP |
2176 | |
2177 | /* Do some needed geometry management. */ | |
2178 | { | |
b7163a50 | 2179 | char *tem, shell_position[sizeof "=x++" + 4 * INT_STRLEN_BOUND (int)]; |
8a94ea33 PE |
2180 | Arg gal[10]; |
2181 | int gac = 0; | |
5031cc10 | 2182 | int extra_borders = 0; |
177c0ea7 | 2183 | int menubar_size |
7556890b RS |
2184 | = (f->output_data.x->menubar_widget |
2185 | ? (f->output_data.x->menubar_widget->core.height | |
2186 | + f->output_data.x->menubar_widget->core.border_width) | |
8fc2766b | 2187 | : 0); |
a7f7d550 | 2188 | |
f7008aff RS |
2189 | #if 0 /* Experimentally, we now get the right results |
2190 | for -geometry -0-0 without this. 24 Aug 96, rms. */ | |
01cbdba5 RS |
2191 | if (FRAME_EXTERNAL_MENU_BAR (f)) |
2192 | { | |
dd254b21 | 2193 | Dimension ibw = 0; |
01cbdba5 RS |
2194 | XtVaGetValues (pane_widget, XtNinternalBorderWidth, &ibw, NULL); |
2195 | menubar_size += ibw; | |
2196 | } | |
f7008aff | 2197 | #endif |
01cbdba5 | 2198 | |
7556890b | 2199 | f->output_data.x->menubar_height = menubar_size; |
00983aba | 2200 | |
440b0bfd | 2201 | #ifndef USE_LUCID |
5031cc10 KH |
2202 | /* Motif seems to need this amount added to the sizes |
2203 | specified for the shell widget. The Athena/Lucid widgets don't. | |
2204 | Both conclusions reached experimentally. -- rms. */ | |
440b0bfd RS |
2205 | XtVaGetValues (f->output_data.x->edit_widget, XtNinternalBorderWidth, |
2206 | &extra_borders, NULL); | |
2207 | extra_borders *= 2; | |
2208 | #endif | |
5031cc10 | 2209 | |
97787173 RS |
2210 | /* Convert our geometry parameters into a geometry string |
2211 | and specify it. | |
2212 | Note that we do not specify here whether the position | |
2213 | is a user-specified or program-specified one. | |
2214 | We pass that information later, in x_wm_set_size_hints. */ | |
2215 | { | |
be786000 | 2216 | int left = f->left_pos; |
97787173 | 2217 | int xneg = window_prompting & XNegative; |
be786000 | 2218 | int top = f->top_pos; |
97787173 RS |
2219 | int yneg = window_prompting & YNegative; |
2220 | if (xneg) | |
2221 | left = -left; | |
2222 | if (yneg) | |
2223 | top = -top; | |
c760f47e KH |
2224 | |
2225 | if (window_prompting & USPosition) | |
5031cc10 | 2226 | sprintf (shell_position, "=%dx%d%c%d%c%d", |
be786000 KS |
2227 | FRAME_PIXEL_WIDTH (f) + extra_borders, |
2228 | FRAME_PIXEL_HEIGHT (f) + menubar_size + extra_borders, | |
c760f47e KH |
2229 | (xneg ? '-' : '+'), left, |
2230 | (yneg ? '-' : '+'), top); | |
2231 | else | |
6b61353c KH |
2232 | { |
2233 | sprintf (shell_position, "=%dx%d", | |
2234 | FRAME_PIXEL_WIDTH (f) + extra_borders, | |
2235 | FRAME_PIXEL_HEIGHT (f) + menubar_size + extra_borders); | |
2236 | ||
2237 | /* Setting x and y when the position is not specified in | |
2238 | the geometry string will set program position in the WM hints. | |
2239 | If Emacs had just one program position, we could set it in | |
2240 | fallback resources, but since each make-frame call can specify | |
2241 | different program positions, this is easier. */ | |
8a94ea33 PE |
2242 | XtSetArg (gal[gac], XtNx, left); gac++; |
2243 | XtSetArg (gal[gac], XtNy, top); gac++; | |
6b61353c | 2244 | } |
97787173 RS |
2245 | } |
2246 | ||
77110caa RS |
2247 | /* We don't free this because we don't know whether |
2248 | it is safe to free it while the frame exists. | |
2249 | It isn't worth the trouble of arranging to free it | |
2250 | when the frame is deleted. */ | |
b3b4476b | 2251 | tem = xstrdup (shell_position); |
8a94ea33 PE |
2252 | XtSetArg (gal[gac], XtNgeometry, tem); gac++; |
2253 | XtSetValues (shell_widget, gal, gac); | |
a7f7d550 FP |
2254 | } |
2255 | ||
9ef48a9d RS |
2256 | XtManageChild (pane_widget); |
2257 | XtRealizeWidget (shell_widget); | |
2258 | ||
2532f20c JD |
2259 | if (FRAME_X_EMBEDDED_P (f)) |
2260 | XReparentWindow (FRAME_X_DISPLAY (f), XtWindow (shell_widget), | |
2261 | f->output_data.x->parent_desc, 0, 0); | |
2262 | ||
177c0ea7 | 2263 | FRAME_X_WINDOW (f) = XtWindow (frame_widget); |
9ef48a9d RS |
2264 | |
2265 | validate_x_resource_name (); | |
b7975ee4 | 2266 | |
51b59d79 PE |
2267 | class_hints.res_name = SSDATA (Vx_resource_name); |
2268 | class_hints.res_class = SSDATA (Vx_resource_class); | |
b9dc4443 | 2269 | XSetClassHint (FRAME_X_DISPLAY (f), XtWindow (shell_widget), &class_hints); |
5a7df7d7 GM |
2270 | |
2271 | #ifdef HAVE_X_I18N | |
2272 | FRAME_XIC (f) = NULL; | |
1576f1ad DL |
2273 | if (use_xim) |
2274 | create_frame_xic (f); | |
5a7df7d7 | 2275 | #endif |
64d16748 | 2276 | |
7556890b RS |
2277 | f->output_data.x->wm_hints.input = True; |
2278 | f->output_data.x->wm_hints.flags |= InputHint; | |
b9dc4443 | 2279 | XSetWMHints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
7556890b | 2280 | &f->output_data.x->wm_hints); |
b8228beb | 2281 | |
c4ec904f | 2282 | hack_wm_protocols (f, shell_widget); |
9ef48a9d | 2283 | |
6c32dd68 PR |
2284 | #ifdef HACK_EDITRES |
2285 | XtAddEventHandler (shell_widget, 0, True, _XEditResCheckMessages, 0); | |
2286 | #endif | |
2287 | ||
9ef48a9d | 2288 | /* Do a stupid property change to force the server to generate a |
333b20bb | 2289 | PropertyNotify event so that the event_stream server timestamp will |
9ef48a9d RS |
2290 | be initialized to something relevant to the time we created the window. |
2291 | */ | |
6c32dd68 | 2292 | XChangeProperty (XtDisplay (frame_widget), XtWindow (frame_widget), |
aad3612f | 2293 | FRAME_DISPLAY_INFO (f)->Xatom_wm_protocols, |
7d652d97 | 2294 | XA_ATOM, 32, PropModeAppend, NULL, 0); |
9ef48a9d | 2295 | |
5a7df7d7 | 2296 | /* Make all the standard events reach the Emacs frame. */ |
31ac8d8c | 2297 | attributes.event_mask = STANDARD_EVENT_SET; |
5a7df7d7 GM |
2298 | |
2299 | #ifdef HAVE_X_I18N | |
2300 | if (FRAME_XIC (f)) | |
2301 | { | |
2302 | /* XIM server might require some X events. */ | |
2303 | unsigned long fevent = NoEventMask; | |
6b61353c | 2304 | XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL); |
5a7df7d7 GM |
2305 | attributes.event_mask |= fevent; |
2306 | } | |
2307 | #endif /* HAVE_X_I18N */ | |
177c0ea7 | 2308 | |
31ac8d8c FP |
2309 | attribute_mask = CWEventMask; |
2310 | XChangeWindowAttributes (XtDisplay (shell_widget), XtWindow (shell_widget), | |
2311 | attribute_mask, &attributes); | |
2312 | ||
6c32dd68 | 2313 | XtMapWidget (frame_widget); |
9ef48a9d | 2314 | |
8fc2766b RS |
2315 | /* x_set_name normally ignores requests to set the name if the |
2316 | requested name is the same as the current name. This is the one | |
2317 | place where that assumption isn't correct; f->name is set, but | |
2318 | the X server hasn't been told. */ | |
2319 | { | |
2320 | Lisp_Object name; | |
2321 | int explicit = f->explicit_name; | |
2322 | ||
2323 | f->explicit_name = 0; | |
e69b0960 | 2324 | name = f->name; |
f00af5b1 | 2325 | fset_name (f, Qnil); |
8fc2766b RS |
2326 | x_set_name (f, name, explicit); |
2327 | } | |
2328 | ||
b9dc4443 | 2329 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
db3b2dc8 JD |
2330 | f->output_data.x->current_cursor |
2331 | = f->output_data.x->text_cursor); | |
8fc2766b | 2332 | |
4d7e6e51 | 2333 | unblock_input (); |
8fc2766b | 2334 | |
495fa05e GM |
2335 | /* This is a no-op, except under Motif. Make sure main areas are |
2336 | set to something reasonable, in case we get an error later. */ | |
2337 | lw_set_main_areas (pane_widget, 0, frame_widget); | |
8fc2766b RS |
2338 | } |
2339 | ||
9ef48a9d | 2340 | #else /* not USE_X_TOOLKIT */ |
488dd4c4 | 2341 | #ifdef USE_GTK |
f78faa98 | 2342 | static void |
a10c8269 | 2343 | x_window (struct frame *f) |
488dd4c4 JD |
2344 | { |
2345 | if (! xg_create_frame_widgets (f)) | |
2346 | error ("Unable to create window"); | |
1fcfb866 JD |
2347 | |
2348 | #ifdef HAVE_X_I18N | |
2349 | FRAME_XIC (f) = NULL; | |
6b61353c | 2350 | if (use_xim) |
1576f1ad | 2351 | { |
4d7e6e51 | 2352 | block_input (); |
1576f1ad DL |
2353 | create_frame_xic (f); |
2354 | if (FRAME_XIC (f)) | |
2355 | { | |
2356 | /* XIM server might require some X events. */ | |
2357 | unsigned long fevent = NoEventMask; | |
6b61353c | 2358 | XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL); |
1fcfb866 | 2359 | |
1576f1ad DL |
2360 | if (fevent != NoEventMask) |
2361 | { | |
2362 | XSetWindowAttributes attributes; | |
2363 | XWindowAttributes wattr; | |
2364 | unsigned long attribute_mask; | |
2365 | ||
2366 | XGetWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
2367 | &wattr); | |
2368 | attributes.event_mask = wattr.your_event_mask | fevent; | |
2369 | attribute_mask = CWEventMask; | |
2370 | XChangeWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
2371 | attribute_mask, &attributes); | |
2372 | } | |
2373 | } | |
4d7e6e51 | 2374 | unblock_input (); |
1576f1ad | 2375 | } |
1fcfb866 | 2376 | #endif |
488dd4c4 | 2377 | } |
9ef48a9d | 2378 | |
488dd4c4 | 2379 | #else /*! USE_GTK */ |
8fc2766b RS |
2380 | /* Create and set up the X window for frame F. */ |
2381 | ||
f78faa98 | 2382 | static void |
0521f580 | 2383 | x_window (struct frame *f) |
8fc2766b RS |
2384 | { |
2385 | XClassHint class_hints; | |
2386 | XSetWindowAttributes attributes; | |
2387 | unsigned long attribute_mask; | |
2388 | ||
5bcee7ef | 2389 | attributes.background_pixel = FRAME_BACKGROUND_PIXEL (f); |
7556890b | 2390 | attributes.border_pixel = f->output_data.x->border_pixel; |
01f1ba30 JB |
2391 | attributes.bit_gravity = StaticGravity; |
2392 | attributes.backing_store = NotUseful; | |
2393 | attributes.save_under = True; | |
2394 | attributes.event_mask = STANDARD_EVENT_SET; | |
9b2956e2 GM |
2395 | attributes.colormap = FRAME_X_COLORMAP (f); |
2396 | attribute_mask = (CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask | |
2397 | | CWColormap); | |
01f1ba30 | 2398 | |
4d7e6e51 | 2399 | block_input (); |
fe24a618 | 2400 | FRAME_X_WINDOW (f) |
b9dc4443 | 2401 | = XCreateWindow (FRAME_X_DISPLAY (f), |
7556890b | 2402 | f->output_data.x->parent_desc, |
be786000 KS |
2403 | f->left_pos, |
2404 | f->top_pos, | |
2405 | FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f), | |
2406 | f->border_width, | |
01f1ba30 JB |
2407 | CopyFromParent, /* depth */ |
2408 | InputOutput, /* class */ | |
383d6ffc | 2409 | FRAME_X_VISUAL (f), |
01f1ba30 | 2410 | attribute_mask, &attributes); |
5a7df7d7 GM |
2411 | |
2412 | #ifdef HAVE_X_I18N | |
4dacadcc | 2413 | if (use_xim) |
5a7df7d7 | 2414 | { |
1576f1ad DL |
2415 | create_frame_xic (f); |
2416 | if (FRAME_XIC (f)) | |
2417 | { | |
2418 | /* XIM server might require some X events. */ | |
2419 | unsigned long fevent = NoEventMask; | |
6b61353c | 2420 | XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL); |
1576f1ad DL |
2421 | attributes.event_mask |= fevent; |
2422 | attribute_mask = CWEventMask; | |
2423 | XChangeWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
2424 | attribute_mask, &attributes); | |
2425 | } | |
5a7df7d7 GM |
2426 | } |
2427 | #endif /* HAVE_X_I18N */ | |
177c0ea7 | 2428 | |
d387c960 | 2429 | validate_x_resource_name (); |
b7975ee4 | 2430 | |
51b59d79 PE |
2431 | class_hints.res_name = SSDATA (Vx_resource_name); |
2432 | class_hints.res_class = SSDATA (Vx_resource_class); | |
b9dc4443 | 2433 | XSetClassHint (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &class_hints); |
01f1ba30 | 2434 | |
00983aba KH |
2435 | /* The menubar is part of the ordinary display; |
2436 | it does not count in addition to the height of the window. */ | |
7556890b | 2437 | f->output_data.x->menubar_height = 0; |
00983aba | 2438 | |
179956b9 JB |
2439 | /* This indicates that we use the "Passive Input" input model. |
2440 | Unless we do this, we don't get the Focus{In,Out} events that we | |
2441 | need to draw the cursor correctly. Accursed bureaucrats. | |
b9dc4443 | 2442 | XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */ |
179956b9 | 2443 | |
7556890b RS |
2444 | f->output_data.x->wm_hints.input = True; |
2445 | f->output_data.x->wm_hints.flags |= InputHint; | |
b9dc4443 | 2446 | XSetWMHints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
7556890b | 2447 | &f->output_data.x->wm_hints); |
6d078211 | 2448 | f->output_data.x->wm_hints.icon_pixmap = None; |
179956b9 | 2449 | |
032e4ebe RS |
2450 | /* Request "save yourself" and "delete window" commands from wm. */ |
2451 | { | |
2452 | Atom protocols[2]; | |
aad3612f DA |
2453 | protocols[0] = FRAME_DISPLAY_INFO (f)->Xatom_wm_delete_window; |
2454 | protocols[1] = FRAME_DISPLAY_INFO (f)->Xatom_wm_save_yourself; | |
b9dc4443 | 2455 | XSetWMProtocols (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), protocols, 2); |
032e4ebe | 2456 | } |
9ef48a9d | 2457 | |
e373f201 JB |
2458 | /* x_set_name normally ignores requests to set the name if the |
2459 | requested name is the same as the current name. This is the one | |
2460 | place where that assumption isn't correct; f->name is set, but | |
2461 | the X server hasn't been told. */ | |
2462 | { | |
98381190 | 2463 | Lisp_Object name; |
cf177271 | 2464 | int explicit = f->explicit_name; |
e373f201 | 2465 | |
cf177271 | 2466 | f->explicit_name = 0; |
e69b0960 | 2467 | name = f->name; |
f00af5b1 | 2468 | fset_name (f, Qnil); |
cf177271 | 2469 | x_set_name (f, name, explicit); |
e373f201 JB |
2470 | } |
2471 | ||
b9dc4443 | 2472 | XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
72ec0c8d JD |
2473 | f->output_data.x->current_cursor |
2474 | = f->output_data.x->text_cursor); | |
9ef48a9d | 2475 | |
4d7e6e51 | 2476 | unblock_input (); |
01f1ba30 | 2477 | |
fe24a618 | 2478 | if (FRAME_X_WINDOW (f) == 0) |
9ef48a9d | 2479 | error ("Unable to create window"); |
01f1ba30 JB |
2480 | } |
2481 | ||
488dd4c4 | 2482 | #endif /* not USE_GTK */ |
8fc2766b RS |
2483 | #endif /* not USE_X_TOOLKIT */ |
2484 | ||
289978b5 LT |
2485 | /* Verify that the icon position args for this window are valid. */ |
2486 | ||
2487 | static void | |
971de7fb | 2488 | x_icon_verify (struct frame *f, Lisp_Object parms) |
289978b5 LT |
2489 | { |
2490 | Lisp_Object icon_x, icon_y; | |
2491 | ||
2492 | /* Set the position of the icon. Note that twm groups all | |
2493 | icons in an icon window. */ | |
2494 | icon_x = x_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER); | |
2495 | icon_y = x_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER); | |
2496 | if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound)) | |
2497 | { | |
2498 | CHECK_NUMBER (icon_x); | |
2499 | CHECK_NUMBER (icon_y); | |
2500 | } | |
2501 | else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound)) | |
2502 | error ("Both left and top icon corners of icon must be specified"); | |
2503 | } | |
2504 | ||
01f1ba30 JB |
2505 | /* Handle the icon stuff for this window. Perhaps later we might |
2506 | want an x_set_icon_position which can be called interactively as | |
b9dc4443 | 2507 | well. */ |
01f1ba30 JB |
2508 | |
2509 | static void | |
971de7fb | 2510 | x_icon (struct frame *f, Lisp_Object parms) |
01f1ba30 | 2511 | { |
f9942c9e | 2512 | Lisp_Object icon_x, icon_y; |
fd0f53a9 | 2513 | #if 0 |
aad3612f | 2514 | struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); |
fd0f53a9 | 2515 | #endif |
01f1ba30 JB |
2516 | |
2517 | /* Set the position of the icon. Note that twm groups all | |
b9dc4443 | 2518 | icons in an icon window. */ |
7c0d3ed8 KS |
2519 | icon_x = x_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER); |
2520 | icon_y = x_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER); | |
f9942c9e | 2521 | if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound)) |
01f1ba30 | 2522 | { |
d311d28c PE |
2523 | CHECK_TYPE_RANGED_INTEGER (int, icon_x); |
2524 | CHECK_TYPE_RANGED_INTEGER (int, icon_y); | |
01f1ba30 | 2525 | } |
f9942c9e | 2526 | else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound)) |
01f1ba30 | 2527 | error ("Both left and top icon corners of icon must be specified"); |
01f1ba30 | 2528 | |
4d7e6e51 | 2529 | block_input (); |
f9942c9e | 2530 | |
fe24a618 JB |
2531 | if (! EQ (icon_x, Qunbound)) |
2532 | x_wm_set_icon_position (f, XINT (icon_x), XINT (icon_y)); | |
f9942c9e | 2533 | |
a9d54793 KL |
2534 | #if 0 /* x_get_arg removes the visibility parameter as a side effect, |
2535 | but x_create_frame still needs it. */ | |
01f1ba30 | 2536 | /* Start up iconic or window? */ |
49795535 | 2537 | x_wm_set_window_state |
333b20bb GM |
2538 | (f, (EQ (x_get_arg (dpyinfo, parms, Qvisibility, 0, 0, RES_TYPE_SYMBOL), |
2539 | Qicon) | |
49795535 JB |
2540 | ? IconicState |
2541 | : NormalState)); | |
a9d54793 | 2542 | #endif |
01f1ba30 | 2543 | |
e69b0960 DA |
2544 | x_text_icon (f, SSDATA ((!NILP (f->icon_name) |
2545 | ? f->icon_name | |
2546 | : f->name))); | |
80534dd6 | 2547 | |
4d7e6e51 | 2548 | unblock_input (); |
01f1ba30 JB |
2549 | } |
2550 | ||
b243755a | 2551 | /* Make the GCs needed for this window, setting the |
01f1ba30 JB |
2552 | background, border and mouse colors; also create the |
2553 | mouse cursor and the gray border tile. */ | |
2554 | ||
2555 | static void | |
971de7fb | 2556 | x_make_gc (struct frame *f) |
01f1ba30 JB |
2557 | { |
2558 | XGCValues gc_values; | |
01f1ba30 | 2559 | |
4d7e6e51 | 2560 | block_input (); |
6afb1d07 | 2561 | |
b243755a | 2562 | /* Create the GCs of this frame. |
9ef48a9d | 2563 | Note that many default values are used. */ |
01f1ba30 | 2564 | |
ce593f6e KL |
2565 | gc_values.foreground = FRAME_FOREGROUND_PIXEL (f); |
2566 | gc_values.background = FRAME_BACKGROUND_PIXEL (f); | |
9ef48a9d | 2567 | gc_values.line_width = 0; /* Means 1 using fast algorithm. */ |
959e647d GM |
2568 | f->output_data.x->normal_gc |
2569 | = XCreateGC (FRAME_X_DISPLAY (f), | |
2570 | FRAME_X_WINDOW (f), | |
b51238f5 | 2571 | GCLineWidth | GCForeground | GCBackground, |
959e647d | 2572 | &gc_values); |
01f1ba30 | 2573 | |
b9dc4443 | 2574 | /* Reverse video style. */ |
ce593f6e KL |
2575 | gc_values.foreground = FRAME_BACKGROUND_PIXEL (f); |
2576 | gc_values.background = FRAME_FOREGROUND_PIXEL (f); | |
959e647d GM |
2577 | f->output_data.x->reverse_gc |
2578 | = XCreateGC (FRAME_X_DISPLAY (f), | |
2579 | FRAME_X_WINDOW (f), | |
b51238f5 | 2580 | GCForeground | GCBackground | GCLineWidth, |
959e647d | 2581 | &gc_values); |
01f1ba30 | 2582 | |
9ef48a9d | 2583 | /* Cursor has cursor-color background, background-color foreground. */ |
ce593f6e | 2584 | gc_values.foreground = FRAME_BACKGROUND_PIXEL (f); |
7556890b | 2585 | gc_values.background = f->output_data.x->cursor_pixel; |
01f1ba30 | 2586 | gc_values.fill_style = FillOpaqueStippled; |
7556890b | 2587 | f->output_data.x->cursor_gc |
b9dc4443 | 2588 | = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
b51238f5 | 2589 | (GCForeground | GCBackground |
c8bcd18a | 2590 | | GCFillStyle | GCLineWidth), |
01f1ba30 JB |
2591 | &gc_values); |
2592 | ||
2593 | /* Create the gray border tile used when the pointer is not in | |
f676886a | 2594 | the frame. Since this depends on the frame's pixel values, |
9ef48a9d | 2595 | this must be done on a per-frame basis. */ |
7556890b | 2596 | f->output_data.x->border_tile |
d043f1a4 | 2597 | = (XCreatePixmapFromBitmapData |
aad3612f | 2598 | (FRAME_X_DISPLAY (f), FRAME_DISPLAY_INFO (f)->root_window, |
d043f1a4 | 2599 | gray_bits, gray_width, gray_height, |
ce593f6e KL |
2600 | FRAME_FOREGROUND_PIXEL (f), |
2601 | FRAME_BACKGROUND_PIXEL (f), | |
ab452f99 | 2602 | DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f)))); |
6afb1d07 | 2603 | |
4d7e6e51 | 2604 | unblock_input (); |
01f1ba30 | 2605 | } |
01f1ba30 | 2606 | |
959e647d | 2607 | |
2b34df4e | 2608 | /* Free what was allocated in x_make_gc. */ |
959e647d GM |
2609 | |
2610 | void | |
971de7fb | 2611 | x_free_gcs (struct frame *f) |
959e647d GM |
2612 | { |
2613 | Display *dpy = FRAME_X_DISPLAY (f); | |
2614 | ||
4d7e6e51 | 2615 | block_input (); |
177c0ea7 | 2616 | |
959e647d GM |
2617 | if (f->output_data.x->normal_gc) |
2618 | { | |
2619 | XFreeGC (dpy, f->output_data.x->normal_gc); | |
2620 | f->output_data.x->normal_gc = 0; | |
2621 | } | |
2622 | ||
2623 | if (f->output_data.x->reverse_gc) | |
2624 | { | |
2625 | XFreeGC (dpy, f->output_data.x->reverse_gc); | |
2626 | f->output_data.x->reverse_gc = 0; | |
2627 | } | |
177c0ea7 | 2628 | |
959e647d GM |
2629 | if (f->output_data.x->cursor_gc) |
2630 | { | |
2631 | XFreeGC (dpy, f->output_data.x->cursor_gc); | |
2632 | f->output_data.x->cursor_gc = 0; | |
2633 | } | |
2634 | ||
2635 | if (f->output_data.x->border_tile) | |
2636 | { | |
2637 | XFreePixmap (dpy, f->output_data.x->border_tile); | |
2638 | f->output_data.x->border_tile = 0; | |
2639 | } | |
2640 | ||
4d7e6e51 | 2641 | unblock_input (); |
959e647d GM |
2642 | } |
2643 | ||
2644 | ||
eaf1eea9 | 2645 | /* Handler for signals raised during x_create_frame and |
c9e7db78 | 2646 | x_create_tip_frame. FRAME is the frame which is partially |
eaf1eea9 GM |
2647 | constructed. */ |
2648 | ||
2649 | static Lisp_Object | |
971de7fb | 2650 | unwind_create_frame (Lisp_Object frame) |
eaf1eea9 GM |
2651 | { |
2652 | struct frame *f = XFRAME (frame); | |
2653 | ||
8346e08b KL |
2654 | /* If frame is already dead, nothing to do. This can happen if the |
2655 | display is disconnected after the frame has become official, but | |
2656 | before x_create_frame removes the unwind protect. */ | |
2657 | if (!FRAME_LIVE_P (f)) | |
2658 | return Qnil; | |
2659 | ||
eaf1eea9 | 2660 | /* If frame is ``official'', nothing to do. */ |
97f18cc8 | 2661 | if (NILP (Fmemq (frame, Vframe_list))) |
eaf1eea9 | 2662 | { |
e509cfa6 | 2663 | #if defined GLYPH_DEBUG && defined ENABLE_CHECKING |
aad3612f | 2664 | struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); |
eaf1eea9 | 2665 | #endif |
177c0ea7 | 2666 | |
eaf1eea9 | 2667 | x_free_frame_resources (f); |
2a58bbc1 | 2668 | free_glyphs (f); |
eaf1eea9 | 2669 | |
e509cfa6 | 2670 | #if defined GLYPH_DEBUG && defined ENABLE_CHECKING |
eaf1eea9 | 2671 | /* Check that reference counts are indeed correct. */ |
a54e2c05 DA |
2672 | eassert (dpyinfo->reference_count == dpyinfo_refcount); |
2673 | eassert (dpyinfo->terminal->image_cache->refcount == image_cache_refcount); | |
5b3f8550 | 2674 | #endif |
c844a81a | 2675 | return Qt; |
eaf1eea9 | 2676 | } |
177c0ea7 | 2677 | |
eaf1eea9 GM |
2678 | return Qnil; |
2679 | } | |
2680 | ||
27e498e6 PE |
2681 | static void |
2682 | do_unwind_create_frame (Lisp_Object frame) | |
2683 | { | |
2684 | unwind_create_frame (frame); | |
2685 | } | |
2686 | ||
2687 | static void | |
f01d3321 CY |
2688 | unwind_create_frame_1 (Lisp_Object val) |
2689 | { | |
d1f55f16 | 2690 | inhibit_lisp_code = val; |
f01d3321 | 2691 | } |
b51238f5 | 2692 | |
02ed2ea8 | 2693 | static void |
971de7fb | 2694 | x_default_font_parameter (struct frame *f, Lisp_Object parms) |
02ed2ea8 | 2695 | { |
aad3612f | 2696 | struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f); |
770e2e6e | 2697 | Lisp_Object font_param = x_get_arg (dpyinfo, parms, Qfont, NULL, NULL, |
637fa988 | 2698 | RES_TYPE_STRING); |
e9b7ab96 | 2699 | Lisp_Object font = Qnil; |
770e2e6e | 2700 | if (EQ (font_param, Qunbound)) |
0d1d0d26 JD |
2701 | font_param = Qnil; |
2702 | ||
2703 | if (NILP (font_param)) | |
637fa988 | 2704 | { |
e1dbe924 | 2705 | /* System font should take precedence over X resources. We suggest this |
0d1d0d26 JD |
2706 | regardless of font-use-system-font because .emacs may not have been |
2707 | read yet. */ | |
2708 | const char *system_font = xsettings_get_system_font (); | |
e9b7ab96 | 2709 | if (system_font) |
d7ea76b4 | 2710 | font = font_open_by_name (f, build_unibyte_string (system_font)); |
637fa988 | 2711 | } |
0d1d0d26 | 2712 | |
e9b7ab96 JD |
2713 | if (NILP (font)) |
2714 | font = !NILP (font_param) ? font_param | |
2715 | : x_get_arg (dpyinfo, parms, Qfont, "font", "Font", RES_TYPE_STRING); | |
2716 | ||
2717 | if (! FONTP (font) && ! STRINGP (font)) | |
02ed2ea8 | 2718 | { |
675e2c69 | 2719 | const char *names[] |
be9d013a CY |
2720 | = { |
2721 | #ifdef HAVE_XFT | |
d7afccca | 2722 | /* This will find the normal Xft font. */ |
c024ac08 | 2723 | "monospace-10", |
be9d013a CY |
2724 | #endif |
2725 | "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1", | |
2726 | "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1", | |
02ed2ea8 KH |
2727 | "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1", |
2728 | /* This was formerly the first thing tried, but it finds | |
2729 | too many fonts and takes too long. */ | |
2730 | "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1", | |
2731 | /* If those didn't work, look for something which will | |
2732 | at least work. */ | |
2733 | "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1", | |
25c25256 | 2734 | "fixed", |
02ed2ea8 KH |
2735 | NULL }; |
2736 | int i; | |
2737 | ||
2738 | for (i = 0; names[i]; i++) | |
2739 | { | |
d7ea76b4 | 2740 | font = font_open_by_name (f, build_unibyte_string (names[i])); |
02ed2ea8 KH |
2741 | if (! NILP (font)) |
2742 | break; | |
2743 | } | |
2744 | if (NILP (font)) | |
25c25256 | 2745 | error ("No suitable font was found"); |
02ed2ea8 | 2746 | } |
770e2e6e | 2747 | else if (!NILP (font_param)) |
27129af9 SM |
2748 | { |
2749 | /* Remember the explicit font parameter, so we can re-apply it after | |
2750 | we've applied the `default' face settings. */ | |
6c6f1994 | 2751 | x_set_frame_parameters (f, list1 (Fcons (Qfont_param, font_param))); |
770e2e6e | 2752 | } |
637fa988 | 2753 | |
5fc8e5bc J |
2754 | /* This call will make X resources override any system font setting. */ |
2755 | x_default_parameter (f, parms, Qfont, font, "font", "Font", RES_TYPE_STRING); | |
02ed2ea8 | 2756 | } |
b51238f5 | 2757 | |
eaf1eea9 | 2758 | |
1c44e124 CY |
2759 | DEFUN ("x-wm-set-size-hint", Fx_wm_set_size_hint, Sx_wm_set_size_hint, |
2760 | 0, 1, 0, | |
2761 | doc: /* Send the size hints for frame FRAME to the window manager. | |
5890e400 DA |
2762 | If FRAME is omitted or nil, use the selected frame. |
2763 | Signal error if FRAME is not an X frame. */) | |
5842a27b | 2764 | (Lisp_Object frame) |
1c44e124 | 2765 | { |
7452b7bd | 2766 | struct frame *f = decode_window_system_frame (frame); |
5890e400 | 2767 | |
4d7e6e51 | 2768 | block_input (); |
5890e400 | 2769 | x_wm_set_size_hint (f, 0, 0); |
4d7e6e51 | 2770 | unblock_input (); |
653a3150 | 2771 | return Qnil; |
1c44e124 CY |
2772 | } |
2773 | ||
3e6bec3b JD |
2774 | static void |
2775 | set_machine_and_pid_properties (struct frame *f) | |
2776 | { | |
ac61e7e1 | 2777 | long pid = (long) getpid (); |
3e6bec3b | 2778 | |
66b16767 J |
2779 | /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME. */ |
2780 | XSetWMProperties (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), NULL, NULL, | |
2781 | NULL, 0, NULL, NULL, NULL); | |
3e6bec3b JD |
2782 | XChangeProperty (FRAME_X_DISPLAY (f), |
2783 | FRAME_OUTER_WINDOW (f), | |
2784 | XInternAtom (FRAME_X_DISPLAY (f), | |
2785 | "_NET_WM_PID", | |
2786 | False), | |
2787 | XA_CARDINAL, 32, PropModeReplace, | |
2788 | (unsigned char *) &pid, 1); | |
2789 | } | |
2790 | ||
f676886a | 2791 | DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame, |
01f1ba30 | 2792 | 1, 1, 0, |
7ee72033 | 2793 | doc: /* Make a new X window, which is called a "frame" in Emacs terms. |
d29a9848 | 2794 | Return an Emacs frame object. |
e0079d39 | 2795 | PARMS is an alist of frame parameters. |
c061c855 GM |
2796 | If the parameters specify that the frame should not have a minibuffer, |
2797 | and do not specify a specific minibuffer window to use, | |
2798 | then `default-minibuffer-frame' must be a frame whose minibuffer can | |
2799 | be shared by the new frame. | |
2800 | ||
7ee72033 | 2801 | This function is an internal primitive--use `make-frame' instead. */) |
5842a27b | 2802 | (Lisp_Object parms) |
01f1ba30 | 2803 | { |
f676886a | 2804 | struct frame *f; |
2365c027 | 2805 | Lisp_Object frame, tem; |
01f1ba30 JB |
2806 | Lisp_Object name; |
2807 | int minibuffer_only = 0; | |
2808 | long window_prompting = 0; | |
45d45af5 | 2809 | int width, height; |
d311d28c | 2810 | ptrdiff_t count = SPECPDL_INDEX (); |
ecaca587 | 2811 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
b9dc4443 | 2812 | Lisp_Object display; |
333b20bb | 2813 | struct x_display_info *dpyinfo = NULL; |
a59e4f3d | 2814 | Lisp_Object parent; |
e557f19d | 2815 | struct kboard *kb; |
01f1ba30 | 2816 | |
5fa98fcf RS |
2817 | parms = Fcopy_alist (parms); |
2818 | ||
b7975ee4 KH |
2819 | /* Use this general default value to start with |
2820 | until we know if this frame has a specified name. */ | |
2821 | Vx_resource_name = Vinvocation_name; | |
2822 | ||
6ed8eeff | 2823 | display = x_get_arg (dpyinfo, parms, Qterminal, 0, 0, RES_TYPE_NUMBER); |
1705c933 | 2824 | if (EQ (display, Qunbound)) |
b6660415 | 2825 | display = x_get_arg (dpyinfo, parms, Qdisplay, 0, 0, RES_TYPE_STRING); |
b9dc4443 RS |
2826 | if (EQ (display, Qunbound)) |
2827 | display = Qnil; | |
2828 | dpyinfo = check_x_display_info (display); | |
6ed8eeff | 2829 | kb = dpyinfo->terminal->kboard; |
b9dc4443 | 2830 | |
89acb56d SM |
2831 | if (!dpyinfo->terminal->name) |
2832 | error ("Terminal is not live, can't create new frames on it"); | |
ab797f65 | 2833 | |
333b20bb | 2834 | name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING); |
6a5e54e2 | 2835 | if (!STRINGP (name) |
cf177271 JB |
2836 | && ! EQ (name, Qunbound) |
2837 | && ! NILP (name)) | |
08a90d6a | 2838 | error ("Invalid frame name--not a string or nil"); |
01f1ba30 | 2839 | |
b7975ee4 KH |
2840 | if (STRINGP (name)) |
2841 | Vx_resource_name = name; | |
2842 | ||
a59e4f3d | 2843 | /* See if parent window is specified. */ |
333b20bb | 2844 | parent = x_get_arg (dpyinfo, parms, Qparent_id, NULL, NULL, RES_TYPE_NUMBER); |
a59e4f3d RS |
2845 | if (EQ (parent, Qunbound)) |
2846 | parent = Qnil; | |
2847 | if (! NILP (parent)) | |
b7826503 | 2848 | CHECK_NUMBER (parent); |
a59e4f3d | 2849 | |
ecaca587 RS |
2850 | /* make_frame_without_minibuffer can run Lisp code and garbage collect. */ |
2851 | /* No need to protect DISPLAY because that's not used after passing | |
2852 | it to make_frame_without_minibuffer. */ | |
2853 | frame = Qnil; | |
2854 | GCPRO4 (parms, parent, name, frame); | |
333b20bb GM |
2855 | tem = x_get_arg (dpyinfo, parms, Qminibuffer, "minibuffer", "Minibuffer", |
2856 | RES_TYPE_SYMBOL); | |
f9942c9e | 2857 | if (EQ (tem, Qnone) || NILP (tem)) |
2526c290 | 2858 | f = make_frame_without_minibuffer (Qnil, kb, display); |
f9942c9e | 2859 | else if (EQ (tem, Qonly)) |
01f1ba30 | 2860 | { |
f676886a | 2861 | f = make_minibuffer_frame (); |
01f1ba30 JB |
2862 | minibuffer_only = 1; |
2863 | } | |
6a5e54e2 | 2864 | else if (WINDOWP (tem)) |
2526c290 | 2865 | f = make_frame_without_minibuffer (tem, kb, display); |
f9942c9e JB |
2866 | else |
2867 | f = make_frame (1); | |
01f1ba30 | 2868 | |
ecaca587 RS |
2869 | XSETFRAME (frame, f); |
2870 | ||
6ed8eeff | 2871 | f->terminal = dpyinfo->terminal; |
428a555e | 2872 | |
08a90d6a | 2873 | f->output_method = output_x_window; |
38182d90 | 2874 | f->output_data.x = xzalloc (sizeof *f->output_data.x); |
7556890b | 2875 | f->output_data.x->icon_bitmap = -1; |
be786000 | 2876 | FRAME_FONTSET (f) = -1; |
333b20bb GM |
2877 | f->output_data.x->scroll_bar_foreground_pixel = -1; |
2878 | f->output_data.x->scroll_bar_background_pixel = -1; | |
f15340b7 MB |
2879 | #ifdef USE_TOOLKIT_SCROLL_BARS |
2880 | f->output_data.x->scroll_bar_top_shadow_pixel = -1; | |
2881 | f->output_data.x->scroll_bar_bottom_shadow_pixel = -1; | |
2882 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | |
08a90d6a | 2883 | |
f00af5b1 PE |
2884 | fset_icon_name (f, |
2885 | x_get_arg (dpyinfo, parms, Qicon_name, "iconName", "Title", | |
2886 | RES_TYPE_STRING)); | |
e69b0960 | 2887 | if (! STRINGP (f->icon_name)) |
f00af5b1 | 2888 | fset_icon_name (f, Qnil); |
80534dd6 | 2889 | |
aad3612f | 2890 | FRAME_DISPLAY_INFO (f) = dpyinfo; |
e3d56613 | 2891 | |
aad3612f | 2892 | /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe. */ |
27e498e6 | 2893 | record_unwind_protect (do_unwind_create_frame, frame); |
08a90d6a | 2894 | |
9b2956e2 GM |
2895 | /* These colors will be set anyway later, but it's important |
2896 | to get the color reference counts right, so initialize them! */ | |
2897 | { | |
2898 | Lisp_Object black; | |
dbf31225 | 2899 | struct gcpro gcpro1; |
cefecbcf GM |
2900 | |
2901 | /* Function x_decode_color can signal an error. Make | |
2902 | sure to initialize color slots so that we won't try | |
2903 | to free colors we haven't allocated. */ | |
ce593f6e KL |
2904 | FRAME_FOREGROUND_PIXEL (f) = -1; |
2905 | FRAME_BACKGROUND_PIXEL (f) = -1; | |
cefecbcf GM |
2906 | f->output_data.x->cursor_pixel = -1; |
2907 | f->output_data.x->cursor_foreground_pixel = -1; | |
2908 | f->output_data.x->border_pixel = -1; | |
2909 | f->output_data.x->mouse_pixel = -1; | |
177c0ea7 | 2910 | |
9b2956e2 | 2911 | black = build_string ("black"); |
dbf31225 | 2912 | GCPRO1 (black); |
ce593f6e | 2913 | FRAME_FOREGROUND_PIXEL (f) |
9b2956e2 | 2914 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); |
ce593f6e | 2915 | FRAME_BACKGROUND_PIXEL (f) |
9b2956e2 GM |
2916 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); |
2917 | f->output_data.x->cursor_pixel | |
2918 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
2919 | f->output_data.x->cursor_foreground_pixel | |
2920 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
2921 | f->output_data.x->border_pixel | |
2922 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
2923 | f->output_data.x->mouse_pixel | |
2924 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
dbf31225 | 2925 | UNGCPRO; |
9b2956e2 GM |
2926 | } |
2927 | ||
a59e4f3d RS |
2928 | /* Specify the parent under which to make this X window. */ |
2929 | ||
2930 | if (!NILP (parent)) | |
2931 | { | |
8c239ac3 | 2932 | f->output_data.x->parent_desc = (Window) XFASTINT (parent); |
7556890b | 2933 | f->output_data.x->explicit_parent = 1; |
a59e4f3d RS |
2934 | } |
2935 | else | |
2936 | { | |
aad3612f | 2937 | f->output_data.x->parent_desc = FRAME_DISPLAY_INFO (f)->root_window; |
7556890b | 2938 | f->output_data.x->explicit_parent = 0; |
a59e4f3d RS |
2939 | } |
2940 | ||
cf177271 JB |
2941 | /* Set the name; the functions to which we pass f expect the name to |
2942 | be set. */ | |
2943 | if (EQ (name, Qunbound) || NILP (name)) | |
2944 | { | |
f00af5b1 | 2945 | fset_name (f, build_string (dpyinfo->x_id_name)); |
cf177271 JB |
2946 | f->explicit_name = 0; |
2947 | } | |
2948 | else | |
2949 | { | |
f00af5b1 | 2950 | fset_name (f, name); |
cf177271 | 2951 | f->explicit_name = 1; |
9ef48a9d RS |
2952 | /* use the frame's title when getting resources for this frame. */ |
2953 | specbind (Qx_resource_name, name); | |
cf177271 | 2954 | } |
01f1ba30 | 2955 | |
02ed2ea8 KH |
2956 | #ifdef HAVE_FREETYPE |
2957 | #ifdef HAVE_XFT | |
b51238f5 | 2958 | register_font_driver (&xftfont_driver, f); |
02ed2ea8 | 2959 | #else /* not HAVE_XFT */ |
b51238f5 | 2960 | register_font_driver (&ftxfont_driver, f); |
02ed2ea8 KH |
2961 | #endif /* not HAVE_XFT */ |
2962 | #endif /* HAVE_FREETYPE */ | |
6332668d | 2963 | register_font_driver (&xfont_driver, f); |
297cc20a | 2964 | |
b51238f5 KH |
2965 | x_default_parameter (f, parms, Qfont_backend, Qnil, |
2966 | "fontBackend", "FontBackend", RES_TYPE_STRING); | |
02ed2ea8 | 2967 | |
01f1ba30 JB |
2968 | /* Extract the window parameters from the supplied values |
2969 | that are needed to determine window geometry. */ | |
b51238f5 | 2970 | x_default_font_parameter (f, parms); |
62d168d8 CY |
2971 | if (!FRAME_FONT (f)) |
2972 | { | |
2973 | delete_frame (frame, Qnoelisp); | |
2974 | error ("Invalid frame font"); | |
2975 | } | |
9ef48a9d | 2976 | |
2532f20c JD |
2977 | /* Frame contents get displaced if an embedded X window has a border. */ |
2978 | if (! FRAME_X_EMBEDDED_P (f)) | |
4bef8d26 | 2979 | x_default_parameter (f, parms, Qborder_width, make_number (0), |
2532f20c | 2980 | "borderWidth", "BorderWidth", RES_TYPE_NUMBER); |
177c0ea7 | 2981 | |
4e397688 | 2982 | /* This defaults to 1 in order to match xterm. We recognize either |
ddf768c3 JB |
2983 | internalBorderWidth or internalBorder (which is what xterm calls |
2984 | it). */ | |
2985 | if (NILP (Fassq (Qinternal_border_width, parms))) | |
2986 | { | |
2987 | Lisp_Object value; | |
2988 | ||
abb4b7ec | 2989 | value = x_get_arg (dpyinfo, parms, Qinternal_border_width, |
333b20bb | 2990 | "internalBorder", "internalBorder", RES_TYPE_NUMBER); |
ddf768c3 JB |
2991 | if (! EQ (value, Qunbound)) |
2992 | parms = Fcons (Fcons (Qinternal_border_width, value), | |
2993 | parms); | |
2994 | } | |
a099c27a SM |
2995 | x_default_parameter (f, parms, Qinternal_border_width, |
2996 | #ifdef USE_GTK /* We used to impose 0 in xg_create_frame_widgets. */ | |
2997 | make_number (0), | |
2998 | #else | |
2999 | make_number (1), | |
3000 | #endif | |
333b20bb GM |
3001 | "internalBorderWidth", "internalBorderWidth", |
3002 | RES_TYPE_NUMBER); | |
303500aa | 3003 | x_default_parameter (f, parms, Qvertical_scroll_bars, |
5e617bc2 | 3004 | #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS) |
303500aa CY |
3005 | Qright, |
3006 | #else | |
3007 | Qleft, | |
3008 | #endif | |
333b20bb GM |
3009 | "verticalScrollBars", "ScrollBars", |
3010 | RES_TYPE_SYMBOL); | |
01f1ba30 | 3011 | |
b9dc4443 | 3012 | /* Also do the stuff which must be set before the window exists. */ |
cf177271 | 3013 | x_default_parameter (f, parms, Qforeground_color, build_string ("black"), |
333b20bb | 3014 | "foreground", "Foreground", RES_TYPE_STRING); |
cf177271 | 3015 | x_default_parameter (f, parms, Qbackground_color, build_string ("white"), |
0b60fc91 | 3016 | "background", "Background", RES_TYPE_STRING); |
cf177271 | 3017 | x_default_parameter (f, parms, Qmouse_color, build_string ("black"), |
333b20bb | 3018 | "pointerColor", "Foreground", RES_TYPE_STRING); |
cf177271 | 3019 | x_default_parameter (f, parms, Qborder_color, build_string ("black"), |
333b20bb | 3020 | "borderColor", "BorderColor", RES_TYPE_STRING); |
d62c8769 GM |
3021 | x_default_parameter (f, parms, Qscreen_gamma, Qnil, |
3022 | "screenGamma", "ScreenGamma", RES_TYPE_FLOAT); | |
563b67aa GM |
3023 | x_default_parameter (f, parms, Qline_spacing, Qnil, |
3024 | "lineSpacing", "LineSpacing", RES_TYPE_NUMBER); | |
b3ba0aa8 KS |
3025 | x_default_parameter (f, parms, Qleft_fringe, Qnil, |
3026 | "leftFringe", "LeftFringe", RES_TYPE_NUMBER); | |
3027 | x_default_parameter (f, parms, Qright_fringe, Qnil, | |
3028 | "rightFringe", "RightFringe", RES_TYPE_NUMBER); | |
333b20bb GM |
3029 | |
3030 | x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_foreground, | |
3031 | "scrollBarForeground", | |
3032 | "ScrollBarForeground", 1); | |
3033 | x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_background, | |
3034 | "scrollBarBackground", | |
3035 | "ScrollBarBackground", 0); | |
3036 | ||
e509cfa6 | 3037 | #ifdef GLYPH_DEBUG |
c9e7db78 JD |
3038 | image_cache_refcount = |
3039 | FRAME_IMAGE_CACHE (f) ? FRAME_IMAGE_CACHE (f)->refcount : 0; | |
3040 | dpyinfo_refcount = dpyinfo->reference_count; | |
3041 | #endif /* GLYPH_DEBUG */ | |
3042 | ||
333b20bb GM |
3043 | /* Init faces before x_default_parameter is called for scroll-bar |
3044 | parameters because that function calls x_set_scroll_bar_width, | |
3045 | which calls change_frame_size, which calls Fset_window_buffer, | |
3046 | which runs hooks, which call Fvertical_motion. At the end, we | |
3047 | end up in init_iterator with a null face cache, which should not | |
3048 | happen. */ | |
3049 | init_frame_faces (f); | |
177c0ea7 | 3050 | |
f01d3321 CY |
3051 | /* Set the menu-bar-lines and tool-bar-lines parameters. We don't |
3052 | look up the X resources controlling the menu-bar and tool-bar | |
3053 | here; they are processed specially at startup, and reflected in | |
3054 | the values of the mode variables. | |
3055 | ||
3056 | Avoid calling window-configuration-change-hook; otherwise we | |
3057 | could get an infloop in next_frame since the frame is not yet in | |
3058 | Vframe_list. */ | |
3059 | { | |
a89654f8 | 3060 | ptrdiff_t count2 = SPECPDL_INDEX (); |
d1f55f16 CY |
3061 | record_unwind_protect (unwind_create_frame_1, inhibit_lisp_code); |
3062 | inhibit_lisp_code = Qt; | |
f01d3321 CY |
3063 | |
3064 | x_default_parameter (f, parms, Qmenu_bar_lines, | |
3065 | NILP (Vmenu_bar_mode) | |
3066 | ? make_number (0) : make_number (1), | |
3067 | NULL, NULL, RES_TYPE_NUMBER); | |
3068 | x_default_parameter (f, parms, Qtool_bar_lines, | |
3069 | NILP (Vtool_bar_mode) | |
3070 | ? make_number (0) : make_number (1), | |
3071 | NULL, NULL, RES_TYPE_NUMBER); | |
3072 | ||
3073 | unbind_to (count2, Qnil); | |
3074 | } | |
6431f2e6 | 3075 | |
79873d50 | 3076 | x_default_parameter (f, parms, Qbuffer_predicate, Qnil, |
333b20bb GM |
3077 | "bufferPredicate", "BufferPredicate", |
3078 | RES_TYPE_SYMBOL); | |
c2304e02 | 3079 | x_default_parameter (f, parms, Qtitle, Qnil, |
333b20bb | 3080 | "title", "Title", RES_TYPE_STRING); |
ea0a1f53 GM |
3081 | x_default_parameter (f, parms, Qwait_for_wm, Qt, |
3082 | "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN); | |
49d41073 EZ |
3083 | x_default_parameter (f, parms, Qfullscreen, Qnil, |
3084 | "fullscreen", "Fullscreen", RES_TYPE_SYMBOL); | |
2b4e6277 | 3085 | x_default_parameter (f, parms, Qtool_bar_position, |
e69b0960 | 3086 | f->tool_bar_position, 0, 0, RES_TYPE_SYMBOL); |
90eb1019 | 3087 | |
35f59f6b | 3088 | /* Compute the size of the X window. */ |
7c0d3ed8 | 3089 | window_prompting = x_figure_window_size (f, parms, 1); |
38d22040 | 3090 | |
495fa05e GM |
3091 | tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN); |
3092 | f->no_split = minibuffer_only || EQ (tem, Qt); | |
3093 | ||
289978b5 LT |
3094 | x_icon_verify (f, parms); |
3095 | ||
6a1bcd01 | 3096 | /* Create the X widget or window. */ |
a7f7d550 FP |
3097 | #ifdef USE_X_TOOLKIT |
3098 | x_window (f, window_prompting, minibuffer_only); | |
3099 | #else | |
f676886a | 3100 | x_window (f); |
a7f7d550 | 3101 | #endif |
177c0ea7 | 3102 | |
f676886a JB |
3103 | x_icon (f, parms); |
3104 | x_make_gc (f); | |
01f1ba30 | 3105 | |
495fa05e | 3106 | /* Now consider the frame official. */ |
c9e7db78 | 3107 | f->terminal->reference_count++; |
aad3612f | 3108 | FRAME_DISPLAY_INFO (f)->reference_count++; |
495fa05e GM |
3109 | Vframe_list = Fcons (frame, Vframe_list); |
3110 | ||
f9942c9e JB |
3111 | /* We need to do this after creating the X window, so that the |
3112 | icon-creation functions can say whose icon they're describing. */ | |
84f25880 | 3113 | x_default_parameter (f, parms, Qicon_type, Qt, |
33ed493b | 3114 | "bitmapIcon", "BitmapIcon", RES_TYPE_BOOLEAN); |
f9942c9e | 3115 | |
cf177271 | 3116 | x_default_parameter (f, parms, Qauto_raise, Qnil, |
333b20bb | 3117 | "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN); |
cf177271 | 3118 | x_default_parameter (f, parms, Qauto_lower, Qnil, |
333b20bb | 3119 | "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN); |
dbc4e1c1 | 3120 | x_default_parameter (f, parms, Qcursor_type, Qbox, |
333b20bb | 3121 | "cursorType", "CursorType", RES_TYPE_SYMBOL); |
28d7281d GM |
3122 | x_default_parameter (f, parms, Qscroll_bar_width, Qnil, |
3123 | "scrollBarWidth", "ScrollBarWidth", | |
3124 | RES_TYPE_NUMBER); | |
271a71c7 GM |
3125 | x_default_parameter (f, parms, Qalpha, Qnil, |
3126 | "alpha", "Alpha", RES_TYPE_NUMBER); | |
f9942c9e | 3127 | |
be786000 | 3128 | /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size. |
01f1ba30 | 3129 | Change will not be effected unless different from the current |
be786000 KS |
3130 | FRAME_LINES (f). */ |
3131 | width = FRAME_COLS (f); | |
3132 | height = FRAME_LINES (f); | |
177c0ea7 | 3133 | |
be786000 KS |
3134 | SET_FRAME_COLS (f, 0); |
3135 | FRAME_LINES (f) = 0; | |
8938a4fb | 3136 | change_frame_size (f, height, width, 1, 0, 0); |
d043f1a4 | 3137 | |
488dd4c4 | 3138 | #if defined (USE_X_TOOLKIT) || defined (USE_GTK) |
495fa05e GM |
3139 | /* Create the menu bar. */ |
3140 | if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f)) | |
3141 | { | |
3142 | /* If this signals an error, we haven't set size hints for the | |
3143 | frame and we didn't make it visible. */ | |
3144 | initialize_frame_menubar (f); | |
3145 | ||
488dd4c4 | 3146 | #ifndef USE_GTK |
495fa05e GM |
3147 | /* This is a no-op, except under Motif where it arranges the |
3148 | main window for the widgets on it. */ | |
3149 | lw_set_main_areas (f->output_data.x->column_widget, | |
3150 | f->output_data.x->menubar_widget, | |
3151 | f->output_data.x->edit_widget); | |
488dd4c4 | 3152 | #endif /* not USE_GTK */ |
495fa05e | 3153 | } |
488dd4c4 | 3154 | #endif /* USE_X_TOOLKIT || USE_GTK */ |
495fa05e GM |
3155 | |
3156 | /* Tell the server what size and position, etc, we want, and how | |
3157 | badly we want them. This should be done after we have the menu | |
3158 | bar so that its size can be taken into account. */ | |
4d7e6e51 | 3159 | block_input (); |
7989f084 | 3160 | x_wm_set_size_hint (f, window_prompting, 0); |
4d7e6e51 | 3161 | unblock_input (); |
01f1ba30 | 3162 | |
495fa05e GM |
3163 | /* Make the window appear on the frame and enable display, unless |
3164 | the caller says not to. However, with explicit parent, Emacs | |
3165 | cannot control visibility, so don't try. */ | |
7556890b | 3166 | if (! f->output_data.x->explicit_parent) |
a59e4f3d RS |
3167 | { |
3168 | Lisp_Object visibility; | |
49795535 | 3169 | |
333b20bb GM |
3170 | visibility = x_get_arg (dpyinfo, parms, Qvisibility, 0, 0, |
3171 | RES_TYPE_SYMBOL); | |
a59e4f3d RS |
3172 | if (EQ (visibility, Qunbound)) |
3173 | visibility = Qt; | |
49795535 | 3174 | |
a59e4f3d RS |
3175 | if (EQ (visibility, Qicon)) |
3176 | x_iconify_frame (f); | |
3177 | else if (! NILP (visibility)) | |
3178 | x_make_frame_visible (f); | |
3179 | else | |
6b437900 PE |
3180 | { |
3181 | /* Must have been Qnil. */ | |
3182 | } | |
a59e4f3d | 3183 | } |
01f1ba30 | 3184 | |
4d7e6e51 | 3185 | block_input (); |
717c30e0 | 3186 | |
3e6bec3b | 3187 | /* Set machine name and pid for the purpose of window managers. */ |
5e617bc2 | 3188 | set_machine_and_pid_properties (f); |
3e6bec3b | 3189 | |
6b61353c KH |
3190 | /* Set the WM leader property. GTK does this itself, so this is not |
3191 | needed when using GTK. */ | |
3192 | if (dpyinfo->client_leader_window != 0) | |
3193 | { | |
6b61353c KH |
3194 | XChangeProperty (FRAME_X_DISPLAY (f), |
3195 | FRAME_OUTER_WINDOW (f), | |
3196 | dpyinfo->Xatom_wm_client_leader, | |
3197 | XA_WINDOW, 32, PropModeReplace, | |
47c53789 | 3198 | (unsigned char *) &dpyinfo->client_leader_window, 1); |
6b61353c KH |
3199 | } |
3200 | ||
4d7e6e51 | 3201 | unblock_input (); |
3e6bec3b | 3202 | |
225c13a5 | 3203 | /* Initialize `default-minibuffer-frame' in case this is the first |
6ed8eeff | 3204 | frame on this terminal. */ |
225c13a5 | 3205 | if (FRAME_HAS_MINIBUF_P (f) |
1344aad4 TT |
3206 | && (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame)) |
3207 | || !FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))) | |
15dbb4d6 | 3208 | kset_default_minibuffer_frame (kb, frame); |
225c13a5 | 3209 | |
5fa98fcf RS |
3210 | /* All remaining specified parameters, which have not been "used" |
3211 | by x_get_arg and friends, now go in the misc. alist of the frame. */ | |
9beb8baa | 3212 | for (tem = parms; CONSP (tem); tem = XCDR (tem)) |
5fa98fcf | 3213 | if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem)))) |
f00af5b1 | 3214 | fset_param_alist (f, Fcons (XCAR (tem), f->param_alist)); |
5fa98fcf | 3215 | |
495fa05e | 3216 | UNGCPRO; |
9e57df62 GM |
3217 | |
3218 | /* Make sure windows on this frame appear in calls to next-window | |
3219 | and similar functions. */ | |
3220 | Vwindow_list = Qnil; | |
177c0ea7 | 3221 | |
9ef48a9d | 3222 | return unbind_to (count, frame); |
01f1ba30 JB |
3223 | } |
3224 | ||
eaf1eea9 | 3225 | |
0d17d282 KH |
3226 | /* FRAME is used only to get a handle on the X display. We don't pass the |
3227 | display info directly because we're called from frame.c, which doesn't | |
3228 | know about that structure. */ | |
e4f79258 | 3229 | |
87498171 | 3230 | Lisp_Object |
971de7fb | 3231 | x_get_focus_frame (struct frame *frame) |
87498171 | 3232 | { |
aad3612f | 3233 | struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (frame); |
87498171 | 3234 | Lisp_Object xfocus; |
0d17d282 | 3235 | if (! dpyinfo->x_focus_frame) |
87498171 KH |
3236 | return Qnil; |
3237 | ||
0d17d282 | 3238 | XSETFRAME (xfocus, dpyinfo->x_focus_frame); |
87498171 KH |
3239 | return xfocus; |
3240 | } | |
f0614854 | 3241 | |
3decc1e7 GM |
3242 | |
3243 | /* In certain situations, when the window manager follows a | |
3244 | click-to-focus policy, there seems to be no way around calling | |
3245 | XSetInputFocus to give another frame the input focus . | |
3246 | ||
3247 | In an ideal world, XSetInputFocus should generally be avoided so | |
3248 | that applications don't interfere with the window manager's focus | |
3249 | policy. But I think it's okay to use when it's clearly done | |
3250 | following a user-command. */ | |
3251 | ||
fcd42c11 DA |
3252 | void |
3253 | x_focus_frame (struct frame *f) | |
3decc1e7 | 3254 | { |
3decc1e7 | 3255 | Display *dpy = FRAME_X_DISPLAY (f); |
3decc1e7 | 3256 | |
4d7e6e51 | 3257 | block_input (); |
9ba8e10d | 3258 | x_catch_errors (dpy); |
75bf0d33 DB |
3259 | |
3260 | if (FRAME_X_EMBEDDED_P (f)) | |
3261 | { | |
3262 | /* For Xembedded frames, normally the embedder forwards key | |
3263 | events. See XEmbed Protocol Specification at | |
3264 | http://freedesktop.org/wiki/Specifications/xembed-spec */ | |
3265 | xembed_request_focus (f); | |
3266 | } | |
3267 | else | |
3268 | { | |
3269 | XSetInputFocus (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), | |
3270 | RevertToParent, CurrentTime); | |
3271 | x_ewmh_activate_frame (f); | |
3272 | } | |
3273 | ||
4545fa20 | 3274 | x_uncatch_errors (); |
4d7e6e51 | 3275 | unblock_input (); |
3decc1e7 GM |
3276 | } |
3277 | ||
f0614854 | 3278 | \f |
2d764c78 | 3279 | DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0, |
4f4f2973 GM |
3280 | doc: /* Internal function called by `color-defined-p', which see |
3281 | .\(Note that the Nextstep version of this function ignores FRAME.) */) | |
5842a27b | 3282 | (Lisp_Object color, Lisp_Object frame) |
e12d55b2 | 3283 | { |
b9dc4443 | 3284 | XColor foo; |
a10c8269 | 3285 | struct frame *f = decode_window_system_frame (frame); |
e12d55b2 | 3286 | |
b7826503 | 3287 | CHECK_STRING (color); |
b9dc4443 | 3288 | |
42a5b22f | 3289 | if (x_defined_color (f, SSDATA (color), &foo, 0)) |
e12d55b2 RS |
3290 | return Qt; |
3291 | else | |
3292 | return Qnil; | |
3293 | } | |
3294 | ||
2d764c78 | 3295 | DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0, |
7ee72033 | 3296 | doc: /* Internal function called by `color-values', which see. */) |
5842a27b | 3297 | (Lisp_Object color, Lisp_Object frame) |
01f1ba30 | 3298 | { |
b9dc4443 | 3299 | XColor foo; |
a10c8269 | 3300 | struct frame *f = decode_window_system_frame (frame); |
b9dc4443 | 3301 | |
b7826503 | 3302 | CHECK_STRING (color); |
01f1ba30 | 3303 | |
42a5b22f | 3304 | if (x_defined_color (f, SSDATA (color), &foo, 0)) |
3de717bd | 3305 | return list3i (foo.red, foo.green, foo.blue); |
01f1ba30 JB |
3306 | else |
3307 | return Qnil; | |
3308 | } | |
3309 | ||
a7ca3326 | 3310 | DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0, |
7ee72033 | 3311 | doc: /* Internal function called by `display-color-p', which see. */) |
5842a27b | 3312 | (Lisp_Object terminal) |
01f1ba30 | 3313 | { |
6ed8eeff | 3314 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
11ae94fe | 3315 | |
b9dc4443 | 3316 | if (dpyinfo->n_planes <= 2) |
01f1ba30 JB |
3317 | return Qnil; |
3318 | ||
b9dc4443 | 3319 | switch (dpyinfo->visual->class) |
01f1ba30 JB |
3320 | { |
3321 | case StaticColor: | |
3322 | case PseudoColor: | |
3323 | case TrueColor: | |
3324 | case DirectColor: | |
3325 | return Qt; | |
3326 | ||
3327 | default: | |
3328 | return Qnil; | |
3329 | } | |
3330 | } | |
3331 | ||
a7ca3326 | 3332 | DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, Sx_display_grayscale_p, |
c061c855 | 3333 | 0, 1, 0, |
7ee72033 | 3334 | doc: /* Return t if the X display supports shades of gray. |
c061c855 | 3335 | Note that color displays do support shades of gray. |
6ed8eeff | 3336 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3337 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3338 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3339 | (Lisp_Object terminal) |
d0c9d219 | 3340 | { |
6ed8eeff | 3341 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
d0c9d219 | 3342 | |
ae6b58f9 | 3343 | if (dpyinfo->n_planes <= 1) |
b9dc4443 RS |
3344 | return Qnil; |
3345 | ||
ae6b58f9 RS |
3346 | switch (dpyinfo->visual->class) |
3347 | { | |
3348 | case StaticColor: | |
3349 | case PseudoColor: | |
3350 | case TrueColor: | |
3351 | case DirectColor: | |
3352 | case StaticGray: | |
3353 | case GrayScale: | |
3354 | return Qt; | |
3355 | ||
3356 | default: | |
3357 | return Qnil; | |
3358 | } | |
d0c9d219 RS |
3359 | } |
3360 | ||
41beb8fc | 3361 | DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width, |
c061c855 | 3362 | 0, 1, 0, |
d29a9848 | 3363 | doc: /* Return the width in pixels of the X display TERMINAL. |
6ed8eeff | 3364 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3365 | TERMINAL should be a terminal object, a frame or a display name (a string). |
d6635ba2 YM |
3366 | If omitted or nil, that stands for the selected frame's display. |
3367 | ||
3368 | On \"multi-monitor\" setups this refers to the pixel width for all | |
3369 | physical monitors associated with TERMINAL. To get information for | |
3370 | each physical monitor, use `display-monitor-attributes-list'. */) | |
5842a27b | 3371 | (Lisp_Object terminal) |
41beb8fc | 3372 | { |
6ed8eeff | 3373 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 | 3374 | |
abe9d29c | 3375 | return make_number (x_display_pixel_width (dpyinfo)); |
41beb8fc RS |
3376 | } |
3377 | ||
3378 | DEFUN ("x-display-pixel-height", Fx_display_pixel_height, | |
c061c855 | 3379 | Sx_display_pixel_height, 0, 1, 0, |
d29a9848 | 3380 | doc: /* Return the height in pixels of the X display TERMINAL. |
6ed8eeff | 3381 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3382 | TERMINAL should be a terminal object, a frame or a display name (a string). |
d6635ba2 YM |
3383 | If omitted or nil, that stands for the selected frame's display. |
3384 | ||
3385 | On \"multi-monitor\" setups this refers to the pixel height for all | |
3386 | physical monitors associated with TERMINAL. To get information for | |
3387 | each physical monitor, use `display-monitor-attributes-list'. */) | |
5842a27b | 3388 | (Lisp_Object terminal) |
41beb8fc | 3389 | { |
6ed8eeff | 3390 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 | 3391 | |
abe9d29c | 3392 | return make_number (x_display_pixel_height (dpyinfo)); |
41beb8fc RS |
3393 | } |
3394 | ||
3395 | DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes, | |
c061c855 | 3396 | 0, 1, 0, |
d29a9848 | 3397 | doc: /* Return the number of bitplanes of the X display TERMINAL. |
6ed8eeff | 3398 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3399 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3400 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3401 | (Lisp_Object terminal) |
41beb8fc | 3402 | { |
6ed8eeff | 3403 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 RS |
3404 | |
3405 | return make_number (dpyinfo->n_planes); | |
41beb8fc RS |
3406 | } |
3407 | ||
3408 | DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells, | |
c061c855 | 3409 | 0, 1, 0, |
d29a9848 | 3410 | doc: /* Return the number of color cells of the X display TERMINAL. |
6ed8eeff | 3411 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3412 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3413 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3414 | (Lisp_Object terminal) |
41beb8fc | 3415 | { |
6ed8eeff | 3416 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 | 3417 | |
6b61353c KH |
3418 | int nr_planes = DisplayPlanes (dpyinfo->display, |
3419 | XScreenNumberOfScreen (dpyinfo->screen)); | |
3420 | ||
3421 | /* Truncate nr_planes to 24 to avoid integer overflow. | |
3422 | Some displays says 32, but only 24 bits are actually significant. | |
3423 | There are only very few and rare video cards that have more than | |
3424 | 24 significant bits. Also 24 bits is more than 16 million colors, | |
3425 | it "should be enough for everyone". */ | |
3426 | if (nr_planes > 24) nr_planes = 24; | |
3427 | ||
3428 | return make_number (1 << nr_planes); | |
41beb8fc RS |
3429 | } |
3430 | ||
9d317b2c RS |
3431 | DEFUN ("x-server-max-request-size", Fx_server_max_request_size, |
3432 | Sx_server_max_request_size, | |
c061c855 | 3433 | 0, 1, 0, |
d29a9848 | 3434 | doc: /* Return the maximum request size of the X server of display TERMINAL. |
6ed8eeff | 3435 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3436 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3437 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3438 | (Lisp_Object terminal) |
9d317b2c | 3439 | { |
6ed8eeff | 3440 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 RS |
3441 | |
3442 | return make_number (MAXREQUEST (dpyinfo->display)); | |
9d317b2c RS |
3443 | } |
3444 | ||
41beb8fc | 3445 | DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0, |
d29a9848 | 3446 | doc: /* Return the "vendor ID" string of the X server of display TERMINAL. |
09e80d9f | 3447 | \(Labeling every distributor as a "vendor" embodies the false assumption |
95d62d8a | 3448 | that operating systems cannot be developed and distributed noncommercially.) |
6ed8eeff | 3449 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3450 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3451 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3452 | (Lisp_Object terminal) |
41beb8fc | 3453 | { |
6ed8eeff | 3454 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
675e2c69 | 3455 | const char *vendor = ServerVendor (dpyinfo->display); |
b9dc4443 | 3456 | |
41beb8fc RS |
3457 | if (! vendor) vendor = ""; |
3458 | return build_string (vendor); | |
3459 | } | |
3460 | ||
3461 | DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0, | |
d29a9848 | 3462 | doc: /* Return the version numbers of the X server of display TERMINAL. |
c061c855 | 3463 | The value is a list of three integers: the major and minor |
95d62d8a | 3464 | version numbers of the X Protocol in use, and the distributor-specific release |
c061c855 GM |
3465 | number. See also the function `x-server-vendor'. |
3466 | ||
6ed8eeff | 3467 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3468 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3469 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3470 | (Lisp_Object terminal) |
41beb8fc | 3471 | { |
6ed8eeff | 3472 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 | 3473 | Display *dpy = dpyinfo->display; |
11ae94fe | 3474 | |
3de717bd DA |
3475 | return list3i (ProtocolVersion (dpy), ProtocolRevision (dpy), |
3476 | VendorRelease (dpy)); | |
41beb8fc RS |
3477 | } |
3478 | ||
3479 | DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0, | |
6ed8eeff KL |
3480 | doc: /* Return the number of screens on the X server of display TERMINAL. |
3481 | The optional argument TERMINAL specifies which display to ask about. | |
708e05dc | 3482 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3483 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3484 | (Lisp_Object terminal) |
41beb8fc | 3485 | { |
6ed8eeff | 3486 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 RS |
3487 | |
3488 | return make_number (ScreenCount (dpyinfo->display)); | |
41beb8fc RS |
3489 | } |
3490 | ||
3491 | DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, 0, | |
6ed8eeff KL |
3492 | doc: /* Return the height in millimeters of the X display TERMINAL. |
3493 | The optional argument TERMINAL specifies which display to ask about. | |
708e05dc | 3494 | TERMINAL should be a terminal object, a frame or a display name (a string). |
d6635ba2 YM |
3495 | If omitted or nil, that stands for the selected frame's display. |
3496 | ||
3497 | On \"multi-monitor\" setups this refers to the height in millimeters for | |
3498 | all physical monitors associated with TERMINAL. To get information | |
3499 | for each physical monitor, use `display-monitor-attributes-list'. */) | |
5842a27b | 3500 | (Lisp_Object terminal) |
41beb8fc | 3501 | { |
6ed8eeff | 3502 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 RS |
3503 | |
3504 | return make_number (HeightMMOfScreen (dpyinfo->screen)); | |
41beb8fc RS |
3505 | } |
3506 | ||
3507 | DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0, | |
6ed8eeff KL |
3508 | doc: /* Return the width in millimeters of the X display TERMINAL. |
3509 | The optional argument TERMINAL specifies which display to ask about. | |
708e05dc | 3510 | TERMINAL should be a terminal object, a frame or a display name (a string). |
d6635ba2 YM |
3511 | If omitted or nil, that stands for the selected frame's display. |
3512 | ||
3513 | On \"multi-monitor\" setups this refers to the width in millimeters for | |
3514 | all physical monitors associated with TERMINAL. To get information | |
3515 | for each physical monitor, use `display-monitor-attributes-list'. */) | |
5842a27b | 3516 | (Lisp_Object terminal) |
41beb8fc | 3517 | { |
6ed8eeff | 3518 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
b9dc4443 RS |
3519 | |
3520 | return make_number (WidthMMOfScreen (dpyinfo->screen)); | |
41beb8fc RS |
3521 | } |
3522 | ||
3523 | DEFUN ("x-display-backing-store", Fx_display_backing_store, | |
c061c855 | 3524 | Sx_display_backing_store, 0, 1, 0, |
d29a9848 | 3525 | doc: /* Return an indication of whether X display TERMINAL does backing store. |
c061c855 | 3526 | The value may be `always', `when-mapped', or `not-useful'. |
6ed8eeff | 3527 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3528 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3529 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3530 | (Lisp_Object terminal) |
41beb8fc | 3531 | { |
6ed8eeff | 3532 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
8ec8a5ec | 3533 | Lisp_Object result; |
11ae94fe | 3534 | |
b9dc4443 | 3535 | switch (DoesBackingStore (dpyinfo->screen)) |
41beb8fc RS |
3536 | { |
3537 | case Always: | |
8ec8a5ec GM |
3538 | result = intern ("always"); |
3539 | break; | |
41beb8fc RS |
3540 | |
3541 | case WhenMapped: | |
8ec8a5ec GM |
3542 | result = intern ("when-mapped"); |
3543 | break; | |
41beb8fc RS |
3544 | |
3545 | case NotUseful: | |
8ec8a5ec GM |
3546 | result = intern ("not-useful"); |
3547 | break; | |
41beb8fc RS |
3548 | |
3549 | default: | |
3550 | error ("Strange value for BackingStore parameter of screen"); | |
3551 | } | |
8ec8a5ec GM |
3552 | |
3553 | return result; | |
41beb8fc RS |
3554 | } |
3555 | ||
3556 | DEFUN ("x-display-visual-class", Fx_display_visual_class, | |
c061c855 | 3557 | Sx_display_visual_class, 0, 1, 0, |
6ed8eeff | 3558 | doc: /* Return the visual class of the X display TERMINAL. |
c061c855 GM |
3559 | The value is one of the symbols `static-gray', `gray-scale', |
3560 | `static-color', `pseudo-color', `true-color', or `direct-color'. | |
3561 | ||
6ed8eeff | 3562 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3563 | TERMINAL should a terminal object, a frame or a display name (a string). |
7ee72033 | 3564 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3565 | (Lisp_Object terminal) |
41beb8fc | 3566 | { |
6ed8eeff | 3567 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
8ec8a5ec | 3568 | Lisp_Object result; |
11ae94fe | 3569 | |
b9dc4443 | 3570 | switch (dpyinfo->visual->class) |
41beb8fc | 3571 | { |
8ec8a5ec GM |
3572 | case StaticGray: |
3573 | result = intern ("static-gray"); | |
3574 | break; | |
3575 | case GrayScale: | |
3576 | result = intern ("gray-scale"); | |
3577 | break; | |
3578 | case StaticColor: | |
3579 | result = intern ("static-color"); | |
3580 | break; | |
3581 | case PseudoColor: | |
3582 | result = intern ("pseudo-color"); | |
3583 | break; | |
3584 | case TrueColor: | |
3585 | result = intern ("true-color"); | |
3586 | break; | |
3587 | case DirectColor: | |
3588 | result = intern ("direct-color"); | |
3589 | break; | |
41beb8fc RS |
3590 | default: |
3591 | error ("Display has an unknown visual class"); | |
3592 | } | |
177c0ea7 | 3593 | |
8ec8a5ec | 3594 | return result; |
41beb8fc RS |
3595 | } |
3596 | ||
3597 | DEFUN ("x-display-save-under", Fx_display_save_under, | |
c061c855 | 3598 | Sx_display_save_under, 0, 1, 0, |
d29a9848 | 3599 | doc: /* Return t if the X display TERMINAL supports the save-under feature. |
6ed8eeff | 3600 | The optional argument TERMINAL specifies which display to ask about. |
708e05dc | 3601 | TERMINAL should be a terminal object, a frame or a display name (a string). |
7ee72033 | 3602 | If omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 3603 | (Lisp_Object terminal) |
41beb8fc | 3604 | { |
6ed8eeff | 3605 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
11ae94fe | 3606 | |
b9dc4443 | 3607 | if (DoesSaveUnders (dpyinfo->screen) == True) |
41beb8fc RS |
3608 | return Qt; |
3609 | else | |
3610 | return Qnil; | |
3611 | } | |
4e3f9230 YM |
3612 | |
3613 | /* Store the geometry of the workarea on display DPYINFO into *RECT. | |
3614 | Return false if and only if the workarea information cannot be | |
3615 | obtained via the _NET_WORKAREA root window property. */ | |
3616 | ||
7583e2a0 | 3617 | #if ! GTK_CHECK_VERSION (3, 4, 0) |
4e3f9230 YM |
3618 | static bool |
3619 | x_get_net_workarea (struct x_display_info *dpyinfo, XRectangle *rect) | |
3620 | { | |
3621 | Display *dpy = dpyinfo->display; | |
3622 | long offset, max_len; | |
3623 | Atom target_type, actual_type; | |
3624 | unsigned long actual_size, bytes_remaining; | |
3625 | int rc, actual_format; | |
3626 | unsigned char *tmp_data = NULL; | |
3627 | bool result = false; | |
3628 | ||
3629 | x_catch_errors (dpy); | |
3630 | offset = 0; | |
3631 | max_len = 1; | |
3632 | target_type = XA_CARDINAL; | |
3633 | rc = XGetWindowProperty (dpy, dpyinfo->root_window, | |
3634 | dpyinfo->Xatom_net_current_desktop, | |
3635 | offset, max_len, False, target_type, | |
3636 | &actual_type, &actual_format, &actual_size, | |
3637 | &bytes_remaining, &tmp_data); | |
3638 | if (rc == Success && actual_type == target_type && !x_had_errors_p (dpy) | |
3639 | && actual_format == 32 && actual_size == max_len) | |
3640 | { | |
3641 | long current_desktop = ((long *) tmp_data)[0]; | |
3642 | ||
3643 | XFree (tmp_data); | |
3644 | tmp_data = NULL; | |
3645 | ||
3646 | offset = 4 * current_desktop; | |
3647 | max_len = 4; | |
3648 | rc = XGetWindowProperty (dpy, dpyinfo->root_window, | |
3649 | dpyinfo->Xatom_net_workarea, | |
3650 | offset, max_len, False, target_type, | |
3651 | &actual_type, &actual_format, &actual_size, | |
3652 | &bytes_remaining, &tmp_data); | |
3653 | if (rc == Success && actual_type == target_type && !x_had_errors_p (dpy) | |
3654 | && actual_format == 32 && actual_size == max_len) | |
3655 | { | |
3656 | long *values = (long *) tmp_data; | |
3657 | ||
3658 | rect->x = values[0]; | |
3659 | rect->y = values[1]; | |
3660 | rect->width = values[2]; | |
3661 | rect->height = values[3]; | |
3662 | ||
3663 | XFree (tmp_data); | |
3664 | tmp_data = NULL; | |
3665 | ||
3666 | result = true; | |
3667 | } | |
3668 | } | |
3669 | if (tmp_data) | |
3670 | XFree (tmp_data); | |
3671 | x_uncatch_errors (); | |
3672 | ||
3673 | return result; | |
3674 | } | |
2b66427d | 3675 | #endif |
4e3f9230 | 3676 | |
5ea03bf5 JD |
3677 | #ifndef USE_GTK |
3678 | ||
4e3f9230 YM |
3679 | /* Return monitor number where F is "most" or closest to. */ |
3680 | static int | |
3681 | x_get_monitor_for_frame (struct frame *f, | |
3682 | struct MonitorInfo *monitors, | |
3683 | int n_monitors) | |
3684 | { | |
3685 | XRectangle frect; | |
3686 | int area = 0, dist = -1; | |
3687 | int best_area = -1, best_dist = -1; | |
3688 | int i; | |
3689 | ||
3690 | if (n_monitors == 1) return 0; | |
3691 | frect.x = f->left_pos; | |
3692 | frect.y = f->top_pos; | |
3693 | frect.width = FRAME_PIXEL_WIDTH (f); | |
3694 | frect.height = FRAME_PIXEL_HEIGHT (f); | |
3695 | ||
3696 | for (i = 0; i < n_monitors; ++i) | |
3697 | { | |
3698 | struct MonitorInfo *mi = &monitors[i]; | |
3699 | XRectangle res; | |
3700 | int a = 0; | |
3701 | ||
3702 | if (mi->geom.width == 0) continue; | |
3703 | ||
3704 | if (x_intersect_rectangles (&mi->geom, &frect, &res)) | |
3705 | { | |
3706 | a = res.width * res.height; | |
e0c9d565 PE |
3707 | if (a > area) |
3708 | { | |
3709 | area = a; | |
3710 | best_area = i; | |
3711 | } | |
4e3f9230 YM |
3712 | } |
3713 | ||
3714 | if (a == 0 && area == 0) | |
3715 | { | |
3716 | int dx, dy, d; | |
3717 | if (frect.x + frect.width < mi->geom.x) | |
3718 | dx = mi->geom.x - frect.x + frect.width; | |
3719 | else if (frect.x > mi->geom.x + mi->geom.width) | |
3720 | dx = frect.x - mi->geom.x + mi->geom.width; | |
3721 | else | |
3722 | dx = 0; | |
3723 | if (frect.y + frect.height < mi->geom.y) | |
3724 | dy = mi->geom.y - frect.y + frect.height; | |
3725 | else if (frect.y > mi->geom.y + mi->geom.height) | |
3726 | dy = frect.y - mi->geom.y + mi->geom.height; | |
3727 | else | |
3728 | dy = 0; | |
3729 | ||
3730 | d = dx*dx + dy*dy; | |
3731 | if (dist == -1 || dist > d) | |
3732 | { | |
3733 | dist = d; | |
3734 | best_dist = i; | |
3735 | } | |
3736 | } | |
3737 | } | |
3738 | ||
3739 | return best_area != -1 ? best_area : (best_dist != -1 ? best_dist : 0); | |
3740 | } | |
3741 | ||
3742 | static Lisp_Object | |
3743 | x_make_monitor_attribute_list (struct MonitorInfo *monitors, | |
3744 | int n_monitors, | |
3745 | int primary_monitor, | |
3746 | struct x_display_info *dpyinfo, | |
3747 | const char *source) | |
3748 | { | |
3749 | Lisp_Object monitor_frames = Fmake_vector (make_number (n_monitors), Qnil); | |
6799bb26 | 3750 | Lisp_Object frame, rest; |
4e3f9230 YM |
3751 | |
3752 | FOR_EACH_FRAME (rest, frame) | |
3753 | { | |
3754 | struct frame *f = XFRAME (frame); | |
3755 | ||
aad3612f | 3756 | if (FRAME_X_P (f) && FRAME_DISPLAY_INFO (f) == dpyinfo |
4e3f9230 YM |
3757 | && !EQ (frame, tip_frame)) |
3758 | { | |
6799bb26 | 3759 | int i = x_get_monitor_for_frame (f, monitors, n_monitors); |
4e3f9230 YM |
3760 | ASET (monitor_frames, i, Fcons (frame, AREF (monitor_frames, i))); |
3761 | } | |
3762 | } | |
3763 | ||
6799bb26 JD |
3764 | return make_monitor_attribute_list (monitors, n_monitors, primary_monitor, |
3765 | monitor_frames, source); | |
4e3f9230 YM |
3766 | } |
3767 | ||
3768 | static Lisp_Object | |
3769 | x_get_monitor_attributes_fallback (struct x_display_info *dpyinfo) | |
3770 | { | |
3771 | struct MonitorInfo monitor; | |
4e3f9230 YM |
3772 | XRectangle workarea_r; |
3773 | ||
3774 | /* Fallback: treat (possibly) multiple physical monitors as if they | |
3775 | formed a single monitor as a whole. This should provide a | |
3776 | consistent result at least on single monitor environments. */ | |
3777 | monitor.geom.x = monitor.geom.y = 0; | |
3778 | monitor.geom.width = x_display_pixel_width (dpyinfo); | |
3779 | monitor.geom.height = x_display_pixel_height (dpyinfo); | |
3780 | monitor.mm_width = WidthMMOfScreen (dpyinfo->screen); | |
3781 | monitor.mm_height = HeightMMOfScreen (dpyinfo->screen); | |
3782 | monitor.name = xstrdup ("combined screen"); | |
3783 | ||
3784 | if (x_get_net_workarea (dpyinfo, &workarea_r)) | |
3785 | monitor.work = workarea_r; | |
3786 | else | |
3787 | monitor.work = monitor.geom; | |
3788 | return x_make_monitor_attribute_list (&monitor, 1, 0, dpyinfo, "fallback"); | |
3789 | } | |
3790 | ||
3791 | ||
3792 | #ifdef HAVE_XINERAMA | |
3793 | static Lisp_Object | |
3794 | x_get_monitor_attributes_xinerama (struct x_display_info *dpyinfo) | |
3795 | { | |
3796 | int n_monitors, i; | |
3797 | Lisp_Object attributes_list = Qnil; | |
3798 | Display *dpy = dpyinfo->display; | |
3799 | XineramaScreenInfo *info = XineramaQueryScreens (dpy, &n_monitors); | |
3800 | struct MonitorInfo *monitors; | |
e0c9d565 | 3801 | double mm_width_per_pixel, mm_height_per_pixel; |
4e3f9230 YM |
3802 | |
3803 | if (! info || n_monitors == 0) | |
3804 | { | |
3805 | if (info) | |
3806 | XFree (info); | |
3807 | return attributes_list; | |
3808 | } | |
3809 | ||
e0c9d565 | 3810 | mm_width_per_pixel = ((double) WidthMMOfScreen (dpyinfo->screen) |
4e3f9230 | 3811 | / x_display_pixel_width (dpyinfo)); |
e0c9d565 | 3812 | mm_height_per_pixel = ((double) HeightMMOfScreen (dpyinfo->screen) |
4e3f9230 | 3813 | / x_display_pixel_height (dpyinfo)); |
7d652d97 | 3814 | monitors = xzalloc (n_monitors * sizeof *monitors); |
4e3f9230 YM |
3815 | for (i = 0; i < n_monitors; ++i) |
3816 | { | |
3817 | struct MonitorInfo *mi = &monitors[i]; | |
3818 | XRectangle workarea_r; | |
3819 | ||
3820 | mi->geom.x = info[i].x_org; | |
3821 | mi->geom.y = info[i].y_org; | |
3822 | mi->geom.width = info[i].width; | |
3823 | mi->geom.height = info[i].height; | |
3824 | mi->mm_width = mi->geom.width * mm_width_per_pixel + 0.5; | |
3825 | mi->mm_height = mi->geom.height * mm_height_per_pixel + 0.5; | |
3826 | mi->name = 0; | |
3827 | ||
3828 | /* Xinerama usually have primary monitor first, just use that. */ | |
3829 | if (i == 0 && x_get_net_workarea (dpyinfo, &workarea_r)) | |
3830 | { | |
3831 | mi->work = workarea_r; | |
3832 | if (! x_intersect_rectangles (&mi->geom, &mi->work, &mi->work)) | |
3833 | mi->work = mi->geom; | |
3834 | } | |
3835 | else | |
3836 | mi->work = mi->geom; | |
3837 | } | |
3838 | XFree (info); | |
3839 | ||
3840 | attributes_list = x_make_monitor_attribute_list (monitors, | |
3841 | n_monitors, | |
3842 | 0, | |
3843 | dpyinfo, | |
3844 | "Xinerama"); | |
3845 | free_monitors (monitors, n_monitors); | |
3846 | return attributes_list; | |
3847 | } | |
3848 | #endif /* HAVE_XINERAMA */ | |
3849 | ||
3850 | ||
3851 | #ifdef HAVE_XRANDR | |
3852 | static Lisp_Object | |
3853 | x_get_monitor_attributes_xrandr (struct x_display_info *dpyinfo) | |
3854 | { | |
3855 | Lisp_Object attributes_list = Qnil; | |
3856 | XRRScreenResources *resources; | |
3857 | Display *dpy = dpyinfo->display; | |
3858 | int i, n_monitors, primary = -1; | |
3859 | RROutput pxid = None; | |
3860 | struct MonitorInfo *monitors; | |
3861 | ||
3862 | #ifdef HAVE_XRRGETSCREENRESOURCESCURRENT | |
3863 | resources = XRRGetScreenResourcesCurrent (dpy, dpyinfo->root_window); | |
3864 | #else | |
3865 | resources = XRRGetScreenResources (dpy, dpyinfo->root_window); | |
3866 | #endif | |
3867 | if (! resources || resources->noutput == 0) | |
3868 | { | |
3869 | if (resources) | |
3870 | XRRFreeScreenResources (resources); | |
3871 | return Qnil; | |
3872 | } | |
3873 | n_monitors = resources->noutput; | |
7d652d97 | 3874 | monitors = xzalloc (n_monitors * sizeof *monitors); |
4e3f9230 YM |
3875 | |
3876 | #ifdef HAVE_XRRGETOUTPUTPRIMARY | |
3877 | pxid = XRRGetOutputPrimary (dpy, dpyinfo->root_window); | |
3878 | #endif | |
3879 | ||
3880 | for (i = 0; i < n_monitors; ++i) | |
3881 | { | |
3882 | XRROutputInfo *info = XRRGetOutputInfo (dpy, resources, | |
3883 | resources->outputs[i]); | |
3884 | Connection conn = info ? info->connection : RR_Disconnected; | |
3885 | RRCrtc id = info ? info->crtc : None; | |
3886 | ||
3887 | if (strcmp (info->name, "default") == 0) | |
3888 | { | |
3889 | /* Non XRandr 1.2 driver, does not give useful data. */ | |
3890 | XRRFreeOutputInfo (info); | |
3891 | XRRFreeScreenResources (resources); | |
3892 | free_monitors (monitors, n_monitors); | |
3893 | return Qnil; | |
3894 | } | |
3895 | ||
3896 | if (conn != RR_Disconnected && id != None) | |
3897 | { | |
3898 | XRRCrtcInfo *crtc = XRRGetCrtcInfo (dpy, resources, id); | |
3899 | struct MonitorInfo *mi = &monitors[i]; | |
3900 | XRectangle workarea_r; | |
3901 | ||
3902 | if (! crtc) | |
3903 | { | |
3904 | XRRFreeOutputInfo (info); | |
3905 | continue; | |
3906 | } | |
3907 | ||
3908 | mi->geom.x = crtc->x; | |
3909 | mi->geom.y = crtc->y; | |
3910 | mi->geom.width = crtc->width; | |
3911 | mi->geom.height = crtc->height; | |
3912 | mi->mm_width = info->mm_width; | |
3913 | mi->mm_height = info->mm_height; | |
3914 | mi->name = xstrdup (info->name); | |
3915 | ||
3916 | if (pxid != None && pxid == resources->outputs[i]) | |
3917 | primary = i; | |
3918 | else if (primary == -1 && strcmp (info->name, "LVDS") == 0) | |
3919 | primary = i; | |
3920 | ||
3921 | if (i == primary && x_get_net_workarea (dpyinfo, &workarea_r)) | |
3922 | { | |
3923 | mi->work= workarea_r; | |
3924 | if (! x_intersect_rectangles (&mi->geom, &mi->work, &mi->work)) | |
3925 | mi->work = mi->geom; | |
3926 | } | |
3927 | else | |
3928 | mi->work = mi->geom; | |
3929 | ||
3930 | XRRFreeCrtcInfo (crtc); | |
3931 | } | |
3932 | XRRFreeOutputInfo (info); | |
3933 | } | |
3934 | XRRFreeScreenResources (resources); | |
3935 | ||
3936 | attributes_list = x_make_monitor_attribute_list (monitors, | |
3937 | n_monitors, | |
3938 | primary, | |
3939 | dpyinfo, | |
3940 | "XRandr"); | |
3941 | free_monitors (monitors, n_monitors); | |
3942 | return attributes_list; | |
3943 | } | |
3944 | #endif /* HAVE_XRANDR */ | |
3945 | ||
3946 | static Lisp_Object | |
3947 | x_get_monitor_attributes (struct x_display_info *dpyinfo) | |
3948 | { | |
3949 | Lisp_Object attributes_list = Qnil; | |
3950 | Display *dpy = dpyinfo->display; | |
3951 | ||
cd9356f2 DC |
3952 | (void) dpy; /* Suppress unused variable warning. */ |
3953 | ||
4e3f9230 YM |
3954 | #ifdef HAVE_XRANDR |
3955 | int xrr_event_base, xrr_error_base; | |
3956 | bool xrr_ok = false; | |
3957 | xrr_ok = XRRQueryExtension (dpy, &xrr_event_base, &xrr_error_base); | |
3958 | if (xrr_ok) | |
3959 | { | |
3960 | int xrr_major, xrr_minor; | |
3961 | XRRQueryVersion (dpy, &xrr_major, &xrr_minor); | |
3962 | xrr_ok = (xrr_major == 1 && xrr_minor >= 2) || xrr_major > 1; | |
3963 | } | |
3964 | ||
3965 | if (xrr_ok) | |
3966 | attributes_list = x_get_monitor_attributes_xrandr (dpyinfo); | |
3967 | #endif /* HAVE_XRANDR */ | |
3968 | ||
3969 | #ifdef HAVE_XINERAMA | |
3970 | if (NILP (attributes_list)) | |
3971 | { | |
3972 | int xin_event_base, xin_error_base; | |
3973 | bool xin_ok = false; | |
3974 | xin_ok = XineramaQueryExtension (dpy, &xin_event_base, &xin_error_base); | |
3975 | if (xin_ok && XineramaIsActive (dpy)) | |
3976 | attributes_list = x_get_monitor_attributes_xinerama (dpyinfo); | |
3977 | } | |
3978 | #endif /* HAVE_XINERAMA */ | |
3979 | ||
3980 | if (NILP (attributes_list)) | |
3981 | attributes_list = x_get_monitor_attributes_fallback (dpyinfo); | |
3982 | ||
3983 | return attributes_list; | |
3984 | } | |
3985 | ||
e0c9d565 PE |
3986 | #endif /* !USE_GTK */ |
3987 | ||
4e3f9230 YM |
3988 | DEFUN ("x-display-monitor-attributes-list", Fx_display_monitor_attributes_list, |
3989 | Sx_display_monitor_attributes_list, | |
3990 | 0, 1, 0, | |
3991 | doc: /* Return a list of physical monitor attributes on the X display TERMINAL. | |
3992 | ||
3993 | The optional argument TERMINAL specifies which display to ask about. | |
3994 | TERMINAL should be a terminal object, a frame or a display name (a string). | |
3995 | If omitted or nil, that stands for the selected frame's display. | |
3996 | ||
3997 | In addition to the standard attribute keys listed in | |
3998 | `display-monitor-attributes-list', the following keys are contained in | |
3999 | the attributes: | |
4000 | ||
4001 | source -- String describing the source from which multi-monitor | |
4002 | information is obtained, one of \"Gdk\", \"XRandr\", | |
4003 | \"Xinerama\", or \"fallback\" | |
4004 | ||
4005 | Internal use only, use `display-monitor-attributes-list' instead. */) | |
4006 | (Lisp_Object terminal) | |
4007 | { | |
4008 | struct x_display_info *dpyinfo = check_x_display_info (terminal); | |
4009 | Lisp_Object attributes_list = Qnil; | |
4010 | ||
4011 | #ifdef USE_GTK | |
e0c9d565 | 4012 | double mm_width_per_pixel, mm_height_per_pixel; |
4e3f9230 YM |
4013 | GdkDisplay *gdpy; |
4014 | GdkScreen *gscreen; | |
4015 | gint primary_monitor = 0, n_monitors, i; | |
4e3f9230 YM |
4016 | Lisp_Object monitor_frames, rest, frame; |
4017 | static const char *source = "Gdk"; | |
6799bb26 | 4018 | struct MonitorInfo *monitors; |
4e3f9230 YM |
4019 | |
4020 | block_input (); | |
e0c9d565 | 4021 | mm_width_per_pixel = ((double) WidthMMOfScreen (dpyinfo->screen) |
4e3f9230 | 4022 | / x_display_pixel_width (dpyinfo)); |
e0c9d565 | 4023 | mm_height_per_pixel = ((double) HeightMMOfScreen (dpyinfo->screen) |
4e3f9230 YM |
4024 | / x_display_pixel_height (dpyinfo)); |
4025 | gdpy = gdk_x11_lookup_xdisplay (dpyinfo->display); | |
4026 | gscreen = gdk_display_get_default_screen (gdpy); | |
7583e2a0 | 4027 | #if GTK_CHECK_VERSION (2, 20, 0) |
4e3f9230 YM |
4028 | primary_monitor = gdk_screen_get_primary_monitor (gscreen); |
4029 | #endif | |
4030 | n_monitors = gdk_screen_get_n_monitors (gscreen); | |
4031 | monitor_frames = Fmake_vector (make_number (n_monitors), Qnil); | |
7d652d97 | 4032 | monitors = xzalloc (n_monitors * sizeof *monitors); |
6799bb26 | 4033 | |
4e3f9230 YM |
4034 | FOR_EACH_FRAME (rest, frame) |
4035 | { | |
4036 | struct frame *f = XFRAME (frame); | |
4037 | ||
aad3612f | 4038 | if (FRAME_X_P (f) && FRAME_DISPLAY_INFO (f) == dpyinfo |
4e3f9230 YM |
4039 | && !EQ (frame, tip_frame)) |
4040 | { | |
4041 | GdkWindow *gwin = gtk_widget_get_window (FRAME_GTK_WIDGET (f)); | |
4042 | ||
4043 | i = gdk_screen_get_monitor_at_window (gscreen, gwin); | |
4044 | ASET (monitor_frames, i, Fcons (frame, AREF (monitor_frames, i))); | |
4045 | } | |
4046 | } | |
4047 | ||
6799bb26 | 4048 | for (i = 0; i < n_monitors; ++i) |
4e3f9230 | 4049 | { |
4e3f9230 | 4050 | gint width_mm = -1, height_mm = -1; |
6799bb26 JD |
4051 | GdkRectangle rec, work; |
4052 | struct MonitorInfo *mi = &monitors[i]; | |
4e3f9230 YM |
4053 | |
4054 | gdk_screen_get_monitor_geometry (gscreen, i, &rec); | |
4e3f9230 | 4055 | |
7583e2a0 | 4056 | #if GTK_CHECK_VERSION (2, 14, 0) |
4e3f9230 YM |
4057 | width_mm = gdk_screen_get_monitor_width_mm (gscreen, i); |
4058 | height_mm = gdk_screen_get_monitor_height_mm (gscreen, i); | |
4059 | #endif | |
4060 | if (width_mm < 0) | |
4061 | width_mm = rec.width * mm_width_per_pixel + 0.5; | |
4062 | if (height_mm < 0) | |
4063 | height_mm = rec.height * mm_height_per_pixel + 0.5; | |
4e3f9230 | 4064 | |
7583e2a0 | 4065 | #if GTK_CHECK_VERSION (3, 4, 0) |
6799bb26 | 4066 | gdk_screen_get_monitor_workarea (gscreen, i, &work); |
4e3f9230 YM |
4067 | #else |
4068 | /* Emulate the behavior of GTK+ 3.4. */ | |
4069 | { | |
4070 | XRectangle workarea_r; | |
4071 | ||
4e3f9230 YM |
4072 | if (i == primary_monitor && x_get_net_workarea (dpyinfo, &workarea_r)) |
4073 | { | |
4e3f9230 YM |
4074 | work.x = workarea_r.x; |
4075 | work.y = workarea_r.y; | |
4076 | work.width = workarea_r.width; | |
4077 | work.height = workarea_r.height; | |
6799bb26 JD |
4078 | if (! gdk_rectangle_intersect (&rec, &work, &work)) |
4079 | work = rec; | |
4080 | } | |
4081 | else | |
4082 | work = rec; | |
4e3f9230 YM |
4083 | } |
4084 | #endif | |
4e3f9230 | 4085 | |
6799bb26 JD |
4086 | |
4087 | mi->geom.x = rec.x; | |
4088 | mi->geom.y = rec.y; | |
4089 | mi->geom.width = rec.width; | |
4090 | mi->geom.height = rec.height; | |
4091 | mi->work.x = work.x; | |
4092 | mi->work.y = work.y; | |
4093 | mi->work.width = work.width; | |
4094 | mi->work.height = work.height; | |
4095 | mi->mm_width = width_mm; | |
4096 | mi->mm_height = height_mm; | |
4097 | ||
7583e2a0 | 4098 | #if GTK_CHECK_VERSION (2, 14, 0) |
6799bb26 | 4099 | mi->name = gdk_screen_get_monitor_plug_name (gscreen, i); |
4e3f9230 | 4100 | #endif |
4e3f9230 YM |
4101 | } |
4102 | ||
6799bb26 JD |
4103 | attributes_list = make_monitor_attribute_list (monitors, |
4104 | n_monitors, | |
4105 | primary_monitor, | |
4106 | monitor_frames, | |
4107 | source); | |
4e3f9230 YM |
4108 | unblock_input (); |
4109 | #else /* not USE_GTK */ | |
4110 | ||
4111 | block_input (); | |
4112 | attributes_list = x_get_monitor_attributes (dpyinfo); | |
4113 | unblock_input (); | |
4114 | ||
4115 | #endif /* not USE_GTK */ | |
4116 | ||
4117 | return attributes_list; | |
4118 | } | |
4119 | ||
a6ad00c0 GM |
4120 | /************************************************************************ |
4121 | X Displays | |
4122 | ************************************************************************/ | |
4123 | ||
01f1ba30 | 4124 | \f |
a6ad00c0 GM |
4125 | /* Mapping visual names to visuals. */ |
4126 | ||
4127 | static struct visual_class | |
4128 | { | |
675e2c69 | 4129 | const char *name; |
a6ad00c0 GM |
4130 | int class; |
4131 | } | |
4132 | visual_classes[] = | |
4133 | { | |
4134 | {"StaticGray", StaticGray}, | |
4135 | {"GrayScale", GrayScale}, | |
4136 | {"StaticColor", StaticColor}, | |
4137 | {"PseudoColor", PseudoColor}, | |
4138 | {"TrueColor", TrueColor}, | |
4139 | {"DirectColor", DirectColor}, | |
9908a324 | 4140 | {NULL, 0} |
a6ad00c0 GM |
4141 | }; |
4142 | ||
4143 | ||
404daac1 | 4144 | #ifndef HAVE_XSCREENNUMBEROFSCREEN |
a6ad00c0 GM |
4145 | |
4146 | /* Value is the screen number of screen SCR. This is a substitute for | |
4147 | the X function with the same name when that doesn't exist. */ | |
4148 | ||
404daac1 RS |
4149 | int |
4150 | XScreenNumberOfScreen (scr) | |
4151 | register Screen *scr; | |
4152 | { | |
a6ad00c0 GM |
4153 | Display *dpy = scr->display; |
4154 | int i; | |
3df34fdb | 4155 | |
a6ad00c0 | 4156 | for (i = 0; i < dpy->nscreens; ++i) |
fbd5ceb2 | 4157 | if (scr == dpy->screens + i) |
a6ad00c0 | 4158 | break; |
404daac1 | 4159 | |
a6ad00c0 | 4160 | return i; |
404daac1 | 4161 | } |
a6ad00c0 | 4162 | |
404daac1 RS |
4163 | #endif /* not HAVE_XSCREENNUMBEROFSCREEN */ |
4164 | ||
01f1ba30 | 4165 | |
a6ad00c0 GM |
4166 | /* Select the visual that should be used on display DPYINFO. Set |
4167 | members of DPYINFO appropriately. Called from x_term_init. */ | |
fe24a618 | 4168 | |
a6ad00c0 | 4169 | void |
971de7fb | 4170 | select_visual (struct x_display_info *dpyinfo) |
a6ad00c0 GM |
4171 | { |
4172 | Display *dpy = dpyinfo->display; | |
4173 | Screen *screen = dpyinfo->screen; | |
4174 | Lisp_Object value; | |
fe24a618 | 4175 | |
a6ad00c0 GM |
4176 | /* See if a visual is specified. */ |
4177 | value = display_x_get_resource (dpyinfo, | |
4178 | build_string ("visualClass"), | |
4179 | build_string ("VisualClass"), | |
4180 | Qnil, Qnil); | |
4181 | if (STRINGP (value)) | |
4182 | { | |
4183 | /* VALUE should be of the form CLASS-DEPTH, where CLASS is one | |
4184 | of `PseudoColor', `TrueColor' etc. and DEPTH is the color | |
4185 | depth, a decimal number. NAME is compared with case ignored. */ | |
38182d90 | 4186 | char *s = alloca (SBYTES (value) + 1); |
a6ad00c0 GM |
4187 | char *dash; |
4188 | int i, class = -1; | |
4189 | XVisualInfo vinfo; | |
4190 | ||
42a5b22f | 4191 | strcpy (s, SSDATA (value)); |
8966b757 | 4192 | dash = strchr (s, '-'); |
a6ad00c0 GM |
4193 | if (dash) |
4194 | { | |
4195 | dpyinfo->n_planes = atoi (dash + 1); | |
4196 | *dash = '\0'; | |
4197 | } | |
4198 | else | |
4199 | /* We won't find a matching visual with depth 0, so that | |
4200 | an error will be printed below. */ | |
4201 | dpyinfo->n_planes = 0; | |
f0614854 | 4202 | |
a6ad00c0 GM |
4203 | /* Determine the visual class. */ |
4204 | for (i = 0; visual_classes[i].name; ++i) | |
05131107 | 4205 | if (xstrcasecmp (s, visual_classes[i].name) == 0) |
a6ad00c0 GM |
4206 | { |
4207 | class = visual_classes[i].class; | |
4208 | break; | |
4209 | } | |
01f1ba30 | 4210 | |
a6ad00c0 GM |
4211 | /* Look up a matching visual for the specified class. */ |
4212 | if (class == -1 | |
4213 | || !XMatchVisualInfo (dpy, XScreenNumberOfScreen (screen), | |
4214 | dpyinfo->n_planes, class, &vinfo)) | |
d5db4077 | 4215 | fatal ("Invalid visual specification `%s'", SDATA (value)); |
177c0ea7 | 4216 | |
a6ad00c0 GM |
4217 | dpyinfo->visual = vinfo.visual; |
4218 | } | |
01f1ba30 JB |
4219 | else |
4220 | { | |
a6ad00c0 GM |
4221 | int n_visuals; |
4222 | XVisualInfo *vinfo, vinfo_template; | |
177c0ea7 | 4223 | |
a6ad00c0 GM |
4224 | dpyinfo->visual = DefaultVisualOfScreen (screen); |
4225 | ||
a6ad00c0 | 4226 | vinfo_template.visualid = XVisualIDFromVisual (dpyinfo->visual); |
a6ad00c0 GM |
4227 | vinfo_template.screen = XScreenNumberOfScreen (screen); |
4228 | vinfo = XGetVisualInfo (dpy, VisualIDMask | VisualScreenMask, | |
4229 | &vinfo_template, &n_visuals); | |
83725342 | 4230 | if (n_visuals <= 0) |
a6ad00c0 GM |
4231 | fatal ("Can't get proper X visual info"); |
4232 | ||
94ac875b | 4233 | dpyinfo->n_planes = vinfo->depth; |
98c6f1e3 | 4234 | XFree (vinfo); |
a6ad00c0 | 4235 | } |
01f1ba30 | 4236 | } |
01f1ba30 | 4237 | |
a6ad00c0 | 4238 | |
b9dc4443 RS |
4239 | /* Return the X display structure for the display named NAME. |
4240 | Open a new connection if necessary. */ | |
4241 | ||
e4cebfca | 4242 | static struct x_display_info * |
971de7fb | 4243 | x_display_info_for_name (Lisp_Object name) |
b9dc4443 RS |
4244 | { |
4245 | struct x_display_info *dpyinfo; | |
4246 | ||
b7826503 | 4247 | CHECK_STRING (name); |
b9dc4443 | 4248 | |
d141d701 DA |
4249 | for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) |
4250 | if (!NILP (Fstring_equal (XCAR (dpyinfo->name_list_element), name))) | |
4251 | return dpyinfo; | |
b9dc4443 | 4252 | |
b7975ee4 KH |
4253 | /* Use this general default value to start with. */ |
4254 | Vx_resource_name = Vinvocation_name; | |
4255 | ||
b9dc4443 RS |
4256 | validate_x_resource_name (); |
4257 | ||
7d652d97 | 4258 | dpyinfo = x_term_init (name, 0, SSDATA (Vx_resource_name)); |
b9dc4443 | 4259 | |
08a90d6a | 4260 | if (dpyinfo == 0) |
d5db4077 | 4261 | error ("Cannot connect to X server %s", SDATA (name)); |
08a90d6a | 4262 | |
b9dc4443 RS |
4263 | XSETFASTINT (Vwindow_system_version, 11); |
4264 | ||
4265 | return dpyinfo; | |
4266 | } | |
4267 | ||
a6ad00c0 | 4268 | |
01f1ba30 | 4269 | DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection, |
c061c855 | 4270 | 1, 3, 0, |
4f4f2973 | 4271 | doc: /* Open a connection to a display server. |
c061c855 GM |
4272 | DISPLAY is the name of the display to connect to. |
4273 | Optional second arg XRM-STRING is a string of resources in xrdb format. | |
4274 | If the optional third arg MUST-SUCCEED is non-nil, | |
4f4f2973 GM |
4275 | terminate Emacs if we can't open the connection. |
4276 | \(In the Nextstep version, the last two arguments are currently ignored.) */) | |
5842a27b | 4277 | (Lisp_Object display, Lisp_Object xrm_string, Lisp_Object must_succeed) |
01f1ba30 | 4278 | { |
5f742c1b | 4279 | char *xrm_option; |
b9dc4443 | 4280 | struct x_display_info *dpyinfo; |
01f1ba30 | 4281 | |
b7826503 | 4282 | CHECK_STRING (display); |
d387c960 | 4283 | if (! NILP (xrm_string)) |
b7826503 | 4284 | CHECK_STRING (xrm_string); |
01f1ba30 | 4285 | |
7d652d97 | 4286 | xrm_option = NILP (xrm_string) ? 0 : SSDATA (xrm_string); |
d387c960 JB |
4287 | |
4288 | validate_x_resource_name (); | |
4289 | ||
e1b1bee8 | 4290 | /* This is what opens the connection and sets x_current_display. |
b9dc4443 RS |
4291 | This also initializes many symbols, such as those used for input. */ |
4292 | dpyinfo = x_term_init (display, xrm_option, | |
51b59d79 | 4293 | SSDATA (Vx_resource_name)); |
f1c16f36 | 4294 | |
08a90d6a RS |
4295 | if (dpyinfo == 0) |
4296 | { | |
4297 | if (!NILP (must_succeed)) | |
10ffbc14 GM |
4298 | fatal ("Cannot connect to X server %s.\n\ |
4299 | Check the DISPLAY environment variable or use `-d'.\n\ | |
842a9389 JB |
4300 | Also use the `xauth' program to verify that you have the proper\n\ |
4301 | authorization information needed to connect the X server.\n\ | |
bf770132 | 4302 | An insecure way to solve the problem may be to use `xhost'.\n", |
d5db4077 | 4303 | SDATA (display)); |
08a90d6a | 4304 | else |
d5db4077 | 4305 | error ("Cannot connect to X server %s", SDATA (display)); |
08a90d6a RS |
4306 | } |
4307 | ||
b9dc4443 | 4308 | XSETFASTINT (Vwindow_system_version, 11); |
01f1ba30 JB |
4309 | return Qnil; |
4310 | } | |
4311 | ||
08a90d6a RS |
4312 | DEFUN ("x-close-connection", Fx_close_connection, |
4313 | Sx_close_connection, 1, 1, 0, | |
00d385b0 | 4314 | doc: /* Close the connection to TERMINAL's X server. |
708e05dc | 4315 | For TERMINAL, specify a terminal object, a frame or a display name (a |
00d385b0 KL |
4316 | string). If TERMINAL is nil, that stands for the selected frame's |
4317 | terminal. */) | |
5842a27b | 4318 | (Lisp_Object terminal) |
01f1ba30 | 4319 | { |
00d385b0 | 4320 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
3457bc6e | 4321 | |
08a90d6a RS |
4322 | if (dpyinfo->reference_count > 0) |
4323 | error ("Display still has frames on it"); | |
01f1ba30 | 4324 | |
6ed8eeff | 4325 | x_delete_terminal (dpyinfo->terminal); |
3457bc6e | 4326 | |
01f1ba30 JB |
4327 | return Qnil; |
4328 | } | |
4329 | ||
08a90d6a | 4330 | DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0, |
7ee72033 | 4331 | doc: /* Return the list of display names that Emacs has connections to. */) |
5842a27b | 4332 | (void) |
08a90d6a | 4333 | { |
d141d701 DA |
4334 | Lisp_Object result = Qnil; |
4335 | struct x_display_info *xdi; | |
08a90d6a | 4336 | |
d141d701 DA |
4337 | for (xdi = x_display_list; xdi; xdi = xdi->next) |
4338 | result = Fcons (XCAR (xdi->name_list_element), result); | |
08a90d6a RS |
4339 | |
4340 | return result; | |
4341 | } | |
4342 | ||
4343 | DEFUN ("x-synchronize", Fx_synchronize, Sx_synchronize, 1, 2, 0, | |
7ee72033 | 4344 | doc: /* If ON is non-nil, report X errors as soon as the erring request is made. |
7c051dd8 GM |
4345 | This function only has an effect on X Windows. With MS Windows, it is |
4346 | defined but does nothing. | |
4347 | ||
c061c855 GM |
4348 | If ON is nil, allow buffering of requests. |
4349 | Turning on synchronization prohibits the Xlib routines from buffering | |
4350 | requests and seriously degrades performance, but makes debugging much | |
4351 | easier. | |
00d385b0 | 4352 | The optional second argument TERMINAL specifies which display to act on. |
708e05dc | 4353 | TERMINAL should be a terminal object, a frame or a display name (a string). |
00d385b0 | 4354 | If TERMINAL is omitted or nil, that stands for the selected frame's display. */) |
5842a27b | 4355 | (Lisp_Object on, Lisp_Object terminal) |
01f1ba30 | 4356 | { |
00d385b0 | 4357 | struct x_display_info *dpyinfo = check_x_display_info (terminal); |
11ae94fe | 4358 | |
b9dc4443 | 4359 | XSynchronize (dpyinfo->display, !EQ (on, Qnil)); |
01f1ba30 JB |
4360 | |
4361 | return Qnil; | |
4362 | } | |
4363 | ||
b9dc4443 | 4364 | /* Wait for responses to all X commands issued so far for frame F. */ |
6b7b1820 RS |
4365 | |
4366 | void | |
a10c8269 | 4367 | x_sync (struct frame *f) |
6b7b1820 | 4368 | { |
4d7e6e51 | 4369 | block_input (); |
b9dc4443 | 4370 | XSync (FRAME_X_DISPLAY (f), False); |
4d7e6e51 | 4371 | unblock_input (); |
6b7b1820 | 4372 | } |
333b20bb | 4373 | |
01f1ba30 | 4374 | \f |
333b20bb | 4375 | /*********************************************************************** |
6b61353c | 4376 | Window properties |
333b20bb | 4377 | ***********************************************************************/ |
f1c16f36 | 4378 | |
6b61353c KH |
4379 | DEFUN ("x-change-window-property", Fx_change_window_property, |
4380 | Sx_change_window_property, 2, 6, 0, | |
4381 | doc: /* Change window property PROP to VALUE on the X window of FRAME. | |
7c051dd8 GM |
4382 | PROP must be a string. VALUE may be a string or a list of conses, |
4383 | numbers and/or strings. If an element in the list is a string, it is | |
4384 | converted to an atom and the value of the atom is used. If an element | |
4385 | is a cons, it is converted to a 32 bit number where the car is the 16 | |
4386 | top bits and the cdr is the lower 16 bits. | |
4387 | ||
6b61353c KH |
4388 | FRAME nil or omitted means use the selected frame. |
4389 | If TYPE is given and non-nil, it is the name of the type of VALUE. | |
4390 | If TYPE is not given or nil, the type is STRING. | |
4391 | FORMAT gives the size in bits of each element if VALUE is a list. | |
4392 | It must be one of 8, 16 or 32. | |
4393 | If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8. | |
fca8d6b6 | 4394 | If OUTER-P is non-nil, the property is changed for the outer X window of |
7c051dd8 | 4395 | FRAME. Default is to change on the edit X window. */) |
fca8d6b6 AS |
4396 | (Lisp_Object prop, Lisp_Object value, Lisp_Object frame, |
4397 | Lisp_Object type, Lisp_Object format, Lisp_Object outer_p) | |
6b61353c | 4398 | { |
7452b7bd | 4399 | struct frame *f = decode_window_system_frame (frame); |
6b61353c KH |
4400 | Atom prop_atom; |
4401 | Atom target_type = XA_STRING; | |
4402 | int element_format = 8; | |
4403 | unsigned char *data; | |
4404 | int nelements; | |
4405 | Window w; | |
333b20bb | 4406 | |
6b61353c | 4407 | CHECK_STRING (prop); |
333b20bb | 4408 | |
6b61353c KH |
4409 | if (! NILP (format)) |
4410 | { | |
4411 | CHECK_NUMBER (format); | |
333b20bb | 4412 | |
d311d28c PE |
4413 | if (XINT (format) != 8 && XINT (format) != 16 |
4414 | && XINT (format) != 32) | |
6b61353c | 4415 | error ("FORMAT must be one of 8, 16 or 32"); |
d311d28c | 4416 | element_format = XINT (format); |
6b61353c | 4417 | } |
333b20bb | 4418 | |
6b61353c KH |
4419 | if (CONSP (value)) |
4420 | { | |
c678c835 PE |
4421 | ptrdiff_t elsize; |
4422 | ||
6b61353c KH |
4423 | nelements = x_check_property_data (value); |
4424 | if (nelements == -1) | |
4425 | error ("Bad data in VALUE, must be number, string or cons"); | |
333b20bb | 4426 | |
c678c835 PE |
4427 | /* The man page for XChangeProperty: |
4428 | "If the specified format is 32, the property data must be a | |
4429 | long array." | |
4430 | This applies even if long is more than 32 bits. The X library | |
4431 | converts to 32 bits before sending to the X server. */ | |
4432 | elsize = element_format == 32 ? sizeof (long) : element_format >> 3; | |
0065d054 | 4433 | data = xnmalloc (nelements, elsize); |
333b20bb | 4434 | |
6b61353c KH |
4435 | x_fill_property_data (FRAME_X_DISPLAY (f), value, data, element_format); |
4436 | } | |
4437 | else | |
4438 | { | |
4439 | CHECK_STRING (value); | |
4440 | data = SDATA (value); | |
c678c835 PE |
4441 | if (INT_MAX < SBYTES (value)) |
4442 | error ("VALUE too long"); | |
4443 | nelements = SBYTES (value); | |
6b61353c | 4444 | } |
333b20bb | 4445 | |
4d7e6e51 | 4446 | block_input (); |
42a5b22f | 4447 | prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SSDATA (prop), False); |
6b61353c KH |
4448 | if (! NILP (type)) |
4449 | { | |
4450 | CHECK_STRING (type); | |
42a5b22f | 4451 | target_type = XInternAtom (FRAME_X_DISPLAY (f), SSDATA (type), False); |
6b61353c | 4452 | } |
333b20bb | 4453 | |
6b61353c KH |
4454 | if (! NILP (outer_p)) w = FRAME_OUTER_WINDOW (f); |
4455 | else w = FRAME_X_WINDOW (f); | |
5b3f8550 | 4456 | |
6b61353c KH |
4457 | XChangeProperty (FRAME_X_DISPLAY (f), w, |
4458 | prop_atom, target_type, element_format, PropModeReplace, | |
4459 | data, nelements); | |
333b20bb | 4460 | |
6b61353c | 4461 | if (CONSP (value)) xfree (data); |
333b20bb | 4462 | |
6b61353c KH |
4463 | /* Make sure the property is set when we return. */ |
4464 | XFlush (FRAME_X_DISPLAY (f)); | |
4d7e6e51 | 4465 | unblock_input (); |
333b20bb | 4466 | |
6b61353c | 4467 | return value; |
333b20bb GM |
4468 | } |
4469 | ||
4470 | ||
6b61353c KH |
4471 | DEFUN ("x-delete-window-property", Fx_delete_window_property, |
4472 | Sx_delete_window_property, 1, 2, 0, | |
4473 | doc: /* Remove window property PROP from X window of FRAME. | |
4474 | FRAME nil or omitted means use the selected frame. Value is PROP. */) | |
5842a27b | 4475 | (Lisp_Object prop, Lisp_Object frame) |
333b20bb | 4476 | { |
7452b7bd | 4477 | struct frame *f = decode_window_system_frame (frame); |
6b61353c | 4478 | Atom prop_atom; |
333b20bb | 4479 | |
6b61353c | 4480 | CHECK_STRING (prop); |
4d7e6e51 | 4481 | block_input (); |
42a5b22f | 4482 | prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SSDATA (prop), False); |
6b61353c | 4483 | XDeleteProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), prop_atom); |
333b20bb | 4484 | |
6b61353c KH |
4485 | /* Make sure the property is removed when we return. */ |
4486 | XFlush (FRAME_X_DISPLAY (f)); | |
4d7e6e51 | 4487 | unblock_input (); |
333b20bb | 4488 | |
6b61353c KH |
4489 | return prop; |
4490 | } | |
333b20bb | 4491 | |
333b20bb | 4492 | |
6b61353c KH |
4493 | DEFUN ("x-window-property", Fx_window_property, Sx_window_property, |
4494 | 1, 6, 0, | |
4495 | doc: /* Value is the value of window property PROP on FRAME. | |
4496 | If FRAME is nil or omitted, use the selected frame. | |
7c051dd8 | 4497 | |
7c051dd8 GM |
4498 | On X Windows, the following optional arguments are also accepted: |
4499 | If TYPE is nil or omitted, get the property as a string. | |
4500 | Otherwise TYPE is the name of the atom that denotes the type expected. | |
6b61353c KH |
4501 | If SOURCE is non-nil, get the property on that window instead of from |
4502 | FRAME. The number 0 denotes the root window. | |
ddadbc0e AS |
4503 | If DELETE-P is non-nil, delete the property after retrieving it. |
4504 | If VECTOR-RET-P is non-nil, don't return a string but a vector of values. | |
4505 | ||
4506 | On MS Windows, this function accepts but ignores those optional arguments. | |
6b61353c KH |
4507 | |
4508 | Value is nil if FRAME hasn't a property with name PROP or if PROP has | |
7c051dd8 | 4509 | no value of TYPE (always string in the MS Windows case). */) |
ddadbc0e AS |
4510 | (Lisp_Object prop, Lisp_Object frame, Lisp_Object type, |
4511 | Lisp_Object source, Lisp_Object delete_p, Lisp_Object vector_ret_p) | |
333b20bb | 4512 | { |
7452b7bd | 4513 | struct frame *f = decode_window_system_frame (frame); |
6b61353c KH |
4514 | Atom prop_atom; |
4515 | int rc; | |
4516 | Lisp_Object prop_value = Qnil; | |
a3db4b26 | 4517 | unsigned char *tmp_data = NULL; |
6b61353c KH |
4518 | Atom actual_type; |
4519 | Atom target_type = XA_STRING; | |
4520 | int actual_format; | |
4521 | unsigned long actual_size, bytes_remaining; | |
4522 | Window target_window = FRAME_X_WINDOW (f); | |
4523 | struct gcpro gcpro1; | |
177c0ea7 | 4524 | |
6b61353c KH |
4525 | GCPRO1 (prop_value); |
4526 | CHECK_STRING (prop); | |
1783ffa2 | 4527 | |
6b61353c KH |
4528 | if (! NILP (source)) |
4529 | { | |
be44ca6c PE |
4530 | CONS_TO_INTEGER (source, Window, target_window); |
4531 | if (! target_window) | |
aad3612f | 4532 | target_window = FRAME_DISPLAY_INFO (f)->root_window; |
333b20bb GM |
4533 | } |
4534 | ||
4d7e6e51 | 4535 | block_input (); |
6b61353c KH |
4536 | if (STRINGP (type)) |
4537 | { | |
42a5b22f | 4538 | if (strcmp ("AnyPropertyType", SSDATA (type)) == 0) |
6b61353c KH |
4539 | target_type = AnyPropertyType; |
4540 | else | |
42a5b22f | 4541 | target_type = XInternAtom (FRAME_X_DISPLAY (f), SSDATA (type), False); |
6b61353c | 4542 | } |
333b20bb | 4543 | |
42a5b22f | 4544 | prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SSDATA (prop), False); |
6b61353c KH |
4545 | rc = XGetWindowProperty (FRAME_X_DISPLAY (f), target_window, |
4546 | prop_atom, 0, 0, False, target_type, | |
4547 | &actual_type, &actual_format, &actual_size, | |
a3db4b26 | 4548 | &bytes_remaining, &tmp_data); |
6b61353c KH |
4549 | if (rc == Success) |
4550 | { | |
4551 | int size = bytes_remaining; | |
333b20bb | 4552 | |
6b61353c KH |
4553 | XFree (tmp_data); |
4554 | tmp_data = NULL; | |
333b20bb | 4555 | |
6b61353c | 4556 | rc = XGetWindowProperty (FRAME_X_DISPLAY (f), target_window, |
333b20bb | 4557 | prop_atom, 0, bytes_remaining, |
6b61353c | 4558 | ! NILP (delete_p), target_type, |
177c0ea7 JB |
4559 | &actual_type, &actual_format, |
4560 | &actual_size, &bytes_remaining, | |
a3db4b26 | 4561 | &tmp_data); |
4c8c7926 | 4562 | if (rc == Success && tmp_data) |
6b61353c | 4563 | { |
fede04ef JD |
4564 | /* The man page for XGetWindowProperty says: |
4565 | "If the returned format is 32, the returned data is represented | |
4566 | as a long array and should be cast to that type to obtain the | |
4567 | elements." | |
4568 | This applies even if long is more than 32 bits, the X library | |
4569 | converts from 32 bit elements received from the X server to long | |
72af86bd | 4570 | and passes the long array to us. Thus, for that case memcpy can not |
fede04ef JD |
4571 | be used. We convert to a 32 bit type here, because so much code |
4572 | assume on that. | |
4573 | ||
4574 | The bytes and offsets passed to XGetWindowProperty refers to the | |
4575 | property and those are indeed in 32 bit quantities if format is | |
4576 | 32. */ | |
4577 | ||
908589fd | 4578 | if (BITS_PER_LONG > 32 && actual_format == 32) |
fede04ef JD |
4579 | { |
4580 | unsigned long i; | |
4581 | int *idata = (int *) tmp_data; | |
4582 | long *ldata = (long *) tmp_data; | |
4583 | ||
4584 | for (i = 0; i < actual_size; ++i) | |
a3db4b26 | 4585 | idata[i] = (int) ldata[i]; |
fede04ef JD |
4586 | } |
4587 | ||
6b61353c | 4588 | if (NILP (vector_ret_p)) |
5f742c1b | 4589 | prop_value = make_string ((char *) tmp_data, size); |
6b61353c KH |
4590 | else |
4591 | prop_value = x_property_data_to_lisp (f, | |
a3db4b26 | 4592 | tmp_data, |
6b61353c KH |
4593 | actual_type, |
4594 | actual_format, | |
4595 | actual_size); | |
4596 | } | |
333b20bb | 4597 | |
6b61353c | 4598 | if (tmp_data) XFree (tmp_data); |
333b20bb GM |
4599 | } |
4600 | ||
4d7e6e51 | 4601 | unblock_input (); |
6b61353c | 4602 | UNGCPRO; |
333b20bb GM |
4603 | return prop_value; |
4604 | } | |
4605 | ||
4606 | ||
4607 | \f | |
4608 | /*********************************************************************** | |
4609 | Busy cursor | |
4610 | ***********************************************************************/ | |
4611 | ||
0af913d7 GM |
4612 | /* Timer function of hourglass_atimer. TIMER is equal to |
4613 | hourglass_atimer. | |
4ae9a85e | 4614 | |
0af913d7 GM |
4615 | Display an hourglass pointer on all frames by mapping the frames' |
4616 | hourglass_window. Set the hourglass_p flag in the frames' | |
4617 | output_data.x structure to indicate that an hourglass cursor is | |
4618 | shown on the frames. */ | |
4ae9a85e | 4619 | |
1885ab29 | 4620 | void |
971de7fb | 4621 | show_hourglass (struct atimer *timer) |
4ae9a85e GM |
4622 | { |
4623 | /* The timer implementation will cancel this timer automatically | |
0af913d7 | 4624 | after this function has run. Set hourglass_atimer to null |
4ae9a85e | 4625 | so that we know the timer doesn't have to be canceled. */ |
0af913d7 | 4626 | hourglass_atimer = NULL; |
4ae9a85e | 4627 | |
0af913d7 | 4628 | if (!hourglass_shown_p) |
333b20bb GM |
4629 | { |
4630 | Lisp_Object rest, frame; | |
177c0ea7 | 4631 | |
4d7e6e51 | 4632 | block_input (); |
177c0ea7 | 4633 | |
333b20bb | 4634 | FOR_EACH_FRAME (rest, frame) |
5f7a1890 GM |
4635 | { |
4636 | struct frame *f = XFRAME (frame); | |
177c0ea7 | 4637 | |
5f7a1890 GM |
4638 | if (FRAME_LIVE_P (f) && FRAME_X_P (f) && FRAME_X_DISPLAY (f)) |
4639 | { | |
4640 | Display *dpy = FRAME_X_DISPLAY (f); | |
177c0ea7 | 4641 | |
5f7a1890 GM |
4642 | #ifdef USE_X_TOOLKIT |
4643 | if (f->output_data.x->widget) | |
4644 | #else | |
4645 | if (FRAME_OUTER_WINDOW (f)) | |
4646 | #endif | |
4647 | { | |
0af913d7 | 4648 | f->output_data.x->hourglass_p = 1; |
177c0ea7 | 4649 | |
0af913d7 | 4650 | if (!f->output_data.x->hourglass_window) |
5f7a1890 GM |
4651 | { |
4652 | unsigned long mask = CWCursor; | |
4653 | XSetWindowAttributes attrs; | |
49b8b5dc JD |
4654 | #ifdef USE_GTK |
4655 | Window parent = FRAME_X_WINDOW (f); | |
4656 | #else | |
4657 | Window parent = FRAME_OUTER_WINDOW (f); | |
4658 | #endif | |
0af913d7 | 4659 | attrs.cursor = f->output_data.x->hourglass_cursor; |
177c0ea7 | 4660 | |
0af913d7 | 4661 | f->output_data.x->hourglass_window |
49b8b5dc | 4662 | = XCreateWindow (dpy, parent, |
5f7a1890 GM |
4663 | 0, 0, 32000, 32000, 0, 0, |
4664 | InputOnly, | |
4665 | CopyFromParent, | |
4666 | mask, &attrs); | |
4667 | } | |
177c0ea7 | 4668 | |
0af913d7 | 4669 | XMapRaised (dpy, f->output_data.x->hourglass_window); |
5f7a1890 GM |
4670 | XFlush (dpy); |
4671 | } | |
4672 | } | |
4673 | } | |
333b20bb | 4674 | |
0af913d7 | 4675 | hourglass_shown_p = 1; |
4d7e6e51 | 4676 | unblock_input (); |
4ae9a85e | 4677 | } |
333b20bb GM |
4678 | } |
4679 | ||
4680 | ||
0af913d7 GM |
4681 | /* Hide the hourglass pointer on all frames, if it is currently |
4682 | shown. */ | |
333b20bb | 4683 | |
1885ab29 | 4684 | void |
971de7fb | 4685 | hide_hourglass (void) |
4ae9a85e | 4686 | { |
0af913d7 | 4687 | if (hourglass_shown_p) |
333b20bb | 4688 | { |
4ae9a85e GM |
4689 | Lisp_Object rest, frame; |
4690 | ||
4d7e6e51 | 4691 | block_input (); |
4ae9a85e | 4692 | FOR_EACH_FRAME (rest, frame) |
333b20bb | 4693 | { |
4ae9a85e | 4694 | struct frame *f = XFRAME (frame); |
177c0ea7 | 4695 | |
4ae9a85e GM |
4696 | if (FRAME_X_P (f) |
4697 | /* Watch out for newly created frames. */ | |
0af913d7 | 4698 | && f->output_data.x->hourglass_window) |
4ae9a85e | 4699 | { |
0af913d7 GM |
4700 | XUnmapWindow (FRAME_X_DISPLAY (f), |
4701 | f->output_data.x->hourglass_window); | |
4702 | /* Sync here because XTread_socket looks at the | |
4703 | hourglass_p flag that is reset to zero below. */ | |
4ae9a85e | 4704 | XSync (FRAME_X_DISPLAY (f), False); |
0af913d7 | 4705 | f->output_data.x->hourglass_p = 0; |
4ae9a85e | 4706 | } |
333b20bb | 4707 | } |
333b20bb | 4708 | |
0af913d7 | 4709 | hourglass_shown_p = 0; |
4d7e6e51 | 4710 | unblock_input (); |
4ae9a85e | 4711 | } |
333b20bb GM |
4712 | } |
4713 | ||
4714 | ||
4715 | \f | |
4716 | /*********************************************************************** | |
4717 | Tool tips | |
4718 | ***********************************************************************/ | |
4719 | ||
f57e2426 J |
4720 | static Lisp_Object x_create_tip_frame (struct x_display_info *, |
4721 | Lisp_Object, Lisp_Object); | |
4722 | static void compute_tip_xy (struct frame *, Lisp_Object, Lisp_Object, | |
4723 | Lisp_Object, int, int, int *, int *); | |
177c0ea7 | 4724 | |
44b5a125 | 4725 | /* The frame of a currently visible tooltip. */ |
333b20bb | 4726 | |
44b5a125 | 4727 | Lisp_Object tip_frame; |
333b20bb GM |
4728 | |
4729 | /* If non-nil, a timer started that hides the last tooltip when it | |
4730 | fires. */ | |
4731 | ||
e4cebfca | 4732 | static Lisp_Object tip_timer; |
333b20bb GM |
4733 | Window tip_window; |
4734 | ||
06d62053 GM |
4735 | /* If non-nil, a vector of 3 elements containing the last args |
4736 | with which x-show-tip was called. See there. */ | |
4737 | ||
e4cebfca | 4738 | static Lisp_Object last_show_tip_args; |
06d62053 | 4739 | |
eaf1eea9 | 4740 | |
27e498e6 | 4741 | static void |
971de7fb | 4742 | unwind_create_tip_frame (Lisp_Object frame) |
eaf1eea9 | 4743 | { |
c844a81a GM |
4744 | Lisp_Object deleted; |
4745 | ||
4746 | deleted = unwind_create_frame (frame); | |
4747 | if (EQ (deleted, Qt)) | |
4748 | { | |
4749 | tip_window = None; | |
4750 | tip_frame = Qnil; | |
4751 | } | |
eaf1eea9 GM |
4752 | } |
4753 | ||
4754 | ||
333b20bb | 4755 | /* Create a frame for a tooltip on the display described by DPYINFO. |
275841bf GM |
4756 | PARMS is a list of frame parameters. TEXT is the string to |
4757 | display in the tip frame. Value is the frame. | |
eaf1eea9 GM |
4758 | |
4759 | Note that functions called here, esp. x_default_parameter can | |
4760 | signal errors, for instance when a specified color name is | |
4761 | undefined. We have to make sure that we're in a consistent state | |
4762 | when this happens. */ | |
333b20bb GM |
4763 | |
4764 | static Lisp_Object | |
aa1859f5 J |
4765 | x_create_tip_frame (struct x_display_info *dpyinfo, |
4766 | Lisp_Object parms, | |
4767 | Lisp_Object text) | |
333b20bb GM |
4768 | { |
4769 | struct frame *f; | |
06b0c8a0 | 4770 | Lisp_Object frame; |
333b20bb | 4771 | Lisp_Object name; |
333b20bb | 4772 | int width, height; |
d311d28c | 4773 | ptrdiff_t count = SPECPDL_INDEX (); |
b6d7acec | 4774 | struct gcpro gcpro1, gcpro2, gcpro3; |
06d62053 | 4775 | int face_change_count_before = face_change_count; |
275841bf GM |
4776 | Lisp_Object buffer; |
4777 | struct buffer *old_buffer; | |
333b20bb | 4778 | |
89acb56d SM |
4779 | if (!dpyinfo->terminal->name) |
4780 | error ("Terminal is not live, can't create new frames on it"); | |
333b20bb | 4781 | |
47f3c6b4 | 4782 | parms = Fcopy_alist (parms); |
333b20bb GM |
4783 | |
4784 | /* Get the name of the frame to use for resource lookup. */ | |
4785 | name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING); | |
4786 | if (!STRINGP (name) | |
4787 | && !EQ (name, Qunbound) | |
4788 | && !NILP (name)) | |
4789 | error ("Invalid frame name--not a string or nil"); | |
333b20bb GM |
4790 | |
4791 | frame = Qnil; | |
4792 | GCPRO3 (parms, name, frame); | |
44b5a125 | 4793 | f = make_frame (1); |
333b20bb | 4794 | XSETFRAME (frame, f); |
275841bf GM |
4795 | |
4796 | buffer = Fget_buffer_create (build_string (" *tip*")); | |
08908aca MR |
4797 | /* Use set_window_buffer instead of Fset_window_buffer (see |
4798 | discussion of bug#11984, bug#12025, bug#12026). */ | |
4799 | set_window_buffer (FRAME_ROOT_WINDOW (f), buffer, 0, 0); | |
275841bf GM |
4800 | old_buffer = current_buffer; |
4801 | set_buffer_internal_1 (XBUFFER (buffer)); | |
39eb03f1 | 4802 | bset_truncate_lines (current_buffer, Qnil); |
5c2a995d KH |
4803 | specbind (Qinhibit_read_only, Qt); |
4804 | specbind (Qinhibit_modification_hooks, Qt); | |
275841bf GM |
4805 | Ferase_buffer (); |
4806 | Finsert (1, &text); | |
4807 | set_buffer_internal_1 (old_buffer); | |
177c0ea7 | 4808 | |
8a1a7743 | 4809 | record_unwind_protect (unwind_create_tip_frame, frame); |
333b20bb | 4810 | |
6ed8eeff | 4811 | f->terminal = dpyinfo->terminal; |
daf01701 | 4812 | |
eaf1eea9 GM |
4813 | /* By setting the output method, we're essentially saying that |
4814 | the frame is live, as per FRAME_LIVE_P. If we get a signal | |
4815 | from this point on, x_destroy_window might screw up reference | |
4816 | counts etc. */ | |
333b20bb | 4817 | f->output_method = output_x_window; |
38182d90 | 4818 | f->output_data.x = xzalloc (sizeof *f->output_data.x); |
333b20bb | 4819 | f->output_data.x->icon_bitmap = -1; |
be786000 | 4820 | FRAME_FONTSET (f) = -1; |
61d461a8 GM |
4821 | f->output_data.x->scroll_bar_foreground_pixel = -1; |
4822 | f->output_data.x->scroll_bar_background_pixel = -1; | |
f15340b7 MB |
4823 | #ifdef USE_TOOLKIT_SCROLL_BARS |
4824 | f->output_data.x->scroll_bar_top_shadow_pixel = -1; | |
4825 | f->output_data.x->scroll_bar_bottom_shadow_pixel = -1; | |
4826 | #endif /* USE_TOOLKIT_SCROLL_BARS */ | |
f00af5b1 | 4827 | fset_icon_name (f, Qnil); |
aad3612f DA |
4828 | FRAME_DISPLAY_INFO (f) = dpyinfo; |
4829 | f->output_data.x->parent_desc = FRAME_DISPLAY_INFO (f)->root_window; | |
333b20bb GM |
4830 | f->output_data.x->explicit_parent = 0; |
4831 | ||
61d461a8 GM |
4832 | /* These colors will be set anyway later, but it's important |
4833 | to get the color reference counts right, so initialize them! */ | |
4834 | { | |
4835 | Lisp_Object black; | |
dbf31225 | 4836 | struct gcpro gcpro1; |
177c0ea7 | 4837 | |
9d3d44ba KL |
4838 | /* Function x_decode_color can signal an error. Make |
4839 | sure to initialize color slots so that we won't try | |
4840 | to free colors we haven't allocated. */ | |
ce593f6e KL |
4841 | FRAME_FOREGROUND_PIXEL (f) = -1; |
4842 | FRAME_BACKGROUND_PIXEL (f) = -1; | |
9d3d44ba KL |
4843 | f->output_data.x->cursor_pixel = -1; |
4844 | f->output_data.x->cursor_foreground_pixel = -1; | |
4845 | f->output_data.x->border_pixel = -1; | |
4846 | f->output_data.x->mouse_pixel = -1; | |
4847 | ||
61d461a8 | 4848 | black = build_string ("black"); |
dbf31225 | 4849 | GCPRO1 (black); |
ce593f6e | 4850 | FRAME_FOREGROUND_PIXEL (f) |
61d461a8 | 4851 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); |
ce593f6e | 4852 | FRAME_BACKGROUND_PIXEL (f) |
61d461a8 GM |
4853 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); |
4854 | f->output_data.x->cursor_pixel | |
4855 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
4856 | f->output_data.x->cursor_foreground_pixel | |
4857 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
4858 | f->output_data.x->border_pixel | |
4859 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
4860 | f->output_data.x->mouse_pixel | |
4861 | = x_decode_color (f, black, BLACK_PIX_DEFAULT (f)); | |
dbf31225 | 4862 | UNGCPRO; |
61d461a8 GM |
4863 | } |
4864 | ||
333b20bb GM |
4865 | /* Set the name; the functions to which we pass f expect the name to |
4866 | be set. */ | |
4867 | if (EQ (name, Qunbound) || NILP (name)) | |
4868 | { | |
f00af5b1 | 4869 | fset_name (f, build_string (dpyinfo->x_id_name)); |
333b20bb GM |
4870 | f->explicit_name = 0; |
4871 | } | |
4872 | else | |
4873 | { | |
f00af5b1 | 4874 | fset_name (f, name); |
333b20bb GM |
4875 | f->explicit_name = 1; |
4876 | /* use the frame's title when getting resources for this frame. */ | |
4877 | specbind (Qx_resource_name, name); | |
4878 | } | |
4879 | ||
bf970f2b | 4880 | register_font_driver (&xfont_driver, f); |
02ed2ea8 KH |
4881 | #ifdef HAVE_FREETYPE |
4882 | #ifdef HAVE_XFT | |
b51238f5 | 4883 | register_font_driver (&xftfont_driver, f); |
02ed2ea8 | 4884 | #else /* not HAVE_XFT */ |
b51238f5 | 4885 | register_font_driver (&ftxfont_driver, f); |
02ed2ea8 KH |
4886 | #endif /* not HAVE_XFT */ |
4887 | #endif /* HAVE_FREETYPE */ | |
d43f6b74 | 4888 | |
b51238f5 KH |
4889 | x_default_parameter (f, parms, Qfont_backend, Qnil, |
4890 | "fontBackend", "FontBackend", RES_TYPE_STRING); | |
02ed2ea8 | 4891 | |
eaf1eea9 GM |
4892 | /* Extract the window parameters from the supplied values that are |
4893 | needed to determine window geometry. */ | |
b51238f5 | 4894 | x_default_font_parameter (f, parms); |
333b20bb | 4895 | |
4bef8d26 | 4896 | x_default_parameter (f, parms, Qborder_width, make_number (0), |
333b20bb | 4897 | "borderWidth", "BorderWidth", RES_TYPE_NUMBER); |
177c0ea7 | 4898 | |
333b20bb GM |
4899 | /* This defaults to 2 in order to match xterm. We recognize either |
4900 | internalBorderWidth or internalBorder (which is what xterm calls | |
4901 | it). */ | |
4902 | if (NILP (Fassq (Qinternal_border_width, parms))) | |
4903 | { | |
4904 | Lisp_Object value; | |
4905 | ||
4906 | value = x_get_arg (dpyinfo, parms, Qinternal_border_width, | |
4907 | "internalBorder", "internalBorder", RES_TYPE_NUMBER); | |
4908 | if (! EQ (value, Qunbound)) | |
4909 | parms = Fcons (Fcons (Qinternal_border_width, value), | |
4910 | parms); | |
4911 | } | |
4912 | ||
4913 | x_default_parameter (f, parms, Qinternal_border_width, make_number (1), | |
4914 | "internalBorderWidth", "internalBorderWidth", | |
4915 | RES_TYPE_NUMBER); | |
4916 | ||
4917 | /* Also do the stuff which must be set before the window exists. */ | |
4918 | x_default_parameter (f, parms, Qforeground_color, build_string ("black"), | |
4919 | "foreground", "Foreground", RES_TYPE_STRING); | |
4920 | x_default_parameter (f, parms, Qbackground_color, build_string ("white"), | |
4921 | "background", "Background", RES_TYPE_STRING); | |
4922 | x_default_parameter (f, parms, Qmouse_color, build_string ("black"), | |
4923 | "pointerColor", "Foreground", RES_TYPE_STRING); | |
4924 | x_default_parameter (f, parms, Qcursor_color, build_string ("black"), | |
4925 | "cursorColor", "Foreground", RES_TYPE_STRING); | |
4926 | x_default_parameter (f, parms, Qborder_color, build_string ("black"), | |
4927 | "borderColor", "BorderColor", RES_TYPE_STRING); | |
4928 | ||
e509cfa6 | 4929 | #ifdef GLYPH_DEBUG |
c9e7db78 JD |
4930 | image_cache_refcount = |
4931 | FRAME_IMAGE_CACHE (f) ? FRAME_IMAGE_CACHE (f)->refcount : 0; | |
4932 | dpyinfo_refcount = dpyinfo->reference_count; | |
4933 | #endif /* GLYPH_DEBUG */ | |
4934 | ||
333b20bb GM |
4935 | /* Init faces before x_default_parameter is called for scroll-bar |
4936 | parameters because that function calls x_set_scroll_bar_width, | |
4937 | which calls change_frame_size, which calls Fset_window_buffer, | |
4938 | which runs hooks, which call Fvertical_motion. At the end, we | |
4939 | end up in init_iterator with a null face cache, which should not | |
4940 | happen. */ | |
4941 | init_frame_faces (f); | |
177c0ea7 | 4942 | |
aad3612f | 4943 | f->output_data.x->parent_desc = FRAME_DISPLAY_INFO (f)->root_window; |
333b20bb | 4944 | |
0ce7538d | 4945 | x_figure_window_size (f, parms, 0); |
333b20bb | 4946 | |
333b20bb GM |
4947 | { |
4948 | XSetWindowAttributes attrs; | |
4949 | unsigned long mask; | |
aad3612f | 4950 | Atom type = FRAME_DISPLAY_INFO (f)->Xatom_net_window_type_tooltip; |
177c0ea7 | 4951 | |
4d7e6e51 | 4952 | block_input (); |
c51d2b5e GM |
4953 | mask = CWBackPixel | CWOverrideRedirect | CWEventMask; |
4954 | if (DoesSaveUnders (dpyinfo->screen)) | |
4955 | mask |= CWSaveUnder; | |
177c0ea7 | 4956 | |
9b2956e2 GM |
4957 | /* Window managers look at the override-redirect flag to determine |
4958 | whether or net to give windows a decoration (Xlib spec, chapter | |
333b20bb GM |
4959 | 3.2.8). */ |
4960 | attrs.override_redirect = True; | |
4961 | attrs.save_under = True; | |
4962 | attrs.background_pixel = FRAME_BACKGROUND_PIXEL (f); | |
4963 | /* Arrange for getting MapNotify and UnmapNotify events. */ | |
4964 | attrs.event_mask = StructureNotifyMask; | |
4965 | tip_window | |
4966 | = FRAME_X_WINDOW (f) | |
4967 | = XCreateWindow (FRAME_X_DISPLAY (f), | |
aad3612f | 4968 | FRAME_DISPLAY_INFO (f)->root_window, |
333b20bb GM |
4969 | /* x, y, width, height */ |
4970 | 0, 0, 1, 1, | |
4971 | /* Border. */ | |
a979dde1 | 4972 | f->border_width, |
333b20bb GM |
4973 | CopyFromParent, InputOutput, CopyFromParent, |
4974 | mask, &attrs); | |
36acb2a7 | 4975 | XChangeProperty (FRAME_X_DISPLAY (f), tip_window, |
aad3612f | 4976 | FRAME_DISPLAY_INFO (f)->Xatom_net_window_type, |
36acb2a7 JD |
4977 | XA_ATOM, 32, PropModeReplace, |
4978 | (unsigned char *)&type, 1); | |
4d7e6e51 | 4979 | unblock_input (); |
333b20bb GM |
4980 | } |
4981 | ||
4982 | x_make_gc (f); | |
4983 | ||
333b20bb GM |
4984 | x_default_parameter (f, parms, Qauto_raise, Qnil, |
4985 | "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN); | |
4986 | x_default_parameter (f, parms, Qauto_lower, Qnil, | |
4987 | "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN); | |
4988 | x_default_parameter (f, parms, Qcursor_type, Qbox, | |
4989 | "cursorType", "CursorType", RES_TYPE_SYMBOL); | |
4990 | ||
be786000 | 4991 | /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size. |
333b20bb | 4992 | Change will not be effected unless different from the current |
be786000 KS |
4993 | FRAME_LINES (f). */ |
4994 | width = FRAME_COLS (f); | |
4995 | height = FRAME_LINES (f); | |
4996 | SET_FRAME_COLS (f, 0); | |
4997 | FRAME_LINES (f) = 0; | |
8938a4fb | 4998 | change_frame_size (f, height, width, 1, 0, 0); |
177c0ea7 | 4999 | |
cd1d850f | 5000 | /* Add `tooltip' frame parameter's default value. */ |
54ee7410 | 5001 | if (NILP (Fframe_parameter (frame, Qtooltip))) |
6c6f1994 | 5002 | Fmodify_frame_parameters (frame, list1 (Fcons (Qtooltip, Qt))); |
177c0ea7 | 5003 | |
cedb4d8b GM |
5004 | /* FIXME - can this be done in a similar way to normal frames? |
5005 | http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00641.html */ | |
5006 | ||
35fdaa62 GM |
5007 | /* Set the `display-type' frame parameter before setting up faces. */ |
5008 | { | |
5009 | Lisp_Object disptype; | |
5010 | ||
aad3612f | 5011 | if (FRAME_DISPLAY_INFO (f)->n_planes == 1) |
35fdaa62 | 5012 | disptype = intern ("mono"); |
aad3612f DA |
5013 | else if (FRAME_DISPLAY_INFO (f)->visual->class == GrayScale |
5014 | || FRAME_DISPLAY_INFO (f)->visual->class == StaticGray) | |
35fdaa62 GM |
5015 | disptype = intern ("grayscale"); |
5016 | else | |
5017 | disptype = intern ("color"); | |
5018 | ||
5019 | if (NILP (Fframe_parameter (frame, Qdisplay_type))) | |
6c6f1994 | 5020 | Fmodify_frame_parameters (frame, list1 (Fcons (Qdisplay_type, disptype))); |
35fdaa62 GM |
5021 | } |
5022 | ||
035d5114 | 5023 | /* Set up faces after all frame parameters are known. This call |
6801a572 GM |
5024 | also merges in face attributes specified for new frames. |
5025 | ||
5026 | Frame parameters may be changed if .Xdefaults contains | |
5027 | specifications for the default font. For example, if there is an | |
5028 | `Emacs.default.attributeBackground: pink', the `background-color' | |
5029 | attribute of the frame get's set, which let's the internal border | |
5030 | of the tooltip frame appear in pink. Prevent this. */ | |
5031 | { | |
5032 | Lisp_Object bg = Fframe_parameter (frame, Qbackground_color); | |
5033 | ||
5034 | /* Set tip_frame here, so that */ | |
5035 | tip_frame = frame; | |
45cebfd9 | 5036 | call2 (Qface_set_after_frame_default, frame, Qnil); |
177c0ea7 | 5037 | |
6801a572 | 5038 | if (!EQ (bg, Fframe_parameter (frame, Qbackground_color))) |
6c6f1994 | 5039 | Fmodify_frame_parameters (frame, list1 (Fcons (Qbackground_color, bg))); |
6801a572 | 5040 | } |
177c0ea7 | 5041 | |
333b20bb GM |
5042 | f->no_split = 1; |
5043 | ||
5044 | UNGCPRO; | |
5045 | ||
c9e7db78 JD |
5046 | /* Now that the frame will be official, it counts as a reference to |
5047 | its display and terminal. */ | |
aad3612f | 5048 | FRAME_DISPLAY_INFO (f)->reference_count++; |
c9e7db78 JD |
5049 | f->terminal->reference_count++; |
5050 | ||
333b20bb GM |
5051 | /* It is now ok to make the frame official even if we get an error |
5052 | below. And the frame needs to be on Vframe_list or making it | |
5053 | visible won't work. */ | |
5054 | Vframe_list = Fcons (frame, Vframe_list); | |
5055 | ||
333b20bb | 5056 | |
06d62053 GM |
5057 | /* Setting attributes of faces of the tooltip frame from resources |
5058 | and similar will increment face_change_count, which leads to the | |
5059 | clearing of all current matrices. Since this isn't necessary | |
5060 | here, avoid it by resetting face_change_count to the value it | |
5061 | had before we created the tip frame. */ | |
5062 | face_change_count = face_change_count_before; | |
5063 | ||
eaf1eea9 | 5064 | /* Discard the unwind_protect. */ |
333b20bb GM |
5065 | return unbind_to (count, frame); |
5066 | } | |
5067 | ||
5068 | ||
06d62053 GM |
5069 | /* Compute where to display tip frame F. PARMS is the list of frame |
5070 | parameters for F. DX and DY are specified offsets from the current | |
ab452f99 GM |
5071 | location of the mouse. WIDTH and HEIGHT are the width and height |
5072 | of the tooltip. Return coordinates relative to the root window of | |
5073 | the display in *ROOT_X, and *ROOT_Y. */ | |
06d62053 GM |
5074 | |
5075 | static void | |
971de7fb | 5076 | compute_tip_xy (struct frame *f, Lisp_Object parms, Lisp_Object dx, Lisp_Object dy, int width, int height, int *root_x, int *root_y) |
06d62053 GM |
5077 | { |
5078 | Lisp_Object left, top; | |
5079 | int win_x, win_y; | |
5080 | Window root, child; | |
5081 | unsigned pmask; | |
177c0ea7 | 5082 | |
06d62053 GM |
5083 | /* User-specified position? */ |
5084 | left = Fcdr (Fassq (Qleft, parms)); | |
5085 | top = Fcdr (Fassq (Qtop, parms)); | |
177c0ea7 | 5086 | |
06d62053 GM |
5087 | /* Move the tooltip window where the mouse pointer is. Resize and |
5088 | show it. */ | |
570d22b0 | 5089 | if (!INTEGERP (left) || !INTEGERP (top)) |
ab452f99 | 5090 | { |
4d7e6e51 | 5091 | block_input (); |
aad3612f | 5092 | XQueryPointer (FRAME_X_DISPLAY (f), FRAME_DISPLAY_INFO (f)->root_window, |
ab452f99 | 5093 | &root, &child, root_x, root_y, &win_x, &win_y, &pmask); |
4d7e6e51 | 5094 | unblock_input (); |
ab452f99 | 5095 | } |
06d62053 | 5096 | |
06d62053 GM |
5097 | if (INTEGERP (top)) |
5098 | *root_y = XINT (top); | |
bf63eb69 JD |
5099 | else if (*root_y + XINT (dy) <= 0) |
5100 | *root_y = 0; /* Can happen for negative dy */ | |
abe9d29c | 5101 | else if (*root_y + XINT (dy) + height |
aad3612f | 5102 | <= x_display_pixel_height (FRAME_DISPLAY_INFO (f))) |
7e8410d1 | 5103 | /* It fits below the pointer */ |
abe9d29c | 5104 | *root_y += XINT (dy); |
7e8410d1 JD |
5105 | else if (height + XINT (dy) <= *root_y) |
5106 | /* It fits above the pointer. */ | |
5107 | *root_y -= height + XINT (dy); | |
5108 | else | |
5109 | /* Put it on the top. */ | |
5110 | *root_y = 0; | |
ab452f99 GM |
5111 | |
5112 | if (INTEGERP (left)) | |
5113 | *root_x = XINT (left); | |
bf63eb69 JD |
5114 | else if (*root_x + XINT (dx) <= 0) |
5115 | *root_x = 0; /* Can happen for negative dx */ | |
abe9d29c | 5116 | else if (*root_x + XINT (dx) + width |
aad3612f | 5117 | <= x_display_pixel_width (FRAME_DISPLAY_INFO (f))) |
d682d3df RS |
5118 | /* It fits to the right of the pointer. */ |
5119 | *root_x += XINT (dx); | |
5120 | else if (width + XINT (dx) <= *root_x) | |
5121 | /* It fits to the left of the pointer. */ | |
ab452f99 GM |
5122 | *root_x -= width + XINT (dx); |
5123 | else | |
d682d3df RS |
5124 | /* Put it left-justified on the screen--it ought to fit that way. */ |
5125 | *root_x = 0; | |
06d62053 GM |
5126 | } |
5127 | ||
5128 | ||
0634ce98 | 5129 | DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0, |
7ee72033 | 5130 | doc: /* Show STRING in a "tooltip" window on frame FRAME. |
c061c855 GM |
5131 | A tooltip window is a small X window displaying a string. |
5132 | ||
87c891c7 EZ |
5133 | This is an internal function; Lisp code should call `tooltip-show'. |
5134 | ||
c061c855 GM |
5135 | FRAME nil or omitted means use the selected frame. |
5136 | ||
5137 | PARMS is an optional list of frame parameters which can be used to | |
5138 | change the tooltip's appearance. | |
5139 | ||
5140 | Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil | |
5141 | means use the default timeout of 5 seconds. | |
5142 | ||
c869cc37 | 5143 | If the list of frame parameters PARMS contains a `left' parameters, |
c061c855 GM |
5144 | the tooltip is displayed at that x-position. Otherwise it is |
5145 | displayed at the mouse position, with offset DX added (default is 5 if | |
5146 | DX isn't specified). Likewise for the y-position; if a `top' frame | |
5147 | parameter is specified, it determines the y-position of the tooltip | |
5148 | window, otherwise it is displayed at the mouse position, with offset | |
5149 | DY added (default is -10). | |
5150 | ||
5151 | A tooltip's maximum size is specified by `x-max-tooltip-size'. | |
7ee72033 | 5152 | Text larger than the specified size is clipped. */) |
5842a27b | 5153 | (Lisp_Object string, Lisp_Object frame, Lisp_Object parms, Lisp_Object timeout, Lisp_Object dx, Lisp_Object dy) |
333b20bb GM |
5154 | { |
5155 | struct frame *f; | |
5156 | struct window *w; | |
06d62053 | 5157 | int root_x, root_y; |
333b20bb GM |
5158 | struct buffer *old_buffer; |
5159 | struct text_pos pos; | |
a971c0a7 | 5160 | int i, width, height, seen_reversed_p; |
393f2d14 | 5161 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
333b20bb | 5162 | int old_windows_or_buffers_changed = windows_or_buffers_changed; |
d311d28c | 5163 | ptrdiff_t count = SPECPDL_INDEX (); |
177c0ea7 | 5164 | |
333b20bb GM |
5165 | specbind (Qinhibit_redisplay, Qt); |
5166 | ||
393f2d14 | 5167 | GCPRO4 (string, parms, frame, timeout); |
333b20bb | 5168 | |
b7826503 | 5169 | CHECK_STRING (string); |
2d7117fe JD |
5170 | if (SCHARS (string) == 0) |
5171 | string = make_unibyte_string (" ", 1); | |
5172 | ||
7452b7bd | 5173 | f = decode_window_system_frame (frame); |
333b20bb GM |
5174 | if (NILP (timeout)) |
5175 | timeout = make_number (5); | |
5176 | else | |
b7826503 | 5177 | CHECK_NATNUM (timeout); |
177c0ea7 | 5178 | |
0634ce98 GM |
5179 | if (NILP (dx)) |
5180 | dx = make_number (5); | |
5181 | else | |
b7826503 | 5182 | CHECK_NUMBER (dx); |
177c0ea7 | 5183 | |
0634ce98 | 5184 | if (NILP (dy)) |
12c67a7f | 5185 | dy = make_number (-10); |
0634ce98 | 5186 | else |
b7826503 | 5187 | CHECK_NUMBER (dy); |
333b20bb | 5188 | |
aa1859f5 J |
5189 | #ifdef USE_GTK |
5190 | if (x_gtk_use_system_tooltips) | |
5191 | { | |
18e27ea8 | 5192 | bool ok; |
aa1859f5 J |
5193 | |
5194 | /* Hide a previous tip, if any. */ | |
5195 | Fx_hide_tip (); | |
5196 | ||
4d7e6e51 | 5197 | block_input (); |
18e27ea8 PE |
5198 | ok = xg_prepare_tooltip (f, string, &width, &height); |
5199 | if (ok) | |
aa1859f5 J |
5200 | { |
5201 | compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y); | |
5202 | xg_show_tooltip (f, root_x, root_y); | |
5203 | /* This is used in Fx_hide_tip. */ | |
5204 | XSETFRAME (tip_frame, f); | |
5205 | } | |
4d7e6e51 | 5206 | unblock_input (); |
aa1859f5 J |
5207 | if (ok) goto start_timer; |
5208 | } | |
5209 | #endif /* USE_GTK */ | |
5210 | ||
06d62053 GM |
5211 | if (NILP (last_show_tip_args)) |
5212 | last_show_tip_args = Fmake_vector (make_number (3), Qnil); | |
5213 | ||
5214 | if (!NILP (tip_frame)) | |
5215 | { | |
5216 | Lisp_Object last_string = AREF (last_show_tip_args, 0); | |
5217 | Lisp_Object last_frame = AREF (last_show_tip_args, 1); | |
5218 | Lisp_Object last_parms = AREF (last_show_tip_args, 2); | |
5219 | ||
5220 | if (EQ (frame, last_frame) | |
5221 | && !NILP (Fequal (last_string, string)) | |
5222 | && !NILP (Fequal (last_parms, parms))) | |
5223 | { | |
58d2d479 | 5224 | struct frame *tip_f = XFRAME (tip_frame); |
177c0ea7 | 5225 | |
06d62053 GM |
5226 | /* Only DX and DY have changed. */ |
5227 | if (!NILP (tip_timer)) | |
ae782866 GM |
5228 | { |
5229 | Lisp_Object timer = tip_timer; | |
5230 | tip_timer = Qnil; | |
5231 | call1 (Qcancel_timer, timer); | |
5232 | } | |
06d62053 | 5233 | |
4d7e6e51 | 5234 | block_input (); |
58d2d479 PE |
5235 | compute_tip_xy (tip_f, parms, dx, dy, FRAME_PIXEL_WIDTH (tip_f), |
5236 | FRAME_PIXEL_HEIGHT (tip_f), &root_x, &root_y); | |
5237 | XMoveWindow (FRAME_X_DISPLAY (tip_f), FRAME_X_WINDOW (tip_f), | |
ab452f99 | 5238 | root_x, root_y); |
4d7e6e51 | 5239 | unblock_input (); |
06d62053 GM |
5240 | goto start_timer; |
5241 | } | |
5242 | } | |
5243 | ||
333b20bb GM |
5244 | /* Hide a previous tip, if any. */ |
5245 | Fx_hide_tip (); | |
5246 | ||
06d62053 GM |
5247 | ASET (last_show_tip_args, 0, string); |
5248 | ASET (last_show_tip_args, 1, frame); | |
5249 | ASET (last_show_tip_args, 2, parms); | |
5250 | ||
333b20bb GM |
5251 | /* Add default values to frame parameters. */ |
5252 | if (NILP (Fassq (Qname, parms))) | |
5253 | parms = Fcons (Fcons (Qname, build_string ("tooltip")), parms); | |
5254 | if (NILP (Fassq (Qinternal_border_width, parms))) | |
5255 | parms = Fcons (Fcons (Qinternal_border_width, make_number (3)), parms); | |
5256 | if (NILP (Fassq (Qborder_width, parms))) | |
5257 | parms = Fcons (Fcons (Qborder_width, make_number (1)), parms); | |
5258 | if (NILP (Fassq (Qborder_color, parms))) | |
5259 | parms = Fcons (Fcons (Qborder_color, build_string ("lightyellow")), parms); | |
5260 | if (NILP (Fassq (Qbackground_color, parms))) | |
5261 | parms = Fcons (Fcons (Qbackground_color, build_string ("lightyellow")), | |
5262 | parms); | |
5263 | ||
5264 | /* Create a frame for the tooltip, and record it in the global | |
5265 | variable tip_frame. */ | |
aad3612f | 5266 | frame = x_create_tip_frame (FRAME_DISPLAY_INFO (f), parms, string); |
44b5a125 | 5267 | f = XFRAME (frame); |
333b20bb | 5268 | |
d63931a2 | 5269 | /* Set up the frame's root window. */ |
333b20bb | 5270 | w = XWINDOW (FRAME_ROOT_WINDOW (f)); |
5f24fa51 DA |
5271 | w->left_col = 0; |
5272 | w->top_line = 0; | |
177c0ea7 | 5273 | |
d63931a2 | 5274 | if (CONSP (Vx_max_tooltip_size) |
d311d28c PE |
5275 | && RANGED_INTEGERP (1, XCAR (Vx_max_tooltip_size), INT_MAX) |
5276 | && RANGED_INTEGERP (1, XCDR (Vx_max_tooltip_size), INT_MAX)) | |
d63931a2 | 5277 | { |
5f24fa51 DA |
5278 | w->total_cols = XFASTINT (XCAR (Vx_max_tooltip_size)); |
5279 | w->total_lines = XFASTINT (XCDR (Vx_max_tooltip_size)); | |
d63931a2 GM |
5280 | } |
5281 | else | |
5282 | { | |
5f24fa51 DA |
5283 | w->total_cols = 80; |
5284 | w->total_lines = 40; | |
d63931a2 | 5285 | } |
177c0ea7 | 5286 | |
5f24fa51 | 5287 | FRAME_TOTAL_COLS (f) = w->total_cols; |
bd0443bb | 5288 | adjust_frame_glyphs (f); |
333b20bb GM |
5289 | w->pseudo_window_p = 1; |
5290 | ||
5291 | /* Display the tooltip text in a temporary buffer. */ | |
333b20bb | 5292 | old_buffer = current_buffer; |
e74aeda8 | 5293 | set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f))->contents)); |
39eb03f1 | 5294 | bset_truncate_lines (current_buffer, Qnil); |
5634ff85 YM |
5295 | clear_glyph_matrix (w->desired_matrix); |
5296 | clear_glyph_matrix (w->current_matrix); | |
5297 | SET_TEXT_POS (pos, BEGV, BEGV_BYTE); | |
6eff5c3d | 5298 | try_window (FRAME_ROOT_WINDOW (f), pos, TRY_WINDOW_IGNORE_FONTS_CHANGE); |
333b20bb GM |
5299 | |
5300 | /* Compute width and height of the tooltip. */ | |
a971c0a7 | 5301 | width = height = seen_reversed_p = 0; |
333b20bb GM |
5302 | for (i = 0; i < w->desired_matrix->nrows; ++i) |
5303 | { | |
5304 | struct glyph_row *row = &w->desired_matrix->rows[i]; | |
5305 | struct glyph *last; | |
5306 | int row_width; | |
5307 | ||
5308 | /* Stop at the first empty row at the end. */ | |
138c0ae8 | 5309 | if (!row->enabled_p || !MATRIX_ROW_DISPLAYS_TEXT_P (row)) |
333b20bb GM |
5310 | break; |
5311 | ||
d7bf0342 GM |
5312 | /* Let the row go over the full width of the frame. */ |
5313 | row->full_width_p = 1; | |
333b20bb | 5314 | |
5b253e9c | 5315 | row_width = row->pixel_width; |
333b20bb GM |
5316 | if (row->used[TEXT_AREA]) |
5317 | { | |
a971c0a7 EZ |
5318 | /* There's a glyph at the end of rows that is used to place |
5319 | the cursor there. Don't include the width of this glyph. */ | |
5320 | if (!row->reversed_p) | |
5321 | { | |
5322 | last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1]; | |
5323 | if (INTEGERP (last->object)) | |
5324 | row_width -= last->pixel_width; | |
5325 | } | |
5326 | else | |
5327 | { | |
5328 | /* There could be a stretch glyph at the beginning of R2L | |
5329 | rows that is produced by extend_face_to_end_of_line. | |
5330 | Don't count that glyph. */ | |
5331 | struct glyph *g = row->glyphs[TEXT_AREA]; | |
5332 | ||
5333 | if (g->type == STRETCH_GLYPH && INTEGERP (g->object)) | |
5334 | { | |
5335 | row_width -= g->pixel_width; | |
5336 | seen_reversed_p = 1; | |
5337 | } | |
5338 | } | |
333b20bb | 5339 | } |
177c0ea7 | 5340 | |
333b20bb GM |
5341 | height += row->height; |
5342 | width = max (width, row_width); | |
5343 | } | |
5344 | ||
a971c0a7 EZ |
5345 | /* If we've seen partial-length R2L rows, we need to re-adjust the |
5346 | tool-tip frame width and redisplay it again, to avoid over-wide | |
5347 | tips due to the stretch glyph that extends R2L lines to full | |
5348 | width of the frame. */ | |
5349 | if (seen_reversed_p) | |
5350 | { | |
5351 | /* w->total_cols and FRAME_TOTAL_COLS want the width in columns, | |
5352 | not in pixels. */ | |
5353 | width /= WINDOW_FRAME_COLUMN_WIDTH (w); | |
5f24fa51 | 5354 | w->total_cols = width; |
a971c0a7 | 5355 | FRAME_TOTAL_COLS (f) = width; |
bd0443bb | 5356 | adjust_frame_glyphs (f); |
a971c0a7 EZ |
5357 | clear_glyph_matrix (w->desired_matrix); |
5358 | clear_glyph_matrix (w->current_matrix); | |
5359 | try_window (FRAME_ROOT_WINDOW (f), pos, 0); | |
5360 | width = height = 0; | |
5361 | /* Recompute width and height of the tooltip. */ | |
5362 | for (i = 0; i < w->desired_matrix->nrows; ++i) | |
5363 | { | |
5364 | struct glyph_row *row = &w->desired_matrix->rows[i]; | |
5365 | struct glyph *last; | |
5366 | int row_width; | |
5367 | ||
138c0ae8 | 5368 | if (!row->enabled_p || !MATRIX_ROW_DISPLAYS_TEXT_P (row)) |
a971c0a7 EZ |
5369 | break; |
5370 | row->full_width_p = 1; | |
5371 | row_width = row->pixel_width; | |
5372 | if (row->used[TEXT_AREA] && !row->reversed_p) | |
5373 | { | |
5374 | last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1]; | |
5375 | if (INTEGERP (last->object)) | |
5376 | row_width -= last->pixel_width; | |
5377 | } | |
5378 | ||
5379 | height += row->height; | |
5380 | width = max (width, row_width); | |
5381 | } | |
5382 | } | |
5383 | ||
333b20bb GM |
5384 | /* Add the frame's internal border to the width and height the X |
5385 | window should have. */ | |
5386 | height += 2 * FRAME_INTERNAL_BORDER_WIDTH (f); | |
5387 | width += 2 * FRAME_INTERNAL_BORDER_WIDTH (f); | |
5388 | ||
5389 | /* Move the tooltip window where the mouse pointer is. Resize and | |
5390 | show it. */ | |
ab452f99 | 5391 | compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y); |
0634ce98 | 5392 | |
4d7e6e51 | 5393 | block_input (); |
333b20bb | 5394 | XMoveResizeWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), |
ab452f99 | 5395 | root_x, root_y, width, height); |
333b20bb | 5396 | XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); |
4d7e6e51 | 5397 | unblock_input (); |
177c0ea7 | 5398 | |
333b20bb GM |
5399 | /* Draw into the window. */ |
5400 | w->must_be_updated_p = 1; | |
5401 | update_single_window (w, 1); | |
5402 | ||
5403 | /* Restore original current buffer. */ | |
5404 | set_buffer_internal_1 (old_buffer); | |
5405 | windows_or_buffers_changed = old_windows_or_buffers_changed; | |
5406 | ||
06d62053 | 5407 | start_timer: |
333b20bb GM |
5408 | /* Let the tip disappear after timeout seconds. */ |
5409 | tip_timer = call3 (intern ("run-at-time"), timeout, Qnil, | |
5410 | intern ("x-hide-tip")); | |
a744a2ec DL |
5411 | |
5412 | UNGCPRO; | |
333b20bb GM |
5413 | return unbind_to (count, Qnil); |
5414 | } | |
5415 | ||
5416 | ||
a7ca3326 | 5417 | DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0, |
7ee72033 MB |
5418 | doc: /* Hide the current tooltip window, if there is any. |
5419 | Value is t if tooltip was open, nil otherwise. */) | |
5842a27b | 5420 | (void) |
333b20bb | 5421 | { |
d311d28c | 5422 | ptrdiff_t count; |
c0006262 GM |
5423 | Lisp_Object deleted, frame, timer; |
5424 | struct gcpro gcpro1, gcpro2; | |
44b5a125 GM |
5425 | |
5426 | /* Return quickly if nothing to do. */ | |
c0006262 | 5427 | if (NILP (tip_timer) && NILP (tip_frame)) |
44b5a125 | 5428 | return Qnil; |
177c0ea7 | 5429 | |
c0006262 GM |
5430 | frame = tip_frame; |
5431 | timer = tip_timer; | |
5432 | GCPRO2 (frame, timer); | |
5433 | tip_frame = tip_timer = deleted = Qnil; | |
177c0ea7 | 5434 | |
331379bf | 5435 | count = SPECPDL_INDEX (); |
333b20bb | 5436 | specbind (Qinhibit_redisplay, Qt); |
44b5a125 | 5437 | specbind (Qinhibit_quit, Qt); |
177c0ea7 | 5438 | |
c0006262 | 5439 | if (!NILP (timer)) |
ae782866 | 5440 | call1 (Qcancel_timer, timer); |
333b20bb | 5441 | |
aa1859f5 | 5442 | #ifdef USE_GTK |
1fe72bf8 PE |
5443 | { |
5444 | /* When using system tooltip, tip_frame is the Emacs frame on which | |
5445 | the tip is shown. */ | |
5446 | struct frame *f = XFRAME (frame); | |
5447 | if (FRAME_LIVE_P (f) && xg_hide_tooltip (f)) | |
5448 | frame = Qnil; | |
5449 | } | |
aa1859f5 J |
5450 | #endif |
5451 | ||
c0006262 | 5452 | if (FRAMEP (frame)) |
333b20bb | 5453 | { |
56f2de10 | 5454 | delete_frame (frame, Qnil); |
44b5a125 | 5455 | deleted = Qt; |
f6c44811 GM |
5456 | |
5457 | #ifdef USE_LUCID | |
5458 | /* Bloodcurdling hack alert: The Lucid menu bar widget's | |
5459 | redisplay procedure is not called when a tip frame over menu | |
5460 | items is unmapped. Redisplay the menu manually... */ | |
5461 | { | |
aa1859f5 | 5462 | Widget w; |
1fe72bf8 | 5463 | struct frame *f = SELECTED_FRAME (); |
aa1859f5 | 5464 | w = f->output_data.x->menubar_widget; |
9180dc8c | 5465 | |
aad3612f | 5466 | if (!DoesSaveUnders (FRAME_DISPLAY_INFO (f)->screen) |
dbc64aa7 | 5467 | && w != NULL) |
f6c44811 | 5468 | { |
4d7e6e51 | 5469 | block_input (); |
f6c44811 | 5470 | xlwmenu_redisplay (w); |
4d7e6e51 | 5471 | unblock_input (); |
f6c44811 GM |
5472 | } |
5473 | } | |
5474 | #endif /* USE_LUCID */ | |
333b20bb GM |
5475 | } |
5476 | ||
c0006262 | 5477 | UNGCPRO; |
44b5a125 | 5478 | return unbind_to (count, deleted); |
333b20bb GM |
5479 | } |
5480 | ||
5481 | ||
5482 | \f | |
5483 | /*********************************************************************** | |
5484 | File selection dialog | |
5485 | ***********************************************************************/ | |
5486 | ||
90f2e16b JD |
5487 | DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog, |
5488 | Sx_uses_old_gtk_dialog, | |
5489 | 0, 0, 0, | |
5490 | doc: /* Return t if the old Gtk+ file selection dialog is used. */) | |
5842a27b | 5491 | (void) |
90f2e16b JD |
5492 | { |
5493 | #ifdef USE_GTK | |
90f2e16b JD |
5494 | if (use_dialog_box |
5495 | && use_file_dialog | |
7452b7bd | 5496 | && window_system_available (SELECTED_FRAME ()) |
90f2e16b JD |
5497 | && xg_uses_old_file_dialog ()) |
5498 | return Qt; | |
5499 | #endif | |
5500 | return Qnil; | |
5501 | } | |
5502 | ||
333b20bb | 5503 | |
90f2e16b | 5504 | #ifdef USE_MOTIF |
333b20bb GM |
5505 | /* Callback for "OK" and "Cancel" on file selection dialog. */ |
5506 | ||
5507 | static void | |
dee186b6 | 5508 | file_dialog_cb (Widget widget, XtPointer client_data, XtPointer call_data) |
333b20bb | 5509 | { |
7d652d97 PE |
5510 | int *result = client_data; |
5511 | XmAnyCallbackStruct *cb = call_data; | |
333b20bb GM |
5512 | *result = cb->reason; |
5513 | } | |
5514 | ||
5515 | ||
a779d213 GM |
5516 | /* Callback for unmapping a file selection dialog. This is used to |
5517 | capture the case where a dialog is closed via a window manager's | |
5518 | closer button, for example. Using a XmNdestroyCallback didn't work | |
5519 | in this case. */ | |
5520 | ||
5521 | static void | |
dee186b6 | 5522 | file_dialog_unmap_cb (Widget widget, XtPointer client_data, XtPointer call_data) |
a779d213 | 5523 | { |
7d652d97 | 5524 | int *result = client_data; |
a779d213 GM |
5525 | *result = XmCR_CANCEL; |
5526 | } | |
5527 | ||
27e498e6 PE |
5528 | static void |
5529 | clean_up_file_dialog (void *arg) | |
24ca7c5a | 5530 | { |
27e498e6 | 5531 | Widget dialog = arg; |
24ca7c5a JD |
5532 | |
5533 | /* Clean up. */ | |
4d7e6e51 | 5534 | block_input (); |
24ca7c5a JD |
5535 | XtUnmanageChild (dialog); |
5536 | XtDestroyWidget (dialog); | |
5537 | x_menu_set_in_use (0); | |
4d7e6e51 | 5538 | unblock_input (); |
24ca7c5a JD |
5539 | } |
5540 | ||
a779d213 | 5541 | |
f9d64bb3 | 5542 | DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0, |
7ee72033 | 5543 | doc: /* Read file name, prompting with PROMPT in directory DIR. |
f9d64bb3 JD |
5544 | Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file |
5545 | selection box, if specified. If MUSTMATCH is non-nil, the returned file | |
7c051dd8 GM |
5546 | or directory must exist. |
5547 | ||
d7e642cc | 5548 | This function is only defined on NS, MS Windows, and X Windows with the |
7c051dd8 GM |
5549 | Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored. |
5550 | Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) | |
a10c8269 DA |
5551 | (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, |
5552 | Lisp_Object mustmatch, Lisp_Object only_dir_p) | |
333b20bb GM |
5553 | { |
5554 | int result; | |
0fe92f72 | 5555 | struct frame *f = SELECTED_FRAME (); |
333b20bb | 5556 | Lisp_Object file = Qnil; |
a8f4bdc6 | 5557 | Lisp_Object decoded_file; |
f9d64bb3 | 5558 | Widget dialog, text, help; |
333b20bb GM |
5559 | Arg al[10]; |
5560 | int ac = 0; | |
333b20bb | 5561 | XmString dir_xmstring, pattern_xmstring; |
d311d28c | 5562 | ptrdiff_t count = SPECPDL_INDEX (); |
f9d64bb3 | 5563 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; |
333b20bb | 5564 | |
7452b7bd | 5565 | check_window_system (f); |
6eeee4d6 | 5566 | |
f9d64bb3 | 5567 | GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file); |
24ca7c5a | 5568 | |
5ae53dcf | 5569 | if (popup_activated ()) |
24ca7c5a JD |
5570 | error ("Trying to use a menu from within a menu-entry"); |
5571 | ||
b7826503 PJ |
5572 | CHECK_STRING (prompt); |
5573 | CHECK_STRING (dir); | |
333b20bb GM |
5574 | |
5575 | /* Prevent redisplay. */ | |
5576 | specbind (Qinhibit_redisplay, Qt); | |
5577 | ||
4d7e6e51 | 5578 | block_input (); |
333b20bb GM |
5579 | |
5580 | /* Create the dialog with PROMPT as title, using DIR as initial | |
5581 | directory and using "*" as pattern. */ | |
5582 | dir = Fexpand_file_name (dir, Qnil); | |
c09bfb2f | 5583 | dir_xmstring = XmStringCreateLocalized (SSDATA (dir)); |
333b20bb | 5584 | pattern_xmstring = XmStringCreateLocalized ("*"); |
177c0ea7 | 5585 | |
d5db4077 | 5586 | XtSetArg (al[ac], XmNtitle, SDATA (prompt)); ++ac; |
333b20bb GM |
5587 | XtSetArg (al[ac], XmNdirectory, dir_xmstring); ++ac; |
5588 | XtSetArg (al[ac], XmNpattern, pattern_xmstring); ++ac; | |
5589 | XtSetArg (al[ac], XmNresizePolicy, XmRESIZE_GROW); ++ac; | |
5590 | XtSetArg (al[ac], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); ++ac; | |
5591 | dialog = XmCreateFileSelectionDialog (f->output_data.x->widget, | |
5592 | "fsb", al, ac); | |
5593 | XmStringFree (dir_xmstring); | |
5594 | XmStringFree (pattern_xmstring); | |
5595 | ||
5596 | /* Add callbacks for OK and Cancel. */ | |
5597 | XtAddCallback (dialog, XmNokCallback, file_dialog_cb, | |
5598 | (XtPointer) &result); | |
5599 | XtAddCallback (dialog, XmNcancelCallback, file_dialog_cb, | |
5600 | (XtPointer) &result); | |
a779d213 GM |
5601 | XtAddCallback (dialog, XmNunmapCallback, file_dialog_unmap_cb, |
5602 | (XtPointer) &result); | |
333b20bb | 5603 | |
f9d64bb3 | 5604 | /* Remove the help button since we can't display help. */ |
333b20bb | 5605 | help = XmFileSelectionBoxGetChild (dialog, XmDIALOG_HELP_BUTTON); |
f9d64bb3 | 5606 | XtUnmanageChild (help); |
333b20bb | 5607 | |
177c0ea7 | 5608 | /* Mark OK button as default. */ |
333b20bb GM |
5609 | XtVaSetValues (XmFileSelectionBoxGetChild (dialog, XmDIALOG_OK_BUTTON), |
5610 | XmNshowAsDefault, True, NULL); | |
5611 | ||
5612 | /* If MUSTMATCH is non-nil, disable the file entry field of the | |
5613 | dialog, so that the user must select a file from the files list | |
5614 | box. We can't remove it because we wouldn't have a way to get at | |
5615 | the result file name, then. */ | |
5616 | text = XmFileSelectionBoxGetChild (dialog, XmDIALOG_TEXT); | |
5617 | if (!NILP (mustmatch)) | |
5618 | { | |
5619 | Widget label; | |
5620 | label = XmFileSelectionBoxGetChild (dialog, XmDIALOG_SELECTION_LABEL); | |
5621 | XtSetSensitive (text, False); | |
5622 | XtSetSensitive (label, False); | |
5623 | } | |
5624 | ||
5625 | /* Manage the dialog, so that list boxes get filled. */ | |
5626 | XtManageChild (dialog); | |
5627 | ||
333b20bb GM |
5628 | if (STRINGP (default_filename)) |
5629 | { | |
5630 | XmString default_xmstring; | |
f9d64bb3 JD |
5631 | Widget wtext = XmFileSelectionBoxGetChild (dialog, XmDIALOG_TEXT); |
5632 | Widget list = XmFileSelectionBoxGetChild (dialog, XmDIALOG_LIST); | |
333b20bb | 5633 | |
f9d64bb3 JD |
5634 | XmTextPosition last_pos = XmTextFieldGetLastPosition (wtext); |
5635 | XmTextFieldReplace (wtext, 0, last_pos, | |
c09bfb2f | 5636 | (SSDATA (Ffile_name_nondirectory (default_filename)))); |
333b20bb | 5637 | |
f9d64bb3 JD |
5638 | /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME |
5639 | must include the path for this to work. */ | |
5640 | ||
c09bfb2f | 5641 | default_xmstring = XmStringCreateLocalized (SSDATA (default_filename)); |
333b20bb | 5642 | |
f9d64bb3 JD |
5643 | if (XmListItemExists (list, default_xmstring)) |
5644 | { | |
5645 | int item_pos = XmListItemPos (list, default_xmstring); | |
5646 | /* Select the item and scroll it into view. */ | |
5647 | XmListSelectPos (list, item_pos, True); | |
5648 | XmListSetPos (list, item_pos); | |
5649 | } | |
5650 | ||
5651 | XmStringFree (default_xmstring); | |
333b20bb GM |
5652 | } |
5653 | ||
27e498e6 | 5654 | record_unwind_protect_ptr (clean_up_file_dialog, dialog); |
24ca7c5a | 5655 | |
bf338245 | 5656 | /* Process events until the user presses Cancel or OK. */ |
5ae53dcf | 5657 | x_menu_set_in_use (1); |
03100098 | 5658 | result = 0; |
a779d213 | 5659 | while (result == 0) |
563b384d | 5660 | { |
bf338245 | 5661 | XEvent event; |
24ca7c5a | 5662 | x_menu_wait_for_event (0); |
bf338245 | 5663 | XtAppNextEvent (Xt_app_con, &event); |
9f6fcdc5 JD |
5664 | if (event.type == KeyPress |
5665 | && FRAME_X_DISPLAY (f) == event.xkey.display) | |
5666 | { | |
5667 | KeySym keysym = XLookupKeysym (&event.xkey, 0); | |
5668 | ||
5669 | /* Pop down on C-g. */ | |
5670 | if (keysym == XK_g && (event.xkey.state & ControlMask) != 0) | |
5671 | XtUnmanageChild (dialog); | |
5672 | } | |
5b3f8550 | 5673 | |
24ca7c5a | 5674 | (void) x_dispatch_event (&event, FRAME_X_DISPLAY (f)); |
563b384d | 5675 | } |
03100098 | 5676 | |
333b20bb GM |
5677 | /* Get the result. */ |
5678 | if (result == XmCR_OK) | |
5679 | { | |
91a3e27b | 5680 | XmString text_string; |
333b20bb | 5681 | String data; |
177c0ea7 | 5682 | |
91a3e27b PE |
5683 | XtVaGetValues (dialog, XmNtextString, &text_string, NULL); |
5684 | XmStringGetLtoR (text_string, XmFONTLIST_DEFAULT_TAG, &data); | |
5685 | XmStringFree (text_string); | |
333b20bb GM |
5686 | file = build_string (data); |
5687 | XtFree (data); | |
5688 | } | |
5689 | else | |
5690 | file = Qnil; | |
5691 | ||
4d7e6e51 | 5692 | unblock_input (); |
333b20bb GM |
5693 | UNGCPRO; |
5694 | ||
5695 | /* Make "Cancel" equivalent to C-g. */ | |
5696 | if (NILP (file)) | |
5697 | Fsignal (Qquit, Qnil); | |
177c0ea7 | 5698 | |
a8f4bdc6 JD |
5699 | decoded_file = DECODE_FILE (file); |
5700 | ||
5701 | return unbind_to (count, decoded_file); | |
333b20bb GM |
5702 | } |
5703 | ||
5704 | #endif /* USE_MOTIF */ | |
5705 | ||
488dd4c4 JD |
5706 | #ifdef USE_GTK |
5707 | ||
27e498e6 PE |
5708 | static void |
5709 | clean_up_dialog (void) | |
24ca7c5a JD |
5710 | { |
5711 | x_menu_set_in_use (0); | |
24ca7c5a JD |
5712 | } |
5713 | ||
f9d64bb3 JD |
5714 | DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0, |
5715 | doc: /* Read file name, prompting with PROMPT in directory DIR. | |
5716 | Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file | |
5717 | selection box, if specified. If MUSTMATCH is non-nil, the returned file | |
7c051dd8 GM |
5718 | or directory must exist. |
5719 | ||
d7e642cc | 5720 | This function is only defined on NS, MS Windows, and X Windows with the |
7c051dd8 GM |
5721 | Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored. |
5722 | Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */) | |
5842a27b | 5723 | (Lisp_Object prompt, Lisp_Object dir, Lisp_Object default_filename, Lisp_Object mustmatch, Lisp_Object only_dir_p) |
488dd4c4 | 5724 | { |
a10c8269 | 5725 | struct frame *f = SELECTED_FRAME (); |
488dd4c4 JD |
5726 | char *fn; |
5727 | Lisp_Object file = Qnil; | |
a8f4bdc6 | 5728 | Lisp_Object decoded_file; |
d311d28c | 5729 | ptrdiff_t count = SPECPDL_INDEX (); |
f9d64bb3 | 5730 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6; |
488dd4c4 | 5731 | char *cdef_file; |
177c0ea7 | 5732 | |
7452b7bd | 5733 | check_window_system (f); |
6eeee4d6 | 5734 | |
f9d64bb3 | 5735 | GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file); |
24ca7c5a | 5736 | |
5ae53dcf | 5737 | if (popup_activated ()) |
24ca7c5a JD |
5738 | error ("Trying to use a menu from within a menu-entry"); |
5739 | ||
488dd4c4 JD |
5740 | CHECK_STRING (prompt); |
5741 | CHECK_STRING (dir); | |
5742 | ||
5743 | /* Prevent redisplay. */ | |
5744 | specbind (Qinhibit_redisplay, Qt); | |
27e498e6 | 5745 | record_unwind_protect_void (clean_up_dialog); |
488dd4c4 | 5746 | |
4d7e6e51 | 5747 | block_input (); |
488dd4c4 JD |
5748 | |
5749 | if (STRINGP (default_filename)) | |
c0951e53 | 5750 | cdef_file = SSDATA (default_filename); |
488dd4c4 | 5751 | else |
c0951e53 | 5752 | cdef_file = SSDATA (dir); |
488dd4c4 | 5753 | |
c0951e53 | 5754 | fn = xg_get_file_name (f, SSDATA (prompt), cdef_file, |
f9d64bb3 JD |
5755 | ! NILP (mustmatch), |
5756 | ! NILP (only_dir_p)); | |
177c0ea7 | 5757 | |
488dd4c4 JD |
5758 | if (fn) |
5759 | { | |
5760 | file = build_string (fn); | |
5761 | xfree (fn); | |
5762 | } | |
5763 | ||
4d7e6e51 | 5764 | unblock_input (); |
488dd4c4 JD |
5765 | UNGCPRO; |
5766 | ||
5767 | /* Make "Cancel" equivalent to C-g. */ | |
5768 | if (NILP (file)) | |
5769 | Fsignal (Qquit, Qnil); | |
177c0ea7 | 5770 | |
a8f4bdc6 JD |
5771 | decoded_file = DECODE_FILE (file); |
5772 | ||
5773 | return unbind_to (count, decoded_file); | |
488dd4c4 JD |
5774 | } |
5775 | ||
9bf80974 CY |
5776 | |
5777 | #ifdef HAVE_FREETYPE | |
5778 | ||
f82605c6 | 5779 | DEFUN ("x-select-font", Fx_select_font, Sx_select_font, 0, 2, 0, |
f2045622 CY |
5780 | doc: /* Read a font using a GTK dialog. |
5781 | Return either a font spec (for GTK versions >= 3.2) or a string | |
5782 | containing a GTK-style font name. | |
f82605c6 | 5783 | |
f2045622 CY |
5784 | FRAME is the frame on which to pop up the font chooser. If omitted or |
5785 | nil, it defaults to the selected frame. */) | |
5842a27b | 5786 | (Lisp_Object frame, Lisp_Object ignored) |
9bf80974 | 5787 | { |
a10c8269 | 5788 | struct frame *f = decode_window_system_frame (frame); |
637fa988 | 5789 | Lisp_Object font; |
e0ab5fcf JD |
5790 | Lisp_Object font_param; |
5791 | char *default_name = NULL; | |
637fa988 | 5792 | struct gcpro gcpro1, gcpro2; |
d311d28c | 5793 | ptrdiff_t count = SPECPDL_INDEX (); |
9bf80974 | 5794 | |
9bf80974 CY |
5795 | if (popup_activated ()) |
5796 | error ("Trying to use a menu from within a menu-entry"); | |
5797 | ||
5798 | /* Prevent redisplay. */ | |
5799 | specbind (Qinhibit_redisplay, Qt); | |
27e498e6 | 5800 | record_unwind_protect_void (clean_up_dialog); |
9bf80974 | 5801 | |
4d7e6e51 | 5802 | block_input (); |
9bf80974 | 5803 | |
5e617bc2 | 5804 | GCPRO2 (font_param, font); |
e0ab5fcf | 5805 | |
637fa988 | 5806 | XSETFONT (font, FRAME_FONT (f)); |
581e51e8 | 5807 | font_param = Ffont_get (font, intern (":name")); |
637fa988 | 5808 | if (STRINGP (font_param)) |
c0951e53 | 5809 | default_name = xstrdup (SSDATA (font_param)); |
f5f6c0e0 | 5810 | else |
53c7540d | 5811 | { |
637fa988 JD |
5812 | font_param = Fframe_parameter (frame, Qfont_param); |
5813 | if (STRINGP (font_param)) | |
c0951e53 | 5814 | default_name = xstrdup (SSDATA (font_param)); |
53c7540d | 5815 | } |
e0ab5fcf | 5816 | |
f2045622 | 5817 | font = xg_get_font (f, default_name); |
581e51e8 | 5818 | xfree (default_name); |
9bf80974 | 5819 | |
4d7e6e51 | 5820 | unblock_input (); |
9bf80974 CY |
5821 | |
5822 | if (NILP (font)) | |
5823 | Fsignal (Qquit, Qnil); | |
5824 | ||
5825 | return unbind_to (count, font); | |
5826 | } | |
5827 | #endif /* HAVE_FREETYPE */ | |
5828 | ||
488dd4c4 | 5829 | #endif /* USE_GTK */ |
333b20bb GM |
5830 | |
5831 | \f | |
82bab41c GM |
5832 | /*********************************************************************** |
5833 | Keyboard | |
5834 | ***********************************************************************/ | |
5835 | ||
afeee3e5 | 5836 | #ifdef HAVE_XKB |
82bab41c GM |
5837 | #include <X11/XKBlib.h> |
5838 | #include <X11/keysym.h> | |
5839 | #endif | |
5840 | ||
5841 | DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p, | |
5842 | Sx_backspace_delete_keys_p, 0, 1, 0, | |
7ee72033 | 5843 | doc: /* Check if both Backspace and Delete keys are on the keyboard of FRAME. |
c061c855 GM |
5844 | FRAME nil means use the selected frame. |
5845 | Value is t if we know that both keys are present, and are mapped to the | |
20d1c5c5 DN |
5846 | usual X keysyms. Value is `lambda' if we cannot determine if both keys are |
5847 | present and mapped to the usual X keysyms. */) | |
5842a27b | 5848 | (Lisp_Object frame) |
82bab41c | 5849 | { |
afeee3e5 PE |
5850 | #ifndef HAVE_XKB |
5851 | return Qlambda; | |
5852 | #else | |
82bab41c | 5853 | XkbDescPtr kb; |
7452b7bd | 5854 | struct frame *f = decode_window_system_frame (frame); |
82bab41c GM |
5855 | Display *dpy = FRAME_X_DISPLAY (f); |
5856 | Lisp_Object have_keys; | |
58d2d479 | 5857 | int major, minor, op, event, error_code; |
82bab41c | 5858 | |
4d7e6e51 | 5859 | block_input (); |
46f6a258 GM |
5860 | |
5861 | /* Check library version in case we're dynamically linked. */ | |
5862 | major = XkbMajorVersion; | |
5863 | minor = XkbMinorVersion; | |
5864 | if (!XkbLibraryVersion (&major, &minor)) | |
c1efd260 | 5865 | { |
4d7e6e51 | 5866 | unblock_input (); |
20d1c5c5 | 5867 | return Qlambda; |
c1efd260 | 5868 | } |
46f6a258 GM |
5869 | |
5870 | /* Check that the server supports XKB. */ | |
5871 | major = XkbMajorVersion; | |
5872 | minor = XkbMinorVersion; | |
58d2d479 | 5873 | if (!XkbQueryExtension (dpy, &op, &event, &error_code, &major, &minor)) |
c1efd260 | 5874 | { |
4d7e6e51 | 5875 | unblock_input (); |
20d1c5c5 | 5876 | return Qlambda; |
c1efd260 | 5877 | } |
177c0ea7 | 5878 | |
3a441526 JD |
5879 | /* In this code we check that the keyboard has physical keys with names |
5880 | that start with BKSP (Backspace) and DELE (Delete), and that they | |
5881 | generate keysym XK_BackSpace and XK_Delete respectively. | |
5882 | This function is used to test if normal-erase-is-backspace should be | |
5883 | turned on. | |
5884 | An alternative approach would be to just check if XK_BackSpace and | |
5885 | XK_Delete are mapped to any key. But if any of those are mapped to | |
5886 | some non-intuitive key combination (Meta-Shift-Ctrl-whatever) and the | |
5887 | user doesn't know about it, it is better to return false here. | |
5888 | It is more obvious to the user what to do if she/he has two keys | |
5889 | clearly marked with names/symbols and one key does something not | |
5890 | expected (i.e. she/he then tries the other). | |
5891 | The cases where Backspace/Delete is mapped to some other key combination | |
5892 | are rare, and in those cases, normal-erase-is-backspace can be turned on | |
5893 | manually. */ | |
5894 | ||
46f6a258 | 5895 | have_keys = Qnil; |
c1efd260 | 5896 | kb = XkbGetMap (dpy, XkbAllMapComponentsMask, XkbUseCoreKbd); |
82bab41c GM |
5897 | if (kb) |
5898 | { | |
5899 | int delete_keycode = 0, backspace_keycode = 0, i; | |
c1efd260 GM |
5900 | |
5901 | if (XkbGetNames (dpy, XkbAllNamesMask, kb) == Success) | |
82bab41c | 5902 | { |
c1efd260 GM |
5903 | for (i = kb->min_key_code; |
5904 | (i < kb->max_key_code | |
5905 | && (delete_keycode == 0 || backspace_keycode == 0)); | |
5906 | ++i) | |
5907 | { | |
d63931a2 GM |
5908 | /* The XKB symbolic key names can be seen most easily in |
5909 | the PS file generated by `xkbprint -label name | |
5910 | $DISPLAY'. */ | |
72af86bd | 5911 | if (memcmp ("DELE", kb->names->keys[i].name, 4) == 0) |
c1efd260 | 5912 | delete_keycode = i; |
72af86bd | 5913 | else if (memcmp ("BKSP", kb->names->keys[i].name, 4) == 0) |
c1efd260 GM |
5914 | backspace_keycode = i; |
5915 | } | |
5916 | ||
5917 | XkbFreeNames (kb, 0, True); | |
82bab41c GM |
5918 | } |
5919 | ||
c1efd260 | 5920 | XkbFreeClientMap (kb, 0, True); |
177c0ea7 | 5921 | |
82bab41c GM |
5922 | if (delete_keycode |
5923 | && backspace_keycode | |
5924 | && XKeysymToKeycode (dpy, XK_Delete) == delete_keycode | |
5925 | && XKeysymToKeycode (dpy, XK_BackSpace) == backspace_keycode) | |
5926 | have_keys = Qt; | |
5927 | } | |
4d7e6e51 | 5928 | unblock_input (); |
82bab41c | 5929 | return have_keys; |
afeee3e5 | 5930 | #endif |
82bab41c GM |
5931 | } |
5932 | ||
5933 | ||
5934 | \f | |
333b20bb GM |
5935 | /*********************************************************************** |
5936 | Initialization | |
5937 | ***********************************************************************/ | |
5938 | ||
4dacadcc | 5939 | /* Keep this list in the same order as frame_parms in frame.c. |
7c0d3ed8 KS |
5940 | Use 0 for unsupported frame parameters. */ |
5941 | ||
5942 | frame_parm_handler x_frame_parm_handlers[] = | |
5943 | { | |
5944 | x_set_autoraise, | |
5945 | x_set_autolower, | |
5946 | x_set_background_color, | |
5947 | x_set_border_color, | |
5948 | x_set_border_width, | |
5949 | x_set_cursor_color, | |
5950 | x_set_cursor_type, | |
5951 | x_set_font, | |
5952 | x_set_foreground_color, | |
5953 | x_set_icon_name, | |
5954 | x_set_icon_type, | |
5955 | x_set_internal_border_width, | |
5956 | x_set_menu_bar_lines, | |
5957 | x_set_mouse_color, | |
5958 | x_explicitly_set_name, | |
5959 | x_set_scroll_bar_width, | |
5960 | x_set_title, | |
5961 | x_set_unsplittable, | |
5962 | x_set_vertical_scroll_bars, | |
5963 | x_set_visibility, | |
5964 | x_set_tool_bar_lines, | |
5965 | x_set_scroll_bar_foreground, | |
5966 | x_set_scroll_bar_background, | |
5967 | x_set_screen_gamma, | |
5968 | x_set_line_spacing, | |
5969 | x_set_fringe_width, | |
5970 | x_set_fringe_width, | |
5971 | x_set_wait_for_wm, | |
5972 | x_set_fullscreen, | |
271a71c7 | 5973 | x_set_font_backend, |
cad9ef74 JD |
5974 | x_set_alpha, |
5975 | x_set_sticky, | |
bfeabdc3 | 5976 | x_set_tool_bar_position, |
7c0d3ed8 KS |
5977 | }; |
5978 | ||
333b20bb | 5979 | void |
971de7fb | 5980 | syms_of_xfns (void) |
333b20bb | 5981 | { |
333b20bb GM |
5982 | /* The section below is built by the lisp expression at the top of the file, |
5983 | just above where these variables are declared. */ | |
5984 | /*&&& init symbols here &&&*/ | |
cd3520a4 JB |
5985 | DEFSYM (Qsuppress_icon, "suppress-icon"); |
5986 | DEFSYM (Qundefined_color, "undefined-color"); | |
5987 | DEFSYM (Qcompound_text, "compound-text"); | |
5988 | DEFSYM (Qcancel_timer, "cancel-timer"); | |
5989 | DEFSYM (Qfont_param, "font-parameter"); | |
f9942c9e JB |
5990 | /* This is the end of symbol initialization. */ |
5991 | ||
01f1ba30 | 5992 | Fput (Qundefined_color, Qerror_conditions, |
3438fe21 | 5993 | listn (CONSTYPE_PURE, 2, Qundefined_color, Qerror)); |
01f1ba30 | 5994 | Fput (Qundefined_color, Qerror_message, |
2a0213a6 | 5995 | build_pure_c_string ("Undefined color")); |
01f1ba30 | 5996 | |
29208e82 | 5997 | DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape, |
7ee72033 | 5998 | doc: /* The shape of the pointer when over text. |
c061c855 GM |
5999 | Changing the value does not affect existing frames |
6000 | unless you set the mouse color. */); | |
01f1ba30 JB |
6001 | Vx_pointer_shape = Qnil; |
6002 | ||
ca0ecbf5 | 6003 | #if 0 /* This doesn't really do anything. */ |
29208e82 | 6004 | DEFVAR_LISP ("x-nontext-pointer-shape", Vx_nontext_pointer_shape, |
7ee72033 | 6005 | doc: /* The shape of the pointer when not over text. |
c061c855 GM |
6006 | This variable takes effect when you create a new frame |
6007 | or when you set the mouse color. */); | |
af01ef26 | 6008 | #endif |
01f1ba30 JB |
6009 | Vx_nontext_pointer_shape = Qnil; |
6010 | ||
29208e82 | 6011 | DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape, |
7ee72033 | 6012 | doc: /* The shape of the pointer when Emacs is busy. |
c061c855 GM |
6013 | This variable takes effect when you create a new frame |
6014 | or when you set the mouse color. */); | |
0af913d7 | 6015 | Vx_hourglass_pointer_shape = Qnil; |
333b20bb | 6016 | |
ca0ecbf5 | 6017 | #if 0 /* This doesn't really do anything. */ |
29208e82 | 6018 | DEFVAR_LISP ("x-mode-pointer-shape", Vx_mode_pointer_shape, |
7ee72033 | 6019 | doc: /* The shape of the pointer when over the mode line. |
c061c855 GM |
6020 | This variable takes effect when you create a new frame |
6021 | or when you set the mouse color. */); | |
af01ef26 | 6022 | #endif |
01f1ba30 JB |
6023 | Vx_mode_pointer_shape = Qnil; |
6024 | ||
d3b06468 | 6025 | DEFVAR_LISP ("x-sensitive-text-pointer-shape", |
29208e82 | 6026 | Vx_sensitive_text_pointer_shape, |
7ee72033 | 6027 | doc: /* The shape of the pointer when over mouse-sensitive text. |
c061c855 GM |
6028 | This variable takes effect when you create a new frame |
6029 | or when you set the mouse color. */); | |
ca0ecbf5 | 6030 | Vx_sensitive_text_pointer_shape = Qnil; |
95f80c78 | 6031 | |
8fb4ec9c | 6032 | DEFVAR_LISP ("x-window-horizontal-drag-cursor", |
29208e82 | 6033 | Vx_window_horizontal_drag_shape, |
7ee72033 | 6034 | doc: /* Pointer shape to use for indicating a window can be dragged horizontally. |
c061c855 GM |
6035 | This variable takes effect when you create a new frame |
6036 | or when you set the mouse color. */); | |
8fb4ec9c GM |
6037 | Vx_window_horizontal_drag_shape = Qnil; |
6038 | ||
29208e82 | 6039 | DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel, |
7ee72033 | 6040 | doc: /* A string indicating the foreground color of the cursor box. */); |
01f1ba30 JB |
6041 | Vx_cursor_fore_pixel = Qnil; |
6042 | ||
29208e82 | 6043 | DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size, |
f5f6c0e0 JB |
6044 | doc: /* Maximum size for tooltips. |
6045 | Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */); | |
d63931a2 | 6046 | Vx_max_tooltip_size = Fcons (make_number (80), make_number (40)); |
177c0ea7 | 6047 | |
29208e82 | 6048 | DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager, |
7ee72033 | 6049 | doc: /* Non-nil if no X window manager is in use. |
c061c855 GM |
6050 | Emacs doesn't try to figure this out; this is always nil |
6051 | unless you set it to something else. */); | |
2d38195d RS |
6052 | /* We don't have any way to find this out, so set it to nil |
6053 | and maybe the user would like to set it to t. */ | |
6054 | Vx_no_window_manager = Qnil; | |
1d3dac41 | 6055 | |
942ea06d | 6056 | DEFVAR_LISP ("x-pixel-size-width-font-regexp", |
29208e82 | 6057 | Vx_pixel_size_width_font_regexp, |
7ee72033 | 6058 | doc: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. |
c061c855 GM |
6059 | |
6060 | Since Emacs gets width of a font matching with this regexp from | |
6061 | PIXEL_SIZE field of the name, font finding mechanism gets faster for | |
6062 | such a font. This is especially effective for such large fonts as | |
6063 | Chinese, Japanese, and Korean. */); | |
942ea06d KH |
6064 | Vx_pixel_size_width_font_regexp = Qnil; |
6065 | ||
255e4140 | 6066 | /* This is not ifdef:ed, so other builds than GTK can customize it. */ |
29208e82 | 6067 | DEFVAR_BOOL ("x-gtk-use-old-file-dialog", x_gtk_use_old_file_dialog, |
fb7ada5f | 6068 | doc: /* Non-nil means prompt with the old GTK file selection dialog. |
255e4140 JD |
6069 | If nil or if the file selection dialog is not available, the new GTK file |
6070 | chooser is used instead. To turn off all file dialogs set the | |
6071 | variable `use-file-dialog'. */); | |
fe2b14b7 | 6072 | x_gtk_use_old_file_dialog = 0; |
255e4140 | 6073 | |
29208e82 | 6074 | DEFVAR_BOOL ("x-gtk-show-hidden-files", x_gtk_show_hidden_files, |
fb7ada5f | 6075 | doc: /* If non-nil, the GTK file chooser will by default show hidden files. |
a8a35720 JD |
6076 | Note that this is just the default, there is a toggle button on the file |
6077 | chooser to show or not show hidden files on a case by case basis. */); | |
6078 | x_gtk_show_hidden_files = 0; | |
6079 | ||
29208e82 | 6080 | DEFVAR_BOOL ("x-gtk-file-dialog-help-text", x_gtk_file_dialog_help_text, |
fb7ada5f | 6081 | doc: /* If non-nil, the GTK file chooser will show additional help text. |
641c0105 JD |
6082 | If more space for files in the file chooser dialog is wanted, set this to nil |
6083 | to turn the additional text off. */); | |
159f8da7 | 6084 | x_gtk_file_dialog_help_text = 1; |
641c0105 | 6085 | |
29208e82 | 6086 | DEFVAR_BOOL ("x-gtk-whole-detached-tool-bar", x_gtk_whole_detached_tool_bar, |
fb7ada5f | 6087 | doc: /* If non-nil, a detached tool bar is shown in full. |
e0f467cb JD |
6088 | The default is to just show an arrow and pressing on that arrow shows |
6089 | the tool bar buttons. */); | |
6090 | x_gtk_whole_detached_tool_bar = 0; | |
6091 | ||
29208e82 | 6092 | DEFVAR_BOOL ("x-gtk-use-system-tooltips", x_gtk_use_system_tooltips, |
fb7ada5f | 6093 | doc: /* If non-nil with a Gtk+ built Emacs, the Gtk+ tooltip is used. |
aa1859f5 J |
6094 | Otherwise use Emacs own tooltip implementation. |
6095 | When using Gtk+ tooltips, the tooltip face is not used. */); | |
6096 | x_gtk_use_system_tooltips = 1; | |
6097 | ||
8d2db8be DA |
6098 | /* Tell Emacs about this window system. */ |
6099 | Fprovide (Qx, Qnil); | |
49be9d28 | 6100 | |
1d3dac41 | 6101 | #ifdef USE_X_TOOLKIT |
d67b4f80 | 6102 | Fprovide (intern_c_string ("x-toolkit"), Qnil); |
5b827abb | 6103 | #ifdef USE_MOTIF |
d67b4f80 | 6104 | Fprovide (intern_c_string ("motif"), Qnil); |
fc2cdd9a | 6105 | |
29208e82 | 6106 | DEFVAR_LISP ("motif-version-string", Vmotif_version_string, |
7ee72033 | 6107 | doc: /* Version info for LessTif/Motif. */); |
fc2cdd9a GM |
6108 | Vmotif_version_string = build_string (XmVERSION_STRING); |
6109 | #endif /* USE_MOTIF */ | |
6110 | #endif /* USE_X_TOOLKIT */ | |
01f1ba30 | 6111 | |
6b61353c | 6112 | #ifdef USE_GTK |
1ec2a572 JD |
6113 | /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it |
6114 | is not an X toolkit in that sense (USE_X_TOOLKIT is not defined). | |
6115 | But for a user it is a toolkit for X, and indeed, configure | |
6116 | accepts --with-x-toolkit=gtk. */ | |
d67b4f80 DN |
6117 | Fprovide (intern_c_string ("x-toolkit"), Qnil); |
6118 | Fprovide (intern_c_string ("gtk"), Qnil); | |
bfeabdc3 | 6119 | Fprovide (intern_c_string ("move-toolbar"), Qnil); |
6b61353c | 6120 | |
29208e82 | 6121 | DEFVAR_LISP ("gtk-version-string", Vgtk_version_string, |
6b61353c KH |
6122 | doc: /* Version info for GTK+. */); |
6123 | { | |
99027bdd PE |
6124 | char gtk_version[sizeof ".." + 3 * INT_STRLEN_BOUND (int)]; |
6125 | int len = sprintf (gtk_version, "%d.%d.%d", | |
6126 | GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION); | |
6127 | Vgtk_version_string = make_pure_string (gtk_version, len, len, 0); | |
6b61353c KH |
6128 | } |
6129 | #endif /* USE_GTK */ | |
6130 | ||
333b20bb GM |
6131 | /* X window properties. */ |
6132 | defsubr (&Sx_change_window_property); | |
6133 | defsubr (&Sx_delete_window_property); | |
6134 | defsubr (&Sx_window_property); | |
6135 | ||
2d764c78 | 6136 | defsubr (&Sxw_display_color_p); |
d0c9d219 | 6137 | defsubr (&Sx_display_grayscale_p); |
2d764c78 EZ |
6138 | defsubr (&Sxw_color_defined_p); |
6139 | defsubr (&Sxw_color_values); | |
9d317b2c | 6140 | defsubr (&Sx_server_max_request_size); |
41beb8fc RS |
6141 | defsubr (&Sx_server_vendor); |
6142 | defsubr (&Sx_server_version); | |
6143 | defsubr (&Sx_display_pixel_width); | |
6144 | defsubr (&Sx_display_pixel_height); | |
6145 | defsubr (&Sx_display_mm_width); | |
6146 | defsubr (&Sx_display_mm_height); | |
6147 | defsubr (&Sx_display_screens); | |
6148 | defsubr (&Sx_display_planes); | |
6149 | defsubr (&Sx_display_color_cells); | |
6150 | defsubr (&Sx_display_visual_class); | |
6151 | defsubr (&Sx_display_backing_store); | |
6152 | defsubr (&Sx_display_save_under); | |
4e3f9230 | 6153 | defsubr (&Sx_display_monitor_attributes_list); |
1c44e124 | 6154 | defsubr (&Sx_wm_set_size_hint); |
f676886a | 6155 | defsubr (&Sx_create_frame); |
01f1ba30 | 6156 | defsubr (&Sx_open_connection); |
08a90d6a RS |
6157 | defsubr (&Sx_close_connection); |
6158 | defsubr (&Sx_display_list); | |
01f1ba30 | 6159 | defsubr (&Sx_synchronize); |
82bab41c | 6160 | defsubr (&Sx_backspace_delete_keys_p); |
177c0ea7 | 6161 | |
333b20bb GM |
6162 | defsubr (&Sx_show_tip); |
6163 | defsubr (&Sx_hide_tip); | |
333b20bb | 6164 | tip_timer = Qnil; |
44b5a125 GM |
6165 | staticpro (&tip_timer); |
6166 | tip_frame = Qnil; | |
6167 | staticpro (&tip_frame); | |
333b20bb | 6168 | |
06d62053 GM |
6169 | last_show_tip_args = Qnil; |
6170 | staticpro (&last_show_tip_args); | |
6171 | ||
90f2e16b | 6172 | defsubr (&Sx_uses_old_gtk_dialog); |
29fabd8c | 6173 | #if defined (USE_MOTIF) || defined (USE_GTK) |
333b20bb GM |
6174 | defsubr (&Sx_file_dialog); |
6175 | #endif | |
9bf80974 | 6176 | |
946598bf | 6177 | #if defined (USE_GTK) && defined (HAVE_FREETYPE) |
f82605c6 | 6178 | defsubr (&Sx_select_font); |
9bf80974 | 6179 | #endif |
333b20bb | 6180 | } |