1 /* Functions for the X window system.
2 Copyright (C) 1989, 92, 93, 94, 95, 96, 97, 98, 99, 2000,01,02,03,04
3 Free Software Foundation.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
31 /* This makes the fields of a Display accessible, in Xlib header files. */
33 #define XLIB_ILLEGAL_ACCESS
40 #include "intervals.h"
41 #include "dispextern.h"
43 #include "blockinput.h"
49 #include "termhooks.h"
56 #include <sys/types.h>
60 #if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */
61 #include "bitmaps/gray.xbm"
63 #include <X11/bitmaps/gray>
66 #include "[.bitmaps]gray.xbm"
74 #include <X11/Shell.h>
77 #include <X11/Xaw/Paned.h>
78 #include <X11/Xaw/Label.h>
79 #endif /* USE_MOTIF */
82 #undef USG /* ####KLUDGE for Solaris 2.2 and up */
91 #include "../lwlib/lwlib.h"
95 #include <Xm/DialogS.h>
96 #include <Xm/FileSB.h>
99 /* Do the EDITRES protocol if running X11R5
100 Exception: HP-UX (at least version A.09.05) has X11R5 without EditRes */
102 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
104 extern void _XEditResCheckMessages ();
105 #endif /* R5 + Athena */
107 /* Unique id counter for widgets created by the Lucid Widget Library. */
109 extern LWLIB_ID widget_id_tick
;
112 /* This is part of a kludge--see lwlib/xlwmenu.c. */
113 extern XFontStruct
*xlwmenu_default_font
;
116 extern void free_frame_menubar ();
117 extern double atof ();
121 /* LessTif/Motif version info. */
123 static Lisp_Object Vmotif_version_string
;
125 #endif /* USE_MOTIF */
127 #endif /* USE_X_TOOLKIT */
131 /* GTK+ version info */
133 static Lisp_Object Vgtk_version_string
;
138 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
140 #define MAXREQUEST(dpy) ((dpy)->max_request_size)
143 /* The gray bitmap `bitmaps/gray'. This is done because xterm.c uses
144 it, and including `bitmaps/gray' more than once is a problem when
145 config.h defines `static' as an empty replacement string. */
147 int gray_bitmap_width
= gray_width
;
148 int gray_bitmap_height
= gray_height
;
149 char *gray_bitmap_bits
= gray_bits
;
151 /* Non-zero means we're allowed to display an hourglass cursor. */
153 int display_hourglass_p
;
155 /* The background and shape of the mouse pointer, and shape when not
156 over text or in the modeline. */
158 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
159 Lisp_Object Vx_hourglass_pointer_shape
;
161 /* The shape when over mouse-sensitive text. */
163 Lisp_Object Vx_sensitive_text_pointer_shape
;
165 /* If non-nil, the pointer shape to indicate that windows can be
166 dragged horizontally. */
168 Lisp_Object Vx_window_horizontal_drag_shape
;
170 /* Color of chars displayed in cursor box. */
172 Lisp_Object Vx_cursor_fore_pixel
;
174 /* Nonzero if using X. */
178 /* Non nil if no window manager is in use. */
180 Lisp_Object Vx_no_window_manager
;
182 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
184 Lisp_Object Vx_pixel_size_width_font_regexp
;
187 Lisp_Object Qsuppress_icon
;
188 Lisp_Object Qundefined_color
;
189 Lisp_Object Qcompound_text
, Qcancel_timer
;
193 extern Lisp_Object Vwindow_system_version
;
195 /* The below are defined in frame.c. */
198 int image_cache_refcount
, dpyinfo_refcount
;
203 /* Error if we are not connected to X. */
209 error ("X windows are not in use or not initialized");
212 /* Nonzero if we can use mouse menus.
213 You should not call this unless HAVE_MENUS is defined. */
221 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
222 and checking validity for X. */
225 check_x_frame (frame
)
231 frame
= selected_frame
;
232 CHECK_LIVE_FRAME (frame
);
235 error ("Non-X frame used");
239 /* Let the user specify an X display with a frame.
240 nil stands for the selected frame--or, if that is not an X frame,
241 the first X display on the list. */
243 struct x_display_info
*
244 check_x_display_info (frame
)
247 struct x_display_info
*dpyinfo
= NULL
;
251 struct frame
*sf
= XFRAME (selected_frame
);
253 if (FRAME_X_P (sf
) && FRAME_LIVE_P (sf
))
254 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
255 else if (x_display_list
!= 0)
256 dpyinfo
= x_display_list
;
258 error ("X windows are not in use or not initialized");
260 else if (INTEGERP (frame
))
262 struct display
*d
= get_display (XINT (frame
));
265 wrong_type_argument (Qdisplay_live_p
, frame
);
266 if (d
->type
!= output_x_window
)
267 error ("Display %d is not an X display", XINT (frame
));
269 dpyinfo
= d
->display_info
.x
;
271 else if (STRINGP (frame
))
272 dpyinfo
= x_display_info_for_name (frame
);
275 FRAME_PTR f
= check_x_frame (frame
);
276 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
283 /* Return the Emacs frame-object corresponding to an X window.
284 It could be the frame's main window or an icon window. */
286 /* This function can be called during GC, so use GC_xxx type test macros. */
289 x_window_to_frame (dpyinfo
, wdesc
)
290 struct x_display_info
*dpyinfo
;
293 Lisp_Object tail
, frame
;
296 if (wdesc
== None
) return 0;
298 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
301 if (!GC_FRAMEP (frame
))
304 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
306 if (f
->output_data
.x
->hourglass_window
== wdesc
)
309 if ((f
->output_data
.x
->edit_widget
310 && XtWindow (f
->output_data
.x
->edit_widget
) == wdesc
)
311 /* A tooltip frame? */
312 || (!f
->output_data
.x
->edit_widget
313 && FRAME_X_WINDOW (f
) == wdesc
)
314 || f
->output_data
.x
->icon_desc
== wdesc
)
316 #else /* not USE_X_TOOLKIT */
318 if (f
->output_data
.x
->edit_widget
)
320 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
321 struct x_output
*x
= f
->output_data
.x
;
322 if (gwdesc
!= 0 && gwdesc
== x
->edit_widget
)
326 if (FRAME_X_WINDOW (f
) == wdesc
327 || f
->output_data
.x
->icon_desc
== wdesc
)
329 #endif /* not USE_X_TOOLKIT */
334 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
335 /* Like x_window_to_frame but also compares the window with the widget's
339 x_any_window_to_frame (dpyinfo
, wdesc
)
340 struct x_display_info
*dpyinfo
;
343 Lisp_Object tail
, frame
;
344 struct frame
*f
, *found
;
347 if (wdesc
== None
) return NULL
;
350 for (tail
= Vframe_list
; GC_CONSP (tail
) && !found
; tail
= XCDR (tail
))
353 if (!GC_FRAMEP (frame
))
357 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
359 /* This frame matches if the window is any of its widgets. */
360 x
= f
->output_data
.x
;
361 if (x
->hourglass_window
== wdesc
)
366 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
368 && (gwdesc
== x
->widget
369 || gwdesc
== x
->edit_widget
370 || gwdesc
== x
->vbox_widget
371 || gwdesc
== x
->menubar_widget
))
374 if (wdesc
== XtWindow (x
->widget
)
375 || wdesc
== XtWindow (x
->column_widget
)
376 || wdesc
== XtWindow (x
->edit_widget
))
378 /* Match if the window is this frame's menubar. */
379 else if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
383 else if (FRAME_X_WINDOW (f
) == wdesc
)
384 /* A tooltip frame. */
392 /* Likewise, but exclude the menu bar widget. */
395 x_non_menubar_window_to_frame (dpyinfo
, wdesc
)
396 struct x_display_info
*dpyinfo
;
399 Lisp_Object tail
, frame
;
403 if (wdesc
== None
) return 0;
405 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
408 if (!GC_FRAMEP (frame
))
411 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
413 x
= f
->output_data
.x
;
414 /* This frame matches if the window is any of its widgets. */
415 if (x
->hourglass_window
== wdesc
)
420 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
422 && (gwdesc
== x
->widget
423 || gwdesc
== x
->edit_widget
424 || gwdesc
== x
->vbox_widget
))
427 if (wdesc
== XtWindow (x
->widget
)
428 || wdesc
== XtWindow (x
->column_widget
)
429 || wdesc
== XtWindow (x
->edit_widget
))
433 else if (FRAME_X_WINDOW (f
) == wdesc
)
434 /* A tooltip frame. */
440 /* Likewise, but consider only the menu bar widget. */
443 x_menubar_window_to_frame (dpyinfo
, wdesc
)
444 struct x_display_info
*dpyinfo
;
447 Lisp_Object tail
, frame
;
451 if (wdesc
== None
) return 0;
453 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
456 if (!GC_FRAMEP (frame
))
459 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
461 x
= f
->output_data
.x
;
462 /* Match if the window is this frame's menubar. */
464 if (x
->menubar_widget
)
466 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
471 && (gwdesc
== x
->menubar_widget
472 || gtk_widget_get_parent (gwdesc
) == x
->menubar_widget
))
478 if (x
->menubar_widget
479 && lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
486 /* Return the frame whose principal (outermost) window is WDESC.
487 If WDESC is some other (smaller) window, we return 0. */
490 x_top_window_to_frame (dpyinfo
, wdesc
)
491 struct x_display_info
*dpyinfo
;
494 Lisp_Object tail
, frame
;
498 if (wdesc
== None
) return 0;
500 for (tail
= Vframe_list
; GC_CONSP (tail
); tail
= XCDR (tail
))
503 if (!GC_FRAMEP (frame
))
506 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
508 x
= f
->output_data
.x
;
512 /* This frame matches if the window is its topmost widget. */
514 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
515 if (gwdesc
== x
->widget
)
518 if (wdesc
== XtWindow (x
->widget
))
520 #if 0 /* I don't know why it did this,
521 but it seems logically wrong,
522 and it causes trouble for MapNotify events. */
523 /* Match if the window is this frame's menubar. */
524 if (x
->menubar_widget
525 && wdesc
== XtWindow (x
->menubar_widget
))
530 else if (FRAME_X_WINDOW (f
) == wdesc
)
536 #endif /* USE_X_TOOLKIT || USE_GTK */
540 static Lisp_Object unwind_create_frame
P_ ((Lisp_Object
));
541 static Lisp_Object unwind_create_tip_frame
P_ ((Lisp_Object
));
543 void x_set_foreground_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
544 static void x_set_wait_for_wm
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
545 void x_set_background_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
546 void x_set_mouse_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
547 void x_set_cursor_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
548 void x_set_border_color
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
549 void x_set_cursor_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
550 void x_set_icon_type
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
551 void x_set_icon_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
552 void x_explicitly_set_name
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
553 void x_set_menu_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
554 void x_set_title
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
555 void x_set_tool_bar_lines
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
));
556 void x_set_scroll_bar_foreground
P_ ((struct frame
*, Lisp_Object
,
558 void x_set_scroll_bar_background
P_ ((struct frame
*, Lisp_Object
,
560 static Lisp_Object x_default_scroll_bar_color_parameter
P_ ((struct frame
*,
567 /* Store the screen positions of frame F into XPTR and YPTR.
568 These are the positions of the containing window manager window,
569 not Emacs's own window. */
572 x_real_positions (f
, xptr
, yptr
)
576 int win_x
, win_y
, outer_x
, outer_y
;
577 int real_x
= 0, real_y
= 0;
579 Window win
= f
->output_data
.x
->parent_desc
;
585 count
= x_catch_errors (FRAME_X_DISPLAY (f
));
587 if (win
== FRAME_X_DISPLAY_INFO (f
)->root_window
)
588 win
= FRAME_OUTER_WINDOW (f
);
590 /* This loop traverses up the containment tree until we hit the root
591 window. Window managers may intersect many windows between our window
592 and the root window. The window we find just before the root window
593 should be the outer WM window. */
596 Window wm_window
, rootw
;
597 Window
*tmp_children
;
598 unsigned int tmp_nchildren
;
601 success
= XQueryTree (FRAME_X_DISPLAY (f
), win
, &rootw
,
602 &wm_window
, &tmp_children
, &tmp_nchildren
);
604 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
606 /* Don't free tmp_children if XQueryTree failed. */
610 XFree ((char *) tmp_children
);
612 if (wm_window
== rootw
|| had_errors
)
623 /* Get the real coordinates for the WM window upper left corner */
624 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
625 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
627 /* Translate real coordinates to coordinates relative to our
628 window. For our window, the upper left corner is 0, 0.
629 Since the upper left corner of the WM window is outside
630 our window, win_x and win_y will be negative:
632 ------------------ ---> x
634 | ----------------- v y
637 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
639 /* From-window, to-window. */
640 FRAME_X_DISPLAY_INFO (f
)->root_window
,
643 /* From-position, to-position. */
644 real_x
, real_y
, &win_x
, &win_y
,
649 if (FRAME_X_WINDOW (f
) == FRAME_OUTER_WINDOW (f
))
656 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
658 /* From-window, to-window. */
659 FRAME_X_DISPLAY_INFO (f
)->root_window
,
660 FRAME_OUTER_WINDOW (f
),
662 /* From-position, to-position. */
663 real_x
, real_y
, &outer_x
, &outer_y
,
669 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
672 x_uncatch_errors (FRAME_X_DISPLAY (f
), count
);
676 if (had_errors
) return;
678 f
->x_pixels_diff
= -win_x
;
679 f
->y_pixels_diff
= -win_y
;
681 FRAME_X_OUTPUT (f
)->x_pixels_outer_diff
= -outer_x
;
682 FRAME_X_OUTPUT (f
)->y_pixels_outer_diff
= -outer_y
;
691 /* Gamma-correct COLOR on frame F. */
694 gamma_correct (f
, color
)
700 color
->red
= pow (color
->red
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
701 color
->green
= pow (color
->green
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
702 color
->blue
= pow (color
->blue
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
707 /* Decide if color named COLOR_NAME is valid for use on frame F. If
708 so, return the RGB values in COLOR. If ALLOC_P is non-zero,
709 allocate the color. Value is zero if COLOR_NAME is invalid, or
710 no color could be allocated. */
713 x_defined_color (f
, color_name
, color
, alloc_p
)
720 Display
*dpy
= FRAME_X_DISPLAY (f
);
721 Colormap cmap
= FRAME_X_COLORMAP (f
);
724 success_p
= XParseColor (dpy
, cmap
, color_name
, color
);
725 if (success_p
&& alloc_p
)
726 success_p
= x_alloc_nearest_color (f
, cmap
, color
);
733 /* Return the pixel color value for color COLOR_NAME on frame F. If F
734 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
735 Signal an error if color can't be allocated. */
738 x_decode_color (f
, color_name
, mono_color
)
740 Lisp_Object color_name
;
745 CHECK_STRING (color_name
);
747 #if 0 /* Don't do this. It's wrong when we're not using the default
748 colormap, it makes freeing difficult, and it's probably not
749 an important optimization. */
750 if (strcmp (SDATA (color_name
), "black") == 0)
751 return BLACK_PIX_DEFAULT (f
);
752 else if (strcmp (SDATA (color_name
), "white") == 0)
753 return WHITE_PIX_DEFAULT (f
);
756 /* Return MONO_COLOR for monochrome frames. */
757 if (FRAME_X_DISPLAY_INFO (f
)->n_planes
== 1)
760 /* x_defined_color is responsible for coping with failures
761 by looking for a near-miss. */
762 if (x_defined_color (f
, SDATA (color_name
), &cdef
, 1))
765 Fsignal (Qerror
, Fcons (build_string ("Undefined color"),
766 Fcons (color_name
, Qnil
)));
772 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
773 the previous value of that parameter, NEW_VALUE is the new value.
774 See also the comment of wait_for_wm in struct x_output. */
777 x_set_wait_for_wm (f
, new_value
, old_value
)
779 Lisp_Object new_value
, old_value
;
781 f
->output_data
.x
->wait_for_wm
= !NILP (new_value
);
786 /* Set icon from FILE for frame F. By using GTK functions the icon
787 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
790 xg_set_icon (f
, file
)
800 found
= x_find_image_file (file
);
808 filename
= SDATA (found
);
811 pixbuf
= gdk_pixbuf_new_from_file (filename
, &err
);
815 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
817 g_object_unref (pixbuf
);
833 /* Functions called only from `x_set_frame_param'
834 to set individual parameters.
836 If FRAME_X_WINDOW (f) is 0,
837 the frame is being created and its X-window does not exist yet.
838 In that case, just record the parameter's new value
839 in the standard place; do not attempt to change the window. */
842 x_set_foreground_color (f
, arg
, oldval
)
844 Lisp_Object arg
, oldval
;
846 struct x_output
*x
= f
->output_data
.x
;
847 unsigned long fg
, old_fg
;
849 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
850 old_fg
= x
->foreground_pixel
;
851 x
->foreground_pixel
= fg
;
853 if (FRAME_X_WINDOW (f
) != 0)
855 Display
*dpy
= FRAME_X_DISPLAY (f
);
858 XSetForeground (dpy
, x
->normal_gc
, fg
);
859 XSetBackground (dpy
, x
->reverse_gc
, fg
);
861 if (x
->cursor_pixel
== old_fg
)
863 unload_color (f
, x
->cursor_pixel
);
864 x
->cursor_pixel
= x_copy_color (f
, fg
);
865 XSetBackground (dpy
, x
->cursor_gc
, x
->cursor_pixel
);
870 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
872 if (FRAME_VISIBLE_P (f
))
876 unload_color (f
, old_fg
);
880 x_set_background_color (f
, arg
, oldval
)
882 Lisp_Object arg
, oldval
;
884 struct x_output
*x
= f
->output_data
.x
;
887 bg
= x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
888 unload_color (f
, x
->background_pixel
);
889 x
->background_pixel
= bg
;
891 if (FRAME_X_WINDOW (f
) != 0)
893 Display
*dpy
= FRAME_X_DISPLAY (f
);
896 XSetBackground (dpy
, x
->normal_gc
, bg
);
897 XSetForeground (dpy
, x
->reverse_gc
, bg
);
898 XSetWindowBackground (dpy
, FRAME_X_WINDOW (f
), bg
);
899 XSetForeground (dpy
, x
->cursor_gc
, bg
);
902 xg_set_background_color (f
, bg
);
905 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
906 toolkit scroll bars. */
909 for (bar
= FRAME_SCROLL_BARS (f
);
911 bar
= XSCROLL_BAR (bar
)->next
)
913 Window window
= SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar
));
914 XSetWindowBackground (dpy
, window
, bg
);
917 #endif /* USE_TOOLKIT_SCROLL_BARS */
920 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
922 if (FRAME_VISIBLE_P (f
))
928 x_set_mouse_color (f
, arg
, oldval
)
930 Lisp_Object arg
, oldval
;
932 struct x_output
*x
= f
->output_data
.x
;
933 Display
*dpy
= FRAME_X_DISPLAY (f
);
934 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
935 Cursor hourglass_cursor
, horizontal_drag_cursor
;
937 unsigned long pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
938 unsigned long mask_color
= x
->background_pixel
;
940 /* Don't let pointers be invisible. */
941 if (mask_color
== pixel
)
943 x_free_colors (f
, &pixel
, 1);
944 pixel
= x_copy_color (f
, x
->foreground_pixel
);
947 unload_color (f
, x
->mouse_pixel
);
948 x
->mouse_pixel
= pixel
;
952 /* It's not okay to crash if the user selects a screwy cursor. */
953 count
= x_catch_errors (dpy
);
955 if (!NILP (Vx_pointer_shape
))
957 CHECK_NUMBER (Vx_pointer_shape
);
958 cursor
= XCreateFontCursor (dpy
, XINT (Vx_pointer_shape
));
961 cursor
= XCreateFontCursor (dpy
, XC_xterm
);
962 x_check_errors (dpy
, "bad text pointer cursor: %s");
964 if (!NILP (Vx_nontext_pointer_shape
))
966 CHECK_NUMBER (Vx_nontext_pointer_shape
);
968 = XCreateFontCursor (dpy
, XINT (Vx_nontext_pointer_shape
));
971 nontext_cursor
= XCreateFontCursor (dpy
, XC_left_ptr
);
972 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
974 if (!NILP (Vx_hourglass_pointer_shape
))
976 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
978 = XCreateFontCursor (dpy
, XINT (Vx_hourglass_pointer_shape
));
981 hourglass_cursor
= XCreateFontCursor (dpy
, XC_watch
);
982 x_check_errors (dpy
, "bad hourglass pointer cursor: %s");
984 if (!NILP (Vx_mode_pointer_shape
))
986 CHECK_NUMBER (Vx_mode_pointer_shape
);
987 mode_cursor
= XCreateFontCursor (dpy
, XINT (Vx_mode_pointer_shape
));
990 mode_cursor
= XCreateFontCursor (dpy
, XC_xterm
);
991 x_check_errors (dpy
, "bad modeline pointer cursor: %s");
993 if (!NILP (Vx_sensitive_text_pointer_shape
))
995 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
997 = XCreateFontCursor (dpy
, XINT (Vx_sensitive_text_pointer_shape
));
1000 hand_cursor
= XCreateFontCursor (dpy
, XC_hand2
);
1002 if (!NILP (Vx_window_horizontal_drag_shape
))
1004 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
1005 horizontal_drag_cursor
1006 = XCreateFontCursor (dpy
, XINT (Vx_window_horizontal_drag_shape
));
1009 horizontal_drag_cursor
1010 = XCreateFontCursor (dpy
, XC_sb_h_double_arrow
);
1012 /* Check and report errors with the above calls. */
1013 x_check_errors (dpy
, "can't set cursor shape: %s");
1014 x_uncatch_errors (dpy
, count
);
1017 XColor fore_color
, back_color
;
1019 fore_color
.pixel
= x
->mouse_pixel
;
1020 x_query_color (f
, &fore_color
);
1021 back_color
.pixel
= mask_color
;
1022 x_query_color (f
, &back_color
);
1024 XRecolorCursor (dpy
, cursor
, &fore_color
, &back_color
);
1025 XRecolorCursor (dpy
, nontext_cursor
, &fore_color
, &back_color
);
1026 XRecolorCursor (dpy
, mode_cursor
, &fore_color
, &back_color
);
1027 XRecolorCursor (dpy
, hand_cursor
, &fore_color
, &back_color
);
1028 XRecolorCursor (dpy
, hourglass_cursor
, &fore_color
, &back_color
);
1029 XRecolorCursor (dpy
, horizontal_drag_cursor
, &fore_color
, &back_color
);
1032 if (FRAME_X_WINDOW (f
) != 0)
1033 XDefineCursor (dpy
, FRAME_X_WINDOW (f
), cursor
);
1035 if (cursor
!= x
->text_cursor
1036 && x
->text_cursor
!= 0)
1037 XFreeCursor (dpy
, x
->text_cursor
);
1038 x
->text_cursor
= cursor
;
1040 if (nontext_cursor
!= x
->nontext_cursor
1041 && x
->nontext_cursor
!= 0)
1042 XFreeCursor (dpy
, x
->nontext_cursor
);
1043 x
->nontext_cursor
= nontext_cursor
;
1045 if (hourglass_cursor
!= x
->hourglass_cursor
1046 && x
->hourglass_cursor
!= 0)
1047 XFreeCursor (dpy
, x
->hourglass_cursor
);
1048 x
->hourglass_cursor
= hourglass_cursor
;
1050 if (mode_cursor
!= x
->modeline_cursor
1051 && x
->modeline_cursor
!= 0)
1052 XFreeCursor (dpy
, f
->output_data
.x
->modeline_cursor
);
1053 x
->modeline_cursor
= mode_cursor
;
1055 if (hand_cursor
!= x
->hand_cursor
1056 && x
->hand_cursor
!= 0)
1057 XFreeCursor (dpy
, x
->hand_cursor
);
1058 x
->hand_cursor
= hand_cursor
;
1060 if (horizontal_drag_cursor
!= x
->horizontal_drag_cursor
1061 && x
->horizontal_drag_cursor
!= 0)
1062 XFreeCursor (dpy
, x
->horizontal_drag_cursor
);
1063 x
->horizontal_drag_cursor
= horizontal_drag_cursor
;
1068 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1072 x_set_cursor_color (f
, arg
, oldval
)
1074 Lisp_Object arg
, oldval
;
1076 unsigned long fore_pixel
, pixel
;
1077 int fore_pixel_allocated_p
= 0, pixel_allocated_p
= 0;
1078 struct x_output
*x
= f
->output_data
.x
;
1080 if (!NILP (Vx_cursor_fore_pixel
))
1082 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1083 WHITE_PIX_DEFAULT (f
));
1084 fore_pixel_allocated_p
= 1;
1087 fore_pixel
= x
->background_pixel
;
1089 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1090 pixel_allocated_p
= 1;
1092 /* Make sure that the cursor color differs from the background color. */
1093 if (pixel
== x
->background_pixel
)
1095 if (pixel_allocated_p
)
1097 x_free_colors (f
, &pixel
, 1);
1098 pixel_allocated_p
= 0;
1101 pixel
= x
->mouse_pixel
;
1102 if (pixel
== fore_pixel
)
1104 if (fore_pixel_allocated_p
)
1106 x_free_colors (f
, &fore_pixel
, 1);
1107 fore_pixel_allocated_p
= 0;
1109 fore_pixel
= x
->background_pixel
;
1113 unload_color (f
, x
->cursor_foreground_pixel
);
1114 if (!fore_pixel_allocated_p
)
1115 fore_pixel
= x_copy_color (f
, fore_pixel
);
1116 x
->cursor_foreground_pixel
= fore_pixel
;
1118 unload_color (f
, x
->cursor_pixel
);
1119 if (!pixel_allocated_p
)
1120 pixel
= x_copy_color (f
, pixel
);
1121 x
->cursor_pixel
= pixel
;
1123 if (FRAME_X_WINDOW (f
) != 0)
1126 XSetBackground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, x
->cursor_pixel
);
1127 XSetForeground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, fore_pixel
);
1130 if (FRAME_VISIBLE_P (f
))
1132 x_update_cursor (f
, 0);
1133 x_update_cursor (f
, 1);
1137 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1140 /* Set the border-color of frame F to pixel value PIX.
1141 Note that this does not fully take effect if done before
1142 F has an x-window. */
1145 x_set_border_pixel (f
, pix
)
1149 unload_color (f
, f
->output_data
.x
->border_pixel
);
1150 f
->output_data
.x
->border_pixel
= pix
;
1152 if (FRAME_X_WINDOW (f
) != 0 && f
->border_width
> 0)
1155 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1156 (unsigned long)pix
);
1159 if (FRAME_VISIBLE_P (f
))
1164 /* Set the border-color of frame F to value described by ARG.
1165 ARG can be a string naming a color.
1166 The border-color is used for the border that is drawn by the X server.
1167 Note that this does not fully take effect if done before
1168 F has an x-window; it must be redone when the window is created.
1170 Note: this is done in two routines because of the way X10 works.
1172 Note: under X11, this is normally the province of the window manager,
1173 and so emacs' border colors may be overridden. */
1176 x_set_border_color (f
, arg
, oldval
)
1178 Lisp_Object arg
, oldval
;
1183 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1184 x_set_border_pixel (f
, pix
);
1185 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1190 x_set_cursor_type (f
, arg
, oldval
)
1192 Lisp_Object arg
, oldval
;
1194 set_frame_cursor_types (f
, arg
);
1196 /* Make sure the cursor gets redrawn. */
1197 cursor_type_changed
= 1;
1201 x_set_icon_type (f
, arg
, oldval
)
1203 Lisp_Object arg
, oldval
;
1209 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1212 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1217 result
= x_text_icon (f
,
1218 (char *) SDATA ((!NILP (f
->icon_name
)
1222 result
= x_bitmap_icon (f
, arg
);
1227 error ("No icon window available");
1230 XFlush (FRAME_X_DISPLAY (f
));
1235 x_set_icon_name (f
, arg
, oldval
)
1237 Lisp_Object arg
, oldval
;
1243 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1246 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1251 if (f
->output_data
.x
->icon_bitmap
!= 0)
1256 result
= x_text_icon (f
,
1257 (char *) SDATA ((!NILP (f
->icon_name
)
1266 error ("No icon window available");
1269 XFlush (FRAME_X_DISPLAY (f
));
1275 x_set_menu_bar_lines (f
, value
, oldval
)
1277 Lisp_Object value
, oldval
;
1280 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
1281 int olines
= FRAME_MENU_BAR_LINES (f
);
1284 /* Right now, menu bars don't work properly in minibuf-only frames;
1285 most of the commands try to apply themselves to the minibuffer
1286 frame itself, and get an error because you can't switch buffers
1287 in or split the minibuffer window. */
1288 if (FRAME_MINIBUF_ONLY_P (f
))
1291 if (INTEGERP (value
))
1292 nlines
= XINT (value
);
1296 /* Make sure we redisplay all windows in this frame. */
1297 windows_or_buffers_changed
++;
1299 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
1300 FRAME_MENU_BAR_LINES (f
) = 0;
1303 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1304 if (FRAME_X_P (f
) && f
->output_data
.x
->menubar_widget
== 0)
1305 /* Make sure next redisplay shows the menu bar. */
1306 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= Qt
;
1310 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1311 free_frame_menubar (f
);
1312 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1314 f
->output_data
.x
->menubar_widget
= 0;
1316 #else /* not USE_X_TOOLKIT && not USE_GTK */
1317 FRAME_MENU_BAR_LINES (f
) = nlines
;
1318 change_window_heights (f
->root_window
, nlines
- olines
);
1319 #endif /* not USE_X_TOOLKIT */
1324 /* Set the number of lines used for the tool bar of frame F to VALUE.
1325 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1326 is the old number of tool bar lines. This function changes the
1327 height of all windows on frame F to match the new tool bar height.
1328 The frame's height doesn't change. */
1331 x_set_tool_bar_lines (f
, value
, oldval
)
1333 Lisp_Object value
, oldval
;
1335 int delta
, nlines
, root_height
;
1336 Lisp_Object root_window
;
1338 /* Treat tool bars like menu bars. */
1339 if (FRAME_MINIBUF_ONLY_P (f
))
1342 /* Use VALUE only if an integer >= 0. */
1343 if (INTEGERP (value
) && XINT (value
) >= 0)
1344 nlines
= XFASTINT (value
);
1349 FRAME_TOOL_BAR_LINES (f
) = 0;
1352 FRAME_EXTERNAL_TOOL_BAR (f
) = 1;
1353 if (FRAME_X_P (f
) && f
->output_data
.x
->toolbar_widget
== 0)
1354 /* Make sure next redisplay shows the tool bar. */
1355 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= Qt
;
1356 update_frame_tool_bar (f
);
1360 if (FRAME_EXTERNAL_TOOL_BAR (f
))
1361 free_frame_tool_bar (f
);
1362 FRAME_EXTERNAL_TOOL_BAR (f
) = 0;
1368 /* Make sure we redisplay all windows in this frame. */
1369 ++windows_or_buffers_changed
;
1371 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1373 /* Don't resize the tool-bar to more than we have room for. */
1374 root_window
= FRAME_ROOT_WINDOW (f
);
1375 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1376 if (root_height
- delta
< 1)
1378 delta
= root_height
- 1;
1379 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1382 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1383 change_window_heights (root_window
, delta
);
1386 /* We also have to make sure that the internal border at the top of
1387 the frame, below the menu bar or tool bar, is redrawn when the
1388 tool bar disappears. This is so because the internal border is
1389 below the tool bar if one is displayed, but is below the menu bar
1390 if there isn't a tool bar. The tool bar draws into the area
1391 below the menu bar. */
1392 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1395 clear_current_matrices (f
);
1398 /* If the tool bar gets smaller, the internal border below it
1399 has to be cleared. It was formerly part of the display
1400 of the larger tool bar, and updating windows won't clear it. */
1403 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1404 int width
= FRAME_PIXEL_WIDTH (f
);
1405 int y
= nlines
* FRAME_LINE_HEIGHT (f
);
1408 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1409 0, y
, width
, height
, False
);
1412 if (WINDOWP (f
->tool_bar_window
))
1413 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1418 /* Set the foreground color for scroll bars on frame F to VALUE.
1419 VALUE should be a string, a color name. If it isn't a string or
1420 isn't a valid color name, do nothing. OLDVAL is the old value of
1421 the frame parameter. */
1424 x_set_scroll_bar_foreground (f
, value
, oldval
)
1426 Lisp_Object value
, oldval
;
1428 unsigned long pixel
;
1430 if (STRINGP (value
))
1431 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
1435 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
1436 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
1438 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
1439 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1441 /* Remove all scroll bars because they have wrong colors. */
1442 if (FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
)
1443 (*FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
) (f
);
1444 if (FRAME_DISPLAY (f
)->judge_scroll_bars_hook
)
1445 (*FRAME_DISPLAY (f
)->judge_scroll_bars_hook
) (f
);
1447 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
1453 /* Set the background color for scroll bars on frame F to VALUE VALUE
1454 should be a string, a color name. If it isn't a string or isn't a
1455 valid color name, do nothing. OLDVAL is the old value of the frame
1459 x_set_scroll_bar_background (f
, value
, oldval
)
1461 Lisp_Object value
, oldval
;
1463 unsigned long pixel
;
1465 if (STRINGP (value
))
1466 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
1470 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
1471 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
1473 #ifdef USE_TOOLKIT_SCROLL_BARS
1474 /* Scrollbar shadow colors. */
1475 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
1477 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
1478 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
1480 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
1482 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
1483 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
1485 #endif /* USE_TOOLKIT_SCROLL_BARS */
1487 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
1488 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1490 /* Remove all scroll bars because they have wrong colors. */
1491 if (FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
)
1492 (*FRAME_DISPLAY (f
)->condemn_scroll_bars_hook
) (f
);
1493 if (FRAME_DISPLAY (f
)->judge_scroll_bars_hook
)
1494 (*FRAME_DISPLAY (f
)->judge_scroll_bars_hook
) (f
);
1496 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
1502 /* Encode Lisp string STRING as a text in a format appropriate for
1503 XICCC (X Inter Client Communication Conventions).
1505 If STRING contains only ASCII characters, do no conversion and
1506 return the string data of STRING. Otherwise, encode the text by
1507 CODING_SYSTEM, and return a newly allocated memory area which
1508 should be freed by `xfree' by a caller.
1510 SELECTIONP non-zero means the string is being encoded for an X
1511 selection, so it is safe to run pre-write conversions (which
1514 Store the byte length of resulting text in *TEXT_BYTES.
1516 If the text contains only ASCII and Latin-1, store 1 in *STRING_P,
1517 which means that the `encoding' of the result can be `STRING'.
1518 Otherwise store 0 in *STRINGP, which means that the `encoding' of
1519 the result should be `COMPOUND_TEXT'. */
1522 x_encode_text (string
, coding_system
, selectionp
, text_bytes
, stringp
)
1523 Lisp_Object string
, coding_system
;
1524 int *text_bytes
, *stringp
;
1527 unsigned char *str
= SDATA (string
);
1528 int chars
= SCHARS (string
);
1529 int bytes
= SBYTES (string
);
1533 struct coding_system coding
;
1534 extern Lisp_Object Qcompound_text_with_extensions
;
1536 charset_info
= find_charset_in_text (str
, chars
, bytes
, NULL
, Qnil
);
1537 if (charset_info
== 0)
1539 /* No multibyte character in OBJ. We need not encode it. */
1540 *text_bytes
= bytes
;
1545 setup_coding_system (coding_system
, &coding
);
1547 && SYMBOLP (coding
.pre_write_conversion
)
1548 && !NILP (Ffboundp (coding
.pre_write_conversion
)))
1550 string
= run_pre_post_conversion_on_str (string
, &coding
, 1);
1551 str
= SDATA (string
);
1552 chars
= SCHARS (string
);
1553 bytes
= SBYTES (string
);
1555 coding
.src_multibyte
= 1;
1556 coding
.dst_multibyte
= 0;
1557 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
1558 if (coding
.type
== coding_type_iso2022
)
1559 coding
.flags
|= CODING_FLAG_ISO_SAFE
;
1560 /* We suppress producing escape sequences for composition. */
1561 coding
.composing
= COMPOSITION_DISABLED
;
1562 bufsize
= encoding_buffer_size (&coding
, bytes
);
1563 buf
= (unsigned char *) xmalloc (bufsize
);
1564 encode_coding (&coding
, str
, buf
, bytes
, bufsize
);
1565 *text_bytes
= coding
.produced
;
1566 *stringp
= (charset_info
== 1
1567 || (!EQ (coding_system
, Qcompound_text
)
1568 && !EQ (coding_system
, Qcompound_text_with_extensions
)));
1573 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1576 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1577 name; if NAME is a string, set F's name to NAME and set
1578 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1580 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1581 suggesting a new name, which lisp code should override; if
1582 F->explicit_name is set, ignore the new name; otherwise, set it. */
1585 x_set_name (f
, name
, explicit)
1590 /* Make sure that requests from lisp code override requests from
1591 Emacs redisplay code. */
1594 /* If we're switching from explicit to implicit, we had better
1595 update the mode lines and thereby update the title. */
1596 if (f
->explicit_name
&& NILP (name
))
1597 update_mode_lines
= 1;
1599 f
->explicit_name
= ! NILP (name
);
1601 else if (f
->explicit_name
)
1604 /* If NAME is nil, set the name to the x_id_name. */
1607 /* Check for no change needed in this very common case
1608 before we do any consing. */
1609 if (!strcmp (FRAME_X_DISPLAY_INFO (f
)->x_id_name
,
1612 name
= build_string (FRAME_X_DISPLAY_INFO (f
)->x_id_name
);
1615 CHECK_STRING (name
);
1617 /* Don't change the name if it's already NAME. */
1618 if (! NILP (Fstring_equal (name
, f
->name
)))
1623 /* For setting the frame title, the title parameter should override
1624 the name parameter. */
1625 if (! NILP (f
->title
))
1628 if (FRAME_X_WINDOW (f
))
1633 XTextProperty text
, icon
;
1635 Lisp_Object coding_system
;
1637 /* Note: Encoding strategy
1639 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1640 text.encoding. But, there are non-internationalized window
1641 managers which don't support that encoding. So, if NAME
1642 contains only ASCII and 8859-1 characters, encode it by
1643 iso-latin-1, and use "STRING" in text.encoding hoping that
1644 such window managers at least analyze this format correctly,
1645 i.e. treat 8-bit bytes as 8859-1 characters.
1647 We may also be able to use "UTF8_STRING" in text.encoding
1648 in the future which can encode all Unicode characters.
1649 But, for the moment, there's no way to know that the
1650 current window manager supports it or not. */
1651 coding_system
= Qcompound_text
;
1652 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
);
1653 text
.encoding
= (stringp
? XA_STRING
1654 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1656 text
.nitems
= bytes
;
1658 if (NILP (f
->icon_name
))
1664 /* See the above comment "Note: Encoding strategy". */
1665 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
1667 icon
.encoding
= (stringp
? XA_STRING
1668 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1670 icon
.nitems
= bytes
;
1673 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1674 SDATA (ENCODE_UTF_8 (name
)));
1675 #else /* not USE_GTK */
1676 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1677 #endif /* not USE_GTK */
1679 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &icon
);
1681 if (!NILP (f
->icon_name
)
1682 && icon
.value
!= (unsigned char *) SDATA (f
->icon_name
))
1684 if (text
.value
!= (unsigned char *) SDATA (name
))
1687 #else /* not HAVE_X11R4 */
1688 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1690 XStoreName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1692 #endif /* not HAVE_X11R4 */
1697 /* This function should be called when the user's lisp code has
1698 specified a name for the frame; the name will override any set by the
1701 x_explicitly_set_name (f
, arg
, oldval
)
1703 Lisp_Object arg
, oldval
;
1705 x_set_name (f
, arg
, 1);
1708 /* This function should be called by Emacs redisplay code to set the
1709 name; names set this way will never override names set by the user's
1712 x_implicitly_set_name (f
, arg
, oldval
)
1714 Lisp_Object arg
, oldval
;
1716 x_set_name (f
, arg
, 0);
1719 /* Change the title of frame F to NAME.
1720 If NAME is nil, use the frame name as the title.
1722 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1723 name; if NAME is a string, set F's name to NAME and set
1724 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1726 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1727 suggesting a new name, which lisp code should override; if
1728 F->explicit_name is set, ignore the new name; otherwise, set it. */
1731 x_set_title (f
, name
, old_name
)
1733 Lisp_Object name
, old_name
;
1735 /* Don't change the title if it's already NAME. */
1736 if (EQ (name
, f
->title
))
1739 update_mode_lines
= 1;
1746 CHECK_STRING (name
);
1748 if (FRAME_X_WINDOW (f
))
1753 XTextProperty text
, icon
;
1755 Lisp_Object coding_system
;
1757 coding_system
= Qcompound_text
;
1758 /* See the comment "Note: Encoding strategy" in x_set_name. */
1759 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
);
1760 text
.encoding
= (stringp
? XA_STRING
1761 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1763 text
.nitems
= bytes
;
1765 if (NILP (f
->icon_name
))
1771 /* See the comment "Note: Encoding strategy" in x_set_name. */
1772 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
1774 icon
.encoding
= (stringp
? XA_STRING
1775 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1777 icon
.nitems
= bytes
;
1781 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1782 SDATA (ENCODE_UTF_8 (name
)));
1783 #else /* not USE_GTK */
1784 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1785 #endif /* not USE_GTK */
1787 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1790 if (!NILP (f
->icon_name
)
1791 && icon
.value
!= (unsigned char *) SDATA (f
->icon_name
))
1793 if (text
.value
!= (unsigned char *) SDATA (name
))
1796 #else /* not HAVE_X11R4 */
1797 XSetIconName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1799 XStoreName (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1801 #endif /* not HAVE_X11R4 */
1807 x_set_scroll_bar_default_width (f
)
1810 int wid
= FRAME_COLUMN_WIDTH (f
);
1812 #ifdef USE_TOOLKIT_SCROLL_BARS
1813 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1814 int width
= 16 + 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1815 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (width
+ wid
- 1) / wid
;
1816 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = width
;
1818 /* Make the actual width at least 14 pixels and a multiple of a
1820 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
1822 /* Use all of that space (aside from required margins) for the
1824 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = 0;
1829 /* Record in frame F the specified or default value according to ALIST
1830 of the parameter named PROP (a Lisp symbol). If no value is
1831 specified for PROP, look for an X default for XPROP on the frame
1832 named NAME. If that is not found either, use the value DEFLT. */
1835 x_default_scroll_bar_color_parameter (f
, alist
, prop
, xprop
, xclass
,
1844 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1847 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
1848 if (EQ (tem
, Qunbound
))
1850 #ifdef USE_TOOLKIT_SCROLL_BARS
1852 /* See if an X resource for the scroll bar color has been
1854 tem
= display_x_get_resource (dpyinfo
,
1855 build_string (foreground_p
1859 build_string ("verticalScrollBar"),
1863 /* If nothing has been specified, scroll bars will use a
1864 toolkit-dependent default. Because these defaults are
1865 difficult to get at without actually creating a scroll
1866 bar, use nil to indicate that no color has been
1871 #else /* not USE_TOOLKIT_SCROLL_BARS */
1875 #endif /* not USE_TOOLKIT_SCROLL_BARS */
1878 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
1884 #if !defined (HAVE_X11R4) && !defined (HAVE_XSETWMPROTOCOLS)
1887 XSetWMProtocols (dpy
, w
, protocols
, count
)
1894 prop
= XInternAtom (dpy
, "WM_PROTOCOLS", False
);
1895 if (prop
== None
) return False
;
1896 XChangeProperty (dpy
, w
, prop
, XA_ATOM
, 32, PropModeReplace
,
1897 (unsigned char *) protocols
, count
);
1900 #endif /* not HAVE_X11R4 && not HAVE_XSETWMPROTOCOLS */
1902 #ifdef USE_X_TOOLKIT
1904 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
1905 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
1906 already be present because of the toolkit (Motif adds some of them,
1907 for example, but Xt doesn't). */
1910 hack_wm_protocols (f
, widget
)
1914 Display
*dpy
= XtDisplay (widget
);
1915 Window w
= XtWindow (widget
);
1916 int need_delete
= 1;
1922 Atom type
, *atoms
= 0;
1924 unsigned long nitems
= 0;
1925 unsigned long bytes_after
;
1927 if ((XGetWindowProperty (dpy
, w
,
1928 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1929 (long)0, (long)100, False
, XA_ATOM
,
1930 &type
, &format
, &nitems
, &bytes_after
,
1931 (unsigned char **) &atoms
)
1933 && format
== 32 && type
== XA_ATOM
)
1937 if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
1939 else if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
1941 else if (atoms
[nitems
] == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
1944 if (atoms
) XFree ((char *) atoms
);
1950 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
1952 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
1954 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
1956 XChangeProperty (dpy
, w
, FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1957 XA_ATOM
, 32, PropModeAppend
,
1958 (unsigned char *) props
, count
);
1966 /* Support routines for XIC (X Input Context). */
1970 static XFontSet xic_create_xfontset
P_ ((struct frame
*, char *));
1971 static XIMStyle best_xim_style
P_ ((XIMStyles
*, XIMStyles
*));
1974 /* Supported XIM styles, ordered by preference. */
1976 static XIMStyle supported_xim_styles
[] =
1978 XIMPreeditPosition
| XIMStatusArea
,
1979 XIMPreeditPosition
| XIMStatusNothing
,
1980 XIMPreeditPosition
| XIMStatusNone
,
1981 XIMPreeditNothing
| XIMStatusArea
,
1982 XIMPreeditNothing
| XIMStatusNothing
,
1983 XIMPreeditNothing
| XIMStatusNone
,
1984 XIMPreeditNone
| XIMStatusArea
,
1985 XIMPreeditNone
| XIMStatusNothing
,
1986 XIMPreeditNone
| XIMStatusNone
,
1991 /* Create an X fontset on frame F with base font name
1995 xic_create_xfontset (f
, base_fontname
)
1997 char *base_fontname
;
2000 char **missing_list
;
2004 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
),
2005 base_fontname
, &missing_list
,
2006 &missing_count
, &def_string
);
2008 XFreeStringList (missing_list
);
2010 /* No need to free def_string. */
2015 /* Value is the best input style, given user preferences USER (already
2016 checked to be supported by Emacs), and styles supported by the
2017 input method XIM. */
2020 best_xim_style (user
, xim
)
2026 for (i
= 0; i
< user
->count_styles
; ++i
)
2027 for (j
= 0; j
< xim
->count_styles
; ++j
)
2028 if (user
->supported_styles
[i
] == xim
->supported_styles
[j
])
2029 return user
->supported_styles
[i
];
2031 /* Return the default style. */
2032 return XIMPreeditNothing
| XIMStatusNothing
;
2035 /* Create XIC for frame F. */
2037 static XIMStyle xic_style
;
2040 create_frame_xic (f
)
2045 XFontSet xfs
= NULL
;
2050 xim
= FRAME_X_XIM (f
);
2055 XVaNestedList preedit_attr
;
2056 XVaNestedList status_attr
;
2057 char *base_fontname
;
2060 s_area
.x
= 0; s_area
.y
= 0; s_area
.width
= 1; s_area
.height
= 1;
2061 spot
.x
= 0; spot
.y
= 1;
2062 /* Create X fontset. */
2063 fontset
= FRAME_FONTSET (f
);
2065 base_fontname
= "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
2068 /* Determine the base fontname from the ASCII font name of
2070 char *ascii_font
= (char *) SDATA (fontset_ascii (fontset
));
2071 char *p
= ascii_font
;
2074 for (i
= 0; *p
; p
++)
2077 /* As the font name doesn't conform to XLFD, we can't
2078 modify it to get a suitable base fontname for the
2080 base_fontname
= "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
2083 int len
= strlen (ascii_font
) + 1;
2086 for (i
= 0, p
= ascii_font
; i
< 8; p
++)
2095 base_fontname
= (char *) alloca (len
);
2096 bzero (base_fontname
, len
);
2097 strcpy (base_fontname
, "-*-*-");
2098 bcopy (p1
, base_fontname
+ 5, p
- p1
);
2099 strcat (base_fontname
, "*-*-*-*-*-*-*");
2102 xfs
= xic_create_xfontset (f
, base_fontname
);
2104 /* Determine XIC style. */
2107 XIMStyles supported_list
;
2108 supported_list
.count_styles
= (sizeof supported_xim_styles
2109 / sizeof supported_xim_styles
[0]);
2110 supported_list
.supported_styles
= supported_xim_styles
;
2111 xic_style
= best_xim_style (&supported_list
,
2112 FRAME_X_XIM_STYLES (f
));
2115 preedit_attr
= XVaCreateNestedList (0,
2118 FRAME_FOREGROUND_PIXEL (f
),
2120 FRAME_BACKGROUND_PIXEL (f
),
2121 (xic_style
& XIMPreeditPosition
2126 status_attr
= XVaCreateNestedList (0,
2132 FRAME_FOREGROUND_PIXEL (f
),
2134 FRAME_BACKGROUND_PIXEL (f
),
2137 xic
= XCreateIC (xim
,
2138 XNInputStyle
, xic_style
,
2139 XNClientWindow
, FRAME_X_WINDOW (f
),
2140 XNFocusWindow
, FRAME_X_WINDOW (f
),
2141 XNStatusAttributes
, status_attr
,
2142 XNPreeditAttributes
, preedit_attr
,
2144 XFree (preedit_attr
);
2145 XFree (status_attr
);
2148 FRAME_XIC (f
) = xic
;
2149 FRAME_XIC_STYLE (f
) = xic_style
;
2150 FRAME_XIC_FONTSET (f
) = xfs
;
2154 /* Destroy XIC and free XIC fontset of frame F, if any. */
2160 if (FRAME_XIC (f
) == NULL
)
2163 XDestroyIC (FRAME_XIC (f
));
2164 if (FRAME_XIC_FONTSET (f
))
2165 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
2167 FRAME_XIC (f
) = NULL
;
2168 FRAME_XIC_FONTSET (f
) = NULL
;
2172 /* Place preedit area for XIC of window W's frame to specified
2173 pixel position X/Y. X and Y are relative to window W. */
2176 xic_set_preeditarea (w
, x
, y
)
2180 struct frame
*f
= XFRAME (w
->frame
);
2184 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
) + WINDOW_LEFT_FRINGE_WIDTH (w
);
2185 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
2186 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
2187 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2192 /* Place status area for XIC in bottom right corner of frame F.. */
2195 xic_set_statusarea (f
)
2198 XIC xic
= FRAME_XIC (f
);
2203 /* Negotiate geometry of status area. If input method has existing
2204 status area, use its current size. */
2205 area
.x
= area
.y
= area
.width
= area
.height
= 0;
2206 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
2207 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2210 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
2211 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2214 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
2216 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
2217 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2221 area
.width
= needed
->width
;
2222 area
.height
= needed
->height
;
2223 area
.x
= FRAME_PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
2224 area
.y
= (FRAME_PIXEL_HEIGHT (f
) - area
.height
2225 - FRAME_MENUBAR_HEIGHT (f
)
2226 - FRAME_TOOLBAR_HEIGHT (f
)
2227 - FRAME_INTERNAL_BORDER_WIDTH (f
));
2230 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
2231 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2236 /* Set X fontset for XIC of frame F, using base font name
2237 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2240 xic_set_xfontset (f
, base_fontname
)
2242 char *base_fontname
;
2247 xfs
= xic_create_xfontset (f
, base_fontname
);
2249 attr
= XVaCreateNestedList (0, XNFontSet
, xfs
, NULL
);
2250 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
2251 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2252 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
2253 XSetICValues (FRAME_XIC (f
), XNStatusAttributes
, attr
, NULL
);
2256 if (FRAME_XIC_FONTSET (f
))
2257 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
2258 FRAME_XIC_FONTSET (f
) = xfs
;
2261 #endif /* HAVE_X_I18N */
2265 #ifdef USE_X_TOOLKIT
2267 /* Create and set up the X widget for frame F. */
2270 x_window (f
, window_prompting
, minibuffer_only
)
2272 long window_prompting
;
2273 int minibuffer_only
;
2275 XClassHint class_hints
;
2276 XSetWindowAttributes attributes
;
2277 unsigned long attribute_mask
;
2278 Widget shell_widget
;
2280 Widget frame_widget
;
2286 /* Use the resource name as the top-level widget name
2287 for looking up resources. Make a non-Lisp copy
2288 for the window manager, so GC relocation won't bother it.
2290 Elsewhere we specify the window name for the window manager. */
2293 char *str
= (char *) SDATA (Vx_resource_name
);
2294 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
2295 strcpy (f
->namebuf
, str
);
2299 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2300 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2301 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2302 XtSetArg (al
[ac
], XtNborderWidth
, f
->border_width
); ac
++;
2303 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2304 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2305 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2306 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2307 applicationShellWidgetClass
,
2308 FRAME_X_DISPLAY (f
), al
, ac
);
2310 f
->output_data
.x
->widget
= shell_widget
;
2311 /* maybe_set_screen_title_format (shell_widget); */
2313 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2314 (widget_value
*) NULL
,
2315 shell_widget
, False
,
2319 (lw_callback
) NULL
);
2322 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2323 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2324 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2325 XtSetValues (pane_widget
, al
, ac
);
2326 f
->output_data
.x
->column_widget
= pane_widget
;
2328 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2329 the emacs screen when changing menubar. This reduces flickering. */
2332 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2333 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2334 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2335 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2336 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2337 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2338 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2339 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2340 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
2343 f
->output_data
.x
->edit_widget
= frame_widget
;
2345 XtManageChild (frame_widget
);
2347 /* Do some needed geometry management. */
2350 char *tem
, shell_position
[32];
2353 int extra_borders
= 0;
2355 = (f
->output_data
.x
->menubar_widget
2356 ? (f
->output_data
.x
->menubar_widget
->core
.height
2357 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
2360 #if 0 /* Experimentally, we now get the right results
2361 for -geometry -0-0 without this. 24 Aug 96, rms. */
2362 if (FRAME_EXTERNAL_MENU_BAR (f
))
2365 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2366 menubar_size
+= ibw
;
2370 f
->output_data
.x
->menubar_height
= menubar_size
;
2373 /* Motif seems to need this amount added to the sizes
2374 specified for the shell widget. The Athena/Lucid widgets don't.
2375 Both conclusions reached experimentally. -- rms. */
2376 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
2377 &extra_borders
, NULL
);
2381 /* Convert our geometry parameters into a geometry string
2383 Note that we do not specify here whether the position
2384 is a user-specified or program-specified one.
2385 We pass that information later, in x_wm_set_size_hints. */
2387 int left
= f
->left_pos
;
2388 int xneg
= window_prompting
& XNegative
;
2389 int top
= f
->top_pos
;
2390 int yneg
= window_prompting
& YNegative
;
2396 if (window_prompting
& USPosition
)
2397 sprintf (shell_position
, "=%dx%d%c%d%c%d",
2398 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2399 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
2400 (xneg
? '-' : '+'), left
,
2401 (yneg
? '-' : '+'), top
);
2404 sprintf (shell_position
, "=%dx%d",
2405 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2406 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
2408 /* Setting x and y when the position is not specified in
2409 the geometry string will set program position in the WM hints.
2410 If Emacs had just one program position, we could set it in
2411 fallback resources, but since each make-frame call can specify
2412 different program positions, this is easier. */
2413 XtSetArg (al
[ac
], XtNx
, left
); ac
++;
2414 XtSetArg (al
[ac
], XtNy
, top
); ac
++;
2418 len
= strlen (shell_position
) + 1;
2419 /* We don't free this because we don't know whether
2420 it is safe to free it while the frame exists.
2421 It isn't worth the trouble of arranging to free it
2422 when the frame is deleted. */
2423 tem
= (char *) xmalloc (len
);
2424 strncpy (tem
, shell_position
, len
);
2425 XtSetArg (al
[ac
], XtNgeometry
, tem
); ac
++;
2426 XtSetValues (shell_widget
, al
, ac
);
2429 XtManageChild (pane_widget
);
2430 XtRealizeWidget (shell_widget
);
2432 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2434 validate_x_resource_name ();
2436 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
2437 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
2438 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2441 FRAME_XIC (f
) = NULL
;
2443 create_frame_xic (f
);
2446 f
->output_data
.x
->wm_hints
.input
= True
;
2447 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2448 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2449 &f
->output_data
.x
->wm_hints
);
2451 hack_wm_protocols (f
, shell_widget
);
2454 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2457 /* Do a stupid property change to force the server to generate a
2458 PropertyNotify event so that the event_stream server timestamp will
2459 be initialized to something relevant to the time we created the window.
2461 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2462 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2463 XA_ATOM
, 32, PropModeAppend
,
2464 (unsigned char*) NULL
, 0);
2466 /* Make all the standard events reach the Emacs frame. */
2467 attributes
.event_mask
= STANDARD_EVENT_SET
;
2472 /* XIM server might require some X events. */
2473 unsigned long fevent
= NoEventMask
;
2474 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2475 attributes
.event_mask
|= fevent
;
2477 #endif /* HAVE_X_I18N */
2479 attribute_mask
= CWEventMask
;
2480 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2481 attribute_mask
, &attributes
);
2483 XtMapWidget (frame_widget
);
2485 /* x_set_name normally ignores requests to set the name if the
2486 requested name is the same as the current name. This is the one
2487 place where that assumption isn't correct; f->name is set, but
2488 the X server hasn't been told. */
2491 int explicit = f
->explicit_name
;
2493 f
->explicit_name
= 0;
2496 x_set_name (f
, name
, explicit);
2499 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2500 f
->output_data
.x
->text_cursor
);
2504 /* This is a no-op, except under Motif. Make sure main areas are
2505 set to something reasonable, in case we get an error later. */
2506 lw_set_main_areas (pane_widget
, 0, frame_widget
);
2509 #else /* not USE_X_TOOLKIT */
2515 if (! xg_create_frame_widgets (f
))
2516 error ("Unable to create window");
2519 FRAME_XIC (f
) = NULL
;
2523 create_frame_xic (f
);
2526 /* XIM server might require some X events. */
2527 unsigned long fevent
= NoEventMask
;
2528 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2530 if (fevent
!= NoEventMask
)
2532 XSetWindowAttributes attributes
;
2533 XWindowAttributes wattr
;
2534 unsigned long attribute_mask
;
2536 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2538 attributes
.event_mask
= wattr
.your_event_mask
| fevent
;
2539 attribute_mask
= CWEventMask
;
2540 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2541 attribute_mask
, &attributes
);
2549 #else /*! USE_GTK */
2550 /* Create and set up the X window for frame F. */
2557 XClassHint class_hints
;
2558 XSetWindowAttributes attributes
;
2559 unsigned long attribute_mask
;
2561 attributes
.background_pixel
= f
->output_data
.x
->background_pixel
;
2562 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
2563 attributes
.bit_gravity
= StaticGravity
;
2564 attributes
.backing_store
= NotUseful
;
2565 attributes
.save_under
= True
;
2566 attributes
.event_mask
= STANDARD_EVENT_SET
;
2567 attributes
.colormap
= FRAME_X_COLORMAP (f
);
2568 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
2573 = XCreateWindow (FRAME_X_DISPLAY (f
),
2574 f
->output_data
.x
->parent_desc
,
2577 FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
),
2579 CopyFromParent
, /* depth */
2580 InputOutput
, /* class */
2582 attribute_mask
, &attributes
);
2587 create_frame_xic (f
);
2590 /* XIM server might require some X events. */
2591 unsigned long fevent
= NoEventMask
;
2592 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2593 attributes
.event_mask
|= fevent
;
2594 attribute_mask
= CWEventMask
;
2595 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2596 attribute_mask
, &attributes
);
2599 #endif /* HAVE_X_I18N */
2601 validate_x_resource_name ();
2603 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
2604 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
2605 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2607 /* The menubar is part of the ordinary display;
2608 it does not count in addition to the height of the window. */
2609 f
->output_data
.x
->menubar_height
= 0;
2611 /* This indicates that we use the "Passive Input" input model.
2612 Unless we do this, we don't get the Focus{In,Out} events that we
2613 need to draw the cursor correctly. Accursed bureaucrats.
2614 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2616 f
->output_data
.x
->wm_hints
.input
= True
;
2617 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2618 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2619 &f
->output_data
.x
->wm_hints
);
2620 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
2622 /* Request "save yourself" and "delete window" commands from wm. */
2625 protocols
[0] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2626 protocols
[1] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2627 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2630 /* x_set_name normally ignores requests to set the name if the
2631 requested name is the same as the current name. This is the one
2632 place where that assumption isn't correct; f->name is set, but
2633 the X server hasn't been told. */
2636 int explicit = f
->explicit_name
;
2638 f
->explicit_name
= 0;
2641 x_set_name (f
, name
, explicit);
2644 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2645 f
->output_data
.x
->text_cursor
);
2649 if (FRAME_X_WINDOW (f
) == 0)
2650 error ("Unable to create window");
2653 #endif /* not USE_GTK */
2654 #endif /* not USE_X_TOOLKIT */
2656 /* Verify that the icon position args for this window are valid. */
2659 x_icon_verify (f
, parms
)
2663 Lisp_Object icon_x
, icon_y
;
2665 /* Set the position of the icon. Note that twm groups all
2666 icons in an icon window. */
2667 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2668 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2669 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2671 CHECK_NUMBER (icon_x
);
2672 CHECK_NUMBER (icon_y
);
2674 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2675 error ("Both left and top icon corners of icon must be specified");
2678 /* Handle the icon stuff for this window. Perhaps later we might
2679 want an x_set_icon_position which can be called interactively as
2687 Lisp_Object icon_x
, icon_y
;
2688 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2690 /* Set the position of the icon. Note that twm groups all
2691 icons in an icon window. */
2692 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2693 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2694 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2696 CHECK_NUMBER (icon_x
);
2697 CHECK_NUMBER (icon_y
);
2699 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2700 error ("Both left and top icon corners of icon must be specified");
2704 if (! EQ (icon_x
, Qunbound
))
2705 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2707 /* Start up iconic or window? */
2708 x_wm_set_window_state
2709 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
2714 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
2721 /* Make the GCs needed for this window, setting the
2722 background, border and mouse colors; also create the
2723 mouse cursor and the gray border tile. */
2725 static char cursor_bits
[] =
2727 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2728 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2729 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2730 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2737 XGCValues gc_values
;
2741 /* Create the GCs of this frame.
2742 Note that many default values are used. */
2745 gc_values
.font
= FRAME_FONT (f
)->fid
;
2746 gc_values
.foreground
= f
->output_data
.x
->foreground_pixel
;
2747 gc_values
.background
= f
->output_data
.x
->background_pixel
;
2748 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2749 f
->output_data
.x
->normal_gc
2750 = XCreateGC (FRAME_X_DISPLAY (f
),
2752 GCLineWidth
| GCFont
| GCForeground
| GCBackground
,
2755 /* Reverse video style. */
2756 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
2757 gc_values
.background
= f
->output_data
.x
->foreground_pixel
;
2758 f
->output_data
.x
->reverse_gc
2759 = XCreateGC (FRAME_X_DISPLAY (f
),
2761 GCFont
| GCForeground
| GCBackground
| GCLineWidth
,
2764 /* Cursor has cursor-color background, background-color foreground. */
2765 gc_values
.foreground
= f
->output_data
.x
->background_pixel
;
2766 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
2767 gc_values
.fill_style
= FillOpaqueStippled
;
2769 = XCreateBitmapFromData (FRAME_X_DISPLAY (f
),
2770 FRAME_X_DISPLAY_INFO (f
)->root_window
,
2771 cursor_bits
, 16, 16);
2772 f
->output_data
.x
->cursor_gc
2773 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2774 (GCFont
| GCForeground
| GCBackground
2775 | GCFillStyle
/* | GCStipple */ | GCLineWidth
),
2779 f
->output_data
.x
->white_relief
.gc
= 0;
2780 f
->output_data
.x
->black_relief
.gc
= 0;
2782 /* Create the gray border tile used when the pointer is not in
2783 the frame. Since this depends on the frame's pixel values,
2784 this must be done on a per-frame basis. */
2785 f
->output_data
.x
->border_tile
2786 = (XCreatePixmapFromBitmapData
2787 (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
2788 gray_bits
, gray_width
, gray_height
,
2789 f
->output_data
.x
->foreground_pixel
,
2790 f
->output_data
.x
->background_pixel
,
2791 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
2797 /* Free what was was allocated in x_make_gc. */
2803 Display
*dpy
= FRAME_X_DISPLAY (f
);
2807 if (f
->output_data
.x
->normal_gc
)
2809 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
2810 f
->output_data
.x
->normal_gc
= 0;
2813 if (f
->output_data
.x
->reverse_gc
)
2815 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
2816 f
->output_data
.x
->reverse_gc
= 0;
2819 if (f
->output_data
.x
->cursor_gc
)
2821 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
2822 f
->output_data
.x
->cursor_gc
= 0;
2825 if (f
->output_data
.x
->border_tile
)
2827 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
2828 f
->output_data
.x
->border_tile
= 0;
2835 /* Handler for signals raised during x_create_frame and
2836 x_create_top_frame. FRAME is the frame which is partially
2840 unwind_create_frame (frame
)
2843 struct frame
*f
= XFRAME (frame
);
2845 /* If frame is ``official'', nothing to do. */
2846 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
2849 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2852 x_free_frame_resources (f
);
2854 /* Check that reference counts are indeed correct. */
2855 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
2856 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
2864 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
2866 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
2867 Returns an Emacs frame object.
2868 ALIST is an alist of frame parameters.
2869 If the parameters specify that the frame should not have a minibuffer,
2870 and do not specify a specific minibuffer window to use,
2871 then `default-minibuffer-frame' must be a frame whose minibuffer can
2872 be shared by the new frame.
2874 This function is an internal primitive--use `make-frame' instead. */)
2879 Lisp_Object frame
, tem
;
2881 int minibuffer_only
= 0;
2882 long window_prompting
= 0;
2884 int count
= SPECPDL_INDEX ();
2885 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
2886 Lisp_Object display
;
2887 struct x_display_info
*dpyinfo
= NULL
;
2891 /* Use this general default value to start with
2892 until we know if this frame has a specified name. */
2893 Vx_resource_name
= Vinvocation_name
;
2895 display
= x_get_arg (dpyinfo
, parms
, Qdisplay_id
, 0, 0, RES_TYPE_NUMBER
);
2896 if (EQ (display
, Qunbound
))
2897 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
2898 if (EQ (display
, Qunbound
))
2900 dpyinfo
= check_x_display_info (display
);
2902 kb
= dpyinfo
->kboard
;
2904 kb
= &the_only_kboard
;
2907 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
2909 && ! EQ (name
, Qunbound
)
2911 error ("Invalid frame name--not a string or nil");
2914 Vx_resource_name
= name
;
2916 /* See if parent window is specified. */
2917 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
2918 if (EQ (parent
, Qunbound
))
2920 if (! NILP (parent
))
2921 CHECK_NUMBER (parent
);
2923 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
2924 /* No need to protect DISPLAY because that's not used after passing
2925 it to make_frame_without_minibuffer. */
2927 GCPRO4 (parms
, parent
, name
, frame
);
2928 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
2930 if (EQ (tem
, Qnone
) || NILP (tem
))
2931 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
2932 else if (EQ (tem
, Qonly
))
2934 f
= make_minibuffer_frame ();
2935 minibuffer_only
= 1;
2937 else if (WINDOWP (tem
))
2938 f
= make_frame_without_minibuffer (tem
, kb
, display
);
2942 XSETFRAME (frame
, f
);
2944 /* Note that X Windows does support scroll bars. */
2945 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
2947 f
->display
= dpyinfo
->frame_display
;
2948 f
->display
->reference_count
++;
2950 f
->output_method
= output_x_window
;
2951 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
2952 bzero (f
->output_data
.x
, sizeof (struct x_output
));
2953 f
->output_data
.x
->icon_bitmap
= -1;
2954 FRAME_FONTSET (f
) = -1;
2955 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
2956 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
2957 #ifdef USE_TOOLKIT_SCROLL_BARS
2958 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
2959 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
2960 #endif /* USE_TOOLKIT_SCROLL_BARS */
2961 record_unwind_protect (unwind_create_frame
, frame
);
2964 = x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
2966 if (! STRINGP (f
->icon_name
))
2967 f
->icon_name
= Qnil
;
2969 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
2971 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
2972 dpyinfo_refcount
= dpyinfo
->reference_count
;
2973 #endif /* GLYPH_DEBUG */
2975 FRAME_KBOARD (f
) = kb
;
2978 /* These colors will be set anyway later, but it's important
2979 to get the color reference counts right, so initialize them! */
2982 struct gcpro gcpro1
;
2984 /* Function x_decode_color can signal an error. Make
2985 sure to initialize color slots so that we won't try
2986 to free colors we haven't allocated. */
2987 f
->output_data
.x
->foreground_pixel
= -1;
2988 f
->output_data
.x
->background_pixel
= -1;
2989 f
->output_data
.x
->cursor_pixel
= -1;
2990 f
->output_data
.x
->cursor_foreground_pixel
= -1;
2991 f
->output_data
.x
->border_pixel
= -1;
2992 f
->output_data
.x
->mouse_pixel
= -1;
2994 black
= build_string ("black");
2996 f
->output_data
.x
->foreground_pixel
2997 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2998 f
->output_data
.x
->background_pixel
2999 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3000 f
->output_data
.x
->cursor_pixel
3001 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3002 f
->output_data
.x
->cursor_foreground_pixel
3003 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3004 f
->output_data
.x
->border_pixel
3005 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3006 f
->output_data
.x
->mouse_pixel
3007 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3011 /* Specify the parent under which to make this X window. */
3015 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
3016 f
->output_data
.x
->explicit_parent
= 1;
3020 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3021 f
->output_data
.x
->explicit_parent
= 0;
3024 /* Set the name; the functions to which we pass f expect the name to
3026 if (EQ (name
, Qunbound
) || NILP (name
))
3028 f
->name
= build_string (dpyinfo
->x_id_name
);
3029 f
->explicit_name
= 0;
3034 f
->explicit_name
= 1;
3035 /* use the frame's title when getting resources for this frame. */
3036 specbind (Qx_resource_name
, name
);
3039 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qwindow_system
, Qx
), Qnil
));
3041 /* Extract the window parameters from the supplied values
3042 that are needed to determine window geometry. */
3046 font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
3049 /* First, try whatever font the caller has specified. */
3052 tem
= Fquery_fontset (font
, Qnil
);
3054 font
= x_new_fontset (f
, SDATA (tem
));
3056 font
= x_new_font (f
, SDATA (font
));
3059 /* Try out a font which we hope has bold and italic variations. */
3060 if (!STRINGP (font
))
3061 font
= x_new_font (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
3062 if (!STRINGP (font
))
3063 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3064 if (! STRINGP (font
))
3065 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
3066 if (! STRINGP (font
))
3067 /* This was formerly the first thing tried, but it finds too many fonts
3068 and takes too long. */
3069 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
3070 /* If those didn't work, look for something which will at least work. */
3071 if (! STRINGP (font
))
3072 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
3074 if (! STRINGP (font
))
3075 font
= build_string ("fixed");
3077 x_default_parameter (f
, parms
, Qfont
, font
,
3078 "font", "Font", RES_TYPE_STRING
);
3082 /* Prevent lwlib/xlwmenu.c from crashing because of a bug
3083 whereby it fails to get any font. */
3084 xlwmenu_default_font
= FRAME_FONT (f
);
3087 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
3088 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
3090 /* This defaults to 1 in order to match xterm. We recognize either
3091 internalBorderWidth or internalBorder (which is what xterm calls
3093 if (NILP (Fassq (Qinternal_border_width
, parms
)))
3097 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
3098 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
3099 if (! EQ (value
, Qunbound
))
3100 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
3103 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
3104 "internalBorderWidth", "internalBorderWidth",
3106 x_default_parameter (f
, parms
, Qvertical_scroll_bars
, Qleft
,
3107 "verticalScrollBars", "ScrollBars",
3110 /* Also do the stuff which must be set before the window exists. */
3111 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3112 "foreground", "Foreground", RES_TYPE_STRING
);
3113 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3114 "background", "Background", RES_TYPE_STRING
);
3115 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3116 "pointerColor", "Foreground", RES_TYPE_STRING
);
3117 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
3118 "cursorColor", "Foreground", RES_TYPE_STRING
);
3119 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3120 "borderColor", "BorderColor", RES_TYPE_STRING
);
3121 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3122 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3123 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3124 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3125 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3126 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3127 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3128 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3130 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3131 "scrollBarForeground",
3132 "ScrollBarForeground", 1);
3133 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3134 "scrollBarBackground",
3135 "ScrollBarBackground", 0);
3137 /* Init faces before x_default_parameter is called for scroll-bar
3138 parameters because that function calls x_set_scroll_bar_width,
3139 which calls change_frame_size, which calls Fset_window_buffer,
3140 which runs hooks, which call Fvertical_motion. At the end, we
3141 end up in init_iterator with a null face cache, which should not
3143 init_frame_faces (f
);
3145 x_default_parameter (f
, parms
, Qmenu_bar_lines
, make_number (1),
3146 "menuBar", "MenuBar", RES_TYPE_NUMBER
);
3147 x_default_parameter (f
, parms
, Qtool_bar_lines
, make_number (1),
3148 "toolBar", "ToolBar", RES_TYPE_NUMBER
);
3149 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3150 "bufferPredicate", "BufferPredicate",
3152 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3153 "title", "Title", RES_TYPE_STRING
);
3154 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3155 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3156 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3157 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3159 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3161 /* Compute the size of the X window. */
3162 window_prompting
= x_figure_window_size (f
, parms
, 1);
3164 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3165 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3167 x_icon_verify (f
, parms
);
3169 /* Create the X widget or window. */
3170 #ifdef USE_X_TOOLKIT
3171 x_window (f
, window_prompting
, minibuffer_only
);
3179 /* Now consider the frame official. */
3180 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
3181 Vframe_list
= Fcons (frame
, Vframe_list
);
3183 /* We need to do this after creating the X window, so that the
3184 icon-creation functions can say whose icon they're describing. */
3185 x_default_parameter (f
, parms
, Qicon_type
, Qnil
,
3186 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
3188 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3189 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3190 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3191 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3192 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3193 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3194 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3195 "scrollBarWidth", "ScrollBarWidth",
3198 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
3199 Change will not be effected unless different from the current
3201 width
= FRAME_COLS (f
);
3202 height
= FRAME_LINES (f
);
3204 SET_FRAME_COLS (f
, 0);
3205 FRAME_LINES (f
) = 0;
3206 change_frame_size (f
, height
, width
, 1, 0, 0);
3208 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3209 /* Create the menu bar. */
3210 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3212 /* If this signals an error, we haven't set size hints for the
3213 frame and we didn't make it visible. */
3214 initialize_frame_menubar (f
);
3217 /* This is a no-op, except under Motif where it arranges the
3218 main window for the widgets on it. */
3219 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3220 f
->output_data
.x
->menubar_widget
,
3221 f
->output_data
.x
->edit_widget
);
3222 #endif /* not USE_GTK */
3224 #endif /* USE_X_TOOLKIT || USE_GTK */
3226 /* Tell the server what size and position, etc, we want, and how
3227 badly we want them. This should be done after we have the menu
3228 bar so that its size can be taken into account. */
3230 x_wm_set_size_hint (f
, window_prompting
, 0);
3233 /* Make the window appear on the frame and enable display, unless
3234 the caller says not to. However, with explicit parent, Emacs
3235 cannot control visibility, so don't try. */
3236 if (! f
->output_data
.x
->explicit_parent
)
3238 Lisp_Object visibility
;
3240 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3242 if (EQ (visibility
, Qunbound
))
3245 if (EQ (visibility
, Qicon
))
3246 x_iconify_frame (f
);
3247 else if (! NILP (visibility
))
3248 x_make_frame_visible (f
);
3250 /* Must have been Qnil. */
3254 /* Set the WM leader property. GTK does this itself, so this is not
3255 needed when using GTK. */
3256 if (dpyinfo
->client_leader_window
!= 0)
3259 XChangeProperty (FRAME_X_DISPLAY (f
),
3260 FRAME_OUTER_WINDOW (f
),
3261 dpyinfo
->Xatom_wm_client_leader
,
3262 XA_WINDOW
, 32, PropModeReplace
,
3263 (char *) &dpyinfo
->client_leader_window
, 1);
3269 /* Make sure windows on this frame appear in calls to next-window
3270 and similar functions. */
3271 Vwindow_list
= Qnil
;
3273 return unbind_to (count
, frame
);
3277 /* FRAME is used only to get a handle on the X display. We don't pass the
3278 display info directly because we're called from frame.c, which doesn't
3279 know about that structure. */
3282 x_get_focus_frame (frame
)
3283 struct frame
*frame
;
3285 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (frame
);
3287 if (! dpyinfo
->x_focus_frame
)
3290 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3295 /* In certain situations, when the window manager follows a
3296 click-to-focus policy, there seems to be no way around calling
3297 XSetInputFocus to give another frame the input focus .
3299 In an ideal world, XSetInputFocus should generally be avoided so
3300 that applications don't interfere with the window manager's focus
3301 policy. But I think it's okay to use when it's clearly done
3302 following a user-command. */
3304 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
3305 doc
: /* Set the input focus to FRAME.
3306 FRAME nil means use the selected frame. */)
3310 struct frame
*f
= check_x_frame (frame
);
3311 Display
*dpy
= FRAME_X_DISPLAY (f
);
3315 count
= x_catch_errors (dpy
);
3316 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3317 RevertToParent
, CurrentTime
);
3318 x_uncatch_errors (dpy
, count
);
3325 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
3326 doc
: /* Internal function called by `color-defined-p', which see. */)
3328 Lisp_Object color
, frame
;
3331 FRAME_PTR f
= check_x_frame (frame
);
3333 CHECK_STRING (color
);
3335 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
3341 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
3342 doc
: /* Internal function called by `color-values', which see. */)
3344 Lisp_Object color
, frame
;
3347 FRAME_PTR f
= check_x_frame (frame
);
3349 CHECK_STRING (color
);
3351 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
3355 rgb
[0] = make_number (foo
.red
);
3356 rgb
[1] = make_number (foo
.green
);
3357 rgb
[2] = make_number (foo
.blue
);
3358 return Flist (3, rgb
);
3364 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
3365 doc
: /* Internal function called by `display-color-p', which see. */)
3367 Lisp_Object display
;
3369 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3371 if (dpyinfo
->n_planes
<= 2)
3374 switch (dpyinfo
->visual
->class)
3387 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3389 doc
: /* Return t if the X display supports shades of gray.
3390 Note that color displays do support shades of gray.
3391 The optional argument DISPLAY specifies which display to ask about.
3392 DISPLAY should be either a frame or a display name (a string).
3393 If omitted or nil, that stands for the selected frame's display. */)
3395 Lisp_Object display
;
3397 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3399 if (dpyinfo
->n_planes
<= 1)
3402 switch (dpyinfo
->visual
->class)
3417 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3419 doc
: /* Returns the width in pixels of the X display DISPLAY.
3420 The optional argument DISPLAY specifies which display to ask about.
3421 DISPLAY should be either a frame or a display name (a string).
3422 If omitted or nil, that stands for the selected frame's display. */)
3424 Lisp_Object display
;
3426 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3428 return make_number (dpyinfo
->width
);
3431 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3432 Sx_display_pixel_height
, 0, 1, 0,
3433 doc
: /* Returns the height in pixels of the X display DISPLAY.
3434 The optional argument DISPLAY specifies which display to ask about.
3435 DISPLAY should be either a frame or a display name (a string).
3436 If omitted or nil, that stands for the selected frame's display. */)
3438 Lisp_Object display
;
3440 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3442 return make_number (dpyinfo
->height
);
3445 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3447 doc
: /* Returns the number of bitplanes of the X display DISPLAY.
3448 The optional argument DISPLAY specifies which display to ask about.
3449 DISPLAY should be either a frame or a display name (a string).
3450 If omitted or nil, that stands for the selected frame's display. */)
3452 Lisp_Object display
;
3454 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3456 return make_number (dpyinfo
->n_planes
);
3459 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3461 doc
: /* Returns the number of color cells of the X display DISPLAY.
3462 The optional argument DISPLAY specifies which display to ask about.
3463 DISPLAY should be either a frame or a display name (a string).
3464 If omitted or nil, that stands for the selected frame's display. */)
3466 Lisp_Object display
;
3468 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3470 int nr_planes
= DisplayPlanes (dpyinfo
->display
,
3471 XScreenNumberOfScreen (dpyinfo
->screen
));
3473 /* Truncate nr_planes to 24 to avoid integer overflow.
3474 Some displays says 32, but only 24 bits are actually significant.
3475 There are only very few and rare video cards that have more than
3476 24 significant bits. Also 24 bits is more than 16 million colors,
3477 it "should be enough for everyone". */
3478 if (nr_planes
> 24) nr_planes
= 24;
3480 return make_number (1 << nr_planes
);
3483 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3484 Sx_server_max_request_size
,
3486 doc
: /* Returns the maximum request size of the X server of display DISPLAY.
3487 The optional argument DISPLAY specifies which display to ask about.
3488 DISPLAY should be either a frame or a display name (a string).
3489 If omitted or nil, that stands for the selected frame's display. */)
3491 Lisp_Object display
;
3493 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3495 return make_number (MAXREQUEST (dpyinfo
->display
));
3498 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3499 doc
: /* Returns the vendor ID string of the X server of display DISPLAY.
3500 The optional argument DISPLAY specifies which display to ask about.
3501 DISPLAY should be either a frame or a display name (a string).
3502 If omitted or nil, that stands for the selected frame's display. */)
3504 Lisp_Object display
;
3506 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3507 char *vendor
= ServerVendor (dpyinfo
->display
);
3509 if (! vendor
) vendor
= "";
3510 return build_string (vendor
);
3513 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3514 doc
: /* Returns the version numbers of the X server of display DISPLAY.
3515 The value is a list of three integers: the major and minor
3516 version numbers of the X Protocol in use, and the vendor-specific release
3517 number. See also the function `x-server-vendor'.
3519 The optional argument DISPLAY specifies which display to ask about.
3520 DISPLAY should be either a frame or a display name (a string).
3521 If omitted or nil, that stands for the selected frame's display. */)
3523 Lisp_Object display
;
3525 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3526 Display
*dpy
= dpyinfo
->display
;
3528 return Fcons (make_number (ProtocolVersion (dpy
)),
3529 Fcons (make_number (ProtocolRevision (dpy
)),
3530 Fcons (make_number (VendorRelease (dpy
)), Qnil
)));
3533 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3534 doc
: /* Return the number of screens on the X server of display DISPLAY.
3535 The optional argument DISPLAY specifies which display to ask about.
3536 DISPLAY should be either a frame or a display name (a string).
3537 If omitted or nil, that stands for the selected frame's display. */)
3539 Lisp_Object display
;
3541 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3543 return make_number (ScreenCount (dpyinfo
->display
));
3546 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3547 doc
: /* Return the height in millimeters of the X display DISPLAY.
3548 The optional argument DISPLAY specifies which display to ask about.
3549 DISPLAY should be either a frame or a display name (a string).
3550 If omitted or nil, that stands for the selected frame's display. */)
3552 Lisp_Object display
;
3554 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3556 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3559 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3560 doc
: /* Return the width in millimeters of the X display DISPLAY.
3561 The optional argument DISPLAY specifies which display to ask about.
3562 DISPLAY should be either a frame or a display name (a string).
3563 If omitted or nil, that stands for the selected frame's display. */)
3565 Lisp_Object display
;
3567 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3569 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3572 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3573 Sx_display_backing_store
, 0, 1, 0,
3574 doc
: /* Returns an indication of whether X display DISPLAY does backing store.
3575 The value may be `always', `when-mapped', or `not-useful'.
3576 The optional argument DISPLAY specifies which display to ask about.
3577 DISPLAY should be either a frame or a display name (a string).
3578 If omitted or nil, that stands for the selected frame's display. */)
3580 Lisp_Object display
;
3582 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3585 switch (DoesBackingStore (dpyinfo
->screen
))
3588 result
= intern ("always");
3592 result
= intern ("when-mapped");
3596 result
= intern ("not-useful");
3600 error ("Strange value for BackingStore parameter of screen");
3607 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3608 Sx_display_visual_class
, 0, 1, 0,
3609 doc
: /* Return the visual class of the X display DISPLAY.
3610 The value is one of the symbols `static-gray', `gray-scale',
3611 `static-color', `pseudo-color', `true-color', or `direct-color'.
3613 The optional argument DISPLAY specifies which display to ask about.
3614 DISPLAY should be either a frame or a display name (a string).
3615 If omitted or nil, that stands for the selected frame's display. */)
3617 Lisp_Object display
;
3619 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3622 switch (dpyinfo
->visual
->class)
3625 result
= intern ("static-gray");
3628 result
= intern ("gray-scale");
3631 result
= intern ("static-color");
3634 result
= intern ("pseudo-color");
3637 result
= intern ("true-color");
3640 result
= intern ("direct-color");
3643 error ("Display has an unknown visual class");
3650 DEFUN ("x-display-save-under", Fx_display_save_under
,
3651 Sx_display_save_under
, 0, 1, 0,
3652 doc
: /* Returns t if the X display DISPLAY supports the save-under feature.
3653 The optional argument DISPLAY specifies which display to ask about.
3654 DISPLAY should be either a frame or a display name (a string).
3655 If omitted or nil, that stands for the selected frame's display. */)
3657 Lisp_Object display
;
3659 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3661 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3669 register struct frame
*f
;
3671 return FRAME_PIXEL_WIDTH (f
);
3676 register struct frame
*f
;
3678 return FRAME_PIXEL_HEIGHT (f
);
3683 register struct frame
*f
;
3685 return FRAME_COLUMN_WIDTH (f
);
3690 register struct frame
*f
;
3692 return FRAME_LINE_HEIGHT (f
);
3697 register struct frame
*f
;
3699 return FRAME_X_DISPLAY_INFO (f
)->n_planes
;
3704 /************************************************************************
3706 ************************************************************************/
3709 /* Mapping visual names to visuals. */
3711 static struct visual_class
3718 {"StaticGray", StaticGray
},
3719 {"GrayScale", GrayScale
},
3720 {"StaticColor", StaticColor
},
3721 {"PseudoColor", PseudoColor
},
3722 {"TrueColor", TrueColor
},
3723 {"DirectColor", DirectColor
},
3728 #ifndef HAVE_XSCREENNUMBEROFSCREEN
3730 /* Value is the screen number of screen SCR. This is a substitute for
3731 the X function with the same name when that doesn't exist. */
3734 XScreenNumberOfScreen (scr
)
3735 register Screen
*scr
;
3737 Display
*dpy
= scr
->display
;
3740 for (i
= 0; i
< dpy
->nscreens
; ++i
)
3741 if (scr
== dpy
->screens
+ i
)
3747 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
3750 /* Select the visual that should be used on display DPYINFO. Set
3751 members of DPYINFO appropriately. Called from x_term_init. */
3754 select_visual (dpyinfo
)
3755 struct x_display_info
*dpyinfo
;
3757 Display
*dpy
= dpyinfo
->display
;
3758 Screen
*screen
= dpyinfo
->screen
;
3761 /* See if a visual is specified. */
3762 value
= display_x_get_resource (dpyinfo
,
3763 build_string ("visualClass"),
3764 build_string ("VisualClass"),
3766 if (STRINGP (value
))
3768 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
3769 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
3770 depth, a decimal number. NAME is compared with case ignored. */
3771 char *s
= (char *) alloca (SBYTES (value
) + 1);
3776 strcpy (s
, SDATA (value
));
3777 dash
= index (s
, '-');
3780 dpyinfo
->n_planes
= atoi (dash
+ 1);
3784 /* We won't find a matching visual with depth 0, so that
3785 an error will be printed below. */
3786 dpyinfo
->n_planes
= 0;
3788 /* Determine the visual class. */
3789 for (i
= 0; visual_classes
[i
].name
; ++i
)
3790 if (xstricmp (s
, visual_classes
[i
].name
) == 0)
3792 class = visual_classes
[i
].class;
3796 /* Look up a matching visual for the specified class. */
3798 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
3799 dpyinfo
->n_planes
, class, &vinfo
))
3800 fatal ("Invalid visual specification `%s'", SDATA (value
));
3802 dpyinfo
->visual
= vinfo
.visual
;
3807 XVisualInfo
*vinfo
, vinfo_template
;
3809 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
3812 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
3814 vinfo_template
.visualid
= dpyinfo
->visual
->visualid
;
3816 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
3817 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
3818 &vinfo_template
, &n_visuals
);
3820 fatal ("Can't get proper X visual info");
3822 dpyinfo
->n_planes
= vinfo
->depth
;
3823 XFree ((char *) vinfo
);
3828 /* Return the X display structure for the display named NAME.
3829 Open a new connection if necessary. */
3831 struct x_display_info
*
3832 x_display_info_for_name (name
)
3836 struct x_display_info
*dpyinfo
;
3838 CHECK_STRING (name
);
3841 if (! EQ (Vinitial_window_system
, intern ("x")))
3842 error ("Not using X Windows"); /* That doesn't stop us anymore. */
3845 for (dpyinfo
= x_display_list
, names
= x_display_name_list
;
3847 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
3850 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
3855 /* Use this general default value to start with. */
3856 Vx_resource_name
= Vinvocation_name
;
3858 validate_x_resource_name ();
3860 dpyinfo
= x_term_init (name
, (char *)0,
3861 (char *) SDATA (Vx_resource_name
));
3864 error ("Cannot connect to X server %s", SDATA (name
));
3867 XSETFASTINT (Vwindow_system_version
, 11);
3873 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
3875 doc
: /* Open a connection to an X server.
3876 DISPLAY is the name of the display to connect to.
3877 Optional second arg XRM-STRING is a string of resources in xrdb format.
3878 If the optional third arg MUST-SUCCEED is non-nil,
3879 terminate Emacs if we can't open the connection. */)
3880 (display
, xrm_string
, must_succeed
)
3881 Lisp_Object display
, xrm_string
, must_succeed
;
3883 unsigned char *xrm_option
;
3884 struct x_display_info
*dpyinfo
;
3886 CHECK_STRING (display
);
3887 if (! NILP (xrm_string
))
3888 CHECK_STRING (xrm_string
);
3891 if (! EQ (Vinitial_window_system
, intern ("x")))
3892 error ("Not using X Windows"); /* That doesn't stop us anymore. */
3895 if (! NILP (xrm_string
))
3896 xrm_option
= (unsigned char *) SDATA (xrm_string
);
3898 xrm_option
= (unsigned char *) 0;
3900 validate_x_resource_name ();
3902 /* This is what opens the connection and sets x_current_display.
3903 This also initializes many symbols, such as those used for input. */
3904 dpyinfo
= x_term_init (display
, xrm_option
,
3905 (char *) SDATA (Vx_resource_name
));
3909 if (!NILP (must_succeed
))
3910 fatal ("Cannot connect to X server %s.\n\
3911 Check the DISPLAY environment variable or use `-d'.\n\
3912 Also use the `xauth' program to verify that you have the proper\n\
3913 authorization information needed to connect the X server.\n\
3914 An insecure way to solve the problem may be to use `xhost'.\n",
3917 error ("Cannot connect to X server %s", SDATA (display
));
3922 XSETFASTINT (Vwindow_system_version
, 11);
3926 DEFUN ("x-close-connection", Fx_close_connection
,
3927 Sx_close_connection
, 1, 1, 0,
3928 doc
: /* Close the connection to DISPLAY's X server.
3929 For DISPLAY, specify either a frame or a display name (a string).
3930 If DISPLAY is nil, that stands for the selected frame's display. */)
3932 Lisp_Object display
;
3934 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3937 if (dpyinfo
->reference_count
> 0)
3938 error ("Display still has frames on it");
3941 /* Free the fonts in the font table. */
3942 for (i
= 0; i
< dpyinfo
->n_fonts
; i
++)
3943 if (dpyinfo
->font_table
[i
].name
)
3945 XFreeFont (dpyinfo
->display
, dpyinfo
->font_table
[i
].font
);
3948 x_destroy_all_bitmaps (dpyinfo
);
3949 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
3951 #ifdef USE_X_TOOLKIT
3952 XtCloseDisplay (dpyinfo
->display
);
3954 XCloseDisplay (dpyinfo
->display
);
3957 x_delete_display (dpyinfo
);
3963 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
3964 doc
: /* Return the list of display names that Emacs has connections to. */)
3967 Lisp_Object tail
, result
;
3970 for (tail
= x_display_name_list
; ! NILP (tail
); tail
= XCDR (tail
))
3971 result
= Fcons (XCAR (XCAR (tail
)), result
);
3976 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
3977 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
3978 If ON is nil, allow buffering of requests.
3979 Turning on synchronization prohibits the Xlib routines from buffering
3980 requests and seriously degrades performance, but makes debugging much
3982 The optional second argument DISPLAY specifies which display to act on.
3983 DISPLAY should be either a frame or a display name (a string).
3984 If DISPLAY is omitted or nil, that stands for the selected frame's display. */)
3986 Lisp_Object display
, on
;
3988 struct x_display_info
*dpyinfo
= check_x_display_info (display
);
3990 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
3995 /* Wait for responses to all X commands issued so far for frame F. */
4002 XSync (FRAME_X_DISPLAY (f
), False
);
4007 /***********************************************************************
4009 ***********************************************************************/
4011 DEFUN ("x-change-window-property", Fx_change_window_property
,
4012 Sx_change_window_property
, 2, 6, 0,
4013 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
4014 PROP must be a string.
4015 VALUE may be a string or a list of conses, numbers and/or strings.
4016 If an element in the list is a string, it is converted to
4017 an Atom and the value of the Atom is used. If an element is a cons,
4018 it is converted to a 32 bit number where the car is the 16 top bits and the
4019 cdr is the lower 16 bits.
4020 FRAME nil or omitted means use the selected frame.
4021 If TYPE is given and non-nil, it is the name of the type of VALUE.
4022 If TYPE is not given or nil, the type is STRING.
4023 FORMAT gives the size in bits of each element if VALUE is a list.
4024 It must be one of 8, 16 or 32.
4025 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4026 If OUTER_P is non-nil, the property is changed for the outer X window of
4027 FRAME. Default is to change on the edit X window.
4030 (prop
, value
, frame
, type
, format
, outer_p
)
4031 Lisp_Object prop
, value
, frame
, type
, format
, outer_p
;
4033 struct frame
*f
= check_x_frame (frame
);
4035 Atom target_type
= XA_STRING
;
4036 int element_format
= 8;
4037 unsigned char *data
;
4041 CHECK_STRING (prop
);
4043 if (! NILP (format
))
4045 CHECK_NUMBER (format
);
4046 element_format
= XFASTINT (format
);
4048 if (element_format
!= 8 && element_format
!= 16
4049 && element_format
!= 32)
4050 error ("FORMAT must be one of 8, 16 or 32");
4055 nelements
= x_check_property_data (value
);
4056 if (nelements
== -1)
4057 error ("Bad data in VALUE, must be number, string or cons");
4059 if (element_format
== 8)
4060 data
= (unsigned char *) xmalloc (nelements
);
4061 else if (element_format
== 16)
4062 data
= (unsigned char *) xmalloc (nelements
*2);
4064 data
= (unsigned char *) xmalloc (nelements
*4);
4066 x_fill_property_data (FRAME_X_DISPLAY (f
), value
, data
, element_format
);
4070 CHECK_STRING (value
);
4071 data
= SDATA (value
);
4072 nelements
= SCHARS (value
);
4076 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4079 CHECK_STRING (type
);
4080 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (type
), False
);
4083 if (! NILP (outer_p
)) w
= FRAME_OUTER_WINDOW (f
);
4084 else w
= FRAME_X_WINDOW (f
);
4086 XChangeProperty (FRAME_X_DISPLAY (f
), w
,
4087 prop_atom
, target_type
, element_format
, PropModeReplace
,
4090 if (CONSP (value
)) xfree (data
);
4092 /* Make sure the property is set when we return. */
4093 XFlush (FRAME_X_DISPLAY (f
));
4100 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
4101 Sx_delete_window_property
, 1, 2, 0,
4102 doc
: /* Remove window property PROP from X window of FRAME.
4103 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4105 Lisp_Object prop
, frame
;
4107 struct frame
*f
= check_x_frame (frame
);
4110 CHECK_STRING (prop
);
4112 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4113 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
4115 /* Make sure the property is removed when we return. */
4116 XFlush (FRAME_X_DISPLAY (f
));
4123 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
4125 doc
: /* Value is the value of window property PROP on FRAME.
4126 If FRAME is nil or omitted, use the selected frame.
4127 If TYPE is nil or omitted, get the property as a string. Otherwise TYPE
4128 is the name of the Atom that denotes the type expected.
4129 If SOURCE is non-nil, get the property on that window instead of from
4130 FRAME. The number 0 denotes the root window.
4131 If DELETE_P is non-nil, delete the property after retreiving it.
4132 If VECTOR_RET_P is non-nil, don't return a string but a vector of values.
4134 Value is nil if FRAME hasn't a property with name PROP or if PROP has
4135 no value of TYPE. */)
4136 (prop
, frame
, type
, source
, delete_p
, vector_ret_p
)
4137 Lisp_Object prop
, frame
, type
, source
, delete_p
, vector_ret_p
;
4139 struct frame
*f
= check_x_frame (frame
);
4142 Lisp_Object prop_value
= Qnil
;
4143 char *tmp_data
= NULL
;
4145 Atom target_type
= XA_STRING
;
4147 unsigned long actual_size
, bytes_remaining
;
4148 Window target_window
= FRAME_X_WINDOW (f
);
4149 struct gcpro gcpro1
;
4151 GCPRO1 (prop_value
);
4152 CHECK_STRING (prop
);
4154 if (! NILP (source
))
4156 if (NUMBERP (source
))
4158 if (FLOATP (source
))
4159 target_window
= (Window
) XFLOAT (source
);
4161 target_window
= XFASTINT (source
);
4163 if (target_window
== 0)
4164 target_window
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4166 else if (CONSP (source
))
4167 target_window
= cons_to_long (source
);
4173 if (strcmp ("AnyPropertyType", SDATA (type
)) == 0)
4174 target_type
= AnyPropertyType
;
4176 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (type
), False
);
4179 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4180 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4181 prop_atom
, 0, 0, False
, target_type
,
4182 &actual_type
, &actual_format
, &actual_size
,
4183 &bytes_remaining
, (unsigned char **) &tmp_data
);
4186 int size
= bytes_remaining
;
4191 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4192 prop_atom
, 0, bytes_remaining
,
4193 ! NILP (delete_p
), target_type
,
4194 &actual_type
, &actual_format
,
4195 &actual_size
, &bytes_remaining
,
4196 (unsigned char **) &tmp_data
);
4197 if (rc
== Success
&& tmp_data
)
4199 if (NILP (vector_ret_p
))
4200 prop_value
= make_string (tmp_data
, size
);
4202 prop_value
= x_property_data_to_lisp (f
,
4203 (unsigned char *) tmp_data
,
4209 if (tmp_data
) XFree (tmp_data
);
4219 /***********************************************************************
4221 ***********************************************************************/
4223 /* If non-null, an asynchronous timer that, when it expires, displays
4224 an hourglass cursor on all frames. */
4226 static struct atimer
*hourglass_atimer
;
4228 /* Non-zero means an hourglass cursor is currently shown. */
4230 static int hourglass_shown_p
;
4232 /* Number of seconds to wait before displaying an hourglass cursor. */
4234 static Lisp_Object Vhourglass_delay
;
4236 /* Default number of seconds to wait before displaying an hourglass
4239 #define DEFAULT_HOURGLASS_DELAY 1
4241 /* Function prototypes. */
4243 static void show_hourglass
P_ ((struct atimer
*));
4244 static void hide_hourglass
P_ ((void));
4247 /* Cancel a currently active hourglass timer, and start a new one. */
4253 int secs
, usecs
= 0;
4255 cancel_hourglass ();
4257 if (INTEGERP (Vhourglass_delay
)
4258 && XINT (Vhourglass_delay
) > 0)
4259 secs
= XFASTINT (Vhourglass_delay
);
4260 else if (FLOATP (Vhourglass_delay
)
4261 && XFLOAT_DATA (Vhourglass_delay
) > 0)
4264 tem
= Ftruncate (Vhourglass_delay
, Qnil
);
4265 secs
= XFASTINT (tem
);
4266 usecs
= (XFLOAT_DATA (Vhourglass_delay
) - secs
) * 1000000;
4269 secs
= DEFAULT_HOURGLASS_DELAY
;
4271 EMACS_SET_SECS_USECS (delay
, secs
, usecs
);
4272 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
4273 show_hourglass
, NULL
);
4277 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
4283 if (hourglass_atimer
)
4285 cancel_atimer (hourglass_atimer
);
4286 hourglass_atimer
= NULL
;
4289 if (hourglass_shown_p
)
4294 /* Timer function of hourglass_atimer. TIMER is equal to
4297 Display an hourglass pointer on all frames by mapping the frames'
4298 hourglass_window. Set the hourglass_p flag in the frames'
4299 output_data.x structure to indicate that an hourglass cursor is
4300 shown on the frames. */
4303 show_hourglass (timer
)
4304 struct atimer
*timer
;
4306 /* The timer implementation will cancel this timer automatically
4307 after this function has run. Set hourglass_atimer to null
4308 so that we know the timer doesn't have to be canceled. */
4309 hourglass_atimer
= NULL
;
4311 if (!hourglass_shown_p
)
4313 Lisp_Object rest
, frame
;
4317 FOR_EACH_FRAME (rest
, frame
)
4319 struct frame
*f
= XFRAME (frame
);
4321 if (FRAME_LIVE_P (f
) && FRAME_X_P (f
) && FRAME_X_DISPLAY (f
))
4323 Display
*dpy
= FRAME_X_DISPLAY (f
);
4325 #ifdef USE_X_TOOLKIT
4326 if (f
->output_data
.x
->widget
)
4328 if (FRAME_OUTER_WINDOW (f
))
4331 f
->output_data
.x
->hourglass_p
= 1;
4333 if (!f
->output_data
.x
->hourglass_window
)
4335 unsigned long mask
= CWCursor
;
4336 XSetWindowAttributes attrs
;
4338 attrs
.cursor
= f
->output_data
.x
->hourglass_cursor
;
4340 f
->output_data
.x
->hourglass_window
4341 = XCreateWindow (dpy
, FRAME_OUTER_WINDOW (f
),
4342 0, 0, 32000, 32000, 0, 0,
4348 XMapRaised (dpy
, f
->output_data
.x
->hourglass_window
);
4354 hourglass_shown_p
= 1;
4360 /* Hide the hourglass pointer on all frames, if it is currently
4366 if (hourglass_shown_p
)
4368 Lisp_Object rest
, frame
;
4371 FOR_EACH_FRAME (rest
, frame
)
4373 struct frame
*f
= XFRAME (frame
);
4376 /* Watch out for newly created frames. */
4377 && f
->output_data
.x
->hourglass_window
)
4379 XUnmapWindow (FRAME_X_DISPLAY (f
),
4380 f
->output_data
.x
->hourglass_window
);
4381 /* Sync here because XTread_socket looks at the
4382 hourglass_p flag that is reset to zero below. */
4383 XSync (FRAME_X_DISPLAY (f
), False
);
4384 f
->output_data
.x
->hourglass_p
= 0;
4388 hourglass_shown_p
= 0;
4395 /***********************************************************************
4397 ***********************************************************************/
4399 static Lisp_Object x_create_tip_frame
P_ ((struct x_display_info
*,
4400 Lisp_Object
, Lisp_Object
));
4401 static void compute_tip_xy
P_ ((struct frame
*, Lisp_Object
, Lisp_Object
,
4402 Lisp_Object
, int, int, int *, int *));
4404 /* The frame of a currently visible tooltip. */
4406 Lisp_Object tip_frame
;
4408 /* If non-nil, a timer started that hides the last tooltip when it
4411 Lisp_Object tip_timer
;
4414 /* If non-nil, a vector of 3 elements containing the last args
4415 with which x-show-tip was called. See there. */
4417 Lisp_Object last_show_tip_args
;
4419 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
4421 Lisp_Object Vx_max_tooltip_size
;
4425 unwind_create_tip_frame (frame
)
4428 Lisp_Object deleted
;
4430 deleted
= unwind_create_frame (frame
);
4431 if (EQ (deleted
, Qt
))
4441 /* Create a frame for a tooltip on the display described by DPYINFO.
4442 PARMS is a list of frame parameters. TEXT is the string to
4443 display in the tip frame. Value is the frame.
4445 Note that functions called here, esp. x_default_parameter can
4446 signal errors, for instance when a specified color name is
4447 undefined. We have to make sure that we're in a consistent state
4448 when this happens. */
4451 x_create_tip_frame (dpyinfo
, parms
, text
)
4452 struct x_display_info
*dpyinfo
;
4453 Lisp_Object parms
, text
;
4456 Lisp_Object frame
, tem
;
4458 long window_prompting
= 0;
4460 int count
= SPECPDL_INDEX ();
4461 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4463 int face_change_count_before
= face_change_count
;
4465 struct buffer
*old_buffer
;
4469 /* Use this general default value to start with until we know if
4470 this frame has a specified name. */
4471 Vx_resource_name
= Vinvocation_name
;
4474 kb
= dpyinfo
->kboard
;
4476 kb
= &the_only_kboard
;
4479 /* Get the name of the frame to use for resource lookup. */
4480 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
4482 && !EQ (name
, Qunbound
)
4484 error ("Invalid frame name--not a string or nil");
4485 Vx_resource_name
= name
;
4488 GCPRO3 (parms
, name
, frame
);
4490 XSETFRAME (frame
, f
);
4492 buffer
= Fget_buffer_create (build_string (" *tip*"));
4493 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
4494 old_buffer
= current_buffer
;
4495 set_buffer_internal_1 (XBUFFER (buffer
));
4496 current_buffer
->truncate_lines
= Qnil
;
4497 specbind (Qinhibit_read_only
, Qt
);
4498 specbind (Qinhibit_modification_hooks
, Qt
);
4501 set_buffer_internal_1 (old_buffer
);
4503 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
4504 record_unwind_protect (unwind_create_tip_frame
, frame
);
4506 f
->display
= dpyinfo
->frame_display
;
4507 f
->display
->reference_count
++;
4509 /* By setting the output method, we're essentially saying that
4510 the frame is live, as per FRAME_LIVE_P. If we get a signal
4511 from this point on, x_destroy_window might screw up reference
4513 f
->output_method
= output_x_window
;
4514 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
4515 bzero (f
->output_data
.x
, sizeof (struct x_output
));
4516 f
->output_data
.x
->icon_bitmap
= -1;
4517 FRAME_FONTSET (f
) = -1;
4518 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
4519 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
4520 #ifdef USE_TOOLKIT_SCROLL_BARS
4521 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
4522 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
4523 #endif /* USE_TOOLKIT_SCROLL_BARS */
4524 f
->icon_name
= Qnil
;
4525 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
4527 image_cache_refcount
= FRAME_X_IMAGE_CACHE (f
)->refcount
;
4528 dpyinfo_refcount
= dpyinfo
->reference_count
;
4529 #endif /* GLYPH_DEBUG */
4531 FRAME_KBOARD (f
) = kb
;
4533 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4534 f
->output_data
.x
->explicit_parent
= 0;
4536 /* These colors will be set anyway later, but it's important
4537 to get the color reference counts right, so initialize them! */
4540 struct gcpro gcpro1
;
4542 black
= build_string ("black");
4544 f
->output_data
.x
->foreground_pixel
4545 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4546 f
->output_data
.x
->background_pixel
4547 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4548 f
->output_data
.x
->cursor_pixel
4549 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4550 f
->output_data
.x
->cursor_foreground_pixel
4551 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4552 f
->output_data
.x
->border_pixel
4553 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4554 f
->output_data
.x
->mouse_pixel
4555 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4559 /* Set the name; the functions to which we pass f expect the name to
4561 if (EQ (name
, Qunbound
) || NILP (name
))
4563 f
->name
= build_string (dpyinfo
->x_id_name
);
4564 f
->explicit_name
= 0;
4569 f
->explicit_name
= 1;
4570 /* use the frame's title when getting resources for this frame. */
4571 specbind (Qx_resource_name
, name
);
4574 /* Extract the window parameters from the supplied values that are
4575 needed to determine window geometry. */
4579 font
= x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
4582 /* First, try whatever font the caller has specified. */
4585 tem
= Fquery_fontset (font
, Qnil
);
4587 font
= x_new_fontset (f
, SDATA (tem
));
4589 font
= x_new_font (f
, SDATA (font
));
4592 /* Try out a font which we hope has bold and italic variations. */
4593 if (!STRINGP (font
))
4594 font
= x_new_font (f
, "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1");
4595 if (!STRINGP (font
))
4596 font
= x_new_font (f
, "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
4597 if (! STRINGP (font
))
4598 font
= x_new_font (f
, "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1");
4599 if (! STRINGP (font
))
4600 /* This was formerly the first thing tried, but it finds too many fonts
4601 and takes too long. */
4602 font
= x_new_font (f
, "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1");
4603 /* If those didn't work, look for something which will at least work. */
4604 if (! STRINGP (font
))
4605 font
= x_new_font (f
, "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1");
4607 if (! STRINGP (font
))
4608 font
= build_string ("fixed");
4610 x_default_parameter (f
, parms
, Qfont
, font
,
4611 "font", "Font", RES_TYPE_STRING
);
4614 x_default_parameter (f
, parms
, Qborder_width
, make_number (2),
4615 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4617 /* This defaults to 2 in order to match xterm. We recognize either
4618 internalBorderWidth or internalBorder (which is what xterm calls
4620 if (NILP (Fassq (Qinternal_border_width
, parms
)))
4624 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
4625 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
4626 if (! EQ (value
, Qunbound
))
4627 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
4631 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
4632 "internalBorderWidth", "internalBorderWidth",
4635 /* Also do the stuff which must be set before the window exists. */
4636 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
4637 "foreground", "Foreground", RES_TYPE_STRING
);
4638 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
4639 "background", "Background", RES_TYPE_STRING
);
4640 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
4641 "pointerColor", "Foreground", RES_TYPE_STRING
);
4642 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
4643 "cursorColor", "Foreground", RES_TYPE_STRING
);
4644 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
4645 "borderColor", "BorderColor", RES_TYPE_STRING
);
4647 /* Init faces before x_default_parameter is called for scroll-bar
4648 parameters because that function calls x_set_scroll_bar_width,
4649 which calls change_frame_size, which calls Fset_window_buffer,
4650 which runs hooks, which call Fvertical_motion. At the end, we
4651 end up in init_iterator with a null face cache, which should not
4653 init_frame_faces (f
);
4655 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4657 window_prompting
= x_figure_window_size (f
, parms
, 0);
4660 XSetWindowAttributes attrs
;
4664 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
;
4665 if (DoesSaveUnders (dpyinfo
->screen
))
4666 mask
|= CWSaveUnder
;
4668 /* Window managers look at the override-redirect flag to determine
4669 whether or net to give windows a decoration (Xlib spec, chapter
4671 attrs
.override_redirect
= True
;
4672 attrs
.save_under
= True
;
4673 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
4674 /* Arrange for getting MapNotify and UnmapNotify events. */
4675 attrs
.event_mask
= StructureNotifyMask
;
4677 = FRAME_X_WINDOW (f
)
4678 = XCreateWindow (FRAME_X_DISPLAY (f
),
4679 FRAME_X_DISPLAY_INFO (f
)->root_window
,
4680 /* x, y, width, height */
4684 CopyFromParent
, InputOutput
, CopyFromParent
,
4691 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
4692 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4693 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
4694 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4695 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
4696 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4698 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4699 Change will not be effected unless different from the current
4701 width
= FRAME_COLS (f
);
4702 height
= FRAME_LINES (f
);
4703 SET_FRAME_COLS (f
, 0);
4704 FRAME_LINES (f
) = 0;
4705 change_frame_size (f
, height
, width
, 1, 0, 0);
4707 /* Add `tooltip' frame parameter's default value. */
4708 if (NILP (Fframe_parameter (frame
, intern ("tooltip"))))
4709 Fmodify_frame_parameters (frame
, Fcons (Fcons (intern ("tooltip"), Qt
),
4712 /* Set up faces after all frame parameters are known. This call
4713 also merges in face attributes specified for new frames.
4715 Frame parameters may be changed if .Xdefaults contains
4716 specifications for the default font. For example, if there is an
4717 `Emacs.default.attributeBackground: pink', the `background-color'
4718 attribute of the frame get's set, which let's the internal border
4719 of the tooltip frame appear in pink. Prevent this. */
4721 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
4723 /* Set tip_frame here, so that */
4725 call1 (Qface_set_after_frame_default
, frame
);
4727 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
4728 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
4732 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qwindow_system
, Qx
), Qnil
));
4738 /* It is now ok to make the frame official even if we get an error
4739 below. And the frame needs to be on Vframe_list or making it
4740 visible won't work. */
4741 Vframe_list
= Fcons (frame
, Vframe_list
);
4743 /* Now that the frame is official, it counts as a reference to
4745 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
4747 /* Setting attributes of faces of the tooltip frame from resources
4748 and similar will increment face_change_count, which leads to the
4749 clearing of all current matrices. Since this isn't necessary
4750 here, avoid it by resetting face_change_count to the value it
4751 had before we created the tip frame. */
4752 face_change_count
= face_change_count_before
;
4754 /* Discard the unwind_protect. */
4755 return unbind_to (count
, frame
);
4759 /* Compute where to display tip frame F. PARMS is the list of frame
4760 parameters for F. DX and DY are specified offsets from the current
4761 location of the mouse. WIDTH and HEIGHT are the width and height
4762 of the tooltip. Return coordinates relative to the root window of
4763 the display in *ROOT_X, and *ROOT_Y. */
4766 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, root_x
, root_y
)
4768 Lisp_Object parms
, dx
, dy
;
4770 int *root_x
, *root_y
;
4772 Lisp_Object left
, top
;
4777 /* User-specified position? */
4778 left
= Fcdr (Fassq (Qleft
, parms
));
4779 top
= Fcdr (Fassq (Qtop
, parms
));
4781 /* Move the tooltip window where the mouse pointer is. Resize and
4783 if (!INTEGERP (left
) || !INTEGERP (top
))
4786 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
4787 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
4792 *root_y
= XINT (top
);
4793 else if (*root_y
+ XINT (dy
) - height
< 0)
4794 *root_y
-= XINT (dy
);
4798 *root_y
+= XINT (dy
);
4801 if (INTEGERP (left
))
4802 *root_x
= XINT (left
);
4803 else if (*root_x
+ XINT (dx
) + width
<= FRAME_X_DISPLAY_INFO (f
)->width
)
4804 /* It fits to the right of the pointer. */
4805 *root_x
+= XINT (dx
);
4806 else if (width
+ XINT (dx
) <= *root_x
)
4807 /* It fits to the left of the pointer. */
4808 *root_x
-= width
+ XINT (dx
);
4810 /* Put it left-justified on the screen--it ought to fit that way. */
4815 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
4816 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
4817 A tooltip window is a small X window displaying a string.
4819 FRAME nil or omitted means use the selected frame.
4821 PARMS is an optional list of frame parameters which can be used to
4822 change the tooltip's appearance.
4824 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
4825 means use the default timeout of 5 seconds.
4827 If the list of frame parameters PARAMS contains a `left' parameters,
4828 the tooltip is displayed at that x-position. Otherwise it is
4829 displayed at the mouse position, with offset DX added (default is 5 if
4830 DX isn't specified). Likewise for the y-position; if a `top' frame
4831 parameter is specified, it determines the y-position of the tooltip
4832 window, otherwise it is displayed at the mouse position, with offset
4833 DY added (default is -10).
4835 A tooltip's maximum size is specified by `x-max-tooltip-size'.
4836 Text larger than the specified size is clipped. */)
4837 (string
, frame
, parms
, timeout
, dx
, dy
)
4838 Lisp_Object string
, frame
, parms
, timeout
, dx
, dy
;
4843 struct buffer
*old_buffer
;
4844 struct text_pos pos
;
4845 int i
, width
, height
;
4846 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4847 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
4848 int count
= SPECPDL_INDEX ();
4850 specbind (Qinhibit_redisplay
, Qt
);
4852 GCPRO4 (string
, parms
, frame
, timeout
);
4854 CHECK_STRING (string
);
4855 f
= check_x_frame (frame
);
4857 timeout
= make_number (5);
4859 CHECK_NATNUM (timeout
);
4862 dx
= make_number (5);
4867 dy
= make_number (-10);
4871 if (NILP (last_show_tip_args
))
4872 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
4874 if (!NILP (tip_frame
))
4876 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
4877 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
4878 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
4880 if (EQ (frame
, last_frame
)
4881 && !NILP (Fequal (last_string
, string
))
4882 && !NILP (Fequal (last_parms
, parms
)))
4884 struct frame
*f
= XFRAME (tip_frame
);
4886 /* Only DX and DY have changed. */
4887 if (!NILP (tip_timer
))
4889 Lisp_Object timer
= tip_timer
;
4891 call1 (Qcancel_timer
, timer
);
4895 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
4896 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
4897 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4904 /* Hide a previous tip, if any. */
4907 ASET (last_show_tip_args
, 0, string
);
4908 ASET (last_show_tip_args
, 1, frame
);
4909 ASET (last_show_tip_args
, 2, parms
);
4911 /* Add default values to frame parameters. */
4912 if (NILP (Fassq (Qname
, parms
)))
4913 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
4914 if (NILP (Fassq (Qinternal_border_width
, parms
)))
4915 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
4916 if (NILP (Fassq (Qborder_width
, parms
)))
4917 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
4918 if (NILP (Fassq (Qborder_color
, parms
)))
4919 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
4920 if (NILP (Fassq (Qbackground_color
, parms
)))
4921 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
4924 /* Create a frame for the tooltip, and record it in the global
4925 variable tip_frame. */
4926 frame
= x_create_tip_frame (FRAME_X_DISPLAY_INFO (f
), parms
, string
);
4929 /* Set up the frame's root window. */
4930 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4931 w
->left_col
= w
->top_line
= make_number (0);
4933 if (CONSP (Vx_max_tooltip_size
)
4934 && INTEGERP (XCAR (Vx_max_tooltip_size
))
4935 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
4936 && INTEGERP (XCDR (Vx_max_tooltip_size
))
4937 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
4939 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
4940 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
4944 w
->total_cols
= make_number (80);
4945 w
->total_lines
= make_number (40);
4948 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
4950 w
->pseudo_window_p
= 1;
4952 /* Display the tooltip text in a temporary buffer. */
4953 old_buffer
= current_buffer
;
4954 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
4955 current_buffer
->truncate_lines
= Qnil
;
4956 clear_glyph_matrix (w
->desired_matrix
);
4957 clear_glyph_matrix (w
->current_matrix
);
4958 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
4959 try_window (FRAME_ROOT_WINDOW (f
), pos
);
4961 /* Compute width and height of the tooltip. */
4963 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
4965 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
4969 /* Stop at the first empty row at the end. */
4970 if (!row
->enabled_p
|| !row
->displays_text_p
)
4973 /* Let the row go over the full width of the frame. */
4974 row
->full_width_p
= 1;
4976 /* There's a glyph at the end of rows that is used to place
4977 the cursor there. Don't include the width of this glyph. */
4978 if (row
->used
[TEXT_AREA
])
4980 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
4981 row_width
= row
->pixel_width
- last
->pixel_width
;
4984 row_width
= row
->pixel_width
;
4986 height
+= row
->height
;
4987 width
= max (width
, row_width
);
4990 /* Add the frame's internal border to the width and height the X
4991 window should have. */
4992 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
4993 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
4995 /* Move the tooltip window where the mouse pointer is. Resize and
4997 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5000 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5001 root_x
, root_y
, width
, height
);
5002 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5005 /* Draw into the window. */
5006 w
->must_be_updated_p
= 1;
5007 update_single_window (w
, 1);
5009 /* Restore original current buffer. */
5010 set_buffer_internal_1 (old_buffer
);
5011 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5014 /* Let the tip disappear after timeout seconds. */
5015 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5016 intern ("x-hide-tip"));
5019 return unbind_to (count
, Qnil
);
5023 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5024 doc
: /* Hide the current tooltip window, if there is any.
5025 Value is t if tooltip was open, nil otherwise. */)
5029 Lisp_Object deleted
, frame
, timer
;
5030 struct gcpro gcpro1
, gcpro2
;
5032 /* Return quickly if nothing to do. */
5033 if (NILP (tip_timer
) && NILP (tip_frame
))
5038 GCPRO2 (frame
, timer
);
5039 tip_frame
= tip_timer
= deleted
= Qnil
;
5041 count
= SPECPDL_INDEX ();
5042 specbind (Qinhibit_redisplay
, Qt
);
5043 specbind (Qinhibit_quit
, Qt
);
5046 call1 (Qcancel_timer
, timer
);
5050 Fdelete_frame (frame
, Qnil
);
5054 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5055 redisplay procedure is not called when a tip frame over menu
5056 items is unmapped. Redisplay the menu manually... */
5058 struct frame
*f
= SELECTED_FRAME ();
5059 Widget w
= f
->output_data
.x
->menubar_widget
;
5060 extern void xlwmenu_redisplay
P_ ((Widget
));
5062 if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f
)->screen
)
5066 xlwmenu_redisplay (w
);
5070 #endif /* USE_LUCID */
5074 return unbind_to (count
, deleted
);
5079 /***********************************************************************
5080 File selection dialog
5081 ***********************************************************************/
5085 /* Callback for "OK" and "Cancel" on file selection dialog. */
5088 file_dialog_cb (widget
, client_data
, call_data
)
5090 XtPointer call_data
, client_data
;
5092 int *result
= (int *) client_data
;
5093 XmAnyCallbackStruct
*cb
= (XmAnyCallbackStruct
*) call_data
;
5094 *result
= cb
->reason
;
5098 /* Callback for unmapping a file selection dialog. This is used to
5099 capture the case where a dialog is closed via a window manager's
5100 closer button, for example. Using a XmNdestroyCallback didn't work
5104 file_dialog_unmap_cb (widget
, client_data
, call_data
)
5106 XtPointer call_data
, client_data
;
5108 int *result
= (int *) client_data
;
5109 *result
= XmCR_CANCEL
;
5113 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
5114 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5115 Use a file selection dialog.
5116 Select DEFAULT-FILENAME in the dialog's file selection box, if
5117 specified. Don't let the user enter a file name in the file
5118 selection dialog's entry field, if MUSTMATCH is non-nil. */)
5119 (prompt
, dir
, default_filename
, mustmatch
)
5120 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
5123 struct frame
*f
= SELECTED_FRAME ();
5124 Lisp_Object file
= Qnil
;
5125 Widget dialog
, text
, list
, help
;
5128 extern XtAppContext Xt_app_con
;
5129 XmString dir_xmstring
, pattern_xmstring
;
5130 int count
= SPECPDL_INDEX ();
5131 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
5133 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
5134 CHECK_STRING (prompt
);
5137 /* Prevent redisplay. */
5138 specbind (Qinhibit_redisplay
, Qt
);
5142 /* Create the dialog with PROMPT as title, using DIR as initial
5143 directory and using "*" as pattern. */
5144 dir
= Fexpand_file_name (dir
, Qnil
);
5145 dir_xmstring
= XmStringCreateLocalized (SDATA (dir
));
5146 pattern_xmstring
= XmStringCreateLocalized ("*");
5148 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
5149 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
5150 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
5151 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
5152 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
5153 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
5155 XmStringFree (dir_xmstring
);
5156 XmStringFree (pattern_xmstring
);
5158 /* Add callbacks for OK and Cancel. */
5159 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
5160 (XtPointer
) &result
);
5161 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
5162 (XtPointer
) &result
);
5163 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
5164 (XtPointer
) &result
);
5166 /* Disable the help button since we can't display help. */
5167 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
5168 XtSetSensitive (help
, False
);
5170 /* Mark OK button as default. */
5171 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
5172 XmNshowAsDefault
, True
, NULL
);
5174 /* If MUSTMATCH is non-nil, disable the file entry field of the
5175 dialog, so that the user must select a file from the files list
5176 box. We can't remove it because we wouldn't have a way to get at
5177 the result file name, then. */
5178 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5179 if (!NILP (mustmatch
))
5182 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
5183 XtSetSensitive (text
, False
);
5184 XtSetSensitive (label
, False
);
5187 /* Manage the dialog, so that list boxes get filled. */
5188 XtManageChild (dialog
);
5190 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5191 must include the path for this to work. */
5192 list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
5193 if (STRINGP (default_filename
))
5195 XmString default_xmstring
;
5199 = XmStringCreateLocalized (SDATA (default_filename
));
5201 if (!XmListItemExists (list
, default_xmstring
))
5203 /* Add a new item if DEFAULT_FILENAME is not in the list. */
5204 XmListAddItem (list
, default_xmstring
, 0);
5208 item_pos
= XmListItemPos (list
, default_xmstring
);
5209 XmStringFree (default_xmstring
);
5211 /* Select the item and scroll it into view. */
5212 XmListSelectPos (list
, item_pos
, True
);
5213 XmListSetPos (list
, item_pos
);
5216 /* Process events until the user presses Cancel or OK. */
5221 XtAppNextEvent (Xt_app_con
, &event
);
5222 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
) );
5225 /* Get the result. */
5226 if (result
== XmCR_OK
)
5231 XtVaGetValues (dialog
, XmNtextString
, &text
, NULL
);
5232 XmStringGetLtoR (text
, XmFONTLIST_DEFAULT_TAG
, &data
);
5233 XmStringFree (text
);
5234 file
= build_string (data
);
5241 XtUnmanageChild (dialog
);
5242 XtDestroyWidget (dialog
);
5246 /* Make "Cancel" equivalent to C-g. */
5248 Fsignal (Qquit
, Qnil
);
5250 return unbind_to (count
, file
);
5253 #endif /* USE_MOTIF */
5257 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 4, 0,
5258 "Read file name, prompting with PROMPT in directory DIR.\n\
5259 Use a file selection dialog.\n\
5260 Select DEFAULT-FILENAME in the dialog's file selection box, if\n\
5261 specified. Don't let the user enter a file name in the file\n\
5262 selection dialog's entry field, if MUSTMATCH is non-nil.")
5263 (prompt
, dir
, default_filename
, mustmatch
)
5264 Lisp_Object prompt
, dir
, default_filename
, mustmatch
;
5266 FRAME_PTR f
= SELECTED_FRAME ();
5268 Lisp_Object file
= Qnil
;
5269 int count
= specpdl_ptr
- specpdl
;
5270 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
5273 GCPRO5 (prompt
, dir
, default_filename
, mustmatch
, file
);
5274 CHECK_STRING (prompt
);
5277 /* Prevent redisplay. */
5278 specbind (Qinhibit_redisplay
, Qt
);
5282 if (STRINGP (default_filename
))
5283 cdef_file
= SDATA (default_filename
);
5285 cdef_file
= SDATA (dir
);
5287 fn
= xg_get_file_name (f
, SDATA (prompt
), cdef_file
, ! NILP (mustmatch
));
5291 file
= build_string (fn
);
5298 /* Make "Cancel" equivalent to C-g. */
5300 Fsignal (Qquit
, Qnil
);
5302 return unbind_to (count
, file
);
5305 #endif /* USE_GTK */
5308 /***********************************************************************
5310 ***********************************************************************/
5312 #ifdef HAVE_XKBGETKEYBOARD
5313 #include <X11/XKBlib.h>
5314 #include <X11/keysym.h>
5317 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
5318 Sx_backspace_delete_keys_p
, 0, 1, 0,
5319 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
5320 FRAME nil means use the selected frame.
5321 Value is t if we know that both keys are present, and are mapped to the
5322 usual X keysyms. */)
5326 #ifdef HAVE_XKBGETKEYBOARD
5328 struct frame
*f
= check_x_frame (frame
);
5329 Display
*dpy
= FRAME_X_DISPLAY (f
);
5330 Lisp_Object have_keys
;
5331 int major
, minor
, op
, event
, error
;
5335 /* Check library version in case we're dynamically linked. */
5336 major
= XkbMajorVersion
;
5337 minor
= XkbMinorVersion
;
5338 if (!XkbLibraryVersion (&major
, &minor
))
5344 /* Check that the server supports XKB. */
5345 major
= XkbMajorVersion
;
5346 minor
= XkbMinorVersion
;
5347 if (!XkbQueryExtension (dpy
, &op
, &event
, &error
, &major
, &minor
))
5354 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
5357 int delete_keycode
= 0, backspace_keycode
= 0, i
;
5359 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
5361 for (i
= kb
->min_key_code
;
5362 (i
< kb
->max_key_code
5363 && (delete_keycode
== 0 || backspace_keycode
== 0));
5366 /* The XKB symbolic key names can be seen most easily in
5367 the PS file generated by `xkbprint -label name
5369 if (bcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
5371 else if (bcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
5372 backspace_keycode
= i
;
5375 XkbFreeNames (kb
, 0, True
);
5378 XkbFreeClientMap (kb
, 0, True
);
5381 && backspace_keycode
5382 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
5383 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
5388 #else /* not HAVE_XKBGETKEYBOARD */
5390 #endif /* not HAVE_XKBGETKEYBOARD */
5395 /***********************************************************************
5397 ***********************************************************************/
5399 /* Keep this list in the same order as frame_parms in frame.c.
5400 Use 0 for unsupported frame parameters. */
5402 frame_parm_handler x_frame_parm_handlers
[] =
5406 x_set_background_color
,
5412 x_set_foreground_color
,
5415 x_set_internal_border_width
,
5416 x_set_menu_bar_lines
,
5418 x_explicitly_set_name
,
5419 x_set_scroll_bar_width
,
5422 x_set_vertical_scroll_bars
,
5424 x_set_tool_bar_lines
,
5425 x_set_scroll_bar_foreground
,
5426 x_set_scroll_bar_background
,
5438 /* This is zero if not using X windows. */
5441 /* The section below is built by the lisp expression at the top of the file,
5442 just above where these variables are declared. */
5443 /*&&& init symbols here &&&*/
5444 Qnone
= intern ("none");
5446 Qsuppress_icon
= intern ("suppress-icon");
5447 staticpro (&Qsuppress_icon
);
5448 Qundefined_color
= intern ("undefined-color");
5449 staticpro (&Qundefined_color
);
5450 Qcompound_text
= intern ("compound-text");
5451 staticpro (&Qcompound_text
);
5452 Qcancel_timer
= intern ("cancel-timer");
5453 staticpro (&Qcancel_timer
);
5454 /* This is the end of symbol initialization. */
5456 /* Text property `display' should be nonsticky by default. */
5457 Vtext_property_default_nonsticky
5458 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
5461 Fput (Qundefined_color
, Qerror_conditions
,
5462 Fcons (Qundefined_color
, Fcons (Qerror
, Qnil
)));
5463 Fput (Qundefined_color
, Qerror_message
,
5464 build_string ("Undefined color"));
5466 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
5467 doc
: /* The shape of the pointer when over text.
5468 Changing the value does not affect existing frames
5469 unless you set the mouse color. */);
5470 Vx_pointer_shape
= Qnil
;
5472 #if 0 /* This doesn't really do anything. */
5473 DEFVAR_LISP ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape
,
5474 doc
: /* The shape of the pointer when not over text.
5475 This variable takes effect when you create a new frame
5476 or when you set the mouse color. */);
5478 Vx_nontext_pointer_shape
= Qnil
;
5480 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
5481 doc
: /* The shape of the pointer when Emacs is busy.
5482 This variable takes effect when you create a new frame
5483 or when you set the mouse color. */);
5484 Vx_hourglass_pointer_shape
= Qnil
;
5486 DEFVAR_BOOL ("display-hourglass", &display_hourglass_p
,
5487 doc
: /* Non-zero means Emacs displays an hourglass pointer on window systems. */);
5488 display_hourglass_p
= 1;
5490 DEFVAR_LISP ("hourglass-delay", &Vhourglass_delay
,
5491 doc
: /* *Seconds to wait before displaying an hourglass pointer.
5492 Value must be an integer or float. */);
5493 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
5495 #if 0 /* This doesn't really do anything. */
5496 DEFVAR_LISP ("x-mode-pointer-shape", &Vx_mode_pointer_shape
,
5497 doc
: /* The shape of the pointer when over the mode line.
5498 This variable takes effect when you create a new frame
5499 or when you set the mouse color. */);
5501 Vx_mode_pointer_shape
= Qnil
;
5503 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
5504 &Vx_sensitive_text_pointer_shape
,
5505 doc
: /* The shape of the pointer when over mouse-sensitive text.
5506 This variable takes effect when you create a new frame
5507 or when you set the mouse color. */);
5508 Vx_sensitive_text_pointer_shape
= Qnil
;
5510 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
5511 &Vx_window_horizontal_drag_shape
,
5512 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
5513 This variable takes effect when you create a new frame
5514 or when you set the mouse color. */);
5515 Vx_window_horizontal_drag_shape
= Qnil
;
5517 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
5518 doc
: /* A string indicating the foreground color of the cursor box. */);
5519 Vx_cursor_fore_pixel
= Qnil
;
5521 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
5522 doc
: /* Maximum size for tooltips. Value is a pair (COLUMNS . ROWS).
5523 Text larger than this is clipped. */);
5524 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
5526 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
5527 doc
: /* Non-nil if no X window manager is in use.
5528 Emacs doesn't try to figure this out; this is always nil
5529 unless you set it to something else. */);
5530 /* We don't have any way to find this out, so set it to nil
5531 and maybe the user would like to set it to t. */
5532 Vx_no_window_manager
= Qnil
;
5534 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
5535 &Vx_pixel_size_width_font_regexp
,
5536 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
5538 Since Emacs gets width of a font matching with this regexp from
5539 PIXEL_SIZE field of the name, font finding mechanism gets faster for
5540 such a font. This is especially effective for such large fonts as
5541 Chinese, Japanese, and Korean. */);
5542 Vx_pixel_size_width_font_regexp
= Qnil
;
5544 #ifdef USE_X_TOOLKIT
5545 Fprovide (intern ("x-toolkit"), Qnil
);
5547 Fprovide (intern ("motif"), Qnil
);
5549 DEFVAR_LISP ("motif-version-string", &Vmotif_version_string
,
5550 doc
: /* Version info for LessTif/Motif. */);
5551 Vmotif_version_string
= build_string (XmVERSION_STRING
);
5552 #endif /* USE_MOTIF */
5553 #endif /* USE_X_TOOLKIT */
5556 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
5557 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
5558 But for a user it is a toolkit for X, and indeed, configure
5559 accepts --with-x-toolkit=gtk. */
5560 Fprovide (intern ("x-toolkit"), Qnil
);
5561 Fprovide (intern ("gtk"), Qnil
);
5563 DEFVAR_LISP ("gtk-version-string", &Vgtk_version_string
,
5564 doc
: /* Version info for GTK+. */);
5566 char gtk_version
[40];
5567 g_snprintf (gtk_version
, sizeof (gtk_version
), "%u.%u.%u",
5568 GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
);
5569 Vgtk_version_string
= build_string (gtk_version
);
5571 #endif /* USE_GTK */
5573 /* X window properties. */
5574 defsubr (&Sx_change_window_property
);
5575 defsubr (&Sx_delete_window_property
);
5576 defsubr (&Sx_window_property
);
5578 defsubr (&Sxw_display_color_p
);
5579 defsubr (&Sx_display_grayscale_p
);
5580 defsubr (&Sxw_color_defined_p
);
5581 defsubr (&Sxw_color_values
);
5582 defsubr (&Sx_server_max_request_size
);
5583 defsubr (&Sx_server_vendor
);
5584 defsubr (&Sx_server_version
);
5585 defsubr (&Sx_display_pixel_width
);
5586 defsubr (&Sx_display_pixel_height
);
5587 defsubr (&Sx_display_mm_width
);
5588 defsubr (&Sx_display_mm_height
);
5589 defsubr (&Sx_display_screens
);
5590 defsubr (&Sx_display_planes
);
5591 defsubr (&Sx_display_color_cells
);
5592 defsubr (&Sx_display_visual_class
);
5593 defsubr (&Sx_display_backing_store
);
5594 defsubr (&Sx_display_save_under
);
5595 defsubr (&Sx_create_frame
);
5596 defsubr (&Sx_open_connection
);
5597 defsubr (&Sx_close_connection
);
5598 defsubr (&Sx_display_list
);
5599 defsubr (&Sx_synchronize
);
5600 defsubr (&Sx_focus_frame
);
5601 defsubr (&Sx_backspace_delete_keys_p
);
5603 /* Setting callback functions for fontset handler. */
5604 get_font_info_func
= x_get_font_info
;
5606 #if 0 /* This function pointer doesn't seem to be used anywhere.
5607 And the pointer assigned has the wrong type, anyway. */
5608 list_fonts_func
= x_list_fonts
;
5611 load_font_func
= x_load_font
;
5612 find_ccl_program_func
= x_find_ccl_program
;
5613 query_font_func
= x_query_font
;
5614 set_frame_fontset_func
= x_set_font
;
5615 check_window_system_func
= check_x
;
5617 hourglass_atimer
= NULL
;
5618 hourglass_shown_p
= 0;
5620 defsubr (&Sx_show_tip
);
5621 defsubr (&Sx_hide_tip
);
5623 staticpro (&tip_timer
);
5625 staticpro (&tip_frame
);
5627 last_show_tip_args
= Qnil
;
5628 staticpro (&last_show_tip_args
);
5631 defsubr (&Sx_file_dialog
);
5635 #endif /* HAVE_X_WINDOWS */
5637 /* arch-tag: 55040d02-5485-4d58-8b22-95a7a05f3288
5638 (do not change this comment) */