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