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