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