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 /* Verify that the icon position args for this window are valid. */
2649 x_icon_verify (f
, parms
)
2653 Lisp_Object icon_x
, icon_y
;
2655 /* Set the position of the icon. Note that twm groups all
2656 icons in an icon window. */
2657 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2658 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2659 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2661 CHECK_NUMBER (icon_x
);
2662 CHECK_NUMBER (icon_y
);
2664 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2665 error ("Both left and top icon corners of icon must be specified");
2668 /* Handle the icon stuff for this window. Perhaps later we might
2669 want an x_set_icon_position which can be called interactively as
2677 Lisp_Object icon_x
, icon_y
;
2678 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2680 /* Set the position of the icon. Note that twm groups all
2681 icons in an icon window. */
2682 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2683 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2684 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2686 CHECK_NUMBER (icon_x
);
2687 CHECK_NUMBER (icon_y
);
2689 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2690 error ("Both left and top icon corners of icon must be specified");
2694 if (! EQ (icon_x
, Qunbound
))
2695 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2697 /* Start up iconic or window? */
2698 x_wm_set_window_state
2699 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
2704 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
2711 /* Make the GCs needed for this window, setting the
2712 background, border and mouse colors; also create the
2713 mouse cursor and the gray border tile. */
2715 static char cursor_bits
[] =
2717 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2718 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2719 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2720 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2727 XGCValues gc_values
;
2731 /* Create the GCs of this frame.
2732 Note that many default values are used. */
2735 gc_values
.font
= FRAME_FONT (f
)->fid
;
2736 gc_values
.foreground
= f
->output_data
.x
->foreground_pixel
;
2737 gc_values
.background
= f
->output_data
.x
->background_pixel
;
2738 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2739 f
->output_data
.x
->normal_gc
2740 = XCreateGC (FRAME_X_DISPLAY (f
),
2742 GCLineWidth
| GCFont
| GCForeground
| GCBackground
,
2745 /* Reverse video style. */
2746 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
2747 gc_values
.background
= f
->output_data
.x
->foreground_pixel
;
2748 f
->output_data
.x
->reverse_gc
2749 = XCreateGC (FRAME_X_DISPLAY (f
),
2751 GCFont
| GCForeground
| GCBackground
| GCLineWidth
,
2754 /* Cursor has cursor-color background, background-color foreground. */
2755 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
2756 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
2757 gc_values
.fill_style
= FillOpaqueStippled
;
2759 = XCreateBitmapFromData (FRAME_X_DISPLAY (f
),
2760 FRAME_X_DISPLAY_INFO (f
)->root_window
,
2761 cursor_bits
, 16, 16);
2762 f
->output_data
.x
->cursor_gc
2763 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2764 (GCFont
| GCForeground
| GCBackground
2765 | GCFillStyle
/* | GCStipple */ | GCLineWidth
),
2769 f
->output_data
.x
->white_relief
.gc
= 0;
2770 f
->output_data
.x
->black_relief
.gc
= 0;
2772 /* Create the gray border tile used when the pointer is not in
2773 the frame. Since this depends on the frame's pixel values,
2774 this must be done on a per-frame basis. */
2775 f
->output_data
.x
->border_tile
2776 = (XCreatePixmapFromBitmapData
2777 (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
2778 gray_bits
, gray_width
, gray_height
,
2779 f
->output_data
.x
->foreground_pixel
,
2780 f
->output_data
.x
->background_pixel
,
2781 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
2787 /* Free what was was allocated in x_make_gc. */
2793 Display
*dpy
= FRAME_X_DISPLAY (f
);
2797 if (f
->output_data
.x
->normal_gc
)
2799 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
2800 f
->output_data
.x
->normal_gc
= 0;
2803 if (f
->output_data
.x
->reverse_gc
)
2805 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
2806 f
->output_data
.x
->reverse_gc
= 0;
2809 if (f
->output_data
.x
->cursor_gc
)
2811 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
2812 f
->output_data
.x
->cursor_gc
= 0;
2815 if (f
->output_data
.x
->border_tile
)
2817 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
2818 f
->output_data
.x
->border_tile
= 0;
2825 /* Handler for signals raised during x_create_frame and
2826 x_create_top_frame. FRAME is the frame which is partially
2830 unwind_create_frame (frame
)
2833 struct frame
*f
= XFRAME (frame
);
2835 /* If frame is ``official'', nothing to do. */
2836 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
2839 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2842 x_free_frame_resources (f
);
2844 /* Check that reference counts are indeed correct. */
2845 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
2846 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
2854 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
2856 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
2857 Returns an Emacs frame object.
2858 ALIST is an alist of frame parameters.
2859 If the parameters specify that the frame should not have a minibuffer,
2860 and do not specify a specific minibuffer window to use,
2861 then `default-minibuffer-frame' must be a frame whose minibuffer can
2862 be shared by the new frame.
2864 This function is an internal primitive--use `make-frame' instead. */)
2869 Lisp_Object frame
, tem
;
2871 int minibuffer_only
= 0;
2872 long window_prompting
= 0;
2874 int count
= SPECPDL_INDEX ();
2875 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
2876 Lisp_Object display
;
2877 struct x_display_info
*dpyinfo
= NULL
;
2881 /* Use this general default value to start with
2882 until we know if this frame has a specified name. */
2883 Vx_resource_name
= Vinvocation_name
;
2885 display
= x_get_arg (dpyinfo
, parms
, Qdisplay_id
, 0, 0, RES_TYPE_NUMBER
);
2886 if (EQ (display
, Qunbound
))
2887 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
2888 if (EQ (display
, Qunbound
))
2890 dpyinfo
= check_x_display_info (display
);
2892 kb
= dpyinfo
->kboard
;
2894 kb
= &the_only_kboard
;
2897 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
2899 && ! EQ (name
, Qunbound
)
2901 error ("Invalid frame name--not a string or nil");
2904 Vx_resource_name
= name
;
2906 /* See if parent window is specified. */
2907 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
2908 if (EQ (parent
, Qunbound
))
2910 if (! NILP (parent
))
2911 CHECK_NUMBER (parent
);
2913 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
2914 /* No need to protect DISPLAY because that's not used after passing
2915 it to make_frame_without_minibuffer. */
2917 GCPRO4 (parms
, parent
, name
, frame
);
2918 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
2920 if (EQ (tem
, Qnone
) || NILP (tem
))
2921 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
2922 else if (EQ (tem
, Qonly
))
2924 f
= make_minibuffer_frame ();
2925 minibuffer_only
= 1;
2927 else if (WINDOWP (tem
))
2928 f
= make_frame_without_minibuffer (tem
, kb
, display
);
2932 XSETFRAME (frame
, f
);
2934 /* Note that X Windows does support scroll bars. */
2935 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
2937 f
->display
= dpyinfo
->frame_display
;
2938 f
->display
->reference_count
++;
2940 f
->output_method
= output_x_window
;
2941 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
2942 bzero (f
->output_data
.x
, sizeof (struct x_output
));
2943 f
->output_data
.x
->icon_bitmap
= -1;
2944 FRAME_FONTSET (f
) = -1;
2945 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
2946 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
2947 #ifdef USE_TOOLKIT_SCROLL_BARS
2948 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
2949 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
2950 #endif /* USE_TOOLKIT_SCROLL_BARS */
2951 record_unwind_protect (unwind_create_frame
, frame
);
2954 = x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
2956 if (! STRINGP (f
->icon_name
))
2957 f
->icon_name
= Qnil
;
2959 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
2961 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
2962 dpyinfo_refcount
= dpyinfo
->reference_count
;
2963 #endif /* GLYPH_DEBUG */
2965 FRAME_KBOARD (f
) = kb
;
2968 /* These colors will be set anyway later, but it's important
2969 to get the color reference counts right, so initialize them! */
2972 struct gcpro gcpro1
;
2974 /* Function x_decode_color can signal an error. Make
2975 sure to initialize color slots so that we won't try
2976 to free colors we haven't allocated. */
2977 f
->output_data
.x
->foreground_pixel
= -1;
2978 f
->output_data
.x
->background_pixel
= -1;
2979 f
->output_data
.x
->cursor_pixel
= -1;
2980 f
->output_data
.x
->cursor_foreground_pixel
= -1;
2981 f
->output_data
.x
->border_pixel
= -1;
2982 f
->output_data
.x
->mouse_pixel
= -1;
2984 black
= build_string ("black");
2986 f
->output_data
.x
->foreground_pixel
2987 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2988 f
->output_data
.x
->background_pixel
2989 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2990 f
->output_data
.x
->cursor_pixel
2991 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2992 f
->output_data
.x
->cursor_foreground_pixel
2993 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2994 f
->output_data
.x
->border_pixel
2995 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2996 f
->output_data
.x
->mouse_pixel
2997 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3001 /* Specify the parent under which to make this X window. */
3005 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
3006 f
->output_data
.x
->explicit_parent
= 1;
3010 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3011 f
->output_data
.x
->explicit_parent
= 0;
3014 /* Set the name; the functions to which we pass f expect the name to
3016 if (EQ (name
, Qunbound
) || NILP (name
))
3018 f
->name
= build_string (dpyinfo
->x_id_name
);
3019 f
->explicit_name
= 0;
3024 f
->explicit_name
= 1;
3025 /* use the frame's title when getting resources for this frame. */
3026 specbind (Qx_resource_name
, name
);
3029 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qwindow_system
, Qx
), Qnil
));
3031 /* Extract the window parameters from the supplied values
3032 that are needed to determine window geometry. */
3036 font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
3039 /* First, try whatever font the caller has specified. */
3042 tem
= Fquery_fontset (font
, Qnil
);
3044 font
= x_new_fontset (f
, SDATA (tem
));
3046 font
= x_new_font (f
, SDATA (font
));
3049 /* Try out a font which we hope has bold and italic variations. */
3050 if (!STRINGP (font
))
3051 font
= x_new_font (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
3052 if (!STRINGP (font
))
3053 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3054 if (! STRINGP (font
))
3055 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3056 if (! STRINGP (font
))
3057 /* This was formerly the first thing tried, but it finds too many fonts
3058 and takes too long. */
3059 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
3060 /* If those didn't work, look for something which will at least work. */
3061 if (! STRINGP (font
))
3062 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
3064 if (! STRINGP (font
))
3065 font
= build_string ("fixed");
3067 x_default_parameter (f
, parms
, Qfont
, font
,
3068 "font", "Font", RES_TYPE_STRING
);
3072 /* Prevent lwlib/xlwmenu.c from crashing because of a bug
3073 whereby it fails to get any font. */
3074 xlwmenu_default_font
= FRAME_FONT (f
);
3077 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
3078 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
3080 /* This defaults to 1 in order to match xterm. We recognize either
3081 internalBorderWidth or internalBorder (which is what xterm calls
3083 if (NILP (Fassq (Qinternal_border_width
, parms
)))
3087 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
3088 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
3089 if (! EQ (value
, Qunbound
))
3090 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
3093 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
3094 "internalBorderWidth", "internalBorderWidth",
3096 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qleft
,
3097 "verticalScrollBars", "ScrollBars",
3100 /* Also do the stuff which must be set before the window exists. */
3101 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3102 "foreground", "Foreground", RES_TYPE_STRING
);
3103 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3104 "background", "Background", RES_TYPE_STRING
);
3105 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3106 "pointerColor", "Foreground", RES_TYPE_STRING
);
3107 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
3108 "cursorColor", "Foreground", RES_TYPE_STRING
);
3109 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3110 "borderColor", "BorderColor", RES_TYPE_STRING
);
3111 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3112 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3113 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3114 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3115 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3116 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3117 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3118 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3120 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3121 "scrollBarForeground",
3122 "ScrollBarForeground", 1);
3123 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3124 "scrollBarBackground",
3125 "ScrollBarBackground", 0);
3127 /* Init faces before x_default_parameter is called for scroll-bar
3128 parameters because that function calls x_set_scroll_bar_width,
3129 which calls change_frame_size, which calls Fset_window_buffer,
3130 which runs hooks, which call Fvertical_motion. At the end, we
3131 end up in init_iterator with a null face cache, which should not
3133 init_frame_faces (f
);
3135 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
3136 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
3137 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (1),
3138 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
3139 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3140 "bufferPredicate", "BufferPredicate",
3142 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3143 "title", "Title", RES_TYPE_STRING
);
3144 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3145 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3146 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3147 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3149 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3151 /* Compute the size of the X window. */
3152 window_prompting
= x_figure_window_size (f
, parms
, 1);
3154 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3155 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3157 x_icon_verify (f
, parms
);
3159 /* Create the X widget or window. */
3160 #ifdef USE_X_TOOLKIT
3161 x_window (f
, window_prompting
, minibuffer_only
);
3169 /* Now consider the frame official. */
3170 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
3171 Vframe_list
= Fcons (frame
, Vframe_list
);
3173 /* We need to do this after creating the X window, so that the
3174 icon-creation functions can say whose icon they're describing. */
3175 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
3176 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
3178 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3179 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3180 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3181 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3182 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3183 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3184 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3185 "scrollBarWidth", "ScrollBarWidth",
3188 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
3189 Change will not be effected unless different from the current
3191 width
= FRAME_COLS (f
);
3192 height
= FRAME_LINES (f
);
3194 SET_FRAME_COLS (f
, 0);
3195 FRAME_LINES (f
) = 0;
3196 change_frame_size (f
, height
, width
, 1, 0, 0);
3198 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3199 /* Create the menu bar. */
3200 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3202 /* If this signals an error, we haven't set size hints for the
3203 frame and we didn't make it visible. */
3204 initialize_frame_menubar (f
);
3207 /* This is a no-op, except under Motif where it arranges the
3208 main window for the widgets on it. */
3209 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3210 f
->output_data
.x
->menubar_widget
,
3211 f
->output_data
.x
->edit_widget
);
3212 #endif /* not USE_GTK */
3214 #endif /* USE_X_TOOLKIT || USE_GTK */
3216 /* Tell the server what size and position, etc, we want, and how
3217 badly we want them. This should be done after we have the menu
3218 bar so that its size can be taken into account. */
3220 x_wm_set_size_hint (f
, window_prompting
, 0);
3223 /* Make the window appear on the frame and enable display, unless
3224 the caller says not to. However, with explicit parent, Emacs
3225 cannot control visibility, so don't try. */
3226 if (! f
->output_data
.x
->explicit_parent
)
3228 Lisp_Object visibility
;
3230 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3232 if (EQ (visibility
, Qunbound
))
3235 if (EQ (visibility
, Qicon
))
3236 x_iconify_frame (f
);
3237 else if (! NILP (visibility
))
3238 x_make_frame_visible (f
);
3240 /* Must have been Qnil. */
3244 /* Set the WM leader property. GTK does this itself, so this is not
3245 needed when using GTK. */
3246 if (dpyinfo
->client_leader_window
!= 0)
3249 XChangeProperty (FRAME_X_DISPLAY (f
),
3250 FRAME_OUTER_WINDOW (f
),
3251 dpyinfo
->Xatom_wm_client_leader
,
3252 XA_WINDOW
, 32, PropModeReplace
,
3253 (char *) &dpyinfo
->client_leader_window
, 1);
3259 /* Make sure windows on this frame appear in calls to next-window
3260 and similar functions. */
3261 Vwindow_list
= Qnil
;
3263 return unbind_to (count
, frame
);
3267 /* FRAME is used only to get a handle on the X display. We don't pass the
3268 display info directly because we're called from frame.c, which doesn't
3269 know about that structure. */
3272 x_get_focus_frame (frame
)
3273 struct frame
*frame
;
3275 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (frame
);
3277 if (! dpyinfo
->x_focus_frame
)
3280 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3285 /* In certain situations, when the window manager follows a
3286 click-to-focus policy, there seems to be no way around calling
3287 XSetInputFocus to give another frame the input focus .
3289 In an ideal world, XSetInputFocus should generally be avoided so
3290 that applications don't interfere with the window manager's focus
3291 policy. But I think it's okay to use when it's clearly done
3292 following a user-command. */
3294 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
3295 doc
: /* Set the input focus to FRAME.
3296 FRAME nil means use the selected frame. */)
3300 struct frame
*f
= check_x_frame (frame
);
3301 Display
*dpy
= FRAME_X_DISPLAY (f
);
3305 count
= x_catch_errors (dpy
);
3306 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3307 RevertToParent
, CurrentTime
);
3308 x_uncatch_errors (dpy
, count
);
3315 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
3316 doc
: /* Internal function called by `color-defined-p', which see. */)
3318 Lisp_Object color
, frame
;
3321 FRAME_PTR f
= check_x_frame (frame
);
3323 CHECK_STRING (color
);
3325 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
3331 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
3332 doc
: /* Internal function called by `color-values', which see. */)
3334 Lisp_Object color
, frame
;
3337 FRAME_PTR f
= check_x_frame (frame
);
3339 CHECK_STRING (color
);
3341 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
3345 rgb
[0] = make_number (foo
.red
);
3346 rgb
[1] = make_number (foo
.green
);
3347 rgb
[2] = make_number (foo
.blue
);
3348 return Flist (3, rgb
);
3354 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
3355 doc
: /* Internal function called by `display-color-p', which see. */)
3357 Lisp_Object display
;
3359 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3361 if (dpyinfo
->n_planes
<= 2)
3364 switch (dpyinfo
->visual
->class)
3377 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3379 doc
: /* Return t if the X display supports shades of gray.
3380 Note that color displays do support shades of gray.
3381 The optional argument DISPLAY specifies which display to ask about.
3382 DISPLAY should be either a frame or a display name (a string).
3383 If omitted or nil, that stands for the selected frame's display. */)
3385 Lisp_Object display
;
3387 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3389 if (dpyinfo
->n_planes
<= 1)
3392 switch (dpyinfo
->visual
->class)
3407 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3409 doc
: /* Returns the width in pixels of the X display DISPLAY.
3410 The optional argument DISPLAY specifies which display to ask about.
3411 DISPLAY should be either a frame or a display name (a string).
3412 If omitted or nil, that stands for the selected frame's display. */)
3414 Lisp_Object display
;
3416 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3418 return make_number (dpyinfo
->width
);
3421 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3422 Sx_display_pixel_height
, 0, 1, 0,
3423 doc
: /* Returns the height in pixels of the X display DISPLAY.
3424 The optional argument DISPLAY specifies which display to ask about.
3425 DISPLAY should be either a frame or a display name (a string).
3426 If omitted or nil, that stands for the selected frame's display. */)
3428 Lisp_Object display
;
3430 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3432 return make_number (dpyinfo
->height
);
3435 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3437 doc
: /* Returns the number of bitplanes of the X display DISPLAY.
3438 The optional argument DISPLAY specifies which display to ask about.
3439 DISPLAY should be either a frame or a display name (a string).
3440 If omitted or nil, that stands for the selected frame's display. */)
3442 Lisp_Object display
;
3444 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3446 return make_number (dpyinfo
->n_planes
);
3449 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3451 doc
: /* Returns the number of color cells of the X display DISPLAY.
3452 The optional argument DISPLAY specifies which display to ask about.
3453 DISPLAY should be either a frame or a display name (a string).
3454 If omitted or nil, that stands for the selected frame's display. */)
3456 Lisp_Object display
;
3458 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3460 int nr_planes
= DisplayPlanes (dpyinfo
->display
,
3461 XScreenNumberOfScreen (dpyinfo
->screen
));
3463 /* Truncate nr_planes to 24 to avoid integer overflow.
3464 Some displays says 32, but only 24 bits are actually significant.
3465 There are only very few and rare video cards that have more than
3466 24 significant bits. Also 24 bits is more than 16 million colors,
3467 it "should be enough for everyone". */
3468 if (nr_planes
> 24) nr_planes
= 24;
3470 return make_number (1 << nr_planes
);
3473 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3474 Sx_server_max_request_size
,
3476 doc
: /* Returns the maximum request size of the X server of display DISPLAY.
3477 The optional argument DISPLAY specifies which display to ask about.
3478 DISPLAY should be either a frame or a display name (a string).
3479 If omitted or nil, that stands for the selected frame's display. */)
3481 Lisp_Object display
;
3483 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3485 return make_number (MAXREQUEST (dpyinfo
->display
));
3488 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3489 doc
: /* Returns the vendor ID string of the X server of display DISPLAY.
3490 The optional argument DISPLAY specifies which display to ask about.
3491 DISPLAY should be either a frame or a display name (a string).
3492 If omitted or nil, that stands for the selected frame's display. */)
3494 Lisp_Object display
;
3496 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3497 char *vendor
= ServerVendor (dpyinfo
->display
);
3499 if (! vendor
) vendor
= "";
3500 return build_string (vendor
);
3503 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3504 doc
: /* Returns the version numbers of the X server of display DISPLAY.
3505 The value is a list of three integers: the major and minor
3506 version numbers of the X Protocol in use, and the vendor-specific release
3507 number. See also the function `x-server-vendor'.
3509 The optional argument DISPLAY specifies which display to ask about.
3510 DISPLAY should be either a frame or a display name (a string).
3511 If omitted or nil, that stands for the selected frame's display. */)
3513 Lisp_Object display
;
3515 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3516 Display
*dpy
= dpyinfo
->display
;
3518 return Fcons (make_number (ProtocolVersion (dpy
)),
3519 Fcons (make_number (ProtocolRevision (dpy
)),
3520 Fcons (make_number (VendorRelease (dpy
)), Qnil
)));
3523 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3524 doc
: /* Return the number of screens on the X server of display DISPLAY.
3525 The optional argument DISPLAY specifies which display to ask about.
3526 DISPLAY should be either a frame or a display name (a string).
3527 If omitted or nil, that stands for the selected frame's display. */)
3529 Lisp_Object display
;
3531 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3533 return make_number (ScreenCount (dpyinfo
->display
));
3536 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3537 doc
: /* Return the height in millimeters of the X display DISPLAY.
3538 The optional argument DISPLAY specifies which display to ask about.
3539 DISPLAY should be either a frame or a display name (a string).
3540 If omitted or nil, that stands for the selected frame's display. */)
3542 Lisp_Object display
;
3544 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3546 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3549 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3550 doc
: /* Return the width in millimeters of the X display DISPLAY.
3551 The optional argument DISPLAY specifies which display to ask about.
3552 DISPLAY should be either a frame or a display name (a string).
3553 If omitted or nil, that stands for the selected frame's display. */)
3555 Lisp_Object display
;
3557 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3559 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3562 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3563 Sx_display_backing_store
, 0, 1, 0,
3564 doc
: /* Returns an indication of whether X display DISPLAY does backing store.
3565 The value may be `always', `when-mapped', or `not-useful'.
3566 The optional argument DISPLAY specifies which display to ask about.
3567 DISPLAY should be either a frame or a display name (a string).
3568 If omitted or nil, that stands for the selected frame's display. */)
3570 Lisp_Object display
;
3572 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3575 switch (DoesBackingStore (dpyinfo
->screen
))
3578 result
= intern ("always");
3582 result
= intern ("when-mapped");
3586 result
= intern ("not-useful");
3590 error ("Strange value for BackingStore parameter of screen");
3597 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3598 Sx_display_visual_class
, 0, 1, 0,
3599 doc
: /* Return the visual class of the X display DISPLAY.
3600 The value is one of the symbols `static-gray', `gray-scale',
3601 `static-color', `pseudo-color', `true-color', or `direct-color'.
3603 The optional argument DISPLAY specifies which display to ask about.
3604 DISPLAY should be either a frame or a display name (a string).
3605 If omitted or nil, that stands for the selected frame's display. */)
3607 Lisp_Object display
;
3609 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3612 switch (dpyinfo
->visual
->class)
3615 result
= intern ("static-gray");
3618 result
= intern ("gray-scale");
3621 result
= intern ("static-color");
3624 result
= intern ("pseudo-color");
3627 result
= intern ("true-color");
3630 result
= intern ("direct-color");
3633 error ("Display has an unknown visual class");
3640 DEFUN ("x-display-save-under", Fx_display_save_under
,
3641 Sx_display_save_under
, 0, 1, 0,
3642 doc
: /* Returns t if the X display DISPLAY supports the save-under feature.
3643 The optional argument DISPLAY specifies which display to ask about.
3644 DISPLAY should be either a frame or a display name (a string).
3645 If omitted or nil, that stands for the selected frame's display. */)
3647 Lisp_Object display
;
3649 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3651 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3659 register struct frame
*f
;
3661 return FRAME_PIXEL_WIDTH (f
);
3666 register struct frame
*f
;
3668 return FRAME_PIXEL_HEIGHT (f
);
3673 register struct frame
*f
;
3675 return FRAME_COLUMN_WIDTH (f
);
3680 register struct frame
*f
;
3682 return FRAME_LINE_HEIGHT (f
);
3687 register struct frame
*f
;
3689 return FRAME_X_DISPLAY_INFO (f
)->n_planes
;
3694 /************************************************************************
3696 ************************************************************************/
3699 /* Mapping visual names to visuals. */
3701 static struct visual_class
3708 {"StaticGray", StaticGray
},
3709 {"GrayScale", GrayScale
},
3710 {"StaticColor", StaticColor
},
3711 {"PseudoColor", PseudoColor
},
3712 {"TrueColor", TrueColor
},
3713 {"DirectColor", DirectColor
},
3718 #ifndef HAVE_XSCREENNUMBEROFSCREEN
3720 /* Value is the screen number of screen SCR. This is a substitute for
3721 the X function with the same name when that doesn't exist. */
3724 XScreenNumberOfScreen (scr
)
3725 register Screen
*scr
;
3727 Display
*dpy
= scr
->display
;
3730 for (i
= 0; i
< dpy
->nscreens
; ++i
)
3731 if (scr
== dpy
->screens
+ i
)
3737 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
3740 /* Select the visual that should be used on display DPYINFO. Set
3741 members of DPYINFO appropriately. Called from x_term_init. */
3744 select_visual (dpyinfo
)
3745 struct x_display_info
*dpyinfo
;
3747 Display
*dpy
= dpyinfo
->display
;
3748 Screen
*screen
= dpyinfo
->screen
;
3751 /* See if a visual is specified. */
3752 value
= display_x_get_resource (dpyinfo
,
3753 build_string ("visualClass"),
3754 build_string ("VisualClass"),
3756 if (STRINGP (value
))
3758 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
3759 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
3760 depth, a decimal number. NAME is compared with case ignored. */
3761 char *s
= (char *) alloca (SBYTES (value
) + 1);
3766 strcpy (s
, SDATA (value
));
3767 dash
= index (s
, '-');
3770 dpyinfo
->n_planes
= atoi (dash
+ 1);
3774 /* We won't find a matching visual with depth 0, so that
3775 an error will be printed below. */
3776 dpyinfo
->n_planes
= 0;
3778 /* Determine the visual class. */
3779 for (i
= 0; visual_classes
[i
].name
; ++i
)
3780 if (xstricmp (s
, visual_classes
[i
].name
) == 0)
3782 class = visual_classes
[i
].class;
3786 /* Look up a matching visual for the specified class. */
3788 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
3789 dpyinfo
->n_planes
, class, &vinfo
))
3790 fatal ("Invalid visual specification `%s'", SDATA (value
));
3792 dpyinfo
->visual
= vinfo
.visual
;
3797 XVisualInfo
*vinfo
, vinfo_template
;
3799 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
3802 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
3804 vinfo_template
.visualid
= dpyinfo
->visual
->visualid
;
3806 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
3807 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
3808 &vinfo_template
, &n_visuals
);
3810 fatal ("Can't get proper X visual info");
3812 dpyinfo
->n_planes
= vinfo
->depth
;
3813 XFree ((char *) vinfo
);
3818 /* Return the X display structure for the display named NAME.
3819 Open a new connection if necessary. */
3821 struct x_display_info
*
3822 x_display_info_for_name (name
)
3826 struct x_display_info
*dpyinfo
;
3828 CHECK_STRING (name
);
3831 if (! EQ (Vinitial_window_system
, intern ("x")))
3832 error ("Not using X Windows"); /* That doesn't stop us anymore. */
3835 for (dpyinfo
= x_display_list
, names
= x_display_name_list
;
3837 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
3840 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
3845 /* Use this general default value to start with. */
3846 Vx_resource_name
= Vinvocation_name
;
3848 validate_x_resource_name ();
3850 dpyinfo
= x_term_init (name
, (char *)0,
3851 (char *) SDATA (Vx_resource_name
));
3854 error ("Cannot connect to X server %s", SDATA (name
));
3857 XSETFASTINT (Vwindow_system_version
, 11);
3863 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
3865 doc
: /* Open a connection to an X server.
3866 DISPLAY is the name of the display to connect to.
3867 Optional second arg XRM-STRING is a string of resources in xrdb format.
3868 If the optional third arg MUST-SUCCEED is non-nil,
3869 terminate Emacs if we can't open the connection. */)
3870 (display
, xrm_string
, must_succeed
)
3871 Lisp_Object display
, xrm_string
, must_succeed
;
3873 unsigned char *xrm_option
;
3874 struct x_display_info
*dpyinfo
;
3876 CHECK_STRING (display
);
3877 if (! NILP (xrm_string
))
3878 CHECK_STRING (xrm_string
);
3881 if (! EQ (Vinitial_window_system
, intern ("x")))
3882 error ("Not using X Windows"); /* That doesn't stop us anymore. */
3885 if (! NILP (xrm_string
))
3886 xrm_option
= (unsigned char *) SDATA (xrm_string
);
3888 xrm_option
= (unsigned char *) 0;
3890 validate_x_resource_name ();
3892 /* This is what opens the connection and sets x_current_display.
3893 This also initializes many symbols, such as those used for input. */
3894 dpyinfo
= x_term_init (display
, xrm_option
,
3895 (char *) SDATA (Vx_resource_name
));
3899 if (!NILP (must_succeed
))
3900 fatal ("Cannot connect to X server %s.\n\
3901 Check the DISPLAY environment variable or use `-d'.\n\
3902 Also use the `xauth' program to verify that you have the proper\n\
3903 authorization information needed to connect the X server.\n\
3904 An insecure way to solve the problem may be to use `xhost'.\n",
3907 error ("Cannot connect to X server %s", SDATA (display
));
3912 XSETFASTINT (Vwindow_system_version
, 11);
3916 DEFUN ("x-close-connection", Fx_close_connection
,
3917 Sx_close_connection
, 1, 1, 0,
3918 doc
: /* Close the connection to DISPLAY's X server.
3919 For DISPLAY, specify either a frame or a display name (a string).
3920 If DISPLAY is nil, that stands for the selected frame's display. */)
3922 Lisp_Object display
;
3924 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3927 if (dpyinfo
->reference_count
> 0)
3928 error ("Display still has frames on it");
3931 /* Free the fonts in the font table. */
3932 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
3933 if (dpyinfo
->font_table
[i
].name
)
3935 XFreeFont (dpyinfo
->display
, dpyinfo
->font_table
[i
].font
);
3938 x_destroy_all_bitmaps (dpyinfo
);
3939 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
3941 #ifdef USE_X_TOOLKIT
3942 XtCloseDisplay (dpyinfo
->display
);
3944 XCloseDisplay (dpyinfo
->display
);
3947 x_delete_display (dpyinfo
);
3953 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
3954 doc
: /* Return the list of display names that Emacs has connections to. */)
3957 Lisp_Object tail
, result
;
3960 for (tail
= x_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
3961 result
= Fcons (XCAR (XCAR (tail
)), result
);
3966 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
3967 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
3968 If ON is nil, allow buffering of requests.
3969 Turning on synchronization prohibits the Xlib routines from buffering
3970 requests and seriously degrades performance, but makes debugging much
3972 The optional second argument DISPLAY specifies which display to act on.
3973 DISPLAY should be either a frame or a display name (a string).
3974 If DISPLAY is omitted or nil, that stands for the selected frame's display. */)
3976 Lisp_Object display
, on
;
3978 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3980 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
3985 /* Wait for responses to all X commands issued so far for frame F. */
3992 XSync (FRAME_X_DISPLAY (f
), False
);
3997 /***********************************************************************
3999 ***********************************************************************/
4001 DEFUN ("x-change-window-property", Fx_change_window_property
,
4002 Sx_change_window_property
, 2, 6, 0,
4003 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
4004 PROP must be a string.
4005 VALUE may be a string or a list of conses, numbers and/or strings.
4006 If an element in the list is a string, it is converted to
4007 an Atom and the value of the Atom is used. If an element is a cons,
4008 it is converted to a 32 bit number where the car is the 16 top bits and the
4009 cdr is the lower 16 bits.
4010 FRAME nil or omitted means use the selected frame.
4011 If TYPE is given and non-nil, it is the name of the type of VALUE.
4012 If TYPE is not given or nil, the type is STRING.
4013 FORMAT gives the size in bits of each element if VALUE is a list.
4014 It must be one of 8, 16 or 32.
4015 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4016 If OUTER_P is non-nil, the property is changed for the outer X window of
4017 FRAME. Default is to change on the edit X window.
4020 (prop
, value
, frame
, type
, format
, outer_p
)
4021 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
4023 struct frame
*f
= check_x_frame (frame
);
4025 Atom target_type
= XA_STRING
;
4026 int element_format
= 8;
4027 unsigned char *data
;
4031 CHECK_STRING (prop
);
4033 if (! NILP (format
))
4035 CHECK_NUMBER (format
);
4036 element_format
= XFASTINT (format
);
4038 if (element_format
!= 8 && element_format
!= 16
4039 && element_format
!= 32)
4040 error ("FORMAT must be one of 8, 16 or 32");
4045 nelements
= x_check_property_data (value
);
4046 if (nelements
== -1)
4047 error ("Bad data in VALUE, must be number, string or cons");
4049 if (element_format
== 8)
4050 data
= (unsigned char *) xmalloc (nelements
);
4051 else if (element_format
== 16)
4052 data
= (unsigned char *) xmalloc (nelements
*2);
4054 data
= (unsigned char *) xmalloc (nelements
*4);
4056 x_fill_property_data (FRAME_X_DISPLAY (f
), value
, data
, element_format
);
4060 CHECK_STRING (value
);
4061 data
= SDATA (value
);
4062 nelements
= SCHARS (value
);
4066 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4069 CHECK_STRING (type
);
4070 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (type
), False
);
4073 if (! NILP (outer_p
)) w
= FRAME_OUTER_WINDOW (f
);
4074 else w
= FRAME_X_WINDOW (f
);
4076 XChangeProperty (FRAME_X_DISPLAY (f
), w
,
4077 prop_atom
, target_type
, element_format
, PropModeReplace
,
4080 if (CONSP (value
)) xfree (data
);
4082 /* Make sure the property is set when we return. */
4083 XFlush (FRAME_X_DISPLAY (f
));
4090 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
4091 Sx_delete_window_property
, 1, 2, 0,
4092 doc
: /* Remove window property PROP from X window of FRAME.
4093 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4095 Lisp_Object prop
, frame
;
4097 struct frame
*f
= check_x_frame (frame
);
4100 CHECK_STRING (prop
);
4102 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4103 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
4105 /* Make sure the property is removed when we return. */
4106 XFlush (FRAME_X_DISPLAY (f
));
4113 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
4115 doc
: /* Value is the value of window property PROP on FRAME.
4116 If FRAME is nil or omitted, use the selected frame.
4117 If TYPE is nil or omitted, get the property as a string. Otherwise TYPE
4118 is the name of the Atom that denotes the type expected.
4119 If SOURCE is non-nil, get the property on that window instead of from
4120 FRAME. The number 0 denotes the root window.
4121 If DELETE_P is non-nil, delete the property after retreiving it.
4122 If VECTOR_RET_P is non-nil, don't return a string but a vector of values.
4124 Value is nil if FRAME hasn't a property with name PROP or if PROP has
4125 no value of TYPE. */)
4126 (prop
, frame
, type
, source
, delete_p
, vector_ret_p
)
4127 Lisp_Object prop
, frame
, type
, source
, delete_p
, vector_ret_p
;
4129 struct frame
*f
= check_x_frame (frame
);
4132 Lisp_Object prop_value
= Qnil
;
4133 char *tmp_data
= NULL
;
4135 Atom target_type
= XA_STRING
;
4137 unsigned long actual_size
, bytes_remaining
;
4138 Window target_window
= FRAME_X_WINDOW (f
);
4139 struct gcpro gcpro1
;
4141 GCPRO1 (prop_value
);
4142 CHECK_STRING (prop
);
4144 if (! NILP (source
))
4146 if (NUMBERP (source
))
4148 if (FLOATP (source
))
4149 target_window
= (Window
) XFLOAT (source
);
4151 target_window
= XFASTINT (source
);
4153 if (target_window
== 0)
4154 target_window
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4156 else if (CONSP (source
))
4157 target_window
= cons_to_long (source
);
4163 if (strcmp ("AnyPropertyType", SDATA (type
)) == 0)
4164 target_type
= AnyPropertyType
;
4166 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (type
), False
);
4169 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4170 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4171 prop_atom
, 0, 0, False
, target_type
,
4172 &actual_type
, &actual_format
, &actual_size
,
4173 &bytes_remaining
, (unsigned char **) &tmp_data
);
4176 int size
= bytes_remaining
;
4181 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4182 prop_atom
, 0, bytes_remaining
,
4183 ! NILP (delete_p
), target_type
,
4184 &actual_type
, &actual_format
,
4185 &actual_size
, &bytes_remaining
,
4186 (unsigned char **) &tmp_data
);
4187 if (rc
== Success
&& tmp_data
)
4189 if (NILP (vector_ret_p
))
4190 prop_value
= make_string (tmp_data
, size
);
4192 prop_value
= x_property_data_to_lisp (f
,
4193 (unsigned char *) tmp_data
,
4199 if (tmp_data
) XFree (tmp_data
);
4209 /***********************************************************************
4211 ***********************************************************************/
4213 /* If non-null, an asynchronous timer that, when it expires, displays
4214 an hourglass cursor on all frames. */
4216 static struct atimer
*hourglass_atimer
;
4218 /* Non-zero means an hourglass cursor is currently shown. */
4220 static int hourglass_shown_p
;
4222 /* Number of seconds to wait before displaying an hourglass cursor. */
4224 static Lisp_Object Vhourglass_delay
;
4226 /* Default number of seconds to wait before displaying an hourglass
4229 #define DEFAULT_HOURGLASS_DELAY 1
4231 /* Function prototypes. */
4233 static void show_hourglass
P_ ((struct atimer
*));
4234 static void hide_hourglass
P_ ((void));
4237 /* Cancel a currently active hourglass timer, and start a new one. */
4243 int secs
, usecs
= 0;
4245 cancel_hourglass ();
4247 if (INTEGERP (Vhourglass_delay
)
4248 && XINT (Vhourglass_delay
) > 0)
4249 secs
= XFASTINT (Vhourglass_delay
);
4250 else if (FLOATP (Vhourglass_delay
)
4251 && XFLOAT_DATA (Vhourglass_delay
) > 0)
4254 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
4255 secs
= XFASTINT (tem
);
4256 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
4259 secs
= DEFAULT_HOURGLASS_DELAY
;
4261 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
4262 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
4263 show_hourglass
, NULL
);
4267 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
4273 if (hourglass_atimer
)
4275 cancel_atimer (hourglass_atimer
);
4276 hourglass_atimer
= NULL
;
4279 if (hourglass_shown_p
)
4284 /* Timer function of hourglass_atimer. TIMER is equal to
4287 Display an hourglass pointer on all frames by mapping the frames'
4288 hourglass_window. Set the hourglass_p flag in the frames'
4289 output_data.x structure to indicate that an hourglass cursor is
4290 shown on the frames. */
4293 show_hourglass (timer
)
4294 struct atimer
*timer
;
4296 /* The timer implementation will cancel this timer automatically
4297 after this function has run. Set hourglass_atimer to null
4298 so that we know the timer doesn't have to be canceled. */
4299 hourglass_atimer
= NULL
;
4301 if (!hourglass_shown_p
)
4303 Lisp_Object rest
, frame
;
4307 FOR_EACH_FRAME (rest
, frame
)
4309 struct frame
*f
= XFRAME (frame
);
4311 if (FRAME_LIVE_P (f
) && FRAME_X_P (f
) && FRAME_X_DISPLAY (f
))
4313 Display
*dpy
= FRAME_X_DISPLAY (f
);
4315 #ifdef USE_X_TOOLKIT
4316 if (f
->output_data
.x
->widget
)
4318 if (FRAME_OUTER_WINDOW (f
))
4321 f
->output_data
.x
->hourglass_p
= 1;
4323 if (!f
->output_data
.x
->hourglass_window
)
4325 unsigned long mask
= CWCursor
;
4326 XSetWindowAttributes attrs
;
4328 attrs
.cursor
= f
->output_data
.x
->hourglass_cursor
;
4330 f
->output_data
.x
->hourglass_window
4331 = XCreateWindow (dpy
, FRAME_OUTER_WINDOW (f
),
4332 0, 0, 32000, 32000, 0, 0,
4338 XMapRaised (dpy
, f
->output_data
.x
->hourglass_window
);
4344 hourglass_shown_p
= 1;
4350 /* Hide the hourglass pointer on all frames, if it is currently
4356 if (hourglass_shown_p
)
4358 Lisp_Object rest
, frame
;
4361 FOR_EACH_FRAME (rest
, frame
)
4363 struct frame
*f
= XFRAME (frame
);
4366 /* Watch out for newly created frames. */
4367 && f
->output_data
.x
->hourglass_window
)
4369 XUnmapWindow (FRAME_X_DISPLAY (f
),
4370 f
->output_data
.x
->hourglass_window
);
4371 /* Sync here because XTread_socket looks at the
4372 hourglass_p flag that is reset to zero below. */
4373 XSync (FRAME_X_DISPLAY (f
), False
);
4374 f
->output_data
.x
->hourglass_p
= 0;
4378 hourglass_shown_p
= 0;
4385 /***********************************************************************
4387 ***********************************************************************/
4389 static Lisp_Object x_create_tip_frame
P_ ((struct x_display_info
*,
4390 Lisp_Object
, Lisp_Object
));
4391 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
4392 Lisp_Object
, int, int, int *, int *));
4394 /* The frame of a currently visible tooltip. */
4396 Lisp_Object tip_frame
;
4398 /* If non-nil, a timer started that hides the last tooltip when it
4401 Lisp_Object tip_timer
;
4404 /* If non-nil, a vector of 3 elements containing the last args
4405 with which x-show-tip was called. See there. */
4407 Lisp_Object last_show_tip_args
;
4409 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
4411 Lisp_Object Vx_max_tooltip_size
;
4415 unwind_create_tip_frame (frame
)
4418 Lisp_Object deleted
;
4420 deleted
= unwind_create_frame (frame
);
4421 if (EQ (deleted
, Qt
))
4431 /* Create a frame for a tooltip on the display described by DPYINFO.
4432 PARMS is a list of frame parameters. TEXT is the string to
4433 display in the tip frame. Value is the frame.
4435 Note that functions called here, esp. x_default_parameter can
4436 signal errors, for instance when a specified color name is
4437 undefined. We have to make sure that we're in a consistent state
4438 when this happens. */
4441 x_create_tip_frame (dpyinfo
, parms
, text
)
4442 struct x_display_info
*dpyinfo
;
4443 Lisp_Object parms
, text
;
4446 Lisp_Object frame
, tem
;
4448 long window_prompting
= 0;
4450 int count
= SPECPDL_INDEX ();
4451 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4453 int face_change_count_before
= face_change_count
;
4455 struct buffer
*old_buffer
;
4459 /* Use this general default value to start with until we know if
4460 this frame has a specified name. */
4461 Vx_resource_name
= Vinvocation_name
;
4464 kb
= dpyinfo
->kboard
;
4466 kb
= &the_only_kboard
;
4469 /* Get the name of the frame to use for resource lookup. */
4470 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
4472 && !EQ (name
, Qunbound
)
4474 error ("Invalid frame name--not a string or nil");
4475 Vx_resource_name
= name
;
4478 GCPRO3 (parms
, name
, frame
);
4480 XSETFRAME (frame
, f
);
4482 buffer
= Fget_buffer_create (build_string (" *tip*"));
4483 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
4484 old_buffer
= current_buffer
;
4485 set_buffer_internal_1 (XBUFFER (buffer
));
4486 current_buffer
->truncate_lines
= Qnil
;
4487 specbind (Qinhibit_read_only
, Qt
);
4488 specbind (Qinhibit_modification_hooks
, Qt
);
4491 set_buffer_internal_1 (old_buffer
);
4493 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
4494 record_unwind_protect (unwind_create_tip_frame
, frame
);
4496 f
->display
= dpyinfo
->frame_display
;
4497 f
->display
->reference_count
++;
4499 /* By setting the output method, we're essentially saying that
4500 the frame is live, as per FRAME_LIVE_P. If we get a signal
4501 from this point on, x_destroy_window might screw up reference
4503 f
->output_method
= output_x_window
;
4504 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
4505 bzero (f
->output_data
.x
, sizeof (struct x_output
));
4506 f
->output_data
.x
->icon_bitmap
= -1;
4507 FRAME_FONTSET (f
) = -1;
4508 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
4509 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
4510 #ifdef USE_TOOLKIT_SCROLL_BARS
4511 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
4512 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
4513 #endif /* USE_TOOLKIT_SCROLL_BARS */
4514 f
->icon_name
= Qnil
;
4515 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
4517 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
4518 dpyinfo_refcount
= dpyinfo
->reference_count
;
4519 #endif /* GLYPH_DEBUG */
4521 FRAME_KBOARD (f
) = kb
;
4523 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4524 f
->output_data
.x
->explicit_parent
= 0;
4526 /* These colors will be set anyway later, but it's important
4527 to get the color reference counts right, so initialize them! */
4530 struct gcpro gcpro1
;
4532 black
= build_string ("black");
4534 f
->output_data
.x
->foreground_pixel
4535 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4536 f
->output_data
.x
->background_pixel
4537 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4538 f
->output_data
.x
->cursor_pixel
4539 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4540 f
->output_data
.x
->cursor_foreground_pixel
4541 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4542 f
->output_data
.x
->border_pixel
4543 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4544 f
->output_data
.x
->mouse_pixel
4545 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4549 /* Set the name; the functions to which we pass f expect the name to
4551 if (EQ (name
, Qunbound
) || NILP (name
))
4553 f
->name
= build_string (dpyinfo
->x_id_name
);
4554 f
->explicit_name
= 0;
4559 f
->explicit_name
= 1;
4560 /* use the frame's title when getting resources for this frame. */
4561 specbind (Qx_resource_name
, name
);
4564 /* Extract the window parameters from the supplied values that are
4565 needed to determine window geometry. */
4569 font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4572 /* First, try whatever font the caller has specified. */
4575 tem
= Fquery_fontset (font
, Qnil
);
4577 font
= x_new_fontset (f
, SDATA (tem
));
4579 font
= x_new_font (f
, SDATA (font
));
4582 /* Try out a font which we hope has bold and italic variations. */
4583 if (!STRINGP (font
))
4584 font
= x_new_font (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
4585 if (!STRINGP (font
))
4586 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
4587 if (! STRINGP (font
))
4588 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
4589 if (! STRINGP (font
))
4590 /* This was formerly the first thing tried, but it finds too many fonts
4591 and takes too long. */
4592 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
4593 /* If those didn't work, look for something which will at least work. */
4594 if (! STRINGP (font
))
4595 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
4597 if (! STRINGP (font
))
4598 font
= build_string ("fixed");
4600 x_default_parameter (f
, parms
, Qfont
, font
,
4601 "font", "Font", RES_TYPE_STRING
);
4604 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
4605 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4607 /* This defaults to 2 in order to match xterm. We recognize either
4608 internalBorderWidth or internalBorder (which is what xterm calls
4610 if (NILP (Fassq (Qinternal_border_width
, parms
)))
4614 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
4615 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
4616 if (! EQ (value
, Qunbound
))
4617 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
4621 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
4622 "internalBorderWidth", "internalBorderWidth",
4625 /* Also do the stuff which must be set before the window exists. */
4626 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
4627 "foreground", "Foreground", RES_TYPE_STRING
);
4628 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
4629 "background", "Background", RES_TYPE_STRING
);
4630 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
4631 "pointerColor", "Foreground", RES_TYPE_STRING
);
4632 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
4633 "cursorColor", "Foreground", RES_TYPE_STRING
);
4634 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
4635 "borderColor", "BorderColor", RES_TYPE_STRING
);
4637 /* Init faces before x_default_parameter is called for scroll-bar
4638 parameters because that function calls x_set_scroll_bar_width,
4639 which calls change_frame_size, which calls Fset_window_buffer,
4640 which runs hooks, which call Fvertical_motion. At the end, we
4641 end up in init_iterator with a null face cache, which should not
4643 init_frame_faces (f
);
4645 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4647 window_prompting
= x_figure_window_size (f
, parms
, 0);
4650 XSetWindowAttributes attrs
;
4654 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
;
4655 if (DoesSaveUnders (dpyinfo
->screen
))
4656 mask
|= CWSaveUnder
;
4658 /* Window managers look at the override-redirect flag to determine
4659 whether or net to give windows a decoration (Xlib spec, chapter
4661 attrs
.override_redirect
= True
;
4662 attrs
.save_under
= True
;
4663 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
4664 /* Arrange for getting MapNotify and UnmapNotify events. */
4665 attrs
.event_mask
= StructureNotifyMask
;
4667 = FRAME_X_WINDOW (f
)
4668 = XCreateWindow (FRAME_X_DISPLAY (f
),
4669 FRAME_X_DISPLAY_INFO (f
)->root_window
,
4670 /* x, y, width, height */
4674 CopyFromParent
, InputOutput
, CopyFromParent
,
4681 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
4682 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4683 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
4684 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4685 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
4686 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4688 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4689 Change will not be effected unless different from the current
4691 width
= FRAME_COLS (f
);
4692 height
= FRAME_LINES (f
);
4693 SET_FRAME_COLS (f
, 0);
4694 FRAME_LINES (f
) = 0;
4695 change_frame_size (f
, height
, width
, 1, 0, 0);
4697 /* Add `tooltip' frame parameter's default value. */
4698 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
4699 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
4702 /* Set up faces after all frame parameters are known. This call
4703 also merges in face attributes specified for new frames.
4705 Frame parameters may be changed if .Xdefaults contains
4706 specifications for the default font. For example, if there is an
4707 `Emacs.default.attributeBackground: pink', the `background-color'
4708 attribute of the frame get's set, which let's the internal border
4709 of the tooltip frame appear in pink. Prevent this. */
4711 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
4713 /* Set tip_frame here, so that */
4715 call1 (Qface_set_after_frame_default
, frame
);
4717 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
4718 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
4722 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qwindow_system
, Qx
), Qnil
));
4728 /* It is now ok to make the frame official even if we get an error
4729 below. And the frame needs to be on Vframe_list or making it
4730 visible won't work. */
4731 Vframe_list
= Fcons (frame
, Vframe_list
);
4733 /* Now that the frame is official, it counts as a reference to
4735 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
4737 /* Setting attributes of faces of the tooltip frame from resources
4738 and similar will increment face_change_count, which leads to the
4739 clearing of all current matrices. Since this isn't necessary
4740 here, avoid it by resetting face_change_count to the value it
4741 had before we created the tip frame. */
4742 face_change_count
= face_change_count_before
;
4744 /* Discard the unwind_protect. */
4745 return unbind_to (count
, frame
);
4749 /* Compute where to display tip frame F. PARMS is the list of frame
4750 parameters for F. DX and DY are specified offsets from the current
4751 location of the mouse. WIDTH and HEIGHT are the width and height
4752 of the tooltip. Return coordinates relative to the root window of
4753 the display in *ROOT_X, and *ROOT_Y. */
4756 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
4758 Lisp_Object parms
, dx
, dy
;
4760 int *root_x
, *root_y
;
4762 Lisp_Object left
, top
;
4767 /* User-specified position? */
4768 left
= Fcdr (Fassq (Qleft
, parms
));
4769 top
= Fcdr (Fassq (Qtop
, parms
));
4771 /* Move the tooltip window where the mouse pointer is. Resize and
4773 if (!INTEGERP (left
) || !INTEGERP (top
))
4776 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
4777 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
4782 *root_y
= XINT (top
);
4783 else if (*root_y
+ XINT (dy
) - height
< 0)
4784 *root_y
-= XINT (dy
);
4788 *root_y
+= XINT (dy
);
4791 if (INTEGERP (left
))
4792 *root_x
= XINT (left
);
4793 else if (*root_x
+ XINT (dx
) + width
<= FRAME_X_DISPLAY_INFO (f
)->width
)
4794 /* It fits to the right of the pointer. */
4795 *root_x
+= XINT (dx
);
4796 else if (width
+ XINT (dx
) <= *root_x
)
4797 /* It fits to the left of the pointer. */
4798 *root_x
-= width
+ XINT (dx
);
4800 /* Put it left-justified on the screen--it ought to fit that way. */
4805 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
4806 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
4807 A tooltip window is a small X window displaying a string.
4809 FRAME nil or omitted means use the selected frame.
4811 PARMS is an optional list of frame parameters which can be used to
4812 change the tooltip's appearance.
4814 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
4815 means use the default timeout of 5 seconds.
4817 If the list of frame parameters PARAMS contains a `left' parameters,
4818 the tooltip is displayed at that x-position. Otherwise it is
4819 displayed at the mouse position, with offset DX added (default is 5 if
4820 DX isn't specified). Likewise for the y-position; if a `top' frame
4821 parameter is specified, it determines the y-position of the tooltip
4822 window, otherwise it is displayed at the mouse position, with offset
4823 DY added (default is -10).
4825 A tooltip's maximum size is specified by `x-max-tooltip-size'.
4826 Text larger than the specified size is clipped. */)
4827 (string
, frame
, parms
, timeout
, dx
, dy
)
4828 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
4833 struct buffer
*old_buffer
;
4834 struct text_pos pos
;
4835 int i
, width
, height
;
4836 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4837 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
4838 int count
= SPECPDL_INDEX ();
4840 specbind (Qinhibit_redisplay
, Qt
);
4842 GCPRO4 (string
, parms
, frame
, timeout
);
4844 CHECK_STRING (string
);
4845 f
= check_x_frame (frame
);
4847 timeout
= make_number (5);
4849 CHECK_NATNUM (timeout
);
4852 dx
= make_number (5);
4857 dy
= make_number (-10);
4861 if (NILP (last_show_tip_args
))
4862 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
4864 if (!NILP (tip_frame
))
4866 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
4867 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
4868 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
4870 if (EQ (frame
, last_frame
)
4871 && !NILP (Fequal (last_string
, string
))
4872 && !NILP (Fequal (last_parms
, parms
)))
4874 struct frame
*f
= XFRAME (tip_frame
);
4876 /* Only DX and DY have changed. */
4877 if (!NILP (tip_timer
))
4879 Lisp_Object timer
= tip_timer
;
4881 call1 (Qcancel_timer
, timer
);
4885 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
4886 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
4887 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4894 /* Hide a previous tip, if any. */
4897 ASET (last_show_tip_args
, 0, string
);
4898 ASET (last_show_tip_args
, 1, frame
);
4899 ASET (last_show_tip_args
, 2, parms
);
4901 /* Add default values to frame parameters. */
4902 if (NILP (Fassq (Qname
, parms
)))
4903 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
4904 if (NILP (Fassq (Qinternal_border_width
, parms
)))
4905 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
4906 if (NILP (Fassq (Qborder_width
, parms
)))
4907 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
4908 if (NILP (Fassq (Qborder_color
, parms
)))
4909 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
4910 if (NILP (Fassq (Qbackground_color
, parms
)))
4911 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
4914 /* Create a frame for the tooltip, and record it in the global
4915 variable tip_frame. */
4916 frame
= x_create_tip_frame (FRAME_X_DISPLAY_INFO (f
), parms
, string
);
4919 /* Set up the frame's root window. */
4920 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4921 w
->left_col
= w
->top_line
= make_number (0);
4923 if (CONSP (Vx_max_tooltip_size
)
4924 && INTEGERP (XCAR (Vx_max_tooltip_size
))
4925 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
4926 && INTEGERP (XCDR (Vx_max_tooltip_size
))
4927 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
4929 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
4930 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
4934 w
->total_cols
= make_number (80);
4935 w
->total_lines
= make_number (40);
4938 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
4940 w
->pseudo_window_p
= 1;
4942 /* Display the tooltip text in a temporary buffer. */
4943 old_buffer
= current_buffer
;
4944 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
4945 current_buffer
->truncate_lines
= Qnil
;
4946 clear_glyph_matrix (w
->desired_matrix
);
4947 clear_glyph_matrix (w
->current_matrix
);
4948 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
4949 try_window (FRAME_ROOT_WINDOW (f
), pos
);
4951 /* Compute width and height of the tooltip. */
4953 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
4955 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
4959 /* Stop at the first empty row at the end. */
4960 if (!row
->enabled_p
|| !row
->displays_text_p
)
4963 /* Let the row go over the full width of the frame. */
4964 row
->full_width_p
= 1;
4966 /* There's a glyph at the end of rows that is used to place
4967 the cursor there. Don't include the width of this glyph. */
4968 if (row
->used
[TEXT_AREA
])
4970 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
4971 row_width
= row
->pixel_width
- last
->pixel_width
;
4974 row_width
= row
->pixel_width
;
4976 height
+= row
->height
;
4977 width
= max (width
, row_width
);
4980 /* Add the frame's internal border to the width and height the X
4981 window should have. */
4982 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
4983 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
4985 /* Move the tooltip window where the mouse pointer is. Resize and
4987 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
4990 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4991 root_x
, root_y
, width
, height
);
4992 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
4995 /* Draw into the window. */
4996 w
->must_be_updated_p
= 1;
4997 update_single_window (w
, 1);
4999 /* Restore original current buffer. */
5000 set_buffer_internal_1 (old_buffer
);
5001 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5004 /* Let the tip disappear after timeout seconds. */
5005 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5006 intern ("x-hide-tip"));
5009 return unbind_to (count
, Qnil
);
5013 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5014 doc
: /* Hide the current tooltip window, if there is any.
5015 Value is t if tooltip was open, nil otherwise. */)
5019 Lisp_Object deleted
, frame
, timer
;
5020 struct gcpro gcpro1
, gcpro2
;
5022 /* Return quickly if nothing to do. */
5023 if (NILP (tip_timer
) && NILP (tip_frame
))
5028 GCPRO2 (frame
, timer
);
5029 tip_frame
= tip_timer
= deleted
= Qnil
;
5031 count
= SPECPDL_INDEX ();
5032 specbind (Qinhibit_redisplay
, Qt
);
5033 specbind (Qinhibit_quit
, Qt
);
5036 call1 (Qcancel_timer
, timer
);
5040 Fdelete_frame (frame
, Qnil
);
5044 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5045 redisplay procedure is not called when a tip frame over menu
5046 items is unmapped. Redisplay the menu manually... */
5048 struct frame
*f
= SELECTED_FRAME ();
5049 Widget w
= f
->output_data
.x
->menubar_widget
;
5050 extern void xlwmenu_redisplay
P_ ((Widget
));
5052 if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f
)->screen
)
5056 xlwmenu_redisplay (w
);
5060 #endif /* USE_LUCID */
5064 return unbind_to (count
, deleted
);
5069 /***********************************************************************
5070 File selection dialog
5071 ***********************************************************************/
5075 /* Callback for "OK" and "Cancel" on file selection dialog. */
5078 file_dialog_cb (widget
, client_data
, call_data
)
5080 XtPointer call_data
, client_data
;
5082 int *result
= (int *) client_data
;
5083 XmAnyCallbackStruct
*cb
= (XmAnyCallbackStruct
*) call_data
;
5084 *result
= cb
->reason
;
5088 /* Callback for unmapping a file selection dialog. This is used to
5089 capture the case where a dialog is closed via a window manager's
5090 closer button, for example. Using a XmNdestroyCallback didn't work
5094 file_dialog_unmap_cb (widget
, client_data
, call_data
)
5096 XtPointer call_data
, client_data
;
5098 int *result
= (int *) client_data
;
5099 *result
= XmCR_CANCEL
;
5103 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
5104 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5105 Use a file selection dialog.
5106 Select DEFAULT-FILENAME in the dialog's file selection box, if
5107 specified. Don't let the user enter a file name in the file
5108 selection dialog's entry field, if MUSTMATCH is non-nil. */)
5109 (prompt
, dir
, default_filename
, mustmatch
)
5110 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
5113 struct frame
*f
= SELECTED_FRAME ();
5114 Lisp_Object file
= Qnil
;
5115 Widget dialog
, text
, list
, help
;
5118 extern XtAppContext Xt_app_con
;
5119 XmString dir_xmstring
, pattern_xmstring
;
5120 int count
= SPECPDL_INDEX ();
5121 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
5123 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
5124 CHECK_STRING (prompt
);
5127 /* Prevent redisplay. */
5128 specbind (Qinhibit_redisplay
, Qt
);
5132 /* Create the dialog with PROMPT as title, using DIR as initial
5133 directory and using "*" as pattern. */
5134 dir
= Fexpand_file_name (dir
, Qnil
);
5135 dir_xmstring
= XmStringCreateLocalized (SDATA (dir
));
5136 pattern_xmstring
= XmStringCreateLocalized ("*");
5138 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
5139 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
5140 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
5141 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
5142 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
5143 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
5145 XmStringFree (dir_xmstring
);
5146 XmStringFree (pattern_xmstring
);
5148 /* Add callbacks for OK and Cancel. */
5149 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
5150 (XtPointer
) &result
);
5151 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
5152 (XtPointer
) &result
);
5153 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
5154 (XtPointer
) &result
);
5156 /* Disable the help button since we can't display help. */
5157 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
5158 XtSetSensitive (help
, False
);
5160 /* Mark OK button as default. */
5161 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
5162 XmNshowAsDefault
, True
, NULL
);
5164 /* If MUSTMATCH is non-nil, disable the file entry field of the
5165 dialog, so that the user must select a file from the files list
5166 box. We can't remove it because we wouldn't have a way to get at
5167 the result file name, then. */
5168 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5169 if (!NILP (mustmatch
))
5172 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
5173 XtSetSensitive (text
, False
);
5174 XtSetSensitive (label
, False
);
5177 /* Manage the dialog, so that list boxes get filled. */
5178 XtManageChild (dialog
);
5180 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5181 must include the path for this to work. */
5182 list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
5183 if (STRINGP (default_filename
))
5185 XmString default_xmstring
;
5189 = XmStringCreateLocalized (SDATA (default_filename
));
5191 if (!XmListItemExists (list
, default_xmstring
))
5193 /* Add a new item if DEFAULT_FILENAME is not in the list. */
5194 XmListAddItem (list
, default_xmstring
, 0);
5198 item_pos
= XmListItemPos (list
, default_xmstring
);
5199 XmStringFree (default_xmstring
);
5201 /* Select the item and scroll it into view. */
5202 XmListSelectPos (list
, item_pos
, True
);
5203 XmListSetPos (list
, item_pos
);
5206 /* Process events until the user presses Cancel or OK. */
5211 XtAppNextEvent (Xt_app_con
, &event
);
5212 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
) );
5215 /* Get the result. */
5216 if (result
== XmCR_OK
)
5221 XtVaGetValues (dialog
, XmNtextString
, &text
, NULL
);
5222 XmStringGetLtoR (text
, XmFONTLIST_DEFAULT_TAG
, &data
);
5223 XmStringFree (text
);
5224 file
= build_string (data
);
5231 XtUnmanageChild (dialog
);
5232 XtDestroyWidget (dialog
);
5236 /* Make "Cancel" equivalent to C-g. */
5238 Fsignal (Qquit
, Qnil
);
5240 return unbind_to (count
, file
);
5243 #endif /* USE_MOTIF */
5247 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
5248 "Read file name, prompting with PROMPT in directory DIR.\n\
5249 Use a file selection dialog.\n\
5250 Select DEFAULT-FILENAME in the dialog's file selection box, if\n\
5251 specified. Don't let the user enter a file name in the file\n\
5252 selection dialog's entry field, if MUSTMATCH is non-nil.")
5253 (prompt
, dir
, default_filename
, mustmatch
)
5254 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
5256 FRAME_PTR f
= SELECTED_FRAME ();
5258 Lisp_Object file
= Qnil
;
5259 int count
= specpdl_ptr
- specpdl
;
5260 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
5263 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
5264 CHECK_STRING (prompt
);
5267 /* Prevent redisplay. */
5268 specbind (Qinhibit_redisplay
, Qt
);
5272 if (STRINGP (default_filename
))
5273 cdef_file
= SDATA (default_filename
);
5275 cdef_file
= SDATA (dir
);
5277 fn
= xg_get_file_name (f
, SDATA (prompt
), cdef_file
, ! NILP (mustmatch
));
5281 file
= build_string (fn
);
5288 /* Make "Cancel" equivalent to C-g. */
5290 Fsignal (Qquit
, Qnil
);
5292 return unbind_to (count
, file
);
5295 #endif /* USE_GTK */
5298 /***********************************************************************
5300 ***********************************************************************/
5302 #ifdef HAVE_XKBGETKEYBOARD
5303 #include <X11/XKBlib.h>
5304 #include <X11/keysym.h>
5307 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
5308 Sx_backspace_delete_keys_p
, 0, 1, 0,
5309 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
5310 FRAME nil means use the selected frame.
5311 Value is t if we know that both keys are present, and are mapped to the
5312 usual X keysyms. */)
5316 #ifdef HAVE_XKBGETKEYBOARD
5318 struct frame
*f
= check_x_frame (frame
);
5319 Display
*dpy
= FRAME_X_DISPLAY (f
);
5320 Lisp_Object have_keys
;
5321 int major
, minor
, op
, event
, error
;
5325 /* Check library version in case we're dynamically linked. */
5326 major
= XkbMajorVersion
;
5327 minor
= XkbMinorVersion
;
5328 if (!XkbLibraryVersion (&major
, &minor
))
5334 /* Check that the server supports XKB. */
5335 major
= XkbMajorVersion
;
5336 minor
= XkbMinorVersion
;
5337 if (!XkbQueryExtension (dpy
, &op
, &event
, &error
, &major
, &minor
))
5344 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
5347 int delete_keycode
= 0, backspace_keycode
= 0, i
;
5349 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
5351 for (i
= kb
->min_key_code
;
5352 (i
< kb
->max_key_code
5353 && (delete_keycode
== 0 || backspace_keycode
== 0));
5356 /* The XKB symbolic key names can be seen most easily in
5357 the PS file generated by `xkbprint -label name
5359 if (bcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
5361 else if (bcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
5362 backspace_keycode
= i
;
5365 XkbFreeNames (kb
, 0, True
);
5368 XkbFreeClientMap (kb
, 0, True
);
5371 && backspace_keycode
5372 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
5373 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
5378 #else /* not HAVE_XKBGETKEYBOARD */
5380 #endif /* not HAVE_XKBGETKEYBOARD */
5385 /***********************************************************************
5387 ***********************************************************************/
5389 /* Keep this list in the same order as frame_parms in frame.c.
5390 Use 0 for unsupported frame parameters. */
5392 frame_parm_handler x_frame_parm_handlers
[] =
5396 x_set_background_color
,
5402 x_set_foreground_color
,
5405 x_set_internal_border_width
,
5406 x_set_menu_bar_lines
,
5408 x_explicitly_set_name
,
5409 x_set_scroll_bar_width
,
5412 x_set_vertical_scroll_bars
,
5414 x_set_tool_bar_lines
,
5415 x_set_scroll_bar_foreground
,
5416 x_set_scroll_bar_background
,
5428 /* This is zero if not using X windows. */
5431 /* The section below is built by the lisp expression at the top of the file,
5432 just above where these variables are declared. */
5433 /*&&& init symbols here &&&*/
5434 Qnone
= intern ("none");
5436 Qsuppress_icon
= intern ("suppress-icon");
5437 staticpro (&Qsuppress_icon
);
5438 Qundefined_color
= intern ("undefined-color");
5439 staticpro (&Qundefined_color
);
5440 Qcompound_text
= intern ("compound-text");
5441 staticpro (&Qcompound_text
);
5442 Qcancel_timer
= intern ("cancel-timer");
5443 staticpro (&Qcancel_timer
);
5444 /* This is the end of symbol initialization. */
5446 /* Text property `display' should be nonsticky by default. */
5447 Vtext_property_default_nonsticky
5448 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
5451 Fput (Qundefined_color
, Qerror_conditions
,
5452 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
5453 Fput (Qundefined_color
, Qerror_message
,
5454 build_string ("Undefined color"));
5456 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
5457 doc
: /* The shape of the pointer when over text.
5458 Changing the value does not affect existing frames
5459 unless you set the mouse color. */);
5460 Vx_pointer_shape
= Qnil
;
5462 #if 0 /* This doesn't really do anything. */
5463 DEFVAR_LISP ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape
,
5464 doc
: /* The shape of the pointer when not over text.
5465 This variable takes effect when you create a new frame
5466 or when you set the mouse color. */);
5468 Vx_nontext_pointer_shape
= Qnil
;
5470 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
5471 doc
: /* The shape of the pointer when Emacs is busy.
5472 This variable takes effect when you create a new frame
5473 or when you set the mouse color. */);
5474 Vx_hourglass_pointer_shape
= Qnil
;
5476 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
5477 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
5478 display_hourglass_p
= 1;
5480 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
5481 doc
: /* *Seconds to wait before displaying an hourglass pointer.
5482 Value must be an integer or float. */);
5483 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
5485 #if 0 /* This doesn't really do anything. */
5486 DEFVAR_LISP ("x-mode-pointer-shape", &Vx_mode_pointer_shape
,
5487 doc
: /* The shape of the pointer when over the mode line.
5488 This variable takes effect when you create a new frame
5489 or when you set the mouse color. */);
5491 Vx_mode_pointer_shape
= Qnil
;
5493 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
5494 &Vx_sensitive_text_pointer_shape
,
5495 doc
: /* The shape of the pointer when over mouse-sensitive text.
5496 This variable takes effect when you create a new frame
5497 or when you set the mouse color. */);
5498 Vx_sensitive_text_pointer_shape
= Qnil
;
5500 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
5501 &Vx_window_horizontal_drag_shape
,
5502 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
5503 This variable takes effect when you create a new frame
5504 or when you set the mouse color. */);
5505 Vx_window_horizontal_drag_shape
= Qnil
;
5507 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
5508 doc
: /* A string indicating the foreground color of the cursor box. */);
5509 Vx_cursor_fore_pixel
= Qnil
;
5511 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
5512 doc
: /* Maximum size for tooltips. Value is a pair (COLUMNS . ROWS).
5513 Text larger than this is clipped. */);
5514 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
5516 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
5517 doc
: /* Non-nil if no X window manager is in use.
5518 Emacs doesn't try to figure this out; this is always nil
5519 unless you set it to something else. */);
5520 /* We don't have any way to find this out, so set it to nil
5521 and maybe the user would like to set it to t. */
5522 Vx_no_window_manager
= Qnil
;
5524 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
5525 &Vx_pixel_size_width_font_regexp
,
5526 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
5528 Since Emacs gets width of a font matching with this regexp from
5529 PIXEL_SIZE field of the name, font finding mechanism gets faster for
5530 such a font. This is especially effective for such large fonts as
5531 Chinese, Japanese, and Korean. */);
5532 Vx_pixel_size_width_font_regexp
= Qnil
;
5534 #ifdef USE_X_TOOLKIT
5535 Fprovide (intern ("x-toolkit"), Qnil
);
5537 Fprovide (intern ("motif"), Qnil
);
5539 DEFVAR_LISP ("motif-version-string", &Vmotif_version_string
,
5540 doc
: /* Version info for LessTif/Motif. */);
5541 Vmotif_version_string
= build_string (XmVERSION_STRING
);
5542 #endif /* USE_MOTIF */
5543 #endif /* USE_X_TOOLKIT */
5546 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
5547 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
5548 But for a user it is a toolkit for X, and indeed, configure
5549 accepts --with-x-toolkit=gtk. */
5550 Fprovide (intern ("x-toolkit"), Qnil
);
5551 Fprovide (intern ("gtk"), Qnil
);
5553 DEFVAR_LISP ("gtk-version-string", &Vgtk_version_string
,
5554 doc
: /* Version info for GTK+. */);
5556 char gtk_version
[40];
5557 g_snprintf (gtk_version
, sizeof (gtk_version
), "%u.%u.%u",
5558 GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
);
5559 Vgtk_version_string
= build_string (gtk_version
);
5561 #endif /* USE_GTK */
5563 /* X window properties. */
5564 defsubr (&Sx_change_window_property
);
5565 defsubr (&Sx_delete_window_property
);
5566 defsubr (&Sx_window_property
);
5568 defsubr (&Sxw_display_color_p
);
5569 defsubr (&Sx_display_grayscale_p
);
5570 defsubr (&Sxw_color_defined_p
);
5571 defsubr (&Sxw_color_values
);
5572 defsubr (&Sx_server_max_request_size
);
5573 defsubr (&Sx_server_vendor
);
5574 defsubr (&Sx_server_version
);
5575 defsubr (&Sx_display_pixel_width
);
5576 defsubr (&Sx_display_pixel_height
);
5577 defsubr (&Sx_display_mm_width
);
5578 defsubr (&Sx_display_mm_height
);
5579 defsubr (&Sx_display_screens
);
5580 defsubr (&Sx_display_planes
);
5581 defsubr (&Sx_display_color_cells
);
5582 defsubr (&Sx_display_visual_class
);
5583 defsubr (&Sx_display_backing_store
);
5584 defsubr (&Sx_display_save_under
);
5585 defsubr (&Sx_create_frame
);
5586 defsubr (&Sx_open_connection
);
5587 defsubr (&Sx_close_connection
);
5588 defsubr (&Sx_display_list
);
5589 defsubr (&Sx_synchronize
);
5590 defsubr (&Sx_focus_frame
);
5591 defsubr (&Sx_backspace_delete_keys_p
);
5593 /* Setting callback functions for fontset handler. */
5594 get_font_info_func
= x_get_font_info
;
5596 #if 0 /* This function pointer doesn't seem to be used anywhere.
5597 And the pointer assigned has the wrong type, anyway. */
5598 list_fonts_func
= x_list_fonts
;
5601 load_font_func
= x_load_font
;
5602 find_ccl_program_func
= x_find_ccl_program
;
5603 query_font_func
= x_query_font
;
5604 set_frame_fontset_func
= x_set_font
;
5605 check_window_system_func
= check_x
;
5607 hourglass_atimer
= NULL
;
5608 hourglass_shown_p
= 0;
5610 defsubr (&Sx_show_tip
);
5611 defsubr (&Sx_hide_tip
);
5613 staticpro (&tip_timer
);
5615 staticpro (&tip_frame
);
5617 last_show_tip_args
= Qnil
;
5618 staticpro (&last_show_tip_args
);
5621 defsubr (&Sx_file_dialog
);
5625 #endif /* HAVE_X_WINDOWS */
5627 /* arch-tag: 55040d02-5485-4d58-8b22-95a7a05f3288
5628 (do not change this comment) */