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