(byte-compile-warning-types): Add interactive-only.
[emacs.git] / src / xfns.c
blob2cf8a59ca5207910db4894f3911059218b9d588e
1 /* Functions for the X window system.
2 Copyright (C) 1989, 92, 93, 94, 95, 96, 97, 98, 99, 2000,01,02,03,04
3 Free Software Foundation.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #include <config.h>
23 #include <signal.h>
24 #include <stdio.h>
25 #include <math.h>
27 #ifdef HAVE_UNISTD_H
28 #include <unistd.h>
29 #endif
31 /* This makes the fields of a Display accessible, in Xlib header files. */
33 #define XLIB_ILLEGAL_ACCESS
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 "charset.h"
46 #include "coding.h"
47 #include "fontset.h"
48 #include "systime.h"
49 #include "termhooks.h"
50 #include "atimer.h"
52 #ifdef HAVE_X_WINDOWS
54 #include <ctype.h>
55 #include <sys/types.h>
56 #include <sys/stat.h>
58 #ifndef VMS
59 #if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */
60 #include "bitmaps/gray.xbm"
61 #else
62 #include <X11/bitmaps/gray>
63 #endif
64 #else
65 #include "[.bitmaps]gray.xbm"
66 #endif
68 #ifdef USE_GTK
69 #include "gtkutil.h"
70 #endif
72 #ifdef USE_X_TOOLKIT
73 #include <X11/Shell.h>
75 #ifndef USE_MOTIF
76 #include <X11/Xaw/Paned.h>
77 #include <X11/Xaw/Label.h>
78 #endif /* USE_MOTIF */
80 #ifdef USG
81 #undef USG /* ####KLUDGE for Solaris 2.2 and up */
82 #include <X11/Xos.h>
83 #define USG
84 #else
85 #include <X11/Xos.h>
86 #endif
88 #include "widget.h"
90 #include "../lwlib/lwlib.h"
92 #ifdef USE_MOTIF
93 #include <Xm/Xm.h>
94 #include <Xm/DialogS.h>
95 #include <Xm/FileSB.h>
96 #endif
98 /* Do the EDITRES protocol if running X11R5
99 Exception: HP-UX (at least version A.09.05) has X11R5 without EditRes */
101 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
102 #define HACK_EDITRES
103 extern void _XEditResCheckMessages ();
104 #endif /* R5 + Athena */
106 /* Unique id counter for widgets created by the Lucid Widget Library. */
108 extern LWLIB_ID widget_id_tick;
110 #ifdef USE_LUCID
111 /* This is part of a kludge--see lwlib/xlwmenu.c. */
112 extern XFontStruct *xlwmenu_default_font;
113 #endif
115 extern void free_frame_menubar ();
116 extern double atof ();
118 #ifdef USE_MOTIF
120 /* LessTif/Motif version info. */
122 static Lisp_Object Vmotif_version_string;
124 #endif /* USE_MOTIF */
126 #endif /* USE_X_TOOLKIT */
128 #ifdef USE_GTK
130 /* GTK+ version info */
132 static Lisp_Object Vgtk_version_string;
134 #endif /* USE_GTK */
136 #ifdef HAVE_X11R4
137 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
138 #else
139 #define MAXREQUEST(dpy) ((dpy)->max_request_size)
140 #endif
142 /* The gray bitmap `bitmaps/gray'. This is done because xterm.c uses
143 it, and including `bitmaps/gray' more than once is a problem when
144 config.h defines `static' as an empty replacement string. */
146 int gray_bitmap_width = gray_width;
147 int gray_bitmap_height = gray_height;
148 char *gray_bitmap_bits = gray_bits;
150 /* Non-zero means we're allowed to display an hourglass cursor. */
152 int display_hourglass_p;
154 /* The background and shape of the mouse pointer, and shape when not
155 over text or in the modeline. */
157 Lisp_Object Vx_pointer_shape, Vx_nontext_pointer_shape, Vx_mode_pointer_shape;
158 Lisp_Object Vx_hourglass_pointer_shape;
160 /* The shape when over mouse-sensitive text. */
162 Lisp_Object Vx_sensitive_text_pointer_shape;
164 /* If non-nil, the pointer shape to indicate that windows can be
165 dragged horizontally. */
167 Lisp_Object Vx_window_horizontal_drag_shape;
169 /* Color of chars displayed in cursor box. */
171 Lisp_Object Vx_cursor_fore_pixel;
173 /* Nonzero if using X. */
175 static int x_in_use;
177 /* Non nil if no window manager is in use. */
179 Lisp_Object Vx_no_window_manager;
181 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
183 Lisp_Object Vx_pixel_size_width_font_regexp;
185 Lisp_Object Qnone;
186 Lisp_Object Qsuppress_icon;
187 Lisp_Object Qundefined_color;
188 Lisp_Object Qcompound_text, Qcancel_timer;
190 /* In dispnew.c */
192 extern Lisp_Object Vwindow_system_version;
194 /* The below are defined in frame.c. */
196 #if GLYPH_DEBUG
197 int image_cache_refcount, dpyinfo_refcount;
198 #endif
202 /* Error if we are not connected to X. */
204 void
205 check_x ()
207 if (! x_in_use)
208 error ("X windows are not in use or not initialized");
211 /* Nonzero if we can use mouse menus.
212 You should not call this unless HAVE_MENUS is defined. */
215 have_menus_p ()
217 return x_in_use;
220 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
221 and checking validity for X. */
223 FRAME_PTR
224 check_x_frame (frame)
225 Lisp_Object frame;
227 FRAME_PTR f;
229 if (NILP (frame))
230 frame = selected_frame;
231 CHECK_LIVE_FRAME (frame);
232 f = XFRAME (frame);
233 if (! FRAME_X_P (f))
234 error ("Non-X frame used");
235 return f;
238 /* Let the user specify an X display with a frame.
239 nil stands for the selected frame--or, if that is not an X frame,
240 the first X display on the list. */
242 struct x_display_info *
243 check_x_display_info (frame)
244 Lisp_Object frame;
246 struct x_display_info *dpyinfo = NULL;
248 if (NILP (frame))
250 struct frame *sf = XFRAME (selected_frame);
252 if (FRAME_X_P (sf) && FRAME_LIVE_P (sf))
253 dpyinfo = FRAME_X_DISPLAY_INFO (sf);
254 else if (x_display_list != 0)
255 dpyinfo = x_display_list;
256 else
257 error ("X windows are not in use or not initialized");
259 else if (STRINGP (frame))
260 dpyinfo = x_display_info_for_name (frame);
261 else
263 FRAME_PTR f = check_x_frame (frame);
264 dpyinfo = FRAME_X_DISPLAY_INFO (f);
267 return dpyinfo;
271 /* Return the Emacs frame-object corresponding to an X window.
272 It could be the frame's main window or an icon window. */
274 /* This function can be called during GC, so use GC_xxx type test macros. */
276 struct frame *
277 x_window_to_frame (dpyinfo, wdesc)
278 struct x_display_info *dpyinfo;
279 int wdesc;
281 Lisp_Object tail, frame;
282 struct frame *f;
284 if (wdesc == None) return 0;
286 for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
288 frame = XCAR (tail);
289 if (!GC_FRAMEP (frame))
290 continue;
291 f = XFRAME (frame);
292 if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
293 continue;
294 if (f->output_data.x->hourglass_window == wdesc)
295 return f;
296 #ifdef USE_X_TOOLKIT
297 if ((f->output_data.x->edit_widget
298 && XtWindow (f->output_data.x->edit_widget) == wdesc)
299 /* A tooltip frame? */
300 || (!f->output_data.x->edit_widget
301 && FRAME_X_WINDOW (f) == wdesc)
302 || f->output_data.x->icon_desc == wdesc)
303 return f;
304 #else /* not USE_X_TOOLKIT */
305 #ifdef USE_GTK
306 if (f->output_data.x->edit_widget)
308 GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
309 struct x_output *x = f->output_data.x;
310 if (gwdesc != 0 && gwdesc == x->edit_widget)
311 return f;
313 #endif /* USE_GTK */
314 if (FRAME_X_WINDOW (f) == wdesc
315 || f->output_data.x->icon_desc == wdesc)
316 return f;
317 #endif /* not USE_X_TOOLKIT */
319 return 0;
322 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
323 /* Like x_window_to_frame but also compares the window with the widget's
324 windows. */
326 struct frame *
327 x_any_window_to_frame (dpyinfo, wdesc)
328 struct x_display_info *dpyinfo;
329 int wdesc;
331 Lisp_Object tail, frame;
332 struct frame *f, *found;
333 struct x_output *x;
335 if (wdesc == None) return NULL;
337 found = NULL;
338 for (tail = Vframe_list; GC_CONSP (tail) && !found; tail = XCDR (tail))
340 frame = XCAR (tail);
341 if (!GC_FRAMEP (frame))
342 continue;
344 f = XFRAME (frame);
345 if (FRAME_X_P (f) && FRAME_X_DISPLAY_INFO (f) == dpyinfo)
347 /* This frame matches if the window is any of its widgets. */
348 x = f->output_data.x;
349 if (x->hourglass_window == wdesc)
350 found = f;
351 else if (x->widget)
353 #ifdef USE_GTK
354 GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
355 if (gwdesc != 0
356 && (gwdesc == x->widget
357 || gwdesc == x->edit_widget
358 || gwdesc == x->vbox_widget
359 || gwdesc == x->menubar_widget))
360 found = f;
361 #else
362 if (wdesc == XtWindow (x->widget)
363 || wdesc == XtWindow (x->column_widget)
364 || wdesc == XtWindow (x->edit_widget))
365 found = f;
366 /* Match if the window is this frame's menubar. */
367 else if (lw_window_is_in_menubar (wdesc, x->menubar_widget))
368 found = f;
369 #endif
371 else if (FRAME_X_WINDOW (f) == wdesc)
372 /* A tooltip frame. */
373 found = f;
377 return found;
380 /* Likewise, but exclude the menu bar widget. */
382 struct frame *
383 x_non_menubar_window_to_frame (dpyinfo, wdesc)
384 struct x_display_info *dpyinfo;
385 int wdesc;
387 Lisp_Object tail, frame;
388 struct frame *f;
389 struct x_output *x;
391 if (wdesc == None) return 0;
393 for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
395 frame = XCAR (tail);
396 if (!GC_FRAMEP (frame))
397 continue;
398 f = XFRAME (frame);
399 if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
400 continue;
401 x = f->output_data.x;
402 /* This frame matches if the window is any of its widgets. */
403 if (x->hourglass_window == wdesc)
404 return f;
405 else if (x->widget)
407 #ifdef USE_GTK
408 GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
409 if (gwdesc != 0
410 && (gwdesc == x->widget
411 || gwdesc == x->edit_widget
412 || gwdesc == x->vbox_widget))
413 return f;
414 #else
415 if (wdesc == XtWindow (x->widget)
416 || wdesc == XtWindow (x->column_widget)
417 || wdesc == XtWindow (x->edit_widget))
418 return f;
419 #endif
421 else if (FRAME_X_WINDOW (f) == wdesc)
422 /* A tooltip frame. */
423 return f;
425 return 0;
428 /* Likewise, but consider only the menu bar widget. */
430 struct frame *
431 x_menubar_window_to_frame (dpyinfo, wdesc)
432 struct x_display_info *dpyinfo;
433 int wdesc;
435 Lisp_Object tail, frame;
436 struct frame *f;
437 struct x_output *x;
439 if (wdesc == None) return 0;
441 for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
443 frame = XCAR (tail);
444 if (!GC_FRAMEP (frame))
445 continue;
446 f = XFRAME (frame);
447 if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
448 continue;
449 x = f->output_data.x;
450 /* Match if the window is this frame's menubar. */
451 #ifdef USE_GTK
452 if (x->menubar_widget)
454 GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
455 int found = 0;
457 BLOCK_INPUT;
458 if (gwdesc != 0
459 && (gwdesc == x->menubar_widget
460 || gtk_widget_get_parent (gwdesc) == x->menubar_widget))
461 found = 1;
462 UNBLOCK_INPUT;
463 if (found) return f;
465 #else
466 if (x->menubar_widget
467 && lw_window_is_in_menubar (wdesc, x->menubar_widget))
468 return f;
469 #endif
471 return 0;
474 /* Return the frame whose principal (outermost) window is WDESC.
475 If WDESC is some other (smaller) window, we return 0. */
477 struct frame *
478 x_top_window_to_frame (dpyinfo, wdesc)
479 struct x_display_info *dpyinfo;
480 int wdesc;
482 Lisp_Object tail, frame;
483 struct frame *f;
484 struct x_output *x;
486 if (wdesc == None) return 0;
488 for (tail = Vframe_list; GC_CONSP (tail); tail = XCDR (tail))
490 frame = XCAR (tail);
491 if (!GC_FRAMEP (frame))
492 continue;
493 f = XFRAME (frame);
494 if (!FRAME_X_P (f) || FRAME_X_DISPLAY_INFO (f) != dpyinfo)
495 continue;
496 x = f->output_data.x;
498 if (x->widget)
500 /* This frame matches if the window is its topmost widget. */
501 #ifdef USE_GTK
502 GtkWidget *gwdesc = xg_win_to_widget (dpyinfo->display, wdesc);
503 if (gwdesc == x->widget)
504 return f;
505 #else
506 if (wdesc == XtWindow (x->widget))
507 return f;
508 #if 0 /* I don't know why it did this,
509 but it seems logically wrong,
510 and it causes trouble for MapNotify events. */
511 /* Match if the window is this frame's menubar. */
512 if (x->menubar_widget
513 && wdesc == XtWindow (x->menubar_widget))
514 return f;
515 #endif
516 #endif
518 else if (FRAME_X_WINDOW (f) == wdesc)
519 /* Tooltip frame. */
520 return f;
522 return 0;
524 #endif /* USE_X_TOOLKIT || USE_GTK */
528 static Lisp_Object unwind_create_frame P_ ((Lisp_Object));
529 static Lisp_Object unwind_create_tip_frame P_ ((Lisp_Object));
531 void x_set_foreground_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
532 static void x_set_wait_for_wm P_ ((struct frame *, Lisp_Object, Lisp_Object));
533 void x_set_background_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
534 void x_set_mouse_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
535 void x_set_cursor_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
536 void x_set_border_color P_ ((struct frame *, Lisp_Object, Lisp_Object));
537 void x_set_cursor_type P_ ((struct frame *, Lisp_Object, Lisp_Object));
538 void x_set_icon_type P_ ((struct frame *, Lisp_Object, Lisp_Object));
539 void x_set_icon_name P_ ((struct frame *, Lisp_Object, Lisp_Object));
540 void x_explicitly_set_name P_ ((struct frame *, Lisp_Object, Lisp_Object));
541 void x_set_menu_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
542 void x_set_title P_ ((struct frame *, Lisp_Object, Lisp_Object));
543 void x_set_tool_bar_lines P_ ((struct frame *, Lisp_Object, Lisp_Object));
544 void x_set_scroll_bar_foreground P_ ((struct frame *, Lisp_Object,
545 Lisp_Object));
546 void x_set_scroll_bar_background P_ ((struct frame *, Lisp_Object,
547 Lisp_Object));
548 static Lisp_Object x_default_scroll_bar_color_parameter P_ ((struct frame *,
549 Lisp_Object,
550 Lisp_Object,
551 char *, char *,
552 int));
555 /* Store the screen positions of frame F into XPTR and YPTR.
556 These are the positions of the containing window manager window,
557 not Emacs's own window. */
559 void
560 x_real_positions (f, xptr, yptr)
561 FRAME_PTR f;
562 int *xptr, *yptr;
564 int win_x, win_y, outer_x, outer_y;
565 int real_x = 0, real_y = 0;
566 int had_errors = 0;
567 Window win = f->output_data.x->parent_desc;
569 int count;
571 BLOCK_INPUT;
573 count = x_catch_errors (FRAME_X_DISPLAY (f));
575 if (win == FRAME_X_DISPLAY_INFO (f)->root_window)
576 win = FRAME_OUTER_WINDOW (f);
578 /* This loop traverses up the containment tree until we hit the root
579 window. Window managers may intersect many windows between our window
580 and the root window. The window we find just before the root window
581 should be the outer WM window. */
582 for (;;)
584 Window wm_window, rootw;
585 Window *tmp_children;
586 unsigned int tmp_nchildren;
587 int success;
589 success = XQueryTree (FRAME_X_DISPLAY (f), win, &rootw,
590 &wm_window, &tmp_children, &tmp_nchildren);
592 had_errors = x_had_errors_p (FRAME_X_DISPLAY (f));
594 /* Don't free tmp_children if XQueryTree failed. */
595 if (! success)
596 break;
598 XFree ((char *) tmp_children);
600 if (wm_window == rootw || had_errors)
601 break;
603 win = wm_window;
606 if (! had_errors)
608 int ign;
609 Window child, rootw;
611 /* Get the real coordinates for the WM window upper left corner */
612 XGetGeometry (FRAME_X_DISPLAY (f), win,
613 &rootw, &real_x, &real_y, &ign, &ign, &ign, &ign);
615 /* Translate real coordinates to coordinates relative to our
616 window. For our window, the upper left corner is 0, 0.
617 Since the upper left corner of the WM window is outside
618 our window, win_x and win_y will be negative:
620 ------------------ ---> x
621 | title |
622 | ----------------- v y
623 | | our window
625 XTranslateCoordinates (FRAME_X_DISPLAY (f),
627 /* From-window, to-window. */
628 FRAME_X_DISPLAY_INFO (f)->root_window,
629 FRAME_X_WINDOW (f),
631 /* From-position, to-position. */
632 real_x, real_y, &win_x, &win_y,
634 /* Child of win. */
635 &child);
637 if (FRAME_X_WINDOW (f) == FRAME_OUTER_WINDOW (f))
639 outer_x = win_x;
640 outer_y = win_y;
642 else
644 XTranslateCoordinates (FRAME_X_DISPLAY (f),
646 /* From-window, to-window. */
647 FRAME_X_DISPLAY_INFO (f)->root_window,
648 FRAME_OUTER_WINDOW (f),
650 /* From-position, to-position. */
651 real_x, real_y, &outer_x, &outer_y,
653 /* Child of win. */
654 &child);
657 had_errors = x_had_errors_p (FRAME_X_DISPLAY (f));
660 x_uncatch_errors (FRAME_X_DISPLAY (f), count);
662 UNBLOCK_INPUT;
664 if (had_errors) return;
666 f->x_pixels_diff = -win_x;
667 f->y_pixels_diff = -win_y;
669 FRAME_X_OUTPUT (f)->x_pixels_outer_diff = -outer_x;
670 FRAME_X_OUTPUT (f)->y_pixels_outer_diff = -outer_y;
672 *xptr = real_x;
673 *yptr = real_y;
679 /* Gamma-correct COLOR on frame F. */
681 void
682 gamma_correct (f, color)
683 struct frame *f;
684 XColor *color;
686 if (f->gamma)
688 color->red = pow (color->red / 65535.0, f->gamma) * 65535.0 + 0.5;
689 color->green = pow (color->green / 65535.0, f->gamma) * 65535.0 + 0.5;
690 color->blue = pow (color->blue / 65535.0, f->gamma) * 65535.0 + 0.5;
695 /* Decide if color named COLOR_NAME is valid for use on frame F. If
696 so, return the RGB values in COLOR. If ALLOC_P is non-zero,
697 allocate the color. Value is zero if COLOR_NAME is invalid, or
698 no color could be allocated. */
701 x_defined_color (f, color_name, color, alloc_p)
702 struct frame *f;
703 char *color_name;
704 XColor *color;
705 int alloc_p;
707 int success_p;
708 Display *dpy = FRAME_X_DISPLAY (f);
709 Colormap cmap = FRAME_X_COLORMAP (f);
711 BLOCK_INPUT;
712 success_p = XParseColor (dpy, cmap, color_name, color);
713 if (success_p && alloc_p)
714 success_p = x_alloc_nearest_color (f, cmap, color);
715 UNBLOCK_INPUT;
717 return success_p;
721 /* Return the pixel color value for color COLOR_NAME on frame F. If F
722 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
723 Signal an error if color can't be allocated. */
726 x_decode_color (f, color_name, mono_color)
727 FRAME_PTR f;
728 Lisp_Object color_name;
729 int mono_color;
731 XColor cdef;
733 CHECK_STRING (color_name);
735 #if 0 /* Don't do this. It's wrong when we're not using the default
736 colormap, it makes freeing difficult, and it's probably not
737 an important optimization. */
738 if (strcmp (SDATA (color_name), "black") == 0)
739 return BLACK_PIX_DEFAULT (f);
740 else if (strcmp (SDATA (color_name), "white") == 0)
741 return WHITE_PIX_DEFAULT (f);
742 #endif
744 /* Return MONO_COLOR for monochrome frames. */
745 if (FRAME_X_DISPLAY_INFO (f)->n_planes == 1)
746 return mono_color;
748 /* x_defined_color is responsible for coping with failures
749 by looking for a near-miss. */
750 if (x_defined_color (f, SDATA (color_name), &cdef, 1))
751 return cdef.pixel;
753 Fsignal (Qerror, Fcons (build_string ("Undefined color"),
754 Fcons (color_name, Qnil)));
755 return 0;
760 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
761 the previous value of that parameter, NEW_VALUE is the new value.
762 See also the comment of wait_for_wm in struct x_output. */
764 static void
765 x_set_wait_for_wm (f, new_value, old_value)
766 struct frame *f;
767 Lisp_Object new_value, old_value;
769 f->output_data.x->wait_for_wm = !NILP (new_value);
772 #ifdef USE_GTK
774 /* Set icon from FILE for frame F. By using GTK functions the icon
775 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
778 xg_set_icon (f, file)
779 FRAME_PTR f;
780 Lisp_Object file;
782 struct gcpro gcpro1;
783 int result = 0;
784 Lisp_Object found;
786 GCPRO1 (found);
788 found = x_find_image_file (file);
790 if (! NILP (found))
792 GdkPixbuf *pixbuf;
793 GError *err = NULL;
794 char *filename;
796 filename = SDATA (found);
797 BLOCK_INPUT;
799 pixbuf = gdk_pixbuf_new_from_file (filename, &err);
801 if (pixbuf)
803 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
804 pixbuf);
805 g_object_unref (pixbuf);
807 result = 1;
809 else
810 g_error_free (err);
812 UNBLOCK_INPUT;
815 UNGCPRO;
816 return result;
818 #endif /* USE_GTK */
821 /* Functions called only from `x_set_frame_param'
822 to set individual parameters.
824 If FRAME_X_WINDOW (f) is 0,
825 the frame is being created and its X-window does not exist yet.
826 In that case, just record the parameter's new value
827 in the standard place; do not attempt to change the window. */
829 void
830 x_set_foreground_color (f, arg, oldval)
831 struct frame *f;
832 Lisp_Object arg, oldval;
834 struct x_output *x = f->output_data.x;
835 unsigned long fg, old_fg;
837 fg = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
838 old_fg = x->foreground_pixel;
839 x->foreground_pixel = fg;
841 if (FRAME_X_WINDOW (f) != 0)
843 Display *dpy = FRAME_X_DISPLAY (f);
845 BLOCK_INPUT;
846 XSetForeground (dpy, x->normal_gc, fg);
847 XSetBackground (dpy, x->reverse_gc, fg);
849 if (x->cursor_pixel == old_fg)
851 unload_color (f, x->cursor_pixel);
852 x->cursor_pixel = x_copy_color (f, fg);
853 XSetBackground (dpy, x->cursor_gc, x->cursor_pixel);
856 UNBLOCK_INPUT;
858 update_face_from_frame_parameter (f, Qforeground_color, arg);
860 if (FRAME_VISIBLE_P (f))
861 redraw_frame (f);
864 unload_color (f, old_fg);
867 void
868 x_set_background_color (f, arg, oldval)
869 struct frame *f;
870 Lisp_Object arg, oldval;
872 struct x_output *x = f->output_data.x;
873 unsigned long bg;
875 bg = x_decode_color (f, arg, WHITE_PIX_DEFAULT (f));
876 unload_color (f, x->background_pixel);
877 x->background_pixel = bg;
879 if (FRAME_X_WINDOW (f) != 0)
881 Display *dpy = FRAME_X_DISPLAY (f);
883 BLOCK_INPUT;
884 XSetBackground (dpy, x->normal_gc, bg);
885 XSetForeground (dpy, x->reverse_gc, bg);
886 XSetWindowBackground (dpy, FRAME_X_WINDOW (f), bg);
887 XSetForeground (dpy, x->cursor_gc, bg);
889 #ifdef USE_GTK
890 xg_set_background_color (f, bg);
891 #endif
893 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
894 toolkit scroll bars. */
896 Lisp_Object bar;
897 for (bar = FRAME_SCROLL_BARS (f);
898 !NILP (bar);
899 bar = XSCROLL_BAR (bar)->next)
901 Window window = SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar));
902 XSetWindowBackground (dpy, window, bg);
905 #endif /* USE_TOOLKIT_SCROLL_BARS */
907 UNBLOCK_INPUT;
908 update_face_from_frame_parameter (f, Qbackground_color, arg);
910 if (FRAME_VISIBLE_P (f))
911 redraw_frame (f);
915 void
916 x_set_mouse_color (f, arg, oldval)
917 struct frame *f;
918 Lisp_Object arg, oldval;
920 struct x_output *x = f->output_data.x;
921 Display *dpy = FRAME_X_DISPLAY (f);
922 Cursor cursor, nontext_cursor, mode_cursor, hand_cursor;
923 Cursor hourglass_cursor, horizontal_drag_cursor;
924 int count;
925 unsigned long pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
926 unsigned long mask_color = x->background_pixel;
928 /* Don't let pointers be invisible. */
929 if (mask_color == pixel)
931 x_free_colors (f, &pixel, 1);
932 pixel = x_copy_color (f, x->foreground_pixel);
935 unload_color (f, x->mouse_pixel);
936 x->mouse_pixel = pixel;
938 BLOCK_INPUT;
940 /* It's not okay to crash if the user selects a screwy cursor. */
941 count = x_catch_errors (dpy);
943 if (!NILP (Vx_pointer_shape))
945 CHECK_NUMBER (Vx_pointer_shape);
946 cursor = XCreateFontCursor (dpy, XINT (Vx_pointer_shape));
948 else
949 cursor = XCreateFontCursor (dpy, XC_xterm);
950 x_check_errors (dpy, "bad text pointer cursor: %s");
952 if (!NILP (Vx_nontext_pointer_shape))
954 CHECK_NUMBER (Vx_nontext_pointer_shape);
955 nontext_cursor
956 = XCreateFontCursor (dpy, XINT (Vx_nontext_pointer_shape));
958 else
959 nontext_cursor = XCreateFontCursor (dpy, XC_left_ptr);
960 x_check_errors (dpy, "bad nontext pointer cursor: %s");
962 if (!NILP (Vx_hourglass_pointer_shape))
964 CHECK_NUMBER (Vx_hourglass_pointer_shape);
965 hourglass_cursor
966 = XCreateFontCursor (dpy, XINT (Vx_hourglass_pointer_shape));
968 else
969 hourglass_cursor = XCreateFontCursor (dpy, XC_watch);
970 x_check_errors (dpy, "bad hourglass pointer cursor: %s");
972 if (!NILP (Vx_mode_pointer_shape))
974 CHECK_NUMBER (Vx_mode_pointer_shape);
975 mode_cursor = XCreateFontCursor (dpy, XINT (Vx_mode_pointer_shape));
977 else
978 mode_cursor = XCreateFontCursor (dpy, XC_xterm);
979 x_check_errors (dpy, "bad modeline pointer cursor: %s");
981 if (!NILP (Vx_sensitive_text_pointer_shape))
983 CHECK_NUMBER (Vx_sensitive_text_pointer_shape);
984 hand_cursor
985 = XCreateFontCursor (dpy, XINT (Vx_sensitive_text_pointer_shape));
987 else
988 hand_cursor = XCreateFontCursor (dpy, XC_hand2);
990 if (!NILP (Vx_window_horizontal_drag_shape))
992 CHECK_NUMBER (Vx_window_horizontal_drag_shape);
993 horizontal_drag_cursor
994 = XCreateFontCursor (dpy, XINT (Vx_window_horizontal_drag_shape));
996 else
997 horizontal_drag_cursor
998 = XCreateFontCursor (dpy, XC_sb_h_double_arrow);
1000 /* Check and report errors with the above calls. */
1001 x_check_errors (dpy, "can't set cursor shape: %s");
1002 x_uncatch_errors (dpy, count);
1005 XColor fore_color, back_color;
1007 fore_color.pixel = x->mouse_pixel;
1008 x_query_color (f, &fore_color);
1009 back_color.pixel = mask_color;
1010 x_query_color (f, &back_color);
1012 XRecolorCursor (dpy, cursor, &fore_color, &back_color);
1013 XRecolorCursor (dpy, nontext_cursor, &fore_color, &back_color);
1014 XRecolorCursor (dpy, mode_cursor, &fore_color, &back_color);
1015 XRecolorCursor (dpy, hand_cursor, &fore_color, &back_color);
1016 XRecolorCursor (dpy, hourglass_cursor, &fore_color, &back_color);
1017 XRecolorCursor (dpy, horizontal_drag_cursor, &fore_color, &back_color);
1020 if (FRAME_X_WINDOW (f) != 0)
1021 XDefineCursor (dpy, FRAME_X_WINDOW (f), cursor);
1023 if (cursor != x->text_cursor
1024 && x->text_cursor != 0)
1025 XFreeCursor (dpy, x->text_cursor);
1026 x->text_cursor = cursor;
1028 if (nontext_cursor != x->nontext_cursor
1029 && x->nontext_cursor != 0)
1030 XFreeCursor (dpy, x->nontext_cursor);
1031 x->nontext_cursor = nontext_cursor;
1033 if (hourglass_cursor != x->hourglass_cursor
1034 && x->hourglass_cursor != 0)
1035 XFreeCursor (dpy, x->hourglass_cursor);
1036 x->hourglass_cursor = hourglass_cursor;
1038 if (mode_cursor != x->modeline_cursor
1039 && x->modeline_cursor != 0)
1040 XFreeCursor (dpy, f->output_data.x->modeline_cursor);
1041 x->modeline_cursor = mode_cursor;
1043 if (hand_cursor != x->hand_cursor
1044 && x->hand_cursor != 0)
1045 XFreeCursor (dpy, x->hand_cursor);
1046 x->hand_cursor = hand_cursor;
1048 if (horizontal_drag_cursor != x->horizontal_drag_cursor
1049 && x->horizontal_drag_cursor != 0)
1050 XFreeCursor (dpy, x->horizontal_drag_cursor);
1051 x->horizontal_drag_cursor = horizontal_drag_cursor;
1053 XFlush (dpy);
1054 UNBLOCK_INPUT;
1056 update_face_from_frame_parameter (f, Qmouse_color, arg);
1059 void
1060 x_set_cursor_color (f, arg, oldval)
1061 struct frame *f;
1062 Lisp_Object arg, oldval;
1064 unsigned long fore_pixel, pixel;
1065 int fore_pixel_allocated_p = 0, pixel_allocated_p = 0;
1066 struct x_output *x = f->output_data.x;
1068 if (!NILP (Vx_cursor_fore_pixel))
1070 fore_pixel = x_decode_color (f, Vx_cursor_fore_pixel,
1071 WHITE_PIX_DEFAULT (f));
1072 fore_pixel_allocated_p = 1;
1074 else
1075 fore_pixel = x->background_pixel;
1077 pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
1078 pixel_allocated_p = 1;
1080 /* Make sure that the cursor color differs from the background color. */
1081 if (pixel == x->background_pixel)
1083 if (pixel_allocated_p)
1085 x_free_colors (f, &pixel, 1);
1086 pixel_allocated_p = 0;
1089 pixel = x->mouse_pixel;
1090 if (pixel == fore_pixel)
1092 if (fore_pixel_allocated_p)
1094 x_free_colors (f, &fore_pixel, 1);
1095 fore_pixel_allocated_p = 0;
1097 fore_pixel = x->background_pixel;
1101 unload_color (f, x->cursor_foreground_pixel);
1102 if (!fore_pixel_allocated_p)
1103 fore_pixel = x_copy_color (f, fore_pixel);
1104 x->cursor_foreground_pixel = fore_pixel;
1106 unload_color (f, x->cursor_pixel);
1107 if (!pixel_allocated_p)
1108 pixel = x_copy_color (f, pixel);
1109 x->cursor_pixel = pixel;
1111 if (FRAME_X_WINDOW (f) != 0)
1113 BLOCK_INPUT;
1114 XSetBackground (FRAME_X_DISPLAY (f), x->cursor_gc, x->cursor_pixel);
1115 XSetForeground (FRAME_X_DISPLAY (f), x->cursor_gc, fore_pixel);
1116 UNBLOCK_INPUT;
1118 if (FRAME_VISIBLE_P (f))
1120 x_update_cursor (f, 0);
1121 x_update_cursor (f, 1);
1125 update_face_from_frame_parameter (f, Qcursor_color, arg);
1128 /* Set the border-color of frame F to pixel value PIX.
1129 Note that this does not fully take effect if done before
1130 F has an x-window. */
1132 void
1133 x_set_border_pixel (f, pix)
1134 struct frame *f;
1135 int pix;
1137 unload_color (f, f->output_data.x->border_pixel);
1138 f->output_data.x->border_pixel = pix;
1140 if (FRAME_X_WINDOW (f) != 0 && f->border_width > 0)
1142 BLOCK_INPUT;
1143 XSetWindowBorder (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1144 (unsigned long)pix);
1145 UNBLOCK_INPUT;
1147 if (FRAME_VISIBLE_P (f))
1148 redraw_frame (f);
1152 /* Set the border-color of frame F to value described by ARG.
1153 ARG can be a string naming a color.
1154 The border-color is used for the border that is drawn by the X server.
1155 Note that this does not fully take effect if done before
1156 F has an x-window; it must be redone when the window is created.
1158 Note: this is done in two routines because of the way X10 works.
1160 Note: under X11, this is normally the province of the window manager,
1161 and so emacs' border colors may be overridden. */
1163 void
1164 x_set_border_color (f, arg, oldval)
1165 struct frame *f;
1166 Lisp_Object arg, oldval;
1168 int pix;
1170 CHECK_STRING (arg);
1171 pix = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
1172 x_set_border_pixel (f, pix);
1173 update_face_from_frame_parameter (f, Qborder_color, arg);
1177 void
1178 x_set_cursor_type (f, arg, oldval)
1179 FRAME_PTR f;
1180 Lisp_Object arg, oldval;
1182 set_frame_cursor_types (f, arg);
1184 /* Make sure the cursor gets redrawn. */
1185 cursor_type_changed = 1;
1188 void
1189 x_set_icon_type (f, arg, oldval)
1190 struct frame *f;
1191 Lisp_Object arg, oldval;
1193 int result;
1195 if (STRINGP (arg))
1197 if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt))
1198 return;
1200 else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil))
1201 return;
1203 BLOCK_INPUT;
1204 if (NILP (arg))
1205 result = x_text_icon (f,
1206 (char *) SDATA ((!NILP (f->icon_name)
1207 ? f->icon_name
1208 : f->name)));
1209 else
1210 result = x_bitmap_icon (f, arg);
1212 if (result)
1214 UNBLOCK_INPUT;
1215 error ("No icon window available");
1218 XFlush (FRAME_X_DISPLAY (f));
1219 UNBLOCK_INPUT;
1222 void
1223 x_set_icon_name (f, arg, oldval)
1224 struct frame *f;
1225 Lisp_Object arg, oldval;
1227 int result;
1229 if (STRINGP (arg))
1231 if (STRINGP (oldval) && EQ (Fstring_equal (oldval, arg), Qt))
1232 return;
1234 else if (!STRINGP (oldval) && EQ (oldval, Qnil) == EQ (arg, Qnil))
1235 return;
1237 f->icon_name = arg;
1239 if (f->output_data.x->icon_bitmap != 0)
1240 return;
1242 BLOCK_INPUT;
1244 result = x_text_icon (f,
1245 (char *) SDATA ((!NILP (f->icon_name)
1246 ? f->icon_name
1247 : !NILP (f->title)
1248 ? f->title
1249 : f->name)));
1251 if (result)
1253 UNBLOCK_INPUT;
1254 error ("No icon window available");
1257 XFlush (FRAME_X_DISPLAY (f));
1258 UNBLOCK_INPUT;
1262 void
1263 x_set_menu_bar_lines (f, value, oldval)
1264 struct frame *f;
1265 Lisp_Object value, oldval;
1267 int nlines;
1268 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
1269 int olines = FRAME_MENU_BAR_LINES (f);
1270 #endif
1272 /* Right now, menu bars don't work properly in minibuf-only frames;
1273 most of the commands try to apply themselves to the minibuffer
1274 frame itself, and get an error because you can't switch buffers
1275 in or split the minibuffer window. */
1276 if (FRAME_MINIBUF_ONLY_P (f))
1277 return;
1279 if (INTEGERP (value))
1280 nlines = XINT (value);
1281 else
1282 nlines = 0;
1284 /* Make sure we redisplay all windows in this frame. */
1285 windows_or_buffers_changed++;
1287 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
1288 FRAME_MENU_BAR_LINES (f) = 0;
1289 if (nlines)
1291 FRAME_EXTERNAL_MENU_BAR (f) = 1;
1292 if (FRAME_X_P (f) && f->output_data.x->menubar_widget == 0)
1293 /* Make sure next redisplay shows the menu bar. */
1294 XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = Qt;
1296 else
1298 if (FRAME_EXTERNAL_MENU_BAR (f) == 1)
1299 free_frame_menubar (f);
1300 FRAME_EXTERNAL_MENU_BAR (f) = 0;
1301 if (FRAME_X_P (f))
1302 f->output_data.x->menubar_widget = 0;
1304 #else /* not USE_X_TOOLKIT && not USE_GTK */
1305 FRAME_MENU_BAR_LINES (f) = nlines;
1306 change_window_heights (f->root_window, nlines - olines);
1307 #endif /* not USE_X_TOOLKIT */
1308 adjust_glyphs (f);
1312 /* Set the number of lines used for the tool bar of frame F to VALUE.
1313 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1314 is the old number of tool bar lines. This function changes the
1315 height of all windows on frame F to match the new tool bar height.
1316 The frame's height doesn't change. */
1318 void
1319 x_set_tool_bar_lines (f, value, oldval)
1320 struct frame *f;
1321 Lisp_Object value, oldval;
1323 int delta, nlines, root_height;
1324 Lisp_Object root_window;
1326 /* Treat tool bars like menu bars. */
1327 if (FRAME_MINIBUF_ONLY_P (f))
1328 return;
1330 /* Use VALUE only if an integer >= 0. */
1331 if (INTEGERP (value) && XINT (value) >= 0)
1332 nlines = XFASTINT (value);
1333 else
1334 nlines = 0;
1336 #ifdef USE_GTK
1337 FRAME_TOOL_BAR_LINES (f) = 0;
1338 if (nlines)
1340 FRAME_EXTERNAL_TOOL_BAR (f) = 1;
1341 if (FRAME_X_P (f) && f->output_data.x->toolbar_widget == 0)
1342 /* Make sure next redisplay shows the tool bar. */
1343 XWINDOW (FRAME_SELECTED_WINDOW (f))->update_mode_line = Qt;
1344 update_frame_tool_bar (f);
1346 else
1348 if (FRAME_EXTERNAL_TOOL_BAR (f))
1349 free_frame_tool_bar (f);
1350 FRAME_EXTERNAL_TOOL_BAR (f) = 0;
1353 return;
1354 #endif
1356 /* Make sure we redisplay all windows in this frame. */
1357 ++windows_or_buffers_changed;
1359 delta = nlines - FRAME_TOOL_BAR_LINES (f);
1361 /* Don't resize the tool-bar to more than we have room for. */
1362 root_window = FRAME_ROOT_WINDOW (f);
1363 root_height = WINDOW_TOTAL_LINES (XWINDOW (root_window));
1364 if (root_height - delta < 1)
1366 delta = root_height - 1;
1367 nlines = FRAME_TOOL_BAR_LINES (f) + delta;
1370 FRAME_TOOL_BAR_LINES (f) = nlines;
1371 change_window_heights (root_window, delta);
1372 adjust_glyphs (f);
1374 /* We also have to make sure that the internal border at the top of
1375 the frame, below the menu bar or tool bar, is redrawn when the
1376 tool bar disappears. This is so because the internal border is
1377 below the tool bar if one is displayed, but is below the menu bar
1378 if there isn't a tool bar. The tool bar draws into the area
1379 below the menu bar. */
1380 if (FRAME_X_WINDOW (f) && FRAME_TOOL_BAR_LINES (f) == 0)
1382 updating_frame = f;
1383 clear_frame ();
1384 clear_current_matrices (f);
1385 updating_frame = NULL;
1388 /* If the tool bar gets smaller, the internal border below it
1389 has to be cleared. It was formerly part of the display
1390 of the larger tool bar, and updating windows won't clear it. */
1391 if (delta < 0)
1393 int height = FRAME_INTERNAL_BORDER_WIDTH (f);
1394 int width = FRAME_PIXEL_WIDTH (f);
1395 int y = nlines * FRAME_LINE_HEIGHT (f);
1397 BLOCK_INPUT;
1398 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1399 0, y, width, height, False);
1400 UNBLOCK_INPUT;
1402 if (WINDOWP (f->tool_bar_window))
1403 clear_glyph_matrix (XWINDOW (f->tool_bar_window)->current_matrix);
1408 /* Set the foreground color for scroll bars on frame F to VALUE.
1409 VALUE should be a string, a color name. If it isn't a string or
1410 isn't a valid color name, do nothing. OLDVAL is the old value of
1411 the frame parameter. */
1413 void
1414 x_set_scroll_bar_foreground (f, value, oldval)
1415 struct frame *f;
1416 Lisp_Object value, oldval;
1418 unsigned long pixel;
1420 if (STRINGP (value))
1421 pixel = x_decode_color (f, value, BLACK_PIX_DEFAULT (f));
1422 else
1423 pixel = -1;
1425 if (f->output_data.x->scroll_bar_foreground_pixel != -1)
1426 unload_color (f, f->output_data.x->scroll_bar_foreground_pixel);
1428 f->output_data.x->scroll_bar_foreground_pixel = pixel;
1429 if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f))
1431 /* Remove all scroll bars because they have wrong colors. */
1432 if (condemn_scroll_bars_hook)
1433 (*condemn_scroll_bars_hook) (f);
1434 if (judge_scroll_bars_hook)
1435 (*judge_scroll_bars_hook) (f);
1437 update_face_from_frame_parameter (f, Qscroll_bar_foreground, value);
1438 redraw_frame (f);
1443 /* Set the background color for scroll bars on frame F to VALUE VALUE
1444 should be a string, a color name. If it isn't a string or isn't a
1445 valid color name, do nothing. OLDVAL is the old value of the frame
1446 parameter. */
1448 void
1449 x_set_scroll_bar_background (f, value, oldval)
1450 struct frame *f;
1451 Lisp_Object value, oldval;
1453 unsigned long pixel;
1455 if (STRINGP (value))
1456 pixel = x_decode_color (f, value, WHITE_PIX_DEFAULT (f));
1457 else
1458 pixel = -1;
1460 if (f->output_data.x->scroll_bar_background_pixel != -1)
1461 unload_color (f, f->output_data.x->scroll_bar_background_pixel);
1463 #ifdef USE_TOOLKIT_SCROLL_BARS
1464 /* Scrollbar shadow colors. */
1465 if (f->output_data.x->scroll_bar_top_shadow_pixel != -1)
1467 unload_color (f, f->output_data.x->scroll_bar_top_shadow_pixel);
1468 f->output_data.x->scroll_bar_top_shadow_pixel = -1;
1470 if (f->output_data.x->scroll_bar_bottom_shadow_pixel != -1)
1472 unload_color (f, f->output_data.x->scroll_bar_bottom_shadow_pixel);
1473 f->output_data.x->scroll_bar_bottom_shadow_pixel = -1;
1475 #endif /* USE_TOOLKIT_SCROLL_BARS */
1477 f->output_data.x->scroll_bar_background_pixel = pixel;
1478 if (FRAME_X_WINDOW (f) && FRAME_VISIBLE_P (f))
1480 /* Remove all scroll bars because they have wrong colors. */
1481 if (condemn_scroll_bars_hook)
1482 (*condemn_scroll_bars_hook) (f);
1483 if (judge_scroll_bars_hook)
1484 (*judge_scroll_bars_hook) (f);
1486 update_face_from_frame_parameter (f, Qscroll_bar_background, value);
1487 redraw_frame (f);
1492 /* Encode Lisp string STRING as a text in a format appropriate for
1493 XICCC (X Inter Client Communication Conventions).
1495 If STRING contains only ASCII characters, do no conversion and
1496 return the string data of STRING. Otherwise, encode the text by
1497 CODING_SYSTEM, and return a newly allocated memory area which
1498 should be freed by `xfree' by a caller.
1500 SELECTIONP non-zero means the string is being encoded for an X
1501 selection, so it is safe to run pre-write conversions (which
1502 may run Lisp code).
1504 Store the byte length of resulting text in *TEXT_BYTES.
1506 If the text contains only ASCII and Latin-1, store 1 in *STRING_P,
1507 which means that the `encoding' of the result can be `STRING'.
1508 Otherwise store 0 in *STRINGP, which means that the `encoding' of
1509 the result should be `COMPOUND_TEXT'. */
1511 unsigned char *
1512 x_encode_text (string, coding_system, selectionp, text_bytes, stringp)
1513 Lisp_Object string, coding_system;
1514 int *text_bytes, *stringp;
1515 int selectionp;
1517 unsigned char *str = SDATA (string);
1518 int chars = SCHARS (string);
1519 int bytes = SBYTES (string);
1520 int charset_info;
1521 int bufsize;
1522 unsigned char *buf;
1523 struct coding_system coding;
1524 extern Lisp_Object Qcompound_text_with_extensions;
1526 charset_info = find_charset_in_text (str, chars, bytes, NULL, Qnil);
1527 if (charset_info == 0)
1529 /* No multibyte character in OBJ. We need not encode it. */
1530 *text_bytes = bytes;
1531 *stringp = 1;
1532 return str;
1535 setup_coding_system (coding_system, &coding);
1536 if (selectionp
1537 && SYMBOLP (coding.pre_write_conversion)
1538 && !NILP (Ffboundp (coding.pre_write_conversion)))
1540 string = run_pre_post_conversion_on_str (string, &coding, 1);
1541 str = SDATA (string);
1542 chars = SCHARS (string);
1543 bytes = SBYTES (string);
1545 coding.src_multibyte = 1;
1546 coding.dst_multibyte = 0;
1547 coding.mode |= CODING_MODE_LAST_BLOCK;
1548 if (coding.type == coding_type_iso2022)
1549 coding.flags |= CODING_FLAG_ISO_SAFE;
1550 /* We suppress producing escape sequences for composition. */
1551 coding.composing = COMPOSITION_DISABLED;
1552 bufsize = encoding_buffer_size (&coding, bytes);
1553 buf = (unsigned char *) xmalloc (bufsize);
1554 encode_coding (&coding, str, buf, bytes, bufsize);
1555 *text_bytes = coding.produced;
1556 *stringp = (charset_info == 1
1557 || (!EQ (coding_system, Qcompound_text)
1558 && !EQ (coding_system, Qcompound_text_with_extensions)));
1559 return buf;
1563 /* Set the WM name to NAME for frame F. Also set the icon name.
1564 If the frame already has an icon name, use that, otherwise set the
1565 icon name to NAME. */
1567 static void
1568 x_set_name_internal (f, name)
1569 FRAME_PTR f;
1570 Lisp_Object name;
1572 if (FRAME_X_WINDOW (f))
1574 BLOCK_INPUT;
1575 #ifdef HAVE_X11R4
1577 XTextProperty text, icon;
1578 int bytes, stringp;
1579 int do_free_icon_value = 0, do_free_text_value = 0;
1580 Lisp_Object coding_system;
1582 coding_system = Qcompound_text;
1583 /* Note: Encoding strategy
1585 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1586 text.encoding. But, there are non-internationalized window
1587 managers which don't support that encoding. So, if NAME
1588 contains only ASCII and 8859-1 characters, encode it by
1589 iso-latin-1, and use "STRING" in text.encoding hoping that
1590 such window managers at least analyze this format correctly,
1591 i.e. treat 8-bit bytes as 8859-1 characters.
1593 We may also be able to use "UTF8_STRING" in text.encoding
1594 in the future which can encode all Unicode characters.
1595 But, for the moment, there's no way to know that the
1596 current window manager supports it or not. */
1597 text.value = x_encode_text (name, coding_system, 0, &bytes, &stringp);
1598 text.encoding = (stringp ? XA_STRING
1599 : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
1600 text.format = 8;
1601 text.nitems = bytes;
1603 /* Check early, because ENCODE_UTF_8 below may GC and name may be
1604 relocated. */
1605 do_free_text_value = text.value != SDATA (name);
1607 if (NILP (f->icon_name))
1609 icon = text;
1611 else
1613 /* See the above comment "Note: Encoding strategy". */
1614 icon.value = x_encode_text (f->icon_name, coding_system, 0,
1615 &bytes, &stringp);
1616 icon.encoding = (stringp ? XA_STRING
1617 : FRAME_X_DISPLAY_INFO (f)->Xatom_COMPOUND_TEXT);
1618 icon.format = 8;
1619 icon.nitems = bytes;
1620 do_free_icon_value = icon.value != SDATA (f->icon_name);
1623 #ifdef USE_GTK
1624 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
1625 SDATA (ENCODE_UTF_8 (name)));
1626 #else /* not USE_GTK */
1627 XSetWMName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &text);
1628 #endif /* not USE_GTK */
1630 XSetWMIconName (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &icon);
1632 if (do_free_icon_value)
1633 xfree (icon.value);
1634 if (do_free_text_value)
1635 xfree (text.value);
1637 #else /* not HAVE_X11R4 */
1638 XSetIconName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1639 SDATA (name));
1640 XStoreName (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
1641 SDATA (name));
1642 #endif /* not HAVE_X11R4 */
1643 UNBLOCK_INPUT;
1647 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1648 x_id_name.
1650 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1651 name; if NAME is a string, set F's name to NAME and set
1652 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1654 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1655 suggesting a new name, which lisp code should override; if
1656 F->explicit_name is set, ignore the new name; otherwise, set it. */
1658 void
1659 x_set_name (f, name, explicit)
1660 struct frame *f;
1661 Lisp_Object name;
1662 int explicit;
1664 /* Make sure that requests from lisp code override requests from
1665 Emacs redisplay code. */
1666 if (explicit)
1668 /* If we're switching from explicit to implicit, we had better
1669 update the mode lines and thereby update the title. */
1670 if (f->explicit_name && NILP (name))
1671 update_mode_lines = 1;
1673 f->explicit_name = ! NILP (name);
1675 else if (f->explicit_name)
1676 return;
1678 /* If NAME is nil, set the name to the x_id_name. */
1679 if (NILP (name))
1681 /* Check for no change needed in this very common case
1682 before we do any consing. */
1683 if (!strcmp (FRAME_X_DISPLAY_INFO (f)->x_id_name,
1684 SDATA (f->name)))
1685 return;
1686 name = build_string (FRAME_X_DISPLAY_INFO (f)->x_id_name);
1688 else
1689 CHECK_STRING (name);
1691 /* Don't change the name if it's already NAME. */
1692 if (! NILP (Fstring_equal (name, f->name)))
1693 return;
1695 f->name = name;
1697 /* For setting the frame title, the title parameter should override
1698 the name parameter. */
1699 if (! NILP (f->title))
1700 name = f->title;
1702 x_set_name_internal (f, name);
1705 /* This function should be called when the user's lisp code has
1706 specified a name for the frame; the name will override any set by the
1707 redisplay code. */
1708 void
1709 x_explicitly_set_name (f, arg, oldval)
1710 FRAME_PTR f;
1711 Lisp_Object arg, oldval;
1713 x_set_name (f, arg, 1);
1716 /* This function should be called by Emacs redisplay code to set the
1717 name; names set this way will never override names set by the user's
1718 lisp code. */
1719 void
1720 x_implicitly_set_name (f, arg, oldval)
1721 FRAME_PTR f;
1722 Lisp_Object arg, oldval;
1724 x_set_name (f, arg, 0);
1727 /* Change the title of frame F to NAME.
1728 If NAME is nil, use the frame name as the title.
1730 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1731 name; if NAME is a string, set F's name to NAME and set
1732 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1734 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1735 suggesting a new name, which lisp code should override; if
1736 F->explicit_name is set, ignore the new name; otherwise, set it. */
1738 void
1739 x_set_title (f, name, old_name)
1740 struct frame *f;
1741 Lisp_Object name, old_name;
1743 /* Don't change the title if it's already NAME. */
1744 if (EQ (name, f->title))
1745 return;
1747 update_mode_lines = 1;
1749 f->title = name;
1751 if (NILP (name))
1752 name = f->name;
1753 else
1754 CHECK_STRING (name);
1756 x_set_name_internal (f, name);
1759 void
1760 x_set_scroll_bar_default_width (f)
1761 struct frame *f;
1763 int wid = FRAME_COLUMN_WIDTH (f);
1765 #ifdef USE_TOOLKIT_SCROLL_BARS
1766 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1767 int width = 16 + 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM;
1768 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (width + wid - 1) / wid;
1769 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = width;
1770 #else
1771 /* Make the actual width at least 14 pixels and a multiple of a
1772 character width. */
1773 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (14 + wid - 1) / wid;
1775 /* Use all of that space (aside from required margins) for the
1776 scroll bar. */
1777 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = 0;
1778 #endif
1782 /* Record in frame F the specified or default value according to ALIST
1783 of the parameter named PROP (a Lisp symbol). If no value is
1784 specified for PROP, look for an X default for XPROP on the frame
1785 named NAME. If that is not found either, use the value DEFLT. */
1787 static Lisp_Object
1788 x_default_scroll_bar_color_parameter (f, alist, prop, xprop, xclass,
1789 foreground_p)
1790 struct frame *f;
1791 Lisp_Object alist;
1792 Lisp_Object prop;
1793 char *xprop;
1794 char *xclass;
1795 int foreground_p;
1797 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
1798 Lisp_Object tem;
1800 tem = x_get_arg (dpyinfo, alist, prop, xprop, xclass, RES_TYPE_STRING);
1801 if (EQ (tem, Qunbound))
1803 #ifdef USE_TOOLKIT_SCROLL_BARS
1805 /* See if an X resource for the scroll bar color has been
1806 specified. */
1807 tem = display_x_get_resource (dpyinfo,
1808 build_string (foreground_p
1809 ? "foreground"
1810 : "background"),
1811 empty_string,
1812 build_string ("verticalScrollBar"),
1813 empty_string);
1814 if (!STRINGP (tem))
1816 /* If nothing has been specified, scroll bars will use a
1817 toolkit-dependent default. Because these defaults are
1818 difficult to get at without actually creating a scroll
1819 bar, use nil to indicate that no color has been
1820 specified. */
1821 tem = Qnil;
1824 #else /* not USE_TOOLKIT_SCROLL_BARS */
1826 tem = Qnil;
1828 #endif /* not USE_TOOLKIT_SCROLL_BARS */
1831 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
1832 return tem;
1837 #if !defined (HAVE_X11R4) && !defined (HAVE_XSETWMPROTOCOLS)
1839 Status
1840 XSetWMProtocols (dpy, w, protocols, count)
1841 Display *dpy;
1842 Window w;
1843 Atom *protocols;
1844 int count;
1846 Atom prop;
1847 prop = XInternAtom (dpy, "WM_PROTOCOLS", False);
1848 if (prop == None) return False;
1849 XChangeProperty (dpy, w, prop, XA_ATOM, 32, PropModeReplace,
1850 (unsigned char *) protocols, count);
1851 return True;
1853 #endif /* not HAVE_X11R4 && not HAVE_XSETWMPROTOCOLS */
1855 #ifdef USE_X_TOOLKIT
1857 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
1858 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
1859 already be present because of the toolkit (Motif adds some of them,
1860 for example, but Xt doesn't). */
1862 static void
1863 hack_wm_protocols (f, widget)
1864 FRAME_PTR f;
1865 Widget widget;
1867 Display *dpy = XtDisplay (widget);
1868 Window w = XtWindow (widget);
1869 int need_delete = 1;
1870 int need_focus = 1;
1871 int need_save = 1;
1873 BLOCK_INPUT;
1875 Atom type, *atoms = 0;
1876 int format = 0;
1877 unsigned long nitems = 0;
1878 unsigned long bytes_after;
1880 if ((XGetWindowProperty (dpy, w,
1881 FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols,
1882 (long)0, (long)100, False, XA_ATOM,
1883 &type, &format, &nitems, &bytes_after,
1884 (unsigned char **) &atoms)
1885 == Success)
1886 && format == 32 && type == XA_ATOM)
1887 while (nitems > 0)
1889 nitems--;
1890 if (atoms[nitems] == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window)
1891 need_delete = 0;
1892 else if (atoms[nitems] == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_take_focus)
1893 need_focus = 0;
1894 else if (atoms[nitems] == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself)
1895 need_save = 0;
1897 if (atoms) XFree ((char *) atoms);
1900 Atom props [10];
1901 int count = 0;
1902 if (need_delete)
1903 props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window;
1904 if (need_focus)
1905 props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_take_focus;
1906 if (need_save)
1907 props[count++] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself;
1908 if (count)
1909 XChangeProperty (dpy, w, FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols,
1910 XA_ATOM, 32, PropModeAppend,
1911 (unsigned char *) props, count);
1913 UNBLOCK_INPUT;
1915 #endif
1919 /* Support routines for XIC (X Input Context). */
1921 #ifdef HAVE_X_I18N
1923 static XFontSet xic_create_xfontset P_ ((struct frame *, char *));
1924 static XIMStyle best_xim_style P_ ((XIMStyles *, XIMStyles *));
1927 /* Supported XIM styles, ordered by preference. */
1929 static XIMStyle supported_xim_styles[] =
1931 XIMPreeditPosition | XIMStatusArea,
1932 XIMPreeditPosition | XIMStatusNothing,
1933 XIMPreeditPosition | XIMStatusNone,
1934 XIMPreeditNothing | XIMStatusArea,
1935 XIMPreeditNothing | XIMStatusNothing,
1936 XIMPreeditNothing | XIMStatusNone,
1937 XIMPreeditNone | XIMStatusArea,
1938 XIMPreeditNone | XIMStatusNothing,
1939 XIMPreeditNone | XIMStatusNone,
1944 /* Create an X fontset on frame F with base font name BASE_FONTNAME. */
1946 static XFontSet
1947 xic_create_xfontset (f, base_fontname)
1948 struct frame *f;
1949 char *base_fontname;
1951 XFontSet xfs = NULL;
1952 char **missing_list = NULL;
1953 int missing_count;
1954 char *def_string;
1955 Lisp_Object rest, frame;
1957 /* See if there is another frame already using same fontset. */
1958 FOR_EACH_FRAME (rest, frame)
1960 struct frame *cf = XFRAME (frame);
1961 if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf)
1962 && FRAME_X_DISPLAY_INFO (cf) == FRAME_X_DISPLAY_INFO (f)
1963 && FRAME_XIC_BASE_FONTNAME (cf)
1964 && !strcmp (FRAME_XIC_BASE_FONTNAME (cf), base_fontname))
1966 xfs = FRAME_XIC_FONTSET (cf);
1967 break;
1971 if (!xfs)
1973 /* New fontset. */
1974 xfs = XCreateFontSet (FRAME_X_DISPLAY (f),
1975 base_fontname, &missing_list,
1976 &missing_count, &def_string);
1977 if (missing_list)
1978 XFreeStringList (missing_list);
1981 if (FRAME_XIC_BASE_FONTNAME (f))
1982 xfree (FRAME_XIC_BASE_FONTNAME (f));
1983 FRAME_XIC_BASE_FONTNAME (f) = xstrdup (base_fontname);
1985 /* No need to free def_string. */
1986 return xfs;
1989 /* Free the X fontset of frame F if it is the last frame using it. */
1991 void
1992 xic_free_xfontset (f)
1993 struct frame *f;
1995 Lisp_Object rest, frame;
1996 int shared_p = 0;
1998 if (!FRAME_XIC_FONTSET (f))
1999 return;
2001 /* See if there is another frame sharing the same fontset. */
2002 FOR_EACH_FRAME (rest, frame)
2004 struct frame *cf = XFRAME (frame);
2005 if (cf != f && FRAME_LIVE_P (f) && FRAME_X_P (cf)
2006 && FRAME_X_DISPLAY_INFO (cf) == FRAME_X_DISPLAY_INFO (f)
2007 && FRAME_XIC_FONTSET (cf) == FRAME_XIC_FONTSET (f))
2009 shared_p = 1;
2010 break;
2014 if (!shared_p)
2015 /* The fontset is not used anymore. It is safe to free it. */
2016 XFreeFontSet (FRAME_X_DISPLAY (f), FRAME_XIC_FONTSET (f));
2018 if (FRAME_XIC_BASE_FONTNAME (f))
2019 xfree (FRAME_XIC_BASE_FONTNAME (f));
2020 FRAME_XIC_BASE_FONTNAME (f) = NULL;
2021 FRAME_XIC_FONTSET (f) = NULL;
2025 /* Value is the best input style, given user preferences USER (already
2026 checked to be supported by Emacs), and styles supported by the
2027 input method XIM. */
2029 static XIMStyle
2030 best_xim_style (user, xim)
2031 XIMStyles *user;
2032 XIMStyles *xim;
2034 int i, j;
2036 for (i = 0; i < user->count_styles; ++i)
2037 for (j = 0; j < xim->count_styles; ++j)
2038 if (user->supported_styles[i] == xim->supported_styles[j])
2039 return user->supported_styles[i];
2041 /* Return the default style. */
2042 return XIMPreeditNothing | XIMStatusNothing;
2045 /* Create XIC for frame F. */
2047 static XIMStyle xic_style;
2049 void
2050 create_frame_xic (f)
2051 struct frame *f;
2053 XIM xim;
2054 XIC xic = NULL;
2055 XFontSet xfs = NULL;
2057 if (FRAME_XIC (f))
2058 return;
2060 xim = FRAME_X_XIM (f);
2061 if (xim)
2063 XRectangle s_area;
2064 XPoint spot;
2065 XVaNestedList preedit_attr;
2066 XVaNestedList status_attr;
2067 char *base_fontname;
2068 int fontset;
2070 s_area.x = 0; s_area.y = 0; s_area.width = 1; s_area.height = 1;
2071 spot.x = 0; spot.y = 1;
2072 /* Create X fontset. */
2073 fontset = FRAME_FONTSET (f);
2074 if (fontset < 0)
2075 base_fontname = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
2076 else
2078 /* Determine the base fontname from the ASCII font name of
2079 FONTSET. */
2080 char *ascii_font = (char *) SDATA (fontset_ascii (fontset));
2081 char *p = ascii_font;
2082 int i;
2084 for (i = 0; *p; p++)
2085 if (*p == '-') i++;
2086 if (i != 14)
2087 /* As the font name doesn't conform to XLFD, we can't
2088 modify it to get a suitable base fontname for the
2089 frame. */
2090 base_fontname = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
2091 else
2093 int len = strlen (ascii_font) + 1;
2094 char *p1 = NULL;
2096 for (i = 0, p = ascii_font; i < 8; p++)
2098 if (*p == '-')
2100 i++;
2101 if (i == 3)
2102 p1 = p + 1;
2105 base_fontname = (char *) alloca (len);
2106 bzero (base_fontname, len);
2107 strcpy (base_fontname, "-*-*-");
2108 bcopy (p1, base_fontname + 5, p - p1);
2109 strcat (base_fontname, "*-*-*-*-*-*-*");
2112 xfs = xic_create_xfontset (f, base_fontname);
2114 /* Determine XIC style. */
2115 if (xic_style == 0)
2117 XIMStyles supported_list;
2118 supported_list.count_styles = (sizeof supported_xim_styles
2119 / sizeof supported_xim_styles[0]);
2120 supported_list.supported_styles = supported_xim_styles;
2121 xic_style = best_xim_style (&supported_list,
2122 FRAME_X_XIM_STYLES (f));
2125 preedit_attr = XVaCreateNestedList (0,
2126 XNFontSet, xfs,
2127 XNForeground,
2128 FRAME_FOREGROUND_PIXEL (f),
2129 XNBackground,
2130 FRAME_BACKGROUND_PIXEL (f),
2131 (xic_style & XIMPreeditPosition
2132 ? XNSpotLocation
2133 : NULL),
2134 &spot,
2135 NULL);
2136 status_attr = XVaCreateNestedList (0,
2137 XNArea,
2138 &s_area,
2139 XNFontSet,
2140 xfs,
2141 XNForeground,
2142 FRAME_FOREGROUND_PIXEL (f),
2143 XNBackground,
2144 FRAME_BACKGROUND_PIXEL (f),
2145 NULL);
2147 xic = XCreateIC (xim,
2148 XNInputStyle, xic_style,
2149 XNClientWindow, FRAME_X_WINDOW (f),
2150 XNFocusWindow, FRAME_X_WINDOW (f),
2151 XNStatusAttributes, status_attr,
2152 XNPreeditAttributes, preedit_attr,
2153 NULL);
2154 XFree (preedit_attr);
2155 XFree (status_attr);
2158 FRAME_XIC (f) = xic;
2159 FRAME_XIC_STYLE (f) = xic_style;
2160 FRAME_XIC_FONTSET (f) = xfs;
2164 /* Destroy XIC and free XIC fontset of frame F, if any. */
2166 void
2167 free_frame_xic (f)
2168 struct frame *f;
2170 if (FRAME_XIC (f) == NULL)
2171 return;
2173 XDestroyIC (FRAME_XIC (f));
2174 xic_free_xfontset (f);
2176 FRAME_XIC (f) = NULL;
2180 /* Place preedit area for XIC of window W's frame to specified
2181 pixel position X/Y. X and Y are relative to window W. */
2183 void
2184 xic_set_preeditarea (w, x, y)
2185 struct window *w;
2186 int x, y;
2188 struct frame *f = XFRAME (w->frame);
2189 XVaNestedList attr;
2190 XPoint spot;
2192 spot.x = WINDOW_TO_FRAME_PIXEL_X (w, x) + WINDOW_LEFT_FRINGE_WIDTH (w);
2193 spot.y = WINDOW_TO_FRAME_PIXEL_Y (w, y) + FONT_BASE (FRAME_FONT (f));
2194 attr = XVaCreateNestedList (0, XNSpotLocation, &spot, NULL);
2195 XSetICValues (FRAME_XIC (f), XNPreeditAttributes, attr, NULL);
2196 XFree (attr);
2200 /* Place status area for XIC in bottom right corner of frame F.. */
2202 void
2203 xic_set_statusarea (f)
2204 struct frame *f;
2206 XIC xic = FRAME_XIC (f);
2207 XVaNestedList attr;
2208 XRectangle area;
2209 XRectangle *needed;
2211 /* Negotiate geometry of status area. If input method has existing
2212 status area, use its current size. */
2213 area.x = area.y = area.width = area.height = 0;
2214 attr = XVaCreateNestedList (0, XNAreaNeeded, &area, NULL);
2215 XSetICValues (xic, XNStatusAttributes, attr, NULL);
2216 XFree (attr);
2218 attr = XVaCreateNestedList (0, XNAreaNeeded, &needed, NULL);
2219 XGetICValues (xic, XNStatusAttributes, attr, NULL);
2220 XFree (attr);
2222 if (needed->width == 0) /* Use XNArea instead of XNAreaNeeded */
2224 attr = XVaCreateNestedList (0, XNArea, &needed, NULL);
2225 XGetICValues (xic, XNStatusAttributes, attr, NULL);
2226 XFree (attr);
2229 area.width = needed->width;
2230 area.height = needed->height;
2231 area.x = FRAME_PIXEL_WIDTH (f) - area.width - FRAME_INTERNAL_BORDER_WIDTH (f);
2232 area.y = (FRAME_PIXEL_HEIGHT (f) - area.height
2233 - FRAME_MENUBAR_HEIGHT (f)
2234 - FRAME_TOOLBAR_HEIGHT (f)
2235 - FRAME_INTERNAL_BORDER_WIDTH (f));
2236 XFree (needed);
2238 attr = XVaCreateNestedList (0, XNArea, &area, NULL);
2239 XSetICValues (xic, XNStatusAttributes, attr, NULL);
2240 XFree (attr);
2244 /* Set X fontset for XIC of frame F, using base font name
2245 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2247 void
2248 xic_set_xfontset (f, base_fontname)
2249 struct frame *f;
2250 char *base_fontname;
2252 XVaNestedList attr;
2253 XFontSet xfs;
2255 xic_free_xfontset (f);
2257 xfs = xic_create_xfontset (f, base_fontname);
2259 attr = XVaCreateNestedList (0, XNFontSet, xfs, NULL);
2260 if (FRAME_XIC_STYLE (f) & XIMPreeditPosition)
2261 XSetICValues (FRAME_XIC (f), XNPreeditAttributes, attr, NULL);
2262 if (FRAME_XIC_STYLE (f) & XIMStatusArea)
2263 XSetICValues (FRAME_XIC (f), XNStatusAttributes, attr, NULL);
2264 XFree (attr);
2266 FRAME_XIC_FONTSET (f) = xfs;
2269 #endif /* HAVE_X_I18N */
2273 #ifdef USE_X_TOOLKIT
2275 /* Create and set up the X widget for frame F. */
2277 static void
2278 x_window (f, window_prompting, minibuffer_only)
2279 struct frame *f;
2280 long window_prompting;
2281 int minibuffer_only;
2283 XClassHint class_hints;
2284 XSetWindowAttributes attributes;
2285 unsigned long attribute_mask;
2286 Widget shell_widget;
2287 Widget pane_widget;
2288 Widget frame_widget;
2289 Arg al [25];
2290 int ac;
2292 BLOCK_INPUT;
2294 /* Use the resource name as the top-level widget name
2295 for looking up resources. Make a non-Lisp copy
2296 for the window manager, so GC relocation won't bother it.
2298 Elsewhere we specify the window name for the window manager. */
2301 char *str = (char *) SDATA (Vx_resource_name);
2302 f->namebuf = (char *) xmalloc (strlen (str) + 1);
2303 strcpy (f->namebuf, str);
2306 ac = 0;
2307 XtSetArg (al[ac], XtNallowShellResize, 1); ac++;
2308 XtSetArg (al[ac], XtNinput, 1); ac++;
2309 XtSetArg (al[ac], XtNmappedWhenManaged, 0); ac++;
2310 XtSetArg (al[ac], XtNborderWidth, f->border_width); ac++;
2311 XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++;
2312 XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++;
2313 XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++;
2314 shell_widget = XtAppCreateShell (f->namebuf, EMACS_CLASS,
2315 applicationShellWidgetClass,
2316 FRAME_X_DISPLAY (f), al, ac);
2318 f->output_data.x->widget = shell_widget;
2319 /* maybe_set_screen_title_format (shell_widget); */
2321 pane_widget = lw_create_widget ("main", "pane", widget_id_tick++,
2322 (widget_value *) NULL,
2323 shell_widget, False,
2324 (lw_callback) NULL,
2325 (lw_callback) NULL,
2326 (lw_callback) NULL,
2327 (lw_callback) NULL);
2329 ac = 0;
2330 XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++;
2331 XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++;
2332 XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++;
2333 XtSetValues (pane_widget, al, ac);
2334 f->output_data.x->column_widget = pane_widget;
2336 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2337 the emacs screen when changing menubar. This reduces flickering. */
2339 ac = 0;
2340 XtSetArg (al[ac], XtNmappedWhenManaged, 0); ac++;
2341 XtSetArg (al[ac], XtNshowGrip, 0); ac++;
2342 XtSetArg (al[ac], XtNallowResize, 1); ac++;
2343 XtSetArg (al[ac], XtNresizeToPreferred, 1); ac++;
2344 XtSetArg (al[ac], XtNemacsFrame, f); ac++;
2345 XtSetArg (al[ac], XtNvisual, FRAME_X_VISUAL (f)); ac++;
2346 XtSetArg (al[ac], XtNdepth, FRAME_X_DISPLAY_INFO (f)->n_planes); ac++;
2347 XtSetArg (al[ac], XtNcolormap, FRAME_X_COLORMAP (f)); ac++;
2348 frame_widget = XtCreateWidget (f->namebuf, emacsFrameClass, pane_widget,
2349 al, ac);
2351 f->output_data.x->edit_widget = frame_widget;
2353 XtManageChild (frame_widget);
2355 /* Do some needed geometry management. */
2357 int len;
2358 char *tem, shell_position[32];
2359 Arg al[10];
2360 int ac = 0;
2361 int extra_borders = 0;
2362 int menubar_size
2363 = (f->output_data.x->menubar_widget
2364 ? (f->output_data.x->menubar_widget->core.height
2365 + f->output_data.x->menubar_widget->core.border_width)
2366 : 0);
2368 #if 0 /* Experimentally, we now get the right results
2369 for -geometry -0-0 without this. 24 Aug 96, rms. */
2370 if (FRAME_EXTERNAL_MENU_BAR (f))
2372 Dimension ibw = 0;
2373 XtVaGetValues (pane_widget, XtNinternalBorderWidth, &ibw, NULL);
2374 menubar_size += ibw;
2376 #endif
2378 f->output_data.x->menubar_height = menubar_size;
2380 #ifndef USE_LUCID
2381 /* Motif seems to need this amount added to the sizes
2382 specified for the shell widget. The Athena/Lucid widgets don't.
2383 Both conclusions reached experimentally. -- rms. */
2384 XtVaGetValues (f->output_data.x->edit_widget, XtNinternalBorderWidth,
2385 &extra_borders, NULL);
2386 extra_borders *= 2;
2387 #endif
2389 /* Convert our geometry parameters into a geometry string
2390 and specify it.
2391 Note that we do not specify here whether the position
2392 is a user-specified or program-specified one.
2393 We pass that information later, in x_wm_set_size_hints. */
2395 int left = f->left_pos;
2396 int xneg = window_prompting & XNegative;
2397 int top = f->top_pos;
2398 int yneg = window_prompting & YNegative;
2399 if (xneg)
2400 left = -left;
2401 if (yneg)
2402 top = -top;
2404 if (window_prompting & USPosition)
2405 sprintf (shell_position, "=%dx%d%c%d%c%d",
2406 FRAME_PIXEL_WIDTH (f) + extra_borders,
2407 FRAME_PIXEL_HEIGHT (f) + menubar_size + extra_borders,
2408 (xneg ? '-' : '+'), left,
2409 (yneg ? '-' : '+'), top);
2410 else
2412 sprintf (shell_position, "=%dx%d",
2413 FRAME_PIXEL_WIDTH (f) + extra_borders,
2414 FRAME_PIXEL_HEIGHT (f) + menubar_size + extra_borders);
2416 /* Setting x and y when the position is not specified in
2417 the geometry string will set program position in the WM hints.
2418 If Emacs had just one program position, we could set it in
2419 fallback resources, but since each make-frame call can specify
2420 different program positions, this is easier. */
2421 XtSetArg (al[ac], XtNx, left); ac++;
2422 XtSetArg (al[ac], XtNy, top); ac++;
2426 len = strlen (shell_position) + 1;
2427 /* We don't free this because we don't know whether
2428 it is safe to free it while the frame exists.
2429 It isn't worth the trouble of arranging to free it
2430 when the frame is deleted. */
2431 tem = (char *) xmalloc (len);
2432 strncpy (tem, shell_position, len);
2433 XtSetArg (al[ac], XtNgeometry, tem); ac++;
2434 XtSetValues (shell_widget, al, ac);
2437 XtManageChild (pane_widget);
2438 XtRealizeWidget (shell_widget);
2440 FRAME_X_WINDOW (f) = XtWindow (frame_widget);
2442 validate_x_resource_name ();
2444 class_hints.res_name = (char *) SDATA (Vx_resource_name);
2445 class_hints.res_class = (char *) SDATA (Vx_resource_class);
2446 XSetClassHint (FRAME_X_DISPLAY (f), XtWindow (shell_widget), &class_hints);
2448 #ifdef HAVE_X_I18N
2449 FRAME_XIC (f) = NULL;
2450 if (use_xim)
2451 create_frame_xic (f);
2452 #endif
2454 f->output_data.x->wm_hints.input = True;
2455 f->output_data.x->wm_hints.flags |= InputHint;
2456 XSetWMHints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2457 &f->output_data.x->wm_hints);
2459 hack_wm_protocols (f, shell_widget);
2461 #ifdef HACK_EDITRES
2462 XtAddEventHandler (shell_widget, 0, True, _XEditResCheckMessages, 0);
2463 #endif
2465 /* Do a stupid property change to force the server to generate a
2466 PropertyNotify event so that the event_stream server timestamp will
2467 be initialized to something relevant to the time we created the window.
2469 XChangeProperty (XtDisplay (frame_widget), XtWindow (frame_widget),
2470 FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols,
2471 XA_ATOM, 32, PropModeAppend,
2472 (unsigned char*) NULL, 0);
2474 /* Make all the standard events reach the Emacs frame. */
2475 attributes.event_mask = STANDARD_EVENT_SET;
2477 #ifdef HAVE_X_I18N
2478 if (FRAME_XIC (f))
2480 /* XIM server might require some X events. */
2481 unsigned long fevent = NoEventMask;
2482 XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL);
2483 attributes.event_mask |= fevent;
2485 #endif /* HAVE_X_I18N */
2487 attribute_mask = CWEventMask;
2488 XChangeWindowAttributes (XtDisplay (shell_widget), XtWindow (shell_widget),
2489 attribute_mask, &attributes);
2491 XtMapWidget (frame_widget);
2493 /* x_set_name normally ignores requests to set the name if the
2494 requested name is the same as the current name. This is the one
2495 place where that assumption isn't correct; f->name is set, but
2496 the X server hasn't been told. */
2498 Lisp_Object name;
2499 int explicit = f->explicit_name;
2501 f->explicit_name = 0;
2502 name = f->name;
2503 f->name = Qnil;
2504 x_set_name (f, name, explicit);
2507 XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2508 f->output_data.x->text_cursor);
2510 UNBLOCK_INPUT;
2512 /* This is a no-op, except under Motif. Make sure main areas are
2513 set to something reasonable, in case we get an error later. */
2514 lw_set_main_areas (pane_widget, 0, frame_widget);
2517 #else /* not USE_X_TOOLKIT */
2518 #ifdef USE_GTK
2519 void
2520 x_window (f)
2521 FRAME_PTR f;
2523 if (! xg_create_frame_widgets (f))
2524 error ("Unable to create window");
2526 #ifdef HAVE_X_I18N
2527 FRAME_XIC (f) = NULL;
2528 if (use_xim)
2530 BLOCK_INPUT;
2531 create_frame_xic (f);
2532 if (FRAME_XIC (f))
2534 /* XIM server might require some X events. */
2535 unsigned long fevent = NoEventMask;
2536 XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL);
2538 if (fevent != NoEventMask)
2540 XSetWindowAttributes attributes;
2541 XWindowAttributes wattr;
2542 unsigned long attribute_mask;
2544 XGetWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2545 &wattr);
2546 attributes.event_mask = wattr.your_event_mask | fevent;
2547 attribute_mask = CWEventMask;
2548 XChangeWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2549 attribute_mask, &attributes);
2552 UNBLOCK_INPUT;
2554 #endif
2557 #else /*! USE_GTK */
2558 /* Create and set up the X window for frame F. */
2560 void
2561 x_window (f)
2562 struct frame *f;
2565 XClassHint class_hints;
2566 XSetWindowAttributes attributes;
2567 unsigned long attribute_mask;
2569 attributes.background_pixel = f->output_data.x->background_pixel;
2570 attributes.border_pixel = f->output_data.x->border_pixel;
2571 attributes.bit_gravity = StaticGravity;
2572 attributes.backing_store = NotUseful;
2573 attributes.save_under = True;
2574 attributes.event_mask = STANDARD_EVENT_SET;
2575 attributes.colormap = FRAME_X_COLORMAP (f);
2576 attribute_mask = (CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask
2577 | CWColormap);
2579 BLOCK_INPUT;
2580 FRAME_X_WINDOW (f)
2581 = XCreateWindow (FRAME_X_DISPLAY (f),
2582 f->output_data.x->parent_desc,
2583 f->left_pos,
2584 f->top_pos,
2585 FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f),
2586 f->border_width,
2587 CopyFromParent, /* depth */
2588 InputOutput, /* class */
2589 FRAME_X_VISUAL (f),
2590 attribute_mask, &attributes);
2592 #ifdef HAVE_X_I18N
2593 if (use_xim)
2595 create_frame_xic (f);
2596 if (FRAME_XIC (f))
2598 /* XIM server might require some X events. */
2599 unsigned long fevent = NoEventMask;
2600 XGetICValues (FRAME_XIC (f), XNFilterEvents, &fevent, NULL);
2601 attributes.event_mask |= fevent;
2602 attribute_mask = CWEventMask;
2603 XChangeWindowAttributes (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2604 attribute_mask, &attributes);
2607 #endif /* HAVE_X_I18N */
2609 validate_x_resource_name ();
2611 class_hints.res_name = (char *) SDATA (Vx_resource_name);
2612 class_hints.res_class = (char *) SDATA (Vx_resource_class);
2613 XSetClassHint (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), &class_hints);
2615 /* The menubar is part of the ordinary display;
2616 it does not count in addition to the height of the window. */
2617 f->output_data.x->menubar_height = 0;
2619 /* This indicates that we use the "Passive Input" input model.
2620 Unless we do this, we don't get the Focus{In,Out} events that we
2621 need to draw the cursor correctly. Accursed bureaucrats.
2622 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2624 f->output_data.x->wm_hints.input = True;
2625 f->output_data.x->wm_hints.flags |= InputHint;
2626 XSetWMHints (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2627 &f->output_data.x->wm_hints);
2628 f->output_data.x->wm_hints.icon_pixmap = None;
2630 /* Request "save yourself" and "delete window" commands from wm. */
2632 Atom protocols[2];
2633 protocols[0] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window;
2634 protocols[1] = FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself;
2635 XSetWMProtocols (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), protocols, 2);
2638 /* x_set_name normally ignores requests to set the name if the
2639 requested name is the same as the current name. This is the one
2640 place where that assumption isn't correct; f->name is set, but
2641 the X server hasn't been told. */
2643 Lisp_Object name;
2644 int explicit = f->explicit_name;
2646 f->explicit_name = 0;
2647 name = f->name;
2648 f->name = Qnil;
2649 x_set_name (f, name, explicit);
2652 XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2653 f->output_data.x->text_cursor);
2655 UNBLOCK_INPUT;
2657 if (FRAME_X_WINDOW (f) == 0)
2658 error ("Unable to create window");
2661 #endif /* not USE_GTK */
2662 #endif /* not USE_X_TOOLKIT */
2664 /* Verify that the icon position args for this window are valid. */
2666 static void
2667 x_icon_verify (f, parms)
2668 struct frame *f;
2669 Lisp_Object parms;
2671 Lisp_Object icon_x, icon_y;
2673 /* Set the position of the icon. Note that twm groups all
2674 icons in an icon window. */
2675 icon_x = x_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
2676 icon_y = x_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER);
2677 if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
2679 CHECK_NUMBER (icon_x);
2680 CHECK_NUMBER (icon_y);
2682 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
2683 error ("Both left and top icon corners of icon must be specified");
2686 /* Handle the icon stuff for this window. Perhaps later we might
2687 want an x_set_icon_position which can be called interactively as
2688 well. */
2690 static void
2691 x_icon (f, parms)
2692 struct frame *f;
2693 Lisp_Object parms;
2695 Lisp_Object icon_x, icon_y;
2696 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
2698 /* Set the position of the icon. Note that twm groups all
2699 icons in an icon window. */
2700 icon_x = x_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
2701 icon_y = x_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER);
2702 if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
2704 CHECK_NUMBER (icon_x);
2705 CHECK_NUMBER (icon_y);
2707 else if (!EQ (icon_x, Qunbound) || !EQ (icon_y, Qunbound))
2708 error ("Both left and top icon corners of icon must be specified");
2710 BLOCK_INPUT;
2712 if (! EQ (icon_x, Qunbound))
2713 x_wm_set_icon_position (f, XINT (icon_x), XINT (icon_y));
2715 /* Start up iconic or window? */
2716 x_wm_set_window_state
2717 (f, (EQ (x_get_arg (dpyinfo, parms, Qvisibility, 0, 0, RES_TYPE_SYMBOL),
2718 Qicon)
2719 ? IconicState
2720 : NormalState));
2722 x_text_icon (f, (char *) SDATA ((!NILP (f->icon_name)
2723 ? f->icon_name
2724 : f->name)));
2726 UNBLOCK_INPUT;
2729 /* Make the GCs needed for this window, setting the
2730 background, border and mouse colors; also create the
2731 mouse cursor and the gray border tile. */
2733 static char cursor_bits[] =
2735 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2736 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2737 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2738 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2741 static void
2742 x_make_gc (f)
2743 struct frame *f;
2745 XGCValues gc_values;
2747 BLOCK_INPUT;
2749 /* Create the GCs of this frame.
2750 Note that many default values are used. */
2752 /* Normal video */
2753 gc_values.font = FRAME_FONT (f)->fid;
2754 gc_values.foreground = f->output_data.x->foreground_pixel;
2755 gc_values.background = f->output_data.x->background_pixel;
2756 gc_values.line_width = 0; /* Means 1 using fast algorithm. */
2757 f->output_data.x->normal_gc
2758 = XCreateGC (FRAME_X_DISPLAY (f),
2759 FRAME_X_WINDOW (f),
2760 GCLineWidth | GCFont | GCForeground | GCBackground,
2761 &gc_values);
2763 /* Reverse video style. */
2764 gc_values.foreground = f->output_data.x->background_pixel;
2765 gc_values.background = f->output_data.x->foreground_pixel;
2766 f->output_data.x->reverse_gc
2767 = XCreateGC (FRAME_X_DISPLAY (f),
2768 FRAME_X_WINDOW (f),
2769 GCFont | GCForeground | GCBackground | GCLineWidth,
2770 &gc_values);
2772 /* Cursor has cursor-color background, background-color foreground. */
2773 gc_values.foreground = f->output_data.x->background_pixel;
2774 gc_values.background = f->output_data.x->cursor_pixel;
2775 gc_values.fill_style = FillOpaqueStippled;
2776 gc_values.stipple
2777 = XCreateBitmapFromData (FRAME_X_DISPLAY (f),
2778 FRAME_X_DISPLAY_INFO (f)->root_window,
2779 cursor_bits, 16, 16);
2780 f->output_data.x->cursor_gc
2781 = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
2782 (GCFont | GCForeground | GCBackground
2783 | GCFillStyle /* | GCStipple */ | GCLineWidth),
2784 &gc_values);
2786 /* Reliefs. */
2787 f->output_data.x->white_relief.gc = 0;
2788 f->output_data.x->black_relief.gc = 0;
2790 /* Create the gray border tile used when the pointer is not in
2791 the frame. Since this depends on the frame's pixel values,
2792 this must be done on a per-frame basis. */
2793 f->output_data.x->border_tile
2794 = (XCreatePixmapFromBitmapData
2795 (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
2796 gray_bits, gray_width, gray_height,
2797 f->output_data.x->foreground_pixel,
2798 f->output_data.x->background_pixel,
2799 DefaultDepth (FRAME_X_DISPLAY (f), FRAME_X_SCREEN_NUMBER (f))));
2801 UNBLOCK_INPUT;
2805 /* Free what was was allocated in x_make_gc. */
2807 void
2808 x_free_gcs (f)
2809 struct frame *f;
2811 Display *dpy = FRAME_X_DISPLAY (f);
2813 BLOCK_INPUT;
2815 if (f->output_data.x->normal_gc)
2817 XFreeGC (dpy, f->output_data.x->normal_gc);
2818 f->output_data.x->normal_gc = 0;
2821 if (f->output_data.x->reverse_gc)
2823 XFreeGC (dpy, f->output_data.x->reverse_gc);
2824 f->output_data.x->reverse_gc = 0;
2827 if (f->output_data.x->cursor_gc)
2829 XFreeGC (dpy, f->output_data.x->cursor_gc);
2830 f->output_data.x->cursor_gc = 0;
2833 if (f->output_data.x->border_tile)
2835 XFreePixmap (dpy, f->output_data.x->border_tile);
2836 f->output_data.x->border_tile = 0;
2839 UNBLOCK_INPUT;
2843 /* Handler for signals raised during x_create_frame and
2844 x_create_top_frame. FRAME is the frame which is partially
2845 constructed. */
2847 static Lisp_Object
2848 unwind_create_frame (frame)
2849 Lisp_Object frame;
2851 struct frame *f = XFRAME (frame);
2853 /* If frame is ``official'', nothing to do. */
2854 if (!CONSP (Vframe_list) || !EQ (XCAR (Vframe_list), frame))
2856 #if GLYPH_DEBUG
2857 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
2858 #endif
2860 x_free_frame_resources (f);
2862 /* Check that reference counts are indeed correct. */
2863 xassert (dpyinfo->reference_count == dpyinfo_refcount);
2864 xassert (dpyinfo->image_cache->refcount == image_cache_refcount);
2865 return Qt;
2868 return Qnil;
2872 DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
2873 1, 1, 0,
2874 doc: /* Make a new X window, which is called a "frame" in Emacs terms.
2875 Returns an Emacs frame object.
2876 ALIST is an alist of frame parameters.
2877 If the parameters specify that the frame should not have a minibuffer,
2878 and do not specify a specific minibuffer window to use,
2879 then `default-minibuffer-frame' must be a frame whose minibuffer can
2880 be shared by the new frame.
2882 This function is an internal primitive--use `make-frame' instead. */)
2883 (parms)
2884 Lisp_Object parms;
2886 struct frame *f;
2887 Lisp_Object frame, tem;
2888 Lisp_Object name;
2889 int minibuffer_only = 0;
2890 long window_prompting = 0;
2891 int width, height;
2892 int count = SPECPDL_INDEX ();
2893 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
2894 Lisp_Object display;
2895 struct x_display_info *dpyinfo = NULL;
2896 Lisp_Object parent;
2897 struct kboard *kb;
2899 check_x ();
2901 /* Use this general default value to start with
2902 until we know if this frame has a specified name. */
2903 Vx_resource_name = Vinvocation_name;
2905 display = x_get_arg (dpyinfo, parms, Qdisplay, 0, 0, RES_TYPE_STRING);
2906 if (EQ (display, Qunbound))
2907 display = Qnil;
2908 dpyinfo = check_x_display_info (display);
2909 #ifdef MULTI_KBOARD
2910 kb = dpyinfo->kboard;
2911 #else
2912 kb = &the_only_kboard;
2913 #endif
2915 name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING);
2916 if (!STRINGP (name)
2917 && ! EQ (name, Qunbound)
2918 && ! NILP (name))
2919 error ("Invalid frame name--not a string or nil");
2921 if (STRINGP (name))
2922 Vx_resource_name = name;
2924 /* See if parent window is specified. */
2925 parent = x_get_arg (dpyinfo, parms, Qparent_id, NULL, NULL, RES_TYPE_NUMBER);
2926 if (EQ (parent, Qunbound))
2927 parent = Qnil;
2928 if (! NILP (parent))
2929 CHECK_NUMBER (parent);
2931 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
2932 /* No need to protect DISPLAY because that's not used after passing
2933 it to make_frame_without_minibuffer. */
2934 frame = Qnil;
2935 GCPRO4 (parms, parent, name, frame);
2936 tem = x_get_arg (dpyinfo, parms, Qminibuffer, "minibuffer", "Minibuffer",
2937 RES_TYPE_SYMBOL);
2938 if (EQ (tem, Qnone) || NILP (tem))
2939 f = make_frame_without_minibuffer (Qnil, kb, display);
2940 else if (EQ (tem, Qonly))
2942 f = make_minibuffer_frame ();
2943 minibuffer_only = 1;
2945 else if (WINDOWP (tem))
2946 f = make_frame_without_minibuffer (tem, kb, display);
2947 else
2948 f = make_frame (1);
2950 XSETFRAME (frame, f);
2952 /* Note that X Windows does support scroll bars. */
2953 FRAME_CAN_HAVE_SCROLL_BARS (f) = 1;
2955 f->output_method = output_x_window;
2956 f->output_data.x = (struct x_output *) xmalloc (sizeof (struct x_output));
2957 bzero (f->output_data.x, sizeof (struct x_output));
2958 f->output_data.x->icon_bitmap = -1;
2959 FRAME_FONTSET (f) = -1;
2960 f->output_data.x->scroll_bar_foreground_pixel = -1;
2961 f->output_data.x->scroll_bar_background_pixel = -1;
2962 #ifdef USE_TOOLKIT_SCROLL_BARS
2963 f->output_data.x->scroll_bar_top_shadow_pixel = -1;
2964 f->output_data.x->scroll_bar_bottom_shadow_pixel = -1;
2965 #endif /* USE_TOOLKIT_SCROLL_BARS */
2966 record_unwind_protect (unwind_create_frame, frame);
2968 f->icon_name
2969 = x_get_arg (dpyinfo, parms, Qicon_name, "iconName", "Title",
2970 RES_TYPE_STRING);
2971 if (! STRINGP (f->icon_name))
2972 f->icon_name = Qnil;
2974 FRAME_X_DISPLAY_INFO (f) = dpyinfo;
2975 #if GLYPH_DEBUG
2976 image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount;
2977 dpyinfo_refcount = dpyinfo->reference_count;
2978 #endif /* GLYPH_DEBUG */
2979 #ifdef MULTI_KBOARD
2980 FRAME_KBOARD (f) = kb;
2981 #endif
2983 /* These colors will be set anyway later, but it's important
2984 to get the color reference counts right, so initialize them! */
2986 Lisp_Object black;
2987 struct gcpro gcpro1;
2989 /* Function x_decode_color can signal an error. Make
2990 sure to initialize color slots so that we won't try
2991 to free colors we haven't allocated. */
2992 f->output_data.x->foreground_pixel = -1;
2993 f->output_data.x->background_pixel = -1;
2994 f->output_data.x->cursor_pixel = -1;
2995 f->output_data.x->cursor_foreground_pixel = -1;
2996 f->output_data.x->border_pixel = -1;
2997 f->output_data.x->mouse_pixel = -1;
2999 black = build_string ("black");
3000 GCPRO1 (black);
3001 f->output_data.x->foreground_pixel
3002 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
3003 f->output_data.x->background_pixel
3004 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
3005 f->output_data.x->cursor_pixel
3006 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
3007 f->output_data.x->cursor_foreground_pixel
3008 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
3009 f->output_data.x->border_pixel
3010 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
3011 f->output_data.x->mouse_pixel
3012 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
3013 UNGCPRO;
3016 /* Specify the parent under which to make this X window. */
3018 if (!NILP (parent))
3020 f->output_data.x->parent_desc = (Window) XFASTINT (parent);
3021 f->output_data.x->explicit_parent = 1;
3023 else
3025 f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
3026 f->output_data.x->explicit_parent = 0;
3029 /* Set the name; the functions to which we pass f expect the name to
3030 be set. */
3031 if (EQ (name, Qunbound) || NILP (name))
3033 f->name = build_string (dpyinfo->x_id_name);
3034 f->explicit_name = 0;
3036 else
3038 f->name = name;
3039 f->explicit_name = 1;
3040 /* use the frame's title when getting resources for this frame. */
3041 specbind (Qx_resource_name, name);
3044 /* Extract the window parameters from the supplied values
3045 that are needed to determine window geometry. */
3047 Lisp_Object font;
3049 font = x_get_arg (dpyinfo, parms, Qfont, "font", "Font", RES_TYPE_STRING);
3051 BLOCK_INPUT;
3052 /* First, try whatever font the caller has specified. */
3053 if (STRINGP (font))
3055 tem = Fquery_fontset (font, Qnil);
3056 if (STRINGP (tem))
3057 font = x_new_fontset (f, SDATA (tem));
3058 else
3059 font = x_new_font (f, SDATA (font));
3062 /* Try out a font which we hope has bold and italic variations. */
3063 if (!STRINGP (font))
3064 font = x_new_font (f, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
3065 if (!STRINGP (font))
3066 font = x_new_font (f, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3067 if (! STRINGP (font))
3068 font = x_new_font (f, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3069 if (! STRINGP (font))
3070 /* This was formerly the first thing tried, but it finds too many fonts
3071 and takes too long. */
3072 font = x_new_font (f, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
3073 /* If those didn't work, look for something which will at least work. */
3074 if (! STRINGP (font))
3075 font = x_new_font (f, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
3076 UNBLOCK_INPUT;
3077 if (! STRINGP (font))
3078 font = build_string ("fixed");
3080 x_default_parameter (f, parms, Qfont, font,
3081 "font", "Font", RES_TYPE_STRING);
3084 #ifdef USE_LUCID
3085 /* Prevent lwlib/xlwmenu.c from crashing because of a bug
3086 whereby it fails to get any font. */
3087 xlwmenu_default_font = FRAME_FONT (f);
3088 #endif
3090 x_default_parameter (f, parms, Qborder_width, make_number (2),
3091 "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
3093 /* This defaults to 1 in order to match xterm. We recognize either
3094 internalBorderWidth or internalBorder (which is what xterm calls
3095 it). */
3096 if (NILP (Fassq (Qinternal_border_width, parms)))
3098 Lisp_Object value;
3100 value = x_get_arg (dpyinfo, parms, Qinternal_border_width,
3101 "internalBorder", "internalBorder", RES_TYPE_NUMBER);
3102 if (! EQ (value, Qunbound))
3103 parms = Fcons (Fcons (Qinternal_border_width, value),
3104 parms);
3106 x_default_parameter (f, parms, Qinternal_border_width, make_number (1),
3107 "internalBorderWidth", "internalBorderWidth",
3108 RES_TYPE_NUMBER);
3109 x_default_parameter (f, parms, Qvertical_scroll_bars, Qleft,
3110 "verticalScrollBars", "ScrollBars",
3111 RES_TYPE_SYMBOL);
3113 /* Also do the stuff which must be set before the window exists. */
3114 x_default_parameter (f, parms, Qforeground_color, build_string ("black"),
3115 "foreground", "Foreground", RES_TYPE_STRING);
3116 x_default_parameter (f, parms, Qbackground_color, build_string ("white"),
3117 "background", "Background", RES_TYPE_STRING);
3118 x_default_parameter (f, parms, Qmouse_color, build_string ("black"),
3119 "pointerColor", "Foreground", RES_TYPE_STRING);
3120 x_default_parameter (f, parms, Qcursor_color, build_string ("black"),
3121 "cursorColor", "Foreground", RES_TYPE_STRING);
3122 x_default_parameter (f, parms, Qborder_color, build_string ("black"),
3123 "borderColor", "BorderColor", RES_TYPE_STRING);
3124 x_default_parameter (f, parms, Qscreen_gamma, Qnil,
3125 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT);
3126 x_default_parameter (f, parms, Qline_spacing, Qnil,
3127 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
3128 x_default_parameter (f, parms, Qleft_fringe, Qnil,
3129 "leftFringe", "LeftFringe", RES_TYPE_NUMBER);
3130 x_default_parameter (f, parms, Qright_fringe, Qnil,
3131 "rightFringe", "RightFringe", RES_TYPE_NUMBER);
3133 x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_foreground,
3134 "scrollBarForeground",
3135 "ScrollBarForeground", 1);
3136 x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_background,
3137 "scrollBarBackground",
3138 "ScrollBarBackground", 0);
3140 /* Init faces before x_default_parameter is called for scroll-bar
3141 parameters because that function calls x_set_scroll_bar_width,
3142 which calls change_frame_size, which calls Fset_window_buffer,
3143 which runs hooks, which call Fvertical_motion. At the end, we
3144 end up in init_iterator with a null face cache, which should not
3145 happen. */
3146 init_frame_faces (f);
3148 x_default_parameter (f, parms, Qmenu_bar_lines, make_number (1),
3149 "menuBar", "MenuBar", RES_TYPE_NUMBER);
3150 x_default_parameter (f, parms, Qtool_bar_lines, make_number (1),
3151 "toolBar", "ToolBar", RES_TYPE_NUMBER);
3152 x_default_parameter (f, parms, Qbuffer_predicate, Qnil,
3153 "bufferPredicate", "BufferPredicate",
3154 RES_TYPE_SYMBOL);
3155 x_default_parameter (f, parms, Qtitle, Qnil,
3156 "title", "Title", RES_TYPE_STRING);
3157 x_default_parameter (f, parms, Qwait_for_wm, Qt,
3158 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN);
3159 x_default_parameter (f, parms, Qfullscreen, Qnil,
3160 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL);
3162 f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
3164 /* Compute the size of the X window. */
3165 window_prompting = x_figure_window_size (f, parms, 1);
3167 tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
3168 f->no_split = minibuffer_only || EQ (tem, Qt);
3170 x_icon_verify (f, parms);
3172 /* Create the X widget or window. */
3173 #ifdef USE_X_TOOLKIT
3174 x_window (f, window_prompting, minibuffer_only);
3175 #else
3176 x_window (f);
3177 #endif
3179 x_icon (f, parms);
3180 x_make_gc (f);
3182 /* Now consider the frame official. */
3183 FRAME_X_DISPLAY_INFO (f)->reference_count++;
3184 Vframe_list = Fcons (frame, Vframe_list);
3186 /* We need to do this after creating the X window, so that the
3187 icon-creation functions can say whose icon they're describing. */
3188 x_default_parameter (f, parms, Qicon_type, Qnil,
3189 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL);
3191 x_default_parameter (f, parms, Qauto_raise, Qnil,
3192 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
3193 x_default_parameter (f, parms, Qauto_lower, Qnil,
3194 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
3195 x_default_parameter (f, parms, Qcursor_type, Qbox,
3196 "cursorType", "CursorType", RES_TYPE_SYMBOL);
3197 x_default_parameter (f, parms, Qscroll_bar_width, Qnil,
3198 "scrollBarWidth", "ScrollBarWidth",
3199 RES_TYPE_NUMBER);
3201 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
3202 Change will not be effected unless different from the current
3203 FRAME_LINES (f). */
3204 width = FRAME_COLS (f);
3205 height = FRAME_LINES (f);
3207 SET_FRAME_COLS (f, 0);
3208 FRAME_LINES (f) = 0;
3209 change_frame_size (f, height, width, 1, 0, 0);
3211 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3212 /* Create the menu bar. */
3213 if (!minibuffer_only && FRAME_EXTERNAL_MENU_BAR (f))
3215 /* If this signals an error, we haven't set size hints for the
3216 frame and we didn't make it visible. */
3217 initialize_frame_menubar (f);
3219 #ifndef USE_GTK
3220 /* This is a no-op, except under Motif where it arranges the
3221 main window for the widgets on it. */
3222 lw_set_main_areas (f->output_data.x->column_widget,
3223 f->output_data.x->menubar_widget,
3224 f->output_data.x->edit_widget);
3225 #endif /* not USE_GTK */
3227 #endif /* USE_X_TOOLKIT || USE_GTK */
3229 /* Tell the server what size and position, etc, we want, and how
3230 badly we want them. This should be done after we have the menu
3231 bar so that its size can be taken into account. */
3232 BLOCK_INPUT;
3233 x_wm_set_size_hint (f, window_prompting, 0);
3234 UNBLOCK_INPUT;
3236 /* Make the window appear on the frame and enable display, unless
3237 the caller says not to. However, with explicit parent, Emacs
3238 cannot control visibility, so don't try. */
3239 if (! f->output_data.x->explicit_parent)
3241 Lisp_Object visibility;
3243 visibility = x_get_arg (dpyinfo, parms, Qvisibility, 0, 0,
3244 RES_TYPE_SYMBOL);
3245 if (EQ (visibility, Qunbound))
3246 visibility = Qt;
3248 if (EQ (visibility, Qicon))
3249 x_iconify_frame (f);
3250 else if (! NILP (visibility))
3251 x_make_frame_visible (f);
3252 else
3253 /* Must have been Qnil. */
3257 /* Set the WM leader property. GTK does this itself, so this is not
3258 needed when using GTK. */
3259 if (dpyinfo->client_leader_window != 0)
3261 BLOCK_INPUT;
3262 XChangeProperty (FRAME_X_DISPLAY (f),
3263 FRAME_OUTER_WINDOW (f),
3264 dpyinfo->Xatom_wm_client_leader,
3265 XA_WINDOW, 32, PropModeReplace,
3266 (char *) &dpyinfo->client_leader_window, 1);
3267 UNBLOCK_INPUT;
3270 UNGCPRO;
3272 /* Make sure windows on this frame appear in calls to next-window
3273 and similar functions. */
3274 Vwindow_list = Qnil;
3276 return unbind_to (count, frame);
3280 /* FRAME is used only to get a handle on the X display. We don't pass the
3281 display info directly because we're called from frame.c, which doesn't
3282 know about that structure. */
3284 Lisp_Object
3285 x_get_focus_frame (frame)
3286 struct frame *frame;
3288 struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (frame);
3289 Lisp_Object xfocus;
3290 if (! dpyinfo->x_focus_frame)
3291 return Qnil;
3293 XSETFRAME (xfocus, dpyinfo->x_focus_frame);
3294 return xfocus;
3298 /* In certain situations, when the window manager follows a
3299 click-to-focus policy, there seems to be no way around calling
3300 XSetInputFocus to give another frame the input focus .
3302 In an ideal world, XSetInputFocus should generally be avoided so
3303 that applications don't interfere with the window manager's focus
3304 policy. But I think it's okay to use when it's clearly done
3305 following a user-command. */
3307 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
3308 doc: /* Set the input focus to FRAME.
3309 FRAME nil means use the selected frame. */)
3310 (frame)
3311 Lisp_Object frame;
3313 struct frame *f = check_x_frame (frame);
3314 Display *dpy = FRAME_X_DISPLAY (f);
3315 int count;
3317 BLOCK_INPUT;
3318 count = x_catch_errors (dpy);
3319 XSetInputFocus (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
3320 RevertToParent, CurrentTime);
3321 x_uncatch_errors (dpy, count);
3322 UNBLOCK_INPUT;
3324 return Qnil;
3328 DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
3329 doc: /* Internal function called by `color-defined-p', which see. */)
3330 (color, frame)
3331 Lisp_Object color, frame;
3333 XColor foo;
3334 FRAME_PTR f = check_x_frame (frame);
3336 CHECK_STRING (color);
3338 if (x_defined_color (f, SDATA (color), &foo, 0))
3339 return Qt;
3340 else
3341 return Qnil;
3344 DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2, 0,
3345 doc: /* Internal function called by `color-values', which see. */)
3346 (color, frame)
3347 Lisp_Object color, frame;
3349 XColor foo;
3350 FRAME_PTR f = check_x_frame (frame);
3352 CHECK_STRING (color);
3354 if (x_defined_color (f, SDATA (color), &foo, 0))
3356 Lisp_Object rgb[3];
3358 rgb[0] = make_number (foo.red);
3359 rgb[1] = make_number (foo.green);
3360 rgb[2] = make_number (foo.blue);
3361 return Flist (3, rgb);
3363 else
3364 return Qnil;
3367 DEFUN ("xw-display-color-p", Fxw_display_color_p, Sxw_display_color_p, 0, 1, 0,
3368 doc: /* Internal function called by `display-color-p', which see. */)
3369 (display)
3370 Lisp_Object display;
3372 struct x_display_info *dpyinfo = check_x_display_info (display);
3374 if (dpyinfo->n_planes <= 2)
3375 return Qnil;
3377 switch (dpyinfo->visual->class)
3379 case StaticColor:
3380 case PseudoColor:
3381 case TrueColor:
3382 case DirectColor:
3383 return Qt;
3385 default:
3386 return Qnil;
3390 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p, Sx_display_grayscale_p,
3391 0, 1, 0,
3392 doc: /* Return t if the X display supports shades of gray.
3393 Note that color displays do support shades of gray.
3394 The optional argument DISPLAY specifies which display to ask about.
3395 DISPLAY should be either a frame or a display name (a string).
3396 If omitted or nil, that stands for the selected frame's display. */)
3397 (display)
3398 Lisp_Object display;
3400 struct x_display_info *dpyinfo = check_x_display_info (display);
3402 if (dpyinfo->n_planes <= 1)
3403 return Qnil;
3405 switch (dpyinfo->visual->class)
3407 case StaticColor:
3408 case PseudoColor:
3409 case TrueColor:
3410 case DirectColor:
3411 case StaticGray:
3412 case GrayScale:
3413 return Qt;
3415 default:
3416 return Qnil;
3420 DEFUN ("x-display-pixel-width", Fx_display_pixel_width, Sx_display_pixel_width,
3421 0, 1, 0,
3422 doc: /* Returns the width in pixels of the X display DISPLAY.
3423 The optional argument DISPLAY specifies which display to ask about.
3424 DISPLAY should be either a frame or a display name (a string).
3425 If omitted or nil, that stands for the selected frame's display. */)
3426 (display)
3427 Lisp_Object display;
3429 struct x_display_info *dpyinfo = check_x_display_info (display);
3431 return make_number (dpyinfo->width);
3434 DEFUN ("x-display-pixel-height", Fx_display_pixel_height,
3435 Sx_display_pixel_height, 0, 1, 0,
3436 doc: /* Returns the height in pixels of the X display DISPLAY.
3437 The optional argument DISPLAY specifies which display to ask about.
3438 DISPLAY should be either a frame or a display name (a string).
3439 If omitted or nil, that stands for the selected frame's display. */)
3440 (display)
3441 Lisp_Object display;
3443 struct x_display_info *dpyinfo = check_x_display_info (display);
3445 return make_number (dpyinfo->height);
3448 DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes,
3449 0, 1, 0,
3450 doc: /* Returns the number of bitplanes of the X display DISPLAY.
3451 The optional argument DISPLAY specifies which display to ask about.
3452 DISPLAY should be either a frame or a display name (a string).
3453 If omitted or nil, that stands for the selected frame's display. */)
3454 (display)
3455 Lisp_Object display;
3457 struct x_display_info *dpyinfo = check_x_display_info (display);
3459 return make_number (dpyinfo->n_planes);
3462 DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells,
3463 0, 1, 0,
3464 doc: /* Returns the number of color cells of the X display DISPLAY.
3465 The optional argument DISPLAY specifies which display to ask about.
3466 DISPLAY should be either a frame or a display name (a string).
3467 If omitted or nil, that stands for the selected frame's display. */)
3468 (display)
3469 Lisp_Object display;
3471 struct x_display_info *dpyinfo = check_x_display_info (display);
3473 int nr_planes = DisplayPlanes (dpyinfo->display,
3474 XScreenNumberOfScreen (dpyinfo->screen));
3476 /* Truncate nr_planes to 24 to avoid integer overflow.
3477 Some displays says 32, but only 24 bits are actually significant.
3478 There are only very few and rare video cards that have more than
3479 24 significant bits. Also 24 bits is more than 16 million colors,
3480 it "should be enough for everyone". */
3481 if (nr_planes > 24) nr_planes = 24;
3483 return make_number (1 << nr_planes);
3486 DEFUN ("x-server-max-request-size", Fx_server_max_request_size,
3487 Sx_server_max_request_size,
3488 0, 1, 0,
3489 doc: /* Returns the maximum request size of the X server of display DISPLAY.
3490 The optional argument DISPLAY specifies which display to ask about.
3491 DISPLAY should be either a frame or a display name (a string).
3492 If omitted or nil, that stands for the selected frame's display. */)
3493 (display)
3494 Lisp_Object display;
3496 struct x_display_info *dpyinfo = check_x_display_info (display);
3498 return make_number (MAXREQUEST (dpyinfo->display));
3501 DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0,
3502 doc: /* Returns the "vendor ID" string of the X server of display DISPLAY.
3503 \(Labelling every distributor as a "vendor" embodies the false assumption
3504 that operating systems cannot be developed and distributed noncommercially.)
3505 The optional argument DISPLAY specifies which display to ask about.
3506 DISPLAY should be either a frame or a display name (a string).
3507 If omitted or nil, that stands for the selected frame's display. */)
3508 (display)
3509 Lisp_Object display;
3511 struct x_display_info *dpyinfo = check_x_display_info (display);
3512 char *vendor = ServerVendor (dpyinfo->display);
3514 if (! vendor) vendor = "";
3515 return build_string (vendor);
3518 DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0,
3519 doc: /* Returns the version numbers of the X server of display DISPLAY.
3520 The value is a list of three integers: the major and minor
3521 version numbers of the X Protocol in use, and the distributor-specific release
3522 number. See also the function `x-server-vendor'.
3524 The optional argument DISPLAY specifies which display to ask about.
3525 DISPLAY should be either a frame or a display name (a string).
3526 If omitted or nil, that stands for the selected frame's display. */)
3527 (display)
3528 Lisp_Object display;
3530 struct x_display_info *dpyinfo = check_x_display_info (display);
3531 Display *dpy = dpyinfo->display;
3533 return Fcons (make_number (ProtocolVersion (dpy)),
3534 Fcons (make_number (ProtocolRevision (dpy)),
3535 Fcons (make_number (VendorRelease (dpy)), Qnil)));
3538 DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens, 0, 1, 0,
3539 doc: /* Return the number of screens on the X server of display DISPLAY.
3540 The optional argument DISPLAY specifies which display to ask about.
3541 DISPLAY should be either a frame or a display name (a string).
3542 If omitted or nil, that stands for the selected frame's display. */)
3543 (display)
3544 Lisp_Object display;
3546 struct x_display_info *dpyinfo = check_x_display_info (display);
3548 return make_number (ScreenCount (dpyinfo->display));
3551 DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height, 0, 1, 0,
3552 doc: /* Return the height in millimeters of the X display DISPLAY.
3553 The optional argument DISPLAY specifies which display to ask about.
3554 DISPLAY should be either a frame or a display name (a string).
3555 If omitted or nil, that stands for the selected frame's display. */)
3556 (display)
3557 Lisp_Object display;
3559 struct x_display_info *dpyinfo = check_x_display_info (display);
3561 return make_number (HeightMMOfScreen (dpyinfo->screen));
3564 DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0,
3565 doc: /* Return the width in millimeters of the X display DISPLAY.
3566 The optional argument DISPLAY specifies which display to ask about.
3567 DISPLAY should be either a frame or a display name (a string).
3568 If omitted or nil, that stands for the selected frame's display. */)
3569 (display)
3570 Lisp_Object display;
3572 struct x_display_info *dpyinfo = check_x_display_info (display);
3574 return make_number (WidthMMOfScreen (dpyinfo->screen));
3577 DEFUN ("x-display-backing-store", Fx_display_backing_store,
3578 Sx_display_backing_store, 0, 1, 0,
3579 doc: /* Returns an indication of whether X display DISPLAY does backing store.
3580 The value may be `always', `when-mapped', or `not-useful'.
3581 The optional argument DISPLAY specifies which display to ask about.
3582 DISPLAY should be either a frame or a display name (a string).
3583 If omitted or nil, that stands for the selected frame's display. */)
3584 (display)
3585 Lisp_Object display;
3587 struct x_display_info *dpyinfo = check_x_display_info (display);
3588 Lisp_Object result;
3590 switch (DoesBackingStore (dpyinfo->screen))
3592 case Always:
3593 result = intern ("always");
3594 break;
3596 case WhenMapped:
3597 result = intern ("when-mapped");
3598 break;
3600 case NotUseful:
3601 result = intern ("not-useful");
3602 break;
3604 default:
3605 error ("Strange value for BackingStore parameter of screen");
3606 result = Qnil;
3609 return result;
3612 DEFUN ("x-display-visual-class", Fx_display_visual_class,
3613 Sx_display_visual_class, 0, 1, 0,
3614 doc: /* Return the visual class of the X display DISPLAY.
3615 The value is one of the symbols `static-gray', `gray-scale',
3616 `static-color', `pseudo-color', `true-color', or `direct-color'.
3618 The optional argument DISPLAY specifies which display to ask about.
3619 DISPLAY should be either a frame or a display name (a string).
3620 If omitted or nil, that stands for the selected frame's display. */)
3621 (display)
3622 Lisp_Object display;
3624 struct x_display_info *dpyinfo = check_x_display_info (display);
3625 Lisp_Object result;
3627 switch (dpyinfo->visual->class)
3629 case StaticGray:
3630 result = intern ("static-gray");
3631 break;
3632 case GrayScale:
3633 result = intern ("gray-scale");
3634 break;
3635 case StaticColor:
3636 result = intern ("static-color");
3637 break;
3638 case PseudoColor:
3639 result = intern ("pseudo-color");
3640 break;
3641 case TrueColor:
3642 result = intern ("true-color");
3643 break;
3644 case DirectColor:
3645 result = intern ("direct-color");
3646 break;
3647 default:
3648 error ("Display has an unknown visual class");
3649 result = Qnil;
3652 return result;
3655 DEFUN ("x-display-save-under", Fx_display_save_under,
3656 Sx_display_save_under, 0, 1, 0,
3657 doc: /* Returns t if the X display DISPLAY supports the save-under feature.
3658 The optional argument DISPLAY specifies which display to ask about.
3659 DISPLAY should be either a frame or a display name (a string).
3660 If omitted or nil, that stands for the selected frame's display. */)
3661 (display)
3662 Lisp_Object display;
3664 struct x_display_info *dpyinfo = check_x_display_info (display);
3666 if (DoesSaveUnders (dpyinfo->screen) == True)
3667 return Qt;
3668 else
3669 return Qnil;
3673 x_pixel_width (f)
3674 register struct frame *f;
3676 return FRAME_PIXEL_WIDTH (f);
3680 x_pixel_height (f)
3681 register struct frame *f;
3683 return FRAME_PIXEL_HEIGHT (f);
3687 x_char_width (f)
3688 register struct frame *f;
3690 return FRAME_COLUMN_WIDTH (f);
3694 x_char_height (f)
3695 register struct frame *f;
3697 return FRAME_LINE_HEIGHT (f);
3701 x_screen_planes (f)
3702 register struct frame *f;
3704 return FRAME_X_DISPLAY_INFO (f)->n_planes;
3709 /************************************************************************
3710 X Displays
3711 ************************************************************************/
3714 /* Mapping visual names to visuals. */
3716 static struct visual_class
3718 char *name;
3719 int class;
3721 visual_classes[] =
3723 {"StaticGray", StaticGray},
3724 {"GrayScale", GrayScale},
3725 {"StaticColor", StaticColor},
3726 {"PseudoColor", PseudoColor},
3727 {"TrueColor", TrueColor},
3728 {"DirectColor", DirectColor},
3729 {NULL, 0}
3733 #ifndef HAVE_XSCREENNUMBEROFSCREEN
3735 /* Value is the screen number of screen SCR. This is a substitute for
3736 the X function with the same name when that doesn't exist. */
3739 XScreenNumberOfScreen (scr)
3740 register Screen *scr;
3742 Display *dpy = scr->display;
3743 int i;
3745 for (i = 0; i < dpy->nscreens; ++i)
3746 if (scr == dpy->screens + i)
3747 break;
3749 return i;
3752 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
3755 /* Select the visual that should be used on display DPYINFO. Set
3756 members of DPYINFO appropriately. Called from x_term_init. */
3758 void
3759 select_visual (dpyinfo)
3760 struct x_display_info *dpyinfo;
3762 Display *dpy = dpyinfo->display;
3763 Screen *screen = dpyinfo->screen;
3764 Lisp_Object value;
3766 /* See if a visual is specified. */
3767 value = display_x_get_resource (dpyinfo,
3768 build_string ("visualClass"),
3769 build_string ("VisualClass"),
3770 Qnil, Qnil);
3771 if (STRINGP (value))
3773 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
3774 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
3775 depth, a decimal number. NAME is compared with case ignored. */
3776 char *s = (char *) alloca (SBYTES (value) + 1);
3777 char *dash;
3778 int i, class = -1;
3779 XVisualInfo vinfo;
3781 strcpy (s, SDATA (value));
3782 dash = index (s, '-');
3783 if (dash)
3785 dpyinfo->n_planes = atoi (dash + 1);
3786 *dash = '\0';
3788 else
3789 /* We won't find a matching visual with depth 0, so that
3790 an error will be printed below. */
3791 dpyinfo->n_planes = 0;
3793 /* Determine the visual class. */
3794 for (i = 0; visual_classes[i].name; ++i)
3795 if (xstricmp (s, visual_classes[i].name) == 0)
3797 class = visual_classes[i].class;
3798 break;
3801 /* Look up a matching visual for the specified class. */
3802 if (class == -1
3803 || !XMatchVisualInfo (dpy, XScreenNumberOfScreen (screen),
3804 dpyinfo->n_planes, class, &vinfo))
3805 fatal ("Invalid visual specification `%s'", SDATA (value));
3807 dpyinfo->visual = vinfo.visual;
3809 else
3811 int n_visuals;
3812 XVisualInfo *vinfo, vinfo_template;
3814 dpyinfo->visual = DefaultVisualOfScreen (screen);
3816 #ifdef HAVE_X11R4
3817 vinfo_template.visualid = XVisualIDFromVisual (dpyinfo->visual);
3818 #else
3819 vinfo_template.visualid = dpyinfo->visual->visualid;
3820 #endif
3821 vinfo_template.screen = XScreenNumberOfScreen (screen);
3822 vinfo = XGetVisualInfo (dpy, VisualIDMask | VisualScreenMask,
3823 &vinfo_template, &n_visuals);
3824 if (n_visuals != 1)
3825 fatal ("Can't get proper X visual info");
3827 dpyinfo->n_planes = vinfo->depth;
3828 XFree ((char *) vinfo);
3833 /* Return the X display structure for the display named NAME.
3834 Open a new connection if necessary. */
3836 struct x_display_info *
3837 x_display_info_for_name (name)
3838 Lisp_Object name;
3840 Lisp_Object names;
3841 struct x_display_info *dpyinfo;
3843 CHECK_STRING (name);
3845 if (! EQ (Vwindow_system, intern ("x")))
3846 error ("Not using X Windows");
3848 for (dpyinfo = x_display_list, names = x_display_name_list;
3849 dpyinfo;
3850 dpyinfo = dpyinfo->next, names = XCDR (names))
3852 Lisp_Object tem;
3853 tem = Fstring_equal (XCAR (XCAR (names)), name);
3854 if (!NILP (tem))
3855 return dpyinfo;
3858 /* Use this general default value to start with. */
3859 Vx_resource_name = Vinvocation_name;
3861 validate_x_resource_name ();
3863 dpyinfo = x_term_init (name, (char *)0,
3864 (char *) SDATA (Vx_resource_name));
3866 if (dpyinfo == 0)
3867 error ("Cannot connect to X server %s", SDATA (name));
3869 x_in_use = 1;
3870 XSETFASTINT (Vwindow_system_version, 11);
3872 return dpyinfo;
3876 DEFUN ("x-open-connection", Fx_open_connection, Sx_open_connection,
3877 1, 3, 0,
3878 doc: /* Open a connection to an X server.
3879 DISPLAY is the name of the display to connect to.
3880 Optional second arg XRM-STRING is a string of resources in xrdb format.
3881 If the optional third arg MUST-SUCCEED is non-nil,
3882 terminate Emacs if we can't open the connection. */)
3883 (display, xrm_string, must_succeed)
3884 Lisp_Object display, xrm_string, must_succeed;
3886 unsigned char *xrm_option;
3887 struct x_display_info *dpyinfo;
3889 CHECK_STRING (display);
3890 if (! NILP (xrm_string))
3891 CHECK_STRING (xrm_string);
3893 if (! EQ (Vwindow_system, intern ("x")))
3894 error ("Not using X Windows");
3896 if (! NILP (xrm_string))
3897 xrm_option = (unsigned char *) SDATA (xrm_string);
3898 else
3899 xrm_option = (unsigned char *) 0;
3901 validate_x_resource_name ();
3903 /* This is what opens the connection and sets x_current_display.
3904 This also initializes many symbols, such as those used for input. */
3905 dpyinfo = x_term_init (display, xrm_option,
3906 (char *) SDATA (Vx_resource_name));
3908 if (dpyinfo == 0)
3910 if (!NILP (must_succeed))
3911 fatal ("Cannot connect to X server %s.\n\
3912 Check the DISPLAY environment variable or use `-d'.\n\
3913 Also use the `xauth' program to verify that you have the proper\n\
3914 authorization information needed to connect the X server.\n\
3915 An insecure way to solve the problem may be to use `xhost'.\n",
3916 SDATA (display));
3917 else
3918 error ("Cannot connect to X server %s", SDATA (display));
3921 x_in_use = 1;
3923 XSETFASTINT (Vwindow_system_version, 11);
3924 return Qnil;
3927 DEFUN ("x-close-connection", Fx_close_connection,
3928 Sx_close_connection, 1, 1, 0,
3929 doc: /* Close the connection to DISPLAY's X server.
3930 For DISPLAY, specify either a frame or a display name (a string).
3931 If DISPLAY is nil, that stands for the selected frame's display. */)
3932 (display)
3933 Lisp_Object display;
3935 struct x_display_info *dpyinfo = check_x_display_info (display);
3936 int i;
3938 if (dpyinfo->reference_count > 0)
3939 error ("Display still has frames on it");
3941 BLOCK_INPUT;
3942 /* Free the fonts in the font table. */
3943 for (i = 0; i < dpyinfo->n_fonts; i++)
3944 if (dpyinfo->font_table[i].name)
3946 XFreeFont (dpyinfo->display, dpyinfo->font_table[i].font);
3949 x_destroy_all_bitmaps (dpyinfo);
3950 XSetCloseDownMode (dpyinfo->display, DestroyAll);
3952 #ifdef USE_X_TOOLKIT
3953 XtCloseDisplay (dpyinfo->display);
3954 #else
3955 XCloseDisplay (dpyinfo->display);
3956 #endif
3958 x_delete_display (dpyinfo);
3959 UNBLOCK_INPUT;
3961 return Qnil;
3964 DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0,
3965 doc: /* Return the list of display names that Emacs has connections to. */)
3968 Lisp_Object tail, result;
3970 result = Qnil;
3971 for (tail = x_display_name_list; ! NILP (tail); tail = XCDR (tail))
3972 result = Fcons (XCAR (XCAR (tail)), result);
3974 return result;
3977 DEFUN ("x-synchronize", Fx_synchronize, Sx_synchronize, 1, 2, 0,
3978 doc: /* If ON is non-nil, report X errors as soon as the erring request is made.
3979 If ON is nil, allow buffering of requests.
3980 Turning on synchronization prohibits the Xlib routines from buffering
3981 requests and seriously degrades performance, but makes debugging much
3982 easier.
3983 The optional second argument DISPLAY specifies which display to act on.
3984 DISPLAY should be either a frame or a display name (a string).
3985 If DISPLAY is omitted or nil, that stands for the selected frame's display. */)
3986 (on, display)
3987 Lisp_Object display, on;
3989 struct x_display_info *dpyinfo = check_x_display_info (display);
3991 XSynchronize (dpyinfo->display, !EQ (on, Qnil));
3993 return Qnil;
3996 /* Wait for responses to all X commands issued so far for frame F. */
3998 void
3999 x_sync (f)
4000 FRAME_PTR f;
4002 BLOCK_INPUT;
4003 XSync (FRAME_X_DISPLAY (f), False);
4004 UNBLOCK_INPUT;
4008 /***********************************************************************
4009 Window properties
4010 ***********************************************************************/
4012 DEFUN ("x-change-window-property", Fx_change_window_property,
4013 Sx_change_window_property, 2, 6, 0,
4014 doc: /* Change window property PROP to VALUE on the X window of FRAME.
4015 PROP must be a string.
4016 VALUE may be a string or a list of conses, numbers and/or strings.
4017 If an element in the list is a string, it is converted to
4018 an Atom and the value of the Atom is used. If an element is a cons,
4019 it is converted to a 32 bit number where the car is the 16 top bits and the
4020 cdr is the lower 16 bits.
4021 FRAME nil or omitted means use the selected frame.
4022 If TYPE is given and non-nil, it is the name of the type of VALUE.
4023 If TYPE is not given or nil, the type is STRING.
4024 FORMAT gives the size in bits of each element if VALUE is a list.
4025 It must be one of 8, 16 or 32.
4026 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4027 If OUTER_P is non-nil, the property is changed for the outer X window of
4028 FRAME. Default is to change on the edit X window.
4030 Value is VALUE. */)
4031 (prop, value, frame, type, format, outer_p)
4032 Lisp_Object prop, value, frame, type, format, outer_p;
4034 struct frame *f = check_x_frame (frame);
4035 Atom prop_atom;
4036 Atom target_type = XA_STRING;
4037 int element_format = 8;
4038 unsigned char *data;
4039 int nelements;
4040 Window w;
4042 CHECK_STRING (prop);
4044 if (! NILP (format))
4046 CHECK_NUMBER (format);
4047 element_format = XFASTINT (format);
4049 if (element_format != 8 && element_format != 16
4050 && element_format != 32)
4051 error ("FORMAT must be one of 8, 16 or 32");
4054 if (CONSP (value))
4056 nelements = x_check_property_data (value);
4057 if (nelements == -1)
4058 error ("Bad data in VALUE, must be number, string or cons");
4060 if (element_format == 8)
4061 data = (unsigned char *) xmalloc (nelements);
4062 else if (element_format == 16)
4063 data = (unsigned char *) xmalloc (nelements*2);
4064 else
4065 data = (unsigned char *) xmalloc (nelements*4);
4067 x_fill_property_data (FRAME_X_DISPLAY (f), value, data, element_format);
4069 else
4071 CHECK_STRING (value);
4072 data = SDATA (value);
4073 nelements = SCHARS (value);
4076 BLOCK_INPUT;
4077 prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SDATA (prop), False);
4078 if (! NILP (type))
4080 CHECK_STRING (type);
4081 target_type = XInternAtom (FRAME_X_DISPLAY (f), SDATA (type), False);
4084 if (! NILP (outer_p)) w = FRAME_OUTER_WINDOW (f);
4085 else w = FRAME_X_WINDOW (f);
4087 XChangeProperty (FRAME_X_DISPLAY (f), w,
4088 prop_atom, target_type, element_format, PropModeReplace,
4089 data, nelements);
4091 if (CONSP (value)) xfree (data);
4093 /* Make sure the property is set when we return. */
4094 XFlush (FRAME_X_DISPLAY (f));
4095 UNBLOCK_INPUT;
4097 return value;
4101 DEFUN ("x-delete-window-property", Fx_delete_window_property,
4102 Sx_delete_window_property, 1, 2, 0,
4103 doc: /* Remove window property PROP from X window of FRAME.
4104 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4105 (prop, frame)
4106 Lisp_Object prop, frame;
4108 struct frame *f = check_x_frame (frame);
4109 Atom prop_atom;
4111 CHECK_STRING (prop);
4112 BLOCK_INPUT;
4113 prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SDATA (prop), False);
4114 XDeleteProperty (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), prop_atom);
4116 /* Make sure the property is removed when we return. */
4117 XFlush (FRAME_X_DISPLAY (f));
4118 UNBLOCK_INPUT;
4120 return prop;
4124 DEFUN ("x-window-property", Fx_window_property, Sx_window_property,
4125 1, 6, 0,
4126 doc: /* Value is the value of window property PROP on FRAME.
4127 If FRAME is nil or omitted, use the selected frame.
4128 If TYPE is nil or omitted, get the property as a string. Otherwise TYPE
4129 is the name of the Atom that denotes the type expected.
4130 If SOURCE is non-nil, get the property on that window instead of from
4131 FRAME. The number 0 denotes the root window.
4132 If DELETE_P is non-nil, delete the property after retreiving it.
4133 If VECTOR_RET_P is non-nil, don't return a string but a vector of values.
4135 Value is nil if FRAME hasn't a property with name PROP or if PROP has
4136 no value of TYPE. */)
4137 (prop, frame, type, source, delete_p, vector_ret_p)
4138 Lisp_Object prop, frame, type, source, delete_p, vector_ret_p;
4140 struct frame *f = check_x_frame (frame);
4141 Atom prop_atom;
4142 int rc;
4143 Lisp_Object prop_value = Qnil;
4144 char *tmp_data = NULL;
4145 Atom actual_type;
4146 Atom target_type = XA_STRING;
4147 int actual_format;
4148 unsigned long actual_size, bytes_remaining;
4149 Window target_window = FRAME_X_WINDOW (f);
4150 struct gcpro gcpro1;
4152 GCPRO1 (prop_value);
4153 CHECK_STRING (prop);
4155 if (! NILP (source))
4157 if (NUMBERP (source))
4159 if (FLOATP (source))
4160 target_window = (Window) XFLOAT (source);
4161 else
4162 target_window = XFASTINT (source);
4164 if (target_window == 0)
4165 target_window = FRAME_X_DISPLAY_INFO (f)->root_window;
4167 else if (CONSP (source))
4168 target_window = cons_to_long (source);
4171 BLOCK_INPUT;
4172 if (STRINGP (type))
4174 if (strcmp ("AnyPropertyType", SDATA (type)) == 0)
4175 target_type = AnyPropertyType;
4176 else
4177 target_type = XInternAtom (FRAME_X_DISPLAY (f), SDATA (type), False);
4180 prop_atom = XInternAtom (FRAME_X_DISPLAY (f), SDATA (prop), False);
4181 rc = XGetWindowProperty (FRAME_X_DISPLAY (f), target_window,
4182 prop_atom, 0, 0, False, target_type,
4183 &actual_type, &actual_format, &actual_size,
4184 &bytes_remaining, (unsigned char **) &tmp_data);
4185 if (rc == Success)
4187 int size = bytes_remaining;
4189 XFree (tmp_data);
4190 tmp_data = NULL;
4192 rc = XGetWindowProperty (FRAME_X_DISPLAY (f), target_window,
4193 prop_atom, 0, bytes_remaining,
4194 ! NILP (delete_p), target_type,
4195 &actual_type, &actual_format,
4196 &actual_size, &bytes_remaining,
4197 (unsigned char **) &tmp_data);
4198 if (rc == Success && tmp_data)
4200 if (NILP (vector_ret_p))
4201 prop_value = make_string (tmp_data, size);
4202 else
4203 prop_value = x_property_data_to_lisp (f,
4204 (unsigned char *) tmp_data,
4205 actual_type,
4206 actual_format,
4207 actual_size);
4210 if (tmp_data) XFree (tmp_data);
4213 UNBLOCK_INPUT;
4214 UNGCPRO;
4215 return prop_value;
4220 /***********************************************************************
4221 Busy cursor
4222 ***********************************************************************/
4224 /* If non-null, an asynchronous timer that, when it expires, displays
4225 an hourglass cursor on all frames. */
4227 static struct atimer *hourglass_atimer;
4229 /* Non-zero means an hourglass cursor is currently shown. */
4231 static int hourglass_shown_p;
4233 /* Number of seconds to wait before displaying an hourglass cursor. */
4235 static Lisp_Object Vhourglass_delay;
4237 /* Default number of seconds to wait before displaying an hourglass
4238 cursor. */
4240 #define DEFAULT_HOURGLASS_DELAY 1
4242 /* Function prototypes. */
4244 static void show_hourglass P_ ((struct atimer *));
4245 static void hide_hourglass P_ ((void));
4248 /* Cancel a currently active hourglass timer, and start a new one. */
4250 void
4251 start_hourglass ()
4253 EMACS_TIME delay;
4254 int secs, usecs = 0;
4256 cancel_hourglass ();
4258 if (INTEGERP (Vhourglass_delay)
4259 && XINT (Vhourglass_delay) > 0)
4260 secs = XFASTINT (Vhourglass_delay);
4261 else if (FLOATP (Vhourglass_delay)
4262 && XFLOAT_DATA (Vhourglass_delay) > 0)
4264 Lisp_Object tem;
4265 tem = Ftruncate (Vhourglass_delay, Qnil);
4266 secs = XFASTINT (tem);
4267 usecs = (XFLOAT_DATA (Vhourglass_delay) - secs) * 1000000;
4269 else
4270 secs = DEFAULT_HOURGLASS_DELAY;
4272 EMACS_SET_SECS_USECS (delay, secs, usecs);
4273 hourglass_atimer = start_atimer (ATIMER_RELATIVE, delay,
4274 show_hourglass, NULL);
4278 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
4279 shown. */
4281 void
4282 cancel_hourglass ()
4284 if (hourglass_atimer)
4286 cancel_atimer (hourglass_atimer);
4287 hourglass_atimer = NULL;
4290 if (hourglass_shown_p)
4291 hide_hourglass ();
4295 /* Timer function of hourglass_atimer. TIMER is equal to
4296 hourglass_atimer.
4298 Display an hourglass pointer on all frames by mapping the frames'
4299 hourglass_window. Set the hourglass_p flag in the frames'
4300 output_data.x structure to indicate that an hourglass cursor is
4301 shown on the frames. */
4303 static void
4304 show_hourglass (timer)
4305 struct atimer *timer;
4307 /* The timer implementation will cancel this timer automatically
4308 after this function has run. Set hourglass_atimer to null
4309 so that we know the timer doesn't have to be canceled. */
4310 hourglass_atimer = NULL;
4312 if (!hourglass_shown_p)
4314 Lisp_Object rest, frame;
4316 BLOCK_INPUT;
4318 FOR_EACH_FRAME (rest, frame)
4320 struct frame *f = XFRAME (frame);
4322 if (FRAME_LIVE_P (f) && FRAME_X_P (f) && FRAME_X_DISPLAY (f))
4324 Display *dpy = FRAME_X_DISPLAY (f);
4326 #ifdef USE_X_TOOLKIT
4327 if (f->output_data.x->widget)
4328 #else
4329 if (FRAME_OUTER_WINDOW (f))
4330 #endif
4332 f->output_data.x->hourglass_p = 1;
4334 if (!f->output_data.x->hourglass_window)
4336 unsigned long mask = CWCursor;
4337 XSetWindowAttributes attrs;
4339 attrs.cursor = f->output_data.x->hourglass_cursor;
4341 f->output_data.x->hourglass_window
4342 = XCreateWindow (dpy, FRAME_OUTER_WINDOW (f),
4343 0, 0, 32000, 32000, 0, 0,
4344 InputOnly,
4345 CopyFromParent,
4346 mask, &attrs);
4349 XMapRaised (dpy, f->output_data.x->hourglass_window);
4350 XFlush (dpy);
4355 hourglass_shown_p = 1;
4356 UNBLOCK_INPUT;
4361 /* Hide the hourglass pointer on all frames, if it is currently
4362 shown. */
4364 static void
4365 hide_hourglass ()
4367 if (hourglass_shown_p)
4369 Lisp_Object rest, frame;
4371 BLOCK_INPUT;
4372 FOR_EACH_FRAME (rest, frame)
4374 struct frame *f = XFRAME (frame);
4376 if (FRAME_X_P (f)
4377 /* Watch out for newly created frames. */
4378 && f->output_data.x->hourglass_window)
4380 XUnmapWindow (FRAME_X_DISPLAY (f),
4381 f->output_data.x->hourglass_window);
4382 /* Sync here because XTread_socket looks at the
4383 hourglass_p flag that is reset to zero below. */
4384 XSync (FRAME_X_DISPLAY (f), False);
4385 f->output_data.x->hourglass_p = 0;
4389 hourglass_shown_p = 0;
4390 UNBLOCK_INPUT;
4396 /***********************************************************************
4397 Tool tips
4398 ***********************************************************************/
4400 static Lisp_Object x_create_tip_frame P_ ((struct x_display_info *,
4401 Lisp_Object, Lisp_Object));
4402 static void compute_tip_xy P_ ((struct frame *, Lisp_Object, Lisp_Object,
4403 Lisp_Object, int, int, int *, int *));
4405 /* The frame of a currently visible tooltip. */
4407 Lisp_Object tip_frame;
4409 /* If non-nil, a timer started that hides the last tooltip when it
4410 fires. */
4412 Lisp_Object tip_timer;
4413 Window tip_window;
4415 /* If non-nil, a vector of 3 elements containing the last args
4416 with which x-show-tip was called. See there. */
4418 Lisp_Object last_show_tip_args;
4420 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
4422 Lisp_Object Vx_max_tooltip_size;
4425 static Lisp_Object
4426 unwind_create_tip_frame (frame)
4427 Lisp_Object frame;
4429 Lisp_Object deleted;
4431 deleted = unwind_create_frame (frame);
4432 if (EQ (deleted, Qt))
4434 tip_window = None;
4435 tip_frame = Qnil;
4438 return deleted;
4442 /* Create a frame for a tooltip on the display described by DPYINFO.
4443 PARMS is a list of frame parameters. TEXT is the string to
4444 display in the tip frame. Value is the frame.
4446 Note that functions called here, esp. x_default_parameter can
4447 signal errors, for instance when a specified color name is
4448 undefined. We have to make sure that we're in a consistent state
4449 when this happens. */
4451 static Lisp_Object
4452 x_create_tip_frame (dpyinfo, parms, text)
4453 struct x_display_info *dpyinfo;
4454 Lisp_Object parms, text;
4456 struct frame *f;
4457 Lisp_Object frame, tem;
4458 Lisp_Object name;
4459 long window_prompting = 0;
4460 int width, height;
4461 int count = SPECPDL_INDEX ();
4462 struct gcpro gcpro1, gcpro2, gcpro3;
4463 struct kboard *kb;
4464 int face_change_count_before = face_change_count;
4465 Lisp_Object buffer;
4466 struct buffer *old_buffer;
4468 check_x ();
4470 /* Use this general default value to start with until we know if
4471 this frame has a specified name. */
4472 Vx_resource_name = Vinvocation_name;
4474 #ifdef MULTI_KBOARD
4475 kb = dpyinfo->kboard;
4476 #else
4477 kb = &the_only_kboard;
4478 #endif
4480 /* Get the name of the frame to use for resource lookup. */
4481 name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING);
4482 if (!STRINGP (name)
4483 && !EQ (name, Qunbound)
4484 && !NILP (name))
4485 error ("Invalid frame name--not a string or nil");
4486 Vx_resource_name = name;
4488 frame = Qnil;
4489 GCPRO3 (parms, name, frame);
4490 f = make_frame (1);
4491 XSETFRAME (frame, f);
4493 buffer = Fget_buffer_create (build_string (" *tip*"));
4494 Fset_window_buffer (FRAME_ROOT_WINDOW (f), buffer, Qnil);
4495 old_buffer = current_buffer;
4496 set_buffer_internal_1 (XBUFFER (buffer));
4497 current_buffer->truncate_lines = Qnil;
4498 specbind (Qinhibit_read_only, Qt);
4499 specbind (Qinhibit_modification_hooks, Qt);
4500 Ferase_buffer ();
4501 Finsert (1, &text);
4502 set_buffer_internal_1 (old_buffer);
4504 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
4505 record_unwind_protect (unwind_create_tip_frame, frame);
4507 /* By setting the output method, we're essentially saying that
4508 the frame is live, as per FRAME_LIVE_P. If we get a signal
4509 from this point on, x_destroy_window might screw up reference
4510 counts etc. */
4511 f->output_method = output_x_window;
4512 f->output_data.x = (struct x_output *) xmalloc (sizeof (struct x_output));
4513 bzero (f->output_data.x, sizeof (struct x_output));
4514 f->output_data.x->icon_bitmap = -1;
4515 FRAME_FONTSET (f) = -1;
4516 f->output_data.x->scroll_bar_foreground_pixel = -1;
4517 f->output_data.x->scroll_bar_background_pixel = -1;
4518 #ifdef USE_TOOLKIT_SCROLL_BARS
4519 f->output_data.x->scroll_bar_top_shadow_pixel = -1;
4520 f->output_data.x->scroll_bar_bottom_shadow_pixel = -1;
4521 #endif /* USE_TOOLKIT_SCROLL_BARS */
4522 f->icon_name = Qnil;
4523 FRAME_X_DISPLAY_INFO (f) = dpyinfo;
4524 #if GLYPH_DEBUG
4525 image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount;
4526 dpyinfo_refcount = dpyinfo->reference_count;
4527 #endif /* GLYPH_DEBUG */
4528 #ifdef MULTI_KBOARD
4529 FRAME_KBOARD (f) = kb;
4530 #endif
4531 f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
4532 f->output_data.x->explicit_parent = 0;
4534 /* These colors will be set anyway later, but it's important
4535 to get the color reference counts right, so initialize them! */
4537 Lisp_Object black;
4538 struct gcpro gcpro1;
4540 black = build_string ("black");
4541 GCPRO1 (black);
4542 f->output_data.x->foreground_pixel
4543 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
4544 f->output_data.x->background_pixel
4545 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
4546 f->output_data.x->cursor_pixel
4547 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
4548 f->output_data.x->cursor_foreground_pixel
4549 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
4550 f->output_data.x->border_pixel
4551 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
4552 f->output_data.x->mouse_pixel
4553 = x_decode_color (f, black, BLACK_PIX_DEFAULT (f));
4554 UNGCPRO;
4557 /* Set the name; the functions to which we pass f expect the name to
4558 be set. */
4559 if (EQ (name, Qunbound) || NILP (name))
4561 f->name = build_string (dpyinfo->x_id_name);
4562 f->explicit_name = 0;
4564 else
4566 f->name = name;
4567 f->explicit_name = 1;
4568 /* use the frame's title when getting resources for this frame. */
4569 specbind (Qx_resource_name, name);
4572 /* Extract the window parameters from the supplied values that are
4573 needed to determine window geometry. */
4575 Lisp_Object font;
4577 font = x_get_arg (dpyinfo, parms, Qfont, "font", "Font", RES_TYPE_STRING);
4579 BLOCK_INPUT;
4580 /* First, try whatever font the caller has specified. */
4581 if (STRINGP (font))
4583 tem = Fquery_fontset (font, Qnil);
4584 if (STRINGP (tem))
4585 font = x_new_fontset (f, SDATA (tem));
4586 else
4587 font = x_new_font (f, SDATA (font));
4590 /* Try out a font which we hope has bold and italic variations. */
4591 if (!STRINGP (font))
4592 font = x_new_font (f, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
4593 if (!STRINGP (font))
4594 font = x_new_font (f, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
4595 if (! STRINGP (font))
4596 font = x_new_font (f, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
4597 if (! STRINGP (font))
4598 /* This was formerly the first thing tried, but it finds too many fonts
4599 and takes too long. */
4600 font = x_new_font (f, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
4601 /* If those didn't work, look for something which will at least work. */
4602 if (! STRINGP (font))
4603 font = x_new_font (f, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
4604 UNBLOCK_INPUT;
4605 if (! STRINGP (font))
4606 font = build_string ("fixed");
4608 x_default_parameter (f, parms, Qfont, font,
4609 "font", "Font", RES_TYPE_STRING);
4612 x_default_parameter (f, parms, Qborder_width, make_number (2),
4613 "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
4615 /* This defaults to 2 in order to match xterm. We recognize either
4616 internalBorderWidth or internalBorder (which is what xterm calls
4617 it). */
4618 if (NILP (Fassq (Qinternal_border_width, parms)))
4620 Lisp_Object value;
4622 value = x_get_arg (dpyinfo, parms, Qinternal_border_width,
4623 "internalBorder", "internalBorder", RES_TYPE_NUMBER);
4624 if (! EQ (value, Qunbound))
4625 parms = Fcons (Fcons (Qinternal_border_width, value),
4626 parms);
4629 x_default_parameter (f, parms, Qinternal_border_width, make_number (1),
4630 "internalBorderWidth", "internalBorderWidth",
4631 RES_TYPE_NUMBER);
4633 /* Also do the stuff which must be set before the window exists. */
4634 x_default_parameter (f, parms, Qforeground_color, build_string ("black"),
4635 "foreground", "Foreground", RES_TYPE_STRING);
4636 x_default_parameter (f, parms, Qbackground_color, build_string ("white"),
4637 "background", "Background", RES_TYPE_STRING);
4638 x_default_parameter (f, parms, Qmouse_color, build_string ("black"),
4639 "pointerColor", "Foreground", RES_TYPE_STRING);
4640 x_default_parameter (f, parms, Qcursor_color, build_string ("black"),
4641 "cursorColor", "Foreground", RES_TYPE_STRING);
4642 x_default_parameter (f, parms, Qborder_color, build_string ("black"),
4643 "borderColor", "BorderColor", RES_TYPE_STRING);
4645 /* Init faces before x_default_parameter is called for scroll-bar
4646 parameters because that function calls x_set_scroll_bar_width,
4647 which calls change_frame_size, which calls Fset_window_buffer,
4648 which runs hooks, which call Fvertical_motion. At the end, we
4649 end up in init_iterator with a null face cache, which should not
4650 happen. */
4651 init_frame_faces (f);
4653 f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
4655 window_prompting = x_figure_window_size (f, parms, 0);
4658 XSetWindowAttributes attrs;
4659 unsigned long mask;
4661 BLOCK_INPUT;
4662 mask = CWBackPixel | CWOverrideRedirect | CWEventMask;
4663 if (DoesSaveUnders (dpyinfo->screen))
4664 mask |= CWSaveUnder;
4666 /* Window managers look at the override-redirect flag to determine
4667 whether or net to give windows a decoration (Xlib spec, chapter
4668 3.2.8). */
4669 attrs.override_redirect = True;
4670 attrs.save_under = True;
4671 attrs.background_pixel = FRAME_BACKGROUND_PIXEL (f);
4672 /* Arrange for getting MapNotify and UnmapNotify events. */
4673 attrs.event_mask = StructureNotifyMask;
4674 tip_window
4675 = FRAME_X_WINDOW (f)
4676 = XCreateWindow (FRAME_X_DISPLAY (f),
4677 FRAME_X_DISPLAY_INFO (f)->root_window,
4678 /* x, y, width, height */
4679 0, 0, 1, 1,
4680 /* Border. */
4682 CopyFromParent, InputOutput, CopyFromParent,
4683 mask, &attrs);
4684 UNBLOCK_INPUT;
4687 x_make_gc (f);
4689 x_default_parameter (f, parms, Qauto_raise, Qnil,
4690 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
4691 x_default_parameter (f, parms, Qauto_lower, Qnil,
4692 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
4693 x_default_parameter (f, parms, Qcursor_type, Qbox,
4694 "cursorType", "CursorType", RES_TYPE_SYMBOL);
4696 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4697 Change will not be effected unless different from the current
4698 FRAME_LINES (f). */
4699 width = FRAME_COLS (f);
4700 height = FRAME_LINES (f);
4701 SET_FRAME_COLS (f, 0);
4702 FRAME_LINES (f) = 0;
4703 change_frame_size (f, height, width, 1, 0, 0);
4705 /* Add `tooltip' frame parameter's default value. */
4706 if (NILP (Fframe_parameter (frame, intern ("tooltip"))))
4707 Fmodify_frame_parameters (frame, Fcons (Fcons (intern ("tooltip"), Qt),
4708 Qnil));
4710 /* Set up faces after all frame parameters are known. This call
4711 also merges in face attributes specified for new frames.
4713 Frame parameters may be changed if .Xdefaults contains
4714 specifications for the default font. For example, if there is an
4715 `Emacs.default.attributeBackground: pink', the `background-color'
4716 attribute of the frame get's set, which let's the internal border
4717 of the tooltip frame appear in pink. Prevent this. */
4719 Lisp_Object bg = Fframe_parameter (frame, Qbackground_color);
4721 /* Set tip_frame here, so that */
4722 tip_frame = frame;
4723 call1 (Qface_set_after_frame_default, frame);
4725 if (!EQ (bg, Fframe_parameter (frame, Qbackground_color)))
4726 Fmodify_frame_parameters (frame, Fcons (Fcons (Qbackground_color, bg),
4727 Qnil));
4730 f->no_split = 1;
4732 UNGCPRO;
4734 /* It is now ok to make the frame official even if we get an error
4735 below. And the frame needs to be on Vframe_list or making it
4736 visible won't work. */
4737 Vframe_list = Fcons (frame, Vframe_list);
4739 /* Now that the frame is official, it counts as a reference to
4740 its display. */
4741 FRAME_X_DISPLAY_INFO (f)->reference_count++;
4743 /* Setting attributes of faces of the tooltip frame from resources
4744 and similar will increment face_change_count, which leads to the
4745 clearing of all current matrices. Since this isn't necessary
4746 here, avoid it by resetting face_change_count to the value it
4747 had before we created the tip frame. */
4748 face_change_count = face_change_count_before;
4750 /* Discard the unwind_protect. */
4751 return unbind_to (count, frame);
4755 /* Compute where to display tip frame F. PARMS is the list of frame
4756 parameters for F. DX and DY are specified offsets from the current
4757 location of the mouse. WIDTH and HEIGHT are the width and height
4758 of the tooltip. Return coordinates relative to the root window of
4759 the display in *ROOT_X, and *ROOT_Y. */
4761 static void
4762 compute_tip_xy (f, parms, dx, dy, width, height, root_x, root_y)
4763 struct frame *f;
4764 Lisp_Object parms, dx, dy;
4765 int width, height;
4766 int *root_x, *root_y;
4768 Lisp_Object left, top;
4769 int win_x, win_y;
4770 Window root, child;
4771 unsigned pmask;
4773 /* User-specified position? */
4774 left = Fcdr (Fassq (Qleft, parms));
4775 top = Fcdr (Fassq (Qtop, parms));
4777 /* Move the tooltip window where the mouse pointer is. Resize and
4778 show it. */
4779 if (!INTEGERP (left) || !INTEGERP (top))
4781 BLOCK_INPUT;
4782 XQueryPointer (FRAME_X_DISPLAY (f), FRAME_X_DISPLAY_INFO (f)->root_window,
4783 &root, &child, root_x, root_y, &win_x, &win_y, &pmask);
4784 UNBLOCK_INPUT;
4787 if (INTEGERP (top))
4788 *root_y = XINT (top);
4789 else if (*root_y + XINT (dy) - height < 0)
4790 *root_y -= XINT (dy);
4791 else
4793 *root_y -= height;
4794 *root_y += XINT (dy);
4797 if (INTEGERP (left))
4798 *root_x = XINT (left);
4799 else if (*root_x + XINT (dx) + width <= FRAME_X_DISPLAY_INFO (f)->width)
4800 /* It fits to the right of the pointer. */
4801 *root_x += XINT (dx);
4802 else if (width + XINT (dx) <= *root_x)
4803 /* It fits to the left of the pointer. */
4804 *root_x -= width + XINT (dx);
4805 else
4806 /* Put it left-justified on the screen--it ought to fit that way. */
4807 *root_x = 0;
4811 DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
4812 doc: /* Show STRING in a "tooltip" window on frame FRAME.
4813 A tooltip window is a small X window displaying a string.
4815 FRAME nil or omitted means use the selected frame.
4817 PARMS is an optional list of frame parameters which can be used to
4818 change the tooltip's appearance.
4820 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
4821 means use the default timeout of 5 seconds.
4823 If the list of frame parameters PARAMS contains a `left' parameters,
4824 the tooltip is displayed at that x-position. Otherwise it is
4825 displayed at the mouse position, with offset DX added (default is 5 if
4826 DX isn't specified). Likewise for the y-position; if a `top' frame
4827 parameter is specified, it determines the y-position of the tooltip
4828 window, otherwise it is displayed at the mouse position, with offset
4829 DY added (default is -10).
4831 A tooltip's maximum size is specified by `x-max-tooltip-size'.
4832 Text larger than the specified size is clipped. */)
4833 (string, frame, parms, timeout, dx, dy)
4834 Lisp_Object string, frame, parms, timeout, dx, dy;
4836 struct frame *f;
4837 struct window *w;
4838 int root_x, root_y;
4839 struct buffer *old_buffer;
4840 struct text_pos pos;
4841 int i, width, height;
4842 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
4843 int old_windows_or_buffers_changed = windows_or_buffers_changed;
4844 int count = SPECPDL_INDEX ();
4846 specbind (Qinhibit_redisplay, Qt);
4848 GCPRO4 (string, parms, frame, timeout);
4850 CHECK_STRING (string);
4851 f = check_x_frame (frame);
4852 if (NILP (timeout))
4853 timeout = make_number (5);
4854 else
4855 CHECK_NATNUM (timeout);
4857 if (NILP (dx))
4858 dx = make_number (5);
4859 else
4860 CHECK_NUMBER (dx);
4862 if (NILP (dy))
4863 dy = make_number (-10);
4864 else
4865 CHECK_NUMBER (dy);
4867 if (NILP (last_show_tip_args))
4868 last_show_tip_args = Fmake_vector (make_number (3), Qnil);
4870 if (!NILP (tip_frame))
4872 Lisp_Object last_string = AREF (last_show_tip_args, 0);
4873 Lisp_Object last_frame = AREF (last_show_tip_args, 1);
4874 Lisp_Object last_parms = AREF (last_show_tip_args, 2);
4876 if (EQ (frame, last_frame)
4877 && !NILP (Fequal (last_string, string))
4878 && !NILP (Fequal (last_parms, parms)))
4880 struct frame *f = XFRAME (tip_frame);
4882 /* Only DX and DY have changed. */
4883 if (!NILP (tip_timer))
4885 Lisp_Object timer = tip_timer;
4886 tip_timer = Qnil;
4887 call1 (Qcancel_timer, timer);
4890 BLOCK_INPUT;
4891 compute_tip_xy (f, parms, dx, dy, FRAME_PIXEL_WIDTH (f),
4892 FRAME_PIXEL_HEIGHT (f), &root_x, &root_y);
4893 XMoveWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4894 root_x, root_y);
4895 UNBLOCK_INPUT;
4896 goto start_timer;
4900 /* Hide a previous tip, if any. */
4901 Fx_hide_tip ();
4903 ASET (last_show_tip_args, 0, string);
4904 ASET (last_show_tip_args, 1, frame);
4905 ASET (last_show_tip_args, 2, parms);
4907 /* Add default values to frame parameters. */
4908 if (NILP (Fassq (Qname, parms)))
4909 parms = Fcons (Fcons (Qname, build_string ("tooltip")), parms);
4910 if (NILP (Fassq (Qinternal_border_width, parms)))
4911 parms = Fcons (Fcons (Qinternal_border_width, make_number (3)), parms);
4912 if (NILP (Fassq (Qborder_width, parms)))
4913 parms = Fcons (Fcons (Qborder_width, make_number (1)), parms);
4914 if (NILP (Fassq (Qborder_color, parms)))
4915 parms = Fcons (Fcons (Qborder_color, build_string ("lightyellow")), parms);
4916 if (NILP (Fassq (Qbackground_color, parms)))
4917 parms = Fcons (Fcons (Qbackground_color, build_string ("lightyellow")),
4918 parms);
4920 /* Create a frame for the tooltip, and record it in the global
4921 variable tip_frame. */
4922 frame = x_create_tip_frame (FRAME_X_DISPLAY_INFO (f), parms, string);
4923 f = XFRAME (frame);
4925 /* Set up the frame's root window. */
4926 w = XWINDOW (FRAME_ROOT_WINDOW (f));
4927 w->left_col = w->top_line = make_number (0);
4929 if (CONSP (Vx_max_tooltip_size)
4930 && INTEGERP (XCAR (Vx_max_tooltip_size))
4931 && XINT (XCAR (Vx_max_tooltip_size)) > 0
4932 && INTEGERP (XCDR (Vx_max_tooltip_size))
4933 && XINT (XCDR (Vx_max_tooltip_size)) > 0)
4935 w->total_cols = XCAR (Vx_max_tooltip_size);
4936 w->total_lines = XCDR (Vx_max_tooltip_size);
4938 else
4940 w->total_cols = make_number (80);
4941 w->total_lines = make_number (40);
4944 FRAME_TOTAL_COLS (f) = XINT (w->total_cols);
4945 adjust_glyphs (f);
4946 w->pseudo_window_p = 1;
4948 /* Display the tooltip text in a temporary buffer. */
4949 old_buffer = current_buffer;
4950 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f))->buffer));
4951 current_buffer->truncate_lines = Qnil;
4952 clear_glyph_matrix (w->desired_matrix);
4953 clear_glyph_matrix (w->current_matrix);
4954 SET_TEXT_POS (pos, BEGV, BEGV_BYTE);
4955 try_window (FRAME_ROOT_WINDOW (f), pos);
4957 /* Compute width and height of the tooltip. */
4958 width = height = 0;
4959 for (i = 0; i < w->desired_matrix->nrows; ++i)
4961 struct glyph_row *row = &w->desired_matrix->rows[i];
4962 struct glyph *last;
4963 int row_width;
4965 /* Stop at the first empty row at the end. */
4966 if (!row->enabled_p || !row->displays_text_p)
4967 break;
4969 /* Let the row go over the full width of the frame. */
4970 row->full_width_p = 1;
4972 /* There's a glyph at the end of rows that is used to place
4973 the cursor there. Don't include the width of this glyph. */
4974 if (row->used[TEXT_AREA])
4976 last = &row->glyphs[TEXT_AREA][row->used[TEXT_AREA] - 1];
4977 row_width = row->pixel_width - last->pixel_width;
4979 else
4980 row_width = row->pixel_width;
4982 height += row->height;
4983 width = max (width, row_width);
4986 /* Add the frame's internal border to the width and height the X
4987 window should have. */
4988 height += 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
4989 width += 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
4991 /* Move the tooltip window where the mouse pointer is. Resize and
4992 show it. */
4993 compute_tip_xy (f, parms, dx, dy, width, height, &root_x, &root_y);
4995 BLOCK_INPUT;
4996 XMoveResizeWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4997 root_x, root_y, width, height);
4998 XMapRaised (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
4999 UNBLOCK_INPUT;
5001 /* Draw into the window. */
5002 w->must_be_updated_p = 1;
5003 update_single_window (w, 1);
5005 /* Restore original current buffer. */
5006 set_buffer_internal_1 (old_buffer);
5007 windows_or_buffers_changed = old_windows_or_buffers_changed;
5009 start_timer:
5010 /* Let the tip disappear after timeout seconds. */
5011 tip_timer = call3 (intern ("run-at-time"), timeout, Qnil,
5012 intern ("x-hide-tip"));
5014 UNGCPRO;
5015 return unbind_to (count, Qnil);
5019 DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
5020 doc: /* Hide the current tooltip window, if there is any.
5021 Value is t if tooltip was open, nil otherwise. */)
5024 int count;
5025 Lisp_Object deleted, frame, timer;
5026 struct gcpro gcpro1, gcpro2;
5028 /* Return quickly if nothing to do. */
5029 if (NILP (tip_timer) && NILP (tip_frame))
5030 return Qnil;
5032 frame = tip_frame;
5033 timer = tip_timer;
5034 GCPRO2 (frame, timer);
5035 tip_frame = tip_timer = deleted = Qnil;
5037 count = SPECPDL_INDEX ();
5038 specbind (Qinhibit_redisplay, Qt);
5039 specbind (Qinhibit_quit, Qt);
5041 if (!NILP (timer))
5042 call1 (Qcancel_timer, timer);
5044 if (FRAMEP (frame))
5046 Fdelete_frame (frame, Qnil);
5047 deleted = Qt;
5049 #ifdef USE_LUCID
5050 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5051 redisplay procedure is not called when a tip frame over menu
5052 items is unmapped. Redisplay the menu manually... */
5054 struct frame *f = SELECTED_FRAME ();
5055 Widget w = f->output_data.x->menubar_widget;
5056 extern void xlwmenu_redisplay P_ ((Widget));
5058 if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f)->screen)
5059 && w != NULL)
5061 BLOCK_INPUT;
5062 xlwmenu_redisplay (w);
5063 UNBLOCK_INPUT;
5066 #endif /* USE_LUCID */
5069 UNGCPRO;
5070 return unbind_to (count, deleted);
5075 /***********************************************************************
5076 File selection dialog
5077 ***********************************************************************/
5079 #ifdef USE_MOTIF
5081 /* Callback for "OK" and "Cancel" on file selection dialog. */
5083 static void
5084 file_dialog_cb (widget, client_data, call_data)
5085 Widget widget;
5086 XtPointer call_data, client_data;
5088 int *result = (int *) client_data;
5089 XmAnyCallbackStruct *cb = (XmAnyCallbackStruct *) call_data;
5090 *result = cb->reason;
5094 /* Callback for unmapping a file selection dialog. This is used to
5095 capture the case where a dialog is closed via a window manager's
5096 closer button, for example. Using a XmNdestroyCallback didn't work
5097 in this case. */
5099 static void
5100 file_dialog_unmap_cb (widget, client_data, call_data)
5101 Widget widget;
5102 XtPointer call_data, client_data;
5104 int *result = (int *) client_data;
5105 *result = XmCR_CANCEL;
5109 DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0,
5110 doc: /* Read file name, prompting with PROMPT in directory DIR.
5111 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5112 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5113 or directory must exist. ONLY-DIR-P is ignored." */)
5114 (prompt, dir, default_filename, mustmatch, only_dir_p)
5115 Lisp_Object prompt, dir, default_filename, mustmatch, only_dir_p;
5117 int result;
5118 struct frame *f = SELECTED_FRAME ();
5119 Lisp_Object file = Qnil;
5120 Widget dialog, text, help;
5121 Arg al[10];
5122 int ac = 0;
5123 extern XtAppContext Xt_app_con;
5124 XmString dir_xmstring, pattern_xmstring;
5125 int count = SPECPDL_INDEX ();
5126 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
5128 GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file);
5129 CHECK_STRING (prompt);
5130 CHECK_STRING (dir);
5132 /* Prevent redisplay. */
5133 specbind (Qinhibit_redisplay, Qt);
5135 BLOCK_INPUT;
5137 /* Create the dialog with PROMPT as title, using DIR as initial
5138 directory and using "*" as pattern. */
5139 dir = Fexpand_file_name (dir, Qnil);
5140 dir_xmstring = XmStringCreateLocalized (SDATA (dir));
5141 pattern_xmstring = XmStringCreateLocalized ("*");
5143 XtSetArg (al[ac], XmNtitle, SDATA (prompt)); ++ac;
5144 XtSetArg (al[ac], XmNdirectory, dir_xmstring); ++ac;
5145 XtSetArg (al[ac], XmNpattern, pattern_xmstring); ++ac;
5146 XtSetArg (al[ac], XmNresizePolicy, XmRESIZE_GROW); ++ac;
5147 XtSetArg (al[ac], XmNdialogStyle, XmDIALOG_APPLICATION_MODAL); ++ac;
5148 dialog = XmCreateFileSelectionDialog (f->output_data.x->widget,
5149 "fsb", al, ac);
5150 XmStringFree (dir_xmstring);
5151 XmStringFree (pattern_xmstring);
5153 /* Add callbacks for OK and Cancel. */
5154 XtAddCallback (dialog, XmNokCallback, file_dialog_cb,
5155 (XtPointer) &result);
5156 XtAddCallback (dialog, XmNcancelCallback, file_dialog_cb,
5157 (XtPointer) &result);
5158 XtAddCallback (dialog, XmNunmapCallback, file_dialog_unmap_cb,
5159 (XtPointer) &result);
5161 /* Remove the help button since we can't display help. */
5162 help = XmFileSelectionBoxGetChild (dialog, XmDIALOG_HELP_BUTTON);
5163 XtUnmanageChild (help);
5165 /* Mark OK button as default. */
5166 XtVaSetValues (XmFileSelectionBoxGetChild (dialog, XmDIALOG_OK_BUTTON),
5167 XmNshowAsDefault, True, NULL);
5169 /* If MUSTMATCH is non-nil, disable the file entry field of the
5170 dialog, so that the user must select a file from the files list
5171 box. We can't remove it because we wouldn't have a way to get at
5172 the result file name, then. */
5173 text = XmFileSelectionBoxGetChild (dialog, XmDIALOG_TEXT);
5174 if (!NILP (mustmatch))
5176 Widget label;
5177 label = XmFileSelectionBoxGetChild (dialog, XmDIALOG_SELECTION_LABEL);
5178 XtSetSensitive (text, False);
5179 XtSetSensitive (label, False);
5182 /* Manage the dialog, so that list boxes get filled. */
5183 XtManageChild (dialog);
5185 if (STRINGP (default_filename))
5187 XmString default_xmstring;
5188 Widget wtext = XmFileSelectionBoxGetChild (dialog, XmDIALOG_TEXT);
5189 Widget list = XmFileSelectionBoxGetChild (dialog, XmDIALOG_LIST);
5191 XmTextPosition last_pos = XmTextFieldGetLastPosition (wtext);
5192 XmTextFieldReplace (wtext, 0, last_pos,
5193 (SDATA (Ffile_name_nondirectory (default_filename))));
5195 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5196 must include the path for this to work. */
5198 default_xmstring = XmStringCreateLocalized (SDATA (default_filename));
5200 if (XmListItemExists (list, default_xmstring))
5202 int item_pos = XmListItemPos (list, default_xmstring);
5203 /* Select the item and scroll it into view. */
5204 XmListSelectPos (list, item_pos, True);
5205 XmListSetPos (list, item_pos);
5208 XmStringFree (default_xmstring);
5211 /* Process events until the user presses Cancel or OK. */
5212 result = 0;
5213 while (result == 0)
5215 XEvent event;
5216 XtAppNextEvent (Xt_app_con, &event);
5217 (void) x_dispatch_event (&event, FRAME_X_DISPLAY (f) );
5220 /* Get the result. */
5221 if (result == XmCR_OK)
5223 XmString text;
5224 String data;
5226 XtVaGetValues (dialog, XmNtextString, &text, NULL);
5227 XmStringGetLtoR (text, XmFONTLIST_DEFAULT_TAG, &data);
5228 XmStringFree (text);
5229 file = build_string (data);
5230 XtFree (data);
5232 else
5233 file = Qnil;
5235 /* Clean up. */
5236 XtUnmanageChild (dialog);
5237 XtDestroyWidget (dialog);
5238 UNBLOCK_INPUT;
5239 UNGCPRO;
5241 /* Make "Cancel" equivalent to C-g. */
5242 if (NILP (file))
5243 Fsignal (Qquit, Qnil);
5245 return unbind_to (count, file);
5248 #endif /* USE_MOTIF */
5250 #ifdef USE_GTK
5252 DEFUN ("x-file-dialog", Fx_file_dialog, Sx_file_dialog, 2, 5, 0,
5253 doc: /* Read file name, prompting with PROMPT in directory DIR.
5254 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5255 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5256 or directory must exist. If ONLY-DIR-P is non-nil, the user can only select
5257 directories. */)
5258 (prompt, dir, default_filename, mustmatch, only_dir_p)
5259 Lisp_Object prompt, dir, default_filename, mustmatch, only_dir_p;
5261 FRAME_PTR f = SELECTED_FRAME ();
5262 char *fn;
5263 Lisp_Object file = Qnil;
5264 int count = specpdl_ptr - specpdl;
5265 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, gcpro6;
5266 char *cdef_file;
5268 GCPRO6 (prompt, dir, default_filename, mustmatch, only_dir_p, file);
5269 CHECK_STRING (prompt);
5270 CHECK_STRING (dir);
5272 /* Prevent redisplay. */
5273 specbind (Qinhibit_redisplay, Qt);
5275 BLOCK_INPUT;
5277 if (STRINGP (default_filename))
5278 cdef_file = SDATA (default_filename);
5279 else
5280 cdef_file = SDATA (dir);
5282 fn = xg_get_file_name (f, SDATA (prompt), cdef_file,
5283 ! NILP (mustmatch),
5284 ! NILP (only_dir_p));
5286 if (fn)
5288 file = build_string (fn);
5289 xfree (fn);
5292 UNBLOCK_INPUT;
5293 UNGCPRO;
5295 /* Make "Cancel" equivalent to C-g. */
5296 if (NILP (file))
5297 Fsignal (Qquit, Qnil);
5299 return unbind_to (count, file);
5302 #endif /* USE_GTK */
5305 /***********************************************************************
5306 Keyboard
5307 ***********************************************************************/
5309 #ifdef HAVE_XKBGETKEYBOARD
5310 #include <X11/XKBlib.h>
5311 #include <X11/keysym.h>
5312 #endif
5314 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p,
5315 Sx_backspace_delete_keys_p, 0, 1, 0,
5316 doc: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
5317 FRAME nil means use the selected frame.
5318 Value is t if we know that both keys are present, and are mapped to the
5319 usual X keysyms. */)
5320 (frame)
5321 Lisp_Object frame;
5323 #ifdef HAVE_XKBGETKEYBOARD
5324 XkbDescPtr kb;
5325 struct frame *f = check_x_frame (frame);
5326 Display *dpy = FRAME_X_DISPLAY (f);
5327 Lisp_Object have_keys;
5328 int major, minor, op, event, error;
5330 BLOCK_INPUT;
5332 /* Check library version in case we're dynamically linked. */
5333 major = XkbMajorVersion;
5334 minor = XkbMinorVersion;
5335 if (!XkbLibraryVersion (&major, &minor))
5337 UNBLOCK_INPUT;
5338 return Qnil;
5341 /* Check that the server supports XKB. */
5342 major = XkbMajorVersion;
5343 minor = XkbMinorVersion;
5344 if (!XkbQueryExtension (dpy, &op, &event, &error, &major, &minor))
5346 UNBLOCK_INPUT;
5347 return Qnil;
5350 have_keys = Qnil;
5351 kb = XkbGetMap (dpy, XkbAllMapComponentsMask, XkbUseCoreKbd);
5352 if (kb)
5354 int delete_keycode = 0, backspace_keycode = 0, i;
5356 if (XkbGetNames (dpy, XkbAllNamesMask, kb) == Success)
5358 for (i = kb->min_key_code;
5359 (i < kb->max_key_code
5360 && (delete_keycode == 0 || backspace_keycode == 0));
5361 ++i)
5363 /* The XKB symbolic key names can be seen most easily in
5364 the PS file generated by `xkbprint -label name
5365 $DISPLAY'. */
5366 if (bcmp ("DELE", kb->names->keys[i].name, 4) == 0)
5367 delete_keycode = i;
5368 else if (bcmp ("BKSP", kb->names->keys[i].name, 4) == 0)
5369 backspace_keycode = i;
5372 XkbFreeNames (kb, 0, True);
5375 XkbFreeClientMap (kb, 0, True);
5377 if (delete_keycode
5378 && backspace_keycode
5379 && XKeysymToKeycode (dpy, XK_Delete) == delete_keycode
5380 && XKeysymToKeycode (dpy, XK_BackSpace) == backspace_keycode)
5381 have_keys = Qt;
5383 UNBLOCK_INPUT;
5384 return have_keys;
5385 #else /* not HAVE_XKBGETKEYBOARD */
5386 return Qnil;
5387 #endif /* not HAVE_XKBGETKEYBOARD */
5392 /***********************************************************************
5393 Initialization
5394 ***********************************************************************/
5396 /* Keep this list in the same order as frame_parms in frame.c.
5397 Use 0 for unsupported frame parameters. */
5399 frame_parm_handler x_frame_parm_handlers[] =
5401 x_set_autoraise,
5402 x_set_autolower,
5403 x_set_background_color,
5404 x_set_border_color,
5405 x_set_border_width,
5406 x_set_cursor_color,
5407 x_set_cursor_type,
5408 x_set_font,
5409 x_set_foreground_color,
5410 x_set_icon_name,
5411 x_set_icon_type,
5412 x_set_internal_border_width,
5413 x_set_menu_bar_lines,
5414 x_set_mouse_color,
5415 x_explicitly_set_name,
5416 x_set_scroll_bar_width,
5417 x_set_title,
5418 x_set_unsplittable,
5419 x_set_vertical_scroll_bars,
5420 x_set_visibility,
5421 x_set_tool_bar_lines,
5422 x_set_scroll_bar_foreground,
5423 x_set_scroll_bar_background,
5424 x_set_screen_gamma,
5425 x_set_line_spacing,
5426 x_set_fringe_width,
5427 x_set_fringe_width,
5428 x_set_wait_for_wm,
5429 x_set_fullscreen,
5432 void
5433 syms_of_xfns ()
5435 /* This is zero if not using X windows. */
5436 x_in_use = 0;
5438 /* The section below is built by the lisp expression at the top of the file,
5439 just above where these variables are declared. */
5440 /*&&& init symbols here &&&*/
5441 Qnone = intern ("none");
5442 staticpro (&Qnone);
5443 Qsuppress_icon = intern ("suppress-icon");
5444 staticpro (&Qsuppress_icon);
5445 Qundefined_color = intern ("undefined-color");
5446 staticpro (&Qundefined_color);
5447 Qcompound_text = intern ("compound-text");
5448 staticpro (&Qcompound_text);
5449 Qcancel_timer = intern ("cancel-timer");
5450 staticpro (&Qcancel_timer);
5451 /* This is the end of symbol initialization. */
5453 /* Text property `display' should be nonsticky by default. */
5454 Vtext_property_default_nonsticky
5455 = Fcons (Fcons (Qdisplay, Qt), Vtext_property_default_nonsticky);
5458 Fput (Qundefined_color, Qerror_conditions,
5459 Fcons (Qundefined_color, Fcons (Qerror, Qnil)));
5460 Fput (Qundefined_color, Qerror_message,
5461 build_string ("Undefined color"));
5463 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape,
5464 doc: /* The shape of the pointer when over text.
5465 Changing the value does not affect existing frames
5466 unless you set the mouse color. */);
5467 Vx_pointer_shape = Qnil;
5469 #if 0 /* This doesn't really do anything. */
5470 DEFVAR_LISP ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape,
5471 doc: /* The shape of the pointer when not over text.
5472 This variable takes effect when you create a new frame
5473 or when you set the mouse color. */);
5474 #endif
5475 Vx_nontext_pointer_shape = Qnil;
5477 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape,
5478 doc: /* The shape of the pointer when Emacs is busy.
5479 This variable takes effect when you create a new frame
5480 or when you set the mouse color. */);
5481 Vx_hourglass_pointer_shape = Qnil;
5483 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p,
5484 doc: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
5485 display_hourglass_p = 1;
5487 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay,
5488 doc: /* *Seconds to wait before displaying an hourglass pointer.
5489 Value must be an integer or float. */);
5490 Vhourglass_delay = make_number (DEFAULT_HOURGLASS_DELAY);
5492 #if 0 /* This doesn't really do anything. */
5493 DEFVAR_LISP ("x-mode-pointer-shape", &Vx_mode_pointer_shape,
5494 doc: /* The shape of the pointer when over the mode line.
5495 This variable takes effect when you create a new frame
5496 or when you set the mouse color. */);
5497 #endif
5498 Vx_mode_pointer_shape = Qnil;
5500 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
5501 &Vx_sensitive_text_pointer_shape,
5502 doc: /* The shape of the pointer when over mouse-sensitive text.
5503 This variable takes effect when you create a new frame
5504 or when you set the mouse color. */);
5505 Vx_sensitive_text_pointer_shape = Qnil;
5507 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
5508 &Vx_window_horizontal_drag_shape,
5509 doc: /* Pointer shape to use for indicating a window can be dragged horizontally.
5510 This variable takes effect when you create a new frame
5511 or when you set the mouse color. */);
5512 Vx_window_horizontal_drag_shape = Qnil;
5514 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel,
5515 doc: /* A string indicating the foreground color of the cursor box. */);
5516 Vx_cursor_fore_pixel = Qnil;
5518 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size,
5519 doc: /* Maximum size for tooltips. Value is a pair (COLUMNS . ROWS).
5520 Text larger than this is clipped. */);
5521 Vx_max_tooltip_size = Fcons (make_number (80), make_number (40));
5523 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager,
5524 doc: /* Non-nil if no X window manager is in use.
5525 Emacs doesn't try to figure this out; this is always nil
5526 unless you set it to something else. */);
5527 /* We don't have any way to find this out, so set it to nil
5528 and maybe the user would like to set it to t. */
5529 Vx_no_window_manager = Qnil;
5531 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
5532 &Vx_pixel_size_width_font_regexp,
5533 doc: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
5535 Since Emacs gets width of a font matching with this regexp from
5536 PIXEL_SIZE field of the name, font finding mechanism gets faster for
5537 such a font. This is especially effective for such large fonts as
5538 Chinese, Japanese, and Korean. */);
5539 Vx_pixel_size_width_font_regexp = Qnil;
5541 #ifdef USE_X_TOOLKIT
5542 Fprovide (intern ("x-toolkit"), Qnil);
5543 #ifdef USE_MOTIF
5544 Fprovide (intern ("motif"), Qnil);
5546 DEFVAR_LISP ("motif-version-string", &Vmotif_version_string,
5547 doc: /* Version info for LessTif/Motif. */);
5548 Vmotif_version_string = build_string (XmVERSION_STRING);
5549 #endif /* USE_MOTIF */
5550 #endif /* USE_X_TOOLKIT */
5552 #ifdef USE_GTK
5553 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
5554 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
5555 But for a user it is a toolkit for X, and indeed, configure
5556 accepts --with-x-toolkit=gtk. */
5557 Fprovide (intern ("x-toolkit"), Qnil);
5558 Fprovide (intern ("gtk"), Qnil);
5560 DEFVAR_LISP ("gtk-version-string", &Vgtk_version_string,
5561 doc: /* Version info for GTK+. */);
5563 char gtk_version[40];
5564 g_snprintf (gtk_version, sizeof (gtk_version), "%u.%u.%u",
5565 GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION);
5566 Vgtk_version_string = build_string (gtk_version);
5568 #endif /* USE_GTK */
5570 /* X window properties. */
5571 defsubr (&Sx_change_window_property);
5572 defsubr (&Sx_delete_window_property);
5573 defsubr (&Sx_window_property);
5575 defsubr (&Sxw_display_color_p);
5576 defsubr (&Sx_display_grayscale_p);
5577 defsubr (&Sxw_color_defined_p);
5578 defsubr (&Sxw_color_values);
5579 defsubr (&Sx_server_max_request_size);
5580 defsubr (&Sx_server_vendor);
5581 defsubr (&Sx_server_version);
5582 defsubr (&Sx_display_pixel_width);
5583 defsubr (&Sx_display_pixel_height);
5584 defsubr (&Sx_display_mm_width);
5585 defsubr (&Sx_display_mm_height);
5586 defsubr (&Sx_display_screens);
5587 defsubr (&Sx_display_planes);
5588 defsubr (&Sx_display_color_cells);
5589 defsubr (&Sx_display_visual_class);
5590 defsubr (&Sx_display_backing_store);
5591 defsubr (&Sx_display_save_under);
5592 defsubr (&Sx_create_frame);
5593 defsubr (&Sx_open_connection);
5594 defsubr (&Sx_close_connection);
5595 defsubr (&Sx_display_list);
5596 defsubr (&Sx_synchronize);
5597 defsubr (&Sx_focus_frame);
5598 defsubr (&Sx_backspace_delete_keys_p);
5600 /* Setting callback functions for fontset handler. */
5601 get_font_info_func = x_get_font_info;
5603 #if 0 /* This function pointer doesn't seem to be used anywhere.
5604 And the pointer assigned has the wrong type, anyway. */
5605 list_fonts_func = x_list_fonts;
5606 #endif
5608 load_font_func = x_load_font;
5609 find_ccl_program_func = x_find_ccl_program;
5610 query_font_func = x_query_font;
5611 set_frame_fontset_func = x_set_font;
5612 check_window_system_func = check_x;
5614 hourglass_atimer = NULL;
5615 hourglass_shown_p = 0;
5617 defsubr (&Sx_show_tip);
5618 defsubr (&Sx_hide_tip);
5619 tip_timer = Qnil;
5620 staticpro (&tip_timer);
5621 tip_frame = Qnil;
5622 staticpro (&tip_frame);
5624 last_show_tip_args = Qnil;
5625 staticpro (&last_show_tip_args);
5627 #if defined (USE_MOTIF) || defined (USE_GTK)
5628 defsubr (&Sx_file_dialog);
5629 #endif
5632 #endif /* HAVE_X_WINDOWS */
5634 /* arch-tag: 55040d02-5485-4d58-8b22-95a7a05f3288
5635 (do not change this comment) */