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