1 /* Functions for the X window system.
2 Copyright (C) 1989, 92, 93, 94, 95, 96, 97, 98, 99, 2000,01,02,03,04
3 Free Software Foundation.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
31 /* This makes the fields of a Display accessible, in Xlib header files. */
33 #define XLIB_ILLEGAL_ACCESS
40 #include "intervals.h"
41 #include "dispextern.h"
43 #include "blockinput.h"
49 #include "termhooks.h"
56 #include <sys/types.h>
60 #if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */
61 #include "bitmaps/gray.xbm"
63 #include <X11/bitmaps/gray>
66 #include "[.bitmaps]gray.xbm"
74 #include <X11/Shell.h>
77 #include <X11/Xaw/Paned.h>
78 #include <X11/Xaw/Label.h>
79 #endif /* USE_MOTIF */
82 #undef USG /* ####KLUDGE for Solaris 2.2 and up */
91 #include "../lwlib/lwlib.h"
95 #include <Xm/DialogS.h>
96 #include <Xm/FileSB.h>
99 /* Do the EDITRES protocol if running X11R5
100 Exception: HP-UX (at least version A.09.05) has X11R5 without EditRes */
102 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
104 extern void _XEditResCheckMessages ();
105 #endif /* R5 + Athena */
107 /* Unique id counter for widgets created by the Lucid Widget Library. */
109 extern LWLIB_ID widget_id_tick
;
112 /* This is part of a kludge--see lwlib/xlwmenu.c. */
113 extern XFontStruct
*xlwmenu_default_font
;
116 extern void free_frame_menubar ();
117 extern double atof ();
121 /* LessTif/Motif version info. */
123 static Lisp_Object Vmotif_version_string
;
125 #endif /* USE_MOTIF */
127 #endif /* USE_X_TOOLKIT */
131 /* GTK+ version info */
133 static Lisp_Object Vgtk_version_string
;
138 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
140 #define MAXREQUEST(dpy) ((dpy)->max_request_size)
143 /* The gray bitmap `bitmaps/gray'. This is done because xterm.c uses
144 it, and including `bitmaps/gray' more than once is a problem when
145 config.h defines `static' as an empty replacement string. */
147 int gray_bitmap_width
= gray_width
;
148 int gray_bitmap_height
= gray_height
;
149 char *gray_bitmap_bits
= gray_bits
;
151 /* Non-zero means we're allowed to display an hourglass cursor. */
153 int display_hourglass_p
;
155 /* The background and shape of the mouse pointer, and shape when not
156 over text or in the modeline. */
158 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
159 Lisp_Object Vx_hourglass_pointer_shape
;
161 /* The shape when over mouse-sensitive text. */
163 Lisp_Object Vx_sensitive_text_pointer_shape
;
165 /* If non-nil, the pointer shape to indicate that windows can be
166 dragged horizontally. */
168 Lisp_Object Vx_window_horizontal_drag_shape
;
170 /* Color of chars displayed in cursor box. */
172 Lisp_Object Vx_cursor_fore_pixel
;
174 /* Nonzero if using X. */
178 /* Non nil if no window manager is in use. */
180 Lisp_Object Vx_no_window_manager
;
182 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
184 Lisp_Object Vx_pixel_size_width_font_regexp
;
187 Lisp_Object Qsuppress_icon
;
188 Lisp_Object Qundefined_color
;
189 Lisp_Object Qcompound_text
, Qcancel_timer
;
193 extern Lisp_Object Vwindow_system_version
;
195 /* The below are defined in frame.c. */
198 int image_cache_refcount
, dpyinfo_refcount
;
203 /* Error if we are not connected to X. */
209 error ("X windows are not in use or not initialized");
212 /* Nonzero if we can use mouse menus.
213 You should not call this unless HAVE_MENUS is defined. */
221 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
222 and checking validity for X. */
225 check_x_frame (frame
)
231 frame
= selected_frame
;
232 CHECK_LIVE_FRAME (frame
);
235 error ("Non-X frame used");
239 /* Let the user specify an X display with a frame.
240 nil stands for the selected frame--or, if that is not an X frame,
241 the first X display on the list. */
243 struct x_display_info
*
244 check_x_display_info (frame
)
247 struct x_display_info
*dpyinfo
= NULL
;
251 struct frame
*sf
= XFRAME (selected_frame
);
253 if (FRAME_X_P (sf
) && FRAME_LIVE_P (sf
))
254 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
255 else if (x_display_list
!= 0)
256 dpyinfo
= x_display_list
;
258 error ("X windows are not in use or not initialized");
260 else if (INTEGERP (frame
))
262 struct display
*d
= get_display (XINT (frame
));
265 wrong_type_argument (Qdisplay_live_p
, frame
);
266 if (d
->type
!= output_x_window
)
267 error ("Display %d is not an X display", XINT (frame
));
269 dpyinfo
= d
->display_info
.x
;
271 else if (STRINGP (frame
))
272 dpyinfo
= x_display_info_for_name (frame
);
275 FRAME_PTR f
= check_x_frame (frame
);
276 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
283 /* Return the Emacs frame-object corresponding to an X window.
284 It could be the frame's main window or an icon window. */
286 /* This function can be called during GC, so use GC_xxx type test macros. */
289 x_window_to_frame (dpyinfo
, wdesc
)
290 struct x_display_info
*dpyinfo
;
293 Lisp_Object tail
, frame
;
296 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
299 if (!GC_FRAMEP (frame
))
302 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
304 if (f
->output_data
.x
->hourglass_window
== wdesc
)
307 if ((f
->output_data
.x
->edit_widget
308 && XtWindow (f
->output_data
.x
->edit_widget
) == wdesc
)
309 /* A tooltip frame? */
310 || (!f
->output_data
.x
->edit_widget
311 && FRAME_X_WINDOW (f
) == wdesc
)
312 || f
->output_data
.x
->icon_desc
== wdesc
)
314 #else /* not USE_X_TOOLKIT */
316 if (f
->output_data
.x
->edit_widget
)
318 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
319 struct x_output
*x
= f
->output_data
.x
;
320 if (gwdesc
!= 0 && gwdesc
== x
->edit_widget
)
324 if (FRAME_X_WINDOW (f
) == wdesc
325 || f
->output_data
.x
->icon_desc
== wdesc
)
327 #endif /* not USE_X_TOOLKIT */
332 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
333 /* Like x_window_to_frame but also compares the window with the widget's
337 x_any_window_to_frame (dpyinfo
, wdesc
)
338 struct x_display_info
*dpyinfo
;
341 Lisp_Object tail
, frame
;
342 struct frame
*f
, *found
;
346 for (tail
= Vframe_list
; GC_CONSP (tail
) && !found
; tail
= XCDR (tail
))
349 if (!GC_FRAMEP (frame
))
353 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
355 /* This frame matches if the window is any of its widgets. */
356 x
= f
->output_data
.x
;
357 if (x
->hourglass_window
== wdesc
)
362 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
364 && (gwdesc
== x
->widget
365 || gwdesc
== x
->edit_widget
366 || gwdesc
== x
->vbox_widget
367 || gwdesc
== x
->menubar_widget
))
370 if (wdesc
== XtWindow (x
->widget
)
371 || wdesc
== XtWindow (x
->column_widget
)
372 || wdesc
== XtWindow (x
->edit_widget
))
374 /* Match if the window is this frame's menubar. */
375 else if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
379 else if (FRAME_X_WINDOW (f
) == wdesc
)
380 /* A tooltip frame. */
388 /* Likewise, but exclude the menu bar widget. */
391 x_non_menubar_window_to_frame (dpyinfo
, wdesc
)
392 struct x_display_info
*dpyinfo
;
395 Lisp_Object tail
, frame
;
399 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
402 if (!GC_FRAMEP (frame
))
405 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
407 x
= f
->output_data
.x
;
408 /* This frame matches if the window is any of its widgets. */
409 if (x
->hourglass_window
== wdesc
)
414 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
416 && (gwdesc
== x
->widget
417 || gwdesc
== x
->edit_widget
418 || gwdesc
== x
->vbox_widget
))
421 if (wdesc
== XtWindow (x
->widget
)
422 || wdesc
== XtWindow (x
->column_widget
)
423 || wdesc
== XtWindow (x
->edit_widget
))
427 else if (FRAME_X_WINDOW (f
) == wdesc
)
428 /* A tooltip frame. */
434 /* Likewise, but consider only the menu bar widget. */
437 x_menubar_window_to_frame (dpyinfo
, wdesc
)
438 struct x_display_info
*dpyinfo
;
441 Lisp_Object tail
, frame
;
445 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
448 if (!GC_FRAMEP (frame
))
451 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
453 x
= f
->output_data
.x
;
454 /* Match if the window is this frame's menubar. */
456 if (x
->menubar_widget
)
458 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
463 && (gwdesc
== x
->menubar_widget
464 || gtk_widget_get_parent (gwdesc
) == x
->menubar_widget
))
470 if (x
->menubar_widget
471 && lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
478 /* Return the frame whose principal (outermost) window is WDESC.
479 If WDESC is some other (smaller) window, we return 0. */
482 x_top_window_to_frame (dpyinfo
, wdesc
)
483 struct x_display_info
*dpyinfo
;
486 Lisp_Object tail
, frame
;
490 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
493 if (!GC_FRAMEP (frame
))
496 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
498 x
= f
->output_data
.x
;
502 /* This frame matches if the window is its topmost widget. */
504 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
505 if (gwdesc
== x
->widget
)
508 if (wdesc
== XtWindow (x
->widget
))
510 #if 0 /* I don't know why it did this,
511 but it seems logically wrong,
512 and it causes trouble for MapNotify events. */
513 /* Match if the window is this frame's menubar. */
514 if (x
->menubar_widget
515 && wdesc
== XtWindow (x
->menubar_widget
))
520 else if (FRAME_X_WINDOW (f
) == wdesc
)
526 #endif /* USE_X_TOOLKIT || USE_GTK */
530 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
531 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
533 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
534 static void x_set_wait_for_wm
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
535 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
536 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
537 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
538 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
539 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
540 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
541 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
542 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
543 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
544 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
545 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
546 void x_set_scroll_bar_foreground
P_ ((struct frame
*, Lisp_Object
,
548 void x_set_scroll_bar_background
P_ ((struct frame
*, Lisp_Object
,
550 static Lisp_Object x_default_scroll_bar_color_parameter
P_ ((struct frame
*,
557 /* Store the screen positions of frame F into XPTR and YPTR.
558 These are the positions of the containing window manager window,
559 not Emacs's own window. */
562 x_real_positions (f
, xptr
, yptr
)
566 int win_x
, win_y
, outer_x
, outer_y
;
567 int real_x
= 0, real_y
= 0;
569 Window win
= f
->output_data
.x
->parent_desc
;
575 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
577 if (win
== FRAME_X_DISPLAY_INFO (f
)->root_window
)
578 win
= FRAME_OUTER_WINDOW (f
);
580 /* This loop traverses up the containment tree until we hit the root
581 window. Window managers may intersect many windows between our window
582 and the root window. The window we find just before the root window
583 should be the outer WM window. */
586 Window wm_window
, rootw
;
587 Window
*tmp_children
;
588 unsigned int tmp_nchildren
;
591 success
= XQueryTree (FRAME_X_DISPLAY (f
), win
, &rootw
,
592 &wm_window
, &tmp_children
, &tmp_nchildren
);
594 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
596 /* Don't free tmp_children if XQueryTree failed. */
600 XFree ((char *) tmp_children
);
602 if (wm_window
== rootw
|| had_errors
)
613 /* Get the real coordinates for the WM window upper left corner */
614 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
615 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
617 /* Translate real coordinates to coordinates relative to our
618 window. For our window, the upper left corner is 0, 0.
619 Since the upper left corner of the WM window is outside
620 our window, win_x and win_y will be negative:
622 ------------------ ---> x
624 | ----------------- v y
627 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
629 /* From-window, to-window. */
630 FRAME_X_DISPLAY_INFO (f
)->root_window
,
633 /* From-position, to-position. */
634 real_x
, real_y
, &win_x
, &win_y
,
639 if (FRAME_X_WINDOW (f
) == FRAME_OUTER_WINDOW (f
))
646 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
648 /* From-window, to-window. */
649 FRAME_X_DISPLAY_INFO (f
)->root_window
,
650 FRAME_OUTER_WINDOW (f
),
652 /* From-position, to-position. */
653 real_x
, real_y
, &outer_x
, &outer_y
,
659 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
662 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
666 if (had_errors
) return;
668 f
->x_pixels_diff
= -win_x
;
669 f
->y_pixels_diff
= -win_y
;
671 FRAME_X_OUTPUT (f
)->x_pixels_outer_diff
= -outer_x
;
672 FRAME_X_OUTPUT (f
)->y_pixels_outer_diff
= -outer_y
;
681 /* Gamma-correct COLOR on frame F. */
684 gamma_correct (f
, color
)
690 color
->red
= pow (color
->red
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
691 color
->green
= pow (color
->green
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
692 color
->blue
= pow (color
->blue
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
697 /* Decide if color named COLOR_NAME is valid for use on frame F. If
698 so, return the RGB values in COLOR. If ALLOC_P is non-zero,
699 allocate the color. Value is zero if COLOR_NAME is invalid, or
700 no color could be allocated. */
703 x_defined_color (f
, color_name
, color
, alloc_p
)
710 Display
*dpy
= FRAME_X_DISPLAY (f
);
711 Colormap cmap
= FRAME_X_COLORMAP (f
);
714 success_p
= XParseColor (dpy
, cmap
, color_name
, color
);
715 if (success_p
&& alloc_p
)
716 success_p
= x_alloc_nearest_color (f
, cmap
, color
);
723 /* Return the pixel color value for color COLOR_NAME on frame F. If F
724 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
725 Signal an error if color can't be allocated. */
728 x_decode_color (f
, color_name
, mono_color
)
730 Lisp_Object color_name
;
735 CHECK_STRING (color_name
);
737 #if 0 /* Don't do this. It's wrong when we're not using the default
738 colormap, it makes freeing difficult, and it's probably not
739 an important optimization. */
740 if (strcmp (SDATA (color_name
), "black") == 0)
741 return BLACK_PIX_DEFAULT (f
);
742 else if (strcmp (SDATA (color_name
), "white") == 0)
743 return WHITE_PIX_DEFAULT (f
);
746 /* Return MONO_COLOR for monochrome frames. */
747 if (FRAME_X_DISPLAY_INFO (f
)->n_planes
== 1)
750 /* x_defined_color is responsible for coping with failures
751 by looking for a near-miss. */
752 if (x_defined_color (f
, SDATA (color_name
), &cdef
, 1))
755 Fsignal (Qerror
, Fcons (build_string ("Undefined color"),
756 Fcons (color_name
, Qnil
)));
762 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
763 the previous value of that parameter, NEW_VALUE is the new value.
764 See also the comment of wait_for_wm in struct x_output. */
767 x_set_wait_for_wm (f
, new_value
, old_value
)
769 Lisp_Object new_value
, old_value
;
771 f
->output_data
.x
->wait_for_wm
= !NILP (new_value
);
776 /* Set icon from FILE for frame F. By using GTK functions the icon
777 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
780 xg_set_icon (f
, file
)
790 found
= x_find_image_file (file
);
798 filename
= SDATA (found
);
801 pixbuf
= gdk_pixbuf_new_from_file (filename
, &err
);
805 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
807 g_object_unref (pixbuf
);
823 /* Functions called only from `x_set_frame_param'
824 to set individual parameters.
826 If FRAME_X_WINDOW (f) is 0,
827 the frame is being created and its X-window does not exist yet.
828 In that case, just record the parameter's new value
829 in the standard place; do not attempt to change the window. */
832 x_set_foreground_color (f
, arg
, oldval
)
834 Lisp_Object arg
, oldval
;
836 struct x_output
*x
= f
->output_data
.x
;
837 unsigned long fg
, old_fg
;
839 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
840 old_fg
= x
->foreground_pixel
;
841 x
->foreground_pixel
= fg
;
843 if (FRAME_X_WINDOW (f
) != 0)
845 Display
*dpy
= FRAME_X_DISPLAY (f
);
848 XSetForeground (dpy
, x
->normal_gc
, fg
);
849 XSetBackground (dpy
, x
->reverse_gc
, fg
);
851 if (x
->cursor_pixel
== old_fg
)
853 unload_color (f
, x
->cursor_pixel
);
854 x
->cursor_pixel
= x_copy_color (f
, fg
);
855 XSetBackground (dpy
, x
->cursor_gc
, x
->cursor_pixel
);
860 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
862 if (FRAME_VISIBLE_P (f
))
866 unload_color (f
, old_fg
);
870 x_set_background_color (f
, arg
, oldval
)
872 Lisp_Object arg
, oldval
;
874 struct x_output
*x
= f
->output_data
.x
;
877 bg
= x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
878 unload_color (f
, x
->background_pixel
);
879 x
->background_pixel
= bg
;
881 if (FRAME_X_WINDOW (f
) != 0)
883 Display
*dpy
= FRAME_X_DISPLAY (f
);
886 XSetBackground (dpy
, x
->normal_gc
, bg
);
887 XSetForeground (dpy
, x
->reverse_gc
, bg
);
888 XSetWindowBackground (dpy
, FRAME_X_WINDOW (f
), bg
);
889 XSetForeground (dpy
, x
->cursor_gc
, bg
);
892 xg_set_background_color (f
, bg
);
895 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
896 toolkit scroll bars. */
899 for (bar
= FRAME_SCROLL_BARS (f
);
901 bar
= XSCROLL_BAR (bar
)->next
)
903 Window window
= SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
));
904 XSetWindowBackground (dpy
, window
, bg
);
907 #endif /* USE_TOOLKIT_SCROLL_BARS */
910 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
912 if (FRAME_VISIBLE_P (f
))
918 x_set_mouse_color (f
, arg
, oldval
)
920 Lisp_Object arg
, oldval
;
922 struct x_output
*x
= f
->output_data
.x
;
923 Display
*dpy
= FRAME_X_DISPLAY (f
);
924 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
925 Cursor hourglass_cursor
, horizontal_drag_cursor
;
927 unsigned long pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
928 unsigned long mask_color
= x
->background_pixel
;
930 /* Don't let pointers be invisible. */
931 if (mask_color
== pixel
)
933 x_free_colors (f
, &pixel
, 1);
934 pixel
= x_copy_color (f
, x
->foreground_pixel
);
937 unload_color (f
, x
->mouse_pixel
);
938 x
->mouse_pixel
= pixel
;
942 /* It's not okay to crash if the user selects a screwy cursor. */
943 count
= x_catch_errors (dpy
);
945 if (!NILP (Vx_pointer_shape
))
947 CHECK_NUMBER (Vx_pointer_shape
);
948 cursor
= XCreateFontCursor (dpy
, XINT (Vx_pointer_shape
));
951 cursor
= XCreateFontCursor (dpy
, XC_xterm
);
952 x_check_errors (dpy
, "bad text pointer cursor: %s");
954 if (!NILP (Vx_nontext_pointer_shape
))
956 CHECK_NUMBER (Vx_nontext_pointer_shape
);
958 = XCreateFontCursor (dpy
, XINT (Vx_nontext_pointer_shape
));
961 nontext_cursor
= XCreateFontCursor (dpy
, XC_left_ptr
);
962 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
964 if (!NILP (Vx_hourglass_pointer_shape
))
966 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
968 = XCreateFontCursor (dpy
, XINT (Vx_hourglass_pointer_shape
));
971 hourglass_cursor
= XCreateFontCursor (dpy
, XC_watch
);
972 x_check_errors (dpy
, "bad hourglass pointer cursor: %s");
974 if (!NILP (Vx_mode_pointer_shape
))
976 CHECK_NUMBER (Vx_mode_pointer_shape
);
977 mode_cursor
= XCreateFontCursor (dpy
, XINT (Vx_mode_pointer_shape
));
980 mode_cursor
= XCreateFontCursor (dpy
, XC_xterm
);
981 x_check_errors (dpy
, "bad modeline pointer cursor: %s");
983 if (!NILP (Vx_sensitive_text_pointer_shape
))
985 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
987 = XCreateFontCursor (dpy
, XINT (Vx_sensitive_text_pointer_shape
));
990 hand_cursor
= XCreateFontCursor (dpy
, XC_hand2
);
992 if (!NILP (Vx_window_horizontal_drag_shape
))
994 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
995 horizontal_drag_cursor
996 = XCreateFontCursor (dpy
, XINT (Vx_window_horizontal_drag_shape
));
999 horizontal_drag_cursor
1000 = XCreateFontCursor (dpy
, XC_sb_h_double_arrow
);
1002 /* Check and report errors with the above calls. */
1003 x_check_errors (dpy
, "can't set cursor shape: %s");
1004 x_uncatch_errors (dpy
, count
);
1007 XColor fore_color
, back_color
;
1009 fore_color
.pixel
= x
->mouse_pixel
;
1010 x_query_color (f
, &fore_color
);
1011 back_color
.pixel
= mask_color
;
1012 x_query_color (f
, &back_color
);
1014 XRecolorCursor (dpy
, cursor
, &fore_color
, &back_color
);
1015 XRecolorCursor (dpy
, nontext_cursor
, &fore_color
, &back_color
);
1016 XRecolorCursor (dpy
, mode_cursor
, &fore_color
, &back_color
);
1017 XRecolorCursor (dpy
, hand_cursor
, &fore_color
, &back_color
);
1018 XRecolorCursor (dpy
, hourglass_cursor
, &fore_color
, &back_color
);
1019 XRecolorCursor (dpy
, horizontal_drag_cursor
, &fore_color
, &back_color
);
1022 if (FRAME_X_WINDOW (f
) != 0)
1023 XDefineCursor (dpy
, FRAME_X_WINDOW (f
), cursor
);
1025 if (cursor
!= x
->text_cursor
1026 && x
->text_cursor
!= 0)
1027 XFreeCursor (dpy
, x
->text_cursor
);
1028 x
->text_cursor
= cursor
;
1030 if (nontext_cursor
!= x
->nontext_cursor
1031 && x
->nontext_cursor
!= 0)
1032 XFreeCursor (dpy
, x
->nontext_cursor
);
1033 x
->nontext_cursor
= nontext_cursor
;
1035 if (hourglass_cursor
!= x
->hourglass_cursor
1036 && x
->hourglass_cursor
!= 0)
1037 XFreeCursor (dpy
, x
->hourglass_cursor
);
1038 x
->hourglass_cursor
= hourglass_cursor
;
1040 if (mode_cursor
!= x
->modeline_cursor
1041 && x
->modeline_cursor
!= 0)
1042 XFreeCursor (dpy
, f
->output_data
.x
->modeline_cursor
);
1043 x
->modeline_cursor
= mode_cursor
;
1045 if (hand_cursor
!= x
->hand_cursor
1046 && x
->hand_cursor
!= 0)
1047 XFreeCursor (dpy
, x
->hand_cursor
);
1048 x
->hand_cursor
= hand_cursor
;
1050 if (horizontal_drag_cursor
!= x
->horizontal_drag_cursor
1051 && x
->horizontal_drag_cursor
!= 0)
1052 XFreeCursor (dpy
, x
->horizontal_drag_cursor
);
1053 x
->horizontal_drag_cursor
= horizontal_drag_cursor
;
1058 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1062 x_set_cursor_color (f
, arg
, oldval
)
1064 Lisp_Object arg
, oldval
;
1066 unsigned long fore_pixel
, pixel
;
1067 int fore_pixel_allocated_p
= 0, pixel_allocated_p
= 0;
1068 struct x_output
*x
= f
->output_data
.x
;
1070 if (!NILP (Vx_cursor_fore_pixel
))
1072 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1073 WHITE_PIX_DEFAULT (f
));
1074 fore_pixel_allocated_p
= 1;
1077 fore_pixel
= x
->background_pixel
;
1079 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1080 pixel_allocated_p
= 1;
1082 /* Make sure that the cursor color differs from the background color. */
1083 if (pixel
== x
->background_pixel
)
1085 if (pixel_allocated_p
)
1087 x_free_colors (f
, &pixel
, 1);
1088 pixel_allocated_p
= 0;
1091 pixel
= x
->mouse_pixel
;
1092 if (pixel
== fore_pixel
)
1094 if (fore_pixel_allocated_p
)
1096 x_free_colors (f
, &fore_pixel
, 1);
1097 fore_pixel_allocated_p
= 0;
1099 fore_pixel
= x
->background_pixel
;
1103 unload_color (f
, x
->cursor_foreground_pixel
);
1104 if (!fore_pixel_allocated_p
)
1105 fore_pixel
= x_copy_color (f
, fore_pixel
);
1106 x
->cursor_foreground_pixel
= fore_pixel
;
1108 unload_color (f
, x
->cursor_pixel
);
1109 if (!pixel_allocated_p
)
1110 pixel
= x_copy_color (f
, pixel
);
1111 x
->cursor_pixel
= pixel
;
1113 if (FRAME_X_WINDOW (f
) != 0)
1116 XSetBackground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, x
->cursor_pixel
);
1117 XSetForeground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, fore_pixel
);
1120 if (FRAME_VISIBLE_P (f
))
1122 x_update_cursor (f
, 0);
1123 x_update_cursor (f
, 1);
1127 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1130 /* Set the border-color of frame F to pixel value PIX.
1131 Note that this does not fully take effect if done before
1132 F has an x-window. */
1135 x_set_border_pixel (f
, pix
)
1139 unload_color (f
, f
->output_data
.x
->border_pixel
);
1140 f
->output_data
.x
->border_pixel
= pix
;
1142 if (FRAME_X_WINDOW (f
) != 0 && f
->border_width
> 0)
1145 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1146 (unsigned long)pix
);
1149 if (FRAME_VISIBLE_P (f
))
1154 /* Set the border-color of frame F to value described by ARG.
1155 ARG can be a string naming a color.
1156 The border-color is used for the border that is drawn by the X server.
1157 Note that this does not fully take effect if done before
1158 F has an x-window; it must be redone when the window is created.
1160 Note: this is done in two routines because of the way X10 works.
1162 Note: under X11, this is normally the province of the window manager,
1163 and so emacs' border colors may be overridden. */
1166 x_set_border_color (f
, arg
, oldval
)
1168 Lisp_Object arg
, oldval
;
1173 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1174 x_set_border_pixel (f
, pix
);
1175 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1180 x_set_cursor_type (f
, arg
, oldval
)
1182 Lisp_Object arg
, oldval
;
1184 set_frame_cursor_types (f
, arg
);
1186 /* Make sure the cursor gets redrawn. */
1187 cursor_type_changed
= 1;
1191 x_set_icon_type (f
, arg
, oldval
)
1193 Lisp_Object arg
, oldval
;
1199 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1202 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1207 result
= x_text_icon (f
,
1208 (char *) SDATA ((!NILP (f
->icon_name
)
1212 result
= x_bitmap_icon (f
, arg
);
1217 error ("No icon window available");
1220 XFlush (FRAME_X_DISPLAY (f
));
1225 x_set_icon_name (f
, arg
, oldval
)
1227 Lisp_Object arg
, oldval
;
1233 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1236 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1241 if (f
->output_data
.x
->icon_bitmap
!= 0)
1246 result
= x_text_icon (f
,
1247 (char *) SDATA ((!NILP (f
->icon_name
)
1256 error ("No icon window available");
1259 XFlush (FRAME_X_DISPLAY (f
));
1265 x_set_menu_bar_lines (f
, value
, oldval
)
1267 Lisp_Object value
, oldval
;
1270 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
1271 int olines
= FRAME_MENU_BAR_LINES (f
);
1274 /* Right now, menu bars don't work properly in minibuf-only frames;
1275 most of the commands try to apply themselves to the minibuffer
1276 frame itself, and get an error because you can't switch buffers
1277 in or split the minibuffer window. */
1278 if (FRAME_MINIBUF_ONLY_P (f
))
1281 if (INTEGERP (value
))
1282 nlines
= XINT (value
);
1286 /* Make sure we redisplay all windows in this frame. */
1287 windows_or_buffers_changed
++;
1289 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
1290 FRAME_MENU_BAR_LINES (f
) = 0;
1293 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1294 if (FRAME_X_P (f
) && f
->output_data
.x
->menubar_widget
== 0)
1295 /* Make sure next redisplay shows the menu bar. */
1296 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= Qt
;
1300 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1301 free_frame_menubar (f
);
1302 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1304 f
->output_data
.x
->menubar_widget
= 0;
1306 #else /* not USE_X_TOOLKIT && not USE_GTK */
1307 FRAME_MENU_BAR_LINES (f
) = nlines
;
1308 change_window_heights (f
->root_window
, nlines
- olines
);
1309 #endif /* not USE_X_TOOLKIT */
1314 /* Set the number of lines used for the tool bar of frame F to VALUE.
1315 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1316 is the old number of tool bar lines. This function changes the
1317 height of all windows on frame F to match the new tool bar height.
1318 The frame's height doesn't change. */
1321 x_set_tool_bar_lines (f
, value
, oldval
)
1323 Lisp_Object value
, oldval
;
1325 int delta
, nlines
, root_height
;
1326 Lisp_Object root_window
;
1328 /* Treat tool bars like menu bars. */
1329 if (FRAME_MINIBUF_ONLY_P (f
))
1332 /* Use VALUE only if an integer >= 0. */
1333 if (INTEGERP (value
) && XINT (value
) >= 0)
1334 nlines
= XFASTINT (value
);
1339 FRAME_TOOL_BAR_LINES (f
) = 0;
1342 FRAME_EXTERNAL_TOOL_BAR (f
) = 1;
1343 if (FRAME_X_P (f
) && f
->output_data
.x
->toolbar_widget
== 0)
1344 /* Make sure next redisplay shows the tool bar. */
1345 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= Qt
;
1346 update_frame_tool_bar (f
);
1350 if (FRAME_EXTERNAL_TOOL_BAR (f
))
1351 free_frame_tool_bar (f
);
1352 FRAME_EXTERNAL_TOOL_BAR (f
) = 0;
1358 /* Make sure we redisplay all windows in this frame. */
1359 ++windows_or_buffers_changed
;
1361 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1363 /* Don't resize the tool-bar to more than we have room for. */
1364 root_window
= FRAME_ROOT_WINDOW (f
);
1365 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1366 if (root_height
- delta
< 1)
1368 delta
= root_height
- 1;
1369 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1372 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1373 change_window_heights (root_window
, delta
);
1376 /* We also have to make sure that the internal border at the top of
1377 the frame, below the menu bar or tool bar, is redrawn when the
1378 tool bar disappears. This is so because the internal border is
1379 below the tool bar if one is displayed, but is below the menu bar
1380 if there isn't a tool bar. The tool bar draws into the area
1381 below the menu bar. */
1382 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1385 clear_current_matrices (f
);
1388 /* If the tool bar gets smaller, the internal border below it
1389 has to be cleared. It was formerly part of the display
1390 of the larger tool bar, and updating windows won't clear it. */
1393 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1394 int width
= FRAME_PIXEL_WIDTH (f
);
1395 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1398 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1399 0, y
, width
, height
, False
);
1402 if (WINDOWP (f
->tool_bar_window
))
1403 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1408 /* Set the foreground color for scroll bars on frame F to VALUE.
1409 VALUE should be a string, a color name. If it isn't a string or
1410 isn't a valid color name, do nothing. OLDVAL is the old value of
1411 the frame parameter. */
1414 x_set_scroll_bar_foreground (f
, value
, oldval
)
1416 Lisp_Object value
, oldval
;
1418 unsigned long pixel
;
1420 if (STRINGP (value
))
1421 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
1425 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
1426 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
1428 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
1429 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1431 /* Remove all scroll bars because they have wrong colors. */
1432 if (FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
)
1433 (*FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
) (f
);
1434 if (FRAME_DISPLAY (f
)->judge_scroll_bars_hook
)
1435 (*FRAME_DISPLAY (f
)->judge_scroll_bars_hook
) (f
);
1437 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
1443 /* Set the background color for scroll bars on frame F to VALUE VALUE
1444 should be a string, a color name. If it isn't a string or isn't a
1445 valid color name, do nothing. OLDVAL is the old value of the frame
1449 x_set_scroll_bar_background (f
, value
, oldval
)
1451 Lisp_Object value
, oldval
;
1453 unsigned long pixel
;
1455 if (STRINGP (value
))
1456 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
1460 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
1461 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
1463 #ifdef USE_TOOLKIT_SCROLL_BARS
1464 /* Scrollbar shadow colors. */
1465 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
1467 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
1468 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
1470 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
1472 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
1473 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
1475 #endif /* USE_TOOLKIT_SCROLL_BARS */
1477 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
1478 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1480 /* Remove all scroll bars because they have wrong colors. */
1481 if (FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
)
1482 (*FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
) (f
);
1483 if (FRAME_DISPLAY (f
)->judge_scroll_bars_hook
)
1484 (*FRAME_DISPLAY (f
)->judge_scroll_bars_hook
) (f
);
1486 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
1492 /* Encode Lisp string STRING as a text in a format appropriate for
1493 XICCC (X Inter Client Communication Conventions).
1495 If STRING contains only ASCII characters, do no conversion and
1496 return the string data of STRING. Otherwise, encode the text by
1497 CODING_SYSTEM, and return a newly allocated memory area which
1498 should be freed by `xfree' by a caller.
1500 SELECTIONP non-zero means the string is being encoded for an X
1501 selection, so it is safe to run pre-write conversions (which
1504 Store the byte length of resulting text in *TEXT_BYTES.
1506 If the text contains only ASCII and Latin-1, store 1 in *STRING_P,
1507 which means that the `encoding' of the result can be `STRING'.
1508 Otherwise store 0 in *STRINGP, which means that the `encoding' of
1509 the result should be `COMPOUND_TEXT'. */
1512 x_encode_text (string
, coding_system
, selectionp
, text_bytes
, stringp
)
1513 Lisp_Object string
, coding_system
;
1514 int *text_bytes
, *stringp
;
1517 unsigned char *str
= SDATA (string
);
1518 int chars
= SCHARS (string
);
1519 int bytes
= SBYTES (string
);
1523 struct coding_system coding
;
1524 extern Lisp_Object Qcompound_text_with_extensions
;
1526 charset_info
= find_charset_in_text (str
, chars
, bytes
, NULL
, Qnil
);
1527 if (charset_info
== 0)
1529 /* No multibyte character in OBJ. We need not encode it. */
1530 *text_bytes
= bytes
;
1535 setup_coding_system (coding_system
, &coding
);
1537 && SYMBOLP (coding
.pre_write_conversion
)
1538 && !NILP (Ffboundp (coding
.pre_write_conversion
)))
1540 string
= run_pre_post_conversion_on_str (string
, &coding
, 1);
1541 str
= SDATA (string
);
1542 chars
= SCHARS (string
);
1543 bytes
= SBYTES (string
);
1545 coding
.src_multibyte
= 1;
1546 coding
.dst_multibyte
= 0;
1547 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
1548 if (coding
.type
== coding_type_iso2022
)
1549 coding
.flags
|= CODING_FLAG_ISO_SAFE
;
1550 /* We suppress producing escape sequences for composition. */
1551 coding
.composing
= COMPOSITION_DISABLED
;
1552 bufsize
= encoding_buffer_size (&coding
, bytes
);
1553 buf
= (unsigned char *) xmalloc (bufsize
);
1554 encode_coding (&coding
, str
, buf
, bytes
, bufsize
);
1555 *text_bytes
= coding
.produced
;
1556 *stringp
= (charset_info
== 1
1557 || (!EQ (coding_system
, Qcompound_text
)
1558 && !EQ (coding_system
, Qcompound_text_with_extensions
)));
1563 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1566 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1567 name; if NAME is a string, set F's name to NAME and set
1568 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1570 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1571 suggesting a new name, which lisp code should override; if
1572 F->explicit_name is set, ignore the new name; otherwise, set it. */
1575 x_set_name (f
, name
, explicit)
1580 /* Make sure that requests from lisp code override requests from
1581 Emacs redisplay code. */
1584 /* If we're switching from explicit to implicit, we had better
1585 update the mode lines and thereby update the title. */
1586 if (f
->explicit_name
&& NILP (name
))
1587 update_mode_lines
= 1;
1589 f
->explicit_name
= ! NILP (name
);
1591 else if (f
->explicit_name
)
1594 /* If NAME is nil, set the name to the x_id_name. */
1597 /* Check for no change needed in this very common case
1598 before we do any consing. */
1599 if (!strcmp (FRAME_X_DISPLAY_INFO (f
)->x_id_name
,
1602 name
= build_string (FRAME_X_DISPLAY_INFO (f
)->x_id_name
);
1605 CHECK_STRING (name
);
1607 /* Don't change the name if it's already NAME. */
1608 if (! NILP (Fstring_equal (name
, f
->name
)))
1613 /* For setting the frame title, the title parameter should override
1614 the name parameter. */
1615 if (! NILP (f
->title
))
1618 if (FRAME_X_WINDOW (f
))
1623 XTextProperty text
, icon
;
1625 Lisp_Object coding_system
;
1627 /* Note: Encoding strategy
1629 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1630 text.encoding. But, there are non-internationalized window
1631 managers which don't support that encoding. So, if NAME
1632 contains only ASCII and 8859-1 characters, encode it by
1633 iso-latin-1, and use "STRING" in text.encoding hoping that
1634 such window managers at least analyze this format correctly,
1635 i.e. treat 8-bit bytes as 8859-1 characters.
1637 We may also be able to use "UTF8_STRING" in text.encoding
1638 in the future which can encode all Unicode characters.
1639 But, for the moment, there's no way to know that the
1640 current window manager supports it or not. */
1641 coding_system
= Qcompound_text
;
1642 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
);
1643 text
.encoding
= (stringp
? XA_STRING
1644 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1646 text
.nitems
= bytes
;
1648 if (NILP (f
->icon_name
))
1654 /* See the above comment "Note: Encoding strategy". */
1655 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
1657 icon
.encoding
= (stringp
? XA_STRING
1658 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1660 icon
.nitems
= bytes
;
1663 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1665 #else /* not USE_GTK */
1666 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1667 #endif /* not USE_GTK */
1669 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &icon
);
1671 if (!NILP (f
->icon_name
)
1672 && icon
.value
!= (unsigned char *) SDATA (f
->icon_name
))
1674 if (text
.value
!= (unsigned char *) SDATA (name
))
1677 #else /* not HAVE_X11R4 */
1678 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1680 XStoreName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1682 #endif /* not HAVE_X11R4 */
1687 /* This function should be called when the user's lisp code has
1688 specified a name for the frame; the name will override any set by the
1691 x_explicitly_set_name (f
, arg
, oldval
)
1693 Lisp_Object arg
, oldval
;
1695 x_set_name (f
, arg
, 1);
1698 /* This function should be called by Emacs redisplay code to set the
1699 name; names set this way will never override names set by the user's
1702 x_implicitly_set_name (f
, arg
, oldval
)
1704 Lisp_Object arg
, oldval
;
1706 x_set_name (f
, arg
, 0);
1709 /* Change the title of frame F to NAME.
1710 If NAME is nil, use the frame name as the title.
1712 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1713 name; if NAME is a string, set F's name to NAME and set
1714 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1716 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1717 suggesting a new name, which lisp code should override; if
1718 F->explicit_name is set, ignore the new name; otherwise, set it. */
1721 x_set_title (f
, name
, old_name
)
1723 Lisp_Object name
, old_name
;
1725 /* Don't change the title if it's already NAME. */
1726 if (EQ (name
, f
->title
))
1729 update_mode_lines
= 1;
1736 CHECK_STRING (name
);
1738 if (FRAME_X_WINDOW (f
))
1743 XTextProperty text
, icon
;
1745 Lisp_Object coding_system
;
1747 coding_system
= Qcompound_text
;
1748 /* See the comment "Note: Encoding strategy" in x_set_name. */
1749 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
);
1750 text
.encoding
= (stringp
? XA_STRING
1751 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1753 text
.nitems
= bytes
;
1755 if (NILP (f
->icon_name
))
1761 /* See the comment "Note: Encoding strategy" in x_set_name. */
1762 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
1764 icon
.encoding
= (stringp
? XA_STRING
1765 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1767 icon
.nitems
= bytes
;
1771 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1773 #else /* not USE_GTK */
1774 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1775 #endif /* not USE_GTK */
1777 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1780 if (!NILP (f
->icon_name
)
1781 && icon
.value
!= (unsigned char *) SDATA (f
->icon_name
))
1783 if (text
.value
!= (unsigned char *) SDATA (name
))
1786 #else /* not HAVE_X11R4 */
1787 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1789 XStoreName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1791 #endif /* not HAVE_X11R4 */
1797 x_set_scroll_bar_default_width (f
)
1800 int wid
= FRAME_COLUMN_WIDTH (f
);
1802 #ifdef USE_TOOLKIT_SCROLL_BARS
1803 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1804 int width
= 16 + 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1805 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (width
+ wid
- 1) / wid
;
1806 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = width
;
1808 /* Make the actual width at least 14 pixels and a multiple of a
1810 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
1812 /* Use all of that space (aside from required margins) for the
1814 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = 0;
1819 /* Record in frame F the specified or default value according to ALIST
1820 of the parameter named PROP (a Lisp symbol). If no value is
1821 specified for PROP, look for an X default for XPROP on the frame
1822 named NAME. If that is not found either, use the value DEFLT. */
1825 x_default_scroll_bar_color_parameter (f
, alist
, prop
, xprop
, xclass
,
1834 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1837 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
1838 if (EQ (tem
, Qunbound
))
1840 #ifdef USE_TOOLKIT_SCROLL_BARS
1842 /* See if an X resource for the scroll bar color has been
1844 tem
= display_x_get_resource (dpyinfo
,
1845 build_string (foreground_p
1849 build_string ("verticalScrollBar"),
1853 /* If nothing has been specified, scroll bars will use a
1854 toolkit-dependent default. Because these defaults are
1855 difficult to get at without actually creating a scroll
1856 bar, use nil to indicate that no color has been
1861 #else /* not USE_TOOLKIT_SCROLL_BARS */
1865 #endif /* not USE_TOOLKIT_SCROLL_BARS */
1868 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
1874 #if !defined (HAVE_X11R4) && !defined (HAVE_XSETWMPROTOCOLS)
1877 XSetWMProtocols (dpy
, w
, protocols
, count
)
1884 prop
= XInternAtom (dpy
, "WM_PROTOCOLS", False
);
1885 if (prop
== None
) return False
;
1886 XChangeProperty (dpy
, w
, prop
, XA_ATOM
, 32, PropModeReplace
,
1887 (unsigned char *) protocols
, count
);
1890 #endif /* not HAVE_X11R4 && not HAVE_XSETWMPROTOCOLS */
1892 #ifdef USE_X_TOOLKIT
1894 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
1895 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
1896 already be present because of the toolkit (Motif adds some of them,
1897 for example, but Xt doesn't). */
1900 hack_wm_protocols (f
, widget
)
1904 Display
*dpy
= XtDisplay (widget
);
1905 Window w
= XtWindow (widget
);
1906 int need_delete
= 1;
1912 Atom type
, *atoms
= 0;
1914 unsigned long nitems
= 0;
1915 unsigned long bytes_after
;
1917 if ((XGetWindowProperty (dpy
, w
,
1918 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1919 (long)0, (long)100, False
, XA_ATOM
,
1920 &type
, &format
, &nitems
, &bytes_after
,
1921 (unsigned char **) &atoms
)
1923 && format
== 32 && type
== XA_ATOM
)
1927 if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
1929 else if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
1931 else if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
1934 if (atoms
) XFree ((char *) atoms
);
1940 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
1942 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
1944 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
1946 XChangeProperty (dpy
, w
, FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1947 XA_ATOM
, 32, PropModeAppend
,
1948 (unsigned char *) props
, count
);
1956 /* Support routines for XIC (X Input Context). */
1960 static XFontSet xic_create_xfontset
P_ ((struct frame
*, char *));
1961 static XIMStyle best_xim_style
P_ ((XIMStyles
*, XIMStyles
*));
1964 /* Supported XIM styles, ordered by preference. */
1966 static XIMStyle supported_xim_styles
[] =
1968 XIMPreeditPosition
| XIMStatusArea
,
1969 XIMPreeditPosition
| XIMStatusNothing
,
1970 XIMPreeditPosition
| XIMStatusNone
,
1971 XIMPreeditNothing
| XIMStatusArea
,
1972 XIMPreeditNothing
| XIMStatusNothing
,
1973 XIMPreeditNothing
| XIMStatusNone
,
1974 XIMPreeditNone
| XIMStatusArea
,
1975 XIMPreeditNone
| XIMStatusNothing
,
1976 XIMPreeditNone
| XIMStatusNone
,
1981 /* Create an X fontset on frame F with base font name
1985 xic_create_xfontset (f
, base_fontname
)
1987 char *base_fontname
;
1990 char **missing_list
;
1994 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
),
1995 base_fontname
, &missing_list
,
1996 &missing_count
, &def_string
);
1998 XFreeStringList (missing_list
);
2000 /* No need to free def_string. */
2005 /* Value is the best input style, given user preferences USER (already
2006 checked to be supported by Emacs), and styles supported by the
2007 input method XIM. */
2010 best_xim_style (user
, xim
)
2016 for (i
= 0; i
< user
->count_styles
; ++i
)
2017 for (j
= 0; j
< xim
->count_styles
; ++j
)
2018 if (user
->supported_styles
[i
] == xim
->supported_styles
[j
])
2019 return user
->supported_styles
[i
];
2021 /* Return the default style. */
2022 return XIMPreeditNothing
| XIMStatusNothing
;
2025 /* Create XIC for frame F. */
2027 static XIMStyle xic_style
;
2030 create_frame_xic (f
)
2035 XFontSet xfs
= NULL
;
2040 xim
= FRAME_X_XIM (f
);
2045 XVaNestedList preedit_attr
;
2046 XVaNestedList status_attr
;
2047 char *base_fontname
;
2050 s_area
.x
= 0; s_area
.y
= 0; s_area
.width
= 1; s_area
.height
= 1;
2051 spot
.x
= 0; spot
.y
= 1;
2052 /* Create X fontset. */
2053 fontset
= FRAME_FONTSET (f
);
2055 base_fontname
= "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
2058 /* Determine the base fontname from the ASCII font name of
2060 char *ascii_font
= (char *) SDATA (fontset_ascii (fontset
));
2061 char *p
= ascii_font
;
2064 for (i
= 0; *p
; p
++)
2067 /* As the font name doesn't conform to XLFD, we can't
2068 modify it to get a suitable base fontname for the
2070 base_fontname
= "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
2073 int len
= strlen (ascii_font
) + 1;
2076 for (i
= 0, p
= ascii_font
; i
< 8; p
++)
2085 base_fontname
= (char *) alloca (len
);
2086 bzero (base_fontname
, len
);
2087 strcpy (base_fontname
, "-*-*-");
2088 bcopy (p1
, base_fontname
+ 5, p
- p1
);
2089 strcat (base_fontname
, "*-*-*-*-*-*-*");
2092 xfs
= xic_create_xfontset (f
, base_fontname
);
2094 /* Determine XIC style. */
2097 XIMStyles supported_list
;
2098 supported_list
.count_styles
= (sizeof supported_xim_styles
2099 / sizeof supported_xim_styles
[0]);
2100 supported_list
.supported_styles
= supported_xim_styles
;
2101 xic_style
= best_xim_style (&supported_list
,
2102 FRAME_X_XIM_STYLES (f
));
2105 preedit_attr
= XVaCreateNestedList (0,
2108 FRAME_FOREGROUND_PIXEL (f
),
2110 FRAME_BACKGROUND_PIXEL (f
),
2111 (xic_style
& XIMPreeditPosition
2116 status_attr
= XVaCreateNestedList (0,
2122 FRAME_FOREGROUND_PIXEL (f
),
2124 FRAME_BACKGROUND_PIXEL (f
),
2127 xic
= XCreateIC (xim
,
2128 XNInputStyle
, xic_style
,
2129 XNClientWindow
, FRAME_X_WINDOW (f
),
2130 XNFocusWindow
, FRAME_X_WINDOW (f
),
2131 XNStatusAttributes
, status_attr
,
2132 XNPreeditAttributes
, preedit_attr
,
2134 XFree (preedit_attr
);
2135 XFree (status_attr
);
2138 FRAME_XIC (f
) = xic
;
2139 FRAME_XIC_STYLE (f
) = xic_style
;
2140 FRAME_XIC_FONTSET (f
) = xfs
;
2144 /* Destroy XIC and free XIC fontset of frame F, if any. */
2150 if (FRAME_XIC (f
) == NULL
)
2153 XDestroyIC (FRAME_XIC (f
));
2154 if (FRAME_XIC_FONTSET (f
))
2155 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
2157 FRAME_XIC (f
) = NULL
;
2158 FRAME_XIC_FONTSET (f
) = NULL
;
2162 /* Place preedit area for XIC of window W's frame to specified
2163 pixel position X/Y. X and Y are relative to window W. */
2166 xic_set_preeditarea (w
, x
, y
)
2170 struct frame
*f
= XFRAME (w
->frame
);
2174 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
) + WINDOW_LEFT_FRINGE_WIDTH (w
);
2175 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
2176 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
2177 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2182 /* Place status area for XIC in bottom right corner of frame F.. */
2185 xic_set_statusarea (f
)
2188 XIC xic
= FRAME_XIC (f
);
2193 /* Negotiate geometry of status area. If input method has existing
2194 status area, use its current size. */
2195 area
.x
= area
.y
= area
.width
= area
.height
= 0;
2196 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
2197 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2200 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
2201 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2204 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
2206 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
2207 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2211 area
.width
= needed
->width
;
2212 area
.height
= needed
->height
;
2213 area
.x
= FRAME_PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
2214 area
.y
= (FRAME_PIXEL_HEIGHT (f
) - area
.height
2215 - FRAME_MENUBAR_HEIGHT (f
)
2216 - FRAME_TOOLBAR_HEIGHT (f
)
2217 - FRAME_INTERNAL_BORDER_WIDTH (f
));
2220 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
2221 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2226 /* Set X fontset for XIC of frame F, using base font name
2227 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2230 xic_set_xfontset (f
, base_fontname
)
2232 char *base_fontname
;
2237 xfs
= xic_create_xfontset (f
, base_fontname
);
2239 attr
= XVaCreateNestedList (0, XNFontSet
, xfs
, NULL
);
2240 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
2241 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2242 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
2243 XSetICValues (FRAME_XIC (f
), XNStatusAttributes
, attr
, NULL
);
2246 if (FRAME_XIC_FONTSET (f
))
2247 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
2248 FRAME_XIC_FONTSET (f
) = xfs
;
2251 #endif /* HAVE_X_I18N */
2255 #ifdef USE_X_TOOLKIT
2257 /* Create and set up the X widget for frame F. */
2260 x_window (f
, window_prompting
, minibuffer_only
)
2262 long window_prompting
;
2263 int minibuffer_only
;
2265 XClassHint class_hints
;
2266 XSetWindowAttributes attributes
;
2267 unsigned long attribute_mask
;
2268 Widget shell_widget
;
2270 Widget frame_widget
;
2276 /* Use the resource name as the top-level widget name
2277 for looking up resources. Make a non-Lisp copy
2278 for the window manager, so GC relocation won't bother it.
2280 Elsewhere we specify the window name for the window manager. */
2283 char *str
= (char *) SDATA (Vx_resource_name
);
2284 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
2285 strcpy (f
->namebuf
, str
);
2289 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2290 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2291 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2292 XtSetArg (al
[ac
], XtNborderWidth
, f
->border_width
); ac
++;
2293 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2294 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2295 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2296 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2297 applicationShellWidgetClass
,
2298 FRAME_X_DISPLAY (f
), al
, ac
);
2300 f
->output_data
.x
->widget
= shell_widget
;
2301 /* maybe_set_screen_title_format (shell_widget); */
2303 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2304 (widget_value
*) NULL
,
2305 shell_widget
, False
,
2309 (lw_callback
) NULL
);
2312 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2313 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2314 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2315 XtSetValues (pane_widget
, al
, ac
);
2316 f
->output_data
.x
->column_widget
= pane_widget
;
2318 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2319 the emacs screen when changing menubar. This reduces flickering. */
2322 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2323 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2324 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2325 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2326 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2327 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2328 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2329 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2330 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
2333 f
->output_data
.x
->edit_widget
= frame_widget
;
2335 XtManageChild (frame_widget
);
2337 /* Do some needed geometry management. */
2340 char *tem
, shell_position
[32];
2343 int extra_borders
= 0;
2345 = (f
->output_data
.x
->menubar_widget
2346 ? (f
->output_data
.x
->menubar_widget
->core
.height
2347 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
2350 #if 0 /* Experimentally, we now get the right results
2351 for -geometry -0-0 without this. 24 Aug 96, rms. */
2352 if (FRAME_EXTERNAL_MENU_BAR (f
))
2355 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2356 menubar_size
+= ibw
;
2360 f
->output_data
.x
->menubar_height
= menubar_size
;
2363 /* Motif seems to need this amount added to the sizes
2364 specified for the shell widget. The Athena/Lucid widgets don't.
2365 Both conclusions reached experimentally. -- rms. */
2366 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
2367 &extra_borders
, NULL
);
2371 /* Convert our geometry parameters into a geometry string
2373 Note that we do not specify here whether the position
2374 is a user-specified or program-specified one.
2375 We pass that information later, in x_wm_set_size_hints. */
2377 int left
= f
->left_pos
;
2378 int xneg
= window_prompting
& XNegative
;
2379 int top
= f
->top_pos
;
2380 int yneg
= window_prompting
& YNegative
;
2386 if (window_prompting
& USPosition
)
2387 sprintf (shell_position
, "=%dx%d%c%d%c%d",
2388 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2389 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
2390 (xneg
? '-' : '+'), left
,
2391 (yneg
? '-' : '+'), top
);
2394 sprintf (shell_position
, "=%dx%d",
2395 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2396 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
2398 /* Setting x and y when the position is not specified in
2399 the geometry string will set program position in the WM hints.
2400 If Emacs had just one program position, we could set it in
2401 fallback resources, but since each make-frame call can specify
2402 different program positions, this is easier. */
2403 XtSetArg (al
[ac
], XtNx
, left
); ac
++;
2404 XtSetArg (al
[ac
], XtNy
, top
); ac
++;
2408 len
= strlen (shell_position
) + 1;
2409 /* We don't free this because we don't know whether
2410 it is safe to free it while the frame exists.
2411 It isn't worth the trouble of arranging to free it
2412 when the frame is deleted. */
2413 tem
= (char *) xmalloc (len
);
2414 strncpy (tem
, shell_position
, len
);
2415 XtSetArg (al
[ac
], XtNgeometry
, tem
); ac
++;
2416 XtSetValues (shell_widget
, al
, ac
);
2419 XtManageChild (pane_widget
);
2420 XtRealizeWidget (shell_widget
);
2422 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2424 validate_x_resource_name ();
2426 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
2427 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
2428 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2431 FRAME_XIC (f
) = NULL
;
2433 create_frame_xic (f
);
2436 f
->output_data
.x
->wm_hints
.input
= True
;
2437 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2438 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2439 &f
->output_data
.x
->wm_hints
);
2441 hack_wm_protocols (f
, shell_widget
);
2444 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2447 /* Do a stupid property change to force the server to generate a
2448 PropertyNotify event so that the event_stream server timestamp will
2449 be initialized to something relevant to the time we created the window.
2451 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2452 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2453 XA_ATOM
, 32, PropModeAppend
,
2454 (unsigned char*) NULL
, 0);
2456 /* Make all the standard events reach the Emacs frame. */
2457 attributes
.event_mask
= STANDARD_EVENT_SET
;
2462 /* XIM server might require some X events. */
2463 unsigned long fevent
= NoEventMask
;
2464 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2465 attributes
.event_mask
|= fevent
;
2467 #endif /* HAVE_X_I18N */
2469 attribute_mask
= CWEventMask
;
2470 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2471 attribute_mask
, &attributes
);
2473 XtMapWidget (frame_widget
);
2475 /* x_set_name normally ignores requests to set the name if the
2476 requested name is the same as the current name. This is the one
2477 place where that assumption isn't correct; f->name is set, but
2478 the X server hasn't been told. */
2481 int explicit = f
->explicit_name
;
2483 f
->explicit_name
= 0;
2486 x_set_name (f
, name
, explicit);
2489 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2490 f
->output_data
.x
->text_cursor
);
2494 /* This is a no-op, except under Motif. Make sure main areas are
2495 set to something reasonable, in case we get an error later. */
2496 lw_set_main_areas (pane_widget
, 0, frame_widget
);
2499 #else /* not USE_X_TOOLKIT */
2505 if (! xg_create_frame_widgets (f
))
2506 error ("Unable to create window");
2509 FRAME_XIC (f
) = NULL
;
2513 create_frame_xic (f
);
2516 /* XIM server might require some X events. */
2517 unsigned long fevent
= NoEventMask
;
2518 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2520 if (fevent
!= NoEventMask
)
2522 XSetWindowAttributes attributes
;
2523 XWindowAttributes wattr
;
2524 unsigned long attribute_mask
;
2526 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2528 attributes
.event_mask
= wattr
.your_event_mask
| fevent
;
2529 attribute_mask
= CWEventMask
;
2530 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2531 attribute_mask
, &attributes
);
2539 #else /*! USE_GTK */
2540 /* Create and set up the X window for frame F. */
2547 XClassHint class_hints
;
2548 XSetWindowAttributes attributes
;
2549 unsigned long attribute_mask
;
2551 attributes
.background_pixel
= f
->output_data
.x
->background_pixel
;
2552 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
2553 attributes
.bit_gravity
= StaticGravity
;
2554 attributes
.backing_store
= NotUseful
;
2555 attributes
.save_under
= True
;
2556 attributes
.event_mask
= STANDARD_EVENT_SET
;
2557 attributes
.colormap
= FRAME_X_COLORMAP (f
);
2558 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
2563 = XCreateWindow (FRAME_X_DISPLAY (f
),
2564 f
->output_data
.x
->parent_desc
,
2567 FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
),
2569 CopyFromParent
, /* depth */
2570 InputOutput
, /* class */
2572 attribute_mask
, &attributes
);
2577 create_frame_xic (f
);
2580 /* XIM server might require some X events. */
2581 unsigned long fevent
= NoEventMask
;
2582 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2583 attributes
.event_mask
|= fevent
;
2584 attribute_mask
= CWEventMask
;
2585 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2586 attribute_mask
, &attributes
);
2589 #endif /* HAVE_X_I18N */
2591 validate_x_resource_name ();
2593 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
2594 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
2595 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2597 /* The menubar is part of the ordinary display;
2598 it does not count in addition to the height of the window. */
2599 f
->output_data
.x
->menubar_height
= 0;
2601 /* This indicates that we use the "Passive Input" input model.
2602 Unless we do this, we don't get the Focus{In,Out} events that we
2603 need to draw the cursor correctly. Accursed bureaucrats.
2604 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2606 f
->output_data
.x
->wm_hints
.input
= True
;
2607 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2608 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2609 &f
->output_data
.x
->wm_hints
);
2610 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
2612 /* Request "save yourself" and "delete window" commands from wm. */
2615 protocols
[0] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2616 protocols
[1] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2617 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2620 /* x_set_name normally ignores requests to set the name if the
2621 requested name is the same as the current name. This is the one
2622 place where that assumption isn't correct; f->name is set, but
2623 the X server hasn't been told. */
2626 int explicit = f
->explicit_name
;
2628 f
->explicit_name
= 0;
2631 x_set_name (f
, name
, explicit);
2634 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2635 f
->output_data
.x
->text_cursor
);
2639 if (FRAME_X_WINDOW (f
) == 0)
2640 error ("Unable to create window");
2643 #endif /* not USE_GTK */
2644 #endif /* not USE_X_TOOLKIT */
2646 /* Handle the icon stuff for this window. Perhaps later we might
2647 want an x_set_icon_position which can be called interactively as
2655 Lisp_Object icon_x
, icon_y
;
2656 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2658 /* Set the position of the icon. Note that twm groups all
2659 icons in an icon window. */
2660 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2661 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2662 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2664 CHECK_NUMBER (icon_x
);
2665 CHECK_NUMBER (icon_y
);
2667 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2668 error ("Both left and top icon corners of icon must be specified");
2672 if (! EQ (icon_x
, Qunbound
))
2673 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2675 /* Start up iconic or window? */
2676 x_wm_set_window_state
2677 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
2682 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
2689 /* Make the GCs needed for this window, setting the
2690 background, border and mouse colors; also create the
2691 mouse cursor and the gray border tile. */
2693 static char cursor_bits
[] =
2695 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2696 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2697 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2698 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2705 XGCValues gc_values
;
2709 /* Create the GCs of this frame.
2710 Note that many default values are used. */
2713 gc_values
.font
= FRAME_FONT (f
)->fid
;
2714 gc_values
.foreground
= f
->output_data
.x
->foreground_pixel
;
2715 gc_values
.background
= f
->output_data
.x
->background_pixel
;
2716 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2717 f
->output_data
.x
->normal_gc
2718 = XCreateGC (FRAME_X_DISPLAY (f
),
2720 GCLineWidth
| GCFont
| GCForeground
| GCBackground
,
2723 /* Reverse video style. */
2724 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
2725 gc_values
.background
= f
->output_data
.x
->foreground_pixel
;
2726 f
->output_data
.x
->reverse_gc
2727 = XCreateGC (FRAME_X_DISPLAY (f
),
2729 GCFont
| GCForeground
| GCBackground
| GCLineWidth
,
2732 /* Cursor has cursor-color background, background-color foreground. */
2733 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
2734 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
2735 gc_values
.fill_style
= FillOpaqueStippled
;
2737 = XCreateBitmapFromData (FRAME_X_DISPLAY (f
),
2738 FRAME_X_DISPLAY_INFO (f
)->root_window
,
2739 cursor_bits
, 16, 16);
2740 f
->output_data
.x
->cursor_gc
2741 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2742 (GCFont
| GCForeground
| GCBackground
2743 | GCFillStyle
/* | GCStipple */ | GCLineWidth
),
2747 f
->output_data
.x
->white_relief
.gc
= 0;
2748 f
->output_data
.x
->black_relief
.gc
= 0;
2750 /* Create the gray border tile used when the pointer is not in
2751 the frame. Since this depends on the frame's pixel values,
2752 this must be done on a per-frame basis. */
2753 f
->output_data
.x
->border_tile
2754 = (XCreatePixmapFromBitmapData
2755 (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
2756 gray_bits
, gray_width
, gray_height
,
2757 f
->output_data
.x
->foreground_pixel
,
2758 f
->output_data
.x
->background_pixel
,
2759 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
2765 /* Free what was was allocated in x_make_gc. */
2771 Display
*dpy
= FRAME_X_DISPLAY (f
);
2775 if (f
->output_data
.x
->normal_gc
)
2777 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
2778 f
->output_data
.x
->normal_gc
= 0;
2781 if (f
->output_data
.x
->reverse_gc
)
2783 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
2784 f
->output_data
.x
->reverse_gc
= 0;
2787 if (f
->output_data
.x
->cursor_gc
)
2789 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
2790 f
->output_data
.x
->cursor_gc
= 0;
2793 if (f
->output_data
.x
->border_tile
)
2795 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
2796 f
->output_data
.x
->border_tile
= 0;
2803 /* Handler for signals raised during x_create_frame and
2804 x_create_top_frame. FRAME is the frame which is partially
2808 unwind_create_frame (frame
)
2811 struct frame
*f
= XFRAME (frame
);
2813 /* If frame is ``official'', nothing to do. */
2814 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
2817 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2820 x_free_frame_resources (f
);
2822 /* Check that reference counts are indeed correct. */
2823 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
2824 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
2832 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
2834 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
2835 Returns an Emacs frame object.
2836 ALIST is an alist of frame parameters.
2837 If the parameters specify that the frame should not have a minibuffer,
2838 and do not specify a specific minibuffer window to use,
2839 then `default-minibuffer-frame' must be a frame whose minibuffer can
2840 be shared by the new frame.
2842 This function is an internal primitive--use `make-frame' instead. */)
2847 Lisp_Object frame
, tem
;
2849 int minibuffer_only
= 0;
2850 long window_prompting
= 0;
2852 int count
= SPECPDL_INDEX ();
2853 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
2854 Lisp_Object display
;
2855 struct x_display_info
*dpyinfo
= NULL
;
2859 /* Use this general default value to start with
2860 until we know if this frame has a specified name. */
2861 Vx_resource_name
= Vinvocation_name
;
2863 display
= x_get_arg (dpyinfo
, parms
, Qdisplay_id
, 0, 0, RES_TYPE_NUMBER
);
2865 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
2866 if (EQ (display
, Qunbound
))
2868 dpyinfo
= check_x_display_info (display
);
2870 kb
= dpyinfo
->kboard
;
2872 kb
= &the_only_kboard
;
2875 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
2877 && ! EQ (name
, Qunbound
)
2879 error ("Invalid frame name--not a string or nil");
2882 Vx_resource_name
= name
;
2884 /* See if parent window is specified. */
2885 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
2886 if (EQ (parent
, Qunbound
))
2888 if (! NILP (parent
))
2889 CHECK_NUMBER (parent
);
2891 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
2892 /* No need to protect DISPLAY because that's not used after passing
2893 it to make_frame_without_minibuffer. */
2895 GCPRO4 (parms
, parent
, name
, frame
);
2896 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
2898 if (EQ (tem
, Qnone
) || NILP (tem
))
2899 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
2900 else if (EQ (tem
, Qonly
))
2902 f
= make_minibuffer_frame ();
2903 minibuffer_only
= 1;
2905 else if (WINDOWP (tem
))
2906 f
= make_frame_without_minibuffer (tem
, kb
, display
);
2910 XSETFRAME (frame
, f
);
2912 /* Note that X Windows does support scroll bars. */
2913 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
2915 f
->display
= dpyinfo
->frame_display
;
2916 f
->display
->reference_count
++;
2918 f
->output_method
= output_x_window
;
2919 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
2920 bzero (f
->output_data
.x
, sizeof (struct x_output
));
2921 f
->output_data
.x
->icon_bitmap
= -1;
2922 FRAME_FONTSET (f
) = -1;
2923 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
2924 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
2925 #ifdef USE_TOOLKIT_SCROLL_BARS
2926 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
2927 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
2928 #endif /* USE_TOOLKIT_SCROLL_BARS */
2929 record_unwind_protect (unwind_create_frame
, frame
);
2932 = x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
2934 if (! STRINGP (f
->icon_name
))
2935 f
->icon_name
= Qnil
;
2937 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
2939 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
2940 dpyinfo_refcount
= dpyinfo
->reference_count
;
2941 #endif /* GLYPH_DEBUG */
2943 FRAME_KBOARD (f
) = kb
;
2946 /* These colors will be set anyway later, but it's important
2947 to get the color reference counts right, so initialize them! */
2950 struct gcpro gcpro1
;
2952 /* Function x_decode_color can signal an error. Make
2953 sure to initialize color slots so that we won't try
2954 to free colors we haven't allocated. */
2955 f
->output_data
.x
->foreground_pixel
= -1;
2956 f
->output_data
.x
->background_pixel
= -1;
2957 f
->output_data
.x
->cursor_pixel
= -1;
2958 f
->output_data
.x
->cursor_foreground_pixel
= -1;
2959 f
->output_data
.x
->border_pixel
= -1;
2960 f
->output_data
.x
->mouse_pixel
= -1;
2962 black
= build_string ("black");
2964 f
->output_data
.x
->foreground_pixel
2965 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2966 f
->output_data
.x
->background_pixel
2967 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2968 f
->output_data
.x
->cursor_pixel
2969 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2970 f
->output_data
.x
->cursor_foreground_pixel
2971 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2972 f
->output_data
.x
->border_pixel
2973 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2974 f
->output_data
.x
->mouse_pixel
2975 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2979 /* Specify the parent under which to make this X window. */
2983 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
2984 f
->output_data
.x
->explicit_parent
= 1;
2988 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
2989 f
->output_data
.x
->explicit_parent
= 0;
2992 /* Set the name; the functions to which we pass f expect the name to
2994 if (EQ (name
, Qunbound
) || NILP (name
))
2996 f
->name
= build_string (dpyinfo
->x_id_name
);
2997 f
->explicit_name
= 0;
3002 f
->explicit_name
= 1;
3003 /* use the frame's title when getting resources for this frame. */
3004 specbind (Qx_resource_name
, name
);
3007 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qwindow_system
, Qx
), Qnil
));
3009 /* Extract the window parameters from the supplied values
3010 that are needed to determine window geometry. */
3014 font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
3017 /* First, try whatever font the caller has specified. */
3020 tem
= Fquery_fontset (font
, Qnil
);
3022 font
= x_new_fontset (f
, SDATA (tem
));
3024 font
= x_new_font (f
, SDATA (font
));
3027 /* Try out a font which we hope has bold and italic variations. */
3028 if (!STRINGP (font
))
3029 font
= x_new_font (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
3030 if (!STRINGP (font
))
3031 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3032 if (! STRINGP (font
))
3033 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3034 if (! STRINGP (font
))
3035 /* This was formerly the first thing tried, but it finds too many fonts
3036 and takes too long. */
3037 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
3038 /* If those didn't work, look for something which will at least work. */
3039 if (! STRINGP (font
))
3040 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
3042 if (! STRINGP (font
))
3043 font
= build_string ("fixed");
3045 x_default_parameter (f
, parms
, Qfont
, font
,
3046 "font", "Font", RES_TYPE_STRING
);
3050 /* Prevent lwlib/xlwmenu.c from crashing because of a bug
3051 whereby it fails to get any font. */
3052 xlwmenu_default_font
= FRAME_FONT (f
);
3055 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
3056 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
3058 /* This defaults to 1 in order to match xterm. We recognize either
3059 internalBorderWidth or internalBorder (which is what xterm calls
3061 if (NILP (Fassq (Qinternal_border_width
, parms
)))
3065 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
3066 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
3067 if (! EQ (value
, Qunbound
))
3068 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
3071 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
3072 "internalBorderWidth", "internalBorderWidth",
3074 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qleft
,
3075 "verticalScrollBars", "ScrollBars",
3078 /* Also do the stuff which must be set before the window exists. */
3079 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3080 "foreground", "Foreground", RES_TYPE_STRING
);
3081 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3082 "background", "Background", RES_TYPE_STRING
);
3083 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3084 "pointerColor", "Foreground", RES_TYPE_STRING
);
3085 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
3086 "cursorColor", "Foreground", RES_TYPE_STRING
);
3087 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3088 "borderColor", "BorderColor", RES_TYPE_STRING
);
3089 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3090 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3091 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3092 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3093 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3094 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3095 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3096 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3098 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3099 "scrollBarForeground",
3100 "ScrollBarForeground", 1);
3101 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3102 "scrollBarBackground",
3103 "ScrollBarBackground", 0);
3105 /* Init faces before x_default_parameter is called for scroll-bar
3106 parameters because that function calls x_set_scroll_bar_width,
3107 which calls change_frame_size, which calls Fset_window_buffer,
3108 which runs hooks, which call Fvertical_motion. At the end, we
3109 end up in init_iterator with a null face cache, which should not
3111 init_frame_faces (f
);
3113 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
3114 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
3115 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (1),
3116 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
3117 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3118 "bufferPredicate", "BufferPredicate",
3120 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3121 "title", "Title", RES_TYPE_STRING
);
3122 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3123 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3124 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3125 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3127 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3129 /* Compute the size of the X window. */
3130 window_prompting
= x_figure_window_size (f
, parms
, 1);
3132 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3133 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3135 /* Create the X widget or window. */
3136 #ifdef USE_X_TOOLKIT
3137 x_window (f
, window_prompting
, minibuffer_only
);
3145 /* Now consider the frame official. */
3146 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
3147 Vframe_list
= Fcons (frame
, Vframe_list
);
3149 /* We need to do this after creating the X window, so that the
3150 icon-creation functions can say whose icon they're describing. */
3151 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
3152 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
3154 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3155 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3156 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3157 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3158 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3159 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3160 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3161 "scrollBarWidth", "ScrollBarWidth",
3164 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
3165 Change will not be effected unless different from the current
3167 width
= FRAME_COLS (f
);
3168 height
= FRAME_LINES (f
);
3170 SET_FRAME_COLS (f
, 0);
3171 FRAME_LINES (f
) = 0;
3172 change_frame_size (f
, height
, width
, 1, 0, 0);
3174 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3175 /* Create the menu bar. */
3176 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3178 /* If this signals an error, we haven't set size hints for the
3179 frame and we didn't make it visible. */
3180 initialize_frame_menubar (f
);
3183 /* This is a no-op, except under Motif where it arranges the
3184 main window for the widgets on it. */
3185 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3186 f
->output_data
.x
->menubar_widget
,
3187 f
->output_data
.x
->edit_widget
);
3188 #endif /* not USE_GTK */
3190 #endif /* USE_X_TOOLKIT || USE_GTK */
3192 /* Tell the server what size and position, etc, we want, and how
3193 badly we want them. This should be done after we have the menu
3194 bar so that its size can be taken into account. */
3196 x_wm_set_size_hint (f
, window_prompting
, 0);
3199 /* Make the window appear on the frame and enable display, unless
3200 the caller says not to. However, with explicit parent, Emacs
3201 cannot control visibility, so don't try. */
3202 if (! f
->output_data
.x
->explicit_parent
)
3204 Lisp_Object visibility
;
3206 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3208 if (EQ (visibility
, Qunbound
))
3211 if (EQ (visibility
, Qicon
))
3212 x_iconify_frame (f
);
3213 else if (! NILP (visibility
))
3214 x_make_frame_visible (f
);
3216 /* Must have been Qnil. */
3220 /* Set the WM leader property. GTK does this itself, so this is not
3221 needed when using GTK. */
3222 if (dpyinfo
->client_leader_window
!= 0)
3225 XChangeProperty (FRAME_X_DISPLAY (f
),
3226 FRAME_OUTER_WINDOW (f
),
3227 dpyinfo
->Xatom_wm_client_leader
,
3228 XA_WINDOW
, 32, PropModeReplace
,
3229 (char *) &dpyinfo
->client_leader_window
, 1);
3235 /* Make sure windows on this frame appear in calls to next-window
3236 and similar functions. */
3237 Vwindow_list
= Qnil
;
3239 return unbind_to (count
, frame
);
3243 /* FRAME is used only to get a handle on the X display. We don't pass the
3244 display info directly because we're called from frame.c, which doesn't
3245 know about that structure. */
3248 x_get_focus_frame (frame
)
3249 struct frame
*frame
;
3251 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (frame
);
3253 if (! dpyinfo
->x_focus_frame
)
3256 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3261 /* In certain situations, when the window manager follows a
3262 click-to-focus policy, there seems to be no way around calling
3263 XSetInputFocus to give another frame the input focus .
3265 In an ideal world, XSetInputFocus should generally be avoided so
3266 that applications don't interfere with the window manager's focus
3267 policy. But I think it's okay to use when it's clearly done
3268 following a user-command. */
3270 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
3271 doc
: /* Set the input focus to FRAME.
3272 FRAME nil means use the selected frame. */)
3276 struct frame
*f
= check_x_frame (frame
);
3277 Display
*dpy
= FRAME_X_DISPLAY (f
);
3281 count
= x_catch_errors (dpy
);
3282 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3283 RevertToParent
, CurrentTime
);
3284 x_uncatch_errors (dpy
, count
);
3291 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
3292 doc
: /* Internal function called by `color-defined-p', which see. */)
3294 Lisp_Object color
, frame
;
3297 FRAME_PTR f
= check_x_frame (frame
);
3299 CHECK_STRING (color
);
3301 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
3307 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
3308 doc
: /* Internal function called by `color-values', which see. */)
3310 Lisp_Object color
, frame
;
3313 FRAME_PTR f
= check_x_frame (frame
);
3315 CHECK_STRING (color
);
3317 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
3321 rgb
[0] = make_number (foo
.red
);
3322 rgb
[1] = make_number (foo
.green
);
3323 rgb
[2] = make_number (foo
.blue
);
3324 return Flist (3, rgb
);
3330 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
3331 doc
: /* Internal function called by `display-color-p', which see. */)
3333 Lisp_Object display
;
3335 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3337 if (dpyinfo
->n_planes
<= 2)
3340 switch (dpyinfo
->visual
->class)
3353 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3355 doc
: /* Return t if the X display supports shades of gray.
3356 Note that color displays do support shades of gray.
3357 The optional argument DISPLAY specifies which display to ask about.
3358 DISPLAY should be either a frame or a display name (a string).
3359 If omitted or nil, that stands for the selected frame's display. */)
3361 Lisp_Object display
;
3363 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3365 if (dpyinfo
->n_planes
<= 1)
3368 switch (dpyinfo
->visual
->class)
3383 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3385 doc
: /* Returns the width in pixels of the X display DISPLAY.
3386 The optional argument DISPLAY specifies which display to ask about.
3387 DISPLAY should be either a frame or a display name (a string).
3388 If omitted or nil, that stands for the selected frame's display. */)
3390 Lisp_Object display
;
3392 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3394 return make_number (dpyinfo
->width
);
3397 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3398 Sx_display_pixel_height
, 0, 1, 0,
3399 doc
: /* Returns the height in pixels of the X display DISPLAY.
3400 The optional argument DISPLAY specifies which display to ask about.
3401 DISPLAY should be either a frame or a display name (a string).
3402 If omitted or nil, that stands for the selected frame's display. */)
3404 Lisp_Object display
;
3406 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3408 return make_number (dpyinfo
->height
);
3411 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3413 doc
: /* Returns the number of bitplanes of the X display DISPLAY.
3414 The optional argument DISPLAY specifies which display to ask about.
3415 DISPLAY should be either a frame or a display name (a string).
3416 If omitted or nil, that stands for the selected frame's display. */)
3418 Lisp_Object display
;
3420 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3422 return make_number (dpyinfo
->n_planes
);
3425 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3427 doc
: /* Returns the number of color cells of the X display DISPLAY.
3428 The optional argument DISPLAY specifies which display to ask about.
3429 DISPLAY should be either a frame or a display name (a string).
3430 If omitted or nil, that stands for the selected frame's display. */)
3432 Lisp_Object display
;
3434 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3436 int nr_planes
= DisplayPlanes (dpyinfo
->display
,
3437 XScreenNumberOfScreen (dpyinfo
->screen
));
3439 /* Truncate nr_planes to 24 to avoid integer overflow.
3440 Some displays says 32, but only 24 bits are actually significant.
3441 There are only very few and rare video cards that have more than
3442 24 significant bits. Also 24 bits is more than 16 million colors,
3443 it "should be enough for everyone". */
3444 if (nr_planes
> 24) nr_planes
= 24;
3446 return make_number (1 << nr_planes
);
3449 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3450 Sx_server_max_request_size
,
3452 doc
: /* Returns the maximum request size of the X server of display DISPLAY.
3453 The optional argument DISPLAY specifies which display to ask about.
3454 DISPLAY should be either a frame or a display name (a string).
3455 If omitted or nil, that stands for the selected frame's display. */)
3457 Lisp_Object display
;
3459 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3461 return make_number (MAXREQUEST (dpyinfo
->display
));
3464 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3465 doc
: /* Returns the vendor ID string of the X server of display DISPLAY.
3466 The optional argument DISPLAY specifies which display to ask about.
3467 DISPLAY should be either a frame or a display name (a string).
3468 If omitted or nil, that stands for the selected frame's display. */)
3470 Lisp_Object display
;
3472 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3473 char *vendor
= ServerVendor (dpyinfo
->display
);
3475 if (! vendor
) vendor
= "";
3476 return build_string (vendor
);
3479 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3480 doc
: /* Returns the version numbers of the X server of display DISPLAY.
3481 The value is a list of three integers: the major and minor
3482 version numbers of the X Protocol in use, and the vendor-specific release
3483 number. See also the function `x-server-vendor'.
3485 The optional argument DISPLAY specifies which display to ask about.
3486 DISPLAY should be either a frame or a display name (a string).
3487 If omitted or nil, that stands for the selected frame's display. */)
3489 Lisp_Object display
;
3491 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3492 Display
*dpy
= dpyinfo
->display
;
3494 return Fcons (make_number (ProtocolVersion (dpy
)),
3495 Fcons (make_number (ProtocolRevision (dpy
)),
3496 Fcons (make_number (VendorRelease (dpy
)), Qnil
)));
3499 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3500 doc
: /* Return the number of screens on the X server of display DISPLAY.
3501 The optional argument DISPLAY specifies which display to ask about.
3502 DISPLAY should be either a frame or a display name (a string).
3503 If omitted or nil, that stands for the selected frame's display. */)
3505 Lisp_Object display
;
3507 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3509 return make_number (ScreenCount (dpyinfo
->display
));
3512 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3513 doc
: /* Return the height in millimeters of the X display DISPLAY.
3514 The optional argument DISPLAY specifies which display to ask about.
3515 DISPLAY should be either a frame or a display name (a string).
3516 If omitted or nil, that stands for the selected frame's display. */)
3518 Lisp_Object display
;
3520 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3522 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3525 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3526 doc
: /* Return the width in millimeters of the X display DISPLAY.
3527 The optional argument DISPLAY specifies which display to ask about.
3528 DISPLAY should be either a frame or a display name (a string).
3529 If omitted or nil, that stands for the selected frame's display. */)
3531 Lisp_Object display
;
3533 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3535 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3538 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3539 Sx_display_backing_store
, 0, 1, 0,
3540 doc
: /* Returns an indication of whether X display DISPLAY does backing store.
3541 The value may be `always', `when-mapped', or `not-useful'.
3542 The optional argument DISPLAY specifies which display to ask about.
3543 DISPLAY should be either a frame or a display name (a string).
3544 If omitted or nil, that stands for the selected frame's display. */)
3546 Lisp_Object display
;
3548 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3551 switch (DoesBackingStore (dpyinfo
->screen
))
3554 result
= intern ("always");
3558 result
= intern ("when-mapped");
3562 result
= intern ("not-useful");
3566 error ("Strange value for BackingStore parameter of screen");
3573 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3574 Sx_display_visual_class
, 0, 1, 0,
3575 doc
: /* Return the visual class of the X display DISPLAY.
3576 The value is one of the symbols `static-gray', `gray-scale',
3577 `static-color', `pseudo-color', `true-color', or `direct-color'.
3579 The optional argument DISPLAY specifies which display to ask about.
3580 DISPLAY should be either a frame or a display name (a string).
3581 If omitted or nil, that stands for the selected frame's display. */)
3583 Lisp_Object display
;
3585 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3588 switch (dpyinfo
->visual
->class)
3591 result
= intern ("static-gray");
3594 result
= intern ("gray-scale");
3597 result
= intern ("static-color");
3600 result
= intern ("pseudo-color");
3603 result
= intern ("true-color");
3606 result
= intern ("direct-color");
3609 error ("Display has an unknown visual class");
3616 DEFUN ("x-display-save-under", Fx_display_save_under
,
3617 Sx_display_save_under
, 0, 1, 0,
3618 doc
: /* Returns t if the X display DISPLAY supports the save-under feature.
3619 The optional argument DISPLAY specifies which display to ask about.
3620 DISPLAY should be either a frame or a display name (a string).
3621 If omitted or nil, that stands for the selected frame's display. */)
3623 Lisp_Object display
;
3625 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3627 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3635 register struct frame
*f
;
3637 return FRAME_PIXEL_WIDTH (f
);
3642 register struct frame
*f
;
3644 return FRAME_PIXEL_HEIGHT (f
);
3649 register struct frame
*f
;
3651 return FRAME_COLUMN_WIDTH (f
);
3656 register struct frame
*f
;
3658 return FRAME_LINE_HEIGHT (f
);
3663 register struct frame
*f
;
3665 return FRAME_X_DISPLAY_INFO (f
)->n_planes
;
3670 /************************************************************************
3672 ************************************************************************/
3675 /* Mapping visual names to visuals. */
3677 static struct visual_class
3684 {"StaticGray", StaticGray
},
3685 {"GrayScale", GrayScale
},
3686 {"StaticColor", StaticColor
},
3687 {"PseudoColor", PseudoColor
},
3688 {"TrueColor", TrueColor
},
3689 {"DirectColor", DirectColor
},
3694 #ifndef HAVE_XSCREENNUMBEROFSCREEN
3696 /* Value is the screen number of screen SCR. This is a substitute for
3697 the X function with the same name when that doesn't exist. */
3700 XScreenNumberOfScreen (scr
)
3701 register Screen
*scr
;
3703 Display
*dpy
= scr
->display
;
3706 for (i
= 0; i
< dpy
->nscreens
; ++i
)
3707 if (scr
== dpy
->screens
+ i
)
3713 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
3716 /* Select the visual that should be used on display DPYINFO. Set
3717 members of DPYINFO appropriately. Called from x_term_init. */
3720 select_visual (dpyinfo
)
3721 struct x_display_info
*dpyinfo
;
3723 Display
*dpy
= dpyinfo
->display
;
3724 Screen
*screen
= dpyinfo
->screen
;
3727 /* See if a visual is specified. */
3728 value
= display_x_get_resource (dpyinfo
,
3729 build_string ("visualClass"),
3730 build_string ("VisualClass"),
3732 if (STRINGP (value
))
3734 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
3735 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
3736 depth, a decimal number. NAME is compared with case ignored. */
3737 char *s
= (char *) alloca (SBYTES (value
) + 1);
3742 strcpy (s
, SDATA (value
));
3743 dash
= index (s
, '-');
3746 dpyinfo
->n_planes
= atoi (dash
+ 1);
3750 /* We won't find a matching visual with depth 0, so that
3751 an error will be printed below. */
3752 dpyinfo
->n_planes
= 0;
3754 /* Determine the visual class. */
3755 for (i
= 0; visual_classes
[i
].name
; ++i
)
3756 if (xstricmp (s
, visual_classes
[i
].name
) == 0)
3758 class = visual_classes
[i
].class;
3762 /* Look up a matching visual for the specified class. */
3764 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
3765 dpyinfo
->n_planes
, class, &vinfo
))
3766 fatal ("Invalid visual specification `%s'", SDATA (value
));
3768 dpyinfo
->visual
= vinfo
.visual
;
3773 XVisualInfo
*vinfo
, vinfo_template
;
3775 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
3778 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
3780 vinfo_template
.visualid
= dpyinfo
->visual
->visualid
;
3782 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
3783 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
3784 &vinfo_template
, &n_visuals
);
3786 fatal ("Can't get proper X visual info");
3788 dpyinfo
->n_planes
= vinfo
->depth
;
3789 XFree ((char *) vinfo
);
3794 /* Return the X display structure for the display named NAME.
3795 Open a new connection if necessary. */
3797 struct x_display_info
*
3798 x_display_info_for_name (name
)
3802 struct x_display_info
*dpyinfo
;
3804 CHECK_STRING (name
);
3807 if (! EQ (Vinitial_window_system
, intern ("x")))
3808 error ("Not using X Windows"); /* That doesn't stop us anymore. */
3811 for (dpyinfo
= x_display_list
, names
= x_display_name_list
;
3813 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
3816 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
3821 /* Use this general default value to start with. */
3822 Vx_resource_name
= Vinvocation_name
;
3824 validate_x_resource_name ();
3826 dpyinfo
= x_term_init (name
, (char *)0,
3827 (char *) SDATA (Vx_resource_name
));
3830 error ("Cannot connect to X server %s", SDATA (name
));
3833 XSETFASTINT (Vwindow_system_version
, 11);
3839 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
3841 doc
: /* Open a connection to an X server.
3842 DISPLAY is the name of the display to connect to.
3843 Optional second arg XRM-STRING is a string of resources in xrdb format.
3844 If the optional third arg MUST-SUCCEED is non-nil,
3845 terminate Emacs if we can't open the connection. */)
3846 (display
, xrm_string
, must_succeed
)
3847 Lisp_Object display
, xrm_string
, must_succeed
;
3849 unsigned char *xrm_option
;
3850 struct x_display_info
*dpyinfo
;
3852 CHECK_STRING (display
);
3853 if (! NILP (xrm_string
))
3854 CHECK_STRING (xrm_string
);
3857 if (! EQ (Vinitial_window_system
, intern ("x")))
3858 error ("Not using X Windows"); /* That doesn't stop us anymore. */
3861 if (! NILP (xrm_string
))
3862 xrm_option
= (unsigned char *) SDATA (xrm_string
);
3864 xrm_option
= (unsigned char *) 0;
3866 validate_x_resource_name ();
3868 /* This is what opens the connection and sets x_current_display.
3869 This also initializes many symbols, such as those used for input. */
3870 dpyinfo
= x_term_init (display
, xrm_option
,
3871 (char *) SDATA (Vx_resource_name
));
3875 if (!NILP (must_succeed
))
3876 fatal ("Cannot connect to X server %s.\n\
3877 Check the DISPLAY environment variable or use `-d'.\n\
3878 Also use the `xauth' program to verify that you have the proper\n\
3879 authorization information needed to connect the X server.\n\
3880 An insecure way to solve the problem may be to use `xhost'.\n",
3883 error ("Cannot connect to X server %s", SDATA (display
));
3888 XSETFASTINT (Vwindow_system_version
, 11);
3892 DEFUN ("x-close-connection", Fx_close_connection
,
3893 Sx_close_connection
, 1, 1, 0,
3894 doc
: /* Close the connection to DISPLAY's X server.
3895 For DISPLAY, specify either a frame or a display name (a string).
3896 If DISPLAY is nil, that stands for the selected frame's display. */)
3898 Lisp_Object display
;
3900 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3903 if (dpyinfo
->reference_count
> 0)
3904 error ("Display still has frames on it");
3907 /* Free the fonts in the font table. */
3908 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
3909 if (dpyinfo
->font_table
[i
].name
)
3911 XFreeFont (dpyinfo
->display
, dpyinfo
->font_table
[i
].font
);
3914 x_destroy_all_bitmaps (dpyinfo
);
3915 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
3917 #ifdef USE_X_TOOLKIT
3918 XtCloseDisplay (dpyinfo
->display
);
3920 XCloseDisplay (dpyinfo
->display
);
3923 x_delete_display (dpyinfo
);
3929 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
3930 doc
: /* Return the list of display names that Emacs has connections to. */)
3933 Lisp_Object tail
, result
;
3936 for (tail
= x_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
3937 result
= Fcons (XCAR (XCAR (tail
)), result
);
3942 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
3943 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
3944 If ON is nil, allow buffering of requests.
3945 Turning on synchronization prohibits the Xlib routines from buffering
3946 requests and seriously degrades performance, but makes debugging much
3948 The optional second argument DISPLAY specifies which display to act on.
3949 DISPLAY should be either a frame or a display name (a string).
3950 If DISPLAY is omitted or nil, that stands for the selected frame's display. */)
3952 Lisp_Object display
, on
;
3954 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3956 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
3961 /* Wait for responses to all X commands issued so far for frame F. */
3968 XSync (FRAME_X_DISPLAY (f
), False
);
3973 /***********************************************************************
3975 ***********************************************************************/
3977 DEFUN ("x-change-window-property", Fx_change_window_property
,
3978 Sx_change_window_property
, 2, 6, 0,
3979 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
3980 PROP must be a string.
3981 VALUE may be a string or a list of conses, numbers and/or strings.
3982 If an element in the list is a string, it is converted to
3983 an Atom and the value of the Atom is used. If an element is a cons,
3984 it is converted to a 32 bit number where the car is the 16 top bits and the
3985 cdr is the lower 16 bits.
3986 FRAME nil or omitted means use the selected frame.
3987 If TYPE is given and non-nil, it is the name of the type of VALUE.
3988 If TYPE is not given or nil, the type is STRING.
3989 FORMAT gives the size in bits of each element if VALUE is a list.
3990 It must be one of 8, 16 or 32.
3991 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
3992 If OUTER_P is non-nil, the property is changed for the outer X window of
3993 FRAME. Default is to change on the edit X window.
3996 (prop
, value
, frame
, type
, format
, outer_p
)
3997 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
3999 struct frame
*f
= check_x_frame (frame
);
4001 Atom target_type
= XA_STRING
;
4002 int element_format
= 8;
4003 unsigned char *data
;
4007 CHECK_STRING (prop
);
4009 if (! NILP (format
))
4011 CHECK_NUMBER (format
);
4012 element_format
= XFASTINT (format
);
4014 if (element_format
!= 8 && element_format
!= 16
4015 && element_format
!= 32)
4016 error ("FORMAT must be one of 8, 16 or 32");
4021 nelements
= x_check_property_data (value
);
4022 if (nelements
== -1)
4023 error ("Bad data in VALUE, must be number, string or cons");
4025 if (element_format
== 8)
4026 data
= (unsigned char *) xmalloc (nelements
);
4027 else if (element_format
== 16)
4028 data
= (unsigned char *) xmalloc (nelements
*2);
4030 data
= (unsigned char *) xmalloc (nelements
*4);
4032 x_fill_property_data (FRAME_X_DISPLAY (f
), value
, data
, element_format
);
4036 CHECK_STRING (value
);
4037 data
= SDATA (value
);
4038 nelements
= SCHARS (value
);
4042 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4045 CHECK_STRING (type
);
4046 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (type
), False
);
4049 if (! NILP (outer_p
)) w
= FRAME_OUTER_WINDOW (f
);
4050 else w
= FRAME_X_WINDOW (f
);
4052 XChangeProperty (FRAME_X_DISPLAY (f
), w
,
4053 prop_atom
, target_type
, element_format
, PropModeReplace
,
4056 if (CONSP (value
)) xfree (data
);
4058 /* Make sure the property is set when we return. */
4059 XFlush (FRAME_X_DISPLAY (f
));
4066 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
4067 Sx_delete_window_property
, 1, 2, 0,
4068 doc
: /* Remove window property PROP from X window of FRAME.
4069 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4071 Lisp_Object prop
, frame
;
4073 struct frame
*f
= check_x_frame (frame
);
4076 CHECK_STRING (prop
);
4078 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4079 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
4081 /* Make sure the property is removed when we return. */
4082 XFlush (FRAME_X_DISPLAY (f
));
4089 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
4091 doc
: /* Value is the value of window property PROP on FRAME.
4092 If FRAME is nil or omitted, use the selected frame.
4093 If TYPE is nil or omitted, get the property as a string. Otherwise TYPE
4094 is the name of the Atom that denotes the type expected.
4095 If SOURCE is non-nil, get the property on that window instead of from
4096 FRAME. The number 0 denotes the root window.
4097 If DELETE_P is non-nil, delete the property after retreiving it.
4098 If VECTOR_RET_P is non-nil, don't return a string but a vector of values.
4100 Value is nil if FRAME hasn't a property with name PROP or if PROP has
4101 no value of TYPE. */)
4102 (prop
, frame
, type
, source
, delete_p
, vector_ret_p
)
4103 Lisp_Object prop
, frame
, type
, source
, delete_p
, vector_ret_p
;
4105 struct frame
*f
= check_x_frame (frame
);
4108 Lisp_Object prop_value
= Qnil
;
4109 char *tmp_data
= NULL
;
4111 Atom target_type
= XA_STRING
;
4113 unsigned long actual_size
, bytes_remaining
;
4114 Window target_window
= FRAME_X_WINDOW (f
);
4115 struct gcpro gcpro1
;
4117 GCPRO1 (prop_value
);
4118 CHECK_STRING (prop
);
4120 if (! NILP (source
))
4122 if (NUMBERP (source
))
4124 if (FLOATP (source
))
4125 target_window
= (Window
) XFLOAT (source
);
4127 target_window
= XFASTINT (source
);
4129 if (target_window
== 0)
4130 target_window
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4132 else if (CONSP (source
))
4133 target_window
= cons_to_long (source
);
4139 if (strcmp ("AnyPropertyType", SDATA (type
)) == 0)
4140 target_type
= AnyPropertyType
;
4142 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (type
), False
);
4145 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4146 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4147 prop_atom
, 0, 0, False
, target_type
,
4148 &actual_type
, &actual_format
, &actual_size
,
4149 &bytes_remaining
, (unsigned char **) &tmp_data
);
4152 int size
= bytes_remaining
;
4157 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4158 prop_atom
, 0, bytes_remaining
,
4159 ! NILP (delete_p
), target_type
,
4160 &actual_type
, &actual_format
,
4161 &actual_size
, &bytes_remaining
,
4162 (unsigned char **) &tmp_data
);
4163 if (rc
== Success
&& tmp_data
)
4165 if (NILP (vector_ret_p
))
4166 prop_value
= make_string (tmp_data
, size
);
4168 prop_value
= x_property_data_to_lisp (f
,
4169 (unsigned char *) tmp_data
,
4175 if (tmp_data
) XFree (tmp_data
);
4185 /***********************************************************************
4187 ***********************************************************************/
4189 /* If non-null, an asynchronous timer that, when it expires, displays
4190 an hourglass cursor on all frames. */
4192 static struct atimer
*hourglass_atimer
;
4194 /* Non-zero means an hourglass cursor is currently shown. */
4196 static int hourglass_shown_p
;
4198 /* Number of seconds to wait before displaying an hourglass cursor. */
4200 static Lisp_Object Vhourglass_delay
;
4202 /* Default number of seconds to wait before displaying an hourglass
4205 #define DEFAULT_HOURGLASS_DELAY 1
4207 /* Function prototypes. */
4209 static void show_hourglass
P_ ((struct atimer
*));
4210 static void hide_hourglass
P_ ((void));
4213 /* Cancel a currently active hourglass timer, and start a new one. */
4219 int secs
, usecs
= 0;
4221 cancel_hourglass ();
4223 if (INTEGERP (Vhourglass_delay
)
4224 && XINT (Vhourglass_delay
) > 0)
4225 secs
= XFASTINT (Vhourglass_delay
);
4226 else if (FLOATP (Vhourglass_delay
)
4227 && XFLOAT_DATA (Vhourglass_delay
) > 0)
4230 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
4231 secs
= XFASTINT (tem
);
4232 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
4235 secs
= DEFAULT_HOURGLASS_DELAY
;
4237 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
4238 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
4239 show_hourglass
, NULL
);
4243 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
4249 if (hourglass_atimer
)
4251 cancel_atimer (hourglass_atimer
);
4252 hourglass_atimer
= NULL
;
4255 if (hourglass_shown_p
)
4260 /* Timer function of hourglass_atimer. TIMER is equal to
4263 Display an hourglass pointer on all frames by mapping the frames'
4264 hourglass_window. Set the hourglass_p flag in the frames'
4265 output_data.x structure to indicate that an hourglass cursor is
4266 shown on the frames. */
4269 show_hourglass (timer
)
4270 struct atimer
*timer
;
4272 /* The timer implementation will cancel this timer automatically
4273 after this function has run. Set hourglass_atimer to null
4274 so that we know the timer doesn't have to be canceled. */
4275 hourglass_atimer
= NULL
;
4277 if (!hourglass_shown_p
)
4279 Lisp_Object rest
, frame
;
4283 FOR_EACH_FRAME (rest
, frame
)
4285 struct frame
*f
= XFRAME (frame
);
4287 if (FRAME_LIVE_P (f
) && FRAME_X_P (f
) && FRAME_X_DISPLAY (f
))
4289 Display
*dpy
= FRAME_X_DISPLAY (f
);
4291 #ifdef USE_X_TOOLKIT
4292 if (f
->output_data
.x
->widget
)
4294 if (FRAME_OUTER_WINDOW (f
))
4297 f
->output_data
.x
->hourglass_p
= 1;
4299 if (!f
->output_data
.x
->hourglass_window
)
4301 unsigned long mask
= CWCursor
;
4302 XSetWindowAttributes attrs
;
4304 attrs
.cursor
= f
->output_data
.x
->hourglass_cursor
;
4306 f
->output_data
.x
->hourglass_window
4307 = XCreateWindow (dpy
, FRAME_OUTER_WINDOW (f
),
4308 0, 0, 32000, 32000, 0, 0,
4314 XMapRaised (dpy
, f
->output_data
.x
->hourglass_window
);
4320 hourglass_shown_p
= 1;
4326 /* Hide the hourglass pointer on all frames, if it is currently
4332 if (hourglass_shown_p
)
4334 Lisp_Object rest
, frame
;
4337 FOR_EACH_FRAME (rest
, frame
)
4339 struct frame
*f
= XFRAME (frame
);
4342 /* Watch out for newly created frames. */
4343 && f
->output_data
.x
->hourglass_window
)
4345 XUnmapWindow (FRAME_X_DISPLAY (f
),
4346 f
->output_data
.x
->hourglass_window
);
4347 /* Sync here because XTread_socket looks at the
4348 hourglass_p flag that is reset to zero below. */
4349 XSync (FRAME_X_DISPLAY (f
), False
);
4350 f
->output_data
.x
->hourglass_p
= 0;
4354 hourglass_shown_p
= 0;
4361 /***********************************************************************
4363 ***********************************************************************/
4365 static Lisp_Object x_create_tip_frame
P_ ((struct x_display_info
*,
4366 Lisp_Object
, Lisp_Object
));
4367 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
4368 Lisp_Object
, int, int, int *, int *));
4370 /* The frame of a currently visible tooltip. */
4372 Lisp_Object tip_frame
;
4374 /* If non-nil, a timer started that hides the last tooltip when it
4377 Lisp_Object tip_timer
;
4380 /* If non-nil, a vector of 3 elements containing the last args
4381 with which x-show-tip was called. See there. */
4383 Lisp_Object last_show_tip_args
;
4385 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
4387 Lisp_Object Vx_max_tooltip_size
;
4391 unwind_create_tip_frame (frame
)
4394 Lisp_Object deleted
;
4396 deleted
= unwind_create_frame (frame
);
4397 if (EQ (deleted
, Qt
))
4407 /* Create a frame for a tooltip on the display described by DPYINFO.
4408 PARMS is a list of frame parameters. TEXT is the string to
4409 display in the tip frame. Value is the frame.
4411 Note that functions called here, esp. x_default_parameter can
4412 signal errors, for instance when a specified color name is
4413 undefined. We have to make sure that we're in a consistent state
4414 when this happens. */
4417 x_create_tip_frame (dpyinfo
, parms
, text
)
4418 struct x_display_info
*dpyinfo
;
4419 Lisp_Object parms
, text
;
4422 Lisp_Object frame
, tem
;
4424 long window_prompting
= 0;
4426 int count
= SPECPDL_INDEX ();
4427 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4429 int face_change_count_before
= face_change_count
;
4431 struct buffer
*old_buffer
;
4435 /* Use this general default value to start with until we know if
4436 this frame has a specified name. */
4437 Vx_resource_name
= Vinvocation_name
;
4440 kb
= dpyinfo
->kboard
;
4442 kb
= &the_only_kboard
;
4445 /* Get the name of the frame to use for resource lookup. */
4446 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
4448 && !EQ (name
, Qunbound
)
4450 error ("Invalid frame name--not a string or nil");
4451 Vx_resource_name
= name
;
4454 GCPRO3 (parms
, name
, frame
);
4456 XSETFRAME (frame
, f
);
4458 buffer
= Fget_buffer_create (build_string (" *tip*"));
4459 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
4460 old_buffer
= current_buffer
;
4461 set_buffer_internal_1 (XBUFFER (buffer
));
4462 current_buffer
->truncate_lines
= Qnil
;
4463 specbind (Qinhibit_read_only
, Qt
);
4464 specbind (Qinhibit_modification_hooks
, Qt
);
4467 set_buffer_internal_1 (old_buffer
);
4469 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
4470 record_unwind_protect (unwind_create_tip_frame
, frame
);
4472 f
->display
= dpyinfo
->frame_display
;
4473 f
->display
->reference_count
++;
4475 /* By setting the output method, we're essentially saying that
4476 the frame is live, as per FRAME_LIVE_P. If we get a signal
4477 from this point on, x_destroy_window might screw up reference
4479 f
->output_method
= output_x_window
;
4480 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
4481 bzero (f
->output_data
.x
, sizeof (struct x_output
));
4482 f
->output_data
.x
->icon_bitmap
= -1;
4483 FRAME_FONTSET (f
) = -1;
4484 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
4485 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
4486 #ifdef USE_TOOLKIT_SCROLL_BARS
4487 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
4488 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
4489 #endif /* USE_TOOLKIT_SCROLL_BARS */
4490 f
->icon_name
= Qnil
;
4491 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
4493 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
4494 dpyinfo_refcount
= dpyinfo
->reference_count
;
4495 #endif /* GLYPH_DEBUG */
4497 FRAME_KBOARD (f
) = kb
;
4499 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4500 f
->output_data
.x
->explicit_parent
= 0;
4502 /* These colors will be set anyway later, but it's important
4503 to get the color reference counts right, so initialize them! */
4506 struct gcpro gcpro1
;
4508 black
= build_string ("black");
4510 f
->output_data
.x
->foreground_pixel
4511 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4512 f
->output_data
.x
->background_pixel
4513 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4514 f
->output_data
.x
->cursor_pixel
4515 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4516 f
->output_data
.x
->cursor_foreground_pixel
4517 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4518 f
->output_data
.x
->border_pixel
4519 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4520 f
->output_data
.x
->mouse_pixel
4521 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4525 /* Set the name; the functions to which we pass f expect the name to
4527 if (EQ (name
, Qunbound
) || NILP (name
))
4529 f
->name
= build_string (dpyinfo
->x_id_name
);
4530 f
->explicit_name
= 0;
4535 f
->explicit_name
= 1;
4536 /* use the frame's title when getting resources for this frame. */
4537 specbind (Qx_resource_name
, name
);
4540 /* Extract the window parameters from the supplied values that are
4541 needed to determine window geometry. */
4545 font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4548 /* First, try whatever font the caller has specified. */
4551 tem
= Fquery_fontset (font
, Qnil
);
4553 font
= x_new_fontset (f
, SDATA (tem
));
4555 font
= x_new_font (f
, SDATA (font
));
4558 /* Try out a font which we hope has bold and italic variations. */
4559 if (!STRINGP (font
))
4560 font
= x_new_font (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
4561 if (!STRINGP (font
))
4562 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
4563 if (! STRINGP (font
))
4564 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
4565 if (! STRINGP (font
))
4566 /* This was formerly the first thing tried, but it finds too many fonts
4567 and takes too long. */
4568 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
4569 /* If those didn't work, look for something which will at least work. */
4570 if (! STRINGP (font
))
4571 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
4573 if (! STRINGP (font
))
4574 font
= build_string ("fixed");
4576 x_default_parameter (f
, parms
, Qfont
, font
,
4577 "font", "Font", RES_TYPE_STRING
);
4580 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
4581 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4583 /* This defaults to 2 in order to match xterm. We recognize either
4584 internalBorderWidth or internalBorder (which is what xterm calls
4586 if (NILP (Fassq (Qinternal_border_width
, parms
)))
4590 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
4591 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
4592 if (! EQ (value
, Qunbound
))
4593 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
4597 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
4598 "internalBorderWidth", "internalBorderWidth",
4601 /* Also do the stuff which must be set before the window exists. */
4602 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
4603 "foreground", "Foreground", RES_TYPE_STRING
);
4604 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
4605 "background", "Background", RES_TYPE_STRING
);
4606 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
4607 "pointerColor", "Foreground", RES_TYPE_STRING
);
4608 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
4609 "cursorColor", "Foreground", RES_TYPE_STRING
);
4610 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
4611 "borderColor", "BorderColor", RES_TYPE_STRING
);
4613 /* Init faces before x_default_parameter is called for scroll-bar
4614 parameters because that function calls x_set_scroll_bar_width,
4615 which calls change_frame_size, which calls Fset_window_buffer,
4616 which runs hooks, which call Fvertical_motion. At the end, we
4617 end up in init_iterator with a null face cache, which should not
4619 init_frame_faces (f
);
4621 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4623 window_prompting
= x_figure_window_size (f
, parms
, 0);
4626 XSetWindowAttributes attrs
;
4630 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
;
4631 if (DoesSaveUnders (dpyinfo
->screen
))
4632 mask
|= CWSaveUnder
;
4634 /* Window managers look at the override-redirect flag to determine
4635 whether or net to give windows a decoration (Xlib spec, chapter
4637 attrs
.override_redirect
= True
;
4638 attrs
.save_under
= True
;
4639 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
4640 /* Arrange for getting MapNotify and UnmapNotify events. */
4641 attrs
.event_mask
= StructureNotifyMask
;
4643 = FRAME_X_WINDOW (f
)
4644 = XCreateWindow (FRAME_X_DISPLAY (f
),
4645 FRAME_X_DISPLAY_INFO (f
)->root_window
,
4646 /* x, y, width, height */
4650 CopyFromParent
, InputOutput
, CopyFromParent
,
4657 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
4658 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4659 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
4660 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4661 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
4662 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4664 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4665 Change will not be effected unless different from the current
4667 width
= FRAME_COLS (f
);
4668 height
= FRAME_LINES (f
);
4669 SET_FRAME_COLS (f
, 0);
4670 FRAME_LINES (f
) = 0;
4671 change_frame_size (f
, height
, width
, 1, 0, 0);
4673 /* Add `tooltip' frame parameter's default value. */
4674 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
4675 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
4678 /* Set up faces after all frame parameters are known. This call
4679 also merges in face attributes specified for new frames.
4681 Frame parameters may be changed if .Xdefaults contains
4682 specifications for the default font. For example, if there is an
4683 `Emacs.default.attributeBackground: pink', the `background-color'
4684 attribute of the frame get's set, which let's the internal border
4685 of the tooltip frame appear in pink. Prevent this. */
4687 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
4689 /* Set tip_frame here, so that */
4691 call1 (Qface_set_after_frame_default
, frame
);
4693 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
4694 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
4698 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qwindow_system
, Qx
), Qnil
));
4704 /* It is now ok to make the frame official even if we get an error
4705 below. And the frame needs to be on Vframe_list or making it
4706 visible won't work. */
4707 Vframe_list
= Fcons (frame
, Vframe_list
);
4709 /* Now that the frame is official, it counts as a reference to
4711 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
4713 /* Setting attributes of faces of the tooltip frame from resources
4714 and similar will increment face_change_count, which leads to the
4715 clearing of all current matrices. Since this isn't necessary
4716 here, avoid it by resetting face_change_count to the value it
4717 had before we created the tip frame. */
4718 face_change_count
= face_change_count_before
;
4720 /* Discard the unwind_protect. */
4721 return unbind_to (count
, frame
);
4725 /* Compute where to display tip frame F. PARMS is the list of frame
4726 parameters for F. DX and DY are specified offsets from the current
4727 location of the mouse. WIDTH and HEIGHT are the width and height
4728 of the tooltip. Return coordinates relative to the root window of
4729 the display in *ROOT_X, and *ROOT_Y. */
4732 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
4734 Lisp_Object parms
, dx
, dy
;
4736 int *root_x
, *root_y
;
4738 Lisp_Object left
, top
;
4743 /* User-specified position? */
4744 left
= Fcdr (Fassq (Qleft
, parms
));
4745 top
= Fcdr (Fassq (Qtop
, parms
));
4747 /* Move the tooltip window where the mouse pointer is. Resize and
4749 if (!INTEGERP (left
) || !INTEGERP (top
))
4752 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
4753 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
4758 *root_y
= XINT (top
);
4759 else if (*root_y
+ XINT (dy
) - height
< 0)
4760 *root_y
-= XINT (dy
);
4764 *root_y
+= XINT (dy
);
4767 if (INTEGERP (left
))
4768 *root_x
= XINT (left
);
4769 else if (*root_x
+ XINT (dx
) + width
<= FRAME_X_DISPLAY_INFO (f
)->width
)
4770 /* It fits to the right of the pointer. */
4771 *root_x
+= XINT (dx
);
4772 else if (width
+ XINT (dx
) <= *root_x
)
4773 /* It fits to the left of the pointer. */
4774 *root_x
-= width
+ XINT (dx
);
4776 /* Put it left-justified on the screen--it ought to fit that way. */
4781 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
4782 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
4783 A tooltip window is a small X window displaying a string.
4785 FRAME nil or omitted means use the selected frame.
4787 PARMS is an optional list of frame parameters which can be used to
4788 change the tooltip's appearance.
4790 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
4791 means use the default timeout of 5 seconds.
4793 If the list of frame parameters PARAMS contains a `left' parameters,
4794 the tooltip is displayed at that x-position. Otherwise it is
4795 displayed at the mouse position, with offset DX added (default is 5 if
4796 DX isn't specified). Likewise for the y-position; if a `top' frame
4797 parameter is specified, it determines the y-position of the tooltip
4798 window, otherwise it is displayed at the mouse position, with offset
4799 DY added (default is -10).
4801 A tooltip's maximum size is specified by `x-max-tooltip-size'.
4802 Text larger than the specified size is clipped. */)
4803 (string
, frame
, parms
, timeout
, dx
, dy
)
4804 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
4809 struct buffer
*old_buffer
;
4810 struct text_pos pos
;
4811 int i
, width
, height
;
4812 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4813 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
4814 int count
= SPECPDL_INDEX ();
4816 specbind (Qinhibit_redisplay
, Qt
);
4818 GCPRO4 (string
, parms
, frame
, timeout
);
4820 CHECK_STRING (string
);
4821 f
= check_x_frame (frame
);
4823 timeout
= make_number (5);
4825 CHECK_NATNUM (timeout
);
4828 dx
= make_number (5);
4833 dy
= make_number (-10);
4837 if (NILP (last_show_tip_args
))
4838 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
4840 if (!NILP (tip_frame
))
4842 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
4843 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
4844 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
4846 if (EQ (frame
, last_frame
)
4847 && !NILP (Fequal (last_string
, string
))
4848 && !NILP (Fequal (last_parms
, parms
)))
4850 struct frame
*f
= XFRAME (tip_frame
);
4852 /* Only DX and DY have changed. */
4853 if (!NILP (tip_timer
))
4855 Lisp_Object timer
= tip_timer
;
4857 call1 (Qcancel_timer
, timer
);
4861 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
4862 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
4863 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4870 /* Hide a previous tip, if any. */
4873 ASET (last_show_tip_args
, 0, string
);
4874 ASET (last_show_tip_args
, 1, frame
);
4875 ASET (last_show_tip_args
, 2, parms
);
4877 /* Add default values to frame parameters. */
4878 if (NILP (Fassq (Qname
, parms
)))
4879 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
4880 if (NILP (Fassq (Qinternal_border_width
, parms
)))
4881 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
4882 if (NILP (Fassq (Qborder_width
, parms
)))
4883 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
4884 if (NILP (Fassq (Qborder_color
, parms
)))
4885 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
4886 if (NILP (Fassq (Qbackground_color
, parms
)))
4887 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
4890 /* Create a frame for the tooltip, and record it in the global
4891 variable tip_frame. */
4892 frame
= x_create_tip_frame (FRAME_X_DISPLAY_INFO (f
), parms
, string
);
4895 /* Set up the frame's root window. */
4896 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4897 w
->left_col
= w
->top_line
= make_number (0);
4899 if (CONSP (Vx_max_tooltip_size
)
4900 && INTEGERP (XCAR (Vx_max_tooltip_size
))
4901 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
4902 && INTEGERP (XCDR (Vx_max_tooltip_size
))
4903 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
4905 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
4906 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
4910 w
->total_cols
= make_number (80);
4911 w
->total_lines
= make_number (40);
4914 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
4916 w
->pseudo_window_p
= 1;
4918 /* Display the tooltip text in a temporary buffer. */
4919 old_buffer
= current_buffer
;
4920 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
4921 current_buffer
->truncate_lines
= Qnil
;
4922 clear_glyph_matrix (w
->desired_matrix
);
4923 clear_glyph_matrix (w
->current_matrix
);
4924 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
4925 try_window (FRAME_ROOT_WINDOW (f
), pos
);
4927 /* Compute width and height of the tooltip. */
4929 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
4931 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
4935 /* Stop at the first empty row at the end. */
4936 if (!row
->enabled_p
|| !row
->displays_text_p
)
4939 /* Let the row go over the full width of the frame. */
4940 row
->full_width_p
= 1;
4942 /* There's a glyph at the end of rows that is used to place
4943 the cursor there. Don't include the width of this glyph. */
4944 if (row
->used
[TEXT_AREA
])
4946 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
4947 row_width
= row
->pixel_width
- last
->pixel_width
;
4950 row_width
= row
->pixel_width
;
4952 height
+= row
->height
;
4953 width
= max (width
, row_width
);
4956 /* Add the frame's internal border to the width and height the X
4957 window should have. */
4958 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
4959 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
4961 /* Move the tooltip window where the mouse pointer is. Resize and
4963 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
4966 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4967 root_x
, root_y
, width
, height
);
4968 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
4971 /* Draw into the window. */
4972 w
->must_be_updated_p
= 1;
4973 update_single_window (w
, 1);
4975 /* Restore original current buffer. */
4976 set_buffer_internal_1 (old_buffer
);
4977 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
4980 /* Let the tip disappear after timeout seconds. */
4981 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
4982 intern ("x-hide-tip"));
4985 return unbind_to (count
, Qnil
);
4989 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
4990 doc
: /* Hide the current tooltip window, if there is any.
4991 Value is t if tooltip was open, nil otherwise. */)
4995 Lisp_Object deleted
, frame
, timer
;
4996 struct gcpro gcpro1
, gcpro2
;
4998 /* Return quickly if nothing to do. */
4999 if (NILP (tip_timer
) && NILP (tip_frame
))
5004 GCPRO2 (frame
, timer
);
5005 tip_frame
= tip_timer
= deleted
= Qnil
;
5007 count
= SPECPDL_INDEX ();
5008 specbind (Qinhibit_redisplay
, Qt
);
5009 specbind (Qinhibit_quit
, Qt
);
5012 call1 (Qcancel_timer
, timer
);
5016 Fdelete_frame (frame
, Qnil
);
5020 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5021 redisplay procedure is not called when a tip frame over menu
5022 items is unmapped. Redisplay the menu manually... */
5024 struct frame
*f
= SELECTED_FRAME ();
5025 Widget w
= f
->output_data
.x
->menubar_widget
;
5026 extern void xlwmenu_redisplay
P_ ((Widget
));
5028 if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f
)->screen
)
5032 xlwmenu_redisplay (w
);
5036 #endif /* USE_LUCID */
5040 return unbind_to (count
, deleted
);
5045 /***********************************************************************
5046 File selection dialog
5047 ***********************************************************************/
5051 /* Callback for "OK" and "Cancel" on file selection dialog. */
5054 file_dialog_cb (widget
, client_data
, call_data
)
5056 XtPointer call_data
, client_data
;
5058 int *result
= (int *) client_data
;
5059 XmAnyCallbackStruct
*cb
= (XmAnyCallbackStruct
*) call_data
;
5060 *result
= cb
->reason
;
5064 /* Callback for unmapping a file selection dialog. This is used to
5065 capture the case where a dialog is closed via a window manager's
5066 closer button, for example. Using a XmNdestroyCallback didn't work
5070 file_dialog_unmap_cb (widget
, client_data
, call_data
)
5072 XtPointer call_data
, client_data
;
5074 int *result
= (int *) client_data
;
5075 *result
= XmCR_CANCEL
;
5079 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
5080 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5081 Use a file selection dialog.
5082 Select DEFAULT-FILENAME in the dialog's file selection box, if
5083 specified. Don't let the user enter a file name in the file
5084 selection dialog's entry field, if MUSTMATCH is non-nil. */)
5085 (prompt
, dir
, default_filename
, mustmatch
)
5086 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
5089 struct frame
*f
= SELECTED_FRAME ();
5090 Lisp_Object file
= Qnil
;
5091 Widget dialog
, text
, list
, help
;
5094 extern XtAppContext Xt_app_con
;
5095 XmString dir_xmstring
, pattern_xmstring
;
5096 int count
= SPECPDL_INDEX ();
5097 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
5099 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
5100 CHECK_STRING (prompt
);
5103 /* Prevent redisplay. */
5104 specbind (Qinhibit_redisplay
, Qt
);
5108 /* Create the dialog with PROMPT as title, using DIR as initial
5109 directory and using "*" as pattern. */
5110 dir
= Fexpand_file_name (dir
, Qnil
);
5111 dir_xmstring
= XmStringCreateLocalized (SDATA (dir
));
5112 pattern_xmstring
= XmStringCreateLocalized ("*");
5114 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
5115 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
5116 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
5117 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
5118 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
5119 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
5121 XmStringFree (dir_xmstring
);
5122 XmStringFree (pattern_xmstring
);
5124 /* Add callbacks for OK and Cancel. */
5125 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
5126 (XtPointer
) &result
);
5127 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
5128 (XtPointer
) &result
);
5129 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
5130 (XtPointer
) &result
);
5132 /* Disable the help button since we can't display help. */
5133 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
5134 XtSetSensitive (help
, False
);
5136 /* Mark OK button as default. */
5137 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
5138 XmNshowAsDefault
, True
, NULL
);
5140 /* If MUSTMATCH is non-nil, disable the file entry field of the
5141 dialog, so that the user must select a file from the files list
5142 box. We can't remove it because we wouldn't have a way to get at
5143 the result file name, then. */
5144 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5145 if (!NILP (mustmatch
))
5148 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
5149 XtSetSensitive (text
, False
);
5150 XtSetSensitive (label
, False
);
5153 /* Manage the dialog, so that list boxes get filled. */
5154 XtManageChild (dialog
);
5156 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5157 must include the path for this to work. */
5158 list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
5159 if (STRINGP (default_filename
))
5161 XmString default_xmstring
;
5165 = XmStringCreateLocalized (SDATA (default_filename
));
5167 if (!XmListItemExists (list
, default_xmstring
))
5169 /* Add a new item if DEFAULT_FILENAME is not in the list. */
5170 XmListAddItem (list
, default_xmstring
, 0);
5174 item_pos
= XmListItemPos (list
, default_xmstring
);
5175 XmStringFree (default_xmstring
);
5177 /* Select the item and scroll it into view. */
5178 XmListSelectPos (list
, item_pos
, True
);
5179 XmListSetPos (list
, item_pos
);
5182 /* Process events until the user presses Cancel or OK. */
5187 XtAppNextEvent (Xt_app_con
, &event
);
5188 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
) );
5191 /* Get the result. */
5192 if (result
== XmCR_OK
)
5197 XtVaGetValues (dialog
, XmNtextString
, &text
, NULL
);
5198 XmStringGetLtoR (text
, XmFONTLIST_DEFAULT_TAG
, &data
);
5199 XmStringFree (text
);
5200 file
= build_string (data
);
5207 XtUnmanageChild (dialog
);
5208 XtDestroyWidget (dialog
);
5212 /* Make "Cancel" equivalent to C-g. */
5214 Fsignal (Qquit
, Qnil
);
5216 return unbind_to (count
, file
);
5219 #endif /* USE_MOTIF */
5223 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
5224 "Read file name, prompting with PROMPT in directory DIR.\n\
5225 Use a file selection dialog.\n\
5226 Select DEFAULT-FILENAME in the dialog's file selection box, if\n\
5227 specified. Don't let the user enter a file name in the file\n\
5228 selection dialog's entry field, if MUSTMATCH is non-nil.")
5229 (prompt
, dir
, default_filename
, mustmatch
)
5230 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
5232 FRAME_PTR f
= SELECTED_FRAME ();
5234 Lisp_Object file
= Qnil
;
5235 int count
= specpdl_ptr
- specpdl
;
5236 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
5239 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
5240 CHECK_STRING (prompt
);
5243 /* Prevent redisplay. */
5244 specbind (Qinhibit_redisplay
, Qt
);
5248 if (STRINGP (default_filename
))
5249 cdef_file
= SDATA (default_filename
);
5251 cdef_file
= SDATA (dir
);
5253 fn
= xg_get_file_name (f
, SDATA (prompt
), cdef_file
, ! NILP (mustmatch
));
5257 file
= build_string (fn
);
5264 /* Make "Cancel" equivalent to C-g. */
5266 Fsignal (Qquit
, Qnil
);
5268 return unbind_to (count
, file
);
5271 #endif /* USE_GTK */
5274 /***********************************************************************
5276 ***********************************************************************/
5278 #ifdef HAVE_XKBGETKEYBOARD
5279 #include <X11/XKBlib.h>
5280 #include <X11/keysym.h>
5283 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
5284 Sx_backspace_delete_keys_p
, 0, 1, 0,
5285 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
5286 FRAME nil means use the selected frame.
5287 Value is t if we know that both keys are present, and are mapped to the
5288 usual X keysyms. */)
5292 #ifdef HAVE_XKBGETKEYBOARD
5294 struct frame
*f
= check_x_frame (frame
);
5295 Display
*dpy
= FRAME_X_DISPLAY (f
);
5296 Lisp_Object have_keys
;
5297 int major
, minor
, op
, event
, error
;
5301 /* Check library version in case we're dynamically linked. */
5302 major
= XkbMajorVersion
;
5303 minor
= XkbMinorVersion
;
5304 if (!XkbLibraryVersion (&major
, &minor
))
5310 /* Check that the server supports XKB. */
5311 major
= XkbMajorVersion
;
5312 minor
= XkbMinorVersion
;
5313 if (!XkbQueryExtension (dpy
, &op
, &event
, &error
, &major
, &minor
))
5320 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
5323 int delete_keycode
= 0, backspace_keycode
= 0, i
;
5325 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
5327 for (i
= kb
->min_key_code
;
5328 (i
< kb
->max_key_code
5329 && (delete_keycode
== 0 || backspace_keycode
== 0));
5332 /* The XKB symbolic key names can be seen most easily in
5333 the PS file generated by `xkbprint -label name
5335 if (bcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
5337 else if (bcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
5338 backspace_keycode
= i
;
5341 XkbFreeNames (kb
, 0, True
);
5344 XkbFreeClientMap (kb
, 0, True
);
5347 && backspace_keycode
5348 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
5349 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
5354 #else /* not HAVE_XKBGETKEYBOARD */
5356 #endif /* not HAVE_XKBGETKEYBOARD */
5361 /***********************************************************************
5363 ***********************************************************************/
5365 /* Keep this list in the same order as frame_parms in frame.c.
5366 Use 0 for unsupported frame parameters. */
5368 frame_parm_handler x_frame_parm_handlers
[] =
5372 x_set_background_color
,
5378 x_set_foreground_color
,
5381 x_set_internal_border_width
,
5382 x_set_menu_bar_lines
,
5384 x_explicitly_set_name
,
5385 x_set_scroll_bar_width
,
5388 x_set_vertical_scroll_bars
,
5390 x_set_tool_bar_lines
,
5391 x_set_scroll_bar_foreground
,
5392 x_set_scroll_bar_background
,
5404 /* This is zero if not using X windows. */
5407 /* The section below is built by the lisp expression at the top of the file,
5408 just above where these variables are declared. */
5409 /*&&& init symbols here &&&*/
5410 Qnone
= intern ("none");
5412 Qsuppress_icon
= intern ("suppress-icon");
5413 staticpro (&Qsuppress_icon
);
5414 Qundefined_color
= intern ("undefined-color");
5415 staticpro (&Qundefined_color
);
5416 Qcompound_text
= intern ("compound-text");
5417 staticpro (&Qcompound_text
);
5418 Qcancel_timer
= intern ("cancel-timer");
5419 staticpro (&Qcancel_timer
);
5420 /* This is the end of symbol initialization. */
5422 /* Text property `display' should be nonsticky by default. */
5423 Vtext_property_default_nonsticky
5424 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
5427 Fput (Qundefined_color
, Qerror_conditions
,
5428 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
5429 Fput (Qundefined_color
, Qerror_message
,
5430 build_string ("Undefined color"));
5432 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
5433 doc
: /* The shape of the pointer when over text.
5434 Changing the value does not affect existing frames
5435 unless you set the mouse color. */);
5436 Vx_pointer_shape
= Qnil
;
5438 #if 0 /* This doesn't really do anything. */
5439 DEFVAR_LISP ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape
,
5440 doc
: /* The shape of the pointer when not over text.
5441 This variable takes effect when you create a new frame
5442 or when you set the mouse color. */);
5444 Vx_nontext_pointer_shape
= Qnil
;
5446 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
5447 doc
: /* The shape of the pointer when Emacs is busy.
5448 This variable takes effect when you create a new frame
5449 or when you set the mouse color. */);
5450 Vx_hourglass_pointer_shape
= Qnil
;
5452 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
5453 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
5454 display_hourglass_p
= 1;
5456 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
5457 doc
: /* *Seconds to wait before displaying an hourglass pointer.
5458 Value must be an integer or float. */);
5459 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
5461 #if 0 /* This doesn't really do anything. */
5462 DEFVAR_LISP ("x-mode-pointer-shape", &Vx_mode_pointer_shape
,
5463 doc
: /* The shape of the pointer when over the mode line.
5464 This variable takes effect when you create a new frame
5465 or when you set the mouse color. */);
5467 Vx_mode_pointer_shape
= Qnil
;
5469 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
5470 &Vx_sensitive_text_pointer_shape
,
5471 doc
: /* The shape of the pointer when over mouse-sensitive text.
5472 This variable takes effect when you create a new frame
5473 or when you set the mouse color. */);
5474 Vx_sensitive_text_pointer_shape
= Qnil
;
5476 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
5477 &Vx_window_horizontal_drag_shape
,
5478 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
5479 This variable takes effect when you create a new frame
5480 or when you set the mouse color. */);
5481 Vx_window_horizontal_drag_shape
= Qnil
;
5483 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
5484 doc
: /* A string indicating the foreground color of the cursor box. */);
5485 Vx_cursor_fore_pixel
= Qnil
;
5487 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
5488 doc
: /* Maximum size for tooltips. Value is a pair (COLUMNS . ROWS).
5489 Text larger than this is clipped. */);
5490 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
5492 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
5493 doc
: /* Non-nil if no X window manager is in use.
5494 Emacs doesn't try to figure this out; this is always nil
5495 unless you set it to something else. */);
5496 /* We don't have any way to find this out, so set it to nil
5497 and maybe the user would like to set it to t. */
5498 Vx_no_window_manager
= Qnil
;
5500 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
5501 &Vx_pixel_size_width_font_regexp
,
5502 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
5504 Since Emacs gets width of a font matching with this regexp from
5505 PIXEL_SIZE field of the name, font finding mechanism gets faster for
5506 such a font. This is especially effective for such large fonts as
5507 Chinese, Japanese, and Korean. */);
5508 Vx_pixel_size_width_font_regexp
= Qnil
;
5510 #ifdef USE_X_TOOLKIT
5511 Fprovide (intern ("x-toolkit"), Qnil
);
5513 Fprovide (intern ("motif"), Qnil
);
5515 DEFVAR_LISP ("motif-version-string", &Vmotif_version_string
,
5516 doc
: /* Version info for LessTif/Motif. */);
5517 Vmotif_version_string
= build_string (XmVERSION_STRING
);
5518 #endif /* USE_MOTIF */
5519 #endif /* USE_X_TOOLKIT */
5522 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
5523 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
5524 But for a user it is a toolkit for X, and indeed, configure
5525 accepts --with-x-toolkit=gtk. */
5526 Fprovide (intern ("x-toolkit"), Qnil
);
5527 Fprovide (intern ("gtk"), Qnil
);
5529 DEFVAR_LISP ("gtk-version-string", &Vgtk_version_string
,
5530 doc
: /* Version info for GTK+. */);
5532 char gtk_version
[40];
5533 g_snprintf (gtk_version
, sizeof (gtk_version
), "%u.%u.%u",
5534 GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
);
5535 Vgtk_version_string
= build_string (gtk_version
);
5537 #endif /* USE_GTK */
5539 /* X window properties. */
5540 defsubr (&Sx_change_window_property
);
5541 defsubr (&Sx_delete_window_property
);
5542 defsubr (&Sx_window_property
);
5544 defsubr (&Sxw_display_color_p
);
5545 defsubr (&Sx_display_grayscale_p
);
5546 defsubr (&Sxw_color_defined_p
);
5547 defsubr (&Sxw_color_values
);
5548 defsubr (&Sx_server_max_request_size
);
5549 defsubr (&Sx_server_vendor
);
5550 defsubr (&Sx_server_version
);
5551 defsubr (&Sx_display_pixel_width
);
5552 defsubr (&Sx_display_pixel_height
);
5553 defsubr (&Sx_display_mm_width
);
5554 defsubr (&Sx_display_mm_height
);
5555 defsubr (&Sx_display_screens
);
5556 defsubr (&Sx_display_planes
);
5557 defsubr (&Sx_display_color_cells
);
5558 defsubr (&Sx_display_visual_class
);
5559 defsubr (&Sx_display_backing_store
);
5560 defsubr (&Sx_display_save_under
);
5561 defsubr (&Sx_create_frame
);
5562 defsubr (&Sx_open_connection
);
5563 defsubr (&Sx_close_connection
);
5564 defsubr (&Sx_display_list
);
5565 defsubr (&Sx_synchronize
);
5566 defsubr (&Sx_focus_frame
);
5567 defsubr (&Sx_backspace_delete_keys_p
);
5569 /* Setting callback functions for fontset handler. */
5570 get_font_info_func
= x_get_font_info
;
5572 #if 0 /* This function pointer doesn't seem to be used anywhere.
5573 And the pointer assigned has the wrong type, anyway. */
5574 list_fonts_func
= x_list_fonts
;
5577 load_font_func
= x_load_font
;
5578 find_ccl_program_func
= x_find_ccl_program
;
5579 query_font_func
= x_query_font
;
5580 set_frame_fontset_func
= x_set_font
;
5581 check_window_system_func
= check_x
;
5583 hourglass_atimer
= NULL
;
5584 hourglass_shown_p
= 0;
5586 defsubr (&Sx_show_tip
);
5587 defsubr (&Sx_hide_tip
);
5589 staticpro (&tip_timer
);
5591 staticpro (&tip_frame
);
5593 last_show_tip_args
= Qnil
;
5594 staticpro (&last_show_tip_args
);
5597 defsubr (&Sx_file_dialog
);
5601 #endif /* HAVE_X_WINDOWS */
5603 /* arch-tag: 55040d02-5485-4d58-8b22-95a7a05f3288
5604 (do not change this comment) */