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"
45 #include "character.h"
50 #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 (STRINGP (frame
))
261 dpyinfo
= x_display_info_for_name (frame
);
264 FRAME_PTR f
= check_x_frame (frame
);
265 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
272 /* Return the Emacs frame-object corresponding to an X window.
273 It could be the frame's main window or an icon window. */
275 /* This function can be called during GC, so use GC_xxx type test macros. */
278 x_window_to_frame (dpyinfo
, wdesc
)
279 struct x_display_info
*dpyinfo
;
282 Lisp_Object tail
, frame
;
285 if (wdesc
== None
) return 0;
287 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
290 if (!GC_FRAMEP (frame
))
293 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
295 if (f
->output_data
.x
->hourglass_window
== wdesc
)
298 if ((f
->output_data
.x
->edit_widget
299 && XtWindow (f
->output_data
.x
->edit_widget
) == wdesc
)
300 /* A tooltip frame? */
301 || (!f
->output_data
.x
->edit_widget
302 && FRAME_X_WINDOW (f
) == wdesc
)
303 || f
->output_data
.x
->icon_desc
== wdesc
)
305 #else /* not USE_X_TOOLKIT */
307 if (f
->output_data
.x
->edit_widget
)
309 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
310 struct x_output
*x
= f
->output_data
.x
;
311 if (gwdesc
!= 0 && gwdesc
== x
->edit_widget
)
315 if (FRAME_X_WINDOW (f
) == wdesc
316 || f
->output_data
.x
->icon_desc
== wdesc
)
318 #endif /* not USE_X_TOOLKIT */
323 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
324 /* Like x_window_to_frame but also compares the window with the widget's
328 x_any_window_to_frame (dpyinfo
, wdesc
)
329 struct x_display_info
*dpyinfo
;
332 Lisp_Object tail
, frame
;
333 struct frame
*f
, *found
;
336 if (wdesc
== None
) return NULL
;
339 for (tail
= Vframe_list
; GC_CONSP (tail
) && !found
; tail
= XCDR (tail
))
342 if (!GC_FRAMEP (frame
))
346 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
348 /* This frame matches if the window is any of its widgets. */
349 x
= f
->output_data
.x
;
350 if (x
->hourglass_window
== wdesc
)
355 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
357 && (gwdesc
== x
->widget
358 || gwdesc
== x
->edit_widget
359 || gwdesc
== x
->vbox_widget
360 || gwdesc
== x
->menubar_widget
))
363 if (wdesc
== XtWindow (x
->widget
)
364 || wdesc
== XtWindow (x
->column_widget
)
365 || wdesc
== XtWindow (x
->edit_widget
))
367 /* Match if the window is this frame's menubar. */
368 else if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
372 else if (FRAME_X_WINDOW (f
) == wdesc
)
373 /* A tooltip frame. */
381 /* Likewise, but exclude the menu bar widget. */
384 x_non_menubar_window_to_frame (dpyinfo
, wdesc
)
385 struct x_display_info
*dpyinfo
;
388 Lisp_Object tail
, frame
;
392 if (wdesc
== None
) return 0;
394 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
397 if (!GC_FRAMEP (frame
))
400 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
402 x
= f
->output_data
.x
;
403 /* This frame matches if the window is any of its widgets. */
404 if (x
->hourglass_window
== wdesc
)
409 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
411 && (gwdesc
== x
->widget
412 || gwdesc
== x
->edit_widget
413 || gwdesc
== x
->vbox_widget
))
416 if (wdesc
== XtWindow (x
->widget
)
417 || wdesc
== XtWindow (x
->column_widget
)
418 || wdesc
== XtWindow (x
->edit_widget
))
422 else if (FRAME_X_WINDOW (f
) == wdesc
)
423 /* A tooltip frame. */
429 /* Likewise, but consider only the menu bar widget. */
432 x_menubar_window_to_frame (dpyinfo
, wdesc
)
433 struct x_display_info
*dpyinfo
;
436 Lisp_Object tail
, frame
;
440 if (wdesc
== None
) return 0;
442 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
445 if (!GC_FRAMEP (frame
))
448 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
450 x
= f
->output_data
.x
;
451 /* Match if the window is this frame's menubar. */
453 if (x
->menubar_widget
)
455 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
460 && (gwdesc
== x
->menubar_widget
461 || gtk_widget_get_parent (gwdesc
) == x
->menubar_widget
))
467 if (x
->menubar_widget
468 && lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
475 /* Return the frame whose principal (outermost) window is WDESC.
476 If WDESC is some other (smaller) window, we return 0. */
479 x_top_window_to_frame (dpyinfo
, wdesc
)
480 struct x_display_info
*dpyinfo
;
483 Lisp_Object tail
, frame
;
487 if (wdesc
== None
) return 0;
489 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
492 if (!GC_FRAMEP (frame
))
495 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
497 x
= f
->output_data
.x
;
501 /* This frame matches if the window is its topmost widget. */
503 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
504 if (gwdesc
== x
->widget
)
507 if (wdesc
== XtWindow (x
->widget
))
509 #if 0 /* I don't know why it did this,
510 but it seems logically wrong,
511 and it causes trouble for MapNotify events. */
512 /* Match if the window is this frame's menubar. */
513 if (x
->menubar_widget
514 && wdesc
== XtWindow (x
->menubar_widget
))
519 else if (FRAME_X_WINDOW (f
) == wdesc
)
525 #endif /* USE_X_TOOLKIT || USE_GTK */
529 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
530 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
532 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
533 static void x_set_wait_for_wm
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
534 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
535 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
536 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
537 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
538 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
539 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
540 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
541 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
542 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
543 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
544 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
545 void x_set_scroll_bar_foreground
P_ ((struct frame
*, Lisp_Object
,
547 void x_set_scroll_bar_background
P_ ((struct frame
*, Lisp_Object
,
549 static Lisp_Object x_default_scroll_bar_color_parameter
P_ ((struct frame
*,
556 /* Store the screen positions of frame F into XPTR and YPTR.
557 These are the positions of the containing window manager window,
558 not Emacs's own window. */
561 x_real_positions (f
, xptr
, yptr
)
565 int win_x
, win_y
, outer_x
, outer_y
;
566 int real_x
= 0, real_y
= 0;
568 Window win
= f
->output_data
.x
->parent_desc
;
574 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
576 if (win
== FRAME_X_DISPLAY_INFO (f
)->root_window
)
577 win
= FRAME_OUTER_WINDOW (f
);
579 /* This loop traverses up the containment tree until we hit the root
580 window. Window managers may intersect many windows between our window
581 and the root window. The window we find just before the root window
582 should be the outer WM window. */
585 Window wm_window
, rootw
;
586 Window
*tmp_children
;
587 unsigned int tmp_nchildren
;
590 success
= XQueryTree (FRAME_X_DISPLAY (f
), win
, &rootw
,
591 &wm_window
, &tmp_children
, &tmp_nchildren
);
593 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
595 /* Don't free tmp_children if XQueryTree failed. */
599 XFree ((char *) tmp_children
);
601 if (wm_window
== rootw
|| had_errors
)
612 /* Get the real coordinates for the WM window upper left corner */
613 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
614 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
616 /* Translate real coordinates to coordinates relative to our
617 window. For our window, the upper left corner is 0, 0.
618 Since the upper left corner of the WM window is outside
619 our window, win_x and win_y will be negative:
621 ------------------ ---> x
623 | ----------------- v y
626 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
628 /* From-window, to-window. */
629 FRAME_X_DISPLAY_INFO (f
)->root_window
,
632 /* From-position, to-position. */
633 real_x
, real_y
, &win_x
, &win_y
,
638 if (FRAME_X_WINDOW (f
) == FRAME_OUTER_WINDOW (f
))
645 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
647 /* From-window, to-window. */
648 FRAME_X_DISPLAY_INFO (f
)->root_window
,
649 FRAME_OUTER_WINDOW (f
),
651 /* From-position, to-position. */
652 real_x
, real_y
, &outer_x
, &outer_y
,
658 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
661 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
665 if (had_errors
) return;
667 f
->x_pixels_diff
= -win_x
;
668 f
->y_pixels_diff
= -win_y
;
670 FRAME_X_OUTPUT (f
)->x_pixels_outer_diff
= -outer_x
;
671 FRAME_X_OUTPUT (f
)->y_pixels_outer_diff
= -outer_y
;
680 /* Gamma-correct COLOR on frame F. */
683 gamma_correct (f
, color
)
689 color
->red
= pow (color
->red
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
690 color
->green
= pow (color
->green
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
691 color
->blue
= pow (color
->blue
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
696 /* Decide if color named COLOR_NAME is valid for use on frame F. If
697 so, return the RGB values in COLOR. If ALLOC_P is non-zero,
698 allocate the color. Value is zero if COLOR_NAME is invalid, or
699 no color could be allocated. */
702 x_defined_color (f
, color_name
, color
, alloc_p
)
709 Display
*dpy
= FRAME_X_DISPLAY (f
);
710 Colormap cmap
= FRAME_X_COLORMAP (f
);
713 success_p
= XParseColor (dpy
, cmap
, color_name
, color
);
714 if (success_p
&& alloc_p
)
715 success_p
= x_alloc_nearest_color (f
, cmap
, color
);
722 /* Return the pixel color value for color COLOR_NAME on frame F. If F
723 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
724 Signal an error if color can't be allocated. */
727 x_decode_color (f
, color_name
, mono_color
)
729 Lisp_Object color_name
;
734 CHECK_STRING (color_name
);
736 #if 0 /* Don't do this. It's wrong when we're not using the default
737 colormap, it makes freeing difficult, and it's probably not
738 an important optimization. */
739 if (strcmp (SDATA (color_name
), "black") == 0)
740 return BLACK_PIX_DEFAULT (f
);
741 else if (strcmp (SDATA (color_name
), "white") == 0)
742 return WHITE_PIX_DEFAULT (f
);
745 /* Return MONO_COLOR for monochrome frames. */
746 if (FRAME_X_DISPLAY_INFO (f
)->n_planes
== 1)
749 /* x_defined_color is responsible for coping with failures
750 by looking for a near-miss. */
751 if (x_defined_color (f
, SDATA (color_name
), &cdef
, 1))
754 Fsignal (Qerror
, Fcons (build_string ("Undefined color"),
755 Fcons (color_name
, Qnil
)));
761 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
762 the previous value of that parameter, NEW_VALUE is the new value.
763 See also the comment of wait_for_wm in struct x_output. */
766 x_set_wait_for_wm (f
, new_value
, old_value
)
768 Lisp_Object new_value
, old_value
;
770 f
->output_data
.x
->wait_for_wm
= !NILP (new_value
);
775 /* Set icon from FILE for frame F. By using GTK functions the icon
776 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
779 xg_set_icon (f
, file
)
789 found
= x_find_image_file (file
);
797 filename
= SDATA (found
);
800 pixbuf
= gdk_pixbuf_new_from_file (filename
, &err
);
804 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
806 g_object_unref (pixbuf
);
822 /* Functions called only from `x_set_frame_param'
823 to set individual parameters.
825 If FRAME_X_WINDOW (f) is 0,
826 the frame is being created and its X-window does not exist yet.
827 In that case, just record the parameter's new value
828 in the standard place; do not attempt to change the window. */
831 x_set_foreground_color (f
, arg
, oldval
)
833 Lisp_Object arg
, oldval
;
835 struct x_output
*x
= f
->output_data
.x
;
836 unsigned long fg
, old_fg
;
838 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
839 old_fg
= x
->foreground_pixel
;
840 x
->foreground_pixel
= fg
;
842 if (FRAME_X_WINDOW (f
) != 0)
844 Display
*dpy
= FRAME_X_DISPLAY (f
);
847 XSetForeground (dpy
, x
->normal_gc
, fg
);
848 XSetBackground (dpy
, x
->reverse_gc
, fg
);
850 if (x
->cursor_pixel
== old_fg
)
852 unload_color (f
, x
->cursor_pixel
);
853 x
->cursor_pixel
= x_copy_color (f
, fg
);
854 XSetBackground (dpy
, x
->cursor_gc
, x
->cursor_pixel
);
859 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
861 if (FRAME_VISIBLE_P (f
))
865 unload_color (f
, old_fg
);
869 x_set_background_color (f
, arg
, oldval
)
871 Lisp_Object arg
, oldval
;
873 struct x_output
*x
= f
->output_data
.x
;
876 bg
= x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
877 unload_color (f
, x
->background_pixel
);
878 x
->background_pixel
= bg
;
880 if (FRAME_X_WINDOW (f
) != 0)
882 Display
*dpy
= FRAME_X_DISPLAY (f
);
885 XSetBackground (dpy
, x
->normal_gc
, bg
);
886 XSetForeground (dpy
, x
->reverse_gc
, bg
);
887 XSetWindowBackground (dpy
, FRAME_X_WINDOW (f
), bg
);
888 XSetForeground (dpy
, x
->cursor_gc
, bg
);
891 xg_set_background_color (f
, bg
);
894 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
895 toolkit scroll bars. */
898 for (bar
= FRAME_SCROLL_BARS (f
);
900 bar
= XSCROLL_BAR (bar
)->next
)
902 Window window
= SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
));
903 XSetWindowBackground (dpy
, window
, bg
);
906 #endif /* USE_TOOLKIT_SCROLL_BARS */
909 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
911 if (FRAME_VISIBLE_P (f
))
917 x_set_mouse_color (f
, arg
, oldval
)
919 Lisp_Object arg
, oldval
;
921 struct x_output
*x
= f
->output_data
.x
;
922 Display
*dpy
= FRAME_X_DISPLAY (f
);
923 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
924 Cursor hourglass_cursor
, horizontal_drag_cursor
;
926 unsigned long pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
927 unsigned long mask_color
= x
->background_pixel
;
929 /* Don't let pointers be invisible. */
930 if (mask_color
== pixel
)
932 x_free_colors (f
, &pixel
, 1);
933 pixel
= x_copy_color (f
, x
->foreground_pixel
);
936 unload_color (f
, x
->mouse_pixel
);
937 x
->mouse_pixel
= pixel
;
941 /* It's not okay to crash if the user selects a screwy cursor. */
942 count
= x_catch_errors (dpy
);
944 if (!NILP (Vx_pointer_shape
))
946 CHECK_NUMBER (Vx_pointer_shape
);
947 cursor
= XCreateFontCursor (dpy
, XINT (Vx_pointer_shape
));
950 cursor
= XCreateFontCursor (dpy
, XC_xterm
);
951 x_check_errors (dpy
, "bad text pointer cursor: %s");
953 if (!NILP (Vx_nontext_pointer_shape
))
955 CHECK_NUMBER (Vx_nontext_pointer_shape
);
957 = XCreateFontCursor (dpy
, XINT (Vx_nontext_pointer_shape
));
960 nontext_cursor
= XCreateFontCursor (dpy
, XC_left_ptr
);
961 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
963 if (!NILP (Vx_hourglass_pointer_shape
))
965 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
967 = XCreateFontCursor (dpy
, XINT (Vx_hourglass_pointer_shape
));
970 hourglass_cursor
= XCreateFontCursor (dpy
, XC_watch
);
971 x_check_errors (dpy
, "bad hourglass pointer cursor: %s");
973 if (!NILP (Vx_mode_pointer_shape
))
975 CHECK_NUMBER (Vx_mode_pointer_shape
);
976 mode_cursor
= XCreateFontCursor (dpy
, XINT (Vx_mode_pointer_shape
));
979 mode_cursor
= XCreateFontCursor (dpy
, XC_xterm
);
980 x_check_errors (dpy
, "bad modeline pointer cursor: %s");
982 if (!NILP (Vx_sensitive_text_pointer_shape
))
984 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
986 = XCreateFontCursor (dpy
, XINT (Vx_sensitive_text_pointer_shape
));
989 hand_cursor
= XCreateFontCursor (dpy
, XC_hand2
);
991 if (!NILP (Vx_window_horizontal_drag_shape
))
993 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
994 horizontal_drag_cursor
995 = XCreateFontCursor (dpy
, XINT (Vx_window_horizontal_drag_shape
));
998 horizontal_drag_cursor
999 = XCreateFontCursor (dpy
, XC_sb_h_double_arrow
);
1001 /* Check and report errors with the above calls. */
1002 x_check_errors (dpy
, "can't set cursor shape: %s");
1003 x_uncatch_errors (dpy
, count
);
1006 XColor fore_color
, back_color
;
1008 fore_color
.pixel
= x
->mouse_pixel
;
1009 x_query_color (f
, &fore_color
);
1010 back_color
.pixel
= mask_color
;
1011 x_query_color (f
, &back_color
);
1013 XRecolorCursor (dpy
, cursor
, &fore_color
, &back_color
);
1014 XRecolorCursor (dpy
, nontext_cursor
, &fore_color
, &back_color
);
1015 XRecolorCursor (dpy
, mode_cursor
, &fore_color
, &back_color
);
1016 XRecolorCursor (dpy
, hand_cursor
, &fore_color
, &back_color
);
1017 XRecolorCursor (dpy
, hourglass_cursor
, &fore_color
, &back_color
);
1018 XRecolorCursor (dpy
, horizontal_drag_cursor
, &fore_color
, &back_color
);
1021 if (FRAME_X_WINDOW (f
) != 0)
1022 XDefineCursor (dpy
, FRAME_X_WINDOW (f
), cursor
);
1024 if (cursor
!= x
->text_cursor
1025 && x
->text_cursor
!= 0)
1026 XFreeCursor (dpy
, x
->text_cursor
);
1027 x
->text_cursor
= cursor
;
1029 if (nontext_cursor
!= x
->nontext_cursor
1030 && x
->nontext_cursor
!= 0)
1031 XFreeCursor (dpy
, x
->nontext_cursor
);
1032 x
->nontext_cursor
= nontext_cursor
;
1034 if (hourglass_cursor
!= x
->hourglass_cursor
1035 && x
->hourglass_cursor
!= 0)
1036 XFreeCursor (dpy
, x
->hourglass_cursor
);
1037 x
->hourglass_cursor
= hourglass_cursor
;
1039 if (mode_cursor
!= x
->modeline_cursor
1040 && x
->modeline_cursor
!= 0)
1041 XFreeCursor (dpy
, f
->output_data
.x
->modeline_cursor
);
1042 x
->modeline_cursor
= mode_cursor
;
1044 if (hand_cursor
!= x
->hand_cursor
1045 && x
->hand_cursor
!= 0)
1046 XFreeCursor (dpy
, x
->hand_cursor
);
1047 x
->hand_cursor
= hand_cursor
;
1049 if (horizontal_drag_cursor
!= x
->horizontal_drag_cursor
1050 && x
->horizontal_drag_cursor
!= 0)
1051 XFreeCursor (dpy
, x
->horizontal_drag_cursor
);
1052 x
->horizontal_drag_cursor
= horizontal_drag_cursor
;
1057 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1061 x_set_cursor_color (f
, arg
, oldval
)
1063 Lisp_Object arg
, oldval
;
1065 unsigned long fore_pixel
, pixel
;
1066 int fore_pixel_allocated_p
= 0, pixel_allocated_p
= 0;
1067 struct x_output
*x
= f
->output_data
.x
;
1069 if (!NILP (Vx_cursor_fore_pixel
))
1071 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1072 WHITE_PIX_DEFAULT (f
));
1073 fore_pixel_allocated_p
= 1;
1076 fore_pixel
= x
->background_pixel
;
1078 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1079 pixel_allocated_p
= 1;
1081 /* Make sure that the cursor color differs from the background color. */
1082 if (pixel
== x
->background_pixel
)
1084 if (pixel_allocated_p
)
1086 x_free_colors (f
, &pixel
, 1);
1087 pixel_allocated_p
= 0;
1090 pixel
= x
->mouse_pixel
;
1091 if (pixel
== fore_pixel
)
1093 if (fore_pixel_allocated_p
)
1095 x_free_colors (f
, &fore_pixel
, 1);
1096 fore_pixel_allocated_p
= 0;
1098 fore_pixel
= x
->background_pixel
;
1102 unload_color (f
, x
->cursor_foreground_pixel
);
1103 if (!fore_pixel_allocated_p
)
1104 fore_pixel
= x_copy_color (f
, fore_pixel
);
1105 x
->cursor_foreground_pixel
= fore_pixel
;
1107 unload_color (f
, x
->cursor_pixel
);
1108 if (!pixel_allocated_p
)
1109 pixel
= x_copy_color (f
, pixel
);
1110 x
->cursor_pixel
= pixel
;
1112 if (FRAME_X_WINDOW (f
) != 0)
1115 XSetBackground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, x
->cursor_pixel
);
1116 XSetForeground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, fore_pixel
);
1119 if (FRAME_VISIBLE_P (f
))
1121 x_update_cursor (f
, 0);
1122 x_update_cursor (f
, 1);
1126 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1129 /* Set the border-color of frame F to pixel value PIX.
1130 Note that this does not fully take effect if done before
1131 F has an x-window. */
1134 x_set_border_pixel (f
, pix
)
1138 unload_color (f
, f
->output_data
.x
->border_pixel
);
1139 f
->output_data
.x
->border_pixel
= pix
;
1141 if (FRAME_X_WINDOW (f
) != 0 && f
->border_width
> 0)
1144 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1145 (unsigned long)pix
);
1148 if (FRAME_VISIBLE_P (f
))
1153 /* Set the border-color of frame F to value described by ARG.
1154 ARG can be a string naming a color.
1155 The border-color is used for the border that is drawn by the X server.
1156 Note that this does not fully take effect if done before
1157 F has an x-window; it must be redone when the window is created.
1159 Note: this is done in two routines because of the way X10 works.
1161 Note: under X11, this is normally the province of the window manager,
1162 and so emacs' border colors may be overridden. */
1165 x_set_border_color (f
, arg
, oldval
)
1167 Lisp_Object arg
, oldval
;
1172 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1173 x_set_border_pixel (f
, pix
);
1174 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1179 x_set_cursor_type (f
, arg
, oldval
)
1181 Lisp_Object arg
, oldval
;
1183 set_frame_cursor_types (f
, arg
);
1185 /* Make sure the cursor gets redrawn. */
1186 cursor_type_changed
= 1;
1190 x_set_icon_type (f
, arg
, oldval
)
1192 Lisp_Object arg
, oldval
;
1198 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1201 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1206 result
= x_text_icon (f
,
1207 (char *) SDATA ((!NILP (f
->icon_name
)
1211 result
= x_bitmap_icon (f
, arg
);
1216 error ("No icon window available");
1219 XFlush (FRAME_X_DISPLAY (f
));
1224 x_set_icon_name (f
, arg
, oldval
)
1226 Lisp_Object arg
, oldval
;
1232 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1235 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1240 if (f
->output_data
.x
->icon_bitmap
!= 0)
1245 result
= x_text_icon (f
,
1246 (char *) SDATA ((!NILP (f
->icon_name
)
1255 error ("No icon window available");
1258 XFlush (FRAME_X_DISPLAY (f
));
1264 x_set_menu_bar_lines (f
, value
, oldval
)
1266 Lisp_Object value
, oldval
;
1269 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
1270 int olines
= FRAME_MENU_BAR_LINES (f
);
1273 /* Right now, menu bars don't work properly in minibuf-only frames;
1274 most of the commands try to apply themselves to the minibuffer
1275 frame itself, and get an error because you can't switch buffers
1276 in or split the minibuffer window. */
1277 if (FRAME_MINIBUF_ONLY_P (f
))
1280 if (INTEGERP (value
))
1281 nlines
= XINT (value
);
1285 /* Make sure we redisplay all windows in this frame. */
1286 windows_or_buffers_changed
++;
1288 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
1289 FRAME_MENU_BAR_LINES (f
) = 0;
1292 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1293 if (FRAME_X_P (f
) && f
->output_data
.x
->menubar_widget
== 0)
1294 /* Make sure next redisplay shows the menu bar. */
1295 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= Qt
;
1299 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1300 free_frame_menubar (f
);
1301 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1303 f
->output_data
.x
->menubar_widget
= 0;
1305 #else /* not USE_X_TOOLKIT && not USE_GTK */
1306 FRAME_MENU_BAR_LINES (f
) = nlines
;
1307 change_window_heights (f
->root_window
, nlines
- olines
);
1308 #endif /* not USE_X_TOOLKIT */
1313 /* Set the number of lines used for the tool bar of frame F to VALUE.
1314 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1315 is the old number of tool bar lines. This function changes the
1316 height of all windows on frame F to match the new tool bar height.
1317 The frame's height doesn't change. */
1320 x_set_tool_bar_lines (f
, value
, oldval
)
1322 Lisp_Object value
, oldval
;
1324 int delta
, nlines
, root_height
;
1325 Lisp_Object root_window
;
1327 /* Treat tool bars like menu bars. */
1328 if (FRAME_MINIBUF_ONLY_P (f
))
1331 /* Use VALUE only if an integer >= 0. */
1332 if (INTEGERP (value
) && XINT (value
) >= 0)
1333 nlines
= XFASTINT (value
);
1338 FRAME_TOOL_BAR_LINES (f
) = 0;
1341 FRAME_EXTERNAL_TOOL_BAR (f
) = 1;
1342 if (FRAME_X_P (f
) && f
->output_data
.x
->toolbar_widget
== 0)
1343 /* Make sure next redisplay shows the tool bar. */
1344 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= Qt
;
1345 update_frame_tool_bar (f
);
1349 if (FRAME_EXTERNAL_TOOL_BAR (f
))
1350 free_frame_tool_bar (f
);
1351 FRAME_EXTERNAL_TOOL_BAR (f
) = 0;
1357 /* Make sure we redisplay all windows in this frame. */
1358 ++windows_or_buffers_changed
;
1360 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1362 /* Don't resize the tool-bar to more than we have room for. */
1363 root_window
= FRAME_ROOT_WINDOW (f
);
1364 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1365 if (root_height
- delta
< 1)
1367 delta
= root_height
- 1;
1368 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1371 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1372 change_window_heights (root_window
, delta
);
1375 /* We also have to make sure that the internal border at the top of
1376 the frame, below the menu bar or tool bar, is redrawn when the
1377 tool bar disappears. This is so because the internal border is
1378 below the tool bar if one is displayed, but is below the menu bar
1379 if there isn't a tool bar. The tool bar draws into the area
1380 below the menu bar. */
1381 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1385 clear_current_matrices (f
);
1386 updating_frame
= NULL
;
1389 /* If the tool bar gets smaller, the internal border below it
1390 has to be cleared. It was formerly part of the display
1391 of the larger tool bar, and updating windows won't clear it. */
1394 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1395 int width
= FRAME_PIXEL_WIDTH (f
);
1396 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1399 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1400 0, y
, width
, height
, False
);
1403 if (WINDOWP (f
->tool_bar_window
))
1404 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1409 /* Set the foreground color for scroll bars on frame F to VALUE.
1410 VALUE should be a string, a color name. If it isn't a string or
1411 isn't a valid color name, do nothing. OLDVAL is the old value of
1412 the frame parameter. */
1415 x_set_scroll_bar_foreground (f
, value
, oldval
)
1417 Lisp_Object value
, oldval
;
1419 unsigned long pixel
;
1421 if (STRINGP (value
))
1422 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
1426 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
1427 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
1429 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
1430 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1432 /* Remove all scroll bars because they have wrong colors. */
1433 if (condemn_scroll_bars_hook
)
1434 (*condemn_scroll_bars_hook
) (f
);
1435 if (judge_scroll_bars_hook
)
1436 (*judge_scroll_bars_hook
) (f
);
1438 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
1444 /* Set the background color for scroll bars on frame F to VALUE VALUE
1445 should be a string, a color name. If it isn't a string or isn't a
1446 valid color name, do nothing. OLDVAL is the old value of the frame
1450 x_set_scroll_bar_background (f
, value
, oldval
)
1452 Lisp_Object value
, oldval
;
1454 unsigned long pixel
;
1456 if (STRINGP (value
))
1457 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
1461 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
1462 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
1464 #ifdef USE_TOOLKIT_SCROLL_BARS
1465 /* Scrollbar shadow colors. */
1466 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
1468 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
1469 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
1471 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
1473 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
1474 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
1476 #endif /* USE_TOOLKIT_SCROLL_BARS */
1478 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
1479 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1481 /* Remove all scroll bars because they have wrong colors. */
1482 if (condemn_scroll_bars_hook
)
1483 (*condemn_scroll_bars_hook
) (f
);
1484 if (judge_scroll_bars_hook
)
1485 (*judge_scroll_bars_hook
) (f
);
1487 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
1493 /* Encode Lisp string STRING as a text in a format appropriate for
1494 XICCC (X Inter Client Communication Conventions).
1496 If STRING contains only ASCII characters, do no conversion and
1497 return the string data of STRING. Otherwise, encode the text by
1498 CODING_SYSTEM, and return a newly allocated memory area which
1499 should be freed by `xfree' by a caller.
1501 SELECTIONP non-zero means the string is being encoded for an X
1502 selection, so it is safe to run pre-write conversions (which
1505 Store the byte length of resulting text in *TEXT_BYTES.
1507 If the text contains only ASCII and Latin-1, store 1 in *STRING_P,
1508 which means that the `encoding' of the result can be `STRING'.
1509 Otherwise store 0 in *STRINGP, which means that the `encoding' of
1510 the result should be `COMPOUND_TEXT'. */
1513 x_encode_text (string
, coding_system
, selectionp
, text_bytes
, stringp
)
1514 Lisp_Object string
, coding_system
;
1515 int *text_bytes
, *stringp
;
1518 int result
= string_xstring_p (string
);
1519 struct coding_system coding
;
1523 /* No multibyte character in OBJ. We need not encode it. */
1524 *text_bytes
= SBYTES (string
);
1526 return SDATA (string
);
1529 setup_coding_system (coding_system
, &coding
);
1530 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
1531 /* We suppress producing escape sequences for composition. */
1532 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
1533 coding
.dst_bytes
= SCHARS (string
) * 2;
1534 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
);
1535 encode_coding_object (&coding
, string
, 0, 0,
1536 SCHARS (string
), SBYTES (string
), Qnil
);
1537 *text_bytes
= coding
.produced
;
1538 *stringp
= (result
== 1 || !EQ (coding_system
, Qcompound_text
));
1539 return coding
.destination
;
1543 /* Set the WM name to NAME for frame F. Also set the icon name.
1544 If the frame already has an icon name, use that, otherwise set the
1545 icon name to NAME. */
1548 x_set_name_internal (f
, name
)
1552 if (FRAME_X_WINDOW (f
))
1557 XTextProperty text
, icon
;
1559 int do_free_icon_value
= 0, do_free_text_value
= 0;
1560 Lisp_Object coding_system
;
1562 coding_system
= Qcompound_text
;
1563 /* Note: Encoding strategy
1565 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1566 text.encoding. But, there are non-internationalized window
1567 managers which don't support that encoding. So, if NAME
1568 contains only ASCII and 8859-1 characters, encode it by
1569 iso-latin-1, and use "STRING" in text.encoding hoping that
1570 such window managers at least analyze this format correctly,
1571 i.e. treat 8-bit bytes as 8859-1 characters.
1573 We may also be able to use "UTF8_STRING" in text.encoding
1574 in the future which can encode all Unicode characters.
1575 But, for the moment, there's no way to know that the
1576 current window manager supports it or not. */
1577 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
);
1578 text
.encoding
= (stringp
? XA_STRING
1579 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1581 text
.nitems
= bytes
;
1583 /* Check early, because ENCODE_UTF_8 below may GC and name may be
1585 do_free_text_value
= text
.value
!= SDATA (name
);
1587 if (NILP (f
->icon_name
))
1593 /* See the above comment "Note: Encoding strategy". */
1594 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
1596 icon
.encoding
= (stringp
? XA_STRING
1597 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1599 icon
.nitems
= bytes
;
1600 do_free_icon_value
= icon
.value
!= SDATA (f
->icon_name
);
1604 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1605 SDATA (ENCODE_UTF_8 (name
)));
1606 #else /* not USE_GTK */
1607 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1608 #endif /* not USE_GTK */
1610 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &icon
);
1612 if (do_free_icon_value
)
1614 if (do_free_text_value
)
1617 #else /* not HAVE_X11R4 */
1618 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1620 XStoreName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1622 #endif /* not HAVE_X11R4 */
1627 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1630 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1631 name; if NAME is a string, set F's name to NAME and set
1632 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1634 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1635 suggesting a new name, which lisp code should override; if
1636 F->explicit_name is set, ignore the new name; otherwise, set it. */
1639 x_set_name (f
, name
, explicit)
1644 /* Make sure that requests from lisp code override requests from
1645 Emacs redisplay code. */
1648 /* If we're switching from explicit to implicit, we had better
1649 update the mode lines and thereby update the title. */
1650 if (f
->explicit_name
&& NILP (name
))
1651 update_mode_lines
= 1;
1653 f
->explicit_name
= ! NILP (name
);
1655 else if (f
->explicit_name
)
1658 /* If NAME is nil, set the name to the x_id_name. */
1661 /* Check for no change needed in this very common case
1662 before we do any consing. */
1663 if (!strcmp (FRAME_X_DISPLAY_INFO (f
)->x_id_name
,
1666 name
= build_string (FRAME_X_DISPLAY_INFO (f
)->x_id_name
);
1669 CHECK_STRING (name
);
1671 /* Don't change the name if it's already NAME. */
1672 if (! NILP (Fstring_equal (name
, f
->name
)))
1677 /* For setting the frame title, the title parameter should override
1678 the name parameter. */
1679 if (! NILP (f
->title
))
1682 x_set_name_internal (f
, name
);
1685 /* This function should be called when the user's lisp code has
1686 specified a name for the frame; the name will override any set by the
1689 x_explicitly_set_name (f
, arg
, oldval
)
1691 Lisp_Object arg
, oldval
;
1693 x_set_name (f
, arg
, 1);
1696 /* This function should be called by Emacs redisplay code to set the
1697 name; names set this way will never override names set by the user's
1700 x_implicitly_set_name (f
, arg
, oldval
)
1702 Lisp_Object arg
, oldval
;
1704 x_set_name (f
, arg
, 0);
1707 /* Change the title of frame F to NAME.
1708 If NAME is nil, use the frame name as the title.
1710 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1711 name; if NAME is a string, set F's name to NAME and set
1712 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1714 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1715 suggesting a new name, which lisp code should override; if
1716 F->explicit_name is set, ignore the new name; otherwise, set it. */
1719 x_set_title (f
, name
, old_name
)
1721 Lisp_Object name
, old_name
;
1723 /* Don't change the title if it's already NAME. */
1724 if (EQ (name
, f
->title
))
1727 update_mode_lines
= 1;
1734 CHECK_STRING (name
);
1736 x_set_name_internal (f
, name
);
1740 x_set_scroll_bar_default_width (f
)
1743 int wid
= FRAME_COLUMN_WIDTH (f
);
1745 #ifdef USE_TOOLKIT_SCROLL_BARS
1746 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1747 int width
= 16 + 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1748 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (width
+ wid
- 1) / wid
;
1749 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = width
;
1751 /* Make the actual width at least 14 pixels and a multiple of a
1753 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
1755 /* Use all of that space (aside from required margins) for the
1757 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = 0;
1762 /* Record in frame F the specified or default value according to ALIST
1763 of the parameter named PROP (a Lisp symbol). If no value is
1764 specified for PROP, look for an X default for XPROP on the frame
1765 named NAME. If that is not found either, use the value DEFLT. */
1768 x_default_scroll_bar_color_parameter (f
, alist
, prop
, xprop
, xclass
,
1777 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1780 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
1781 if (EQ (tem
, Qunbound
))
1783 #ifdef USE_TOOLKIT_SCROLL_BARS
1785 /* See if an X resource for the scroll bar color has been
1787 tem
= display_x_get_resource (dpyinfo
,
1788 build_string (foreground_p
1792 build_string ("verticalScrollBar"),
1796 /* If nothing has been specified, scroll bars will use a
1797 toolkit-dependent default. Because these defaults are
1798 difficult to get at without actually creating a scroll
1799 bar, use nil to indicate that no color has been
1804 #else /* not USE_TOOLKIT_SCROLL_BARS */
1808 #endif /* not USE_TOOLKIT_SCROLL_BARS */
1811 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
1817 #if !defined (HAVE_X11R4) && !defined (HAVE_XSETWMPROTOCOLS)
1820 XSetWMProtocols (dpy
, w
, protocols
, count
)
1827 prop
= XInternAtom (dpy
, "WM_PROTOCOLS", False
);
1828 if (prop
== None
) return False
;
1829 XChangeProperty (dpy
, w
, prop
, XA_ATOM
, 32, PropModeReplace
,
1830 (unsigned char *) protocols
, count
);
1833 #endif /* not HAVE_X11R4 && not HAVE_XSETWMPROTOCOLS */
1835 #ifdef USE_X_TOOLKIT
1837 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
1838 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
1839 already be present because of the toolkit (Motif adds some of them,
1840 for example, but Xt doesn't). */
1843 hack_wm_protocols (f
, widget
)
1847 Display
*dpy
= XtDisplay (widget
);
1848 Window w
= XtWindow (widget
);
1849 int need_delete
= 1;
1855 Atom type
, *atoms
= 0;
1857 unsigned long nitems
= 0;
1858 unsigned long bytes_after
;
1860 if ((XGetWindowProperty (dpy
, w
,
1861 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1862 (long)0, (long)100, False
, XA_ATOM
,
1863 &type
, &format
, &nitems
, &bytes_after
,
1864 (unsigned char **) &atoms
)
1866 && format
== 32 && type
== XA_ATOM
)
1870 if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
1872 else if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
1874 else if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
1877 if (atoms
) XFree ((char *) atoms
);
1883 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
1885 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
1887 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
1889 XChangeProperty (dpy
, w
, FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1890 XA_ATOM
, 32, PropModeAppend
,
1891 (unsigned char *) props
, count
);
1899 /* Support routines for XIC (X Input Context). */
1903 static XFontSet xic_create_xfontset
P_ ((struct frame
*, char *));
1904 static XIMStyle best_xim_style
P_ ((XIMStyles
*, XIMStyles
*));
1907 /* Supported XIM styles, ordered by preference. */
1909 static XIMStyle supported_xim_styles
[] =
1911 XIMPreeditPosition
| XIMStatusArea
,
1912 XIMPreeditPosition
| XIMStatusNothing
,
1913 XIMPreeditPosition
| XIMStatusNone
,
1914 XIMPreeditNothing
| XIMStatusArea
,
1915 XIMPreeditNothing
| XIMStatusNothing
,
1916 XIMPreeditNothing
| XIMStatusNone
,
1917 XIMPreeditNone
| XIMStatusArea
,
1918 XIMPreeditNone
| XIMStatusNothing
,
1919 XIMPreeditNone
| XIMStatusNone
,
1924 /* Create an X fontset on frame F with base font name BASE_FONTNAME. */
1927 xic_create_xfontset (f
, base_fontname
)
1929 char *base_fontname
;
1931 XFontSet xfs
= NULL
;
1932 char **missing_list
= NULL
;
1935 Lisp_Object rest
, frame
;
1937 /* See if there is another frame already using same fontset. */
1938 FOR_EACH_FRAME (rest
, frame
)
1940 struct frame
*cf
= XFRAME (frame
);
1941 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
1942 && FRAME_X_DISPLAY_INFO (cf
) == FRAME_X_DISPLAY_INFO (f
)
1943 && FRAME_XIC_BASE_FONTNAME (cf
)
1944 && !strcmp (FRAME_XIC_BASE_FONTNAME (cf
), base_fontname
))
1946 xfs
= FRAME_XIC_FONTSET (cf
);
1954 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
),
1955 base_fontname
, &missing_list
,
1956 &missing_count
, &def_string
);
1958 XFreeStringList (missing_list
);
1961 if (FRAME_XIC_BASE_FONTNAME (f
))
1962 xfree (FRAME_XIC_BASE_FONTNAME (f
));
1963 FRAME_XIC_BASE_FONTNAME (f
) = xstrdup (base_fontname
);
1965 /* No need to free def_string. */
1969 /* Free the X fontset of frame F if it is the last frame using it. */
1972 xic_free_xfontset (f
)
1975 Lisp_Object rest
, frame
;
1978 if (!FRAME_XIC_FONTSET (f
))
1981 /* See if there is another frame sharing the same fontset. */
1982 FOR_EACH_FRAME (rest
, frame
)
1984 struct frame
*cf
= XFRAME (frame
);
1985 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
1986 && FRAME_X_DISPLAY_INFO (cf
) == FRAME_X_DISPLAY_INFO (f
)
1987 && FRAME_XIC_FONTSET (cf
) == FRAME_XIC_FONTSET (f
))
1995 /* The fontset is not used anymore. It is safe to free it. */
1996 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
1998 if (FRAME_XIC_BASE_FONTNAME (f
))
1999 xfree (FRAME_XIC_BASE_FONTNAME (f
));
2000 FRAME_XIC_BASE_FONTNAME (f
) = NULL
;
2001 FRAME_XIC_FONTSET (f
) = NULL
;
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 xic_free_xfontset (f
);
2156 FRAME_XIC (f
) = NULL
;
2160 /* Place preedit area for XIC of window W's frame to specified
2161 pixel position X/Y. X and Y are relative to window W. */
2164 xic_set_preeditarea (w
, x
, y
)
2168 struct frame
*f
= XFRAME (w
->frame
);
2172 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
) + WINDOW_LEFT_FRINGE_WIDTH (w
);
2173 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
2174 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
2175 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2180 /* Place status area for XIC in bottom right corner of frame F.. */
2183 xic_set_statusarea (f
)
2186 XIC xic
= FRAME_XIC (f
);
2191 /* Negotiate geometry of status area. If input method has existing
2192 status area, use its current size. */
2193 area
.x
= area
.y
= area
.width
= area
.height
= 0;
2194 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
2195 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2198 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
2199 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2202 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
2204 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
2205 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2209 area
.width
= needed
->width
;
2210 area
.height
= needed
->height
;
2211 area
.x
= FRAME_PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
2212 area
.y
= (FRAME_PIXEL_HEIGHT (f
) - area
.height
2213 - FRAME_MENUBAR_HEIGHT (f
)
2214 - FRAME_TOOLBAR_HEIGHT (f
)
2215 - FRAME_INTERNAL_BORDER_WIDTH (f
));
2218 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
2219 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2224 /* Set X fontset for XIC of frame F, using base font name
2225 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2228 xic_set_xfontset (f
, base_fontname
)
2230 char *base_fontname
;
2235 xic_free_xfontset (f
);
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 FRAME_XIC_FONTSET (f
) = xfs
;
2249 #endif /* HAVE_X_I18N */
2253 #ifdef USE_X_TOOLKIT
2255 /* Create and set up the X widget for frame F. */
2258 x_window (f
, window_prompting
, minibuffer_only
)
2260 long window_prompting
;
2261 int minibuffer_only
;
2263 XClassHint class_hints
;
2264 XSetWindowAttributes attributes
;
2265 unsigned long attribute_mask
;
2266 Widget shell_widget
;
2268 Widget frame_widget
;
2274 /* Use the resource name as the top-level widget name
2275 for looking up resources. Make a non-Lisp copy
2276 for the window manager, so GC relocation won't bother it.
2278 Elsewhere we specify the window name for the window manager. */
2281 char *str
= (char *) SDATA (Vx_resource_name
);
2282 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
2283 strcpy (f
->namebuf
, str
);
2287 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2288 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2289 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2290 XtSetArg (al
[ac
], XtNborderWidth
, f
->border_width
); ac
++;
2291 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2292 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2293 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2294 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2295 applicationShellWidgetClass
,
2296 FRAME_X_DISPLAY (f
), al
, ac
);
2298 f
->output_data
.x
->widget
= shell_widget
;
2299 /* maybe_set_screen_title_format (shell_widget); */
2301 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2302 (widget_value
*) NULL
,
2303 shell_widget
, False
,
2307 (lw_callback
) NULL
);
2310 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2311 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2312 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2313 XtSetValues (pane_widget
, al
, ac
);
2314 f
->output_data
.x
->column_widget
= pane_widget
;
2316 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2317 the emacs screen when changing menubar. This reduces flickering. */
2320 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2321 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2322 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2323 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2324 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2325 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2326 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2327 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2328 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
2331 f
->output_data
.x
->edit_widget
= frame_widget
;
2333 XtManageChild (frame_widget
);
2335 /* Do some needed geometry management. */
2338 char *tem
, shell_position
[32];
2341 int extra_borders
= 0;
2343 = (f
->output_data
.x
->menubar_widget
2344 ? (f
->output_data
.x
->menubar_widget
->core
.height
2345 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
2348 #if 0 /* Experimentally, we now get the right results
2349 for -geometry -0-0 without this. 24 Aug 96, rms. */
2350 if (FRAME_EXTERNAL_MENU_BAR (f
))
2353 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2354 menubar_size
+= ibw
;
2358 f
->output_data
.x
->menubar_height
= menubar_size
;
2361 /* Motif seems to need this amount added to the sizes
2362 specified for the shell widget. The Athena/Lucid widgets don't.
2363 Both conclusions reached experimentally. -- rms. */
2364 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
2365 &extra_borders
, NULL
);
2369 /* Convert our geometry parameters into a geometry string
2371 Note that we do not specify here whether the position
2372 is a user-specified or program-specified one.
2373 We pass that information later, in x_wm_set_size_hints. */
2375 int left
= f
->left_pos
;
2376 int xneg
= window_prompting
& XNegative
;
2377 int top
= f
->top_pos
;
2378 int yneg
= window_prompting
& YNegative
;
2384 if (window_prompting
& USPosition
)
2385 sprintf (shell_position
, "=%dx%d%c%d%c%d",
2386 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2387 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
2388 (xneg
? '-' : '+'), left
,
2389 (yneg
? '-' : '+'), top
);
2392 sprintf (shell_position
, "=%dx%d",
2393 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2394 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
2396 /* Setting x and y when the position is not specified in
2397 the geometry string will set program position in the WM hints.
2398 If Emacs had just one program position, we could set it in
2399 fallback resources, but since each make-frame call can specify
2400 different program positions, this is easier. */
2401 XtSetArg (al
[ac
], XtNx
, left
); ac
++;
2402 XtSetArg (al
[ac
], XtNy
, top
); ac
++;
2406 len
= strlen (shell_position
) + 1;
2407 /* We don't free this because we don't know whether
2408 it is safe to free it while the frame exists.
2409 It isn't worth the trouble of arranging to free it
2410 when the frame is deleted. */
2411 tem
= (char *) xmalloc (len
);
2412 strncpy (tem
, shell_position
, len
);
2413 XtSetArg (al
[ac
], XtNgeometry
, tem
); ac
++;
2414 XtSetValues (shell_widget
, al
, ac
);
2417 XtManageChild (pane_widget
);
2418 XtRealizeWidget (shell_widget
);
2420 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2422 validate_x_resource_name ();
2424 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
2425 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
2426 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2429 FRAME_XIC (f
) = NULL
;
2431 create_frame_xic (f
);
2434 f
->output_data
.x
->wm_hints
.input
= True
;
2435 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2436 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2437 &f
->output_data
.x
->wm_hints
);
2439 hack_wm_protocols (f
, shell_widget
);
2442 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2445 /* Do a stupid property change to force the server to generate a
2446 PropertyNotify event so that the event_stream server timestamp will
2447 be initialized to something relevant to the time we created the window.
2449 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2450 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2451 XA_ATOM
, 32, PropModeAppend
,
2452 (unsigned char*) NULL
, 0);
2454 /* Make all the standard events reach the Emacs frame. */
2455 attributes
.event_mask
= STANDARD_EVENT_SET
;
2460 /* XIM server might require some X events. */
2461 unsigned long fevent
= NoEventMask
;
2462 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2463 attributes
.event_mask
|= fevent
;
2465 #endif /* HAVE_X_I18N */
2467 attribute_mask
= CWEventMask
;
2468 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2469 attribute_mask
, &attributes
);
2471 XtMapWidget (frame_widget
);
2473 /* x_set_name normally ignores requests to set the name if the
2474 requested name is the same as the current name. This is the one
2475 place where that assumption isn't correct; f->name is set, but
2476 the X server hasn't been told. */
2479 int explicit = f
->explicit_name
;
2481 f
->explicit_name
= 0;
2484 x_set_name (f
, name
, explicit);
2487 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2488 f
->output_data
.x
->text_cursor
);
2492 /* This is a no-op, except under Motif. Make sure main areas are
2493 set to something reasonable, in case we get an error later. */
2494 lw_set_main_areas (pane_widget
, 0, frame_widget
);
2497 #else /* not USE_X_TOOLKIT */
2503 if (! xg_create_frame_widgets (f
))
2504 error ("Unable to create window");
2507 FRAME_XIC (f
) = NULL
;
2511 create_frame_xic (f
);
2514 /* XIM server might require some X events. */
2515 unsigned long fevent
= NoEventMask
;
2516 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2518 if (fevent
!= NoEventMask
)
2520 XSetWindowAttributes attributes
;
2521 XWindowAttributes wattr
;
2522 unsigned long attribute_mask
;
2524 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2526 attributes
.event_mask
= wattr
.your_event_mask
| fevent
;
2527 attribute_mask
= CWEventMask
;
2528 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2529 attribute_mask
, &attributes
);
2537 #else /*! USE_GTK */
2538 /* Create and set up the X window for frame F. */
2545 XClassHint class_hints
;
2546 XSetWindowAttributes attributes
;
2547 unsigned long attribute_mask
;
2549 attributes
.background_pixel
= f
->output_data
.x
->background_pixel
;
2550 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
2551 attributes
.bit_gravity
= StaticGravity
;
2552 attributes
.backing_store
= NotUseful
;
2553 attributes
.save_under
= True
;
2554 attributes
.event_mask
= STANDARD_EVENT_SET
;
2555 attributes
.colormap
= FRAME_X_COLORMAP (f
);
2556 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
2561 = XCreateWindow (FRAME_X_DISPLAY (f
),
2562 f
->output_data
.x
->parent_desc
,
2565 FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
),
2567 CopyFromParent
, /* depth */
2568 InputOutput
, /* class */
2570 attribute_mask
, &attributes
);
2575 create_frame_xic (f
);
2578 /* XIM server might require some X events. */
2579 unsigned long fevent
= NoEventMask
;
2580 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2581 attributes
.event_mask
|= fevent
;
2582 attribute_mask
= CWEventMask
;
2583 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2584 attribute_mask
, &attributes
);
2587 #endif /* HAVE_X_I18N */
2589 validate_x_resource_name ();
2591 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
2592 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
2593 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2595 /* The menubar is part of the ordinary display;
2596 it does not count in addition to the height of the window. */
2597 f
->output_data
.x
->menubar_height
= 0;
2599 /* This indicates that we use the "Passive Input" input model.
2600 Unless we do this, we don't get the Focus{In,Out} events that we
2601 need to draw the cursor correctly. Accursed bureaucrats.
2602 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2604 f
->output_data
.x
->wm_hints
.input
= True
;
2605 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2606 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2607 &f
->output_data
.x
->wm_hints
);
2608 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
2610 /* Request "save yourself" and "delete window" commands from wm. */
2613 protocols
[0] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2614 protocols
[1] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2615 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2618 /* x_set_name normally ignores requests to set the name if the
2619 requested name is the same as the current name. This is the one
2620 place where that assumption isn't correct; f->name is set, but
2621 the X server hasn't been told. */
2624 int explicit = f
->explicit_name
;
2626 f
->explicit_name
= 0;
2629 x_set_name (f
, name
, explicit);
2632 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2633 f
->output_data
.x
->text_cursor
);
2637 if (FRAME_X_WINDOW (f
) == 0)
2638 error ("Unable to create window");
2641 #endif /* not USE_GTK */
2642 #endif /* not USE_X_TOOLKIT */
2644 /* Verify that the icon position args for this window are valid. */
2647 x_icon_verify (f
, parms
)
2651 Lisp_Object icon_x
, icon_y
;
2653 /* Set the position of the icon. Note that twm groups all
2654 icons in an icon window. */
2655 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2656 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2657 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2659 CHECK_NUMBER (icon_x
);
2660 CHECK_NUMBER (icon_y
);
2662 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2663 error ("Both left and top icon corners of icon must be specified");
2666 /* Handle the icon stuff for this window. Perhaps later we might
2667 want an x_set_icon_position which can be called interactively as
2675 Lisp_Object icon_x
, icon_y
;
2676 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2678 /* Set the position of the icon. Note that twm groups all
2679 icons in an icon window. */
2680 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2681 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2682 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2684 CHECK_NUMBER (icon_x
);
2685 CHECK_NUMBER (icon_y
);
2687 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2688 error ("Both left and top icon corners of icon must be specified");
2692 if (! EQ (icon_x
, Qunbound
))
2693 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2695 /* Start up iconic or window? */
2696 x_wm_set_window_state
2697 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
2702 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
2709 /* Make the GCs needed for this window, setting the
2710 background, border and mouse colors; also create the
2711 mouse cursor and the gray border tile. */
2713 static char cursor_bits
[] =
2715 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2716 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2717 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2718 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2725 XGCValues gc_values
;
2729 /* Create the GCs of this frame.
2730 Note that many default values are used. */
2733 gc_values
.font
= FRAME_FONT (f
)->fid
;
2734 gc_values
.foreground
= f
->output_data
.x
->foreground_pixel
;
2735 gc_values
.background
= f
->output_data
.x
->background_pixel
;
2736 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2737 f
->output_data
.x
->normal_gc
2738 = XCreateGC (FRAME_X_DISPLAY (f
),
2740 GCLineWidth
| GCFont
| GCForeground
| GCBackground
,
2743 /* Reverse video style. */
2744 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
2745 gc_values
.background
= f
->output_data
.x
->foreground_pixel
;
2746 f
->output_data
.x
->reverse_gc
2747 = XCreateGC (FRAME_X_DISPLAY (f
),
2749 GCFont
| GCForeground
| GCBackground
| GCLineWidth
,
2752 /* Cursor has cursor-color background, background-color foreground. */
2753 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
2754 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
2755 gc_values
.fill_style
= FillOpaqueStippled
;
2757 = XCreateBitmapFromData (FRAME_X_DISPLAY (f
),
2758 FRAME_X_DISPLAY_INFO (f
)->root_window
,
2759 cursor_bits
, 16, 16);
2760 f
->output_data
.x
->cursor_gc
2761 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2762 (GCFont
| GCForeground
| GCBackground
2763 | GCFillStyle
/* | GCStipple */ | GCLineWidth
),
2767 f
->output_data
.x
->white_relief
.gc
= 0;
2768 f
->output_data
.x
->black_relief
.gc
= 0;
2770 /* Create the gray border tile used when the pointer is not in
2771 the frame. Since this depends on the frame's pixel values,
2772 this must be done on a per-frame basis. */
2773 f
->output_data
.x
->border_tile
2774 = (XCreatePixmapFromBitmapData
2775 (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
2776 gray_bits
, gray_width
, gray_height
,
2777 f
->output_data
.x
->foreground_pixel
,
2778 f
->output_data
.x
->background_pixel
,
2779 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
2785 /* Free what was was allocated in x_make_gc. */
2791 Display
*dpy
= FRAME_X_DISPLAY (f
);
2795 if (f
->output_data
.x
->normal_gc
)
2797 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
2798 f
->output_data
.x
->normal_gc
= 0;
2801 if (f
->output_data
.x
->reverse_gc
)
2803 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
2804 f
->output_data
.x
->reverse_gc
= 0;
2807 if (f
->output_data
.x
->cursor_gc
)
2809 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
2810 f
->output_data
.x
->cursor_gc
= 0;
2813 if (f
->output_data
.x
->border_tile
)
2815 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
2816 f
->output_data
.x
->border_tile
= 0;
2823 /* Handler for signals raised during x_create_frame and
2824 x_create_top_frame. FRAME is the frame which is partially
2828 unwind_create_frame (frame
)
2831 struct frame
*f
= XFRAME (frame
);
2833 /* If frame is ``official'', nothing to do. */
2834 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
2837 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2840 x_free_frame_resources (f
);
2842 /* Check that reference counts are indeed correct. */
2843 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
2844 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
2852 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
2854 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
2855 Returns an Emacs frame object.
2856 ALIST is an alist of frame parameters.
2857 If the parameters specify that the frame should not have a minibuffer,
2858 and do not specify a specific minibuffer window to use,
2859 then `default-minibuffer-frame' must be a frame whose minibuffer can
2860 be shared by the new frame.
2862 This function is an internal primitive--use `make-frame' instead. */)
2867 Lisp_Object frame
, tem
;
2869 int minibuffer_only
= 0;
2870 long window_prompting
= 0;
2872 int count
= SPECPDL_INDEX ();
2873 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
2874 Lisp_Object display
;
2875 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
, 0, 0, RES_TYPE_STRING
);
2886 if (EQ (display
, Qunbound
))
2888 dpyinfo
= check_x_display_info (display
);
2890 kb
= dpyinfo
->kboard
;
2892 kb
= &the_only_kboard
;
2895 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
2897 && ! EQ (name
, Qunbound
)
2899 error ("Invalid frame name--not a string or nil");
2902 Vx_resource_name
= name
;
2904 /* See if parent window is specified. */
2905 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
2906 if (EQ (parent
, Qunbound
))
2908 if (! NILP (parent
))
2909 CHECK_NUMBER (parent
);
2911 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
2912 /* No need to protect DISPLAY because that's not used after passing
2913 it to make_frame_without_minibuffer. */
2915 GCPRO4 (parms
, parent
, name
, frame
);
2916 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
2918 if (EQ (tem
, Qnone
) || NILP (tem
))
2919 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
2920 else if (EQ (tem
, Qonly
))
2922 f
= make_minibuffer_frame ();
2923 minibuffer_only
= 1;
2925 else if (WINDOWP (tem
))
2926 f
= make_frame_without_minibuffer (tem
, kb
, display
);
2930 XSETFRAME (frame
, f
);
2932 /* Note that X Windows does support scroll bars. */
2933 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
2935 f
->output_method
= output_x_window
;
2936 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
2937 bzero (f
->output_data
.x
, sizeof (struct x_output
));
2938 f
->output_data
.x
->icon_bitmap
= -1;
2939 FRAME_FONTSET (f
) = -1;
2940 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
2941 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
2942 #ifdef USE_TOOLKIT_SCROLL_BARS
2943 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
2944 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
2945 #endif /* USE_TOOLKIT_SCROLL_BARS */
2946 record_unwind_protect (unwind_create_frame
, frame
);
2949 = x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
2951 if (! STRINGP (f
->icon_name
))
2952 f
->icon_name
= Qnil
;
2954 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
2956 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
2957 dpyinfo_refcount
= dpyinfo
->reference_count
;
2958 #endif /* GLYPH_DEBUG */
2960 FRAME_KBOARD (f
) = kb
;
2963 /* These colors will be set anyway later, but it's important
2964 to get the color reference counts right, so initialize them! */
2967 struct gcpro gcpro1
;
2969 /* Function x_decode_color can signal an error. Make
2970 sure to initialize color slots so that we won't try
2971 to free colors we haven't allocated. */
2972 f
->output_data
.x
->foreground_pixel
= -1;
2973 f
->output_data
.x
->background_pixel
= -1;
2974 f
->output_data
.x
->cursor_pixel
= -1;
2975 f
->output_data
.x
->cursor_foreground_pixel
= -1;
2976 f
->output_data
.x
->border_pixel
= -1;
2977 f
->output_data
.x
->mouse_pixel
= -1;
2979 black
= build_string ("black");
2981 f
->output_data
.x
->foreground_pixel
2982 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2983 f
->output_data
.x
->background_pixel
2984 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2985 f
->output_data
.x
->cursor_pixel
2986 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2987 f
->output_data
.x
->cursor_foreground_pixel
2988 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2989 f
->output_data
.x
->border_pixel
2990 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2991 f
->output_data
.x
->mouse_pixel
2992 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2996 /* Specify the parent under which to make this X window. */
3000 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
3001 f
->output_data
.x
->explicit_parent
= 1;
3005 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3006 f
->output_data
.x
->explicit_parent
= 0;
3009 /* Set the name; the functions to which we pass f expect the name to
3011 if (EQ (name
, Qunbound
) || NILP (name
))
3013 f
->name
= build_string (dpyinfo
->x_id_name
);
3014 f
->explicit_name
= 0;
3019 f
->explicit_name
= 1;
3020 /* use the frame's title when getting resources for this frame. */
3021 specbind (Qx_resource_name
, name
);
3024 /* Extract the window parameters from the supplied values
3025 that are needed to determine window geometry. */
3029 font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
3031 /* If the caller has specified no font, try out fonts which we
3032 hope have bold and italic variations. */
3033 if (!STRINGP (font
))
3036 = { "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1",
3037 "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
3038 "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
3039 /* This was formerly the first thing tried, but it finds
3040 too many fonts and takes too long. */
3041 "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1",
3042 /* If those didn't work, look for something which will
3044 "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1",
3049 for (i
= 0; names
[i
]; i
++)
3053 list
= x_list_fonts (f
, build_string (names
[i
]), 0, 1);
3061 if (! STRINGP (font
))
3062 font
= build_string ("fixed");
3064 x_default_parameter (f
, parms
, Qfont
, font
,
3065 "font", "Font", RES_TYPE_STRING
);
3069 /* Prevent lwlib/xlwmenu.c from crashing because of a bug
3070 whereby it fails to get any font. */
3071 xlwmenu_default_font
= FRAME_FONT (f
);
3074 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
3075 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
3077 /* This defaults to 1 in order to match xterm. We recognize either
3078 internalBorderWidth or internalBorder (which is what xterm calls
3080 if (NILP (Fassq (Qinternal_border_width
, parms
)))
3084 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
3085 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
3086 if (! EQ (value
, Qunbound
))
3087 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
3090 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
3091 "internalBorderWidth", "internalBorderWidth",
3093 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qleft
,
3094 "verticalScrollBars", "ScrollBars",
3097 /* Also do the stuff which must be set before the window exists. */
3098 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3099 "foreground", "Foreground", RES_TYPE_STRING
);
3100 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3101 "background", "Background", RES_TYPE_STRING
);
3102 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3103 "pointerColor", "Foreground", RES_TYPE_STRING
);
3104 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
3105 "cursorColor", "Foreground", RES_TYPE_STRING
);
3106 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3107 "borderColor", "BorderColor", RES_TYPE_STRING
);
3108 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3109 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3110 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3111 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3112 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3113 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3114 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3115 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3117 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3118 "scrollBarForeground",
3119 "ScrollBarForeground", 1);
3120 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3121 "scrollBarBackground",
3122 "ScrollBarBackground", 0);
3124 /* Init faces before x_default_parameter is called for scroll-bar
3125 parameters because that function calls x_set_scroll_bar_width,
3126 which calls change_frame_size, which calls Fset_window_buffer,
3127 which runs hooks, which call Fvertical_motion. At the end, we
3128 end up in init_iterator with a null face cache, which should not
3130 init_frame_faces (f
);
3132 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
3133 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
3134 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (1),
3135 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
3136 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3137 "bufferPredicate", "BufferPredicate",
3139 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3140 "title", "Title", RES_TYPE_STRING
);
3141 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3142 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3143 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3144 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3146 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3148 /* Compute the size of the X window. */
3149 window_prompting
= x_figure_window_size (f
, parms
, 1);
3151 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3152 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3154 x_icon_verify (f
, parms
);
3156 /* Create the X widget or window. */
3157 #ifdef USE_X_TOOLKIT
3158 x_window (f
, window_prompting
, minibuffer_only
);
3166 /* Now consider the frame official. */
3167 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
3168 Vframe_list
= Fcons (frame
, Vframe_list
);
3170 /* We need to do this after creating the X window, so that the
3171 icon-creation functions can say whose icon they're describing. */
3172 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
3173 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
3175 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3176 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3177 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3178 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3179 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3180 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3181 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3182 "scrollBarWidth", "ScrollBarWidth",
3185 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
3186 Change will not be effected unless different from the current
3188 width
= FRAME_COLS (f
);
3189 height
= FRAME_LINES (f
);
3191 SET_FRAME_COLS (f
, 0);
3192 FRAME_LINES (f
) = 0;
3193 change_frame_size (f
, height
, width
, 1, 0, 0);
3195 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3196 /* Create the menu bar. */
3197 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3199 /* If this signals an error, we haven't set size hints for the
3200 frame and we didn't make it visible. */
3201 initialize_frame_menubar (f
);
3204 /* This is a no-op, except under Motif where it arranges the
3205 main window for the widgets on it. */
3206 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3207 f
->output_data
.x
->menubar_widget
,
3208 f
->output_data
.x
->edit_widget
);
3209 #endif /* not USE_GTK */
3211 #endif /* USE_X_TOOLKIT || USE_GTK */
3213 /* Tell the server what size and position, etc, we want, and how
3214 badly we want them. This should be done after we have the menu
3215 bar so that its size can be taken into account. */
3217 x_wm_set_size_hint (f
, window_prompting
, 0);
3220 /* Make the window appear on the frame and enable display, unless
3221 the caller says not to. However, with explicit parent, Emacs
3222 cannot control visibility, so don't try. */
3223 if (! f
->output_data
.x
->explicit_parent
)
3225 Lisp_Object visibility
;
3227 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3229 if (EQ (visibility
, Qunbound
))
3232 if (EQ (visibility
, Qicon
))
3233 x_iconify_frame (f
);
3234 else if (! NILP (visibility
))
3235 x_make_frame_visible (f
);
3237 /* Must have been Qnil. */
3241 /* Set the WM leader property. GTK does this itself, so this is not
3242 needed when using GTK. */
3243 if (dpyinfo
->client_leader_window
!= 0)
3246 XChangeProperty (FRAME_X_DISPLAY (f
),
3247 FRAME_OUTER_WINDOW (f
),
3248 dpyinfo
->Xatom_wm_client_leader
,
3249 XA_WINDOW
, 32, PropModeReplace
,
3250 (char *) &dpyinfo
->client_leader_window
, 1);
3256 /* Make sure windows on this frame appear in calls to next-window
3257 and similar functions. */
3258 Vwindow_list
= Qnil
;
3260 return unbind_to (count
, frame
);
3264 /* FRAME is used only to get a handle on the X display. We don't pass the
3265 display info directly because we're called from frame.c, which doesn't
3266 know about that structure. */
3269 x_get_focus_frame (frame
)
3270 struct frame
*frame
;
3272 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (frame
);
3274 if (! dpyinfo
->x_focus_frame
)
3277 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3282 /* In certain situations, when the window manager follows a
3283 click-to-focus policy, there seems to be no way around calling
3284 XSetInputFocus to give another frame the input focus .
3286 In an ideal world, XSetInputFocus should generally be avoided so
3287 that applications don't interfere with the window manager's focus
3288 policy. But I think it's okay to use when it's clearly done
3289 following a user-command. */
3291 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
3292 doc
: /* Set the input focus to FRAME.
3293 FRAME nil means use the selected frame. */)
3297 struct frame
*f
= check_x_frame (frame
);
3298 Display
*dpy
= FRAME_X_DISPLAY (f
);
3302 count
= x_catch_errors (dpy
);
3303 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3304 RevertToParent
, CurrentTime
);
3305 x_uncatch_errors (dpy
, count
);
3312 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
3313 doc
: /* Internal function called by `color-defined-p', which see. */)
3315 Lisp_Object color
, frame
;
3318 FRAME_PTR f
= check_x_frame (frame
);
3320 CHECK_STRING (color
);
3322 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
3328 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
3329 doc
: /* Internal function called by `color-values', which see. */)
3331 Lisp_Object color
, frame
;
3334 FRAME_PTR f
= check_x_frame (frame
);
3336 CHECK_STRING (color
);
3338 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
3342 rgb
[0] = make_number (foo
.red
);
3343 rgb
[1] = make_number (foo
.green
);
3344 rgb
[2] = make_number (foo
.blue
);
3345 return Flist (3, rgb
);
3351 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
3352 doc
: /* Internal function called by `display-color-p', which see. */)
3354 Lisp_Object display
;
3356 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3358 if (dpyinfo
->n_planes
<= 2)
3361 switch (dpyinfo
->visual
->class)
3374 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3376 doc
: /* Return t if the X display supports shades of gray.
3377 Note that color displays do support shades of gray.
3378 The optional argument DISPLAY specifies which display to ask about.
3379 DISPLAY should be either a frame or a display name (a string).
3380 If omitted or nil, that stands for the selected frame's display. */)
3382 Lisp_Object display
;
3384 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3386 if (dpyinfo
->n_planes
<= 1)
3389 switch (dpyinfo
->visual
->class)
3404 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3406 doc
: /* Returns the width in pixels of the X display DISPLAY.
3407 The optional argument DISPLAY specifies which display to ask about.
3408 DISPLAY should be either a frame or a display name (a string).
3409 If omitted or nil, that stands for the selected frame's display. */)
3411 Lisp_Object display
;
3413 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3415 return make_number (dpyinfo
->width
);
3418 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3419 Sx_display_pixel_height
, 0, 1, 0,
3420 doc
: /* Returns the height in pixels of the X display DISPLAY.
3421 The optional argument DISPLAY specifies which display to ask about.
3422 DISPLAY should be either a frame or a display name (a string).
3423 If omitted or nil, that stands for the selected frame's display. */)
3425 Lisp_Object display
;
3427 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3429 return make_number (dpyinfo
->height
);
3432 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3434 doc
: /* Returns the number of bitplanes of the X display DISPLAY.
3435 The optional argument DISPLAY specifies which display to ask about.
3436 DISPLAY should be either a frame or a display name (a string).
3437 If omitted or nil, that stands for the selected frame's display. */)
3439 Lisp_Object display
;
3441 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3443 return make_number (dpyinfo
->n_planes
);
3446 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3448 doc
: /* Returns the number of color cells of the X display DISPLAY.
3449 The optional argument DISPLAY specifies which display to ask about.
3450 DISPLAY should be either a frame or a display name (a string).
3451 If omitted or nil, that stands for the selected frame's display. */)
3453 Lisp_Object display
;
3455 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3457 int nr_planes
= DisplayPlanes (dpyinfo
->display
,
3458 XScreenNumberOfScreen (dpyinfo
->screen
));
3460 /* Truncate nr_planes to 24 to avoid integer overflow.
3461 Some displays says 32, but only 24 bits are actually significant.
3462 There are only very few and rare video cards that have more than
3463 24 significant bits. Also 24 bits is more than 16 million colors,
3464 it "should be enough for everyone". */
3465 if (nr_planes
> 24) nr_planes
= 24;
3467 return make_number (1 << nr_planes
);
3470 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3471 Sx_server_max_request_size
,
3473 doc
: /* Returns the maximum request size of the X server of display DISPLAY.
3474 The optional argument DISPLAY specifies which display to ask about.
3475 DISPLAY should be either a frame or a display name (a string).
3476 If omitted or nil, that stands for the selected frame's display. */)
3478 Lisp_Object display
;
3480 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3482 return make_number (MAXREQUEST (dpyinfo
->display
));
3485 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3486 doc
: /* Returns the "vendor ID" string of the X server of display DISPLAY.
3487 \(Labelling every distributor as a "vendor" embodies the false assumption
3488 that operating systems cannot be developed and distributed noncommercially.)
3489 The optional argument DISPLAY specifies which display to ask about.
3490 DISPLAY should be either a frame or a display name (a string).
3491 If omitted or nil, that stands for the selected frame's display. */)
3493 Lisp_Object display
;
3495 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3496 char *vendor
= ServerVendor (dpyinfo
->display
);
3498 if (! vendor
) vendor
= "";
3499 return build_string (vendor
);
3502 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3503 doc
: /* Returns the version numbers of the X server of display DISPLAY.
3504 The value is a list of three integers: the major and minor
3505 version numbers of the X Protocol in use, and the distributor-specific release
3506 number. See also the function `x-server-vendor'.
3508 The optional argument DISPLAY specifies which display to ask about.
3509 DISPLAY should be either a frame or a display name (a string).
3510 If omitted or nil, that stands for the selected frame's display. */)
3512 Lisp_Object display
;
3514 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3515 Display
*dpy
= dpyinfo
->display
;
3517 return Fcons (make_number (ProtocolVersion (dpy
)),
3518 Fcons (make_number (ProtocolRevision (dpy
)),
3519 Fcons (make_number (VendorRelease (dpy
)), Qnil
)));
3522 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3523 doc
: /* Return the number of screens on the X server of display DISPLAY.
3524 The optional argument DISPLAY specifies which display to ask about.
3525 DISPLAY should be either a frame or a display name (a string).
3526 If omitted or nil, that stands for the selected frame's display. */)
3528 Lisp_Object display
;
3530 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3532 return make_number (ScreenCount (dpyinfo
->display
));
3535 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3536 doc
: /* Return the height in millimeters of the X display DISPLAY.
3537 The optional argument DISPLAY specifies which display to ask about.
3538 DISPLAY should be either a frame or a display name (a string).
3539 If omitted or nil, that stands for the selected frame's display. */)
3541 Lisp_Object display
;
3543 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3545 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3548 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3549 doc
: /* Return the width in millimeters of the X display DISPLAY.
3550 The optional argument DISPLAY specifies which display to ask about.
3551 DISPLAY should be either a frame or a display name (a string).
3552 If omitted or nil, that stands for the selected frame's display. */)
3554 Lisp_Object display
;
3556 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3558 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3561 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3562 Sx_display_backing_store
, 0, 1, 0,
3563 doc
: /* Returns an indication of whether X display DISPLAY does backing store.
3564 The value may be `always', `when-mapped', or `not-useful'.
3565 The optional argument DISPLAY specifies which display to ask about.
3566 DISPLAY should be either a frame or a display name (a string).
3567 If omitted or nil, that stands for the selected frame's display. */)
3569 Lisp_Object display
;
3571 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3574 switch (DoesBackingStore (dpyinfo
->screen
))
3577 result
= intern ("always");
3581 result
= intern ("when-mapped");
3585 result
= intern ("not-useful");
3589 error ("Strange value for BackingStore parameter of screen");
3596 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3597 Sx_display_visual_class
, 0, 1, 0,
3598 doc
: /* Return the visual class of the X display DISPLAY.
3599 The value is one of the symbols `static-gray', `gray-scale',
3600 `static-color', `pseudo-color', `true-color', or `direct-color'.
3602 The optional argument DISPLAY specifies which display to ask about.
3603 DISPLAY should be either a frame or a display name (a string).
3604 If omitted or nil, that stands for the selected frame's display. */)
3606 Lisp_Object display
;
3608 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3611 switch (dpyinfo
->visual
->class)
3614 result
= intern ("static-gray");
3617 result
= intern ("gray-scale");
3620 result
= intern ("static-color");
3623 result
= intern ("pseudo-color");
3626 result
= intern ("true-color");
3629 result
= intern ("direct-color");
3632 error ("Display has an unknown visual class");
3639 DEFUN ("x-display-save-under", Fx_display_save_under
,
3640 Sx_display_save_under
, 0, 1, 0,
3641 doc
: /* Returns t if the X display DISPLAY supports the save-under feature.
3642 The optional argument DISPLAY specifies which display to ask about.
3643 DISPLAY should be either a frame or a display name (a string).
3644 If omitted or nil, that stands for the selected frame's display. */)
3646 Lisp_Object display
;
3648 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3650 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3658 register struct frame
*f
;
3660 return FRAME_PIXEL_WIDTH (f
);
3665 register struct frame
*f
;
3667 return FRAME_PIXEL_HEIGHT (f
);
3672 register struct frame
*f
;
3674 return FRAME_COLUMN_WIDTH (f
);
3679 register struct frame
*f
;
3681 return FRAME_LINE_HEIGHT (f
);
3686 register struct frame
*f
;
3688 return FRAME_X_DISPLAY_INFO (f
)->n_planes
;
3693 /************************************************************************
3695 ************************************************************************/
3698 /* Mapping visual names to visuals. */
3700 static struct visual_class
3707 {"StaticGray", StaticGray
},
3708 {"GrayScale", GrayScale
},
3709 {"StaticColor", StaticColor
},
3710 {"PseudoColor", PseudoColor
},
3711 {"TrueColor", TrueColor
},
3712 {"DirectColor", DirectColor
},
3717 #ifndef HAVE_XSCREENNUMBEROFSCREEN
3719 /* Value is the screen number of screen SCR. This is a substitute for
3720 the X function with the same name when that doesn't exist. */
3723 XScreenNumberOfScreen (scr
)
3724 register Screen
*scr
;
3726 Display
*dpy
= scr
->display
;
3729 for (i
= 0; i
< dpy
->nscreens
; ++i
)
3730 if (scr
== dpy
->screens
+ i
)
3736 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
3739 /* Select the visual that should be used on display DPYINFO. Set
3740 members of DPYINFO appropriately. Called from x_term_init. */
3743 select_visual (dpyinfo
)
3744 struct x_display_info
*dpyinfo
;
3746 Display
*dpy
= dpyinfo
->display
;
3747 Screen
*screen
= dpyinfo
->screen
;
3750 /* See if a visual is specified. */
3751 value
= display_x_get_resource (dpyinfo
,
3752 build_string ("visualClass"),
3753 build_string ("VisualClass"),
3755 if (STRINGP (value
))
3757 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
3758 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
3759 depth, a decimal number. NAME is compared with case ignored. */
3760 char *s
= (char *) alloca (SBYTES (value
) + 1);
3765 strcpy (s
, SDATA (value
));
3766 dash
= index (s
, '-');
3769 dpyinfo
->n_planes
= atoi (dash
+ 1);
3773 /* We won't find a matching visual with depth 0, so that
3774 an error will be printed below. */
3775 dpyinfo
->n_planes
= 0;
3777 /* Determine the visual class. */
3778 for (i
= 0; visual_classes
[i
].name
; ++i
)
3779 if (xstricmp (s
, visual_classes
[i
].name
) == 0)
3781 class = visual_classes
[i
].class;
3785 /* Look up a matching visual for the specified class. */
3787 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
3788 dpyinfo
->n_planes
, class, &vinfo
))
3789 fatal ("Invalid visual specification `%s'", SDATA (value
));
3791 dpyinfo
->visual
= vinfo
.visual
;
3796 XVisualInfo
*vinfo
, vinfo_template
;
3798 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
3801 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
3803 vinfo_template
.visualid
= dpyinfo
->visual
->visualid
;
3805 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
3806 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
3807 &vinfo_template
, &n_visuals
);
3809 fatal ("Can't get proper X visual info");
3811 dpyinfo
->n_planes
= vinfo
->depth
;
3812 XFree ((char *) vinfo
);
3817 /* Return the X display structure for the display named NAME.
3818 Open a new connection if necessary. */
3820 struct x_display_info
*
3821 x_display_info_for_name (name
)
3825 struct x_display_info
*dpyinfo
;
3827 CHECK_STRING (name
);
3829 if (! EQ (Vwindow_system
, intern ("x")))
3830 error ("Not using X Windows");
3832 for (dpyinfo
= x_display_list
, names
= x_display_name_list
;
3834 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
3837 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
3842 /* Use this general default value to start with. */
3843 Vx_resource_name
= Vinvocation_name
;
3845 validate_x_resource_name ();
3847 dpyinfo
= x_term_init (name
, (char *)0,
3848 (char *) SDATA (Vx_resource_name
));
3851 error ("Cannot connect to X server %s", SDATA (name
));
3854 XSETFASTINT (Vwindow_system_version
, 11);
3860 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
3862 doc
: /* Open a connection to an X server.
3863 DISPLAY is the name of the display to connect to.
3864 Optional second arg XRM-STRING is a string of resources in xrdb format.
3865 If the optional third arg MUST-SUCCEED is non-nil,
3866 terminate Emacs if we can't open the connection. */)
3867 (display
, xrm_string
, must_succeed
)
3868 Lisp_Object display
, xrm_string
, must_succeed
;
3870 unsigned char *xrm_option
;
3871 struct x_display_info
*dpyinfo
;
3873 CHECK_STRING (display
);
3874 if (! NILP (xrm_string
))
3875 CHECK_STRING (xrm_string
);
3877 if (! EQ (Vwindow_system
, intern ("x")))
3878 error ("Not using X Windows");
3880 if (! NILP (xrm_string
))
3881 xrm_option
= (unsigned char *) SDATA (xrm_string
);
3883 xrm_option
= (unsigned char *) 0;
3885 validate_x_resource_name ();
3887 /* This is what opens the connection and sets x_current_display.
3888 This also initializes many symbols, such as those used for input. */
3889 dpyinfo
= x_term_init (display
, xrm_option
,
3890 (char *) SDATA (Vx_resource_name
));
3894 if (!NILP (must_succeed
))
3895 fatal ("Cannot connect to X server %s.\n\
3896 Check the DISPLAY environment variable or use `-d'.\n\
3897 Also use the `xauth' program to verify that you have the proper\n\
3898 authorization information needed to connect the X server.\n\
3899 An insecure way to solve the problem may be to use `xhost'.\n",
3902 error ("Cannot connect to X server %s", SDATA (display
));
3907 XSETFASTINT (Vwindow_system_version
, 11);
3911 DEFUN ("x-close-connection", Fx_close_connection
,
3912 Sx_close_connection
, 1, 1, 0,
3913 doc
: /* Close the connection to DISPLAY's X server.
3914 For DISPLAY, specify either a frame or a display name (a string).
3915 If DISPLAY is nil, that stands for the selected frame's display. */)
3917 Lisp_Object display
;
3919 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3922 if (dpyinfo
->reference_count
> 0)
3923 error ("Display still has frames on it");
3926 /* Free the fonts in the font table. */
3927 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
3928 if (dpyinfo
->font_table
[i
].name
)
3930 XFreeFont (dpyinfo
->display
, dpyinfo
->font_table
[i
].font
);
3933 x_destroy_all_bitmaps (dpyinfo
);
3934 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
3936 #ifdef USE_X_TOOLKIT
3937 XtCloseDisplay (dpyinfo
->display
);
3939 XCloseDisplay (dpyinfo
->display
);
3942 x_delete_display (dpyinfo
);
3948 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
3949 doc
: /* Return the list of display names that Emacs has connections to. */)
3952 Lisp_Object tail
, result
;
3955 for (tail
= x_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
3956 result
= Fcons (XCAR (XCAR (tail
)), result
);
3961 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
3962 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
3963 If ON is nil, allow buffering of requests.
3964 Turning on synchronization prohibits the Xlib routines from buffering
3965 requests and seriously degrades performance, but makes debugging much
3967 The optional second argument DISPLAY specifies which display to act on.
3968 DISPLAY should be either a frame or a display name (a string).
3969 If DISPLAY is omitted or nil, that stands for the selected frame's display. */)
3971 Lisp_Object display
, on
;
3973 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3975 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
3980 /* Wait for responses to all X commands issued so far for frame F. */
3987 XSync (FRAME_X_DISPLAY (f
), False
);
3992 /***********************************************************************
3994 ***********************************************************************/
3996 DEFUN ("x-change-window-property", Fx_change_window_property
,
3997 Sx_change_window_property
, 2, 6, 0,
3998 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
3999 PROP must be a string.
4000 VALUE may be a string or a list of conses, numbers and/or strings.
4001 If an element in the list is a string, it is converted to
4002 an Atom and the value of the Atom is used. If an element is a cons,
4003 it is converted to a 32 bit number where the car is the 16 top bits and the
4004 cdr is the lower 16 bits.
4005 FRAME nil or omitted means use the selected frame.
4006 If TYPE is given and non-nil, it is the name of the type of VALUE.
4007 If TYPE is not given or nil, the type is STRING.
4008 FORMAT gives the size in bits of each element if VALUE is a list.
4009 It must be one of 8, 16 or 32.
4010 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4011 If OUTER_P is non-nil, the property is changed for the outer X window of
4012 FRAME. Default is to change on the edit X window.
4015 (prop
, value
, frame
, type
, format
, outer_p
)
4016 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
4018 struct frame
*f
= check_x_frame (frame
);
4020 Atom target_type
= XA_STRING
;
4021 int element_format
= 8;
4022 unsigned char *data
;
4026 CHECK_STRING (prop
);
4028 if (! NILP (format
))
4030 CHECK_NUMBER (format
);
4031 element_format
= XFASTINT (format
);
4033 if (element_format
!= 8 && element_format
!= 16
4034 && element_format
!= 32)
4035 error ("FORMAT must be one of 8, 16 or 32");
4040 nelements
= x_check_property_data (value
);
4041 if (nelements
== -1)
4042 error ("Bad data in VALUE, must be number, string or cons");
4044 if (element_format
== 8)
4045 data
= (unsigned char *) xmalloc (nelements
);
4046 else if (element_format
== 16)
4047 data
= (unsigned char *) xmalloc (nelements
*2);
4049 data
= (unsigned char *) xmalloc (nelements
*4);
4051 x_fill_property_data (FRAME_X_DISPLAY (f
), value
, data
, element_format
);
4055 CHECK_STRING (value
);
4056 data
= SDATA (value
);
4057 nelements
= SCHARS (value
);
4061 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4064 CHECK_STRING (type
);
4065 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (type
), False
);
4068 if (! NILP (outer_p
)) w
= FRAME_OUTER_WINDOW (f
);
4069 else w
= FRAME_X_WINDOW (f
);
4071 XChangeProperty (FRAME_X_DISPLAY (f
), w
,
4072 prop_atom
, target_type
, element_format
, PropModeReplace
,
4075 if (CONSP (value
)) xfree (data
);
4077 /* Make sure the property is set when we return. */
4078 XFlush (FRAME_X_DISPLAY (f
));
4085 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
4086 Sx_delete_window_property
, 1, 2, 0,
4087 doc
: /* Remove window property PROP from X window of FRAME.
4088 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4090 Lisp_Object prop
, frame
;
4092 struct frame
*f
= check_x_frame (frame
);
4095 CHECK_STRING (prop
);
4097 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4098 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
4100 /* Make sure the property is removed when we return. */
4101 XFlush (FRAME_X_DISPLAY (f
));
4108 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
4110 doc
: /* Value is the value of window property PROP on FRAME.
4111 If FRAME is nil or omitted, use the selected frame.
4112 If TYPE is nil or omitted, get the property as a string. Otherwise TYPE
4113 is the name of the Atom that denotes the type expected.
4114 If SOURCE is non-nil, get the property on that window instead of from
4115 FRAME. The number 0 denotes the root window.
4116 If DELETE_P is non-nil, delete the property after retreiving it.
4117 If VECTOR_RET_P is non-nil, don't return a string but a vector of values.
4119 Value is nil if FRAME hasn't a property with name PROP or if PROP has
4120 no value of TYPE. */)
4121 (prop
, frame
, type
, source
, delete_p
, vector_ret_p
)
4122 Lisp_Object prop
, frame
, type
, source
, delete_p
, vector_ret_p
;
4124 struct frame
*f
= check_x_frame (frame
);
4127 Lisp_Object prop_value
= Qnil
;
4128 char *tmp_data
= NULL
;
4130 Atom target_type
= XA_STRING
;
4132 unsigned long actual_size
, bytes_remaining
;
4133 Window target_window
= FRAME_X_WINDOW (f
);
4134 struct gcpro gcpro1
;
4136 GCPRO1 (prop_value
);
4137 CHECK_STRING (prop
);
4139 if (! NILP (source
))
4141 if (NUMBERP (source
))
4143 if (FLOATP (source
))
4144 target_window
= (Window
) XFLOAT (source
);
4146 target_window
= XFASTINT (source
);
4148 if (target_window
== 0)
4149 target_window
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4151 else if (CONSP (source
))
4152 target_window
= cons_to_long (source
);
4158 if (strcmp ("AnyPropertyType", SDATA (type
)) == 0)
4159 target_type
= AnyPropertyType
;
4161 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (type
), False
);
4164 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4165 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4166 prop_atom
, 0, 0, False
, target_type
,
4167 &actual_type
, &actual_format
, &actual_size
,
4168 &bytes_remaining
, (unsigned char **) &tmp_data
);
4171 int size
= bytes_remaining
;
4176 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4177 prop_atom
, 0, bytes_remaining
,
4178 ! NILP (delete_p
), target_type
,
4179 &actual_type
, &actual_format
,
4180 &actual_size
, &bytes_remaining
,
4181 (unsigned char **) &tmp_data
);
4182 if (rc
== Success
&& tmp_data
)
4184 if (NILP (vector_ret_p
))
4185 prop_value
= make_string (tmp_data
, size
);
4187 prop_value
= x_property_data_to_lisp (f
,
4188 (unsigned char *) tmp_data
,
4194 if (tmp_data
) XFree (tmp_data
);
4204 /***********************************************************************
4206 ***********************************************************************/
4208 /* If non-null, an asynchronous timer that, when it expires, displays
4209 an hourglass cursor on all frames. */
4211 static struct atimer
*hourglass_atimer
;
4213 /* Non-zero means an hourglass cursor is currently shown. */
4215 static int hourglass_shown_p
;
4217 /* Number of seconds to wait before displaying an hourglass cursor. */
4219 static Lisp_Object Vhourglass_delay
;
4221 /* Default number of seconds to wait before displaying an hourglass
4224 #define DEFAULT_HOURGLASS_DELAY 1
4226 /* Function prototypes. */
4228 static void show_hourglass
P_ ((struct atimer
*));
4229 static void hide_hourglass
P_ ((void));
4232 /* Cancel a currently active hourglass timer, and start a new one. */
4238 int secs
, usecs
= 0;
4240 cancel_hourglass ();
4242 if (INTEGERP (Vhourglass_delay
)
4243 && XINT (Vhourglass_delay
) > 0)
4244 secs
= XFASTINT (Vhourglass_delay
);
4245 else if (FLOATP (Vhourglass_delay
)
4246 && XFLOAT_DATA (Vhourglass_delay
) > 0)
4249 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
4250 secs
= XFASTINT (tem
);
4251 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
4254 secs
= DEFAULT_HOURGLASS_DELAY
;
4256 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
4257 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
4258 show_hourglass
, NULL
);
4262 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
4268 if (hourglass_atimer
)
4270 cancel_atimer (hourglass_atimer
);
4271 hourglass_atimer
= NULL
;
4274 if (hourglass_shown_p
)
4279 /* Timer function of hourglass_atimer. TIMER is equal to
4282 Display an hourglass pointer on all frames by mapping the frames'
4283 hourglass_window. Set the hourglass_p flag in the frames'
4284 output_data.x structure to indicate that an hourglass cursor is
4285 shown on the frames. */
4288 show_hourglass (timer
)
4289 struct atimer
*timer
;
4291 /* The timer implementation will cancel this timer automatically
4292 after this function has run. Set hourglass_atimer to null
4293 so that we know the timer doesn't have to be canceled. */
4294 hourglass_atimer
= NULL
;
4296 if (!hourglass_shown_p
)
4298 Lisp_Object rest
, frame
;
4302 FOR_EACH_FRAME (rest
, frame
)
4304 struct frame
*f
= XFRAME (frame
);
4306 if (FRAME_LIVE_P (f
) && FRAME_X_P (f
) && FRAME_X_DISPLAY (f
))
4308 Display
*dpy
= FRAME_X_DISPLAY (f
);
4310 #ifdef USE_X_TOOLKIT
4311 if (f
->output_data
.x
->widget
)
4313 if (FRAME_OUTER_WINDOW (f
))
4316 f
->output_data
.x
->hourglass_p
= 1;
4318 if (!f
->output_data
.x
->hourglass_window
)
4320 unsigned long mask
= CWCursor
;
4321 XSetWindowAttributes attrs
;
4323 attrs
.cursor
= f
->output_data
.x
->hourglass_cursor
;
4325 f
->output_data
.x
->hourglass_window
4326 = XCreateWindow (dpy
, FRAME_OUTER_WINDOW (f
),
4327 0, 0, 32000, 32000, 0, 0,
4333 XMapRaised (dpy
, f
->output_data
.x
->hourglass_window
);
4339 hourglass_shown_p
= 1;
4345 /* Hide the hourglass pointer on all frames, if it is currently
4351 if (hourglass_shown_p
)
4353 Lisp_Object rest
, frame
;
4356 FOR_EACH_FRAME (rest
, frame
)
4358 struct frame
*f
= XFRAME (frame
);
4361 /* Watch out for newly created frames. */
4362 && f
->output_data
.x
->hourglass_window
)
4364 XUnmapWindow (FRAME_X_DISPLAY (f
),
4365 f
->output_data
.x
->hourglass_window
);
4366 /* Sync here because XTread_socket looks at the
4367 hourglass_p flag that is reset to zero below. */
4368 XSync (FRAME_X_DISPLAY (f
), False
);
4369 f
->output_data
.x
->hourglass_p
= 0;
4373 hourglass_shown_p
= 0;
4380 /***********************************************************************
4382 ***********************************************************************/
4384 static Lisp_Object x_create_tip_frame
P_ ((struct x_display_info
*,
4385 Lisp_Object
, Lisp_Object
));
4386 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
4387 Lisp_Object
, int, int, int *, int *));
4389 /* The frame of a currently visible tooltip. */
4391 Lisp_Object tip_frame
;
4393 /* If non-nil, a timer started that hides the last tooltip when it
4396 Lisp_Object tip_timer
;
4399 /* If non-nil, a vector of 3 elements containing the last args
4400 with which x-show-tip was called. See there. */
4402 Lisp_Object last_show_tip_args
;
4404 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
4406 Lisp_Object Vx_max_tooltip_size
;
4410 unwind_create_tip_frame (frame
)
4413 Lisp_Object deleted
;
4415 deleted
= unwind_create_frame (frame
);
4416 if (EQ (deleted
, Qt
))
4426 /* Create a frame for a tooltip on the display described by DPYINFO.
4427 PARMS is a list of frame parameters. TEXT is the string to
4428 display in the tip frame. Value is the frame.
4430 Note that functions called here, esp. x_default_parameter can
4431 signal errors, for instance when a specified color name is
4432 undefined. We have to make sure that we're in a consistent state
4433 when this happens. */
4436 x_create_tip_frame (dpyinfo
, parms
, text
)
4437 struct x_display_info
*dpyinfo
;
4438 Lisp_Object parms
, text
;
4441 Lisp_Object frame
, tem
;
4443 long window_prompting
= 0;
4445 int count
= SPECPDL_INDEX ();
4446 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4448 int face_change_count_before
= face_change_count
;
4450 struct buffer
*old_buffer
;
4454 /* Use this general default value to start with until we know if
4455 this frame has a specified name. */
4456 Vx_resource_name
= Vinvocation_name
;
4459 kb
= dpyinfo
->kboard
;
4461 kb
= &the_only_kboard
;
4464 /* Get the name of the frame to use for resource lookup. */
4465 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
4467 && !EQ (name
, Qunbound
)
4469 error ("Invalid frame name--not a string or nil");
4470 Vx_resource_name
= name
;
4473 GCPRO3 (parms
, name
, frame
);
4475 XSETFRAME (frame
, f
);
4477 buffer
= Fget_buffer_create (build_string (" *tip*"));
4478 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
4479 old_buffer
= current_buffer
;
4480 set_buffer_internal_1 (XBUFFER (buffer
));
4481 current_buffer
->truncate_lines
= Qnil
;
4482 specbind (Qinhibit_read_only
, Qt
);
4483 specbind (Qinhibit_modification_hooks
, Qt
);
4486 set_buffer_internal_1 (old_buffer
);
4488 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
4489 record_unwind_protect (unwind_create_tip_frame
, frame
);
4491 /* By setting the output method, we're essentially saying that
4492 the frame is live, as per FRAME_LIVE_P. If we get a signal
4493 from this point on, x_destroy_window might screw up reference
4495 f
->output_method
= output_x_window
;
4496 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
4497 bzero (f
->output_data
.x
, sizeof (struct x_output
));
4498 f
->output_data
.x
->icon_bitmap
= -1;
4499 FRAME_FONTSET (f
) = -1;
4500 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
4501 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
4502 #ifdef USE_TOOLKIT_SCROLL_BARS
4503 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
4504 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
4505 #endif /* USE_TOOLKIT_SCROLL_BARS */
4506 f
->icon_name
= Qnil
;
4507 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
4509 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
4510 dpyinfo_refcount
= dpyinfo
->reference_count
;
4511 #endif /* GLYPH_DEBUG */
4513 FRAME_KBOARD (f
) = kb
;
4515 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4516 f
->output_data
.x
->explicit_parent
= 0;
4518 /* These colors will be set anyway later, but it's important
4519 to get the color reference counts right, so initialize them! */
4522 struct gcpro gcpro1
;
4524 black
= build_string ("black");
4526 f
->output_data
.x
->foreground_pixel
4527 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4528 f
->output_data
.x
->background_pixel
4529 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4530 f
->output_data
.x
->cursor_pixel
4531 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4532 f
->output_data
.x
->cursor_foreground_pixel
4533 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4534 f
->output_data
.x
->border_pixel
4535 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4536 f
->output_data
.x
->mouse_pixel
4537 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4541 /* Set the name; the functions to which we pass f expect the name to
4543 if (EQ (name
, Qunbound
) || NILP (name
))
4545 f
->name
= build_string (dpyinfo
->x_id_name
);
4546 f
->explicit_name
= 0;
4551 f
->explicit_name
= 1;
4552 /* use the frame's title when getting resources for this frame. */
4553 specbind (Qx_resource_name
, name
);
4556 /* Extract the window parameters from the supplied values that are
4557 needed to determine window geometry. */
4561 font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4564 /* First, try whatever font the caller has specified. */
4567 tem
= Fquery_fontset (font
, Qnil
);
4569 font
= x_new_fontset (f
, tem
);
4571 font
= x_new_font (f
, SDATA (font
));
4574 /* Try out a font which we hope has bold and italic variations. */
4575 if (!STRINGP (font
))
4576 font
= x_new_font (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
4577 if (!STRINGP (font
))
4578 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
4579 if (! STRINGP (font
))
4580 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
4581 if (! STRINGP (font
))
4582 /* This was formerly the first thing tried, but it finds too many fonts
4583 and takes too long. */
4584 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
4585 /* If those didn't work, look for something which will at least work. */
4586 if (! STRINGP (font
))
4587 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
4589 if (! STRINGP (font
))
4590 font
= build_string ("fixed");
4592 x_default_parameter (f
, parms
, Qfont
, font
,
4593 "font", "Font", RES_TYPE_STRING
);
4596 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
4597 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4599 /* This defaults to 2 in order to match xterm. We recognize either
4600 internalBorderWidth or internalBorder (which is what xterm calls
4602 if (NILP (Fassq (Qinternal_border_width
, parms
)))
4606 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
4607 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
4608 if (! EQ (value
, Qunbound
))
4609 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
4613 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
4614 "internalBorderWidth", "internalBorderWidth",
4617 /* Also do the stuff which must be set before the window exists. */
4618 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
4619 "foreground", "Foreground", RES_TYPE_STRING
);
4620 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
4621 "background", "Background", RES_TYPE_STRING
);
4622 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
4623 "pointerColor", "Foreground", RES_TYPE_STRING
);
4624 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
4625 "cursorColor", "Foreground", RES_TYPE_STRING
);
4626 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
4627 "borderColor", "BorderColor", RES_TYPE_STRING
);
4629 /* Init faces before x_default_parameter is called for scroll-bar
4630 parameters because that function calls x_set_scroll_bar_width,
4631 which calls change_frame_size, which calls Fset_window_buffer,
4632 which runs hooks, which call Fvertical_motion. At the end, we
4633 end up in init_iterator with a null face cache, which should not
4635 init_frame_faces (f
);
4637 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4639 window_prompting
= x_figure_window_size (f
, parms
, 0);
4642 XSetWindowAttributes attrs
;
4646 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
;
4647 if (DoesSaveUnders (dpyinfo
->screen
))
4648 mask
|= CWSaveUnder
;
4650 /* Window managers look at the override-redirect flag to determine
4651 whether or net to give windows a decoration (Xlib spec, chapter
4653 attrs
.override_redirect
= True
;
4654 attrs
.save_under
= True
;
4655 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
4656 /* Arrange for getting MapNotify and UnmapNotify events. */
4657 attrs
.event_mask
= StructureNotifyMask
;
4659 = FRAME_X_WINDOW (f
)
4660 = XCreateWindow (FRAME_X_DISPLAY (f
),
4661 FRAME_X_DISPLAY_INFO (f
)->root_window
,
4662 /* x, y, width, height */
4666 CopyFromParent
, InputOutput
, CopyFromParent
,
4673 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
4674 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4675 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
4676 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4677 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
4678 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4680 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4681 Change will not be effected unless different from the current
4683 width
= FRAME_COLS (f
);
4684 height
= FRAME_LINES (f
);
4685 SET_FRAME_COLS (f
, 0);
4686 FRAME_LINES (f
) = 0;
4687 change_frame_size (f
, height
, width
, 1, 0, 0);
4689 /* Add `tooltip' frame parameter's default value. */
4690 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
4691 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
4694 /* Set up faces after all frame parameters are known. This call
4695 also merges in face attributes specified for new frames.
4697 Frame parameters may be changed if .Xdefaults contains
4698 specifications for the default font. For example, if there is an
4699 `Emacs.default.attributeBackground: pink', the `background-color'
4700 attribute of the frame get's set, which let's the internal border
4701 of the tooltip frame appear in pink. Prevent this. */
4703 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
4705 /* Set tip_frame here, so that */
4707 call1 (Qface_set_after_frame_default
, frame
);
4709 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
4710 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
4718 /* It is now ok to make the frame official even if we get an error
4719 below. And the frame needs to be on Vframe_list or making it
4720 visible won't work. */
4721 Vframe_list
= Fcons (frame
, Vframe_list
);
4723 /* Now that the frame is official, it counts as a reference to
4725 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
4727 /* Setting attributes of faces of the tooltip frame from resources
4728 and similar will increment face_change_count, which leads to the
4729 clearing of all current matrices. Since this isn't necessary
4730 here, avoid it by resetting face_change_count to the value it
4731 had before we created the tip frame. */
4732 face_change_count
= face_change_count_before
;
4734 /* Discard the unwind_protect. */
4735 return unbind_to (count
, frame
);
4739 /* Compute where to display tip frame F. PARMS is the list of frame
4740 parameters for F. DX and DY are specified offsets from the current
4741 location of the mouse. WIDTH and HEIGHT are the width and height
4742 of the tooltip. Return coordinates relative to the root window of
4743 the display in *ROOT_X, and *ROOT_Y. */
4746 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
4748 Lisp_Object parms
, dx
, dy
;
4750 int *root_x
, *root_y
;
4752 Lisp_Object left
, top
;
4757 /* User-specified position? */
4758 left
= Fcdr (Fassq (Qleft
, parms
));
4759 top
= Fcdr (Fassq (Qtop
, parms
));
4761 /* Move the tooltip window where the mouse pointer is. Resize and
4763 if (!INTEGERP (left
) || !INTEGERP (top
))
4766 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
4767 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
4772 *root_y
= XINT (top
);
4773 else if (*root_y
+ XINT (dy
) - height
< 0)
4774 *root_y
-= XINT (dy
);
4778 *root_y
+= XINT (dy
);
4781 if (INTEGERP (left
))
4782 *root_x
= XINT (left
);
4783 else if (*root_x
+ XINT (dx
) + width
<= FRAME_X_DISPLAY_INFO (f
)->width
)
4784 /* It fits to the right of the pointer. */
4785 *root_x
+= XINT (dx
);
4786 else if (width
+ XINT (dx
) <= *root_x
)
4787 /* It fits to the left of the pointer. */
4788 *root_x
-= width
+ XINT (dx
);
4790 /* Put it left-justified on the screen--it ought to fit that way. */
4795 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
4796 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
4797 A tooltip window is a small X window displaying a string.
4799 FRAME nil or omitted means use the selected frame.
4801 PARMS is an optional list of frame parameters which can be used to
4802 change the tooltip's appearance.
4804 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
4805 means use the default timeout of 5 seconds.
4807 If the list of frame parameters PARAMS contains a `left' parameters,
4808 the tooltip is displayed at that x-position. Otherwise it is
4809 displayed at the mouse position, with offset DX added (default is 5 if
4810 DX isn't specified). Likewise for the y-position; if a `top' frame
4811 parameter is specified, it determines the y-position of the tooltip
4812 window, otherwise it is displayed at the mouse position, with offset
4813 DY added (default is -10).
4815 A tooltip's maximum size is specified by `x-max-tooltip-size'.
4816 Text larger than the specified size is clipped. */)
4817 (string
, frame
, parms
, timeout
, dx
, dy
)
4818 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
4823 struct buffer
*old_buffer
;
4824 struct text_pos pos
;
4825 int i
, width
, height
;
4826 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4827 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
4828 int count
= SPECPDL_INDEX ();
4830 specbind (Qinhibit_redisplay
, Qt
);
4832 GCPRO4 (string
, parms
, frame
, timeout
);
4834 CHECK_STRING (string
);
4835 f
= check_x_frame (frame
);
4837 timeout
= make_number (5);
4839 CHECK_NATNUM (timeout
);
4842 dx
= make_number (5);
4847 dy
= make_number (-10);
4851 if (NILP (last_show_tip_args
))
4852 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
4854 if (!NILP (tip_frame
))
4856 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
4857 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
4858 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
4860 if (EQ (frame
, last_frame
)
4861 && !NILP (Fequal (last_string
, string
))
4862 && !NILP (Fequal (last_parms
, parms
)))
4864 struct frame
*f
= XFRAME (tip_frame
);
4866 /* Only DX and DY have changed. */
4867 if (!NILP (tip_timer
))
4869 Lisp_Object timer
= tip_timer
;
4871 call1 (Qcancel_timer
, timer
);
4875 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
4876 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
4877 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4884 /* Hide a previous tip, if any. */
4887 ASET (last_show_tip_args
, 0, string
);
4888 ASET (last_show_tip_args
, 1, frame
);
4889 ASET (last_show_tip_args
, 2, parms
);
4891 /* Add default values to frame parameters. */
4892 if (NILP (Fassq (Qname
, parms
)))
4893 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
4894 if (NILP (Fassq (Qinternal_border_width
, parms
)))
4895 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
4896 if (NILP (Fassq (Qborder_width
, parms
)))
4897 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
4898 if (NILP (Fassq (Qborder_color
, parms
)))
4899 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
4900 if (NILP (Fassq (Qbackground_color
, parms
)))
4901 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
4904 /* Create a frame for the tooltip, and record it in the global
4905 variable tip_frame. */
4906 frame
= x_create_tip_frame (FRAME_X_DISPLAY_INFO (f
), parms
, string
);
4909 /* Set up the frame's root window. */
4910 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4911 w
->left_col
= w
->top_line
= make_number (0);
4913 if (CONSP (Vx_max_tooltip_size
)
4914 && INTEGERP (XCAR (Vx_max_tooltip_size
))
4915 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
4916 && INTEGERP (XCDR (Vx_max_tooltip_size
))
4917 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
4919 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
4920 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
4924 w
->total_cols
= make_number (80);
4925 w
->total_lines
= make_number (40);
4928 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
4930 w
->pseudo_window_p
= 1;
4932 /* Display the tooltip text in a temporary buffer. */
4933 old_buffer
= current_buffer
;
4934 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
4935 current_buffer
->truncate_lines
= Qnil
;
4936 clear_glyph_matrix (w
->desired_matrix
);
4937 clear_glyph_matrix (w
->current_matrix
);
4938 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
4939 try_window (FRAME_ROOT_WINDOW (f
), pos
);
4941 /* Compute width and height of the tooltip. */
4943 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
4945 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
4949 /* Stop at the first empty row at the end. */
4950 if (!row
->enabled_p
|| !row
->displays_text_p
)
4953 /* Let the row go over the full width of the frame. */
4954 row
->full_width_p
= 1;
4956 /* There's a glyph at the end of rows that is used to place
4957 the cursor there. Don't include the width of this glyph. */
4958 if (row
->used
[TEXT_AREA
])
4960 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
4961 row_width
= row
->pixel_width
- last
->pixel_width
;
4964 row_width
= row
->pixel_width
;
4966 height
+= row
->height
;
4967 width
= max (width
, row_width
);
4970 /* Add the frame's internal border to the width and height the X
4971 window should have. */
4972 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
4973 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
4975 /* Move the tooltip window where the mouse pointer is. Resize and
4977 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
4980 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4981 root_x
, root_y
, width
, height
);
4982 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
4985 /* Draw into the window. */
4986 w
->must_be_updated_p
= 1;
4987 update_single_window (w
, 1);
4989 /* Restore original current buffer. */
4990 set_buffer_internal_1 (old_buffer
);
4991 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
4994 /* Let the tip disappear after timeout seconds. */
4995 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
4996 intern ("x-hide-tip"));
4999 return unbind_to (count
, Qnil
);
5003 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5004 doc
: /* Hide the current tooltip window, if there is any.
5005 Value is t if tooltip was open, nil otherwise. */)
5009 Lisp_Object deleted
, frame
, timer
;
5010 struct gcpro gcpro1
, gcpro2
;
5012 /* Return quickly if nothing to do. */
5013 if (NILP (tip_timer
) && NILP (tip_frame
))
5018 GCPRO2 (frame
, timer
);
5019 tip_frame
= tip_timer
= deleted
= Qnil
;
5021 count
= SPECPDL_INDEX ();
5022 specbind (Qinhibit_redisplay
, Qt
);
5023 specbind (Qinhibit_quit
, Qt
);
5026 call1 (Qcancel_timer
, timer
);
5030 Fdelete_frame (frame
, Qnil
);
5034 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5035 redisplay procedure is not called when a tip frame over menu
5036 items is unmapped. Redisplay the menu manually... */
5038 struct frame
*f
= SELECTED_FRAME ();
5039 Widget w
= f
->output_data
.x
->menubar_widget
;
5040 extern void xlwmenu_redisplay
P_ ((Widget
));
5042 if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f
)->screen
)
5046 xlwmenu_redisplay (w
);
5050 #endif /* USE_LUCID */
5054 return unbind_to (count
, deleted
);
5059 /***********************************************************************
5060 File selection dialog
5061 ***********************************************************************/
5065 /* Callback for "OK" and "Cancel" on file selection dialog. */
5068 file_dialog_cb (widget
, client_data
, call_data
)
5070 XtPointer call_data
, client_data
;
5072 int *result
= (int *) client_data
;
5073 XmAnyCallbackStruct
*cb
= (XmAnyCallbackStruct
*) call_data
;
5074 *result
= cb
->reason
;
5078 /* Callback for unmapping a file selection dialog. This is used to
5079 capture the case where a dialog is closed via a window manager's
5080 closer button, for example. Using a XmNdestroyCallback didn't work
5084 file_dialog_unmap_cb (widget
, client_data
, call_data
)
5086 XtPointer call_data
, client_data
;
5088 int *result
= (int *) client_data
;
5089 *result
= XmCR_CANCEL
;
5093 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5094 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5095 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5096 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5097 or directory must exist. ONLY-DIR-P is ignored." */)
5098 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
5099 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
5102 struct frame
*f
= SELECTED_FRAME ();
5103 Lisp_Object file
= Qnil
;
5104 Widget dialog
, text
, help
;
5107 extern XtAppContext Xt_app_con
;
5108 XmString dir_xmstring
, pattern_xmstring
;
5109 int count
= SPECPDL_INDEX ();
5110 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5112 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5113 CHECK_STRING (prompt
);
5116 /* Prevent redisplay. */
5117 specbind (Qinhibit_redisplay
, Qt
);
5121 /* Create the dialog with PROMPT as title, using DIR as initial
5122 directory and using "*" as pattern. */
5123 dir
= Fexpand_file_name (dir
, Qnil
);
5124 dir_xmstring
= XmStringCreateLocalized (SDATA (dir
));
5125 pattern_xmstring
= XmStringCreateLocalized ("*");
5127 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
5128 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
5129 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
5130 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
5131 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
5132 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
5134 XmStringFree (dir_xmstring
);
5135 XmStringFree (pattern_xmstring
);
5137 /* Add callbacks for OK and Cancel. */
5138 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
5139 (XtPointer
) &result
);
5140 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
5141 (XtPointer
) &result
);
5142 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
5143 (XtPointer
) &result
);
5145 /* Remove the help button since we can't display help. */
5146 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
5147 XtUnmanageChild (help
);
5149 /* Mark OK button as default. */
5150 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
5151 XmNshowAsDefault
, True
, NULL
);
5153 /* If MUSTMATCH is non-nil, disable the file entry field of the
5154 dialog, so that the user must select a file from the files list
5155 box. We can't remove it because we wouldn't have a way to get at
5156 the result file name, then. */
5157 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5158 if (!NILP (mustmatch
))
5161 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
5162 XtSetSensitive (text
, False
);
5163 XtSetSensitive (label
, False
);
5166 /* Manage the dialog, so that list boxes get filled. */
5167 XtManageChild (dialog
);
5169 if (STRINGP (default_filename
))
5171 XmString default_xmstring
;
5172 Widget wtext
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5173 Widget list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
5175 XmTextPosition last_pos
= XmTextFieldGetLastPosition (wtext
);
5176 XmTextFieldReplace (wtext
, 0, last_pos
,
5177 (SDATA (Ffile_name_nondirectory (default_filename
))));
5179 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5180 must include the path for this to work. */
5182 default_xmstring
= XmStringCreateLocalized (SDATA (default_filename
));
5184 if (XmListItemExists (list
, default_xmstring
))
5186 int item_pos
= XmListItemPos (list
, default_xmstring
);
5187 /* Select the item and scroll it into view. */
5188 XmListSelectPos (list
, item_pos
, True
);
5189 XmListSetPos (list
, item_pos
);
5192 XmStringFree (default_xmstring
);
5195 /* Process events until the user presses Cancel or OK. */
5200 XtAppNextEvent (Xt_app_con
, &event
);
5201 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
) );
5204 /* Get the result. */
5205 if (result
== XmCR_OK
)
5210 XtVaGetValues (dialog
, XmNtextString
, &text
, NULL
);
5211 XmStringGetLtoR (text
, XmFONTLIST_DEFAULT_TAG
, &data
);
5212 XmStringFree (text
);
5213 file
= build_string (data
);
5220 XtUnmanageChild (dialog
);
5221 XtDestroyWidget (dialog
);
5225 /* Make "Cancel" equivalent to C-g. */
5227 Fsignal (Qquit
, Qnil
);
5229 return unbind_to (count
, file
);
5232 #endif /* USE_MOTIF */
5236 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5237 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5238 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5239 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5240 or directory must exist. If ONLY-DIR-P is non-nil, the user can only select
5242 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
)
5243 Lisp_Object prompt
, dir
, default_filename
, mustmatch
, only_dir_p
;
5245 FRAME_PTR f
= SELECTED_FRAME ();
5247 Lisp_Object file
= Qnil
;
5248 int count
= specpdl_ptr
- specpdl
;
5249 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5252 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5253 CHECK_STRING (prompt
);
5256 /* Prevent redisplay. */
5257 specbind (Qinhibit_redisplay
, Qt
);
5261 if (STRINGP (default_filename
))
5262 cdef_file
= SDATA (default_filename
);
5264 cdef_file
= SDATA (dir
);
5266 fn
= xg_get_file_name (f
, SDATA (prompt
), cdef_file
,
5268 ! NILP (only_dir_p
));
5272 file
= build_string (fn
);
5279 /* Make "Cancel" equivalent to C-g. */
5281 Fsignal (Qquit
, Qnil
);
5283 return unbind_to (count
, file
);
5286 #endif /* USE_GTK */
5289 /***********************************************************************
5291 ***********************************************************************/
5293 #ifdef HAVE_XKBGETKEYBOARD
5294 #include <X11/XKBlib.h>
5295 #include <X11/keysym.h>
5298 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
5299 Sx_backspace_delete_keys_p
, 0, 1, 0,
5300 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
5301 FRAME nil means use the selected frame.
5302 Value is t if we know that both keys are present, and are mapped to the
5303 usual X keysyms. */)
5307 #ifdef HAVE_XKBGETKEYBOARD
5309 struct frame
*f
= check_x_frame (frame
);
5310 Display
*dpy
= FRAME_X_DISPLAY (f
);
5311 Lisp_Object have_keys
;
5312 int major
, minor
, op
, event
, error
;
5316 /* Check library version in case we're dynamically linked. */
5317 major
= XkbMajorVersion
;
5318 minor
= XkbMinorVersion
;
5319 if (!XkbLibraryVersion (&major
, &minor
))
5325 /* Check that the server supports XKB. */
5326 major
= XkbMajorVersion
;
5327 minor
= XkbMinorVersion
;
5328 if (!XkbQueryExtension (dpy
, &op
, &event
, &error
, &major
, &minor
))
5335 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
5338 int delete_keycode
= 0, backspace_keycode
= 0, i
;
5340 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
5342 for (i
= kb
->min_key_code
;
5343 (i
< kb
->max_key_code
5344 && (delete_keycode
== 0 || backspace_keycode
== 0));
5347 /* The XKB symbolic key names can be seen most easily in
5348 the PS file generated by `xkbprint -label name
5350 if (bcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
5352 else if (bcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
5353 backspace_keycode
= i
;
5356 XkbFreeNames (kb
, 0, True
);
5359 XkbFreeClientMap (kb
, 0, True
);
5362 && backspace_keycode
5363 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
5364 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
5369 #else /* not HAVE_XKBGETKEYBOARD */
5371 #endif /* not HAVE_XKBGETKEYBOARD */
5376 /***********************************************************************
5378 ***********************************************************************/
5380 /* Keep this list in the same order as frame_parms in frame.c.
5381 Use 0 for unsupported frame parameters. */
5383 frame_parm_handler x_frame_parm_handlers
[] =
5387 x_set_background_color
,
5393 x_set_foreground_color
,
5396 x_set_internal_border_width
,
5397 x_set_menu_bar_lines
,
5399 x_explicitly_set_name
,
5400 x_set_scroll_bar_width
,
5403 x_set_vertical_scroll_bars
,
5405 x_set_tool_bar_lines
,
5406 x_set_scroll_bar_foreground
,
5407 x_set_scroll_bar_background
,
5419 /* This is zero if not using X windows. */
5422 /* The section below is built by the lisp expression at the top of the file,
5423 just above where these variables are declared. */
5424 /*&&& init symbols here &&&*/
5425 Qnone
= intern ("none");
5427 Qsuppress_icon
= intern ("suppress-icon");
5428 staticpro (&Qsuppress_icon
);
5429 Qundefined_color
= intern ("undefined-color");
5430 staticpro (&Qundefined_color
);
5431 Qcompound_text
= intern ("compound-text");
5432 staticpro (&Qcompound_text
);
5433 Qcancel_timer
= intern ("cancel-timer");
5434 staticpro (&Qcancel_timer
);
5435 /* This is the end of symbol initialization. */
5437 /* Text property `display' should be nonsticky by default. */
5438 Vtext_property_default_nonsticky
5439 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
5442 Fput (Qundefined_color
, Qerror_conditions
,
5443 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
5444 Fput (Qundefined_color
, Qerror_message
,
5445 build_string ("Undefined color"));
5447 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
5448 doc
: /* The shape of the pointer when over text.
5449 Changing the value does not affect existing frames
5450 unless you set the mouse color. */);
5451 Vx_pointer_shape
= Qnil
;
5453 #if 0 /* This doesn't really do anything. */
5454 DEFVAR_LISP ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape
,
5455 doc
: /* The shape of the pointer when not over text.
5456 This variable takes effect when you create a new frame
5457 or when you set the mouse color. */);
5459 Vx_nontext_pointer_shape
= Qnil
;
5461 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
5462 doc
: /* The shape of the pointer when Emacs is busy.
5463 This variable takes effect when you create a new frame
5464 or when you set the mouse color. */);
5465 Vx_hourglass_pointer_shape
= Qnil
;
5467 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
5468 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
5469 display_hourglass_p
= 1;
5471 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
5472 doc
: /* *Seconds to wait before displaying an hourglass pointer.
5473 Value must be an integer or float. */);
5474 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
5476 #if 0 /* This doesn't really do anything. */
5477 DEFVAR_LISP ("x-mode-pointer-shape", &Vx_mode_pointer_shape
,
5478 doc
: /* The shape of the pointer when over the mode line.
5479 This variable takes effect when you create a new frame
5480 or when you set the mouse color. */);
5482 Vx_mode_pointer_shape
= Qnil
;
5484 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
5485 &Vx_sensitive_text_pointer_shape
,
5486 doc
: /* The shape of the pointer when over mouse-sensitive text.
5487 This variable takes effect when you create a new frame
5488 or when you set the mouse color. */);
5489 Vx_sensitive_text_pointer_shape
= Qnil
;
5491 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
5492 &Vx_window_horizontal_drag_shape
,
5493 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
5494 This variable takes effect when you create a new frame
5495 or when you set the mouse color. */);
5496 Vx_window_horizontal_drag_shape
= Qnil
;
5498 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
5499 doc
: /* A string indicating the foreground color of the cursor box. */);
5500 Vx_cursor_fore_pixel
= Qnil
;
5502 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
5503 doc
: /* Maximum size for tooltips. Value is a pair (COLUMNS . ROWS).
5504 Text larger than this is clipped. */);
5505 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
5507 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
5508 doc
: /* Non-nil if no X window manager is in use.
5509 Emacs doesn't try to figure this out; this is always nil
5510 unless you set it to something else. */);
5511 /* We don't have any way to find this out, so set it to nil
5512 and maybe the user would like to set it to t. */
5513 Vx_no_window_manager
= Qnil
;
5515 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
5516 &Vx_pixel_size_width_font_regexp
,
5517 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
5519 Since Emacs gets width of a font matching with this regexp from
5520 PIXEL_SIZE field of the name, font finding mechanism gets faster for
5521 such a font. This is especially effective for such large fonts as
5522 Chinese, Japanese, and Korean. */);
5523 Vx_pixel_size_width_font_regexp
= Qnil
;
5525 #ifdef USE_X_TOOLKIT
5526 Fprovide (intern ("x-toolkit"), Qnil
);
5528 Fprovide (intern ("motif"), Qnil
);
5530 DEFVAR_LISP ("motif-version-string", &Vmotif_version_string
,
5531 doc
: /* Version info for LessTif/Motif. */);
5532 Vmotif_version_string
= build_string (XmVERSION_STRING
);
5533 #endif /* USE_MOTIF */
5534 #endif /* USE_X_TOOLKIT */
5537 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
5538 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
5539 But for a user it is a toolkit for X, and indeed, configure
5540 accepts --with-x-toolkit=gtk. */
5541 Fprovide (intern ("x-toolkit"), Qnil
);
5542 Fprovide (intern ("gtk"), Qnil
);
5544 DEFVAR_LISP ("gtk-version-string", &Vgtk_version_string
,
5545 doc
: /* Version info for GTK+. */);
5547 char gtk_version
[40];
5548 g_snprintf (gtk_version
, sizeof (gtk_version
), "%u.%u.%u",
5549 GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
);
5550 Vgtk_version_string
= build_string (gtk_version
);
5552 #endif /* USE_GTK */
5554 /* X window properties. */
5555 defsubr (&Sx_change_window_property
);
5556 defsubr (&Sx_delete_window_property
);
5557 defsubr (&Sx_window_property
);
5559 defsubr (&Sxw_display_color_p
);
5560 defsubr (&Sx_display_grayscale_p
);
5561 defsubr (&Sxw_color_defined_p
);
5562 defsubr (&Sxw_color_values
);
5563 defsubr (&Sx_server_max_request_size
);
5564 defsubr (&Sx_server_vendor
);
5565 defsubr (&Sx_server_version
);
5566 defsubr (&Sx_display_pixel_width
);
5567 defsubr (&Sx_display_pixel_height
);
5568 defsubr (&Sx_display_mm_width
);
5569 defsubr (&Sx_display_mm_height
);
5570 defsubr (&Sx_display_screens
);
5571 defsubr (&Sx_display_planes
);
5572 defsubr (&Sx_display_color_cells
);
5573 defsubr (&Sx_display_visual_class
);
5574 defsubr (&Sx_display_backing_store
);
5575 defsubr (&Sx_display_save_under
);
5576 defsubr (&Sx_create_frame
);
5577 defsubr (&Sx_open_connection
);
5578 defsubr (&Sx_close_connection
);
5579 defsubr (&Sx_display_list
);
5580 defsubr (&Sx_synchronize
);
5581 defsubr (&Sx_focus_frame
);
5582 defsubr (&Sx_backspace_delete_keys_p
);
5584 /* Setting callback functions for fontset handler. */
5585 get_font_info_func
= x_get_font_info
;
5587 #if 0 /* This function pointer doesn't seem to be used anywhere.
5588 And the pointer assigned has the wrong type, anyway. */
5589 list_fonts_func
= x_list_fonts
;
5592 load_font_func
= x_load_font
;
5593 find_ccl_program_func
= x_find_ccl_program
;
5594 query_font_func
= x_query_font
;
5595 set_frame_fontset_func
= x_set_font
;
5596 get_font_repertory_func
= x_get_font_repertory
;
5597 check_window_system_func
= check_x
;
5599 hourglass_atimer
= NULL
;
5600 hourglass_shown_p
= 0;
5602 defsubr (&Sx_show_tip
);
5603 defsubr (&Sx_hide_tip
);
5605 staticpro (&tip_timer
);
5607 staticpro (&tip_frame
);
5609 last_show_tip_args
= Qnil
;
5610 staticpro (&last_show_tip_args
);
5612 #if defined (USE_MOTIF) || defined (USE_GTK)
5613 defsubr (&Sx_file_dialog
);
5617 #endif /* HAVE_X_WINDOWS */
5619 /* arch-tag: 55040d02-5485-4d58-8b22-95a7a05f3288
5620 (do not change this comment) */