1 /* Functions for the X window system.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
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)
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., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
30 /* This makes the fields of a Display accessible, in Xlib header files. */
32 #define XLIB_ILLEGAL_ACCESS
39 #include "intervals.h"
40 #include "dispextern.h"
42 #include "blockinput.h"
48 #include "termhooks.h"
54 #include <sys/types.h>
58 #if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */
59 #include "bitmaps/gray.xbm"
61 #include <X11/bitmaps/gray>
64 #include "[.bitmaps]gray.xbm"
72 #include <X11/Shell.h>
75 #include <X11/Xaw/Paned.h>
76 #include <X11/Xaw/Label.h>
77 #endif /* USE_MOTIF */
80 #undef USG /* ####KLUDGE for Solaris 2.2 and up */
89 #include "../lwlib/lwlib.h"
93 #include <Xm/DialogS.h>
94 #include <Xm/FileSB.h>
97 /* Do the EDITRES protocol if running X11R5
98 Exception: HP-UX (at least version A.09.05) has X11R5 without EditRes */
100 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
102 extern void _XEditResCheckMessages ();
103 #endif /* R5 + Athena */
105 /* Unique id counter for widgets created by the Lucid Widget Library. */
107 extern LWLIB_ID widget_id_tick
;
110 /* This is part of a kludge--see lwlib/xlwmenu.c. */
111 extern XFontStruct
*xlwmenu_default_font
;
114 extern void free_frame_menubar ();
115 extern double atof ();
119 /* LessTif/Motif version info. */
121 static Lisp_Object Vmotif_version_string
;
123 #endif /* USE_MOTIF */
125 #endif /* USE_X_TOOLKIT */
129 /* GTK+ version info */
131 static Lisp_Object Vgtk_version_string
;
136 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
138 #define MAXREQUEST(dpy) ((dpy)->max_request_size)
141 /* The gray bitmap `bitmaps/gray'. This is done because xterm.c uses
142 it, and including `bitmaps/gray' more than once is a problem when
143 config.h defines `static' as an empty replacement string. */
145 int gray_bitmap_width
= gray_width
;
146 int gray_bitmap_height
= gray_height
;
147 char *gray_bitmap_bits
= gray_bits
;
149 /* Non-zero means we're allowed to display an hourglass cursor. */
151 int display_hourglass_p
;
153 /* Non-zero means prompt with the old GTK file selection dialog. */
155 int x_use_old_gtk_file_dialog
;
157 /* The background and shape of the mouse pointer, and shape when not
158 over text or in the modeline. */
160 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
161 Lisp_Object Vx_hourglass_pointer_shape
;
163 /* The shape when over mouse-sensitive text. */
165 Lisp_Object Vx_sensitive_text_pointer_shape
;
167 /* If non-nil, the pointer shape to indicate that windows can be
168 dragged horizontally. */
170 Lisp_Object Vx_window_horizontal_drag_shape
;
172 /* Color of chars displayed in cursor box. */
174 Lisp_Object Vx_cursor_fore_pixel
;
176 /* Nonzero if using X. */
180 /* Non nil if no window manager is in use. */
182 Lisp_Object Vx_no_window_manager
;
184 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
186 Lisp_Object Vx_pixel_size_width_font_regexp
;
189 Lisp_Object Qsuppress_icon
;
190 Lisp_Object Qundefined_color
;
191 Lisp_Object Qcompound_text
, Qcancel_timer
;
195 extern Lisp_Object Vwindow_system_version
;
197 /* The below are defined in frame.c. */
200 int image_cache_refcount
, dpyinfo_refcount
;
205 /* Error if we are not connected to X. */
211 error ("X windows are not in use or not initialized");
214 /* Nonzero if we can use mouse menus.
215 You should not call this unless HAVE_MENUS is defined. */
223 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
224 and checking validity for X. */
227 check_x_frame (frame
)
233 frame
= selected_frame
;
234 CHECK_LIVE_FRAME (frame
);
237 error ("Non-X frame used");
241 /* Let the user specify an X display with a frame.
242 nil stands for the selected frame--or, if that is not an X frame,
243 the first X display on the list. */
245 struct x_display_info
*
246 check_x_display_info (frame
)
249 struct x_display_info
*dpyinfo
= NULL
;
253 struct frame
*sf
= XFRAME (selected_frame
);
255 if (FRAME_X_P (sf
) && FRAME_LIVE_P (sf
))
256 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
257 else if (x_display_list
!= 0)
258 dpyinfo
= x_display_list
;
260 error ("X windows are not in use or not initialized");
262 else if (STRINGP (frame
))
263 dpyinfo
= x_display_info_for_name (frame
);
266 FRAME_PTR f
= check_x_frame (frame
);
267 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
274 /* Return the Emacs frame-object corresponding to an X window.
275 It could be the frame's main window or an icon window. */
277 /* This function can be called during GC, so use GC_xxx type test macros. */
280 x_window_to_frame (dpyinfo
, wdesc
)
281 struct x_display_info
*dpyinfo
;
284 Lisp_Object tail
, frame
;
287 if (wdesc
== None
) return 0;
289 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
292 if (!GC_FRAMEP (frame
))
295 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
297 if (f
->output_data
.x
->hourglass_window
== wdesc
)
300 if ((f
->output_data
.x
->edit_widget
301 && XtWindow (f
->output_data
.x
->edit_widget
) == wdesc
)
302 /* A tooltip frame? */
303 || (!f
->output_data
.x
->edit_widget
304 && FRAME_X_WINDOW (f
) == wdesc
)
305 || f
->output_data
.x
->icon_desc
== wdesc
)
307 #else /* not USE_X_TOOLKIT */
309 if (f
->output_data
.x
->edit_widget
)
311 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
312 struct x_output
*x
= f
->output_data
.x
;
313 if (gwdesc
!= 0 && gwdesc
== x
->edit_widget
)
317 if (FRAME_X_WINDOW (f
) == wdesc
318 || f
->output_data
.x
->icon_desc
== wdesc
)
320 #endif /* not USE_X_TOOLKIT */
325 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
326 /* Like x_window_to_frame but also compares the window with the widget's
330 x_any_window_to_frame (dpyinfo
, wdesc
)
331 struct x_display_info
*dpyinfo
;
334 Lisp_Object tail
, frame
;
335 struct frame
*f
, *found
;
338 if (wdesc
== None
) return NULL
;
341 for (tail
= Vframe_list
; GC_CONSP (tail
) && !found
; tail
= XCDR (tail
))
344 if (!GC_FRAMEP (frame
))
348 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
350 /* This frame matches if the window is any of its widgets. */
351 x
= f
->output_data
.x
;
352 if (x
->hourglass_window
== wdesc
)
357 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
359 && (gwdesc
== x
->widget
360 || gwdesc
== x
->edit_widget
361 || gwdesc
== x
->vbox_widget
362 || gwdesc
== x
->menubar_widget
))
365 if (wdesc
== XtWindow (x
->widget
)
366 || wdesc
== XtWindow (x
->column_widget
)
367 || wdesc
== XtWindow (x
->edit_widget
))
369 /* Match if the window is this frame's menubar. */
370 else if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
374 else if (FRAME_X_WINDOW (f
) == wdesc
)
375 /* A tooltip frame. */
383 /* Likewise, but exclude the menu bar widget. */
386 x_non_menubar_window_to_frame (dpyinfo
, wdesc
)
387 struct x_display_info
*dpyinfo
;
390 Lisp_Object tail
, frame
;
394 if (wdesc
== None
) return 0;
396 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
399 if (!GC_FRAMEP (frame
))
402 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
404 x
= f
->output_data
.x
;
405 /* This frame matches if the window is any of its widgets. */
406 if (x
->hourglass_window
== wdesc
)
411 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
413 && (gwdesc
== x
->widget
414 || gwdesc
== x
->edit_widget
415 || gwdesc
== x
->vbox_widget
))
418 if (wdesc
== XtWindow (x
->widget
)
419 || wdesc
== XtWindow (x
->column_widget
)
420 || wdesc
== XtWindow (x
->edit_widget
))
424 else if (FRAME_X_WINDOW (f
) == wdesc
)
425 /* A tooltip frame. */
431 /* Likewise, but consider only the menu bar widget. */
434 x_menubar_window_to_frame (dpyinfo
, wdesc
)
435 struct x_display_info
*dpyinfo
;
438 Lisp_Object tail
, frame
;
442 if (wdesc
== None
) return 0;
444 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
447 if (!GC_FRAMEP (frame
))
450 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
452 x
= f
->output_data
.x
;
453 /* Match if the window is this frame's menubar. */
455 if (x
->menubar_widget
)
457 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
462 && (gwdesc
== x
->menubar_widget
463 || gtk_widget_get_parent (gwdesc
) == x
->menubar_widget
))
469 if (x
->menubar_widget
470 && lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
477 /* Return the frame whose principal (outermost) window is WDESC.
478 If WDESC is some other (smaller) window, we return 0. */
481 x_top_window_to_frame (dpyinfo
, wdesc
)
482 struct x_display_info
*dpyinfo
;
485 Lisp_Object tail
, frame
;
489 if (wdesc
== None
) return 0;
491 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
494 if (!GC_FRAMEP (frame
))
497 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
499 x
= f
->output_data
.x
;
503 /* This frame matches if the window is its topmost widget. */
505 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
506 if (gwdesc
== x
->widget
)
509 if (wdesc
== XtWindow (x
->widget
))
511 #if 0 /* I don't know why it did this,
512 but it seems logically wrong,
513 and it causes trouble for MapNotify events. */
514 /* Match if the window is this frame's menubar. */
515 if (x
->menubar_widget
516 && wdesc
== XtWindow (x
->menubar_widget
))
521 else if (FRAME_X_WINDOW (f
) == wdesc
)
527 #endif /* USE_X_TOOLKIT || USE_GTK */
531 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
532 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
534 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
535 static void x_set_wait_for_wm
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
536 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
537 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
538 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
539 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
540 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
541 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
542 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
543 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
544 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
545 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
546 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
547 void x_set_scroll_bar_foreground
P_ ((struct frame
*, Lisp_Object
,
549 void x_set_scroll_bar_background
P_ ((struct frame
*, Lisp_Object
,
551 static Lisp_Object x_default_scroll_bar_color_parameter
P_ ((struct frame
*,
558 /* Store the screen positions of frame F into XPTR and YPTR.
559 These are the positions of the containing window manager window,
560 not Emacs's own window. */
563 x_real_positions (f
, xptr
, yptr
)
567 int win_x
, win_y
, outer_x
, outer_y
;
568 int real_x
= 0, real_y
= 0;
570 Window win
= f
->output_data
.x
->parent_desc
;
576 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
578 if (win
== FRAME_X_DISPLAY_INFO (f
)->root_window
)
579 win
= FRAME_OUTER_WINDOW (f
);
581 /* This loop traverses up the containment tree until we hit the root
582 window. Window managers may intersect many windows between our window
583 and the root window. The window we find just before the root window
584 should be the outer WM window. */
587 Window wm_window
, rootw
;
588 Window
*tmp_children
;
589 unsigned int tmp_nchildren
;
592 success
= XQueryTree (FRAME_X_DISPLAY (f
), win
, &rootw
,
593 &wm_window
, &tmp_children
, &tmp_nchildren
);
595 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
597 /* Don't free tmp_children if XQueryTree failed. */
601 XFree ((char *) tmp_children
);
603 if (wm_window
== rootw
|| had_errors
)
614 /* Get the real coordinates for the WM window upper left corner */
615 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
616 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
618 /* Translate real coordinates to coordinates relative to our
619 window. For our window, the upper left corner is 0, 0.
620 Since the upper left corner of the WM window is outside
621 our window, win_x and win_y will be negative:
623 ------------------ ---> x
625 | ----------------- v y
628 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
630 /* From-window, to-window. */
631 FRAME_X_DISPLAY_INFO (f
)->root_window
,
634 /* From-position, to-position. */
635 real_x
, real_y
, &win_x
, &win_y
,
640 if (FRAME_X_WINDOW (f
) == FRAME_OUTER_WINDOW (f
))
647 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
649 /* From-window, to-window. */
650 FRAME_X_DISPLAY_INFO (f
)->root_window
,
651 FRAME_OUTER_WINDOW (f
),
653 /* From-position, to-position. */
654 real_x
, real_y
, &outer_x
, &outer_y
,
660 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
663 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
667 if (had_errors
) return;
669 f
->x_pixels_diff
= -win_x
;
670 f
->y_pixels_diff
= -win_y
;
672 FRAME_X_OUTPUT (f
)->x_pixels_outer_diff
= -outer_x
;
673 FRAME_X_OUTPUT (f
)->y_pixels_outer_diff
= -outer_y
;
682 /* Gamma-correct COLOR on frame F. */
685 gamma_correct (f
, color
)
691 color
->red
= pow (color
->red
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
692 color
->green
= pow (color
->green
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
693 color
->blue
= pow (color
->blue
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
698 /* Decide if color named COLOR_NAME is valid for use on frame F. If
699 so, return the RGB values in COLOR. If ALLOC_P is non-zero,
700 allocate the color. Value is zero if COLOR_NAME is invalid, or
701 no color could be allocated. */
704 x_defined_color (f
, color_name
, color
, alloc_p
)
711 Display
*dpy
= FRAME_X_DISPLAY (f
);
712 Colormap cmap
= FRAME_X_COLORMAP (f
);
715 success_p
= XParseColor (dpy
, cmap
, color_name
, color
);
716 if (success_p
&& alloc_p
)
717 success_p
= x_alloc_nearest_color (f
, cmap
, color
);
724 /* Return the pixel color value for color COLOR_NAME on frame F. If F
725 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
726 Signal an error if color can't be allocated. */
729 x_decode_color (f
, color_name
, mono_color
)
731 Lisp_Object color_name
;
736 CHECK_STRING (color_name
);
738 #if 0 /* Don't do this. It's wrong when we're not using the default
739 colormap, it makes freeing difficult, and it's probably not
740 an important optimization. */
741 if (strcmp (SDATA (color_name
), "black") == 0)
742 return BLACK_PIX_DEFAULT (f
);
743 else if (strcmp (SDATA (color_name
), "white") == 0)
744 return WHITE_PIX_DEFAULT (f
);
747 /* Return MONO_COLOR for monochrome frames. */
748 if (FRAME_X_DISPLAY_INFO (f
)->n_planes
== 1)
751 /* x_defined_color is responsible for coping with failures
752 by looking for a near-miss. */
753 if (x_defined_color (f
, SDATA (color_name
), &cdef
, 1))
756 Fsignal (Qerror
, Fcons (build_string ("Undefined color"),
757 Fcons (color_name
, Qnil
)));
763 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
764 the previous value of that parameter, NEW_VALUE is the new value.
765 See also the comment of wait_for_wm in struct x_output. */
768 x_set_wait_for_wm (f
, new_value
, old_value
)
770 Lisp_Object new_value
, old_value
;
772 f
->output_data
.x
->wait_for_wm
= !NILP (new_value
);
777 /* Set icon from FILE for frame F. By using GTK functions the icon
778 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
781 xg_set_icon (f
, file
)
791 found
= x_find_image_file (file
);
799 filename
= SDATA (found
);
802 pixbuf
= gdk_pixbuf_new_from_file (filename
, &err
);
806 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
808 g_object_unref (pixbuf
);
823 xg_set_icon_from_xpm_data (f
, data
)
829 GdkPixbuf
*pixbuf
= gdk_pixbuf_new_from_xpm_data (data
);
837 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
839 g_object_unref (pixbuf
);
845 /* Functions called only from `x_set_frame_param'
846 to set individual parameters.
848 If FRAME_X_WINDOW (f) is 0,
849 the frame is being created and its X-window does not exist yet.
850 In that case, just record the parameter's new value
851 in the standard place; do not attempt to change the window. */
854 x_set_foreground_color (f
, arg
, oldval
)
856 Lisp_Object arg
, oldval
;
858 struct x_output
*x
= f
->output_data
.x
;
859 unsigned long fg
, old_fg
;
861 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
862 old_fg
= x
->foreground_pixel
;
863 x
->foreground_pixel
= fg
;
865 if (FRAME_X_WINDOW (f
) != 0)
867 Display
*dpy
= FRAME_X_DISPLAY (f
);
870 XSetForeground (dpy
, x
->normal_gc
, fg
);
871 XSetBackground (dpy
, x
->reverse_gc
, fg
);
873 if (x
->cursor_pixel
== old_fg
)
875 unload_color (f
, x
->cursor_pixel
);
876 x
->cursor_pixel
= x_copy_color (f
, fg
);
877 XSetBackground (dpy
, x
->cursor_gc
, x
->cursor_pixel
);
882 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
884 if (FRAME_VISIBLE_P (f
))
888 unload_color (f
, old_fg
);
892 x_set_background_color (f
, arg
, oldval
)
894 Lisp_Object arg
, oldval
;
896 struct x_output
*x
= f
->output_data
.x
;
899 bg
= x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
900 unload_color (f
, x
->background_pixel
);
901 x
->background_pixel
= bg
;
903 if (FRAME_X_WINDOW (f
) != 0)
905 Display
*dpy
= FRAME_X_DISPLAY (f
);
908 XSetBackground (dpy
, x
->normal_gc
, bg
);
909 XSetForeground (dpy
, x
->reverse_gc
, bg
);
910 XSetWindowBackground (dpy
, FRAME_X_WINDOW (f
), bg
);
911 XSetForeground (dpy
, x
->cursor_gc
, bg
);
914 xg_set_background_color (f
, bg
);
917 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
918 toolkit scroll bars. */
921 for (bar
= FRAME_SCROLL_BARS (f
);
923 bar
= XSCROLL_BAR (bar
)->next
)
925 Window window
= SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
));
926 XSetWindowBackground (dpy
, window
, bg
);
929 #endif /* USE_TOOLKIT_SCROLL_BARS */
932 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
934 if (FRAME_VISIBLE_P (f
))
940 x_set_mouse_color (f
, arg
, oldval
)
942 Lisp_Object arg
, oldval
;
944 struct x_output
*x
= f
->output_data
.x
;
945 Display
*dpy
= FRAME_X_DISPLAY (f
);
946 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
947 Cursor hourglass_cursor
, horizontal_drag_cursor
;
949 unsigned long pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
950 unsigned long mask_color
= x
->background_pixel
;
952 /* Don't let pointers be invisible. */
953 if (mask_color
== pixel
)
955 x_free_colors (f
, &pixel
, 1);
956 pixel
= x_copy_color (f
, x
->foreground_pixel
);
959 unload_color (f
, x
->mouse_pixel
);
960 x
->mouse_pixel
= pixel
;
964 /* It's not okay to crash if the user selects a screwy cursor. */
965 count
= x_catch_errors (dpy
);
967 if (!NILP (Vx_pointer_shape
))
969 CHECK_NUMBER (Vx_pointer_shape
);
970 cursor
= XCreateFontCursor (dpy
, XINT (Vx_pointer_shape
));
973 cursor
= XCreateFontCursor (dpy
, XC_xterm
);
974 x_check_errors (dpy
, "bad text pointer cursor: %s");
976 if (!NILP (Vx_nontext_pointer_shape
))
978 CHECK_NUMBER (Vx_nontext_pointer_shape
);
980 = XCreateFontCursor (dpy
, XINT (Vx_nontext_pointer_shape
));
983 nontext_cursor
= XCreateFontCursor (dpy
, XC_left_ptr
);
984 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
986 if (!NILP (Vx_hourglass_pointer_shape
))
988 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
990 = XCreateFontCursor (dpy
, XINT (Vx_hourglass_pointer_shape
));
993 hourglass_cursor
= XCreateFontCursor (dpy
, XC_watch
);
994 x_check_errors (dpy
, "bad hourglass pointer cursor: %s");
996 if (!NILP (Vx_mode_pointer_shape
))
998 CHECK_NUMBER (Vx_mode_pointer_shape
);
999 mode_cursor
= XCreateFontCursor (dpy
, XINT (Vx_mode_pointer_shape
));
1002 mode_cursor
= XCreateFontCursor (dpy
, XC_xterm
);
1003 x_check_errors (dpy
, "bad modeline pointer cursor: %s");
1005 if (!NILP (Vx_sensitive_text_pointer_shape
))
1007 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1009 = XCreateFontCursor (dpy
, XINT (Vx_sensitive_text_pointer_shape
));
1012 hand_cursor
= XCreateFontCursor (dpy
, XC_hand2
);
1014 if (!NILP (Vx_window_horizontal_drag_shape
))
1016 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1017 horizontal_drag_cursor
1018 = XCreateFontCursor (dpy
, XINT (Vx_window_horizontal_drag_shape
));
1021 horizontal_drag_cursor
1022 = XCreateFontCursor (dpy
, XC_sb_h_double_arrow
);
1024 /* Check and report errors with the above calls. */
1025 x_check_errors (dpy
, "can't set cursor shape: %s");
1026 x_uncatch_errors (dpy
, count
);
1029 XColor fore_color
, back_color
;
1031 fore_color
.pixel
= x
->mouse_pixel
;
1032 x_query_color (f
, &fore_color
);
1033 back_color
.pixel
= mask_color
;
1034 x_query_color (f
, &back_color
);
1036 XRecolorCursor (dpy
, cursor
, &fore_color
, &back_color
);
1037 XRecolorCursor (dpy
, nontext_cursor
, &fore_color
, &back_color
);
1038 XRecolorCursor (dpy
, mode_cursor
, &fore_color
, &back_color
);
1039 XRecolorCursor (dpy
, hand_cursor
, &fore_color
, &back_color
);
1040 XRecolorCursor (dpy
, hourglass_cursor
, &fore_color
, &back_color
);
1041 XRecolorCursor (dpy
, horizontal_drag_cursor
, &fore_color
, &back_color
);
1044 if (FRAME_X_WINDOW (f
) != 0)
1045 XDefineCursor (dpy
, FRAME_X_WINDOW (f
), cursor
);
1047 if (cursor
!= x
->text_cursor
1048 && x
->text_cursor
!= 0)
1049 XFreeCursor (dpy
, x
->text_cursor
);
1050 x
->text_cursor
= cursor
;
1052 if (nontext_cursor
!= x
->nontext_cursor
1053 && x
->nontext_cursor
!= 0)
1054 XFreeCursor (dpy
, x
->nontext_cursor
);
1055 x
->nontext_cursor
= nontext_cursor
;
1057 if (hourglass_cursor
!= x
->hourglass_cursor
1058 && x
->hourglass_cursor
!= 0)
1059 XFreeCursor (dpy
, x
->hourglass_cursor
);
1060 x
->hourglass_cursor
= hourglass_cursor
;
1062 if (mode_cursor
!= x
->modeline_cursor
1063 && x
->modeline_cursor
!= 0)
1064 XFreeCursor (dpy
, f
->output_data
.x
->modeline_cursor
);
1065 x
->modeline_cursor
= mode_cursor
;
1067 if (hand_cursor
!= x
->hand_cursor
1068 && x
->hand_cursor
!= 0)
1069 XFreeCursor (dpy
, x
->hand_cursor
);
1070 x
->hand_cursor
= hand_cursor
;
1072 if (horizontal_drag_cursor
!= x
->horizontal_drag_cursor
1073 && x
->horizontal_drag_cursor
!= 0)
1074 XFreeCursor (dpy
, x
->horizontal_drag_cursor
);
1075 x
->horizontal_drag_cursor
= horizontal_drag_cursor
;
1080 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1084 x_set_cursor_color (f
, arg
, oldval
)
1086 Lisp_Object arg
, oldval
;
1088 unsigned long fore_pixel
, pixel
;
1089 int fore_pixel_allocated_p
= 0, pixel_allocated_p
= 0;
1090 struct x_output
*x
= f
->output_data
.x
;
1092 if (!NILP (Vx_cursor_fore_pixel
))
1094 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1095 WHITE_PIX_DEFAULT (f
));
1096 fore_pixel_allocated_p
= 1;
1099 fore_pixel
= x
->background_pixel
;
1101 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1102 pixel_allocated_p
= 1;
1104 /* Make sure that the cursor color differs from the background color. */
1105 if (pixel
== x
->background_pixel
)
1107 if (pixel_allocated_p
)
1109 x_free_colors (f
, &pixel
, 1);
1110 pixel_allocated_p
= 0;
1113 pixel
= x
->mouse_pixel
;
1114 if (pixel
== fore_pixel
)
1116 if (fore_pixel_allocated_p
)
1118 x_free_colors (f
, &fore_pixel
, 1);
1119 fore_pixel_allocated_p
= 0;
1121 fore_pixel
= x
->background_pixel
;
1125 unload_color (f
, x
->cursor_foreground_pixel
);
1126 if (!fore_pixel_allocated_p
)
1127 fore_pixel
= x_copy_color (f
, fore_pixel
);
1128 x
->cursor_foreground_pixel
= fore_pixel
;
1130 unload_color (f
, x
->cursor_pixel
);
1131 if (!pixel_allocated_p
)
1132 pixel
= x_copy_color (f
, pixel
);
1133 x
->cursor_pixel
= pixel
;
1135 if (FRAME_X_WINDOW (f
) != 0)
1138 XSetBackground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, x
->cursor_pixel
);
1139 XSetForeground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, fore_pixel
);
1142 if (FRAME_VISIBLE_P (f
))
1144 x_update_cursor (f
, 0);
1145 x_update_cursor (f
, 1);
1149 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1152 /* Set the border-color of frame F to pixel value PIX.
1153 Note that this does not fully take effect if done before
1154 F has an x-window. */
1157 x_set_border_pixel (f
, pix
)
1161 unload_color (f
, f
->output_data
.x
->border_pixel
);
1162 f
->output_data
.x
->border_pixel
= pix
;
1164 if (FRAME_X_WINDOW (f
) != 0 && f
->border_width
> 0)
1167 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1168 (unsigned long)pix
);
1171 if (FRAME_VISIBLE_P (f
))
1176 /* Set the border-color of frame F to value described by ARG.
1177 ARG can be a string naming a color.
1178 The border-color is used for the border that is drawn by the X server.
1179 Note that this does not fully take effect if done before
1180 F has an x-window; it must be redone when the window is created.
1182 Note: this is done in two routines because of the way X10 works.
1184 Note: under X11, this is normally the province of the window manager,
1185 and so emacs' border colors may be overridden. */
1188 x_set_border_color (f
, arg
, oldval
)
1190 Lisp_Object arg
, oldval
;
1195 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1196 x_set_border_pixel (f
, pix
);
1197 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1202 x_set_cursor_type (f
, arg
, oldval
)
1204 Lisp_Object arg
, oldval
;
1206 set_frame_cursor_types (f
, arg
);
1208 /* Make sure the cursor gets redrawn. */
1209 cursor_type_changed
= 1;
1213 x_set_icon_type (f
, arg
, oldval
)
1215 Lisp_Object arg
, oldval
;
1221 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1224 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1229 result
= x_text_icon (f
,
1230 (char *) SDATA ((!NILP (f
->icon_name
)
1234 result
= x_bitmap_icon (f
, arg
);
1239 error ("No icon window available");
1242 XFlush (FRAME_X_DISPLAY (f
));
1247 x_set_icon_name (f
, arg
, oldval
)
1249 Lisp_Object arg
, oldval
;
1255 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1258 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1263 if (f
->output_data
.x
->icon_bitmap
!= 0)
1268 result
= x_text_icon (f
,
1269 (char *) SDATA ((!NILP (f
->icon_name
)
1278 error ("No icon window available");
1281 XFlush (FRAME_X_DISPLAY (f
));
1287 x_set_menu_bar_lines (f
, value
, oldval
)
1289 Lisp_Object value
, oldval
;
1292 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
1293 int olines
= FRAME_MENU_BAR_LINES (f
);
1296 /* Right now, menu bars don't work properly in minibuf-only frames;
1297 most of the commands try to apply themselves to the minibuffer
1298 frame itself, and get an error because you can't switch buffers
1299 in or split the minibuffer window. */
1300 if (FRAME_MINIBUF_ONLY_P (f
))
1303 if (INTEGERP (value
))
1304 nlines
= XINT (value
);
1308 /* Make sure we redisplay all windows in this frame. */
1309 windows_or_buffers_changed
++;
1311 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
1312 FRAME_MENU_BAR_LINES (f
) = 0;
1315 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1316 if (FRAME_X_P (f
) && f
->output_data
.x
->menubar_widget
== 0)
1317 /* Make sure next redisplay shows the menu bar. */
1318 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= Qt
;
1322 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1323 free_frame_menubar (f
);
1324 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1326 f
->output_data
.x
->menubar_widget
= 0;
1328 #else /* not USE_X_TOOLKIT && not USE_GTK */
1329 FRAME_MENU_BAR_LINES (f
) = nlines
;
1330 change_window_heights (f
->root_window
, nlines
- olines
);
1331 #endif /* not USE_X_TOOLKIT */
1336 /* Set the number of lines used for the tool bar of frame F to VALUE.
1337 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1338 is the old number of tool bar lines. This function changes the
1339 height of all windows on frame F to match the new tool bar height.
1340 The frame's height doesn't change. */
1343 x_set_tool_bar_lines (f
, value
, oldval
)
1345 Lisp_Object value
, oldval
;
1347 int delta
, nlines
, root_height
;
1348 Lisp_Object root_window
;
1350 /* Treat tool bars like menu bars. */
1351 if (FRAME_MINIBUF_ONLY_P (f
))
1354 /* Use VALUE only if an integer >= 0. */
1355 if (INTEGERP (value
) && XINT (value
) >= 0)
1356 nlines
= XFASTINT (value
);
1361 FRAME_TOOL_BAR_LINES (f
) = 0;
1364 FRAME_EXTERNAL_TOOL_BAR (f
) = 1;
1365 if (FRAME_X_P (f
) && f
->output_data
.x
->toolbar_widget
== 0)
1366 /* Make sure next redisplay shows the tool bar. */
1367 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= Qt
;
1368 update_frame_tool_bar (f
);
1372 if (FRAME_EXTERNAL_TOOL_BAR (f
))
1373 free_frame_tool_bar (f
);
1374 FRAME_EXTERNAL_TOOL_BAR (f
) = 0;
1380 /* Make sure we redisplay all windows in this frame. */
1381 ++windows_or_buffers_changed
;
1383 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1385 /* Don't resize the tool-bar to more than we have room for. */
1386 root_window
= FRAME_ROOT_WINDOW (f
);
1387 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1388 if (root_height
- delta
< 1)
1390 delta
= root_height
- 1;
1391 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1394 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1395 change_window_heights (root_window
, delta
);
1398 /* We also have to make sure that the internal border at the top of
1399 the frame, below the menu bar or tool bar, is redrawn when the
1400 tool bar disappears. This is so because the internal border is
1401 below the tool bar if one is displayed, but is below the menu bar
1402 if there isn't a tool bar. The tool bar draws into the area
1403 below the menu bar. */
1404 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1408 clear_current_matrices (f
);
1409 updating_frame
= NULL
;
1412 /* If the tool bar gets smaller, the internal border below it
1413 has to be cleared. It was formerly part of the display
1414 of the larger tool bar, and updating windows won't clear it. */
1417 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1418 int width
= FRAME_PIXEL_WIDTH (f
);
1419 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1421 /* height can be zero here. */
1422 if (height
> 0 && width
> 0)
1425 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1426 0, y
, width
, height
, False
);
1430 if (WINDOWP (f
->tool_bar_window
))
1431 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1436 /* Set the foreground color for scroll bars on frame F to VALUE.
1437 VALUE should be a string, a color name. If it isn't a string or
1438 isn't a valid color name, do nothing. OLDVAL is the old value of
1439 the frame parameter. */
1442 x_set_scroll_bar_foreground (f
, value
, oldval
)
1444 Lisp_Object value
, oldval
;
1446 unsigned long pixel
;
1448 if (STRINGP (value
))
1449 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
1453 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
1454 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
1456 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
1457 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1459 /* Remove all scroll bars because they have wrong colors. */
1460 if (condemn_scroll_bars_hook
)
1461 (*condemn_scroll_bars_hook
) (f
);
1462 if (judge_scroll_bars_hook
)
1463 (*judge_scroll_bars_hook
) (f
);
1465 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
1471 /* Set the background color for scroll bars on frame F to VALUE VALUE
1472 should be a string, a color name. If it isn't a string or isn't a
1473 valid color name, do nothing. OLDVAL is the old value of the frame
1477 x_set_scroll_bar_background (f
, value
, oldval
)
1479 Lisp_Object value
, oldval
;
1481 unsigned long pixel
;
1483 if (STRINGP (value
))
1484 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
1488 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
1489 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
1491 #ifdef USE_TOOLKIT_SCROLL_BARS
1492 /* Scrollbar shadow colors. */
1493 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
1495 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
1496 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
1498 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
1500 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
1501 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
1503 #endif /* USE_TOOLKIT_SCROLL_BARS */
1505 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
1506 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1508 /* Remove all scroll bars because they have wrong colors. */
1509 if (condemn_scroll_bars_hook
)
1510 (*condemn_scroll_bars_hook
) (f
);
1511 if (judge_scroll_bars_hook
)
1512 (*judge_scroll_bars_hook
) (f
);
1514 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
1520 /* Encode Lisp string STRING as a text in a format appropriate for
1521 XICCC (X Inter Client Communication Conventions).
1523 If STRING contains only ASCII characters, do no conversion and
1524 return the string data of STRING. Otherwise, encode the text by
1525 CODING_SYSTEM, and return a newly allocated memory area which
1526 should be freed by `xfree' by a caller.
1528 SELECTIONP non-zero means the string is being encoded for an X
1529 selection, so it is safe to run pre-write conversions (which
1532 Store the byte length of resulting text in *TEXT_BYTES.
1534 If the text contains only ASCII and Latin-1, store 1 in *STRING_P,
1535 which means that the `encoding' of the result can be `STRING'.
1536 Otherwise store 0 in *STRINGP, which means that the `encoding' of
1537 the result should be `COMPOUND_TEXT'. */
1539 static unsigned char *
1540 x_encode_text (string
, coding_system
, selectionp
, text_bytes
, stringp
, freep
)
1541 Lisp_Object string
, coding_system
;
1542 int *text_bytes
, *stringp
;
1546 unsigned char *str
= SDATA (string
);
1547 int chars
= SCHARS (string
);
1548 int bytes
= SBYTES (string
);
1552 struct coding_system coding
;
1553 extern Lisp_Object Qcompound_text_with_extensions
;
1555 charset_info
= find_charset_in_text (str
, chars
, bytes
, NULL
, Qnil
);
1556 if (charset_info
== 0)
1558 /* No multibyte character in OBJ. We need not encode it. */
1559 *text_bytes
= bytes
;
1565 setup_coding_system (coding_system
, &coding
);
1567 && SYMBOLP (coding
.pre_write_conversion
)
1568 && !NILP (Ffboundp (coding
.pre_write_conversion
)))
1570 string
= run_pre_post_conversion_on_str (string
, &coding
, 1);
1571 str
= SDATA (string
);
1572 chars
= SCHARS (string
);
1573 bytes
= SBYTES (string
);
1575 coding
.src_multibyte
= 1;
1576 coding
.dst_multibyte
= 0;
1577 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
1578 if (coding
.type
== coding_type_iso2022
)
1579 coding
.flags
|= CODING_FLAG_ISO_SAFE
;
1580 /* We suppress producing escape sequences for composition. */
1581 coding
.composing
= COMPOSITION_DISABLED
;
1582 bufsize
= encoding_buffer_size (&coding
, bytes
);
1583 buf
= (unsigned char *) xmalloc (bufsize
);
1584 encode_coding (&coding
, str
, buf
, bytes
, bufsize
);
1585 *text_bytes
= coding
.produced
;
1586 *stringp
= (charset_info
== 1
1587 || (!EQ (coding_system
, Qcompound_text
)
1588 && !EQ (coding_system
, Qcompound_text_with_extensions
)));
1594 /* Set the WM name to NAME for frame F. Also set the icon name.
1595 If the frame already has an icon name, use that, otherwise set the
1596 icon name to NAME. */
1599 x_set_name_internal (f
, name
)
1603 if (FRAME_X_WINDOW (f
))
1608 XTextProperty text
, icon
;
1610 int do_free_icon_value
= 0, do_free_text_value
= 0;
1611 Lisp_Object coding_system
;
1613 coding_system
= Qcompound_text
;
1614 /* Note: Encoding strategy
1616 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1617 text.encoding. But, there are non-internationalized window
1618 managers which don't support that encoding. So, if NAME
1619 contains only ASCII and 8859-1 characters, encode it by
1620 iso-latin-1, and use "STRING" in text.encoding hoping that
1621 such window managers at least analyze this format correctly,
1622 i.e. treat 8-bit bytes as 8859-1 characters.
1624 We may also be able to use "UTF8_STRING" in text.encoding
1625 in the future which can encode all Unicode characters.
1626 But, for the moment, there's no way to know that the
1627 current window manager supports it or not. */
1628 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
,
1629 &do_free_text_value
);
1630 text
.encoding
= (stringp
? XA_STRING
1631 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1633 text
.nitems
= bytes
;
1635 if (NILP (f
->icon_name
))
1641 /* See the above comment "Note: Encoding strategy". */
1642 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
1643 &bytes
, &stringp
, &do_free_icon_value
);
1644 icon
.encoding
= (stringp
? XA_STRING
1645 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1647 icon
.nitems
= bytes
;
1651 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1652 SDATA (ENCODE_UTF_8 (name
)));
1653 #else /* not USE_GTK */
1654 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1655 #endif /* not USE_GTK */
1657 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &icon
);
1659 if (do_free_icon_value
)
1661 if (do_free_text_value
)
1664 #else /* not HAVE_X11R4 */
1665 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1667 XStoreName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1669 #endif /* not HAVE_X11R4 */
1674 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1677 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1678 name; if NAME is a string, set F's name to NAME and set
1679 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1681 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1682 suggesting a new name, which lisp code should override; if
1683 F->explicit_name is set, ignore the new name; otherwise, set it. */
1686 x_set_name (f
, name
, explicit)
1691 /* Make sure that requests from lisp code override requests from
1692 Emacs redisplay code. */
1695 /* If we're switching from explicit to implicit, we had better
1696 update the mode lines and thereby update the title. */
1697 if (f
->explicit_name
&& NILP (name
))
1698 update_mode_lines
= 1;
1700 f
->explicit_name
= ! NILP (name
);
1702 else if (f
->explicit_name
)
1705 /* If NAME is nil, set the name to the x_id_name. */
1708 /* Check for no change needed in this very common case
1709 before we do any consing. */
1710 if (!strcmp (FRAME_X_DISPLAY_INFO (f
)->x_id_name
,
1713 name
= build_string (FRAME_X_DISPLAY_INFO (f
)->x_id_name
);
1716 CHECK_STRING (name
);
1718 /* Don't change the name if it's already NAME. */
1719 if (! NILP (Fstring_equal (name
, f
->name
)))
1724 /* For setting the frame title, the title parameter should override
1725 the name parameter. */
1726 if (! NILP (f
->title
))
1729 x_set_name_internal (f
, name
);
1732 /* This function should be called when the user's lisp code has
1733 specified a name for the frame; the name will override any set by the
1736 x_explicitly_set_name (f
, arg
, oldval
)
1738 Lisp_Object arg
, oldval
;
1740 x_set_name (f
, arg
, 1);
1743 /* This function should be called by Emacs redisplay code to set the
1744 name; names set this way will never override names set by the user's
1747 x_implicitly_set_name (f
, arg
, oldval
)
1749 Lisp_Object arg
, oldval
;
1751 x_set_name (f
, arg
, 0);
1754 /* Change the title of frame F to NAME.
1755 If NAME is nil, use the frame name as the title.
1757 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1758 name; if NAME is a string, set F's name to NAME and set
1759 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1761 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1762 suggesting a new name, which lisp code should override; if
1763 F->explicit_name is set, ignore the new name; otherwise, set it. */
1766 x_set_title (f
, name
, old_name
)
1768 Lisp_Object name
, old_name
;
1770 /* Don't change the title if it's already NAME. */
1771 if (EQ (name
, f
->title
))
1774 update_mode_lines
= 1;
1781 CHECK_STRING (name
);
1783 x_set_name_internal (f
, name
);
1787 x_set_scroll_bar_default_width (f
)
1790 int wid
= FRAME_COLUMN_WIDTH (f
);
1792 #ifdef USE_TOOLKIT_SCROLL_BARS
1793 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1794 int width
= 16 + 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1795 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (width
+ wid
- 1) / wid
;
1796 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = width
;
1798 /* Make the actual width at least 14 pixels and a multiple of a
1800 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
1802 /* Use all of that space (aside from required margins) for the
1804 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = 0;
1809 /* Record in frame F the specified or default value according to ALIST
1810 of the parameter named PROP (a Lisp symbol). If no value is
1811 specified for PROP, look for an X default for XPROP on the frame
1812 named NAME. If that is not found either, use the value DEFLT. */
1815 x_default_scroll_bar_color_parameter (f
, alist
, prop
, xprop
, xclass
,
1824 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1827 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
1828 if (EQ (tem
, Qunbound
))
1830 #ifdef USE_TOOLKIT_SCROLL_BARS
1832 /* See if an X resource for the scroll bar color has been
1834 tem
= display_x_get_resource (dpyinfo
,
1835 build_string (foreground_p
1839 build_string ("verticalScrollBar"),
1843 /* If nothing has been specified, scroll bars will use a
1844 toolkit-dependent default. Because these defaults are
1845 difficult to get at without actually creating a scroll
1846 bar, use nil to indicate that no color has been
1851 #else /* not USE_TOOLKIT_SCROLL_BARS */
1855 #endif /* not USE_TOOLKIT_SCROLL_BARS */
1858 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
1864 #if !defined (HAVE_X11R4) && !defined (HAVE_XSETWMPROTOCOLS)
1867 XSetWMProtocols (dpy
, w
, protocols
, count
)
1874 prop
= XInternAtom (dpy
, "WM_PROTOCOLS", False
);
1875 if (prop
== None
) return False
;
1876 XChangeProperty (dpy
, w
, prop
, XA_ATOM
, 32, PropModeReplace
,
1877 (unsigned char *) protocols
, count
);
1880 #endif /* not HAVE_X11R4 && not HAVE_XSETWMPROTOCOLS */
1882 #ifdef USE_X_TOOLKIT
1884 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
1885 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
1886 already be present because of the toolkit (Motif adds some of them,
1887 for example, but Xt doesn't). */
1890 hack_wm_protocols (f
, widget
)
1894 Display
*dpy
= XtDisplay (widget
);
1895 Window w
= XtWindow (widget
);
1896 int need_delete
= 1;
1903 unsigned char *catoms
;
1905 unsigned long nitems
= 0;
1906 unsigned long bytes_after
;
1908 if ((XGetWindowProperty (dpy
, w
,
1909 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1910 (long)0, (long)100, False
, XA_ATOM
,
1911 &type
, &format
, &nitems
, &bytes_after
,
1914 && format
== 32 && type
== XA_ATOM
)
1916 Atom
*atoms
= (Atom
*) catoms
;
1921 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
1923 else if (atoms
[nitems
]
1924 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
1926 else if (atoms
[nitems
]
1927 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
1938 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
1940 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
1942 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
1944 XChangeProperty (dpy
, w
, FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1945 XA_ATOM
, 32, PropModeAppend
,
1946 (unsigned char *) props
, count
);
1954 /* Support routines for XIC (X Input Context). */
1958 static XFontSet xic_create_xfontset
P_ ((struct frame
*, char *));
1959 static XIMStyle best_xim_style
P_ ((XIMStyles
*, XIMStyles
*));
1962 /* Supported XIM styles, ordered by preference. */
1964 static XIMStyle supported_xim_styles
[] =
1966 XIMPreeditPosition
| XIMStatusArea
,
1967 XIMPreeditPosition
| XIMStatusNothing
,
1968 XIMPreeditPosition
| XIMStatusNone
,
1969 XIMPreeditNothing
| XIMStatusArea
,
1970 XIMPreeditNothing
| XIMStatusNothing
,
1971 XIMPreeditNothing
| XIMStatusNone
,
1972 XIMPreeditNone
| XIMStatusArea
,
1973 XIMPreeditNone
| XIMStatusNothing
,
1974 XIMPreeditNone
| XIMStatusNone
,
1979 /* Create an X fontset on frame F with base font name BASE_FONTNAME. */
1981 char xic_defaut_fontset
[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
1983 /* Create an Xt fontset spec from the name of a base font.
1984 If `motif' is True use the Motif syntax. */
1986 xic_create_fontsetname (base_fontname
, motif
)
1987 char *base_fontname
;
1990 const char *sep
= motif
? ";" : ",";
1993 /* Make a fontset name from the base font name. */
1994 if (xic_defaut_fontset
== base_fontname
)
1995 { /* There is no base font name, use the default. */
1996 int len
= strlen (base_fontname
) + 2;
1997 fontsetname
= xmalloc (len
);
1998 bzero (fontsetname
, len
);
1999 strcpy (fontsetname
, base_fontname
);
2003 /* Make a fontset name from the base font name.
2004 The font set will be made of the following elements:
2006 - the base font where the charset spec is replaced by -*-*.
2007 - the same but with the family also replaced with -*-*-. */
2008 char *p
= base_fontname
;
2011 for (i
= 0; *p
; p
++)
2014 { /* As the font name doesn't conform to XLFD, we can't
2015 modify it to generalize it to allcs and allfamilies.
2016 Use the specified font plus the default. */
2017 int len
= strlen (base_fontname
) + strlen (xic_defaut_fontset
) + 3;
2018 fontsetname
= xmalloc (len
);
2019 bzero (fontsetname
, len
);
2020 strcpy (fontsetname
, base_fontname
);
2021 strcat (fontsetname
, sep
);
2022 strcat (fontsetname
, xic_defaut_fontset
);
2027 char *p1
= NULL
, *p2
= NULL
;
2028 char *font_allcs
= NULL
;
2029 char *font_allfamilies
= NULL
;
2030 char *font_all
= NULL
;
2031 char *allcs
= "*-*-*-*-*-*-*";
2032 char *allfamilies
= "-*-*-";
2033 char *all
= "*-*-*-*-";
2035 for (i
= 0, p
= base_fontname
; i
< 8; p
++)
2046 /* Build the font spec that matches all charsets. */
2047 len
= p
- base_fontname
+ strlen (allcs
) + 1;
2048 font_allcs
= (char *) alloca (len
);
2049 bzero (font_allcs
, len
);
2050 bcopy (base_fontname
, font_allcs
, p
- base_fontname
);
2051 strcat (font_allcs
, allcs
);
2053 /* Build the font spec that matches all families. */
2054 len
= p
- p1
+ strlen (allcs
) + strlen (allfamilies
) + 1;
2055 font_allfamilies
= (char *) alloca (len
);
2056 bzero (font_allfamilies
, len
);
2057 strcpy (font_allfamilies
, allfamilies
);
2058 bcopy (p1
, font_allfamilies
+ strlen (allfamilies
), p
- p1
);
2059 strcat (font_allfamilies
, allcs
);
2061 /* Build the font spec that matches all. */
2062 len
= p
- p2
+ strlen (allcs
) + strlen (all
) + strlen (allfamilies
) + 1;
2063 font_all
= (char *) alloca (len
);
2064 bzero (font_all
, len
);
2065 strcpy (font_all
, allfamilies
);
2066 strcat (font_all
, all
);
2067 bcopy (p2
, font_all
+ strlen (all
) + strlen (allfamilies
), p
- p2
);
2068 strcat (font_all
, allcs
);
2070 /* Build the actual font set name. */
2071 len
= strlen (base_fontname
) + strlen (font_allcs
)
2072 + strlen (font_allfamilies
) + strlen (font_all
) + 5;
2073 fontsetname
= xmalloc (len
);
2074 bzero (fontsetname
, len
);
2075 strcpy (fontsetname
, base_fontname
);
2076 strcat (fontsetname
, sep
);
2077 strcat (fontsetname
, font_allcs
);
2078 strcat (fontsetname
, sep
);
2079 strcat (fontsetname
, font_allfamilies
);
2080 strcat (fontsetname
, sep
);
2081 strcat (fontsetname
, font_all
);
2085 strcat (fontsetname
, ":");
2090 xic_create_xfontset (f
, base_fontname
)
2092 char *base_fontname
;
2094 XFontSet xfs
= NULL
;
2095 char **missing_list
= NULL
;
2098 Lisp_Object rest
, frame
;
2101 base_fontname
= xic_defaut_fontset
;
2103 /* See if there is another frame already using same fontset. */
2104 FOR_EACH_FRAME (rest
, frame
)
2106 struct frame
*cf
= XFRAME (frame
);
2107 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
2108 && FRAME_X_DISPLAY_INFO (cf
) == FRAME_X_DISPLAY_INFO (f
)
2109 && FRAME_XIC_BASE_FONTNAME (cf
)
2110 && !strcmp (FRAME_XIC_BASE_FONTNAME (cf
), base_fontname
))
2112 xfs
= FRAME_XIC_FONTSET (cf
);
2119 char *fontsetname
= xic_create_fontsetname (base_fontname
, False
);
2122 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
),
2123 fontsetname
, &missing_list
,
2124 &missing_count
, &def_string
);
2126 XFreeStringList (missing_list
);
2127 xfree (fontsetname
);
2130 if (FRAME_XIC_BASE_FONTNAME (f
))
2131 xfree (FRAME_XIC_BASE_FONTNAME (f
));
2132 FRAME_XIC_BASE_FONTNAME (f
) = xstrdup (base_fontname
);
2134 /* No need to free def_string. */
2138 /* Free the X fontset of frame F if it is the last frame using it. */
2141 xic_free_xfontset (f
)
2144 Lisp_Object rest
, frame
;
2147 if (!FRAME_XIC_FONTSET (f
))
2150 /* See if there is another frame sharing the same fontset. */
2151 FOR_EACH_FRAME (rest
, frame
)
2153 struct frame
*cf
= XFRAME (frame
);
2154 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
2155 && FRAME_X_DISPLAY_INFO (cf
) == FRAME_X_DISPLAY_INFO (f
)
2156 && FRAME_XIC_FONTSET (cf
) == FRAME_XIC_FONTSET (f
))
2164 /* The fontset is not used anymore. It is safe to free it. */
2165 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
2167 if (FRAME_XIC_BASE_FONTNAME (f
))
2168 xfree (FRAME_XIC_BASE_FONTNAME (f
));
2169 FRAME_XIC_BASE_FONTNAME (f
) = NULL
;
2170 FRAME_XIC_FONTSET (f
) = NULL
;
2174 /* Value is the best input style, given user preferences USER (already
2175 checked to be supported by Emacs), and styles supported by the
2176 input method XIM. */
2179 best_xim_style (user
, xim
)
2185 for (i
= 0; i
< user
->count_styles
; ++i
)
2186 for (j
= 0; j
< xim
->count_styles
; ++j
)
2187 if (user
->supported_styles
[i
] == xim
->supported_styles
[j
])
2188 return user
->supported_styles
[i
];
2190 /* Return the default style. */
2191 return XIMPreeditNothing
| XIMStatusNothing
;
2194 /* Create XIC for frame F. */
2196 static XIMStyle xic_style
;
2199 create_frame_xic (f
)
2204 XFontSet xfs
= NULL
;
2209 /* Create X fontset. */
2210 xfs
= xic_create_xfontset
2211 (f
, (FRAME_FONTSET (f
) < 0) ? NULL
2212 : (char *) SDATA (fontset_ascii (FRAME_FONTSET (f
))));
2214 xim
= FRAME_X_XIM (f
);
2219 XVaNestedList preedit_attr
;
2220 XVaNestedList status_attr
;
2222 s_area
.x
= 0; s_area
.y
= 0; s_area
.width
= 1; s_area
.height
= 1;
2223 spot
.x
= 0; spot
.y
= 1;
2225 /* Determine XIC style. */
2228 XIMStyles supported_list
;
2229 supported_list
.count_styles
= (sizeof supported_xim_styles
2230 / sizeof supported_xim_styles
[0]);
2231 supported_list
.supported_styles
= supported_xim_styles
;
2232 xic_style
= best_xim_style (&supported_list
,
2233 FRAME_X_XIM_STYLES (f
));
2236 preedit_attr
= XVaCreateNestedList (0,
2239 FRAME_FOREGROUND_PIXEL (f
),
2241 FRAME_BACKGROUND_PIXEL (f
),
2242 (xic_style
& XIMPreeditPosition
2247 status_attr
= XVaCreateNestedList (0,
2253 FRAME_FOREGROUND_PIXEL (f
),
2255 FRAME_BACKGROUND_PIXEL (f
),
2258 xic
= XCreateIC (xim
,
2259 XNInputStyle
, xic_style
,
2260 XNClientWindow
, FRAME_X_WINDOW (f
),
2261 XNFocusWindow
, FRAME_X_WINDOW (f
),
2262 XNStatusAttributes
, status_attr
,
2263 XNPreeditAttributes
, preedit_attr
,
2265 XFree (preedit_attr
);
2266 XFree (status_attr
);
2269 FRAME_XIC (f
) = xic
;
2270 FRAME_XIC_STYLE (f
) = xic_style
;
2271 FRAME_XIC_FONTSET (f
) = xfs
;
2275 /* Destroy XIC and free XIC fontset of frame F, if any. */
2281 if (FRAME_XIC (f
) == NULL
)
2284 XDestroyIC (FRAME_XIC (f
));
2285 xic_free_xfontset (f
);
2287 FRAME_XIC (f
) = NULL
;
2291 /* Place preedit area for XIC of window W's frame to specified
2292 pixel position X/Y. X and Y are relative to window W. */
2295 xic_set_preeditarea (w
, x
, y
)
2299 struct frame
*f
= XFRAME (w
->frame
);
2303 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
) + WINDOW_LEFT_FRINGE_WIDTH (w
);
2304 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
2305 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
2306 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2311 /* Place status area for XIC in bottom right corner of frame F.. */
2314 xic_set_statusarea (f
)
2317 XIC xic
= FRAME_XIC (f
);
2322 /* Negotiate geometry of status area. If input method has existing
2323 status area, use its current size. */
2324 area
.x
= area
.y
= area
.width
= area
.height
= 0;
2325 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
2326 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2329 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
2330 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2333 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
2335 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
2336 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2340 area
.width
= needed
->width
;
2341 area
.height
= needed
->height
;
2342 area
.x
= FRAME_PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
2343 area
.y
= (FRAME_PIXEL_HEIGHT (f
) - area
.height
2344 - FRAME_MENUBAR_HEIGHT (f
)
2345 - FRAME_TOOLBAR_HEIGHT (f
)
2346 - FRAME_INTERNAL_BORDER_WIDTH (f
));
2349 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
2350 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2355 /* Set X fontset for XIC of frame F, using base font name
2356 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2359 xic_set_xfontset (f
, base_fontname
)
2361 char *base_fontname
;
2366 xic_free_xfontset (f
);
2368 xfs
= xic_create_xfontset (f
, base_fontname
);
2370 attr
= XVaCreateNestedList (0, XNFontSet
, xfs
, NULL
);
2371 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
2372 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2373 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
2374 XSetICValues (FRAME_XIC (f
), XNStatusAttributes
, attr
, NULL
);
2377 FRAME_XIC_FONTSET (f
) = xfs
;
2380 #endif /* HAVE_X_I18N */
2384 #ifdef USE_X_TOOLKIT
2386 /* Create and set up the X widget for frame F. */
2389 x_window (f
, window_prompting
, minibuffer_only
)
2391 long window_prompting
;
2392 int minibuffer_only
;
2394 XClassHint class_hints
;
2395 XSetWindowAttributes attributes
;
2396 unsigned long attribute_mask
;
2397 Widget shell_widget
;
2399 Widget frame_widget
;
2405 /* Use the resource name as the top-level widget name
2406 for looking up resources. Make a non-Lisp copy
2407 for the window manager, so GC relocation won't bother it.
2409 Elsewhere we specify the window name for the window manager. */
2412 char *str
= (char *) SDATA (Vx_resource_name
);
2413 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
2414 strcpy (f
->namebuf
, str
);
2418 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2419 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2420 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2421 XtSetArg (al
[ac
], XtNborderWidth
, f
->border_width
); ac
++;
2422 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2423 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2424 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2425 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2426 applicationShellWidgetClass
,
2427 FRAME_X_DISPLAY (f
), al
, ac
);
2429 f
->output_data
.x
->widget
= shell_widget
;
2430 /* maybe_set_screen_title_format (shell_widget); */
2432 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2433 (widget_value
*) NULL
,
2434 shell_widget
, False
,
2438 (lw_callback
) NULL
);
2441 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2442 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2443 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2444 XtSetValues (pane_widget
, al
, ac
);
2445 f
->output_data
.x
->column_widget
= pane_widget
;
2447 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2448 the emacs screen when changing menubar. This reduces flickering. */
2451 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2452 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2453 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2454 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2455 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2456 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2457 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2458 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2459 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
2462 f
->output_data
.x
->edit_widget
= frame_widget
;
2464 XtManageChild (frame_widget
);
2466 /* Do some needed geometry management. */
2469 char *tem
, shell_position
[32];
2472 int extra_borders
= 0;
2474 = (f
->output_data
.x
->menubar_widget
2475 ? (f
->output_data
.x
->menubar_widget
->core
.height
2476 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
2479 #if 0 /* Experimentally, we now get the right results
2480 for -geometry -0-0 without this. 24 Aug 96, rms. */
2481 if (FRAME_EXTERNAL_MENU_BAR (f
))
2484 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2485 menubar_size
+= ibw
;
2489 f
->output_data
.x
->menubar_height
= menubar_size
;
2492 /* Motif seems to need this amount added to the sizes
2493 specified for the shell widget. The Athena/Lucid widgets don't.
2494 Both conclusions reached experimentally. -- rms. */
2495 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
2496 &extra_borders
, NULL
);
2500 /* Convert our geometry parameters into a geometry string
2502 Note that we do not specify here whether the position
2503 is a user-specified or program-specified one.
2504 We pass that information later, in x_wm_set_size_hints. */
2506 int left
= f
->left_pos
;
2507 int xneg
= window_prompting
& XNegative
;
2508 int top
= f
->top_pos
;
2509 int yneg
= window_prompting
& YNegative
;
2515 if (window_prompting
& USPosition
)
2516 sprintf (shell_position
, "=%dx%d%c%d%c%d",
2517 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2518 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
2519 (xneg
? '-' : '+'), left
,
2520 (yneg
? '-' : '+'), top
);
2523 sprintf (shell_position
, "=%dx%d",
2524 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2525 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
2527 /* Setting x and y when the position is not specified in
2528 the geometry string will set program position in the WM hints.
2529 If Emacs had just one program position, we could set it in
2530 fallback resources, but since each make-frame call can specify
2531 different program positions, this is easier. */
2532 XtSetArg (al
[ac
], XtNx
, left
); ac
++;
2533 XtSetArg (al
[ac
], XtNy
, top
); ac
++;
2537 len
= strlen (shell_position
) + 1;
2538 /* We don't free this because we don't know whether
2539 it is safe to free it while the frame exists.
2540 It isn't worth the trouble of arranging to free it
2541 when the frame is deleted. */
2542 tem
= (char *) xmalloc (len
);
2543 strncpy (tem
, shell_position
, len
);
2544 XtSetArg (al
[ac
], XtNgeometry
, tem
); ac
++;
2545 XtSetValues (shell_widget
, al
, ac
);
2548 XtManageChild (pane_widget
);
2549 XtRealizeWidget (shell_widget
);
2551 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2553 validate_x_resource_name ();
2555 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
2556 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
2557 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2560 FRAME_XIC (f
) = NULL
;
2562 create_frame_xic (f
);
2565 f
->output_data
.x
->wm_hints
.input
= True
;
2566 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2567 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2568 &f
->output_data
.x
->wm_hints
);
2570 hack_wm_protocols (f
, shell_widget
);
2573 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2576 /* Do a stupid property change to force the server to generate a
2577 PropertyNotify event so that the event_stream server timestamp will
2578 be initialized to something relevant to the time we created the window.
2580 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2581 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2582 XA_ATOM
, 32, PropModeAppend
,
2583 (unsigned char*) NULL
, 0);
2585 /* Make all the standard events reach the Emacs frame. */
2586 attributes
.event_mask
= STANDARD_EVENT_SET
;
2591 /* XIM server might require some X events. */
2592 unsigned long fevent
= NoEventMask
;
2593 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2594 attributes
.event_mask
|= fevent
;
2596 #endif /* HAVE_X_I18N */
2598 attribute_mask
= CWEventMask
;
2599 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2600 attribute_mask
, &attributes
);
2602 XtMapWidget (frame_widget
);
2604 /* x_set_name normally ignores requests to set the name if the
2605 requested name is the same as the current name. This is the one
2606 place where that assumption isn't correct; f->name is set, but
2607 the X server hasn't been told. */
2610 int explicit = f
->explicit_name
;
2612 f
->explicit_name
= 0;
2615 x_set_name (f
, name
, explicit);
2618 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2619 f
->output_data
.x
->text_cursor
);
2623 /* This is a no-op, except under Motif. Make sure main areas are
2624 set to something reasonable, in case we get an error later. */
2625 lw_set_main_areas (pane_widget
, 0, frame_widget
);
2628 #else /* not USE_X_TOOLKIT */
2634 if (! xg_create_frame_widgets (f
))
2635 error ("Unable to create window");
2638 FRAME_XIC (f
) = NULL
;
2642 create_frame_xic (f
);
2645 /* XIM server might require some X events. */
2646 unsigned long fevent
= NoEventMask
;
2647 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2649 if (fevent
!= NoEventMask
)
2651 XSetWindowAttributes attributes
;
2652 XWindowAttributes wattr
;
2653 unsigned long attribute_mask
;
2655 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2657 attributes
.event_mask
= wattr
.your_event_mask
| fevent
;
2658 attribute_mask
= CWEventMask
;
2659 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2660 attribute_mask
, &attributes
);
2668 #else /*! USE_GTK */
2669 /* Create and set up the X window for frame F. */
2676 XClassHint class_hints
;
2677 XSetWindowAttributes attributes
;
2678 unsigned long attribute_mask
;
2680 attributes
.background_pixel
= f
->output_data
.x
->background_pixel
;
2681 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
2682 attributes
.bit_gravity
= StaticGravity
;
2683 attributes
.backing_store
= NotUseful
;
2684 attributes
.save_under
= True
;
2685 attributes
.event_mask
= STANDARD_EVENT_SET
;
2686 attributes
.colormap
= FRAME_X_COLORMAP (f
);
2687 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
2692 = XCreateWindow (FRAME_X_DISPLAY (f
),
2693 f
->output_data
.x
->parent_desc
,
2696 FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
),
2698 CopyFromParent
, /* depth */
2699 InputOutput
, /* class */
2701 attribute_mask
, &attributes
);
2706 create_frame_xic (f
);
2709 /* XIM server might require some X events. */
2710 unsigned long fevent
= NoEventMask
;
2711 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2712 attributes
.event_mask
|= fevent
;
2713 attribute_mask
= CWEventMask
;
2714 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2715 attribute_mask
, &attributes
);
2718 #endif /* HAVE_X_I18N */
2720 validate_x_resource_name ();
2722 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
2723 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
2724 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2726 /* The menubar is part of the ordinary display;
2727 it does not count in addition to the height of the window. */
2728 f
->output_data
.x
->menubar_height
= 0;
2730 /* This indicates that we use the "Passive Input" input model.
2731 Unless we do this, we don't get the Focus{In,Out} events that we
2732 need to draw the cursor correctly. Accursed bureaucrats.
2733 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2735 f
->output_data
.x
->wm_hints
.input
= True
;
2736 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2737 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2738 &f
->output_data
.x
->wm_hints
);
2739 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
2741 /* Request "save yourself" and "delete window" commands from wm. */
2744 protocols
[0] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2745 protocols
[1] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2746 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2749 /* x_set_name normally ignores requests to set the name if the
2750 requested name is the same as the current name. This is the one
2751 place where that assumption isn't correct; f->name is set, but
2752 the X server hasn't been told. */
2755 int explicit = f
->explicit_name
;
2757 f
->explicit_name
= 0;
2760 x_set_name (f
, name
, explicit);
2763 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2764 f
->output_data
.x
->text_cursor
);
2768 if (FRAME_X_WINDOW (f
) == 0)
2769 error ("Unable to create window");
2772 #endif /* not USE_GTK */
2773 #endif /* not USE_X_TOOLKIT */
2775 /* Verify that the icon position args for this window are valid. */
2778 x_icon_verify (f
, parms
)
2782 Lisp_Object icon_x
, icon_y
;
2784 /* Set the position of the icon. Note that twm groups all
2785 icons in an icon window. */
2786 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2787 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2788 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2790 CHECK_NUMBER (icon_x
);
2791 CHECK_NUMBER (icon_y
);
2793 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2794 error ("Both left and top icon corners of icon must be specified");
2797 /* Handle the icon stuff for this window. Perhaps later we might
2798 want an x_set_icon_position which can be called interactively as
2806 Lisp_Object icon_x
, icon_y
;
2807 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2809 /* Set the position of the icon. Note that twm groups all
2810 icons in an icon window. */
2811 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2812 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2813 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2815 CHECK_NUMBER (icon_x
);
2816 CHECK_NUMBER (icon_y
);
2818 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2819 error ("Both left and top icon corners of icon must be specified");
2823 if (! EQ (icon_x
, Qunbound
))
2824 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2826 /* Start up iconic or window? */
2827 x_wm_set_window_state
2828 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
2833 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
2840 /* Make the GCs needed for this window, setting the
2841 background, border and mouse colors; also create the
2842 mouse cursor and the gray border tile. */
2844 static char cursor_bits
[] =
2846 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2847 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2848 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2849 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2856 XGCValues gc_values
;
2860 /* Create the GCs of this frame.
2861 Note that many default values are used. */
2864 gc_values
.font
= FRAME_FONT (f
)->fid
;
2865 gc_values
.foreground
= f
->output_data
.x
->foreground_pixel
;
2866 gc_values
.background
= f
->output_data
.x
->background_pixel
;
2867 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2868 f
->output_data
.x
->normal_gc
2869 = XCreateGC (FRAME_X_DISPLAY (f
),
2871 GCLineWidth
| GCFont
| GCForeground
| GCBackground
,
2874 /* Reverse video style. */
2875 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
2876 gc_values
.background
= f
->output_data
.x
->foreground_pixel
;
2877 f
->output_data
.x
->reverse_gc
2878 = XCreateGC (FRAME_X_DISPLAY (f
),
2880 GCFont
| GCForeground
| GCBackground
| GCLineWidth
,
2883 /* Cursor has cursor-color background, background-color foreground. */
2884 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
2885 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
2886 gc_values
.fill_style
= FillOpaqueStippled
;
2888 = XCreateBitmapFromData (FRAME_X_DISPLAY (f
),
2889 FRAME_X_DISPLAY_INFO (f
)->root_window
,
2890 cursor_bits
, 16, 16);
2891 f
->output_data
.x
->cursor_gc
2892 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2893 (GCFont
| GCForeground
| GCBackground
2894 | GCFillStyle
/* | GCStipple */ | GCLineWidth
),
2898 f
->output_data
.x
->white_relief
.gc
= 0;
2899 f
->output_data
.x
->black_relief
.gc
= 0;
2901 /* Create the gray border tile used when the pointer is not in
2902 the frame. Since this depends on the frame's pixel values,
2903 this must be done on a per-frame basis. */
2904 f
->output_data
.x
->border_tile
2905 = (XCreatePixmapFromBitmapData
2906 (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
2907 gray_bits
, gray_width
, gray_height
,
2908 f
->output_data
.x
->foreground_pixel
,
2909 f
->output_data
.x
->background_pixel
,
2910 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
2916 /* Free what was was allocated in x_make_gc. */
2922 Display
*dpy
= FRAME_X_DISPLAY (f
);
2926 if (f
->output_data
.x
->normal_gc
)
2928 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
2929 f
->output_data
.x
->normal_gc
= 0;
2932 if (f
->output_data
.x
->reverse_gc
)
2934 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
2935 f
->output_data
.x
->reverse_gc
= 0;
2938 if (f
->output_data
.x
->cursor_gc
)
2940 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
2941 f
->output_data
.x
->cursor_gc
= 0;
2944 if (f
->output_data
.x
->border_tile
)
2946 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
2947 f
->output_data
.x
->border_tile
= 0;
2954 /* Handler for signals raised during x_create_frame and
2955 x_create_top_frame. FRAME is the frame which is partially
2959 unwind_create_frame (frame
)
2962 struct frame
*f
= XFRAME (frame
);
2964 /* If frame is ``official'', nothing to do. */
2965 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
2968 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2971 x_free_frame_resources (f
);
2974 /* Check that reference counts are indeed correct. */
2975 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
2976 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
2985 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
2987 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
2988 Returns an Emacs frame object.
2989 ALIST is an alist of frame parameters.
2990 If the parameters specify that the frame should not have a minibuffer,
2991 and do not specify a specific minibuffer window to use,
2992 then `default-minibuffer-frame' must be a frame whose minibuffer can
2993 be shared by the new frame.
2995 This function is an internal primitive--use `make-frame' instead. */)
3000 Lisp_Object frame
, tem
;
3002 int minibuffer_only
= 0;
3003 long window_prompting
= 0;
3005 int count
= SPECPDL_INDEX ();
3006 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
3007 Lisp_Object display
;
3008 struct x_display_info
*dpyinfo
= NULL
;
3014 /* Use this general default value to start with
3015 until we know if this frame has a specified name. */
3016 Vx_resource_name
= Vinvocation_name
;
3018 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
3019 if (EQ (display
, Qunbound
))
3021 dpyinfo
= check_x_display_info (display
);
3023 kb
= dpyinfo
->kboard
;
3025 kb
= &the_only_kboard
;
3028 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
3030 && ! EQ (name
, Qunbound
)
3032 error ("Invalid frame name--not a string or nil");
3035 Vx_resource_name
= name
;
3037 /* See if parent window is specified. */
3038 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
3039 if (EQ (parent
, Qunbound
))
3041 if (! NILP (parent
))
3042 CHECK_NUMBER (parent
);
3044 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
3045 /* No need to protect DISPLAY because that's not used after passing
3046 it to make_frame_without_minibuffer. */
3048 GCPRO4 (parms
, parent
, name
, frame
);
3049 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
3051 if (EQ (tem
, Qnone
) || NILP (tem
))
3052 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
3053 else if (EQ (tem
, Qonly
))
3055 f
= make_minibuffer_frame ();
3056 minibuffer_only
= 1;
3058 else if (WINDOWP (tem
))
3059 f
= make_frame_without_minibuffer (tem
, kb
, display
);
3063 XSETFRAME (frame
, f
);
3065 /* Note that X Windows does support scroll bars. */
3066 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
3068 f
->output_method
= output_x_window
;
3069 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
3070 bzero (f
->output_data
.x
, sizeof (struct x_output
));
3071 f
->output_data
.x
->icon_bitmap
= -1;
3072 FRAME_FONTSET (f
) = -1;
3073 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
3074 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
3075 #ifdef USE_TOOLKIT_SCROLL_BARS
3076 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
3077 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
3078 #endif /* USE_TOOLKIT_SCROLL_BARS */
3079 record_unwind_protect (unwind_create_frame
, frame
);
3082 = x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
3084 if (! STRINGP (f
->icon_name
))
3085 f
->icon_name
= Qnil
;
3087 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
3089 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
3090 dpyinfo_refcount
= dpyinfo
->reference_count
;
3091 #endif /* GLYPH_DEBUG */
3093 FRAME_KBOARD (f
) = kb
;
3096 /* These colors will be set anyway later, but it's important
3097 to get the color reference counts right, so initialize them! */
3100 struct gcpro gcpro1
;
3102 /* Function x_decode_color can signal an error. Make
3103 sure to initialize color slots so that we won't try
3104 to free colors we haven't allocated. */
3105 f
->output_data
.x
->foreground_pixel
= -1;
3106 f
->output_data
.x
->background_pixel
= -1;
3107 f
->output_data
.x
->cursor_pixel
= -1;
3108 f
->output_data
.x
->cursor_foreground_pixel
= -1;
3109 f
->output_data
.x
->border_pixel
= -1;
3110 f
->output_data
.x
->mouse_pixel
= -1;
3112 black
= build_string ("black");
3114 f
->output_data
.x
->foreground_pixel
3115 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3116 f
->output_data
.x
->background_pixel
3117 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3118 f
->output_data
.x
->cursor_pixel
3119 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3120 f
->output_data
.x
->cursor_foreground_pixel
3121 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3122 f
->output_data
.x
->border_pixel
3123 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3124 f
->output_data
.x
->mouse_pixel
3125 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3129 /* Specify the parent under which to make this X window. */
3133 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
3134 f
->output_data
.x
->explicit_parent
= 1;
3138 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3139 f
->output_data
.x
->explicit_parent
= 0;
3142 /* Set the name; the functions to which we pass f expect the name to
3144 if (EQ (name
, Qunbound
) || NILP (name
))
3146 f
->name
= build_string (dpyinfo
->x_id_name
);
3147 f
->explicit_name
= 0;
3152 f
->explicit_name
= 1;
3153 /* use the frame's title when getting resources for this frame. */
3154 specbind (Qx_resource_name
, name
);
3157 /* Extract the window parameters from the supplied values
3158 that are needed to determine window geometry. */
3162 font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
3165 /* First, try whatever font the caller has specified. */
3168 tem
= Fquery_fontset (font
, Qnil
);
3170 font
= x_new_fontset (f
, SDATA (tem
));
3172 font
= x_new_font (f
, SDATA (font
));
3175 /* Try out a font which we hope has bold and italic variations. */
3176 if (!STRINGP (font
))
3177 font
= x_new_font (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
3178 if (!STRINGP (font
))
3179 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3180 if (! STRINGP (font
))
3181 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3182 if (! STRINGP (font
))
3183 /* This was formerly the first thing tried, but it finds too many fonts
3184 and takes too long. */
3185 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
3186 /* If those didn't work, look for something which will at least work. */
3187 if (! STRINGP (font
))
3188 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
3190 if (! STRINGP (font
))
3191 font
= build_string ("fixed");
3193 x_default_parameter (f
, parms
, Qfont
, font
,
3194 "font", "Font", RES_TYPE_STRING
);
3198 /* Prevent lwlib/xlwmenu.c from crashing because of a bug
3199 whereby it fails to get any font. */
3200 xlwmenu_default_font
= FRAME_FONT (f
);
3203 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
3204 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
3206 /* This defaults to 1 in order to match xterm. We recognize either
3207 internalBorderWidth or internalBorder (which is what xterm calls
3209 if (NILP (Fassq (Qinternal_border_width
, parms
)))
3213 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
3214 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
3215 if (! EQ (value
, Qunbound
))
3216 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
3219 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
3220 "internalBorderWidth", "internalBorderWidth",
3222 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qleft
,
3223 "verticalScrollBars", "ScrollBars",
3226 /* Also do the stuff which must be set before the window exists. */
3227 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3228 "foreground", "Foreground", RES_TYPE_STRING
);
3229 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3230 "background", "Background", RES_TYPE_STRING
);
3231 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3232 "pointerColor", "Foreground", RES_TYPE_STRING
);
3233 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
3234 "cursorColor", "Foreground", RES_TYPE_STRING
);
3235 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3236 "borderColor", "BorderColor", RES_TYPE_STRING
);
3237 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3238 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3239 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3240 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3241 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3242 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3243 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3244 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3246 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3247 "scrollBarForeground",
3248 "ScrollBarForeground", 1);
3249 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3250 "scrollBarBackground",
3251 "ScrollBarBackground", 0);
3253 /* Init faces before x_default_parameter is called for scroll-bar
3254 parameters because that function calls x_set_scroll_bar_width,
3255 which calls change_frame_size, which calls Fset_window_buffer,
3256 which runs hooks, which call Fvertical_motion. At the end, we
3257 end up in init_iterator with a null face cache, which should not
3259 init_frame_faces (f
);
3261 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
3262 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
3263 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (1),
3264 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
3265 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3266 "bufferPredicate", "BufferPredicate",
3268 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3269 "title", "Title", RES_TYPE_STRING
);
3270 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3271 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3272 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3273 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3275 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3277 /* Compute the size of the X window. */
3278 window_prompting
= x_figure_window_size (f
, parms
, 1);
3280 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3281 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3283 x_icon_verify (f
, parms
);
3285 /* Create the X widget or window. */
3286 #ifdef USE_X_TOOLKIT
3287 x_window (f
, window_prompting
, minibuffer_only
);
3295 /* Now consider the frame official. */
3296 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
3297 Vframe_list
= Fcons (frame
, Vframe_list
);
3299 /* We need to do this after creating the X window, so that the
3300 icon-creation functions can say whose icon they're describing. */
3301 x_default_parameter (f
, parms
, Qicon_type
, Qt
,
3302 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
3304 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3305 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3306 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3307 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3308 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3309 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3310 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3311 "scrollBarWidth", "ScrollBarWidth",
3314 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
3315 Change will not be effected unless different from the current
3317 width
= FRAME_COLS (f
);
3318 height
= FRAME_LINES (f
);
3320 SET_FRAME_COLS (f
, 0);
3321 FRAME_LINES (f
) = 0;
3322 change_frame_size (f
, height
, width
, 1, 0, 0);
3324 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3325 /* Create the menu bar. */
3326 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3328 /* If this signals an error, we haven't set size hints for the
3329 frame and we didn't make it visible. */
3330 initialize_frame_menubar (f
);
3333 /* This is a no-op, except under Motif where it arranges the
3334 main window for the widgets on it. */
3335 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3336 f
->output_data
.x
->menubar_widget
,
3337 f
->output_data
.x
->edit_widget
);
3338 #endif /* not USE_GTK */
3340 #endif /* USE_X_TOOLKIT || USE_GTK */
3342 /* Tell the server what size and position, etc, we want, and how
3343 badly we want them. This should be done after we have the menu
3344 bar so that its size can be taken into account. */
3346 x_wm_set_size_hint (f
, window_prompting
, 0);
3349 /* Make the window appear on the frame and enable display, unless
3350 the caller says not to. However, with explicit parent, Emacs
3351 cannot control visibility, so don't try. */
3352 if (! f
->output_data
.x
->explicit_parent
)
3354 Lisp_Object visibility
;
3356 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3358 if (EQ (visibility
, Qunbound
))
3361 if (EQ (visibility
, Qicon
))
3362 x_iconify_frame (f
);
3363 else if (! NILP (visibility
))
3364 x_make_frame_visible (f
);
3366 /* Must have been Qnil. */
3370 /* Set the WM leader property. GTK does this itself, so this is not
3371 needed when using GTK. */
3372 if (dpyinfo
->client_leader_window
!= 0)
3375 XChangeProperty (FRAME_X_DISPLAY (f
),
3376 FRAME_OUTER_WINDOW (f
),
3377 dpyinfo
->Xatom_wm_client_leader
,
3378 XA_WINDOW
, 32, PropModeReplace
,
3379 (char *) &dpyinfo
->client_leader_window
, 1);
3385 /* Make sure windows on this frame appear in calls to next-window
3386 and similar functions. */
3387 Vwindow_list
= Qnil
;
3389 return unbind_to (count
, frame
);
3393 /* FRAME is used only to get a handle on the X display. We don't pass the
3394 display info directly because we're called from frame.c, which doesn't
3395 know about that structure. */
3398 x_get_focus_frame (frame
)
3399 struct frame
*frame
;
3401 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (frame
);
3403 if (! dpyinfo
->x_focus_frame
)
3406 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3411 /* In certain situations, when the window manager follows a
3412 click-to-focus policy, there seems to be no way around calling
3413 XSetInputFocus to give another frame the input focus .
3415 In an ideal world, XSetInputFocus should generally be avoided so
3416 that applications don't interfere with the window manager's focus
3417 policy. But I think it's okay to use when it's clearly done
3418 following a user-command. */
3420 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
3421 doc
: /* Set the input focus to FRAME.
3422 FRAME nil means use the selected frame. */)
3426 struct frame
*f
= check_x_frame (frame
);
3427 Display
*dpy
= FRAME_X_DISPLAY (f
);
3431 count
= x_catch_errors (dpy
);
3432 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3433 RevertToParent
, CurrentTime
);
3434 x_uncatch_errors (dpy
, count
);
3441 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
3442 doc
: /* Internal function called by `color-defined-p', which see. */)
3444 Lisp_Object color
, frame
;
3447 FRAME_PTR f
= check_x_frame (frame
);
3449 CHECK_STRING (color
);
3451 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
3457 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
3458 doc
: /* Internal function called by `color-values', which see. */)
3460 Lisp_Object color
, frame
;
3463 FRAME_PTR f
= check_x_frame (frame
);
3465 CHECK_STRING (color
);
3467 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
3471 rgb
[0] = make_number (foo
.red
);
3472 rgb
[1] = make_number (foo
.green
);
3473 rgb
[2] = make_number (foo
.blue
);
3474 return Flist (3, rgb
);
3480 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
3481 doc
: /* Internal function called by `display-color-p', which see. */)
3483 Lisp_Object display
;
3485 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3487 if (dpyinfo
->n_planes
<= 2)
3490 switch (dpyinfo
->visual
->class)
3503 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3505 doc
: /* Return t if the X display supports shades of gray.
3506 Note that color displays do support shades of gray.
3507 The optional argument DISPLAY specifies which display to ask about.
3508 DISPLAY should be either a frame or a display name (a string).
3509 If omitted or nil, that stands for the selected frame's display. */)
3511 Lisp_Object display
;
3513 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3515 if (dpyinfo
->n_planes
<= 1)
3518 switch (dpyinfo
->visual
->class)
3533 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3535 doc
: /* Returns the width in pixels of the X display DISPLAY.
3536 The optional argument DISPLAY specifies which display to ask about.
3537 DISPLAY should be either a frame or a display name (a string).
3538 If omitted or nil, that stands for the selected frame's display. */)
3540 Lisp_Object display
;
3542 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3544 return make_number (dpyinfo
->width
);
3547 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3548 Sx_display_pixel_height
, 0, 1, 0,
3549 doc
: /* Returns the height in pixels of the X display DISPLAY.
3550 The optional argument DISPLAY specifies which display to ask about.
3551 DISPLAY should be either a frame or a display name (a string).
3552 If omitted or nil, that stands for the selected frame's display. */)
3554 Lisp_Object display
;
3556 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3558 return make_number (dpyinfo
->height
);
3561 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3563 doc
: /* Returns the number of bitplanes of the X display DISPLAY.
3564 The optional argument DISPLAY specifies which display to ask about.
3565 DISPLAY should be either a frame or a display name (a string).
3566 If omitted or nil, that stands for the selected frame's display. */)
3568 Lisp_Object display
;
3570 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3572 return make_number (dpyinfo
->n_planes
);
3575 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3577 doc
: /* Returns the number of color cells of the X display DISPLAY.
3578 The optional argument DISPLAY specifies which display to ask about.
3579 DISPLAY should be either a frame or a display name (a string).
3580 If omitted or nil, that stands for the selected frame's display. */)
3582 Lisp_Object display
;
3584 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3586 int nr_planes
= DisplayPlanes (dpyinfo
->display
,
3587 XScreenNumberOfScreen (dpyinfo
->screen
));
3589 /* Truncate nr_planes to 24 to avoid integer overflow.
3590 Some displays says 32, but only 24 bits are actually significant.
3591 There are only very few and rare video cards that have more than
3592 24 significant bits. Also 24 bits is more than 16 million colors,
3593 it "should be enough for everyone". */
3594 if (nr_planes
> 24) nr_planes
= 24;
3596 return make_number (1 << nr_planes
);
3599 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3600 Sx_server_max_request_size
,
3602 doc
: /* Returns the maximum request size of the X server of display DISPLAY.
3603 The optional argument DISPLAY specifies which display to ask about.
3604 DISPLAY should be either a frame or a display name (a string).
3605 If omitted or nil, that stands for the selected frame's display. */)
3607 Lisp_Object display
;
3609 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3611 return make_number (MAXREQUEST (dpyinfo
->display
));
3614 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3615 doc
: /* Returns the "vendor ID" string of the X server of display DISPLAY.
3616 \(Labelling every distributor as a "vendor" embodies the false assumption
3617 that operating systems cannot be developed and distributed noncommercially.)
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. */)
3622 Lisp_Object display
;
3624 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3625 char *vendor
= ServerVendor (dpyinfo
->display
);
3627 if (! vendor
) vendor
= "";
3628 return build_string (vendor
);
3631 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3632 doc
: /* Returns the version numbers of the X server of display DISPLAY.
3633 The value is a list of three integers: the major and minor
3634 version numbers of the X Protocol in use, and the distributor-specific release
3635 number. See also the function `x-server-vendor'.
3637 The optional argument DISPLAY specifies which display to ask about.
3638 DISPLAY should be either a frame or a display name (a string).
3639 If omitted or nil, that stands for the selected frame's display. */)
3641 Lisp_Object display
;
3643 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3644 Display
*dpy
= dpyinfo
->display
;
3646 return Fcons (make_number (ProtocolVersion (dpy
)),
3647 Fcons (make_number (ProtocolRevision (dpy
)),
3648 Fcons (make_number (VendorRelease (dpy
)), Qnil
)));
3651 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3652 doc
: /* Return the number of screens on the X server of display DISPLAY.
3653 The optional argument DISPLAY specifies which display to ask about.
3654 DISPLAY should be either a frame or a display name (a string).
3655 If omitted or nil, that stands for the selected frame's display. */)
3657 Lisp_Object display
;
3659 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3661 return make_number (ScreenCount (dpyinfo
->display
));
3664 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3665 doc
: /* Return the height in millimeters of the X display DISPLAY.
3666 The optional argument DISPLAY specifies which display to ask about.
3667 DISPLAY should be either a frame or a display name (a string).
3668 If omitted or nil, that stands for the selected frame's display. */)
3670 Lisp_Object display
;
3672 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3674 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3677 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3678 doc
: /* Return the width in millimeters of the X display DISPLAY.
3679 The optional argument DISPLAY specifies which display to ask about.
3680 DISPLAY should be either a frame or a display name (a string).
3681 If omitted or nil, that stands for the selected frame's display. */)
3683 Lisp_Object display
;
3685 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3687 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3690 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3691 Sx_display_backing_store
, 0, 1, 0,
3692 doc
: /* Returns an indication of whether X display DISPLAY does backing store.
3693 The value may be `always', `when-mapped', or `not-useful'.
3694 The optional argument DISPLAY specifies which display to ask about.
3695 DISPLAY should be either a frame or a display name (a string).
3696 If omitted or nil, that stands for the selected frame's display. */)
3698 Lisp_Object display
;
3700 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3703 switch (DoesBackingStore (dpyinfo
->screen
))
3706 result
= intern ("always");
3710 result
= intern ("when-mapped");
3714 result
= intern ("not-useful");
3718 error ("Strange value for BackingStore parameter of screen");
3725 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3726 Sx_display_visual_class
, 0, 1, 0,
3727 doc
: /* Return the visual class of the X display DISPLAY.
3728 The value is one of the symbols `static-gray', `gray-scale',
3729 `static-color', `pseudo-color', `true-color', or `direct-color'.
3731 The optional argument DISPLAY specifies which display to ask about.
3732 DISPLAY should be either a frame or a display name (a string).
3733 If omitted or nil, that stands for the selected frame's display. */)
3735 Lisp_Object display
;
3737 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3740 switch (dpyinfo
->visual
->class)
3743 result
= intern ("static-gray");
3746 result
= intern ("gray-scale");
3749 result
= intern ("static-color");
3752 result
= intern ("pseudo-color");
3755 result
= intern ("true-color");
3758 result
= intern ("direct-color");
3761 error ("Display has an unknown visual class");
3768 DEFUN ("x-display-save-under", Fx_display_save_under
,
3769 Sx_display_save_under
, 0, 1, 0,
3770 doc
: /* Returns t if the X display DISPLAY supports the save-under feature.
3771 The optional argument DISPLAY specifies which display to ask about.
3772 DISPLAY should be either a frame or a display name (a string).
3773 If omitted or nil, that stands for the selected frame's display. */)
3775 Lisp_Object display
;
3777 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3779 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3787 register struct frame
*f
;
3789 return FRAME_PIXEL_WIDTH (f
);
3794 register struct frame
*f
;
3796 return FRAME_PIXEL_HEIGHT (f
);
3801 register struct frame
*f
;
3803 return FRAME_COLUMN_WIDTH (f
);
3808 register struct frame
*f
;
3810 return FRAME_LINE_HEIGHT (f
);
3815 register struct frame
*f
;
3817 return FRAME_X_DISPLAY_INFO (f
)->n_planes
;
3822 /************************************************************************
3824 ************************************************************************/
3827 /* Mapping visual names to visuals. */
3829 static struct visual_class
3836 {"StaticGray", StaticGray
},
3837 {"GrayScale", GrayScale
},
3838 {"StaticColor", StaticColor
},
3839 {"PseudoColor", PseudoColor
},
3840 {"TrueColor", TrueColor
},
3841 {"DirectColor", DirectColor
},
3846 #ifndef HAVE_XSCREENNUMBEROFSCREEN
3848 /* Value is the screen number of screen SCR. This is a substitute for
3849 the X function with the same name when that doesn't exist. */
3852 XScreenNumberOfScreen (scr
)
3853 register Screen
*scr
;
3855 Display
*dpy
= scr
->display
;
3858 for (i
= 0; i
< dpy
->nscreens
; ++i
)
3859 if (scr
== dpy
->screens
+ i
)
3865 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
3868 /* Select the visual that should be used on display DPYINFO. Set
3869 members of DPYINFO appropriately. Called from x_term_init. */
3872 select_visual (dpyinfo
)
3873 struct x_display_info
*dpyinfo
;
3875 Display
*dpy
= dpyinfo
->display
;
3876 Screen
*screen
= dpyinfo
->screen
;
3879 /* See if a visual is specified. */
3880 value
= display_x_get_resource (dpyinfo
,
3881 build_string ("visualClass"),
3882 build_string ("VisualClass"),
3884 if (STRINGP (value
))
3886 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
3887 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
3888 depth, a decimal number. NAME is compared with case ignored. */
3889 char *s
= (char *) alloca (SBYTES (value
) + 1);
3894 strcpy (s
, SDATA (value
));
3895 dash
= index (s
, '-');
3898 dpyinfo
->n_planes
= atoi (dash
+ 1);
3902 /* We won't find a matching visual with depth 0, so that
3903 an error will be printed below. */
3904 dpyinfo
->n_planes
= 0;
3906 /* Determine the visual class. */
3907 for (i
= 0; visual_classes
[i
].name
; ++i
)
3908 if (xstricmp (s
, visual_classes
[i
].name
) == 0)
3910 class = visual_classes
[i
].class;
3914 /* Look up a matching visual for the specified class. */
3916 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
3917 dpyinfo
->n_planes
, class, &vinfo
))
3918 fatal ("Invalid visual specification `%s'", SDATA (value
));
3920 dpyinfo
->visual
= vinfo
.visual
;
3925 XVisualInfo
*vinfo
, vinfo_template
;
3927 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
3930 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
3932 vinfo_template
.visualid
= dpyinfo
->visual
->visualid
;
3934 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
3935 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
3936 &vinfo_template
, &n_visuals
);
3938 fatal ("Can't get proper X visual info");
3940 dpyinfo
->n_planes
= vinfo
->depth
;
3941 XFree ((char *) vinfo
);
3946 /* Return the X display structure for the display named NAME.
3947 Open a new connection if necessary. */
3949 struct x_display_info
*
3950 x_display_info_for_name (name
)
3954 struct x_display_info
*dpyinfo
;
3956 CHECK_STRING (name
);
3958 if (! EQ (Vwindow_system
, intern ("x")))
3959 error ("Not using X Windows");
3961 for (dpyinfo
= x_display_list
, names
= x_display_name_list
;
3963 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
3966 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
3971 /* Use this general default value to start with. */
3972 Vx_resource_name
= Vinvocation_name
;
3974 validate_x_resource_name ();
3976 dpyinfo
= x_term_init (name
, (char *)0,
3977 (char *) SDATA (Vx_resource_name
));
3980 error ("Cannot connect to X server %s", SDATA (name
));
3983 XSETFASTINT (Vwindow_system_version
, 11);
3989 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
3991 doc
: /* Open a connection to an X server.
3992 DISPLAY is the name of the display to connect to.
3993 Optional second arg XRM-STRING is a string of resources in xrdb format.
3994 If the optional third arg MUST-SUCCEED is non-nil,
3995 terminate Emacs if we can't open the connection. */)
3996 (display
, xrm_string
, must_succeed
)
3997 Lisp_Object display
, xrm_string
, must_succeed
;
3999 unsigned char *xrm_option
;
4000 struct x_display_info
*dpyinfo
;
4002 CHECK_STRING (display
);
4003 if (! NILP (xrm_string
))
4004 CHECK_STRING (xrm_string
);
4006 if (! EQ (Vwindow_system
, intern ("x")))
4007 error ("Not using X Windows");
4009 if (! NILP (xrm_string
))
4010 xrm_option
= (unsigned char *) SDATA (xrm_string
);
4012 xrm_option
= (unsigned char *) 0;
4014 validate_x_resource_name ();
4016 /* This is what opens the connection and sets x_current_display.
4017 This also initializes many symbols, such as those used for input. */
4018 dpyinfo
= x_term_init (display
, xrm_option
,
4019 (char *) SDATA (Vx_resource_name
));
4023 if (!NILP (must_succeed
))
4024 fatal ("Cannot connect to X server %s.\n\
4025 Check the DISPLAY environment variable or use `-d'.\n\
4026 Also use the `xauth' program to verify that you have the proper\n\
4027 authorization information needed to connect the X server.\n\
4028 An insecure way to solve the problem may be to use `xhost'.\n",
4031 error ("Cannot connect to X server %s", SDATA (display
));
4036 XSETFASTINT (Vwindow_system_version
, 11);
4040 DEFUN ("x-close-connection", Fx_close_connection
,
4041 Sx_close_connection
, 1, 1, 0,
4042 doc
: /* Close the connection to DISPLAY's X server.
4043 For DISPLAY, specify either a frame or a display name (a string).
4044 If DISPLAY is nil, that stands for the selected frame's display. */)
4046 Lisp_Object display
;
4048 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4051 if (dpyinfo
->reference_count
> 0)
4052 error ("Display still has frames on it");
4055 /* Free the fonts in the font table. */
4056 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
4057 if (dpyinfo
->font_table
[i
].name
)
4059 XFreeFont (dpyinfo
->display
, dpyinfo
->font_table
[i
].font
);
4062 x_destroy_all_bitmaps (dpyinfo
);
4063 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
4065 #ifdef USE_X_TOOLKIT
4066 XtCloseDisplay (dpyinfo
->display
);
4068 XCloseDisplay (dpyinfo
->display
);
4071 x_delete_display (dpyinfo
);
4077 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4078 doc
: /* Return the list of display names that Emacs has connections to. */)
4081 Lisp_Object tail
, result
;
4084 for (tail
= x_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
4085 result
= Fcons (XCAR (XCAR (tail
)), result
);
4090 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4091 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
4092 If ON is nil, allow buffering of requests.
4093 Turning on synchronization prohibits the Xlib routines from buffering
4094 requests and seriously degrades performance, but makes debugging much
4096 The optional second argument DISPLAY specifies which display to act on.
4097 DISPLAY should be either a frame or a display name (a string).
4098 If DISPLAY is omitted or nil, that stands for the selected frame's display. */)
4100 Lisp_Object display
, on
;
4102 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
4104 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
4109 /* Wait for responses to all X commands issued so far for frame F. */
4116 XSync (FRAME_X_DISPLAY (f
), False
);
4121 /***********************************************************************
4123 ***********************************************************************/
4125 DEFUN ("x-change-window-property", Fx_change_window_property
,
4126 Sx_change_window_property
, 2, 6, 0,
4127 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
4128 PROP must be a string.
4129 VALUE may be a string or a list of conses, numbers and/or strings.
4130 If an element in the list is a string, it is converted to
4131 an Atom and the value of the Atom is used. If an element is a cons,
4132 it is converted to a 32 bit number where the car is the 16 top bits and the
4133 cdr is the lower 16 bits.
4134 FRAME nil or omitted means use the selected frame.
4135 If TYPE is given and non-nil, it is the name of the type of VALUE.
4136 If TYPE is not given or nil, the type is STRING.
4137 FORMAT gives the size in bits of each element if VALUE is a list.
4138 It must be one of 8, 16 or 32.
4139 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4140 If OUTER_P is non-nil, the property is changed for the outer X window of
4141 FRAME. Default is to change on the edit X window.
4144 (prop
, value
, frame
, type
, format
, outer_p
)
4145 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
4147 struct frame
*f
= check_x_frame (frame
);
4149 Atom target_type
= XA_STRING
;
4150 int element_format
= 8;
4151 unsigned char *data
;
4155 CHECK_STRING (prop
);
4157 if (! NILP (format
))
4159 CHECK_NUMBER (format
);
4160 element_format
= XFASTINT (format
);
4162 if (element_format
!= 8 && element_format
!= 16
4163 && element_format
!= 32)
4164 error ("FORMAT must be one of 8, 16 or 32");
4169 nelements
= x_check_property_data (value
);
4170 if (nelements
== -1)
4171 error ("Bad data in VALUE, must be number, string or cons");
4173 if (element_format
== 8)
4174 data
= (unsigned char *) xmalloc (nelements
);
4175 else if (element_format
== 16)
4176 data
= (unsigned char *) xmalloc (nelements
*2);
4177 else /* format == 32 */
4178 /* The man page for XChangeProperty:
4179 "If the specified format is 32, the property data must be a
4181 This applies even if long is more than 64 bits. The X library
4182 converts to 32 bits before sending to the X server. */
4183 data
= (unsigned char *) xmalloc (nelements
* sizeof(long));
4185 x_fill_property_data (FRAME_X_DISPLAY (f
), value
, data
, element_format
);
4189 CHECK_STRING (value
);
4190 data
= SDATA (value
);
4191 nelements
= SCHARS (value
);
4195 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4198 CHECK_STRING (type
);
4199 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (type
), False
);
4202 if (! NILP (outer_p
)) w
= FRAME_OUTER_WINDOW (f
);
4203 else w
= FRAME_X_WINDOW (f
);
4205 XChangeProperty (FRAME_X_DISPLAY (f
), w
,
4206 prop_atom
, target_type
, element_format
, PropModeReplace
,
4209 if (CONSP (value
)) xfree (data
);
4211 /* Make sure the property is set when we return. */
4212 XFlush (FRAME_X_DISPLAY (f
));
4219 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
4220 Sx_delete_window_property
, 1, 2, 0,
4221 doc
: /* Remove window property PROP from X window of FRAME.
4222 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4224 Lisp_Object prop
, frame
;
4226 struct frame
*f
= check_x_frame (frame
);
4229 CHECK_STRING (prop
);
4231 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4232 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
4234 /* Make sure the property is removed when we return. */
4235 XFlush (FRAME_X_DISPLAY (f
));
4242 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
4244 doc
: /* Value is the value of window property PROP on FRAME.
4245 If FRAME is nil or omitted, use the selected frame.
4246 If TYPE is nil or omitted, get the property as a string. Otherwise TYPE
4247 is the name of the Atom that denotes the type expected.
4248 If SOURCE is non-nil, get the property on that window instead of from
4249 FRAME. The number 0 denotes the root window.
4250 If DELETE_P is non-nil, delete the property after retreiving it.
4251 If VECTOR_RET_P is non-nil, don't return a string but a vector of values.
4253 Value is nil if FRAME hasn't a property with name PROP or if PROP has
4254 no value of TYPE. */)
4255 (prop
, frame
, type
, source
, delete_p
, vector_ret_p
)
4256 Lisp_Object prop
, frame
, type
, source
, delete_p
, vector_ret_p
;
4258 struct frame
*f
= check_x_frame (frame
);
4261 Lisp_Object prop_value
= Qnil
;
4262 unsigned char *tmp_data
= NULL
;
4264 Atom target_type
= XA_STRING
;
4266 unsigned long actual_size
, bytes_remaining
;
4267 Window target_window
= FRAME_X_WINDOW (f
);
4268 struct gcpro gcpro1
;
4270 GCPRO1 (prop_value
);
4271 CHECK_STRING (prop
);
4273 if (! NILP (source
))
4275 if (NUMBERP (source
))
4277 if (FLOATP (source
))
4278 target_window
= (Window
) XFLOAT (source
);
4280 target_window
= XFASTINT (source
);
4282 if (target_window
== 0)
4283 target_window
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4285 else if (CONSP (source
))
4286 target_window
= cons_to_long (source
);
4292 if (strcmp ("AnyPropertyType", SDATA (type
)) == 0)
4293 target_type
= AnyPropertyType
;
4295 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (type
), False
);
4298 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4299 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4300 prop_atom
, 0, 0, False
, target_type
,
4301 &actual_type
, &actual_format
, &actual_size
,
4302 &bytes_remaining
, &tmp_data
);
4305 int size
= bytes_remaining
;
4310 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4311 prop_atom
, 0, bytes_remaining
,
4312 ! NILP (delete_p
), target_type
,
4313 &actual_type
, &actual_format
,
4314 &actual_size
, &bytes_remaining
,
4316 if (rc
== Success
&& tmp_data
)
4318 /* The man page for XGetWindowProperty says:
4319 "If the returned format is 32, the returned data is represented
4320 as a long array and should be cast to that type to obtain the
4322 This applies even if long is more than 32 bits, the X library
4323 converts from 32 bit elements received from the X server to long
4324 and passes the long array to us. Thus, for that case bcopy can not
4325 be used. We convert to a 32 bit type here, because so much code
4328 The bytes and offsets passed to XGetWindowProperty refers to the
4329 property and those are indeed in 32 bit quantities if format is
4332 if (actual_format
== 32 && actual_format
< BITS_PER_LONG
)
4335 int *idata
= (int *) tmp_data
;
4336 long *ldata
= (long *) tmp_data
;
4338 for (i
= 0; i
< actual_size
; ++i
)
4339 idata
[i
] = (int) ldata
[i
];
4342 if (NILP (vector_ret_p
))
4343 prop_value
= make_string (tmp_data
, size
);
4345 prop_value
= x_property_data_to_lisp (f
,
4352 if (tmp_data
) XFree (tmp_data
);
4362 /***********************************************************************
4364 ***********************************************************************/
4366 /* If non-null, an asynchronous timer that, when it expires, displays
4367 an hourglass cursor on all frames. */
4369 static struct atimer
*hourglass_atimer
;
4371 /* Non-zero means an hourglass cursor is currently shown. */
4373 static int hourglass_shown_p
;
4375 /* Number of seconds to wait before displaying an hourglass cursor. */
4377 static Lisp_Object Vhourglass_delay
;
4379 /* Default number of seconds to wait before displaying an hourglass
4382 #define DEFAULT_HOURGLASS_DELAY 1
4384 /* Function prototypes. */
4386 static void show_hourglass
P_ ((struct atimer
*));
4387 static void hide_hourglass
P_ ((void));
4389 /* Return non-zero if houglass timer has been started or hourglass is shown. */
4392 hourglass_started ()
4394 return hourglass_shown_p
|| hourglass_atimer
!= NULL
;
4398 /* Cancel a currently active hourglass timer, and start a new one. */
4404 int secs
, usecs
= 0;
4406 /* Don't bother for ttys. */
4407 if (NILP (Vwindow_system
))
4410 cancel_hourglass ();
4412 if (INTEGERP (Vhourglass_delay
)
4413 && XINT (Vhourglass_delay
) > 0)
4414 secs
= XFASTINT (Vhourglass_delay
);
4415 else if (FLOATP (Vhourglass_delay
)
4416 && XFLOAT_DATA (Vhourglass_delay
) > 0)
4419 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
4420 secs
= XFASTINT (tem
);
4421 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
4424 secs
= DEFAULT_HOURGLASS_DELAY
;
4426 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
4427 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
4428 show_hourglass
, NULL
);
4432 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
4438 if (hourglass_atimer
)
4440 cancel_atimer (hourglass_atimer
);
4441 hourglass_atimer
= NULL
;
4444 if (hourglass_shown_p
)
4449 /* Timer function of hourglass_atimer. TIMER is equal to
4452 Display an hourglass pointer on all frames by mapping the frames'
4453 hourglass_window. Set the hourglass_p flag in the frames'
4454 output_data.x structure to indicate that an hourglass cursor is
4455 shown on the frames. */
4458 show_hourglass (timer
)
4459 struct atimer
*timer
;
4461 /* The timer implementation will cancel this timer automatically
4462 after this function has run. Set hourglass_atimer to null
4463 so that we know the timer doesn't have to be canceled. */
4464 hourglass_atimer
= NULL
;
4466 if (!hourglass_shown_p
)
4468 Lisp_Object rest
, frame
;
4472 FOR_EACH_FRAME (rest
, frame
)
4474 struct frame
*f
= XFRAME (frame
);
4476 if (FRAME_LIVE_P (f
) && FRAME_X_P (f
) && FRAME_X_DISPLAY (f
))
4478 Display
*dpy
= FRAME_X_DISPLAY (f
);
4480 #ifdef USE_X_TOOLKIT
4481 if (f
->output_data
.x
->widget
)
4483 if (FRAME_OUTER_WINDOW (f
))
4486 f
->output_data
.x
->hourglass_p
= 1;
4488 if (!f
->output_data
.x
->hourglass_window
)
4490 unsigned long mask
= CWCursor
;
4491 XSetWindowAttributes attrs
;
4493 Window parent
= FRAME_X_WINDOW (f
);
4495 Window parent
= FRAME_OUTER_WINDOW (f
);
4497 attrs
.cursor
= f
->output_data
.x
->hourglass_cursor
;
4499 f
->output_data
.x
->hourglass_window
4500 = XCreateWindow (dpy
, parent
,
4501 0, 0, 32000, 32000, 0, 0,
4507 XMapRaised (dpy
, f
->output_data
.x
->hourglass_window
);
4513 hourglass_shown_p
= 1;
4519 /* Hide the hourglass pointer on all frames, if it is currently
4525 if (hourglass_shown_p
)
4527 Lisp_Object rest
, frame
;
4530 FOR_EACH_FRAME (rest
, frame
)
4532 struct frame
*f
= XFRAME (frame
);
4535 /* Watch out for newly created frames. */
4536 && f
->output_data
.x
->hourglass_window
)
4538 XUnmapWindow (FRAME_X_DISPLAY (f
),
4539 f
->output_data
.x
->hourglass_window
);
4540 /* Sync here because XTread_socket looks at the
4541 hourglass_p flag that is reset to zero below. */
4542 XSync (FRAME_X_DISPLAY (f
), False
);
4543 f
->output_data
.x
->hourglass_p
= 0;
4547 hourglass_shown_p
= 0;
4554 /***********************************************************************
4556 ***********************************************************************/
4558 static Lisp_Object x_create_tip_frame
P_ ((struct x_display_info
*,
4559 Lisp_Object
, Lisp_Object
));
4560 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
4561 Lisp_Object
, int, int, int *, int *));
4563 /* The frame of a currently visible tooltip. */
4565 Lisp_Object tip_frame
;
4567 /* If non-nil, a timer started that hides the last tooltip when it
4570 Lisp_Object tip_timer
;
4573 /* If non-nil, a vector of 3 elements containing the last args
4574 with which x-show-tip was called. See there. */
4576 Lisp_Object last_show_tip_args
;
4578 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
4580 Lisp_Object Vx_max_tooltip_size
;
4584 unwind_create_tip_frame (frame
)
4587 Lisp_Object deleted
;
4589 deleted
= unwind_create_frame (frame
);
4590 if (EQ (deleted
, Qt
))
4600 /* Create a frame for a tooltip on the display described by DPYINFO.
4601 PARMS is a list of frame parameters. TEXT is the string to
4602 display in the tip frame. Value is the frame.
4604 Note that functions called here, esp. x_default_parameter can
4605 signal errors, for instance when a specified color name is
4606 undefined. We have to make sure that we're in a consistent state
4607 when this happens. */
4610 x_create_tip_frame (dpyinfo
, parms
, text
)
4611 struct x_display_info
*dpyinfo
;
4612 Lisp_Object parms
, text
;
4615 Lisp_Object frame
, tem
;
4617 long window_prompting
= 0;
4619 int count
= SPECPDL_INDEX ();
4620 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4622 int face_change_count_before
= face_change_count
;
4624 struct buffer
*old_buffer
;
4630 kb
= dpyinfo
->kboard
;
4632 kb
= &the_only_kboard
;
4635 /* Get the name of the frame to use for resource lookup. */
4636 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
4638 && !EQ (name
, Qunbound
)
4640 error ("Invalid frame name--not a string or nil");
4643 GCPRO3 (parms
, name
, frame
);
4645 XSETFRAME (frame
, f
);
4647 buffer
= Fget_buffer_create (build_string (" *tip*"));
4648 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
4649 old_buffer
= current_buffer
;
4650 set_buffer_internal_1 (XBUFFER (buffer
));
4651 current_buffer
->truncate_lines
= Qnil
;
4652 specbind (Qinhibit_read_only
, Qt
);
4653 specbind (Qinhibit_modification_hooks
, Qt
);
4656 set_buffer_internal_1 (old_buffer
);
4658 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
4659 record_unwind_protect (unwind_create_tip_frame
, frame
);
4661 /* By setting the output method, we're essentially saying that
4662 the frame is live, as per FRAME_LIVE_P. If we get a signal
4663 from this point on, x_destroy_window might screw up reference
4665 f
->output_method
= output_x_window
;
4666 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
4667 bzero (f
->output_data
.x
, sizeof (struct x_output
));
4668 f
->output_data
.x
->icon_bitmap
= -1;
4669 FRAME_FONTSET (f
) = -1;
4670 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
4671 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
4672 #ifdef USE_TOOLKIT_SCROLL_BARS
4673 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
4674 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
4675 #endif /* USE_TOOLKIT_SCROLL_BARS */
4676 f
->icon_name
= Qnil
;
4677 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
4679 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
4680 dpyinfo_refcount
= dpyinfo
->reference_count
;
4681 #endif /* GLYPH_DEBUG */
4683 FRAME_KBOARD (f
) = kb
;
4685 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4686 f
->output_data
.x
->explicit_parent
= 0;
4688 /* These colors will be set anyway later, but it's important
4689 to get the color reference counts right, so initialize them! */
4692 struct gcpro gcpro1
;
4694 black
= build_string ("black");
4696 f
->output_data
.x
->foreground_pixel
4697 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4698 f
->output_data
.x
->background_pixel
4699 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4700 f
->output_data
.x
->cursor_pixel
4701 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4702 f
->output_data
.x
->cursor_foreground_pixel
4703 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4704 f
->output_data
.x
->border_pixel
4705 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4706 f
->output_data
.x
->mouse_pixel
4707 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4711 /* Set the name; the functions to which we pass f expect the name to
4713 if (EQ (name
, Qunbound
) || NILP (name
))
4715 f
->name
= build_string (dpyinfo
->x_id_name
);
4716 f
->explicit_name
= 0;
4721 f
->explicit_name
= 1;
4722 /* use the frame's title when getting resources for this frame. */
4723 specbind (Qx_resource_name
, name
);
4726 /* Extract the window parameters from the supplied values that are
4727 needed to determine window geometry. */
4731 font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4734 /* First, try whatever font the caller has specified. */
4737 tem
= Fquery_fontset (font
, Qnil
);
4739 font
= x_new_fontset (f
, SDATA (tem
));
4741 font
= x_new_font (f
, SDATA (font
));
4744 /* Try out a font which we hope has bold and italic variations. */
4745 if (!STRINGP (font
))
4746 font
= x_new_font (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
4747 if (!STRINGP (font
))
4748 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
4749 if (! STRINGP (font
))
4750 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
4751 if (! STRINGP (font
))
4752 /* This was formerly the first thing tried, but it finds too many fonts
4753 and takes too long. */
4754 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
4755 /* If those didn't work, look for something which will at least work. */
4756 if (! STRINGP (font
))
4757 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
4759 if (! STRINGP (font
))
4760 font
= build_string ("fixed");
4762 x_default_parameter (f
, parms
, Qfont
, font
,
4763 "font", "Font", RES_TYPE_STRING
);
4766 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
4767 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4769 /* This defaults to 2 in order to match xterm. We recognize either
4770 internalBorderWidth or internalBorder (which is what xterm calls
4772 if (NILP (Fassq (Qinternal_border_width
, parms
)))
4776 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
4777 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
4778 if (! EQ (value
, Qunbound
))
4779 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
4783 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
4784 "internalBorderWidth", "internalBorderWidth",
4787 /* Also do the stuff which must be set before the window exists. */
4788 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
4789 "foreground", "Foreground", RES_TYPE_STRING
);
4790 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
4791 "background", "Background", RES_TYPE_STRING
);
4792 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
4793 "pointerColor", "Foreground", RES_TYPE_STRING
);
4794 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
4795 "cursorColor", "Foreground", RES_TYPE_STRING
);
4796 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
4797 "borderColor", "BorderColor", RES_TYPE_STRING
);
4799 /* Init faces before x_default_parameter is called for scroll-bar
4800 parameters because that function calls x_set_scroll_bar_width,
4801 which calls change_frame_size, which calls Fset_window_buffer,
4802 which runs hooks, which call Fvertical_motion. At the end, we
4803 end up in init_iterator with a null face cache, which should not
4805 init_frame_faces (f
);
4807 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4809 window_prompting
= x_figure_window_size (f
, parms
, 0);
4812 XSetWindowAttributes attrs
;
4816 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
;
4817 if (DoesSaveUnders (dpyinfo
->screen
))
4818 mask
|= CWSaveUnder
;
4820 /* Window managers look at the override-redirect flag to determine
4821 whether or net to give windows a decoration (Xlib spec, chapter
4823 attrs
.override_redirect
= True
;
4824 attrs
.save_under
= True
;
4825 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
4826 /* Arrange for getting MapNotify and UnmapNotify events. */
4827 attrs
.event_mask
= StructureNotifyMask
;
4829 = FRAME_X_WINDOW (f
)
4830 = XCreateWindow (FRAME_X_DISPLAY (f
),
4831 FRAME_X_DISPLAY_INFO (f
)->root_window
,
4832 /* x, y, width, height */
4836 CopyFromParent
, InputOutput
, CopyFromParent
,
4843 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
4844 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4845 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
4846 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4847 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
4848 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4850 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4851 Change will not be effected unless different from the current
4853 width
= FRAME_COLS (f
);
4854 height
= FRAME_LINES (f
);
4855 SET_FRAME_COLS (f
, 0);
4856 FRAME_LINES (f
) = 0;
4857 change_frame_size (f
, height
, width
, 1, 0, 0);
4859 /* Add `tooltip' frame parameter's default value. */
4860 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
4861 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
4864 /* Set up faces after all frame parameters are known. This call
4865 also merges in face attributes specified for new frames.
4867 Frame parameters may be changed if .Xdefaults contains
4868 specifications for the default font. For example, if there is an
4869 `Emacs.default.attributeBackground: pink', the `background-color'
4870 attribute of the frame get's set, which let's the internal border
4871 of the tooltip frame appear in pink. Prevent this. */
4873 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
4875 /* Set tip_frame here, so that */
4877 call1 (Qface_set_after_frame_default
, frame
);
4879 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
4880 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
4888 /* It is now ok to make the frame official even if we get an error
4889 below. And the frame needs to be on Vframe_list or making it
4890 visible won't work. */
4891 Vframe_list
= Fcons (frame
, Vframe_list
);
4893 /* Now that the frame is official, it counts as a reference to
4895 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
4897 /* Setting attributes of faces of the tooltip frame from resources
4898 and similar will increment face_change_count, which leads to the
4899 clearing of all current matrices. Since this isn't necessary
4900 here, avoid it by resetting face_change_count to the value it
4901 had before we created the tip frame. */
4902 face_change_count
= face_change_count_before
;
4904 /* Discard the unwind_protect. */
4905 return unbind_to (count
, frame
);
4909 /* Compute where to display tip frame F. PARMS is the list of frame
4910 parameters for F. DX and DY are specified offsets from the current
4911 location of the mouse. WIDTH and HEIGHT are the width and height
4912 of the tooltip. Return coordinates relative to the root window of
4913 the display in *ROOT_X, and *ROOT_Y. */
4916 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
4918 Lisp_Object parms
, dx
, dy
;
4920 int *root_x
, *root_y
;
4922 Lisp_Object left
, top
;
4927 /* User-specified position? */
4928 left
= Fcdr (Fassq (Qleft
, parms
));
4929 top
= Fcdr (Fassq (Qtop
, parms
));
4931 /* Move the tooltip window where the mouse pointer is. Resize and
4933 if (!INTEGERP (left
) || !INTEGERP (top
))
4936 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
4937 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
4942 *root_y
= XINT (top
);
4943 else if (*root_y
+ XINT (dy
) - height
< 0)
4944 *root_y
-= XINT (dy
);
4948 *root_y
+= XINT (dy
);
4951 if (INTEGERP (left
))
4952 *root_x
= XINT (left
);
4953 else if (*root_x
+ XINT (dx
) + width
<= FRAME_X_DISPLAY_INFO (f
)->width
)
4954 /* It fits to the right of the pointer. */
4955 *root_x
+= XINT (dx
);
4956 else if (width
+ XINT (dx
) <= *root_x
)
4957 /* It fits to the left of the pointer. */
4958 *root_x
-= width
+ XINT (dx
);
4960 /* Put it left-justified on the screen--it ought to fit that way. */
4965 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
4966 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
4967 A tooltip window is a small X window displaying a string.
4969 FRAME nil or omitted means use the selected frame.
4971 PARMS is an optional list of frame parameters which can be used to
4972 change the tooltip's appearance.
4974 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
4975 means use the default timeout of 5 seconds.
4977 If the list of frame parameters PARAMS contains a `left' parameters,
4978 the tooltip is displayed at that x-position. Otherwise it is
4979 displayed at the mouse position, with offset DX added (default is 5 if
4980 DX isn't specified). Likewise for the y-position; if a `top' frame
4981 parameter is specified, it determines the y-position of the tooltip
4982 window, otherwise it is displayed at the mouse position, with offset
4983 DY added (default is -10).
4985 A tooltip's maximum size is specified by `x-max-tooltip-size'.
4986 Text larger than the specified size is clipped. */)
4987 (string
, frame
, parms
, timeout
, dx
, dy
)
4988 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
4993 struct buffer
*old_buffer
;
4994 struct text_pos pos
;
4995 int i
, width
, height
;
4996 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4997 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
4998 int count
= SPECPDL_INDEX ();
5000 specbind (Qinhibit_redisplay
, Qt
);
5002 GCPRO4 (string
, parms
, frame
, timeout
);
5004 CHECK_STRING (string
);
5005 f
= check_x_frame (frame
);
5007 timeout
= make_number (5);
5009 CHECK_NATNUM (timeout
);
5012 dx
= make_number (5);
5017 dy
= make_number (-10);
5021 if (NILP (last_show_tip_args
))
5022 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5024 if (!NILP (tip_frame
))
5026 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5027 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5028 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5030 if (EQ (frame
, last_frame
)
5031 && !NILP (Fequal (last_string
, string
))
5032 && !NILP (Fequal (last_parms
, parms
)))
5034 struct frame
*f
= XFRAME (tip_frame
);
5036 /* Only DX and DY have changed. */
5037 if (!NILP (tip_timer
))
5039 Lisp_Object timer
= tip_timer
;
5041 call1 (Qcancel_timer
, timer
);
5045 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
5046 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
5047 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5054 /* Hide a previous tip, if any. */
5057 ASET (last_show_tip_args
, 0, string
);
5058 ASET (last_show_tip_args
, 1, frame
);
5059 ASET (last_show_tip_args
, 2, parms
);
5061 /* Add default values to frame parameters. */
5062 if (NILP (Fassq (Qname
, parms
)))
5063 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5064 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5065 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5066 if (NILP (Fassq (Qborder_width
, parms
)))
5067 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5068 if (NILP (Fassq (Qborder_color
, parms
)))
5069 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5070 if (NILP (Fassq (Qbackground_color
, parms
)))
5071 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5074 /* Create a frame for the tooltip, and record it in the global
5075 variable tip_frame. */
5076 frame
= x_create_tip_frame (FRAME_X_DISPLAY_INFO (f
), parms
, string
);
5079 /* Set up the frame's root window. */
5080 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5081 w
->left_col
= w
->top_line
= make_number (0);
5083 if (CONSP (Vx_max_tooltip_size
)
5084 && INTEGERP (XCAR (Vx_max_tooltip_size
))
5085 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
5086 && INTEGERP (XCDR (Vx_max_tooltip_size
))
5087 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
5089 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
5090 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
5094 w
->total_cols
= make_number (80);
5095 w
->total_lines
= make_number (40);
5098 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
5100 w
->pseudo_window_p
= 1;
5102 /* Display the tooltip text in a temporary buffer. */
5103 old_buffer
= current_buffer
;
5104 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
5105 current_buffer
->truncate_lines
= Qnil
;
5106 clear_glyph_matrix (w
->desired_matrix
);
5107 clear_glyph_matrix (w
->current_matrix
);
5108 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5109 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
5111 /* Compute width and height of the tooltip. */
5113 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5115 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5119 /* Stop at the first empty row at the end. */
5120 if (!row
->enabled_p
|| !row
->displays_text_p
)
5123 /* Let the row go over the full width of the frame. */
5124 row
->full_width_p
= 1;
5126 /* There's a glyph at the end of rows that is used to place
5127 the cursor there. Don't include the width of this glyph. */
5128 if (row
->used
[TEXT_AREA
])
5130 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5131 row_width
= row
->pixel_width
- last
->pixel_width
;
5134 row_width
= row
->pixel_width
;
5136 height
+= row
->height
;
5137 width
= max (width
, row_width
);
5140 /* Add the frame's internal border to the width and height the X
5141 window should have. */
5142 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5143 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5145 /* Move the tooltip window where the mouse pointer is. Resize and
5147 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5150 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5151 root_x
, root_y
, width
, height
);
5152 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5155 /* Draw into the window. */
5156 w
->must_be_updated_p
= 1;
5157 update_single_window (w
, 1);
5159 /* Restore original current buffer. */
5160 set_buffer_internal_1 (old_buffer
);
5161 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5164 /* Let the tip disappear after timeout seconds. */
5165 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5166 intern ("x-hide-tip"));
5169 return unbind_to (count
, Qnil
);
5173 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5174 doc
: /* Hide the current tooltip window, if there is any.
5175 Value is t if tooltip was open, nil otherwise. */)
5179 Lisp_Object deleted
, frame
, timer
;
5180 struct gcpro gcpro1
, gcpro2
;
5182 /* Return quickly if nothing to do. */
5183 if (NILP (tip_timer
) && NILP (tip_frame
))
5188 GCPRO2 (frame
, timer
);
5189 tip_frame
= tip_timer
= deleted
= Qnil
;
5191 count
= SPECPDL_INDEX ();
5192 specbind (Qinhibit_redisplay
, Qt
);
5193 specbind (Qinhibit_quit
, Qt
);
5196 call1 (Qcancel_timer
, timer
);
5200 Fdelete_frame (frame
, Qnil
);
5204 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5205 redisplay procedure is not called when a tip frame over menu
5206 items is unmapped. Redisplay the menu manually... */
5208 struct frame
*f
= SELECTED_FRAME ();
5209 Widget w
= f
->output_data
.x
->menubar_widget
;
5210 extern void xlwmenu_redisplay
P_ ((Widget
));
5212 if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f
)->screen
)
5216 xlwmenu_redisplay (w
);
5220 #endif /* USE_LUCID */
5224 return unbind_to (count
, deleted
);
5229 /***********************************************************************
5230 File selection dialog
5231 ***********************************************************************/
5235 /* Callback for "OK" and "Cancel" on file selection dialog. */
5238 file_dialog_cb (widget
, client_data
, call_data
)
5240 XtPointer call_data
, client_data
;
5242 int *result
= (int *) client_data
;
5243 XmAnyCallbackStruct
*cb
= (XmAnyCallbackStruct
*) call_data
;
5244 *result
= cb
->reason
;
5248 /* Callback for unmapping a file selection dialog. This is used to
5249 capture the case where a dialog is closed via a window manager's
5250 closer button, for example. Using a XmNdestroyCallback didn't work
5254 file_dialog_unmap_cb (widget
, client_data
, call_data
)
5256 XtPointer call_data
, client_data
;
5258 int *result
= (int *) client_data
;
5259 *result
= XmCR_CANCEL
;
5263 clean_up_file_dialog (arg
)
5266 struct Lisp_Save_Value
*p
= XSAVE_VALUE (arg
);
5267 Widget dialog
= (Widget
) p
->pointer
;
5271 XtUnmanageChild (dialog
);
5272 XtDestroyWidget (dialog
);
5273 x_menu_set_in_use (0);
5280 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5281 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5282 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5283 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5284 or directory must exist. ONLY-DIR-P is ignored." */)
5285 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
5286 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
5289 struct frame
*f
= SELECTED_FRAME ();
5290 Lisp_Object file
= Qnil
;
5291 Widget dialog
, text
, help
;
5294 extern XtAppContext Xt_app_con
;
5295 XmString dir_xmstring
, pattern_xmstring
;
5296 int count
= SPECPDL_INDEX ();
5297 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5299 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5301 if (popup_activated ())
5302 error ("Trying to use a menu from within a menu-entry");
5304 CHECK_STRING (prompt
);
5307 /* Prevent redisplay. */
5308 specbind (Qinhibit_redisplay
, Qt
);
5312 /* Create the dialog with PROMPT as title, using DIR as initial
5313 directory and using "*" as pattern. */
5314 dir
= Fexpand_file_name (dir
, Qnil
);
5315 dir_xmstring
= XmStringCreateLocalized (SDATA (dir
));
5316 pattern_xmstring
= XmStringCreateLocalized ("*");
5318 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
5319 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
5320 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
5321 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
5322 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
5323 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
5325 XmStringFree (dir_xmstring
);
5326 XmStringFree (pattern_xmstring
);
5328 /* Add callbacks for OK and Cancel. */
5329 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
5330 (XtPointer
) &result
);
5331 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
5332 (XtPointer
) &result
);
5333 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
5334 (XtPointer
) &result
);
5336 /* Remove the help button since we can't display help. */
5337 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
5338 XtUnmanageChild (help
);
5340 /* Mark OK button as default. */
5341 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
5342 XmNshowAsDefault
, True
, NULL
);
5344 /* If MUSTMATCH is non-nil, disable the file entry field of the
5345 dialog, so that the user must select a file from the files list
5346 box. We can't remove it because we wouldn't have a way to get at
5347 the result file name, then. */
5348 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5349 if (!NILP (mustmatch
))
5352 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
5353 XtSetSensitive (text
, False
);
5354 XtSetSensitive (label
, False
);
5357 /* Manage the dialog, so that list boxes get filled. */
5358 XtManageChild (dialog
);
5360 if (STRINGP (default_filename
))
5362 XmString default_xmstring
;
5363 Widget wtext
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5364 Widget list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
5366 XmTextPosition last_pos
= XmTextFieldGetLastPosition (wtext
);
5367 XmTextFieldReplace (wtext
, 0, last_pos
,
5368 (SDATA (Ffile_name_nondirectory (default_filename
))));
5370 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5371 must include the path for this to work. */
5373 default_xmstring
= XmStringCreateLocalized (SDATA (default_filename
));
5375 if (XmListItemExists (list
, default_xmstring
))
5377 int item_pos
= XmListItemPos (list
, default_xmstring
);
5378 /* Select the item and scroll it into view. */
5379 XmListSelectPos (list
, item_pos
, True
);
5380 XmListSetPos (list
, item_pos
);
5383 XmStringFree (default_xmstring
);
5386 record_unwind_protect (clean_up_file_dialog
, make_save_value (dialog
, 0));
5388 /* Process events until the user presses Cancel or OK. */
5389 x_menu_set_in_use (1);
5394 x_menu_wait_for_event (0);
5395 XtAppNextEvent (Xt_app_con
, &event
);
5396 if (event
.type
== KeyPress
5397 && FRAME_X_DISPLAY (f
) == event
.xkey
.display
)
5399 KeySym keysym
= XLookupKeysym (&event
.xkey
, 0);
5401 /* Pop down on C-g. */
5402 if (keysym
== XK_g
&& (event
.xkey
.state
& ControlMask
) != 0)
5403 XtUnmanageChild (dialog
);
5406 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
));
5409 /* Get the result. */
5410 if (result
== XmCR_OK
)
5415 XtVaGetValues (dialog
, XmNtextString
, &text
, NULL
);
5416 XmStringGetLtoR (text
, XmFONTLIST_DEFAULT_TAG
, &data
);
5417 XmStringFree (text
);
5418 file
= build_string (data
);
5427 /* Make "Cancel" equivalent to C-g. */
5429 Fsignal (Qquit
, Qnil
);
5431 return unbind_to (count
, file
);
5434 #endif /* USE_MOTIF */
5439 clean_up_dialog (arg
)
5442 x_menu_set_in_use (0);
5447 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5448 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5449 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5450 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5451 or directory must exist. If ONLY-DIR-P is non-nil, the user can only select
5453 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
5454 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
5456 FRAME_PTR f
= SELECTED_FRAME ();
5458 Lisp_Object file
= Qnil
;
5459 int count
= SPECPDL_INDEX ();
5460 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5463 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5465 if (popup_activated ())
5466 error ("Trying to use a menu from within a menu-entry");
5468 CHECK_STRING (prompt
);
5471 /* Prevent redisplay. */
5472 specbind (Qinhibit_redisplay
, Qt
);
5473 record_unwind_protect (clean_up_dialog
, Qnil
);
5477 if (STRINGP (default_filename
))
5478 cdef_file
= SDATA (default_filename
);
5480 cdef_file
= SDATA (dir
);
5482 fn
= xg_get_file_name (f
, SDATA (prompt
), cdef_file
,
5484 ! NILP (only_dir_p
));
5488 file
= build_string (fn
);
5495 /* Make "Cancel" equivalent to C-g. */
5497 Fsignal (Qquit
, Qnil
);
5499 return unbind_to (count
, file
);
5502 #endif /* USE_GTK */
5505 /***********************************************************************
5507 ***********************************************************************/
5509 #ifdef HAVE_XKBGETKEYBOARD
5510 #include <X11/XKBlib.h>
5511 #include <X11/keysym.h>
5514 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
5515 Sx_backspace_delete_keys_p
, 0, 1, 0,
5516 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
5517 FRAME nil means use the selected frame.
5518 Value is t if we know that both keys are present, and are mapped to the
5519 usual X keysyms. */)
5523 #ifdef HAVE_XKBGETKEYBOARD
5525 struct frame
*f
= check_x_frame (frame
);
5526 Display
*dpy
= FRAME_X_DISPLAY (f
);
5527 Lisp_Object have_keys
;
5528 int major
, minor
, op
, event
, error
;
5532 /* Check library version in case we're dynamically linked. */
5533 major
= XkbMajorVersion
;
5534 minor
= XkbMinorVersion
;
5535 if (!XkbLibraryVersion (&major
, &minor
))
5541 /* Check that the server supports XKB. */
5542 major
= XkbMajorVersion
;
5543 minor
= XkbMinorVersion
;
5544 if (!XkbQueryExtension (dpy
, &op
, &event
, &error
, &major
, &minor
))
5550 /* In this code we check that the keyboard has physical keys with names
5551 that start with BKSP (Backspace) and DELE (Delete), and that they
5552 generate keysym XK_BackSpace and XK_Delete respectively.
5553 This function is used to test if normal-erase-is-backspace should be
5555 An alternative approach would be to just check if XK_BackSpace and
5556 XK_Delete are mapped to any key. But if any of those are mapped to
5557 some non-intuitive key combination (Meta-Shift-Ctrl-whatever) and the
5558 user doesn't know about it, it is better to return false here.
5559 It is more obvious to the user what to do if she/he has two keys
5560 clearly marked with names/symbols and one key does something not
5561 expected (i.e. she/he then tries the other).
5562 The cases where Backspace/Delete is mapped to some other key combination
5563 are rare, and in those cases, normal-erase-is-backspace can be turned on
5567 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
5570 int delete_keycode
= 0, backspace_keycode
= 0, i
;
5572 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
5574 for (i
= kb
->min_key_code
;
5575 (i
< kb
->max_key_code
5576 && (delete_keycode
== 0 || backspace_keycode
== 0));
5579 /* The XKB symbolic key names can be seen most easily in
5580 the PS file generated by `xkbprint -label name
5582 if (bcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
5584 else if (bcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
5585 backspace_keycode
= i
;
5588 XkbFreeNames (kb
, 0, True
);
5591 XkbFreeClientMap (kb
, 0, True
);
5594 && backspace_keycode
5595 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
5596 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
5601 #else /* not HAVE_XKBGETKEYBOARD */
5603 #endif /* not HAVE_XKBGETKEYBOARD */
5608 /***********************************************************************
5610 ***********************************************************************/
5612 /* Keep this list in the same order as frame_parms in frame.c.
5613 Use 0 for unsupported frame parameters. */
5615 frame_parm_handler x_frame_parm_handlers
[] =
5619 x_set_background_color
,
5625 x_set_foreground_color
,
5628 x_set_internal_border_width
,
5629 x_set_menu_bar_lines
,
5631 x_explicitly_set_name
,
5632 x_set_scroll_bar_width
,
5635 x_set_vertical_scroll_bars
,
5637 x_set_tool_bar_lines
,
5638 x_set_scroll_bar_foreground
,
5639 x_set_scroll_bar_background
,
5651 /* This is zero if not using X windows. */
5654 /* The section below is built by the lisp expression at the top of the file,
5655 just above where these variables are declared. */
5656 /*&&& init symbols here &&&*/
5657 Qnone
= intern ("none");
5659 Qsuppress_icon
= intern ("suppress-icon");
5660 staticpro (&Qsuppress_icon
);
5661 Qundefined_color
= intern ("undefined-color");
5662 staticpro (&Qundefined_color
);
5663 Qcompound_text
= intern ("compound-text");
5664 staticpro (&Qcompound_text
);
5665 Qcancel_timer
= intern ("cancel-timer");
5666 staticpro (&Qcancel_timer
);
5667 /* This is the end of symbol initialization. */
5669 /* Text property `display' should be nonsticky by default. */
5670 Vtext_property_default_nonsticky
5671 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
5674 Fput (Qundefined_color
, Qerror_conditions
,
5675 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
5676 Fput (Qundefined_color
, Qerror_message
,
5677 build_string ("Undefined color"));
5679 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
5680 doc
: /* The shape of the pointer when over text.
5681 Changing the value does not affect existing frames
5682 unless you set the mouse color. */);
5683 Vx_pointer_shape
= Qnil
;
5685 #if 0 /* This doesn't really do anything. */
5686 DEFVAR_LISP ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape
,
5687 doc
: /* The shape of the pointer when not over text.
5688 This variable takes effect when you create a new frame
5689 or when you set the mouse color. */);
5691 Vx_nontext_pointer_shape
= Qnil
;
5693 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
5694 doc
: /* The shape of the pointer when Emacs is busy.
5695 This variable takes effect when you create a new frame
5696 or when you set the mouse color. */);
5697 Vx_hourglass_pointer_shape
= Qnil
;
5699 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
5700 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
5701 display_hourglass_p
= 1;
5703 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
5704 doc
: /* *Seconds to wait before displaying an hourglass pointer.
5705 Value must be an integer or float. */);
5706 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
5708 #if 0 /* This doesn't really do anything. */
5709 DEFVAR_LISP ("x-mode-pointer-shape", &Vx_mode_pointer_shape
,
5710 doc
: /* The shape of the pointer when over the mode line.
5711 This variable takes effect when you create a new frame
5712 or when you set the mouse color. */);
5714 Vx_mode_pointer_shape
= Qnil
;
5716 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
5717 &Vx_sensitive_text_pointer_shape
,
5718 doc
: /* The shape of the pointer when over mouse-sensitive text.
5719 This variable takes effect when you create a new frame
5720 or when you set the mouse color. */);
5721 Vx_sensitive_text_pointer_shape
= Qnil
;
5723 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
5724 &Vx_window_horizontal_drag_shape
,
5725 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
5726 This variable takes effect when you create a new frame
5727 or when you set the mouse color. */);
5728 Vx_window_horizontal_drag_shape
= Qnil
;
5730 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
5731 doc
: /* A string indicating the foreground color of the cursor box. */);
5732 Vx_cursor_fore_pixel
= Qnil
;
5734 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
5735 doc
: /* Maximum size for tooltips. Value is a pair (COLUMNS . ROWS).
5736 Text larger than this is clipped. */);
5737 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
5739 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
5740 doc
: /* Non-nil if no X window manager is in use.
5741 Emacs doesn't try to figure this out; this is always nil
5742 unless you set it to something else. */);
5743 /* We don't have any way to find this out, so set it to nil
5744 and maybe the user would like to set it to t. */
5745 Vx_no_window_manager
= Qnil
;
5747 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
5748 &Vx_pixel_size_width_font_regexp
,
5749 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
5751 Since Emacs gets width of a font matching with this regexp from
5752 PIXEL_SIZE field of the name, font finding mechanism gets faster for
5753 such a font. This is especially effective for such large fonts as
5754 Chinese, Japanese, and Korean. */);
5755 Vx_pixel_size_width_font_regexp
= Qnil
;
5757 /* This is not ifdef:ed, so other builds than GTK can customize it. */
5758 DEFVAR_BOOL ("x-use-old-gtk-file-dialog", &x_use_old_gtk_file_dialog
,
5759 doc
: /* *Non-nil means prompt with the old GTK file selection dialog.
5760 If nil or if the file selection dialog is not available, the new GTK file
5761 chooser is used instead. To turn off all file dialogs set the
5762 variable `use-file-dialog'. */);
5763 x_use_old_gtk_file_dialog
= 0;
5765 Fprovide (intern ("x"), Qnil
);
5767 #ifdef USE_X_TOOLKIT
5768 Fprovide (intern ("x-toolkit"), Qnil
);
5770 Fprovide (intern ("motif"), Qnil
);
5772 DEFVAR_LISP ("motif-version-string", &Vmotif_version_string
,
5773 doc
: /* Version info for LessTif/Motif. */);
5774 Vmotif_version_string
= build_string (XmVERSION_STRING
);
5775 #endif /* USE_MOTIF */
5776 #endif /* USE_X_TOOLKIT */
5779 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
5780 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
5781 But for a user it is a toolkit for X, and indeed, configure
5782 accepts --with-x-toolkit=gtk. */
5783 Fprovide (intern ("x-toolkit"), Qnil
);
5784 Fprovide (intern ("gtk"), Qnil
);
5786 DEFVAR_LISP ("gtk-version-string", &Vgtk_version_string
,
5787 doc
: /* Version info for GTK+. */);
5789 char gtk_version
[40];
5790 g_snprintf (gtk_version
, sizeof (gtk_version
), "%u.%u.%u",
5791 GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
);
5792 Vgtk_version_string
= build_string (gtk_version
);
5794 #endif /* USE_GTK */
5796 /* X window properties. */
5797 defsubr (&Sx_change_window_property
);
5798 defsubr (&Sx_delete_window_property
);
5799 defsubr (&Sx_window_property
);
5801 defsubr (&Sxw_display_color_p
);
5802 defsubr (&Sx_display_grayscale_p
);
5803 defsubr (&Sxw_color_defined_p
);
5804 defsubr (&Sxw_color_values
);
5805 defsubr (&Sx_server_max_request_size
);
5806 defsubr (&Sx_server_vendor
);
5807 defsubr (&Sx_server_version
);
5808 defsubr (&Sx_display_pixel_width
);
5809 defsubr (&Sx_display_pixel_height
);
5810 defsubr (&Sx_display_mm_width
);
5811 defsubr (&Sx_display_mm_height
);
5812 defsubr (&Sx_display_screens
);
5813 defsubr (&Sx_display_planes
);
5814 defsubr (&Sx_display_color_cells
);
5815 defsubr (&Sx_display_visual_class
);
5816 defsubr (&Sx_display_backing_store
);
5817 defsubr (&Sx_display_save_under
);
5818 defsubr (&Sx_create_frame
);
5819 defsubr (&Sx_open_connection
);
5820 defsubr (&Sx_close_connection
);
5821 defsubr (&Sx_display_list
);
5822 defsubr (&Sx_synchronize
);
5823 defsubr (&Sx_focus_frame
);
5824 defsubr (&Sx_backspace_delete_keys_p
);
5826 /* Setting callback functions for fontset handler. */
5827 get_font_info_func
= x_get_font_info
;
5829 #if 0 /* This function pointer doesn't seem to be used anywhere.
5830 And the pointer assigned has the wrong type, anyway. */
5831 list_fonts_func
= x_list_fonts
;
5834 load_font_func
= x_load_font
;
5835 find_ccl_program_func
= x_find_ccl_program
;
5836 query_font_func
= x_query_font
;
5837 set_frame_fontset_func
= x_set_font
;
5838 check_window_system_func
= check_x
;
5840 hourglass_atimer
= NULL
;
5841 hourglass_shown_p
= 0;
5843 defsubr (&Sx_show_tip
);
5844 defsubr (&Sx_hide_tip
);
5846 staticpro (&tip_timer
);
5848 staticpro (&tip_frame
);
5850 last_show_tip_args
= Qnil
;
5851 staticpro (&last_show_tip_args
);
5853 #if defined (USE_MOTIF) || defined (USE_GTK)
5854 defsubr (&Sx_file_dialog
);
5858 #endif /* HAVE_X_WINDOWS */
5860 /* arch-tag: 55040d02-5485-4d58-8b22-95a7a05f3288
5861 (do not change this comment) */