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
);
797 char *filename
= (char *) SDATA (found
);
800 pixbuf
= gdk_pixbuf_new_from_file (filename
, &err
);
804 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
806 g_object_unref (pixbuf
);
821 xg_set_icon_from_xpm_data (f
, data
)
826 GdkPixbuf
*pixbuf
= gdk_pixbuf_new_from_xpm_data ((const char **) data
);
831 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)), pixbuf
);
832 g_object_unref (pixbuf
);
838 /* Functions called only from `x_set_frame_param'
839 to set individual parameters.
841 If FRAME_X_WINDOW (f) is 0,
842 the frame is being created and its X-window does not exist yet.
843 In that case, just record the parameter's new value
844 in the standard place; do not attempt to change the window. */
847 x_set_foreground_color (f
, arg
, oldval
)
849 Lisp_Object arg
, oldval
;
851 struct x_output
*x
= f
->output_data
.x
;
852 unsigned long fg
, old_fg
;
854 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
855 old_fg
= x
->foreground_pixel
;
856 x
->foreground_pixel
= fg
;
858 if (FRAME_X_WINDOW (f
) != 0)
860 Display
*dpy
= FRAME_X_DISPLAY (f
);
863 XSetForeground (dpy
, x
->normal_gc
, fg
);
864 XSetBackground (dpy
, x
->reverse_gc
, fg
);
866 if (x
->cursor_pixel
== old_fg
)
868 unload_color (f
, x
->cursor_pixel
);
869 x
->cursor_pixel
= x_copy_color (f
, fg
);
870 XSetBackground (dpy
, x
->cursor_gc
, x
->cursor_pixel
);
875 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
877 if (FRAME_VISIBLE_P (f
))
881 unload_color (f
, old_fg
);
885 x_set_background_color (f
, arg
, oldval
)
887 Lisp_Object arg
, oldval
;
889 struct x_output
*x
= f
->output_data
.x
;
892 bg
= x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
893 unload_color (f
, x
->background_pixel
);
894 x
->background_pixel
= bg
;
896 if (FRAME_X_WINDOW (f
) != 0)
898 Display
*dpy
= FRAME_X_DISPLAY (f
);
901 XSetBackground (dpy
, x
->normal_gc
, bg
);
902 XSetForeground (dpy
, x
->reverse_gc
, bg
);
903 XSetWindowBackground (dpy
, FRAME_X_WINDOW (f
), bg
);
904 XSetForeground (dpy
, x
->cursor_gc
, bg
);
907 xg_set_background_color (f
, bg
);
910 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
911 toolkit scroll bars. */
914 for (bar
= FRAME_SCROLL_BARS (f
);
916 bar
= XSCROLL_BAR (bar
)->next
)
918 Window window
= SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
));
919 XSetWindowBackground (dpy
, window
, bg
);
922 #endif /* USE_TOOLKIT_SCROLL_BARS */
925 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
927 if (FRAME_VISIBLE_P (f
))
933 x_set_mouse_color (f
, arg
, oldval
)
935 Lisp_Object arg
, oldval
;
937 struct x_output
*x
= f
->output_data
.x
;
938 Display
*dpy
= FRAME_X_DISPLAY (f
);
939 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
940 Cursor hourglass_cursor
, horizontal_drag_cursor
;
942 unsigned long pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
943 unsigned long mask_color
= x
->background_pixel
;
945 /* Don't let pointers be invisible. */
946 if (mask_color
== pixel
)
948 x_free_colors (f
, &pixel
, 1);
949 pixel
= x_copy_color (f
, x
->foreground_pixel
);
952 unload_color (f
, x
->mouse_pixel
);
953 x
->mouse_pixel
= pixel
;
957 /* It's not okay to crash if the user selects a screwy cursor. */
958 count
= x_catch_errors (dpy
);
960 if (!NILP (Vx_pointer_shape
))
962 CHECK_NUMBER (Vx_pointer_shape
);
963 cursor
= XCreateFontCursor (dpy
, XINT (Vx_pointer_shape
));
966 cursor
= XCreateFontCursor (dpy
, XC_xterm
);
967 x_check_errors (dpy
, "bad text pointer cursor: %s");
969 if (!NILP (Vx_nontext_pointer_shape
))
971 CHECK_NUMBER (Vx_nontext_pointer_shape
);
973 = XCreateFontCursor (dpy
, XINT (Vx_nontext_pointer_shape
));
976 nontext_cursor
= XCreateFontCursor (dpy
, XC_left_ptr
);
977 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
979 if (!NILP (Vx_hourglass_pointer_shape
))
981 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
983 = XCreateFontCursor (dpy
, XINT (Vx_hourglass_pointer_shape
));
986 hourglass_cursor
= XCreateFontCursor (dpy
, XC_watch
);
987 x_check_errors (dpy
, "bad hourglass pointer cursor: %s");
989 if (!NILP (Vx_mode_pointer_shape
))
991 CHECK_NUMBER (Vx_mode_pointer_shape
);
992 mode_cursor
= XCreateFontCursor (dpy
, XINT (Vx_mode_pointer_shape
));
995 mode_cursor
= XCreateFontCursor (dpy
, XC_xterm
);
996 x_check_errors (dpy
, "bad modeline pointer cursor: %s");
998 if (!NILP (Vx_sensitive_text_pointer_shape
))
1000 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
1002 = XCreateFontCursor (dpy
, XINT (Vx_sensitive_text_pointer_shape
));
1005 hand_cursor
= XCreateFontCursor (dpy
, XC_hand2
);
1007 if (!NILP (Vx_window_horizontal_drag_shape
))
1009 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1010 horizontal_drag_cursor
1011 = XCreateFontCursor (dpy
, XINT (Vx_window_horizontal_drag_shape
));
1014 horizontal_drag_cursor
1015 = XCreateFontCursor (dpy
, XC_sb_h_double_arrow
);
1017 /* Check and report errors with the above calls. */
1018 x_check_errors (dpy
, "can't set cursor shape: %s");
1019 x_uncatch_errors (dpy
, count
);
1022 XColor fore_color
, back_color
;
1024 fore_color
.pixel
= x
->mouse_pixel
;
1025 x_query_color (f
, &fore_color
);
1026 back_color
.pixel
= mask_color
;
1027 x_query_color (f
, &back_color
);
1029 XRecolorCursor (dpy
, cursor
, &fore_color
, &back_color
);
1030 XRecolorCursor (dpy
, nontext_cursor
, &fore_color
, &back_color
);
1031 XRecolorCursor (dpy
, mode_cursor
, &fore_color
, &back_color
);
1032 XRecolorCursor (dpy
, hand_cursor
, &fore_color
, &back_color
);
1033 XRecolorCursor (dpy
, hourglass_cursor
, &fore_color
, &back_color
);
1034 XRecolorCursor (dpy
, horizontal_drag_cursor
, &fore_color
, &back_color
);
1037 if (FRAME_X_WINDOW (f
) != 0)
1038 XDefineCursor (dpy
, FRAME_X_WINDOW (f
), cursor
);
1040 if (cursor
!= x
->text_cursor
1041 && x
->text_cursor
!= 0)
1042 XFreeCursor (dpy
, x
->text_cursor
);
1043 x
->text_cursor
= cursor
;
1045 if (nontext_cursor
!= x
->nontext_cursor
1046 && x
->nontext_cursor
!= 0)
1047 XFreeCursor (dpy
, x
->nontext_cursor
);
1048 x
->nontext_cursor
= nontext_cursor
;
1050 if (hourglass_cursor
!= x
->hourglass_cursor
1051 && x
->hourglass_cursor
!= 0)
1052 XFreeCursor (dpy
, x
->hourglass_cursor
);
1053 x
->hourglass_cursor
= hourglass_cursor
;
1055 if (mode_cursor
!= x
->modeline_cursor
1056 && x
->modeline_cursor
!= 0)
1057 XFreeCursor (dpy
, f
->output_data
.x
->modeline_cursor
);
1058 x
->modeline_cursor
= mode_cursor
;
1060 if (hand_cursor
!= x
->hand_cursor
1061 && x
->hand_cursor
!= 0)
1062 XFreeCursor (dpy
, x
->hand_cursor
);
1063 x
->hand_cursor
= hand_cursor
;
1065 if (horizontal_drag_cursor
!= x
->horizontal_drag_cursor
1066 && x
->horizontal_drag_cursor
!= 0)
1067 XFreeCursor (dpy
, x
->horizontal_drag_cursor
);
1068 x
->horizontal_drag_cursor
= horizontal_drag_cursor
;
1073 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1077 x_set_cursor_color (f
, arg
, oldval
)
1079 Lisp_Object arg
, oldval
;
1081 unsigned long fore_pixel
, pixel
;
1082 int fore_pixel_allocated_p
= 0, pixel_allocated_p
= 0;
1083 struct x_output
*x
= f
->output_data
.x
;
1085 if (!NILP (Vx_cursor_fore_pixel
))
1087 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1088 WHITE_PIX_DEFAULT (f
));
1089 fore_pixel_allocated_p
= 1;
1092 fore_pixel
= x
->background_pixel
;
1094 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1095 pixel_allocated_p
= 1;
1097 /* Make sure that the cursor color differs from the background color. */
1098 if (pixel
== x
->background_pixel
)
1100 if (pixel_allocated_p
)
1102 x_free_colors (f
, &pixel
, 1);
1103 pixel_allocated_p
= 0;
1106 pixel
= x
->mouse_pixel
;
1107 if (pixel
== fore_pixel
)
1109 if (fore_pixel_allocated_p
)
1111 x_free_colors (f
, &fore_pixel
, 1);
1112 fore_pixel_allocated_p
= 0;
1114 fore_pixel
= x
->background_pixel
;
1118 unload_color (f
, x
->cursor_foreground_pixel
);
1119 if (!fore_pixel_allocated_p
)
1120 fore_pixel
= x_copy_color (f
, fore_pixel
);
1121 x
->cursor_foreground_pixel
= fore_pixel
;
1123 unload_color (f
, x
->cursor_pixel
);
1124 if (!pixel_allocated_p
)
1125 pixel
= x_copy_color (f
, pixel
);
1126 x
->cursor_pixel
= pixel
;
1128 if (FRAME_X_WINDOW (f
) != 0)
1131 XSetBackground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, x
->cursor_pixel
);
1132 XSetForeground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, fore_pixel
);
1135 if (FRAME_VISIBLE_P (f
))
1137 x_update_cursor (f
, 0);
1138 x_update_cursor (f
, 1);
1142 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1145 /* Set the border-color of frame F to pixel value PIX.
1146 Note that this does not fully take effect if done before
1147 F has an x-window. */
1150 x_set_border_pixel (f
, pix
)
1154 unload_color (f
, f
->output_data
.x
->border_pixel
);
1155 f
->output_data
.x
->border_pixel
= pix
;
1157 if (FRAME_X_WINDOW (f
) != 0 && f
->border_width
> 0)
1160 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1161 (unsigned long)pix
);
1164 if (FRAME_VISIBLE_P (f
))
1169 /* Set the border-color of frame F to value described by ARG.
1170 ARG can be a string naming a color.
1171 The border-color is used for the border that is drawn by the X server.
1172 Note that this does not fully take effect if done before
1173 F has an x-window; it must be redone when the window is created.
1175 Note: this is done in two routines because of the way X10 works.
1177 Note: under X11, this is normally the province of the window manager,
1178 and so emacs' border colors may be overridden. */
1181 x_set_border_color (f
, arg
, oldval
)
1183 Lisp_Object arg
, oldval
;
1188 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1189 x_set_border_pixel (f
, pix
);
1190 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1195 x_set_cursor_type (f
, arg
, oldval
)
1197 Lisp_Object arg
, oldval
;
1199 set_frame_cursor_types (f
, arg
);
1201 /* Make sure the cursor gets redrawn. */
1202 cursor_type_changed
= 1;
1206 x_set_icon_type (f
, arg
, oldval
)
1208 Lisp_Object arg
, oldval
;
1214 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1217 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1222 result
= x_text_icon (f
,
1223 (char *) SDATA ((!NILP (f
->icon_name
)
1227 result
= x_bitmap_icon (f
, arg
);
1232 error ("No icon window available");
1235 XFlush (FRAME_X_DISPLAY (f
));
1240 x_set_icon_name (f
, arg
, oldval
)
1242 Lisp_Object arg
, oldval
;
1248 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1251 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1256 if (f
->output_data
.x
->icon_bitmap
!= 0)
1261 result
= x_text_icon (f
,
1262 (char *) SDATA ((!NILP (f
->icon_name
)
1271 error ("No icon window available");
1274 XFlush (FRAME_X_DISPLAY (f
));
1280 x_set_menu_bar_lines (f
, value
, oldval
)
1282 Lisp_Object value
, oldval
;
1285 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
1286 int olines
= FRAME_MENU_BAR_LINES (f
);
1289 /* Right now, menu bars don't work properly in minibuf-only frames;
1290 most of the commands try to apply themselves to the minibuffer
1291 frame itself, and get an error because you can't switch buffers
1292 in or split the minibuffer window. */
1293 if (FRAME_MINIBUF_ONLY_P (f
))
1296 if (INTEGERP (value
))
1297 nlines
= XINT (value
);
1301 /* Make sure we redisplay all windows in this frame. */
1302 windows_or_buffers_changed
++;
1304 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
1305 FRAME_MENU_BAR_LINES (f
) = 0;
1308 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1309 if (FRAME_X_P (f
) && f
->output_data
.x
->menubar_widget
== 0)
1310 /* Make sure next redisplay shows the menu bar. */
1311 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= Qt
;
1315 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1316 free_frame_menubar (f
);
1317 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1319 f
->output_data
.x
->menubar_widget
= 0;
1321 #else /* not USE_X_TOOLKIT && not USE_GTK */
1322 FRAME_MENU_BAR_LINES (f
) = nlines
;
1323 change_window_heights (f
->root_window
, nlines
- olines
);
1324 #endif /* not USE_X_TOOLKIT */
1329 /* Set the number of lines used for the tool bar of frame F to VALUE.
1330 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1331 is the old number of tool bar lines. This function changes the
1332 height of all windows on frame F to match the new tool bar height.
1333 The frame's height doesn't change. */
1336 x_set_tool_bar_lines (f
, value
, oldval
)
1338 Lisp_Object value
, oldval
;
1340 int delta
, nlines
, root_height
;
1341 Lisp_Object root_window
;
1343 /* Treat tool bars like menu bars. */
1344 if (FRAME_MINIBUF_ONLY_P (f
))
1347 /* Use VALUE only if an integer >= 0. */
1348 if (INTEGERP (value
) && XINT (value
) >= 0)
1349 nlines
= XFASTINT (value
);
1354 FRAME_TOOL_BAR_LINES (f
) = 0;
1357 FRAME_EXTERNAL_TOOL_BAR (f
) = 1;
1358 if (FRAME_X_P (f
) && f
->output_data
.x
->toolbar_widget
== 0)
1359 /* Make sure next redisplay shows the tool bar. */
1360 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= Qt
;
1361 update_frame_tool_bar (f
);
1365 if (FRAME_EXTERNAL_TOOL_BAR (f
))
1366 free_frame_tool_bar (f
);
1367 FRAME_EXTERNAL_TOOL_BAR (f
) = 0;
1373 /* Make sure we redisplay all windows in this frame. */
1374 ++windows_or_buffers_changed
;
1376 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1378 /* Don't resize the tool-bar to more than we have room for. */
1379 root_window
= FRAME_ROOT_WINDOW (f
);
1380 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1381 if (root_height
- delta
< 1)
1383 delta
= root_height
- 1;
1384 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1387 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1388 change_window_heights (root_window
, delta
);
1391 /* We also have to make sure that the internal border at the top of
1392 the frame, below the menu bar or tool bar, is redrawn when the
1393 tool bar disappears. This is so because the internal border is
1394 below the tool bar if one is displayed, but is below the menu bar
1395 if there isn't a tool bar. The tool bar draws into the area
1396 below the menu bar. */
1397 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1401 clear_current_matrices (f
);
1402 updating_frame
= NULL
;
1405 /* If the tool bar gets smaller, the internal border below it
1406 has to be cleared. It was formerly part of the display
1407 of the larger tool bar, and updating windows won't clear it. */
1410 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1411 int width
= FRAME_PIXEL_WIDTH (f
);
1412 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1414 /* height can be zero here. */
1415 if (height
> 0 && width
> 0)
1418 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1419 0, y
, width
, height
, False
);
1423 if (WINDOWP (f
->tool_bar_window
))
1424 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1429 /* Set the foreground color for scroll bars on frame F to VALUE.
1430 VALUE should be a string, a color name. If it isn't a string or
1431 isn't a valid color name, do nothing. OLDVAL is the old value of
1432 the frame parameter. */
1435 x_set_scroll_bar_foreground (f
, value
, oldval
)
1437 Lisp_Object value
, oldval
;
1439 unsigned long pixel
;
1441 if (STRINGP (value
))
1442 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
1446 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
1447 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
1449 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
1450 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1452 /* Remove all scroll bars because they have wrong colors. */
1453 if (condemn_scroll_bars_hook
)
1454 (*condemn_scroll_bars_hook
) (f
);
1455 if (judge_scroll_bars_hook
)
1456 (*judge_scroll_bars_hook
) (f
);
1458 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
1464 /* Set the background color for scroll bars on frame F to VALUE VALUE
1465 should be a string, a color name. If it isn't a string or isn't a
1466 valid color name, do nothing. OLDVAL is the old value of the frame
1470 x_set_scroll_bar_background (f
, value
, oldval
)
1472 Lisp_Object value
, oldval
;
1474 unsigned long pixel
;
1476 if (STRINGP (value
))
1477 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
1481 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
1482 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
1484 #ifdef USE_TOOLKIT_SCROLL_BARS
1485 /* Scrollbar shadow colors. */
1486 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
1488 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
1489 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
1491 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
1493 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
1494 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
1496 #endif /* USE_TOOLKIT_SCROLL_BARS */
1498 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
1499 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1501 /* Remove all scroll bars because they have wrong colors. */
1502 if (condemn_scroll_bars_hook
)
1503 (*condemn_scroll_bars_hook
) (f
);
1504 if (judge_scroll_bars_hook
)
1505 (*judge_scroll_bars_hook
) (f
);
1507 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
1513 /* Encode Lisp string STRING as a text in a format appropriate for
1514 XICCC (X Inter Client Communication Conventions).
1516 If STRING contains only ASCII characters, do no conversion and
1517 return the string data of STRING. Otherwise, encode the text by
1518 CODING_SYSTEM, and return a newly allocated memory area which
1519 should be freed by `xfree' by a caller.
1521 SELECTIONP non-zero means the string is being encoded for an X
1522 selection, so it is safe to run pre-write conversions (which
1525 Store the byte length of resulting text in *TEXT_BYTES.
1527 If the text contains only ASCII and Latin-1, store 1 in *STRING_P,
1528 which means that the `encoding' of the result can be `STRING'.
1529 Otherwise store 0 in *STRINGP, which means that the `encoding' of
1530 the result should be `COMPOUND_TEXT'. */
1532 static unsigned char *
1533 x_encode_text (string
, coding_system
, selectionp
, text_bytes
, stringp
, freep
)
1534 Lisp_Object string
, coding_system
;
1535 int *text_bytes
, *stringp
;
1539 unsigned char *str
= SDATA (string
);
1540 int chars
= SCHARS (string
);
1541 int bytes
= SBYTES (string
);
1545 struct coding_system coding
;
1546 extern Lisp_Object Qcompound_text_with_extensions
;
1548 charset_info
= find_charset_in_text (str
, chars
, bytes
, NULL
, Qnil
);
1549 if (charset_info
== 0)
1551 /* No multibyte character in OBJ. We need not encode it. */
1552 *text_bytes
= bytes
;
1558 setup_coding_system (coding_system
, &coding
);
1560 && SYMBOLP (coding
.pre_write_conversion
)
1561 && !NILP (Ffboundp (coding
.pre_write_conversion
)))
1563 string
= run_pre_post_conversion_on_str (string
, &coding
, 1);
1564 str
= SDATA (string
);
1565 chars
= SCHARS (string
);
1566 bytes
= SBYTES (string
);
1568 coding
.src_multibyte
= 1;
1569 coding
.dst_multibyte
= 0;
1570 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
1571 if (coding
.type
== coding_type_iso2022
)
1572 coding
.flags
|= CODING_FLAG_ISO_SAFE
;
1573 /* We suppress producing escape sequences for composition. */
1574 coding
.composing
= COMPOSITION_DISABLED
;
1575 bufsize
= encoding_buffer_size (&coding
, bytes
);
1576 buf
= (unsigned char *) xmalloc (bufsize
);
1577 encode_coding (&coding
, str
, buf
, bytes
, bufsize
);
1578 *text_bytes
= coding
.produced
;
1579 *stringp
= (charset_info
== 1
1580 || (!EQ (coding_system
, Qcompound_text
)
1581 && !EQ (coding_system
, Qcompound_text_with_extensions
)));
1587 /* Set the WM name to NAME for frame F. Also set the icon name.
1588 If the frame already has an icon name, use that, otherwise set the
1589 icon name to NAME. */
1592 x_set_name_internal (f
, name
)
1596 if (FRAME_X_WINDOW (f
))
1601 XTextProperty text
, icon
;
1603 int do_free_icon_value
= 0, do_free_text_value
= 0;
1604 Lisp_Object coding_system
;
1606 coding_system
= Qcompound_text
;
1607 /* Note: Encoding strategy
1609 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1610 text.encoding. But, there are non-internationalized window
1611 managers which don't support that encoding. So, if NAME
1612 contains only ASCII and 8859-1 characters, encode it by
1613 iso-latin-1, and use "STRING" in text.encoding hoping that
1614 such window managers at least analyze this format correctly,
1615 i.e. treat 8-bit bytes as 8859-1 characters.
1617 We may also be able to use "UTF8_STRING" in text.encoding
1618 in the future which can encode all Unicode characters.
1619 But, for the moment, there's no way to know that the
1620 current window manager supports it or not. */
1621 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
,
1622 &do_free_text_value
);
1623 text
.encoding
= (stringp
? XA_STRING
1624 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1626 text
.nitems
= bytes
;
1628 if (NILP (f
->icon_name
))
1634 /* See the above comment "Note: Encoding strategy". */
1635 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
1636 &bytes
, &stringp
, &do_free_icon_value
);
1637 icon
.encoding
= (stringp
? XA_STRING
1638 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1640 icon
.nitems
= bytes
;
1644 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1645 (char *) SDATA (ENCODE_UTF_8 (name
)));
1646 #else /* not USE_GTK */
1647 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1648 #endif /* not USE_GTK */
1650 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &icon
);
1652 if (do_free_icon_value
)
1654 if (do_free_text_value
)
1657 #else /* not HAVE_X11R4 */
1658 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1660 XStoreName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1662 #endif /* not HAVE_X11R4 */
1667 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1670 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1671 name; if NAME is a string, set F's name to NAME and set
1672 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1674 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1675 suggesting a new name, which lisp code should override; if
1676 F->explicit_name is set, ignore the new name; otherwise, set it. */
1679 x_set_name (f
, name
, explicit)
1684 /* Make sure that requests from lisp code override requests from
1685 Emacs redisplay code. */
1688 /* If we're switching from explicit to implicit, we had better
1689 update the mode lines and thereby update the title. */
1690 if (f
->explicit_name
&& NILP (name
))
1691 update_mode_lines
= 1;
1693 f
->explicit_name
= ! NILP (name
);
1695 else if (f
->explicit_name
)
1698 /* If NAME is nil, set the name to the x_id_name. */
1701 /* Check for no change needed in this very common case
1702 before we do any consing. */
1703 if (!strcmp (FRAME_X_DISPLAY_INFO (f
)->x_id_name
,
1706 name
= build_string (FRAME_X_DISPLAY_INFO (f
)->x_id_name
);
1709 CHECK_STRING (name
);
1711 /* Don't change the name if it's already NAME. */
1712 if (! NILP (Fstring_equal (name
, f
->name
)))
1717 /* For setting the frame title, the title parameter should override
1718 the name parameter. */
1719 if (! NILP (f
->title
))
1722 x_set_name_internal (f
, name
);
1725 /* This function should be called when the user's lisp code has
1726 specified a name for the frame; the name will override any set by the
1729 x_explicitly_set_name (f
, arg
, oldval
)
1731 Lisp_Object arg
, oldval
;
1733 x_set_name (f
, arg
, 1);
1736 /* This function should be called by Emacs redisplay code to set the
1737 name; names set this way will never override names set by the user's
1740 x_implicitly_set_name (f
, arg
, oldval
)
1742 Lisp_Object arg
, oldval
;
1744 x_set_name (f
, arg
, 0);
1747 /* Change the title of frame F to NAME.
1748 If NAME is nil, use the frame name as the title.
1750 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1751 name; if NAME is a string, set F's name to NAME and set
1752 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1754 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1755 suggesting a new name, which lisp code should override; if
1756 F->explicit_name is set, ignore the new name; otherwise, set it. */
1759 x_set_title (f
, name
, old_name
)
1761 Lisp_Object name
, old_name
;
1763 /* Don't change the title if it's already NAME. */
1764 if (EQ (name
, f
->title
))
1767 update_mode_lines
= 1;
1774 CHECK_STRING (name
);
1776 x_set_name_internal (f
, name
);
1780 x_set_scroll_bar_default_width (f
)
1783 int wid
= FRAME_COLUMN_WIDTH (f
);
1785 #ifdef USE_TOOLKIT_SCROLL_BARS
1786 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1787 int width
= 16 + 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1788 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (width
+ wid
- 1) / wid
;
1789 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = width
;
1791 /* Make the actual width at least 14 pixels and a multiple of a
1793 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
1795 /* Use all of that space (aside from required margins) for the
1797 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = 0;
1802 /* Record in frame F the specified or default value according to ALIST
1803 of the parameter named PROP (a Lisp symbol). If no value is
1804 specified for PROP, look for an X default for XPROP on the frame
1805 named NAME. If that is not found either, use the value DEFLT. */
1808 x_default_scroll_bar_color_parameter (f
, alist
, prop
, xprop
, xclass
,
1817 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1820 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
1821 if (EQ (tem
, Qunbound
))
1823 #ifdef USE_TOOLKIT_SCROLL_BARS
1825 /* See if an X resource for the scroll bar color has been
1827 tem
= display_x_get_resource (dpyinfo
,
1828 build_string (foreground_p
1832 build_string ("verticalScrollBar"),
1836 /* If nothing has been specified, scroll bars will use a
1837 toolkit-dependent default. Because these defaults are
1838 difficult to get at without actually creating a scroll
1839 bar, use nil to indicate that no color has been
1844 #else /* not USE_TOOLKIT_SCROLL_BARS */
1848 #endif /* not USE_TOOLKIT_SCROLL_BARS */
1851 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
1857 #if !defined (HAVE_X11R4) && !defined (HAVE_XSETWMPROTOCOLS)
1860 XSetWMProtocols (dpy
, w
, protocols
, count
)
1867 prop
= XInternAtom (dpy
, "WM_PROTOCOLS", False
);
1868 if (prop
== None
) return False
;
1869 XChangeProperty (dpy
, w
, prop
, XA_ATOM
, 32, PropModeReplace
,
1870 (unsigned char *) protocols
, count
);
1873 #endif /* not HAVE_X11R4 && not HAVE_XSETWMPROTOCOLS */
1875 #ifdef USE_X_TOOLKIT
1877 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
1878 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
1879 already be present because of the toolkit (Motif adds some of them,
1880 for example, but Xt doesn't). */
1883 hack_wm_protocols (f
, widget
)
1887 Display
*dpy
= XtDisplay (widget
);
1888 Window w
= XtWindow (widget
);
1889 int need_delete
= 1;
1896 unsigned char *catoms
;
1898 unsigned long nitems
= 0;
1899 unsigned long bytes_after
;
1901 if ((XGetWindowProperty (dpy
, w
,
1902 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1903 (long)0, (long)100, False
, XA_ATOM
,
1904 &type
, &format
, &nitems
, &bytes_after
,
1907 && format
== 32 && type
== XA_ATOM
)
1909 Atom
*atoms
= (Atom
*) catoms
;
1914 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
1916 else if (atoms
[nitems
]
1917 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
1919 else if (atoms
[nitems
]
1920 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
1931 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
1933 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
1935 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
1937 XChangeProperty (dpy
, w
, FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1938 XA_ATOM
, 32, PropModeAppend
,
1939 (unsigned char *) props
, count
);
1947 /* Support routines for XIC (X Input Context). */
1951 static XFontSet xic_create_xfontset
P_ ((struct frame
*, char *));
1952 static XIMStyle best_xim_style
P_ ((XIMStyles
*, XIMStyles
*));
1955 /* Supported XIM styles, ordered by preference. */
1957 static XIMStyle supported_xim_styles
[] =
1959 XIMPreeditPosition
| XIMStatusArea
,
1960 XIMPreeditPosition
| XIMStatusNothing
,
1961 XIMPreeditPosition
| XIMStatusNone
,
1962 XIMPreeditNothing
| XIMStatusArea
,
1963 XIMPreeditNothing
| XIMStatusNothing
,
1964 XIMPreeditNothing
| XIMStatusNone
,
1965 XIMPreeditNone
| XIMStatusArea
,
1966 XIMPreeditNone
| XIMStatusNothing
,
1967 XIMPreeditNone
| XIMStatusNone
,
1972 /* Create an X fontset on frame F with base font name BASE_FONTNAME. */
1974 char xic_defaut_fontset
[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
1976 /* Create an Xt fontset spec from the name of a base font.
1977 If `motif' is True use the Motif syntax. */
1979 xic_create_fontsetname (base_fontname
, motif
)
1980 char *base_fontname
;
1983 const char *sep
= motif
? ";" : ",";
1986 /* Make a fontset name from the base font name. */
1987 if (xic_defaut_fontset
== base_fontname
)
1988 { /* There is no base font name, use the default. */
1989 int len
= strlen (base_fontname
) + 2;
1990 fontsetname
= xmalloc (len
);
1991 bzero (fontsetname
, len
);
1992 strcpy (fontsetname
, base_fontname
);
1996 /* Make a fontset name from the base font name.
1997 The font set will be made of the following elements:
1999 - the base font where the charset spec is replaced by -*-*.
2000 - the same but with the family also replaced with -*-*-. */
2001 char *p
= base_fontname
;
2004 for (i
= 0; *p
; p
++)
2007 { /* As the font name doesn't conform to XLFD, we can't
2008 modify it to generalize it to allcs and allfamilies.
2009 Use the specified font plus the default. */
2010 int len
= strlen (base_fontname
) + strlen (xic_defaut_fontset
) + 3;
2011 fontsetname
= xmalloc (len
);
2012 bzero (fontsetname
, len
);
2013 strcpy (fontsetname
, base_fontname
);
2014 strcat (fontsetname
, sep
);
2015 strcat (fontsetname
, xic_defaut_fontset
);
2020 char *p1
= NULL
, *p2
= NULL
;
2021 char *font_allcs
= NULL
;
2022 char *font_allfamilies
= NULL
;
2023 char *font_all
= NULL
;
2024 char *allcs
= "*-*-*-*-*-*-*";
2025 char *allfamilies
= "-*-*-";
2026 char *all
= "*-*-*-*-";
2028 for (i
= 0, p
= base_fontname
; i
< 8; p
++)
2039 /* Build the font spec that matches all charsets. */
2040 len
= p
- base_fontname
+ strlen (allcs
) + 1;
2041 font_allcs
= (char *) alloca (len
);
2042 bzero (font_allcs
, len
);
2043 bcopy (base_fontname
, font_allcs
, p
- base_fontname
);
2044 strcat (font_allcs
, allcs
);
2046 /* Build the font spec that matches all families. */
2047 len
= p
- p1
+ strlen (allcs
) + strlen (allfamilies
) + 1;
2048 font_allfamilies
= (char *) alloca (len
);
2049 bzero (font_allfamilies
, len
);
2050 strcpy (font_allfamilies
, allfamilies
);
2051 bcopy (p1
, font_allfamilies
+ strlen (allfamilies
), p
- p1
);
2052 strcat (font_allfamilies
, allcs
);
2054 /* Build the font spec that matches all. */
2055 len
= p
- p2
+ strlen (allcs
) + strlen (all
) + strlen (allfamilies
) + 1;
2056 font_all
= (char *) alloca (len
);
2057 bzero (font_all
, len
);
2058 strcpy (font_all
, allfamilies
);
2059 strcat (font_all
, all
);
2060 bcopy (p2
, font_all
+ strlen (all
) + strlen (allfamilies
), p
- p2
);
2061 strcat (font_all
, allcs
);
2063 /* Build the actual font set name. */
2064 len
= strlen (base_fontname
) + strlen (font_allcs
)
2065 + strlen (font_allfamilies
) + strlen (font_all
) + 5;
2066 fontsetname
= xmalloc (len
);
2067 bzero (fontsetname
, len
);
2068 strcpy (fontsetname
, base_fontname
);
2069 strcat (fontsetname
, sep
);
2070 strcat (fontsetname
, font_allcs
);
2071 strcat (fontsetname
, sep
);
2072 strcat (fontsetname
, font_allfamilies
);
2073 strcat (fontsetname
, sep
);
2074 strcat (fontsetname
, font_all
);
2078 strcat (fontsetname
, ":");
2083 xic_create_xfontset (f
, base_fontname
)
2085 char *base_fontname
;
2087 XFontSet xfs
= NULL
;
2088 char **missing_list
= NULL
;
2091 Lisp_Object rest
, frame
;
2094 base_fontname
= xic_defaut_fontset
;
2096 /* See if there is another frame already using same fontset. */
2097 FOR_EACH_FRAME (rest
, frame
)
2099 struct frame
*cf
= XFRAME (frame
);
2100 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
2101 && FRAME_X_DISPLAY_INFO (cf
) == FRAME_X_DISPLAY_INFO (f
)
2102 && FRAME_XIC_BASE_FONTNAME (cf
)
2103 && !strcmp (FRAME_XIC_BASE_FONTNAME (cf
), base_fontname
))
2105 xfs
= FRAME_XIC_FONTSET (cf
);
2112 char *fontsetname
= xic_create_fontsetname (base_fontname
, False
);
2115 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
),
2116 fontsetname
, &missing_list
,
2117 &missing_count
, &def_string
);
2119 XFreeStringList (missing_list
);
2120 xfree (fontsetname
);
2123 if (FRAME_XIC_BASE_FONTNAME (f
))
2124 xfree (FRAME_XIC_BASE_FONTNAME (f
));
2125 FRAME_XIC_BASE_FONTNAME (f
) = xstrdup (base_fontname
);
2127 /* No need to free def_string. */
2131 /* Free the X fontset of frame F if it is the last frame using it. */
2134 xic_free_xfontset (f
)
2137 Lisp_Object rest
, frame
;
2140 if (!FRAME_XIC_FONTSET (f
))
2143 /* See if there is another frame sharing the same fontset. */
2144 FOR_EACH_FRAME (rest
, frame
)
2146 struct frame
*cf
= XFRAME (frame
);
2147 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
2148 && FRAME_X_DISPLAY_INFO (cf
) == FRAME_X_DISPLAY_INFO (f
)
2149 && FRAME_XIC_FONTSET (cf
) == FRAME_XIC_FONTSET (f
))
2157 /* The fontset is not used anymore. It is safe to free it. */
2158 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
2160 if (FRAME_XIC_BASE_FONTNAME (f
))
2161 xfree (FRAME_XIC_BASE_FONTNAME (f
));
2162 FRAME_XIC_BASE_FONTNAME (f
) = NULL
;
2163 FRAME_XIC_FONTSET (f
) = NULL
;
2167 /* Value is the best input style, given user preferences USER (already
2168 checked to be supported by Emacs), and styles supported by the
2169 input method XIM. */
2172 best_xim_style (user
, xim
)
2178 for (i
= 0; i
< user
->count_styles
; ++i
)
2179 for (j
= 0; j
< xim
->count_styles
; ++j
)
2180 if (user
->supported_styles
[i
] == xim
->supported_styles
[j
])
2181 return user
->supported_styles
[i
];
2183 /* Return the default style. */
2184 return XIMPreeditNothing
| XIMStatusNothing
;
2187 /* Create XIC for frame F. */
2189 static XIMStyle xic_style
;
2192 create_frame_xic (f
)
2197 XFontSet xfs
= NULL
;
2202 /* Create X fontset. */
2203 xfs
= xic_create_xfontset
2204 (f
, (FRAME_FONTSET (f
) < 0) ? NULL
2205 : (char *) SDATA (fontset_ascii (FRAME_FONTSET (f
))));
2207 xim
= FRAME_X_XIM (f
);
2212 XVaNestedList preedit_attr
;
2213 XVaNestedList status_attr
;
2215 s_area
.x
= 0; s_area
.y
= 0; s_area
.width
= 1; s_area
.height
= 1;
2216 spot
.x
= 0; spot
.y
= 1;
2218 /* Determine XIC style. */
2221 XIMStyles supported_list
;
2222 supported_list
.count_styles
= (sizeof supported_xim_styles
2223 / sizeof supported_xim_styles
[0]);
2224 supported_list
.supported_styles
= supported_xim_styles
;
2225 xic_style
= best_xim_style (&supported_list
,
2226 FRAME_X_XIM_STYLES (f
));
2229 preedit_attr
= XVaCreateNestedList (0,
2232 FRAME_FOREGROUND_PIXEL (f
),
2234 FRAME_BACKGROUND_PIXEL (f
),
2235 (xic_style
& XIMPreeditPosition
2240 status_attr
= XVaCreateNestedList (0,
2246 FRAME_FOREGROUND_PIXEL (f
),
2248 FRAME_BACKGROUND_PIXEL (f
),
2251 xic
= XCreateIC (xim
,
2252 XNInputStyle
, xic_style
,
2253 XNClientWindow
, FRAME_X_WINDOW (f
),
2254 XNFocusWindow
, FRAME_X_WINDOW (f
),
2255 XNStatusAttributes
, status_attr
,
2256 XNPreeditAttributes
, preedit_attr
,
2258 XFree (preedit_attr
);
2259 XFree (status_attr
);
2262 FRAME_XIC (f
) = xic
;
2263 FRAME_XIC_STYLE (f
) = xic_style
;
2264 FRAME_XIC_FONTSET (f
) = xfs
;
2268 /* Destroy XIC and free XIC fontset of frame F, if any. */
2274 if (FRAME_XIC (f
) == NULL
)
2277 XDestroyIC (FRAME_XIC (f
));
2278 xic_free_xfontset (f
);
2280 FRAME_XIC (f
) = NULL
;
2284 /* Place preedit area for XIC of window W's frame to specified
2285 pixel position X/Y. X and Y are relative to window W. */
2288 xic_set_preeditarea (w
, x
, y
)
2292 struct frame
*f
= XFRAME (w
->frame
);
2296 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
) + WINDOW_LEFT_FRINGE_WIDTH (w
);
2297 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
2298 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
2299 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2304 /* Place status area for XIC in bottom right corner of frame F.. */
2307 xic_set_statusarea (f
)
2310 XIC xic
= FRAME_XIC (f
);
2315 /* Negotiate geometry of status area. If input method has existing
2316 status area, use its current size. */
2317 area
.x
= area
.y
= area
.width
= area
.height
= 0;
2318 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
2319 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2322 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
2323 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2326 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
2328 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
2329 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2333 area
.width
= needed
->width
;
2334 area
.height
= needed
->height
;
2335 area
.x
= FRAME_PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
2336 area
.y
= (FRAME_PIXEL_HEIGHT (f
) - area
.height
2337 - FRAME_MENUBAR_HEIGHT (f
)
2338 - FRAME_TOOLBAR_HEIGHT (f
)
2339 - FRAME_INTERNAL_BORDER_WIDTH (f
));
2342 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
2343 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2348 /* Set X fontset for XIC of frame F, using base font name
2349 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2352 xic_set_xfontset (f
, base_fontname
)
2354 char *base_fontname
;
2359 xic_free_xfontset (f
);
2361 xfs
= xic_create_xfontset (f
, base_fontname
);
2363 attr
= XVaCreateNestedList (0, XNFontSet
, xfs
, NULL
);
2364 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
2365 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2366 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
2367 XSetICValues (FRAME_XIC (f
), XNStatusAttributes
, attr
, NULL
);
2370 FRAME_XIC_FONTSET (f
) = xfs
;
2373 #endif /* HAVE_X_I18N */
2377 #ifdef USE_X_TOOLKIT
2379 /* Create and set up the X widget for frame F. */
2382 x_window (f
, window_prompting
, minibuffer_only
)
2384 long window_prompting
;
2385 int minibuffer_only
;
2387 XClassHint class_hints
;
2388 XSetWindowAttributes attributes
;
2389 unsigned long attribute_mask
;
2390 Widget shell_widget
;
2392 Widget frame_widget
;
2398 /* Use the resource name as the top-level widget name
2399 for looking up resources. Make a non-Lisp copy
2400 for the window manager, so GC relocation won't bother it.
2402 Elsewhere we specify the window name for the window manager. */
2405 char *str
= (char *) SDATA (Vx_resource_name
);
2406 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
2407 strcpy (f
->namebuf
, str
);
2411 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2412 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2413 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2414 XtSetArg (al
[ac
], XtNborderWidth
, f
->border_width
); ac
++;
2415 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2416 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2417 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2418 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2419 applicationShellWidgetClass
,
2420 FRAME_X_DISPLAY (f
), al
, ac
);
2422 f
->output_data
.x
->widget
= shell_widget
;
2423 /* maybe_set_screen_title_format (shell_widget); */
2425 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2426 (widget_value
*) NULL
,
2427 shell_widget
, False
,
2431 (lw_callback
) NULL
);
2434 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2435 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2436 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2437 XtSetValues (pane_widget
, al
, ac
);
2438 f
->output_data
.x
->column_widget
= pane_widget
;
2440 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2441 the emacs screen when changing menubar. This reduces flickering. */
2444 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2445 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2446 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2447 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2448 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2449 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2450 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2451 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2452 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
2455 f
->output_data
.x
->edit_widget
= frame_widget
;
2457 XtManageChild (frame_widget
);
2459 /* Do some needed geometry management. */
2462 char *tem
, shell_position
[32];
2465 int extra_borders
= 0;
2467 = (f
->output_data
.x
->menubar_widget
2468 ? (f
->output_data
.x
->menubar_widget
->core
.height
2469 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
2472 #if 0 /* Experimentally, we now get the right results
2473 for -geometry -0-0 without this. 24 Aug 96, rms. */
2474 if (FRAME_EXTERNAL_MENU_BAR (f
))
2477 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2478 menubar_size
+= ibw
;
2482 f
->output_data
.x
->menubar_height
= menubar_size
;
2485 /* Motif seems to need this amount added to the sizes
2486 specified for the shell widget. The Athena/Lucid widgets don't.
2487 Both conclusions reached experimentally. -- rms. */
2488 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
2489 &extra_borders
, NULL
);
2493 /* Convert our geometry parameters into a geometry string
2495 Note that we do not specify here whether the position
2496 is a user-specified or program-specified one.
2497 We pass that information later, in x_wm_set_size_hints. */
2499 int left
= f
->left_pos
;
2500 int xneg
= window_prompting
& XNegative
;
2501 int top
= f
->top_pos
;
2502 int yneg
= window_prompting
& YNegative
;
2508 if (window_prompting
& USPosition
)
2509 sprintf (shell_position
, "=%dx%d%c%d%c%d",
2510 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2511 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
2512 (xneg
? '-' : '+'), left
,
2513 (yneg
? '-' : '+'), top
);
2516 sprintf (shell_position
, "=%dx%d",
2517 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2518 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
2520 /* Setting x and y when the position is not specified in
2521 the geometry string will set program position in the WM hints.
2522 If Emacs had just one program position, we could set it in
2523 fallback resources, but since each make-frame call can specify
2524 different program positions, this is easier. */
2525 XtSetArg (al
[ac
], XtNx
, left
); ac
++;
2526 XtSetArg (al
[ac
], XtNy
, top
); ac
++;
2530 len
= strlen (shell_position
) + 1;
2531 /* We don't free this because we don't know whether
2532 it is safe to free it while the frame exists.
2533 It isn't worth the trouble of arranging to free it
2534 when the frame is deleted. */
2535 tem
= (char *) xmalloc (len
);
2536 strncpy (tem
, shell_position
, len
);
2537 XtSetArg (al
[ac
], XtNgeometry
, tem
); ac
++;
2538 XtSetValues (shell_widget
, al
, ac
);
2541 XtManageChild (pane_widget
);
2542 XtRealizeWidget (shell_widget
);
2544 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2546 validate_x_resource_name ();
2548 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
2549 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
2550 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2553 FRAME_XIC (f
) = NULL
;
2555 create_frame_xic (f
);
2558 f
->output_data
.x
->wm_hints
.input
= True
;
2559 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2560 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2561 &f
->output_data
.x
->wm_hints
);
2563 hack_wm_protocols (f
, shell_widget
);
2566 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2569 /* Do a stupid property change to force the server to generate a
2570 PropertyNotify event so that the event_stream server timestamp will
2571 be initialized to something relevant to the time we created the window.
2573 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2574 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2575 XA_ATOM
, 32, PropModeAppend
,
2576 (unsigned char*) NULL
, 0);
2578 /* Make all the standard events reach the Emacs frame. */
2579 attributes
.event_mask
= STANDARD_EVENT_SET
;
2584 /* XIM server might require some X events. */
2585 unsigned long fevent
= NoEventMask
;
2586 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2587 attributes
.event_mask
|= fevent
;
2589 #endif /* HAVE_X_I18N */
2591 attribute_mask
= CWEventMask
;
2592 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2593 attribute_mask
, &attributes
);
2595 XtMapWidget (frame_widget
);
2597 /* x_set_name normally ignores requests to set the name if the
2598 requested name is the same as the current name. This is the one
2599 place where that assumption isn't correct; f->name is set, but
2600 the X server hasn't been told. */
2603 int explicit = f
->explicit_name
;
2605 f
->explicit_name
= 0;
2608 x_set_name (f
, name
, explicit);
2611 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2612 f
->output_data
.x
->text_cursor
);
2616 /* This is a no-op, except under Motif. Make sure main areas are
2617 set to something reasonable, in case we get an error later. */
2618 lw_set_main_areas (pane_widget
, 0, frame_widget
);
2621 #else /* not USE_X_TOOLKIT */
2627 if (! xg_create_frame_widgets (f
))
2628 error ("Unable to create window");
2631 FRAME_XIC (f
) = NULL
;
2635 create_frame_xic (f
);
2638 /* XIM server might require some X events. */
2639 unsigned long fevent
= NoEventMask
;
2640 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2642 if (fevent
!= NoEventMask
)
2644 XSetWindowAttributes attributes
;
2645 XWindowAttributes wattr
;
2646 unsigned long attribute_mask
;
2648 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2650 attributes
.event_mask
= wattr
.your_event_mask
| fevent
;
2651 attribute_mask
= CWEventMask
;
2652 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2653 attribute_mask
, &attributes
);
2661 #else /*! USE_GTK */
2662 /* Create and set up the X window for frame F. */
2669 XClassHint class_hints
;
2670 XSetWindowAttributes attributes
;
2671 unsigned long attribute_mask
;
2673 attributes
.background_pixel
= f
->output_data
.x
->background_pixel
;
2674 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
2675 attributes
.bit_gravity
= StaticGravity
;
2676 attributes
.backing_store
= NotUseful
;
2677 attributes
.save_under
= True
;
2678 attributes
.event_mask
= STANDARD_EVENT_SET
;
2679 attributes
.colormap
= FRAME_X_COLORMAP (f
);
2680 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
2685 = XCreateWindow (FRAME_X_DISPLAY (f
),
2686 f
->output_data
.x
->parent_desc
,
2689 FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
),
2691 CopyFromParent
, /* depth */
2692 InputOutput
, /* class */
2694 attribute_mask
, &attributes
);
2699 create_frame_xic (f
);
2702 /* XIM server might require some X events. */
2703 unsigned long fevent
= NoEventMask
;
2704 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2705 attributes
.event_mask
|= fevent
;
2706 attribute_mask
= CWEventMask
;
2707 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2708 attribute_mask
, &attributes
);
2711 #endif /* HAVE_X_I18N */
2713 validate_x_resource_name ();
2715 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
2716 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
2717 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2719 /* The menubar is part of the ordinary display;
2720 it does not count in addition to the height of the window. */
2721 f
->output_data
.x
->menubar_height
= 0;
2723 /* This indicates that we use the "Passive Input" input model.
2724 Unless we do this, we don't get the Focus{In,Out} events that we
2725 need to draw the cursor correctly. Accursed bureaucrats.
2726 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2728 f
->output_data
.x
->wm_hints
.input
= True
;
2729 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2730 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2731 &f
->output_data
.x
->wm_hints
);
2732 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
2734 /* Request "save yourself" and "delete window" commands from wm. */
2737 protocols
[0] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2738 protocols
[1] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2739 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2742 /* x_set_name normally ignores requests to set the name if the
2743 requested name is the same as the current name. This is the one
2744 place where that assumption isn't correct; f->name is set, but
2745 the X server hasn't been told. */
2748 int explicit = f
->explicit_name
;
2750 f
->explicit_name
= 0;
2753 x_set_name (f
, name
, explicit);
2756 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2757 f
->output_data
.x
->text_cursor
);
2761 if (FRAME_X_WINDOW (f
) == 0)
2762 error ("Unable to create window");
2765 #endif /* not USE_GTK */
2766 #endif /* not USE_X_TOOLKIT */
2768 /* Verify that the icon position args for this window are valid. */
2771 x_icon_verify (f
, parms
)
2775 Lisp_Object icon_x
, icon_y
;
2777 /* Set the position of the icon. Note that twm groups all
2778 icons in an icon window. */
2779 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2780 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2781 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2783 CHECK_NUMBER (icon_x
);
2784 CHECK_NUMBER (icon_y
);
2786 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2787 error ("Both left and top icon corners of icon must be specified");
2790 /* Handle the icon stuff for this window. Perhaps later we might
2791 want an x_set_icon_position which can be called interactively as
2799 Lisp_Object icon_x
, icon_y
;
2800 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2802 /* Set the position of the icon. Note that twm groups all
2803 icons in an icon window. */
2804 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2805 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2806 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2808 CHECK_NUMBER (icon_x
);
2809 CHECK_NUMBER (icon_y
);
2811 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2812 error ("Both left and top icon corners of icon must be specified");
2816 if (! EQ (icon_x
, Qunbound
))
2817 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2819 /* Start up iconic or window? */
2820 x_wm_set_window_state
2821 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
2826 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
2833 /* Make the GCs needed for this window, setting the
2834 background, border and mouse colors; also create the
2835 mouse cursor and the gray border tile. */
2837 static char cursor_bits
[] =
2839 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2840 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2841 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2842 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2849 XGCValues gc_values
;
2853 /* Create the GCs of this frame.
2854 Note that many default values are used. */
2857 gc_values
.font
= FRAME_FONT (f
)->fid
;
2858 gc_values
.foreground
= f
->output_data
.x
->foreground_pixel
;
2859 gc_values
.background
= f
->output_data
.x
->background_pixel
;
2860 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2861 f
->output_data
.x
->normal_gc
2862 = XCreateGC (FRAME_X_DISPLAY (f
),
2864 GCLineWidth
| GCFont
| GCForeground
| GCBackground
,
2867 /* Reverse video style. */
2868 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
2869 gc_values
.background
= f
->output_data
.x
->foreground_pixel
;
2870 f
->output_data
.x
->reverse_gc
2871 = XCreateGC (FRAME_X_DISPLAY (f
),
2873 GCFont
| GCForeground
| GCBackground
| GCLineWidth
,
2876 /* Cursor has cursor-color background, background-color foreground. */
2877 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
2878 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
2879 gc_values
.fill_style
= FillOpaqueStippled
;
2881 = XCreateBitmapFromData (FRAME_X_DISPLAY (f
),
2882 FRAME_X_DISPLAY_INFO (f
)->root_window
,
2883 cursor_bits
, 16, 16);
2884 f
->output_data
.x
->cursor_gc
2885 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2886 (GCFont
| GCForeground
| GCBackground
2887 | GCFillStyle
/* | GCStipple */ | GCLineWidth
),
2891 f
->output_data
.x
->white_relief
.gc
= 0;
2892 f
->output_data
.x
->black_relief
.gc
= 0;
2894 /* Create the gray border tile used when the pointer is not in
2895 the frame. Since this depends on the frame's pixel values,
2896 this must be done on a per-frame basis. */
2897 f
->output_data
.x
->border_tile
2898 = (XCreatePixmapFromBitmapData
2899 (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
2900 gray_bits
, gray_width
, gray_height
,
2901 f
->output_data
.x
->foreground_pixel
,
2902 f
->output_data
.x
->background_pixel
,
2903 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
2909 /* Free what was was allocated in x_make_gc. */
2915 Display
*dpy
= FRAME_X_DISPLAY (f
);
2919 if (f
->output_data
.x
->normal_gc
)
2921 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
2922 f
->output_data
.x
->normal_gc
= 0;
2925 if (f
->output_data
.x
->reverse_gc
)
2927 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
2928 f
->output_data
.x
->reverse_gc
= 0;
2931 if (f
->output_data
.x
->cursor_gc
)
2933 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
2934 f
->output_data
.x
->cursor_gc
= 0;
2937 if (f
->output_data
.x
->border_tile
)
2939 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
2940 f
->output_data
.x
->border_tile
= 0;
2947 /* Handler for signals raised during x_create_frame and
2948 x_create_top_frame. FRAME is the frame which is partially
2952 unwind_create_frame (frame
)
2955 struct frame
*f
= XFRAME (frame
);
2957 /* If frame is ``official'', nothing to do. */
2958 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
2961 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2964 x_free_frame_resources (f
);
2967 /* Check that reference counts are indeed correct. */
2968 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
2969 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
2978 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
2980 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
2981 Returns an Emacs frame object.
2982 ALIST is an alist of frame parameters.
2983 If the parameters specify that the frame should not have a minibuffer,
2984 and do not specify a specific minibuffer window to use,
2985 then `default-minibuffer-frame' must be a frame whose minibuffer can
2986 be shared by the new frame.
2988 This function is an internal primitive--use `make-frame' instead. */)
2993 Lisp_Object frame
, tem
;
2995 int minibuffer_only
= 0;
2996 long window_prompting
= 0;
2998 int count
= SPECPDL_INDEX ();
2999 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
3000 Lisp_Object display
;
3001 struct x_display_info
*dpyinfo
= NULL
;
3007 /* Use this general default value to start with
3008 until we know if this frame has a specified name. */
3009 Vx_resource_name
= Vinvocation_name
;
3011 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
3012 if (EQ (display
, Qunbound
))
3014 dpyinfo
= check_x_display_info (display
);
3016 kb
= dpyinfo
->kboard
;
3018 kb
= &the_only_kboard
;
3021 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
3023 && ! EQ (name
, Qunbound
)
3025 error ("Invalid frame name--not a string or nil");
3028 Vx_resource_name
= name
;
3030 /* See if parent window is specified. */
3031 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
3032 if (EQ (parent
, Qunbound
))
3034 if (! NILP (parent
))
3035 CHECK_NUMBER (parent
);
3037 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
3038 /* No need to protect DISPLAY because that's not used after passing
3039 it to make_frame_without_minibuffer. */
3041 GCPRO4 (parms
, parent
, name
, frame
);
3042 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
3044 if (EQ (tem
, Qnone
) || NILP (tem
))
3045 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
3046 else if (EQ (tem
, Qonly
))
3048 f
= make_minibuffer_frame ();
3049 minibuffer_only
= 1;
3051 else if (WINDOWP (tem
))
3052 f
= make_frame_without_minibuffer (tem
, kb
, display
);
3056 XSETFRAME (frame
, f
);
3058 /* Note that X Windows does support scroll bars. */
3059 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
3061 f
->output_method
= output_x_window
;
3062 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
3063 bzero (f
->output_data
.x
, sizeof (struct x_output
));
3064 f
->output_data
.x
->icon_bitmap
= -1;
3065 FRAME_FONTSET (f
) = -1;
3066 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
3067 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
3068 #ifdef USE_TOOLKIT_SCROLL_BARS
3069 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
3070 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
3071 #endif /* USE_TOOLKIT_SCROLL_BARS */
3072 record_unwind_protect (unwind_create_frame
, frame
);
3075 = x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
3077 if (! STRINGP (f
->icon_name
))
3078 f
->icon_name
= Qnil
;
3080 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
3082 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
3083 dpyinfo_refcount
= dpyinfo
->reference_count
;
3084 #endif /* GLYPH_DEBUG */
3086 FRAME_KBOARD (f
) = kb
;
3089 /* These colors will be set anyway later, but it's important
3090 to get the color reference counts right, so initialize them! */
3093 struct gcpro gcpro1
;
3095 /* Function x_decode_color can signal an error. Make
3096 sure to initialize color slots so that we won't try
3097 to free colors we haven't allocated. */
3098 f
->output_data
.x
->foreground_pixel
= -1;
3099 f
->output_data
.x
->background_pixel
= -1;
3100 f
->output_data
.x
->cursor_pixel
= -1;
3101 f
->output_data
.x
->cursor_foreground_pixel
= -1;
3102 f
->output_data
.x
->border_pixel
= -1;
3103 f
->output_data
.x
->mouse_pixel
= -1;
3105 black
= build_string ("black");
3107 f
->output_data
.x
->foreground_pixel
3108 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3109 f
->output_data
.x
->background_pixel
3110 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3111 f
->output_data
.x
->cursor_pixel
3112 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3113 f
->output_data
.x
->cursor_foreground_pixel
3114 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3115 f
->output_data
.x
->border_pixel
3116 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3117 f
->output_data
.x
->mouse_pixel
3118 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3122 /* Specify the parent under which to make this X window. */
3126 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
3127 f
->output_data
.x
->explicit_parent
= 1;
3131 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3132 f
->output_data
.x
->explicit_parent
= 0;
3135 /* Set the name; the functions to which we pass f expect the name to
3137 if (EQ (name
, Qunbound
) || NILP (name
))
3139 f
->name
= build_string (dpyinfo
->x_id_name
);
3140 f
->explicit_name
= 0;
3145 f
->explicit_name
= 1;
3146 /* use the frame's title when getting resources for this frame. */
3147 specbind (Qx_resource_name
, name
);
3150 /* Extract the window parameters from the supplied values
3151 that are needed to determine window geometry. */
3155 font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
3158 /* First, try whatever font the caller has specified. */
3161 tem
= Fquery_fontset (font
, Qnil
);
3163 font
= x_new_fontset (f
, SDATA (tem
));
3165 font
= x_new_font (f
, SDATA (font
));
3168 /* Try out a font which we hope has bold and italic variations. */
3169 if (!STRINGP (font
))
3170 font
= x_new_font (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
3171 if (!STRINGP (font
))
3172 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3173 if (! STRINGP (font
))
3174 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3175 if (! STRINGP (font
))
3176 /* This was formerly the first thing tried, but it finds too many fonts
3177 and takes too long. */
3178 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
3179 /* If those didn't work, look for something which will at least work. */
3180 if (! STRINGP (font
))
3181 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
3183 if (! STRINGP (font
))
3184 font
= build_string ("fixed");
3186 x_default_parameter (f
, parms
, Qfont
, font
,
3187 "font", "Font", RES_TYPE_STRING
);
3191 /* Prevent lwlib/xlwmenu.c from crashing because of a bug
3192 whereby it fails to get any font. */
3193 xlwmenu_default_font
= FRAME_FONT (f
);
3196 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
3197 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
3199 /* This defaults to 1 in order to match xterm. We recognize either
3200 internalBorderWidth or internalBorder (which is what xterm calls
3202 if (NILP (Fassq (Qinternal_border_width
, parms
)))
3206 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
3207 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
3208 if (! EQ (value
, Qunbound
))
3209 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
3212 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
3213 "internalBorderWidth", "internalBorderWidth",
3215 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qleft
,
3216 "verticalScrollBars", "ScrollBars",
3219 /* Also do the stuff which must be set before the window exists. */
3220 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3221 "foreground", "Foreground", RES_TYPE_STRING
);
3222 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3223 "background", "Background", RES_TYPE_STRING
);
3224 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3225 "pointerColor", "Foreground", RES_TYPE_STRING
);
3226 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
3227 "cursorColor", "Foreground", RES_TYPE_STRING
);
3228 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3229 "borderColor", "BorderColor", RES_TYPE_STRING
);
3230 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3231 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3232 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3233 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3234 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3235 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3236 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3237 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3239 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3240 "scrollBarForeground",
3241 "ScrollBarForeground", 1);
3242 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3243 "scrollBarBackground",
3244 "ScrollBarBackground", 0);
3246 /* Init faces before x_default_parameter is called for scroll-bar
3247 parameters because that function calls x_set_scroll_bar_width,
3248 which calls change_frame_size, which calls Fset_window_buffer,
3249 which runs hooks, which call Fvertical_motion. At the end, we
3250 end up in init_iterator with a null face cache, which should not
3252 init_frame_faces (f
);
3254 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
3255 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
3256 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (1),
3257 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
3258 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3259 "bufferPredicate", "BufferPredicate",
3261 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3262 "title", "Title", RES_TYPE_STRING
);
3263 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3264 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3265 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3266 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3268 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3270 /* Compute the size of the X window. */
3271 window_prompting
= x_figure_window_size (f
, parms
, 1);
3273 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3274 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3276 x_icon_verify (f
, parms
);
3278 /* Create the X widget or window. */
3279 #ifdef USE_X_TOOLKIT
3280 x_window (f
, window_prompting
, minibuffer_only
);
3288 /* Now consider the frame official. */
3289 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
3290 Vframe_list
= Fcons (frame
, Vframe_list
);
3292 /* We need to do this after creating the X window, so that the
3293 icon-creation functions can say whose icon they're describing. */
3294 x_default_parameter (f
, parms
, Qicon_type
, Qt
,
3295 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
3297 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3298 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3299 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3300 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3301 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3302 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3303 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3304 "scrollBarWidth", "ScrollBarWidth",
3307 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
3308 Change will not be effected unless different from the current
3310 width
= FRAME_COLS (f
);
3311 height
= FRAME_LINES (f
);
3313 SET_FRAME_COLS (f
, 0);
3314 FRAME_LINES (f
) = 0;
3315 change_frame_size (f
, height
, width
, 1, 0, 0);
3317 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3318 /* Create the menu bar. */
3319 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3321 /* If this signals an error, we haven't set size hints for the
3322 frame and we didn't make it visible. */
3323 initialize_frame_menubar (f
);
3326 /* This is a no-op, except under Motif where it arranges the
3327 main window for the widgets on it. */
3328 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3329 f
->output_data
.x
->menubar_widget
,
3330 f
->output_data
.x
->edit_widget
);
3331 #endif /* not USE_GTK */
3333 #endif /* USE_X_TOOLKIT || USE_GTK */
3335 /* Tell the server what size and position, etc, we want, and how
3336 badly we want them. This should be done after we have the menu
3337 bar so that its size can be taken into account. */
3339 x_wm_set_size_hint (f
, window_prompting
, 0);
3342 /* Make the window appear on the frame and enable display, unless
3343 the caller says not to. However, with explicit parent, Emacs
3344 cannot control visibility, so don't try. */
3345 if (! f
->output_data
.x
->explicit_parent
)
3347 Lisp_Object visibility
;
3349 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3351 if (EQ (visibility
, Qunbound
))
3354 if (EQ (visibility
, Qicon
))
3355 x_iconify_frame (f
);
3356 else if (! NILP (visibility
))
3357 x_make_frame_visible (f
);
3359 /* Must have been Qnil. */
3363 /* Set the WM leader property. GTK does this itself, so this is not
3364 needed when using GTK. */
3365 if (dpyinfo
->client_leader_window
!= 0)
3368 XChangeProperty (FRAME_X_DISPLAY (f
),
3369 FRAME_OUTER_WINDOW (f
),
3370 dpyinfo
->Xatom_wm_client_leader
,
3371 XA_WINDOW
, 32, PropModeReplace
,
3372 (unsigned char *) &dpyinfo
->client_leader_window
, 1);
3376 /* Initialize `default-minibuffer-frame' in case this is the first
3377 frame on this display device. */
3378 if (FRAME_HAS_MINIBUF_P (f
)
3379 && (!FRAMEP (kb
->Vdefault_minibuffer_frame
)
3380 || !FRAME_LIVE_P (XFRAME (kb
->Vdefault_minibuffer_frame
))))
3381 kb
->Vdefault_minibuffer_frame
= frame
;
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
) <= 0)
4944 *root_y
= 0; /* Can happen for negative dy */
4945 else if (*root_y
+ XINT (dy
) + height
<= FRAME_X_DISPLAY_INFO (f
)->height
)
4946 /* It fits below the pointer */
4947 *root_y
+= XINT (dy
);
4948 else if (height
+ XINT (dy
) <= *root_y
)
4949 /* It fits above the pointer. */
4950 *root_y
-= height
+ XINT (dy
);
4952 /* Put it on the top. */
4955 if (INTEGERP (left
))
4956 *root_x
= XINT (left
);
4957 else if (*root_x
+ XINT (dx
) <= 0)
4958 *root_x
= 0; /* Can happen for negative dx */
4959 else if (*root_x
+ XINT (dx
) + width
<= FRAME_X_DISPLAY_INFO (f
)->width
)
4960 /* It fits to the right of the pointer. */
4961 *root_x
+= XINT (dx
);
4962 else if (width
+ XINT (dx
) <= *root_x
)
4963 /* It fits to the left of the pointer. */
4964 *root_x
-= width
+ XINT (dx
);
4966 /* Put it left-justified on the screen--it ought to fit that way. */
4971 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
4972 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
4973 A tooltip window is a small X window displaying a string.
4975 FRAME nil or omitted means use the selected frame.
4977 PARMS is an optional list of frame parameters which can be used to
4978 change the tooltip's appearance.
4980 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
4981 means use the default timeout of 5 seconds.
4983 If the list of frame parameters PARAMS contains a `left' parameters,
4984 the tooltip is displayed at that x-position. Otherwise it is
4985 displayed at the mouse position, with offset DX added (default is 5 if
4986 DX isn't specified). Likewise for the y-position; if a `top' frame
4987 parameter is specified, it determines the y-position of the tooltip
4988 window, otherwise it is displayed at the mouse position, with offset
4989 DY added (default is -10).
4991 A tooltip's maximum size is specified by `x-max-tooltip-size'.
4992 Text larger than the specified size is clipped. */)
4993 (string
, frame
, parms
, timeout
, dx
, dy
)
4994 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
4999 struct buffer
*old_buffer
;
5000 struct text_pos pos
;
5001 int i
, width
, height
;
5002 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5003 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5004 int count
= SPECPDL_INDEX ();
5006 specbind (Qinhibit_redisplay
, Qt
);
5008 GCPRO4 (string
, parms
, frame
, timeout
);
5010 CHECK_STRING (string
);
5011 f
= check_x_frame (frame
);
5013 timeout
= make_number (5);
5015 CHECK_NATNUM (timeout
);
5018 dx
= make_number (5);
5023 dy
= make_number (-10);
5027 if (NILP (last_show_tip_args
))
5028 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5030 if (!NILP (tip_frame
))
5032 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5033 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5034 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5036 if (EQ (frame
, last_frame
)
5037 && !NILP (Fequal (last_string
, string
))
5038 && !NILP (Fequal (last_parms
, parms
)))
5040 struct frame
*f
= XFRAME (tip_frame
);
5042 /* Only DX and DY have changed. */
5043 if (!NILP (tip_timer
))
5045 Lisp_Object timer
= tip_timer
;
5047 call1 (Qcancel_timer
, timer
);
5051 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
5052 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
5053 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5060 /* Hide a previous tip, if any. */
5063 ASET (last_show_tip_args
, 0, string
);
5064 ASET (last_show_tip_args
, 1, frame
);
5065 ASET (last_show_tip_args
, 2, parms
);
5067 /* Add default values to frame parameters. */
5068 if (NILP (Fassq (Qname
, parms
)))
5069 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5070 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5071 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5072 if (NILP (Fassq (Qborder_width
, parms
)))
5073 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5074 if (NILP (Fassq (Qborder_color
, parms
)))
5075 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5076 if (NILP (Fassq (Qbackground_color
, parms
)))
5077 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5080 /* Create a frame for the tooltip, and record it in the global
5081 variable tip_frame. */
5082 frame
= x_create_tip_frame (FRAME_X_DISPLAY_INFO (f
), parms
, string
);
5085 /* Set up the frame's root window. */
5086 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5087 w
->left_col
= w
->top_line
= make_number (0);
5089 if (CONSP (Vx_max_tooltip_size
)
5090 && INTEGERP (XCAR (Vx_max_tooltip_size
))
5091 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
5092 && INTEGERP (XCDR (Vx_max_tooltip_size
))
5093 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
5095 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
5096 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
5100 w
->total_cols
= make_number (80);
5101 w
->total_lines
= make_number (40);
5104 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
5106 w
->pseudo_window_p
= 1;
5108 /* Display the tooltip text in a temporary buffer. */
5109 old_buffer
= current_buffer
;
5110 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
5111 current_buffer
->truncate_lines
= Qnil
;
5112 clear_glyph_matrix (w
->desired_matrix
);
5113 clear_glyph_matrix (w
->current_matrix
);
5114 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5115 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
5117 /* Compute width and height of the tooltip. */
5119 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5121 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5125 /* Stop at the first empty row at the end. */
5126 if (!row
->enabled_p
|| !row
->displays_text_p
)
5129 /* Let the row go over the full width of the frame. */
5130 row
->full_width_p
= 1;
5132 /* There's a glyph at the end of rows that is used to place
5133 the cursor there. Don't include the width of this glyph. */
5134 if (row
->used
[TEXT_AREA
])
5136 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5137 row_width
= row
->pixel_width
- last
->pixel_width
;
5140 row_width
= row
->pixel_width
;
5142 height
+= row
->height
;
5143 width
= max (width
, row_width
);
5146 /* Add the frame's internal border to the width and height the X
5147 window should have. */
5148 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5149 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5151 /* Move the tooltip window where the mouse pointer is. Resize and
5153 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5156 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5157 root_x
, root_y
, width
, height
);
5158 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5161 /* Draw into the window. */
5162 w
->must_be_updated_p
= 1;
5163 update_single_window (w
, 1);
5165 /* Restore original current buffer. */
5166 set_buffer_internal_1 (old_buffer
);
5167 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5170 /* Let the tip disappear after timeout seconds. */
5171 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5172 intern ("x-hide-tip"));
5175 return unbind_to (count
, Qnil
);
5179 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5180 doc
: /* Hide the current tooltip window, if there is any.
5181 Value is t if tooltip was open, nil otherwise. */)
5185 Lisp_Object deleted
, frame
, timer
;
5186 struct gcpro gcpro1
, gcpro2
;
5188 /* Return quickly if nothing to do. */
5189 if (NILP (tip_timer
) && NILP (tip_frame
))
5194 GCPRO2 (frame
, timer
);
5195 tip_frame
= tip_timer
= deleted
= Qnil
;
5197 count
= SPECPDL_INDEX ();
5198 specbind (Qinhibit_redisplay
, Qt
);
5199 specbind (Qinhibit_quit
, Qt
);
5202 call1 (Qcancel_timer
, timer
);
5206 Fdelete_frame (frame
, Qnil
);
5210 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5211 redisplay procedure is not called when a tip frame over menu
5212 items is unmapped. Redisplay the menu manually... */
5214 struct frame
*f
= SELECTED_FRAME ();
5215 Widget w
= f
->output_data
.x
->menubar_widget
;
5216 extern void xlwmenu_redisplay
P_ ((Widget
));
5218 if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f
)->screen
)
5222 xlwmenu_redisplay (w
);
5226 #endif /* USE_LUCID */
5230 return unbind_to (count
, deleted
);
5235 /***********************************************************************
5236 File selection dialog
5237 ***********************************************************************/
5241 /* Callback for "OK" and "Cancel" on file selection dialog. */
5244 file_dialog_cb (widget
, client_data
, call_data
)
5246 XtPointer call_data
, client_data
;
5248 int *result
= (int *) client_data
;
5249 XmAnyCallbackStruct
*cb
= (XmAnyCallbackStruct
*) call_data
;
5250 *result
= cb
->reason
;
5254 /* Callback for unmapping a file selection dialog. This is used to
5255 capture the case where a dialog is closed via a window manager's
5256 closer button, for example. Using a XmNdestroyCallback didn't work
5260 file_dialog_unmap_cb (widget
, client_data
, call_data
)
5262 XtPointer call_data
, client_data
;
5264 int *result
= (int *) client_data
;
5265 *result
= XmCR_CANCEL
;
5269 clean_up_file_dialog (arg
)
5272 struct Lisp_Save_Value
*p
= XSAVE_VALUE (arg
);
5273 Widget dialog
= (Widget
) p
->pointer
;
5277 XtUnmanageChild (dialog
);
5278 XtDestroyWidget (dialog
);
5279 x_menu_set_in_use (0);
5286 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5287 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5288 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5289 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5290 or directory must exist. ONLY-DIR-P is ignored." */)
5291 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
5292 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
5295 struct frame
*f
= SELECTED_FRAME ();
5296 Lisp_Object file
= Qnil
;
5297 Widget dialog
, text
, help
;
5300 extern XtAppContext Xt_app_con
;
5301 XmString dir_xmstring
, pattern_xmstring
;
5302 int count
= SPECPDL_INDEX ();
5303 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5305 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5307 if (popup_activated ())
5308 error ("Trying to use a menu from within a menu-entry");
5310 CHECK_STRING (prompt
);
5313 /* Prevent redisplay. */
5314 specbind (Qinhibit_redisplay
, Qt
);
5318 /* Create the dialog with PROMPT as title, using DIR as initial
5319 directory and using "*" as pattern. */
5320 dir
= Fexpand_file_name (dir
, Qnil
);
5321 dir_xmstring
= XmStringCreateLocalized (SDATA (dir
));
5322 pattern_xmstring
= XmStringCreateLocalized ("*");
5324 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
5325 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
5326 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
5327 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
5328 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
5329 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
5331 XmStringFree (dir_xmstring
);
5332 XmStringFree (pattern_xmstring
);
5334 /* Add callbacks for OK and Cancel. */
5335 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
5336 (XtPointer
) &result
);
5337 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
5338 (XtPointer
) &result
);
5339 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
5340 (XtPointer
) &result
);
5342 /* Remove the help button since we can't display help. */
5343 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
5344 XtUnmanageChild (help
);
5346 /* Mark OK button as default. */
5347 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
5348 XmNshowAsDefault
, True
, NULL
);
5350 /* If MUSTMATCH is non-nil, disable the file entry field of the
5351 dialog, so that the user must select a file from the files list
5352 box. We can't remove it because we wouldn't have a way to get at
5353 the result file name, then. */
5354 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5355 if (!NILP (mustmatch
))
5358 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
5359 XtSetSensitive (text
, False
);
5360 XtSetSensitive (label
, False
);
5363 /* Manage the dialog, so that list boxes get filled. */
5364 XtManageChild (dialog
);
5366 if (STRINGP (default_filename
))
5368 XmString default_xmstring
;
5369 Widget wtext
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5370 Widget list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
5372 XmTextPosition last_pos
= XmTextFieldGetLastPosition (wtext
);
5373 XmTextFieldReplace (wtext
, 0, last_pos
,
5374 (SDATA (Ffile_name_nondirectory (default_filename
))));
5376 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5377 must include the path for this to work. */
5379 default_xmstring
= XmStringCreateLocalized (SDATA (default_filename
));
5381 if (XmListItemExists (list
, default_xmstring
))
5383 int item_pos
= XmListItemPos (list
, default_xmstring
);
5384 /* Select the item and scroll it into view. */
5385 XmListSelectPos (list
, item_pos
, True
);
5386 XmListSetPos (list
, item_pos
);
5389 XmStringFree (default_xmstring
);
5392 record_unwind_protect (clean_up_file_dialog
, make_save_value (dialog
, 0));
5394 /* Process events until the user presses Cancel or OK. */
5395 x_menu_set_in_use (1);
5400 x_menu_wait_for_event (0);
5401 XtAppNextEvent (Xt_app_con
, &event
);
5402 if (event
.type
== KeyPress
5403 && FRAME_X_DISPLAY (f
) == event
.xkey
.display
)
5405 KeySym keysym
= XLookupKeysym (&event
.xkey
, 0);
5407 /* Pop down on C-g. */
5408 if (keysym
== XK_g
&& (event
.xkey
.state
& ControlMask
) != 0)
5409 XtUnmanageChild (dialog
);
5412 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
));
5415 /* Get the result. */
5416 if (result
== XmCR_OK
)
5421 XtVaGetValues (dialog
, XmNtextString
, &text
, NULL
);
5422 XmStringGetLtoR (text
, XmFONTLIST_DEFAULT_TAG
, &data
);
5423 XmStringFree (text
);
5424 file
= build_string (data
);
5433 /* Make "Cancel" equivalent to C-g. */
5435 Fsignal (Qquit
, Qnil
);
5437 return unbind_to (count
, file
);
5440 #endif /* USE_MOTIF */
5445 clean_up_dialog (arg
)
5448 x_menu_set_in_use (0);
5453 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5454 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5455 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5456 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5457 or directory must exist. If ONLY-DIR-P is non-nil, the user can only select
5459 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
5460 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
5462 FRAME_PTR f
= SELECTED_FRAME ();
5464 Lisp_Object file
= Qnil
;
5465 int count
= SPECPDL_INDEX ();
5466 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5469 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5471 if (popup_activated ())
5472 error ("Trying to use a menu from within a menu-entry");
5474 CHECK_STRING (prompt
);
5477 /* Prevent redisplay. */
5478 specbind (Qinhibit_redisplay
, Qt
);
5479 record_unwind_protect (clean_up_dialog
, Qnil
);
5483 if (STRINGP (default_filename
))
5484 cdef_file
= SDATA (default_filename
);
5486 cdef_file
= SDATA (dir
);
5488 fn
= xg_get_file_name (f
, SDATA (prompt
), cdef_file
,
5490 ! NILP (only_dir_p
));
5494 file
= build_string (fn
);
5501 /* Make "Cancel" equivalent to C-g. */
5503 Fsignal (Qquit
, Qnil
);
5505 return unbind_to (count
, file
);
5508 #endif /* USE_GTK */
5511 /***********************************************************************
5513 ***********************************************************************/
5515 #ifdef HAVE_XKBGETKEYBOARD
5516 #include <X11/XKBlib.h>
5517 #include <X11/keysym.h>
5520 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
5521 Sx_backspace_delete_keys_p
, 0, 1, 0,
5522 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
5523 FRAME nil means use the selected frame.
5524 Value is t if we know that both keys are present, and are mapped to the
5525 usual X keysyms. Value is `lambda' if we cannot determine if both keys are
5526 present and mapped to the usual X keysyms. */)
5530 #ifdef HAVE_XKBGETKEYBOARD
5532 struct frame
*f
= check_x_frame (frame
);
5533 Display
*dpy
= FRAME_X_DISPLAY (f
);
5534 Lisp_Object have_keys
;
5535 int major
, minor
, op
, event
, error
;
5539 /* Check library version in case we're dynamically linked. */
5540 major
= XkbMajorVersion
;
5541 minor
= XkbMinorVersion
;
5542 if (!XkbLibraryVersion (&major
, &minor
))
5548 /* Check that the server supports XKB. */
5549 major
= XkbMajorVersion
;
5550 minor
= XkbMinorVersion
;
5551 if (!XkbQueryExtension (dpy
, &op
, &event
, &error
, &major
, &minor
))
5557 /* In this code we check that the keyboard has physical keys with names
5558 that start with BKSP (Backspace) and DELE (Delete), and that they
5559 generate keysym XK_BackSpace and XK_Delete respectively.
5560 This function is used to test if normal-erase-is-backspace should be
5562 An alternative approach would be to just check if XK_BackSpace and
5563 XK_Delete are mapped to any key. But if any of those are mapped to
5564 some non-intuitive key combination (Meta-Shift-Ctrl-whatever) and the
5565 user doesn't know about it, it is better to return false here.
5566 It is more obvious to the user what to do if she/he has two keys
5567 clearly marked with names/symbols and one key does something not
5568 expected (i.e. she/he then tries the other).
5569 The cases where Backspace/Delete is mapped to some other key combination
5570 are rare, and in those cases, normal-erase-is-backspace can be turned on
5574 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
5577 int delete_keycode
= 0, backspace_keycode
= 0, i
;
5579 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
5581 for (i
= kb
->min_key_code
;
5582 (i
< kb
->max_key_code
5583 && (delete_keycode
== 0 || backspace_keycode
== 0));
5586 /* The XKB symbolic key names can be seen most easily in
5587 the PS file generated by `xkbprint -label name
5589 if (bcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
5591 else if (bcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
5592 backspace_keycode
= i
;
5595 XkbFreeNames (kb
, 0, True
);
5598 XkbFreeClientMap (kb
, 0, True
);
5601 && backspace_keycode
5602 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
5603 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
5608 #else /* not HAVE_XKBGETKEYBOARD */
5610 #endif /* not HAVE_XKBGETKEYBOARD */
5615 /***********************************************************************
5617 ***********************************************************************/
5619 /* Keep this list in the same order as frame_parms in frame.c.
5620 Use 0 for unsupported frame parameters. */
5622 frame_parm_handler x_frame_parm_handlers
[] =
5626 x_set_background_color
,
5632 x_set_foreground_color
,
5635 x_set_internal_border_width
,
5636 x_set_menu_bar_lines
,
5638 x_explicitly_set_name
,
5639 x_set_scroll_bar_width
,
5642 x_set_vertical_scroll_bars
,
5644 x_set_tool_bar_lines
,
5645 x_set_scroll_bar_foreground
,
5646 x_set_scroll_bar_background
,
5658 /* This is zero if not using X windows. */
5661 /* The section below is built by the lisp expression at the top of the file,
5662 just above where these variables are declared. */
5663 /*&&& init symbols here &&&*/
5664 Qnone
= intern ("none");
5666 Qsuppress_icon
= intern ("suppress-icon");
5667 staticpro (&Qsuppress_icon
);
5668 Qundefined_color
= intern ("undefined-color");
5669 staticpro (&Qundefined_color
);
5670 Qcompound_text
= intern ("compound-text");
5671 staticpro (&Qcompound_text
);
5672 Qcancel_timer
= intern ("cancel-timer");
5673 staticpro (&Qcancel_timer
);
5674 /* This is the end of symbol initialization. */
5676 /* Text property `display' should be nonsticky by default. */
5677 Vtext_property_default_nonsticky
5678 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
5681 Fput (Qundefined_color
, Qerror_conditions
,
5682 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
5683 Fput (Qundefined_color
, Qerror_message
,
5684 build_string ("Undefined color"));
5686 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
5687 doc
: /* The shape of the pointer when over text.
5688 Changing the value does not affect existing frames
5689 unless you set the mouse color. */);
5690 Vx_pointer_shape
= Qnil
;
5692 #if 0 /* This doesn't really do anything. */
5693 DEFVAR_LISP ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape
,
5694 doc
: /* The shape of the pointer when not over text.
5695 This variable takes effect when you create a new frame
5696 or when you set the mouse color. */);
5698 Vx_nontext_pointer_shape
= Qnil
;
5700 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
5701 doc
: /* The shape of the pointer when Emacs is busy.
5702 This variable takes effect when you create a new frame
5703 or when you set the mouse color. */);
5704 Vx_hourglass_pointer_shape
= Qnil
;
5706 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
5707 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
5708 display_hourglass_p
= 1;
5710 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
5711 doc
: /* *Seconds to wait before displaying an hourglass pointer.
5712 Value must be an integer or float. */);
5713 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
5715 #if 0 /* This doesn't really do anything. */
5716 DEFVAR_LISP ("x-mode-pointer-shape", &Vx_mode_pointer_shape
,
5717 doc
: /* The shape of the pointer when over the mode line.
5718 This variable takes effect when you create a new frame
5719 or when you set the mouse color. */);
5721 Vx_mode_pointer_shape
= Qnil
;
5723 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
5724 &Vx_sensitive_text_pointer_shape
,
5725 doc
: /* The shape of the pointer when over mouse-sensitive text.
5726 This variable takes effect when you create a new frame
5727 or when you set the mouse color. */);
5728 Vx_sensitive_text_pointer_shape
= Qnil
;
5730 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
5731 &Vx_window_horizontal_drag_shape
,
5732 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
5733 This variable takes effect when you create a new frame
5734 or when you set the mouse color. */);
5735 Vx_window_horizontal_drag_shape
= Qnil
;
5737 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
5738 doc
: /* A string indicating the foreground color of the cursor box. */);
5739 Vx_cursor_fore_pixel
= Qnil
;
5741 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
5742 doc
: /* Maximum size for tooltips. Value is a pair (COLUMNS . ROWS).
5743 Text larger than this is clipped. */);
5744 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
5746 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
5747 doc
: /* Non-nil if no X window manager is in use.
5748 Emacs doesn't try to figure this out; this is always nil
5749 unless you set it to something else. */);
5750 /* We don't have any way to find this out, so set it to nil
5751 and maybe the user would like to set it to t. */
5752 Vx_no_window_manager
= Qnil
;
5754 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
5755 &Vx_pixel_size_width_font_regexp
,
5756 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
5758 Since Emacs gets width of a font matching with this regexp from
5759 PIXEL_SIZE field of the name, font finding mechanism gets faster for
5760 such a font. This is especially effective for such large fonts as
5761 Chinese, Japanese, and Korean. */);
5762 Vx_pixel_size_width_font_regexp
= Qnil
;
5764 /* This is not ifdef:ed, so other builds than GTK can customize it. */
5765 DEFVAR_BOOL ("x-use-old-gtk-file-dialog", &x_use_old_gtk_file_dialog
,
5766 doc
: /* *Non-nil means prompt with the old GTK file selection dialog.
5767 If nil or if the file selection dialog is not available, the new GTK file
5768 chooser is used instead. To turn off all file dialogs set the
5769 variable `use-file-dialog'. */);
5770 x_use_old_gtk_file_dialog
= 0;
5772 Fprovide (intern ("x"), Qnil
);
5774 #ifdef USE_X_TOOLKIT
5775 Fprovide (intern ("x-toolkit"), Qnil
);
5777 Fprovide (intern ("motif"), Qnil
);
5779 DEFVAR_LISP ("motif-version-string", &Vmotif_version_string
,
5780 doc
: /* Version info for LessTif/Motif. */);
5781 Vmotif_version_string
= build_string (XmVERSION_STRING
);
5782 #endif /* USE_MOTIF */
5783 #endif /* USE_X_TOOLKIT */
5786 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
5787 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
5788 But for a user it is a toolkit for X, and indeed, configure
5789 accepts --with-x-toolkit=gtk. */
5790 Fprovide (intern ("x-toolkit"), Qnil
);
5791 Fprovide (intern ("gtk"), Qnil
);
5793 DEFVAR_LISP ("gtk-version-string", &Vgtk_version_string
,
5794 doc
: /* Version info for GTK+. */);
5796 char gtk_version
[40];
5797 g_snprintf (gtk_version
, sizeof (gtk_version
), "%u.%u.%u",
5798 GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
);
5799 Vgtk_version_string
= build_string (gtk_version
);
5801 #endif /* USE_GTK */
5803 /* X window properties. */
5804 defsubr (&Sx_change_window_property
);
5805 defsubr (&Sx_delete_window_property
);
5806 defsubr (&Sx_window_property
);
5808 defsubr (&Sxw_display_color_p
);
5809 defsubr (&Sx_display_grayscale_p
);
5810 defsubr (&Sxw_color_defined_p
);
5811 defsubr (&Sxw_color_values
);
5812 defsubr (&Sx_server_max_request_size
);
5813 defsubr (&Sx_server_vendor
);
5814 defsubr (&Sx_server_version
);
5815 defsubr (&Sx_display_pixel_width
);
5816 defsubr (&Sx_display_pixel_height
);
5817 defsubr (&Sx_display_mm_width
);
5818 defsubr (&Sx_display_mm_height
);
5819 defsubr (&Sx_display_screens
);
5820 defsubr (&Sx_display_planes
);
5821 defsubr (&Sx_display_color_cells
);
5822 defsubr (&Sx_display_visual_class
);
5823 defsubr (&Sx_display_backing_store
);
5824 defsubr (&Sx_display_save_under
);
5825 defsubr (&Sx_create_frame
);
5826 defsubr (&Sx_open_connection
);
5827 defsubr (&Sx_close_connection
);
5828 defsubr (&Sx_display_list
);
5829 defsubr (&Sx_synchronize
);
5830 defsubr (&Sx_focus_frame
);
5831 defsubr (&Sx_backspace_delete_keys_p
);
5833 /* Setting callback functions for fontset handler. */
5834 get_font_info_func
= x_get_font_info
;
5836 #if 0 /* This function pointer doesn't seem to be used anywhere.
5837 And the pointer assigned has the wrong type, anyway. */
5838 list_fonts_func
= x_list_fonts
;
5841 load_font_func
= x_load_font
;
5842 find_ccl_program_func
= x_find_ccl_program
;
5843 query_font_func
= x_query_font
;
5844 set_frame_fontset_func
= x_set_font
;
5845 check_window_system_func
= check_x
;
5847 hourglass_atimer
= NULL
;
5848 hourglass_shown_p
= 0;
5850 defsubr (&Sx_show_tip
);
5851 defsubr (&Sx_hide_tip
);
5853 staticpro (&tip_timer
);
5855 staticpro (&tip_frame
);
5857 last_show_tip_args
= Qnil
;
5858 staticpro (&last_show_tip_args
);
5860 #if defined (USE_MOTIF) || defined (USE_GTK)
5861 defsubr (&Sx_file_dialog
);
5865 #endif /* HAVE_X_WINDOWS */
5867 /* arch-tag: 55040d02-5485-4d58-8b22-95a7a05f3288
5868 (do not change this comment) */