1 /* Functions for the X window system.
3 Copyright (C) 1989, 1992-2012 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>. */
26 /* This makes the fields of a Display accessible, in Xlib header files. */
28 #define XLIB_ILLEGAL_ACCESS
34 #include "character.h"
36 #include "intervals.h"
37 #include "dispextern.h"
39 #include "blockinput.h"
45 #include "termhooks.h"
52 #include <sys/types.h>
55 #if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */
56 #include "bitmaps/gray.xbm"
58 #include <X11/bitmaps/gray>
61 #include "xsettings.h"
68 #include <X11/Shell.h>
72 #include <X11/Xaw3d/Paned.h>
73 #include <X11/Xaw3d/Label.h>
74 #else /* !HAVE_XAW3D */
75 #include <X11/Xaw/Paned.h>
76 #include <X11/Xaw/Label.h>
77 #endif /* HAVE_XAW3D */
78 #endif /* USE_MOTIF */
81 #undef USG /* ####KLUDGE for Solaris 2.2 and up */
84 #ifdef USG /* Pacify gcc -Wunused-macros. */
92 #include "../lwlib/lwlib.h"
96 #include <Xm/DialogS.h>
97 #include <Xm/FileSB.h>
103 #include "../lwlib/xlwmenu.h"
106 #if !defined (NO_EDITRES)
108 extern void _XEditResCheckMessages (Widget
, XtPointer
, XEvent
*, Boolean
*);
109 #endif /* not defined NO_EDITRES */
111 /* Unique id counter for widgets created by the Lucid Widget Library. */
113 extern LWLIB_ID widget_id_tick
;
117 #endif /* USE_MOTIF */
119 #endif /* USE_X_TOOLKIT */
125 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
127 /* Nonzero if using X. */
131 static Lisp_Object Qsuppress_icon
;
132 static Lisp_Object Qundefined_color
;
133 static Lisp_Object Qcompound_text
, Qcancel_timer
;
134 Lisp_Object Qfont_param
;
137 static ptrdiff_t image_cache_refcount
;
138 static int dpyinfo_refcount
;
141 static struct x_display_info
*x_display_info_for_name (Lisp_Object
);
144 /* Error if we are not connected to X. */
150 error ("X windows are not in use or not initialized");
153 /* Nonzero if we can use mouse menus.
154 You should not call this unless HAVE_MENUS is defined. */
162 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
163 and checking validity for X. */
166 check_x_frame (Lisp_Object frame
)
171 frame
= selected_frame
;
172 CHECK_LIVE_FRAME (frame
);
175 error ("Non-X frame used");
179 /* Let the user specify an X display with a Lisp object.
180 OBJECT may be nil, a frame or a terminal object.
181 nil stands for the selected frame--or, if that is not an X frame,
182 the first X display on the list. */
184 struct x_display_info
*
185 check_x_display_info (Lisp_Object object
)
187 struct x_display_info
*dpyinfo
= NULL
;
191 struct frame
*sf
= XFRAME (selected_frame
);
193 if (FRAME_X_P (sf
) && FRAME_LIVE_P (sf
))
194 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
195 else if (x_display_list
!= 0)
196 dpyinfo
= x_display_list
;
198 error ("X windows are not in use or not initialized");
200 else if (TERMINALP (object
))
202 struct terminal
*t
= get_terminal (object
, 1);
204 if (t
->type
!= output_x_window
)
205 error ("Terminal %"pI
"d is not an X display", XINT (object
));
207 dpyinfo
= t
->display_info
.x
;
209 else if (STRINGP (object
))
210 dpyinfo
= x_display_info_for_name (object
);
213 FRAME_PTR f
= check_x_frame (object
);
214 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
221 /* Return the Emacs frame-object corresponding to an X window.
222 It could be the frame's main window or an icon window. */
224 /* This function can be called during GC, so use GC_xxx type test macros. */
227 x_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
229 Lisp_Object tail
, frame
;
232 if (wdesc
== None
) return 0;
234 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
240 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
242 if (f
->output_data
.x
->hourglass_window
== wdesc
)
245 if ((f
->output_data
.x
->edit_widget
246 && XtWindow (f
->output_data
.x
->edit_widget
) == wdesc
)
247 /* A tooltip frame? */
248 || (!f
->output_data
.x
->edit_widget
249 && FRAME_X_WINDOW (f
) == wdesc
)
250 || f
->output_data
.x
->icon_desc
== wdesc
)
252 #else /* not USE_X_TOOLKIT */
254 if (f
->output_data
.x
->edit_widget
)
256 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
257 struct x_output
*x
= f
->output_data
.x
;
258 if (gwdesc
!= 0 && gwdesc
== x
->edit_widget
)
262 if (FRAME_X_WINDOW (f
) == wdesc
263 || f
->output_data
.x
->icon_desc
== wdesc
)
265 #endif /* not USE_X_TOOLKIT */
270 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
271 /* Like x_window_to_frame but also compares the window with the widget's
275 x_any_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
277 Lisp_Object tail
, frame
;
278 struct frame
*f
, *found
;
281 if (wdesc
== None
) return NULL
;
284 for (tail
= Vframe_list
; CONSP (tail
) && !found
; tail
= XCDR (tail
))
291 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
293 /* This frame matches if the window is any of its widgets. */
294 x
= f
->output_data
.x
;
295 if (x
->hourglass_window
== wdesc
)
300 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
302 && gtk_widget_get_toplevel (gwdesc
) == x
->widget
)
305 if (wdesc
== XtWindow (x
->widget
)
306 || wdesc
== XtWindow (x
->column_widget
)
307 || wdesc
== XtWindow (x
->edit_widget
))
309 /* Match if the window is this frame's menubar. */
310 else if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
314 else if (FRAME_X_WINDOW (f
) == wdesc
)
315 /* A tooltip frame. */
323 /* Likewise, but consider only the menu bar widget. */
326 x_menubar_window_to_frame (struct x_display_info
*dpyinfo
, XEvent
*event
)
328 Window wdesc
= event
->xany
.window
;
329 Lisp_Object tail
, frame
;
333 if (wdesc
== None
) return 0;
335 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
341 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
343 x
= f
->output_data
.x
;
345 if (x
->menubar_widget
&& xg_event_is_for_menubar (f
, event
))
348 /* Match if the window is this frame's menubar. */
349 if (x
->menubar_widget
350 && lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
357 /* Return the frame whose principal (outermost) window is WDESC.
358 If WDESC is some other (smaller) window, we return 0. */
361 x_top_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
363 Lisp_Object tail
, frame
;
367 if (wdesc
== None
) return 0;
369 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
375 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
377 x
= f
->output_data
.x
;
381 /* This frame matches if the window is its topmost widget. */
383 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
384 if (gwdesc
== x
->widget
)
387 if (wdesc
== XtWindow (x
->widget
))
389 #if 0 /* I don't know why it did this,
390 but it seems logically wrong,
391 and it causes trouble for MapNotify events. */
392 /* Match if the window is this frame's menubar. */
393 if (x
->menubar_widget
394 && wdesc
== XtWindow (x
->menubar_widget
))
399 else if (FRAME_X_WINDOW (f
) == wdesc
)
405 #endif /* USE_X_TOOLKIT || USE_GTK */
409 /* Store the screen positions of frame F into XPTR and YPTR.
410 These are the positions of the containing window manager window,
411 not Emacs's own window. */
414 x_real_positions (FRAME_PTR f
, int *xptr
, int *yptr
)
416 int win_x
, win_y
, outer_x
IF_LINT (= 0), outer_y
IF_LINT (= 0);
417 int real_x
= 0, real_y
= 0;
419 Window win
= f
->output_data
.x
->parent_desc
;
421 unsigned long actual_size
, bytes_remaining
;
422 int rc
, actual_format
;
423 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
425 Display
*dpy
= FRAME_X_DISPLAY (f
);
426 unsigned char *tmp_data
= NULL
;
427 Atom target_type
= XA_CARDINAL
;
431 x_catch_errors (dpy
);
433 if (win
== dpyinfo
->root_window
)
434 win
= FRAME_OUTER_WINDOW (f
);
436 /* This loop traverses up the containment tree until we hit the root
437 window. Window managers may intersect many windows between our window
438 and the root window. The window we find just before the root window
439 should be the outer WM window. */
442 Window wm_window
, rootw
;
443 Window
*tmp_children
;
444 unsigned int tmp_nchildren
;
447 success
= XQueryTree (FRAME_X_DISPLAY (f
), win
, &rootw
,
448 &wm_window
, &tmp_children
, &tmp_nchildren
);
450 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
452 /* Don't free tmp_children if XQueryTree failed. */
456 XFree (tmp_children
);
458 if (wm_window
== rootw
|| had_errors
)
469 /* Get the real coordinates for the WM window upper left corner */
470 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
471 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
473 /* Translate real coordinates to coordinates relative to our
474 window. For our window, the upper left corner is 0, 0.
475 Since the upper left corner of the WM window is outside
476 our window, win_x and win_y will be negative:
478 ------------------ ---> x
480 | ----------------- v y
483 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
485 /* From-window, to-window. */
486 FRAME_X_DISPLAY_INFO (f
)->root_window
,
489 /* From-position, to-position. */
490 real_x
, real_y
, &win_x
, &win_y
,
495 if (FRAME_X_WINDOW (f
) == FRAME_OUTER_WINDOW (f
))
502 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
504 /* From-window, to-window. */
505 FRAME_X_DISPLAY_INFO (f
)->root_window
,
506 FRAME_OUTER_WINDOW (f
),
508 /* From-position, to-position. */
509 real_x
, real_y
, &outer_x
, &outer_y
,
515 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
519 if (dpyinfo
->root_window
== f
->output_data
.x
->parent_desc
)
521 /* Try _NET_FRAME_EXTENTS if our parent is the root window. */
522 rc
= XGetWindowProperty (dpy
, win
, dpyinfo
->Xatom_net_frame_extents
,
523 0, max_len
, False
, target_type
,
524 &actual_type
, &actual_format
, &actual_size
,
525 &bytes_remaining
, &tmp_data
);
527 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
528 && actual_size
== 4 && actual_format
== 32)
532 long *fe
= (long *)tmp_data
;
534 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
535 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
543 if (tmp_data
) XFree (tmp_data
);
549 if (had_errors
) return;
551 f
->x_pixels_diff
= -win_x
;
552 f
->y_pixels_diff
= -win_y
;
554 FRAME_X_OUTPUT (f
)->x_pixels_outer_diff
= -outer_x
;
555 FRAME_X_OUTPUT (f
)->y_pixels_outer_diff
= -outer_y
;
564 /* Gamma-correct COLOR on frame F. */
567 gamma_correct (struct frame
*f
, XColor
*color
)
571 color
->red
= pow (color
->red
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
572 color
->green
= pow (color
->green
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
573 color
->blue
= pow (color
->blue
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
578 /* Decide if color named COLOR_NAME is valid for use on frame F. If
579 so, return the RGB values in COLOR. If ALLOC_P is non-zero,
580 allocate the color. Value is zero if COLOR_NAME is invalid, or
581 no color could be allocated. */
584 x_defined_color (struct frame
*f
, const char *color_name
,
585 XColor
*color
, int alloc_p
)
588 Display
*dpy
= FRAME_X_DISPLAY (f
);
589 Colormap cmap
= FRAME_X_COLORMAP (f
);
593 success_p
= xg_check_special_colors (f
, color_name
, color
);
596 success_p
= XParseColor (dpy
, cmap
, color_name
, color
);
597 if (success_p
&& alloc_p
)
598 success_p
= x_alloc_nearest_color (f
, cmap
, color
);
605 /* Return the pixel color value for color COLOR_NAME on frame F. If F
606 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
607 Signal an error if color can't be allocated. */
610 x_decode_color (FRAME_PTR f
, Lisp_Object color_name
, int mono_color
)
614 CHECK_STRING (color_name
);
616 #if 0 /* Don't do this. It's wrong when we're not using the default
617 colormap, it makes freeing difficult, and it's probably not
618 an important optimization. */
619 if (strcmp (SDATA (color_name
), "black") == 0)
620 return BLACK_PIX_DEFAULT (f
);
621 else if (strcmp (SDATA (color_name
), "white") == 0)
622 return WHITE_PIX_DEFAULT (f
);
625 /* Return MONO_COLOR for monochrome frames. */
626 if (FRAME_X_DISPLAY_INFO (f
)->n_planes
== 1)
629 /* x_defined_color is responsible for coping with failures
630 by looking for a near-miss. */
631 if (x_defined_color (f
, SSDATA (color_name
), &cdef
, 1))
634 signal_error ("Undefined color", color_name
);
639 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
640 the previous value of that parameter, NEW_VALUE is the new value.
641 See also the comment of wait_for_wm in struct x_output. */
644 x_set_wait_for_wm (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
646 f
->output_data
.x
->wait_for_wm
= !NILP (new_value
);
650 x_set_tool_bar_position (struct frame
*f
,
651 Lisp_Object new_value
,
652 Lisp_Object old_value
)
654 if (! EQ (new_value
, Qleft
) && ! EQ (new_value
, Qright
)
655 && ! EQ (new_value
, Qbottom
) && ! EQ (new_value
, Qtop
))
657 if (EQ (new_value
, old_value
)) return;
660 if (xg_change_toolbar_position (f
, new_value
))
661 fset_tool_bar_position (f
, new_value
);
667 /* Set icon from FILE for frame F. By using GTK functions the icon
668 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
671 xg_set_icon (FRAME_PTR f
, Lisp_Object file
)
676 found
= x_find_image_file (file
);
682 char *filename
= SSDATA (found
);
685 pixbuf
= gdk_pixbuf_new_from_file (filename
, &err
);
689 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
691 g_object_unref (pixbuf
);
705 xg_set_icon_from_xpm_data (FRAME_PTR f
, const char **data
)
707 GdkPixbuf
*pixbuf
= gdk_pixbuf_new_from_xpm_data (data
);
712 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)), pixbuf
);
713 g_object_unref (pixbuf
);
719 /* Functions called only from `x_set_frame_param'
720 to set individual parameters.
722 If FRAME_X_WINDOW (f) is 0,
723 the frame is being created and its X-window does not exist yet.
724 In that case, just record the parameter's new value
725 in the standard place; do not attempt to change the window. */
728 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
730 struct x_output
*x
= f
->output_data
.x
;
731 unsigned long fg
, old_fg
;
733 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
734 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
735 FRAME_FOREGROUND_PIXEL (f
) = fg
;
737 if (FRAME_X_WINDOW (f
) != 0)
739 Display
*dpy
= FRAME_X_DISPLAY (f
);
742 XSetForeground (dpy
, x
->normal_gc
, fg
);
743 XSetBackground (dpy
, x
->reverse_gc
, fg
);
745 if (x
->cursor_pixel
== old_fg
)
747 unload_color (f
, x
->cursor_pixel
);
748 x
->cursor_pixel
= x_copy_color (f
, fg
);
749 XSetBackground (dpy
, x
->cursor_gc
, x
->cursor_pixel
);
754 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
756 if (FRAME_VISIBLE_P (f
))
760 unload_color (f
, old_fg
);
764 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
766 struct x_output
*x
= f
->output_data
.x
;
769 bg
= x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
770 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
771 FRAME_BACKGROUND_PIXEL (f
) = bg
;
773 if (FRAME_X_WINDOW (f
) != 0)
775 Display
*dpy
= FRAME_X_DISPLAY (f
);
778 XSetBackground (dpy
, x
->normal_gc
, bg
);
779 XSetForeground (dpy
, x
->reverse_gc
, bg
);
780 XSetWindowBackground (dpy
, FRAME_X_WINDOW (f
), bg
);
781 XSetForeground (dpy
, x
->cursor_gc
, bg
);
784 xg_set_background_color (f
, bg
);
787 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
788 toolkit scroll bars. */
791 for (bar
= FRAME_SCROLL_BARS (f
);
793 bar
= XSCROLL_BAR (bar
)->next
)
795 Window window
= XSCROLL_BAR (bar
)->x_window
;
796 XSetWindowBackground (dpy
, window
, bg
);
799 #endif /* USE_TOOLKIT_SCROLL_BARS */
802 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
804 if (FRAME_VISIBLE_P (f
))
810 make_invisible_cursor (struct frame
*f
)
812 Display
*dpy
= FRAME_X_DISPLAY (f
);
813 static char const no_data
[] = { 0 };
818 x_catch_errors (dpy
);
819 pix
= XCreateBitmapFromData (dpy
, FRAME_X_DISPLAY_INFO (f
)->root_window
,
821 if (! x_had_errors_p (dpy
) && pix
!= None
)
825 col
.red
= col
.green
= col
.blue
= 0;
826 col
.flags
= DoRed
| DoGreen
| DoBlue
;
827 pixc
= XCreatePixmapCursor (dpy
, pix
, pix
, &col
, &col
, 0, 0);
828 if (! x_had_errors_p (dpy
) && pixc
!= None
)
830 XFreePixmap (dpy
, pix
);
839 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
841 struct x_output
*x
= f
->output_data
.x
;
842 Display
*dpy
= FRAME_X_DISPLAY (f
);
843 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
844 Cursor hourglass_cursor
, horizontal_drag_cursor
;
845 unsigned long pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
846 unsigned long mask_color
= FRAME_BACKGROUND_PIXEL (f
);
848 /* Don't let pointers be invisible. */
849 if (mask_color
== pixel
)
851 x_free_colors (f
, &pixel
, 1);
852 pixel
= x_copy_color (f
, FRAME_FOREGROUND_PIXEL (f
));
855 unload_color (f
, x
->mouse_pixel
);
856 x
->mouse_pixel
= pixel
;
860 /* It's not okay to crash if the user selects a screwy cursor. */
861 x_catch_errors (dpy
);
863 if (!NILP (Vx_pointer_shape
))
865 CHECK_NUMBER (Vx_pointer_shape
);
866 cursor
= XCreateFontCursor (dpy
, XINT (Vx_pointer_shape
));
869 cursor
= XCreateFontCursor (dpy
, XC_xterm
);
870 x_check_errors (dpy
, "bad text pointer cursor: %s");
872 if (!NILP (Vx_nontext_pointer_shape
))
874 CHECK_NUMBER (Vx_nontext_pointer_shape
);
876 = XCreateFontCursor (dpy
, XINT (Vx_nontext_pointer_shape
));
879 nontext_cursor
= XCreateFontCursor (dpy
, XC_left_ptr
);
880 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
882 if (!NILP (Vx_hourglass_pointer_shape
))
884 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
886 = XCreateFontCursor (dpy
, XINT (Vx_hourglass_pointer_shape
));
889 hourglass_cursor
= XCreateFontCursor (dpy
, XC_watch
);
890 x_check_errors (dpy
, "bad hourglass pointer cursor: %s");
892 if (!NILP (Vx_mode_pointer_shape
))
894 CHECK_NUMBER (Vx_mode_pointer_shape
);
895 mode_cursor
= XCreateFontCursor (dpy
, XINT (Vx_mode_pointer_shape
));
898 mode_cursor
= XCreateFontCursor (dpy
, XC_xterm
);
899 x_check_errors (dpy
, "bad modeline pointer cursor: %s");
901 if (!NILP (Vx_sensitive_text_pointer_shape
))
903 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
905 = XCreateFontCursor (dpy
, XINT (Vx_sensitive_text_pointer_shape
));
908 hand_cursor
= XCreateFontCursor (dpy
, XC_hand2
);
910 if (!NILP (Vx_window_horizontal_drag_shape
))
912 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
913 horizontal_drag_cursor
914 = XCreateFontCursor (dpy
, XINT (Vx_window_horizontal_drag_shape
));
917 horizontal_drag_cursor
918 = XCreateFontCursor (dpy
, XC_sb_h_double_arrow
);
920 /* Check and report errors with the above calls. */
921 x_check_errors (dpy
, "can't set cursor shape: %s");
925 XColor fore_color
, back_color
;
927 fore_color
.pixel
= x
->mouse_pixel
;
928 x_query_color (f
, &fore_color
);
929 back_color
.pixel
= mask_color
;
930 x_query_color (f
, &back_color
);
932 XRecolorCursor (dpy
, cursor
, &fore_color
, &back_color
);
933 XRecolorCursor (dpy
, nontext_cursor
, &fore_color
, &back_color
);
934 XRecolorCursor (dpy
, mode_cursor
, &fore_color
, &back_color
);
935 XRecolorCursor (dpy
, hand_cursor
, &fore_color
, &back_color
);
936 XRecolorCursor (dpy
, hourglass_cursor
, &fore_color
, &back_color
);
937 XRecolorCursor (dpy
, horizontal_drag_cursor
, &fore_color
, &back_color
);
940 if (FRAME_X_WINDOW (f
) != 0)
941 XDefineCursor (dpy
, FRAME_X_WINDOW (f
),
942 f
->output_data
.x
->current_cursor
= cursor
);
944 if (FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
== 0)
945 FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
= make_invisible_cursor (f
);
947 if (cursor
!= x
->text_cursor
948 && x
->text_cursor
!= 0)
949 XFreeCursor (dpy
, x
->text_cursor
);
950 x
->text_cursor
= cursor
;
952 if (nontext_cursor
!= x
->nontext_cursor
953 && x
->nontext_cursor
!= 0)
954 XFreeCursor (dpy
, x
->nontext_cursor
);
955 x
->nontext_cursor
= nontext_cursor
;
957 if (hourglass_cursor
!= x
->hourglass_cursor
958 && x
->hourglass_cursor
!= 0)
959 XFreeCursor (dpy
, x
->hourglass_cursor
);
960 x
->hourglass_cursor
= hourglass_cursor
;
962 if (mode_cursor
!= x
->modeline_cursor
963 && x
->modeline_cursor
!= 0)
964 XFreeCursor (dpy
, f
->output_data
.x
->modeline_cursor
);
965 x
->modeline_cursor
= mode_cursor
;
967 if (hand_cursor
!= x
->hand_cursor
968 && x
->hand_cursor
!= 0)
969 XFreeCursor (dpy
, x
->hand_cursor
);
970 x
->hand_cursor
= hand_cursor
;
972 if (horizontal_drag_cursor
!= x
->horizontal_drag_cursor
973 && x
->horizontal_drag_cursor
!= 0)
974 XFreeCursor (dpy
, x
->horizontal_drag_cursor
);
975 x
->horizontal_drag_cursor
= horizontal_drag_cursor
;
980 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
984 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
986 unsigned long fore_pixel
, pixel
;
987 int fore_pixel_allocated_p
= 0, pixel_allocated_p
= 0;
988 struct x_output
*x
= f
->output_data
.x
;
990 if (!NILP (Vx_cursor_fore_pixel
))
992 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
993 WHITE_PIX_DEFAULT (f
));
994 fore_pixel_allocated_p
= 1;
997 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
999 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1000 pixel_allocated_p
= 1;
1002 /* Make sure that the cursor color differs from the background color. */
1003 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1005 if (pixel_allocated_p
)
1007 x_free_colors (f
, &pixel
, 1);
1008 pixel_allocated_p
= 0;
1011 pixel
= x
->mouse_pixel
;
1012 if (pixel
== fore_pixel
)
1014 if (fore_pixel_allocated_p
)
1016 x_free_colors (f
, &fore_pixel
, 1);
1017 fore_pixel_allocated_p
= 0;
1019 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1023 unload_color (f
, x
->cursor_foreground_pixel
);
1024 if (!fore_pixel_allocated_p
)
1025 fore_pixel
= x_copy_color (f
, fore_pixel
);
1026 x
->cursor_foreground_pixel
= fore_pixel
;
1028 unload_color (f
, x
->cursor_pixel
);
1029 if (!pixel_allocated_p
)
1030 pixel
= x_copy_color (f
, pixel
);
1031 x
->cursor_pixel
= pixel
;
1033 if (FRAME_X_WINDOW (f
) != 0)
1036 XSetBackground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, x
->cursor_pixel
);
1037 XSetForeground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, fore_pixel
);
1040 if (FRAME_VISIBLE_P (f
))
1042 x_update_cursor (f
, 0);
1043 x_update_cursor (f
, 1);
1047 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1050 /* Set the border-color of frame F to pixel value PIX.
1051 Note that this does not fully take effect if done before
1052 F has an x-window. */
1055 x_set_border_pixel (struct frame
*f
, int pix
)
1057 unload_color (f
, f
->output_data
.x
->border_pixel
);
1058 f
->output_data
.x
->border_pixel
= pix
;
1060 if (FRAME_X_WINDOW (f
) != 0 && f
->border_width
> 0)
1063 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), pix
);
1066 if (FRAME_VISIBLE_P (f
))
1071 /* Set the border-color of frame F to value described by ARG.
1072 ARG can be a string naming a color.
1073 The border-color is used for the border that is drawn by the X server.
1074 Note that this does not fully take effect if done before
1075 F has an x-window; it must be redone when the window is created.
1077 Note: this is done in two routines because of the way X10 works.
1079 Note: under X11, this is normally the province of the window manager,
1080 and so emacs' border colors may be overridden. */
1083 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1088 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1089 x_set_border_pixel (f
, pix
);
1090 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1095 x_set_cursor_type (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1097 set_frame_cursor_types (f
, arg
);
1099 /* Make sure the cursor gets redrawn. */
1100 cursor_type_changed
= 1;
1104 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1110 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1113 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1118 result
= x_text_icon (f
,
1119 SSDATA ((!NILP (f
->icon_name
)
1123 result
= x_bitmap_icon (f
, arg
);
1128 error ("No icon window available");
1131 XFlush (FRAME_X_DISPLAY (f
));
1136 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1142 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1145 else if (!NILP (arg
) || NILP (oldval
))
1148 fset_icon_name (f
, arg
);
1150 if (f
->output_data
.x
->icon_bitmap
!= 0)
1155 result
= x_text_icon (f
,
1156 SSDATA ((!NILP (f
->icon_name
)
1165 error ("No icon window available");
1168 XFlush (FRAME_X_DISPLAY (f
));
1174 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1177 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
1178 int olines
= FRAME_MENU_BAR_LINES (f
);
1181 /* Right now, menu bars don't work properly in minibuf-only frames;
1182 most of the commands try to apply themselves to the minibuffer
1183 frame itself, and get an error because you can't switch buffers
1184 in or split the minibuffer window. */
1185 if (FRAME_MINIBUF_ONLY_P (f
))
1188 if (TYPE_RANGED_INTEGERP (int, value
))
1189 nlines
= XINT (value
);
1193 /* Make sure we redisplay all windows in this frame. */
1194 windows_or_buffers_changed
++;
1196 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
1197 FRAME_MENU_BAR_LINES (f
) = 0;
1200 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1201 if (FRAME_X_P (f
) && f
->output_data
.x
->menubar_widget
== 0)
1202 /* Make sure next redisplay shows the menu bar. */
1203 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= 1;
1207 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1208 free_frame_menubar (f
);
1209 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1211 f
->output_data
.x
->menubar_widget
= 0;
1213 #else /* not USE_X_TOOLKIT && not USE_GTK */
1214 FRAME_MENU_BAR_LINES (f
) = nlines
;
1215 resize_frame_windows (f
, FRAME_LINES (f
), 0);
1217 /* If the menu bar height gets changed, the internal border below
1218 the top margin has to be cleared. Also, if the menu bar gets
1219 larger, the area for the added lines has to be cleared except for
1220 the first menu bar line that is to be drawn later. */
1221 if (nlines
!= olines
)
1223 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1224 int width
= FRAME_PIXEL_WIDTH (f
);
1227 /* height can be zero here. */
1228 if (height
> 0 && width
> 0)
1230 y
= FRAME_TOP_MARGIN_HEIGHT (f
);
1233 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1234 0, y
, width
, height
, False
);
1238 if (nlines
> 1 && nlines
> olines
)
1240 y
= (olines
== 0 ? 1 : olines
) * FRAME_LINE_HEIGHT (f
);
1241 height
= nlines
* FRAME_LINE_HEIGHT (f
) - y
;
1244 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1245 0, y
, width
, height
, False
);
1249 if (nlines
== 0 && WINDOWP (f
->menu_bar_window
))
1250 clear_glyph_matrix (XWINDOW (f
->menu_bar_window
)->current_matrix
);
1252 #endif /* not USE_X_TOOLKIT && not USE_GTK */
1254 run_window_configuration_change_hook (f
);
1258 /* Set the number of lines used for the tool bar of frame F to VALUE.
1259 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1260 is the old number of tool bar lines. This function changes the
1261 height of all windows on frame F to match the new tool bar height.
1262 The frame's height doesn't change. */
1265 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1267 int delta
, nlines
, root_height
;
1268 Lisp_Object root_window
;
1270 /* Treat tool bars like menu bars. */
1271 if (FRAME_MINIBUF_ONLY_P (f
))
1274 /* Use VALUE only if an int >= 0. */
1275 if (RANGED_INTEGERP (0, value
, INT_MAX
))
1276 nlines
= XFASTINT (value
);
1281 FRAME_TOOL_BAR_LINES (f
) = 0;
1284 FRAME_EXTERNAL_TOOL_BAR (f
) = 1;
1285 if (FRAME_X_P (f
) && f
->output_data
.x
->toolbar_widget
== 0)
1286 /* Make sure next redisplay shows the tool bar. */
1287 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= 1;
1288 update_frame_tool_bar (f
);
1292 if (FRAME_EXTERNAL_TOOL_BAR (f
))
1293 free_frame_tool_bar (f
);
1294 FRAME_EXTERNAL_TOOL_BAR (f
) = 0;
1300 /* Make sure we redisplay all windows in this frame. */
1301 ++windows_or_buffers_changed
;
1303 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1305 /* Don't resize the tool-bar to more than we have room for. */
1306 root_window
= FRAME_ROOT_WINDOW (f
);
1307 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1308 if (root_height
- delta
< 1)
1310 delta
= root_height
- 1;
1311 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1314 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1315 resize_frame_windows (f
, FRAME_LINES (f
), 0);
1318 /* We also have to make sure that the internal border at the top of
1319 the frame, below the menu bar or tool bar, is redrawn when the
1320 tool bar disappears. This is so because the internal border is
1321 below the tool bar if one is displayed, but is below the menu bar
1322 if there isn't a tool bar. The tool bar draws into the area
1323 below the menu bar. */
1324 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1327 clear_current_matrices (f
);
1330 /* If the tool bar gets smaller, the internal border below it
1331 has to be cleared. It was formerly part of the display
1332 of the larger tool bar, and updating windows won't clear it. */
1335 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1336 int width
= FRAME_PIXEL_WIDTH (f
);
1337 int y
= (FRAME_MENU_BAR_LINES (f
) + nlines
) * FRAME_LINE_HEIGHT (f
);
1339 /* height can be zero here. */
1340 if (height
> 0 && width
> 0)
1343 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1344 0, y
, width
, height
, False
);
1348 if (WINDOWP (f
->tool_bar_window
))
1349 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1352 run_window_configuration_change_hook (f
);
1357 /* Set the foreground color for scroll bars on frame F to VALUE.
1358 VALUE should be a string, a color name. If it isn't a string or
1359 isn't a valid color name, do nothing. OLDVAL is the old value of
1360 the frame parameter. */
1363 x_set_scroll_bar_foreground (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1365 unsigned long pixel
;
1367 if (STRINGP (value
))
1368 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
1372 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
1373 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
1375 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
1376 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1378 /* Remove all scroll bars because they have wrong colors. */
1379 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1380 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1381 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1382 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1384 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
1390 /* Set the background color for scroll bars on frame F to VALUE VALUE
1391 should be a string, a color name. If it isn't a string or isn't a
1392 valid color name, do nothing. OLDVAL is the old value of the frame
1396 x_set_scroll_bar_background (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1398 unsigned long pixel
;
1400 if (STRINGP (value
))
1401 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
1405 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
1406 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
1408 #ifdef USE_TOOLKIT_SCROLL_BARS
1409 /* Scrollbar shadow colors. */
1410 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
1412 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
1413 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
1415 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
1417 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
1418 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
1420 #endif /* USE_TOOLKIT_SCROLL_BARS */
1422 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
1423 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1425 /* Remove all scroll bars because they have wrong colors. */
1426 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1427 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1428 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1429 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1431 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
1437 /* Encode Lisp string STRING as a text in a format appropriate for
1438 XICCC (X Inter Client Communication Conventions).
1440 This can call Lisp code, so callers must GCPRO.
1442 If STRING contains only ASCII characters, do no conversion and
1443 return the string data of STRING. Otherwise, encode the text by
1444 CODING_SYSTEM, and return a newly allocated memory area which
1445 should be freed by `xfree' by a caller.
1447 SELECTIONP non-zero means the string is being encoded for an X
1448 selection, so it is safe to run pre-write conversions (which
1451 Store the byte length of resulting text in *TEXT_BYTES.
1453 If the text contains only ASCII and Latin-1, store 1 in *STRING_P,
1454 which means that the `encoding' of the result can be `STRING'.
1455 Otherwise store 0 in *STRINGP, which means that the `encoding' of
1456 the result should be `COMPOUND_TEXT'. */
1458 static unsigned char *
1459 x_encode_text (Lisp_Object string
, Lisp_Object coding_system
, int selectionp
,
1460 ptrdiff_t *text_bytes
, int *stringp
, int *freep
)
1462 int result
= string_xstring_p (string
);
1463 struct coding_system coding
;
1467 /* No multibyte character in OBJ. We need not encode it. */
1468 *text_bytes
= SBYTES (string
);
1471 return SDATA (string
);
1474 setup_coding_system (coding_system
, &coding
);
1475 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
1476 /* We suppress producing escape sequences for composition. */
1477 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
1478 coding
.destination
= xnmalloc (SCHARS (string
), 2);
1479 coding
.dst_bytes
= SCHARS (string
) * 2;
1480 encode_coding_object (&coding
, string
, 0, 0,
1481 SCHARS (string
), SBYTES (string
), Qnil
);
1482 *text_bytes
= coding
.produced
;
1483 *stringp
= (result
== 1 || !EQ (coding_system
, Qcompound_text
));
1485 return coding
.destination
;
1489 /* Set the WM name to NAME for frame F. Also set the icon name.
1490 If the frame already has an icon name, use that, otherwise set the
1491 icon name to NAME. */
1494 x_set_name_internal (FRAME_PTR f
, Lisp_Object name
)
1496 if (FRAME_X_WINDOW (f
))
1500 XTextProperty text
, icon
;
1503 int do_free_icon_value
= 0, do_free_text_value
= 0;
1504 Lisp_Object coding_system
;
1505 Lisp_Object encoded_name
;
1506 Lisp_Object encoded_icon_name
;
1507 struct gcpro gcpro1
;
1509 /* As ENCODE_UTF_8 may cause GC and relocation of string data,
1510 we use it before x_encode_text that may return string data. */
1512 encoded_name
= ENCODE_UTF_8 (name
);
1515 coding_system
= Qcompound_text
;
1516 /* Note: Encoding strategy
1518 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1519 text.encoding. But, there are non-internationalized window
1520 managers which don't support that encoding. So, if NAME
1521 contains only ASCII and 8859-1 characters, encode it by
1522 iso-latin-1, and use "STRING" in text.encoding hoping that
1523 such window managers at least analyze this format correctly,
1524 i.e. treat 8-bit bytes as 8859-1 characters.
1526 We may also be able to use "UTF8_STRING" in text.encoding
1527 in the future which can encode all Unicode characters.
1528 But, for the moment, there's no way to know that the
1529 current window manager supports it or not.
1531 Either way, we also set the _NET_WM_NAME and _NET_WM_ICON_NAME
1532 properties. Per the EWMH specification, those two properties
1533 are always UTF8_STRING. This matches what gtk_window_set_title()
1534 does in the USE_GTK case. */
1535 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
,
1536 &do_free_text_value
);
1537 text
.encoding
= (stringp
? XA_STRING
1538 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1540 text
.nitems
= bytes
;
1541 if (text
.nitems
!= bytes
)
1542 error ("Window name too large");
1544 if (!STRINGP (f
->icon_name
))
1547 encoded_icon_name
= encoded_name
;
1551 /* See the above comment "Note: Encoding strategy". */
1552 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
1553 &bytes
, &stringp
, &do_free_icon_value
);
1554 icon
.encoding
= (stringp
? XA_STRING
1555 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1557 icon
.nitems
= bytes
;
1558 if (icon
.nitems
!= bytes
)
1559 error ("Icon name too large");
1561 encoded_icon_name
= ENCODE_UTF_8 (f
->icon_name
);
1565 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1566 SSDATA (encoded_name
));
1567 #else /* not USE_GTK */
1568 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1569 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1570 FRAME_X_DISPLAY_INFO (f
)->Xatom_net_wm_name
,
1571 FRAME_X_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1573 SDATA (encoded_name
),
1574 SBYTES (encoded_name
));
1575 #endif /* not USE_GTK */
1577 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &icon
);
1578 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1579 FRAME_X_DISPLAY_INFO (f
)->Xatom_net_wm_icon_name
,
1580 FRAME_X_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1582 SDATA (encoded_icon_name
),
1583 SBYTES (encoded_icon_name
));
1585 if (do_free_icon_value
)
1587 if (do_free_text_value
)
1594 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1597 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1598 name; if NAME is a string, set F's name to NAME and set
1599 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1601 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1602 suggesting a new name, which lisp code should override; if
1603 F->explicit_name is set, ignore the new name; otherwise, set it. */
1606 x_set_name (struct frame
*f
, Lisp_Object name
, int explicit)
1608 /* Make sure that requests from lisp code override requests from
1609 Emacs redisplay code. */
1612 /* If we're switching from explicit to implicit, we had better
1613 update the mode lines and thereby update the title. */
1614 if (f
->explicit_name
&& NILP (name
))
1615 update_mode_lines
= 1;
1617 f
->explicit_name
= ! NILP (name
);
1619 else if (f
->explicit_name
)
1622 /* If NAME is nil, set the name to the x_id_name. */
1625 /* Check for no change needed in this very common case
1626 before we do any consing. */
1627 if (!strcmp (FRAME_X_DISPLAY_INFO (f
)->x_id_name
,
1630 name
= build_string (FRAME_X_DISPLAY_INFO (f
)->x_id_name
);
1633 CHECK_STRING (name
);
1635 /* Don't change the name if it's already NAME. */
1636 if (! NILP (Fstring_equal (name
, f
->name
)))
1639 fset_name (f
, name
);
1641 /* For setting the frame title, the title parameter should override
1642 the name parameter. */
1643 if (! NILP (f
->title
))
1646 x_set_name_internal (f
, name
);
1649 /* This function should be called when the user's lisp code has
1650 specified a name for the frame; the name will override any set by the
1653 x_explicitly_set_name (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1655 x_set_name (f
, arg
, 1);
1658 /* This function should be called by Emacs redisplay code to set the
1659 name; names set this way will never override names set by the user's
1662 x_implicitly_set_name (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1664 x_set_name (f
, arg
, 0);
1667 /* Change the title of frame F to NAME.
1668 If NAME is nil, use the frame name as the title. */
1671 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1673 /* Don't change the title if it's already NAME. */
1674 if (EQ (name
, f
->title
))
1677 update_mode_lines
= 1;
1679 fset_title (f
, name
);
1684 CHECK_STRING (name
);
1686 x_set_name_internal (f
, name
);
1690 x_set_scroll_bar_default_width (struct frame
*f
)
1692 int wid
= FRAME_COLUMN_WIDTH (f
);
1693 #ifdef USE_TOOLKIT_SCROLL_BARS
1695 int minw
= xg_get_default_scrollbar_width ();
1699 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1700 int width
= minw
+ 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1701 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (width
+ wid
- 1) / wid
;
1702 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = width
;
1704 /* Make the actual width at least 14 pixels and a multiple of a
1706 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
1708 /* Use all of that space (aside from required margins) for the
1710 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = 0;
1715 /* Record in frame F the specified or default value according to ALIST
1716 of the parameter named PROP (a Lisp symbol). If no value is
1717 specified for PROP, look for an X default for XPROP on the frame
1718 named NAME. If that is not found either, use the value DEFLT. */
1721 x_default_scroll_bar_color_parameter (struct frame
*f
,
1722 Lisp_Object alist
, Lisp_Object prop
,
1723 const char *xprop
, const char *xclass
,
1726 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1729 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
1730 if (EQ (tem
, Qunbound
))
1732 #ifdef USE_TOOLKIT_SCROLL_BARS
1734 /* See if an X resource for the scroll bar color has been
1736 tem
= display_x_get_resource (dpyinfo
,
1737 build_string (foreground_p
1740 empty_unibyte_string
,
1741 build_string ("verticalScrollBar"),
1742 empty_unibyte_string
);
1745 /* If nothing has been specified, scroll bars will use a
1746 toolkit-dependent default. Because these defaults are
1747 difficult to get at without actually creating a scroll
1748 bar, use nil to indicate that no color has been
1753 #else /* not USE_TOOLKIT_SCROLL_BARS */
1757 #endif /* not USE_TOOLKIT_SCROLL_BARS */
1760 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
1767 #ifdef USE_X_TOOLKIT
1769 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
1770 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
1771 already be present because of the toolkit (Motif adds some of them,
1772 for example, but Xt doesn't). */
1775 hack_wm_protocols (FRAME_PTR f
, Widget widget
)
1777 Display
*dpy
= XtDisplay (widget
);
1778 Window w
= XtWindow (widget
);
1779 int need_delete
= 1;
1786 unsigned char *catoms
;
1788 unsigned long nitems
= 0;
1789 unsigned long bytes_after
;
1791 if ((XGetWindowProperty (dpy
, w
,
1792 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1793 (long)0, (long)100, False
, XA_ATOM
,
1794 &type
, &format
, &nitems
, &bytes_after
,
1797 && format
== 32 && type
== XA_ATOM
)
1799 Atom
*atoms
= (Atom
*) catoms
;
1804 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
1806 else if (atoms
[nitems
]
1807 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
1809 else if (atoms
[nitems
]
1810 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
1821 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
1823 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
1825 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
1827 XChangeProperty (dpy
, w
, FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1828 XA_ATOM
, 32, PropModeAppend
,
1829 (unsigned char *) props
, count
);
1837 /* Support routines for XIC (X Input Context). */
1841 static XFontSet
xic_create_xfontset (struct frame
*);
1842 static XIMStyle
best_xim_style (XIMStyles
*, XIMStyles
*);
1845 /* Supported XIM styles, ordered by preference. */
1847 static XIMStyle supported_xim_styles
[] =
1849 XIMPreeditPosition
| XIMStatusArea
,
1850 XIMPreeditPosition
| XIMStatusNothing
,
1851 XIMPreeditPosition
| XIMStatusNone
,
1852 XIMPreeditNothing
| XIMStatusArea
,
1853 XIMPreeditNothing
| XIMStatusNothing
,
1854 XIMPreeditNothing
| XIMStatusNone
,
1855 XIMPreeditNone
| XIMStatusArea
,
1856 XIMPreeditNone
| XIMStatusNothing
,
1857 XIMPreeditNone
| XIMStatusNone
,
1862 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1863 /* Create an X fontset on frame F with base font name BASE_FONTNAME. */
1865 static const char xic_default_fontset
[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
1867 /* Create an Xt fontset spec from the name of a base font.
1868 If `motif' is True use the Motif syntax. */
1870 xic_create_fontsetname (const char *base_fontname
, int motif
)
1872 const char *sep
= motif
? ";" : ",";
1875 /* Make a fontset name from the base font name. */
1876 if (xic_default_fontset
== base_fontname
)
1878 /* There is no base font name, use the default. */
1879 fontsetname
= xmalloc (strlen (base_fontname
) + 2);
1880 strcpy (fontsetname
, base_fontname
);
1884 /* Make a fontset name from the base font name.
1885 The font set will be made of the following elements:
1887 - the base font where the charset spec is replaced by -*-*.
1888 - the same but with the family also replaced with -*-*-. */
1889 const char *p
= base_fontname
;
1892 for (i
= 0; *p
; p
++)
1896 /* As the font name doesn't conform to XLFD, we can't
1897 modify it to generalize it to allcs and allfamilies.
1898 Use the specified font plus the default. */
1899 fontsetname
= xmalloc (strlen (base_fontname
)
1900 + strlen (xic_default_fontset
) + 3);
1901 strcpy (fontsetname
, base_fontname
);
1902 strcat (fontsetname
, sep
);
1903 strcat (fontsetname
, xic_default_fontset
);
1908 const char *p1
= NULL
, *p2
= NULL
, *p3
= NULL
;
1909 char *font_allcs
= NULL
;
1910 char *font_allfamilies
= NULL
;
1911 char *font_all
= NULL
;
1912 const char *allcs
= "*-*-*-*-*-*-*";
1913 const char *allfamilies
= "-*-*-";
1914 const char *all
= "*-*-*-*-";
1917 for (i
= 0, p
= base_fontname
; i
< 8; p
++)
1930 /* If base_fontname specifies ADSTYLE, make it a
1934 ptrdiff_t diff
= (p2
- p3
) - 2;
1936 base
= alloca (strlen (base_fontname
) + 1);
1937 memcpy (base
, base_fontname
, p3
- base_fontname
);
1938 base
[p3
- base_fontname
] = '*';
1939 base
[(p3
- base_fontname
) + 1] = '-';
1940 strcpy (base
+ (p3
- base_fontname
) + 2, p2
);
1941 p
= base
+ (p
- base_fontname
) - diff
;
1942 p1
= base
+ (p1
- base_fontname
);
1943 p2
= base
+ (p2
- base_fontname
) - diff
;
1944 base_fontname
= base
;
1947 /* Build the font spec that matches all charsets. */
1948 len
= p
- base_fontname
+ strlen (allcs
) + 1;
1949 font_allcs
= alloca (len
);
1950 memcpy (font_allcs
, base_fontname
, p
- base_fontname
);
1951 strcat (font_allcs
, allcs
);
1953 /* Build the font spec that matches all families and
1955 len
= p
- p1
+ strlen (allcs
) + strlen (allfamilies
) + 1;
1956 font_allfamilies
= alloca (len
);
1957 strcpy (font_allfamilies
, allfamilies
);
1958 memcpy (font_allfamilies
+ strlen (allfamilies
), p1
, p
- p1
);
1959 strcat (font_allfamilies
, allcs
);
1961 /* Build the font spec that matches all. */
1962 len
= p
- p2
+ strlen (allcs
) + strlen (all
) + strlen (allfamilies
) + 1;
1963 font_all
= alloca (len
);
1964 strcpy (font_all
, allfamilies
);
1965 strcat (font_all
, all
);
1966 memcpy (font_all
+ strlen (all
) + strlen (allfamilies
), p2
, p
- p2
);
1967 strcat (font_all
, allcs
);
1969 /* Build the actual font set name. */
1970 len
= strlen (base_fontname
) + strlen (font_allcs
)
1971 + strlen (font_allfamilies
) + strlen (font_all
) + 5;
1972 fontsetname
= xmalloc (len
);
1973 strcpy (fontsetname
, base_fontname
);
1974 strcat (fontsetname
, sep
);
1975 strcat (fontsetname
, font_allcs
);
1976 strcat (fontsetname
, sep
);
1977 strcat (fontsetname
, font_allfamilies
);
1978 strcat (fontsetname
, sep
);
1979 strcat (fontsetname
, font_all
);
1983 strcat (fontsetname
, ":");
1986 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
1988 #ifdef DEBUG_XIC_FONTSET
1990 print_fontset_result (XFontSet xfs
, char *name
, char **missing_list
,
1994 fprintf (stderr
, "XIC Fontset created: %s\n", name
);
1997 fprintf (stderr
, "XIC Fontset failed: %s\n", name
);
1998 while (missing_count
-- > 0)
2000 fprintf (stderr
, " missing: %s\n", *missing_list
);
2009 xic_create_xfontset (struct frame
*f
)
2011 XFontSet xfs
= NULL
;
2012 struct font
*font
= FRAME_FONT (f
);
2013 int pixel_size
= font
->pixel_size
;
2014 Lisp_Object rest
, frame
;
2016 /* See if there is another frame already using same fontset. */
2017 FOR_EACH_FRAME (rest
, frame
)
2019 struct frame
*cf
= XFRAME (frame
);
2021 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
2022 && FRAME_X_DISPLAY_INFO (cf
) == FRAME_X_DISPLAY_INFO (f
)
2024 && FRAME_FONT (f
)->pixel_size
== pixel_size
)
2026 xfs
= FRAME_XIC_FONTSET (cf
);
2034 char **missing_list
;
2037 const char *xlfd_format
= "-*-*-medium-r-normal--%d-*-*-*-*-*";
2039 sprintf (buf
, xlfd_format
, pixel_size
);
2040 missing_list
= NULL
;
2041 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
2042 &missing_list
, &missing_count
, &def_string
);
2043 #ifdef DEBUG_XIC_FONTSET
2044 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
2047 XFreeStringList (missing_list
);
2050 /* List of pixel sizes most likely available. Find one that
2051 is closest to pixel_size. */
2052 int sizes
[] = {0, 8, 10, 11, 12, 14, 17, 18, 20, 24, 26, 34, 0};
2053 int *smaller
, *larger
;
2055 for (smaller
= sizes
; smaller
[1]; smaller
++)
2056 if (smaller
[1] >= pixel_size
)
2058 larger
= smaller
+ 1;
2059 if (*larger
== pixel_size
)
2061 while (*smaller
|| *larger
)
2066 this_size
= *smaller
--;
2067 else if (! *smaller
)
2068 this_size
= *larger
++;
2069 else if (pixel_size
- *smaller
< *larger
- pixel_size
)
2070 this_size
= *smaller
--;
2072 this_size
= *larger
++;
2073 sprintf (buf
, xlfd_format
, this_size
);
2074 missing_list
= NULL
;
2075 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
2076 &missing_list
, &missing_count
, &def_string
);
2077 #ifdef DEBUG_XIC_FONTSET
2078 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
2081 XFreeStringList (missing_list
);
2088 const char *last_resort
= "-*-*-*-r-normal--*-*-*-*-*-*";
2090 missing_list
= NULL
;
2091 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), last_resort
,
2092 &missing_list
, &missing_count
, &def_string
);
2093 #ifdef DEBUG_XIC_FONTSET
2094 print_fontset_result (xfs
, last_resort
, missing_list
, missing_count
);
2097 XFreeStringList (missing_list
);
2105 /* Free the X fontset of frame F if it is the last frame using it. */
2108 xic_free_xfontset (struct frame
*f
)
2110 Lisp_Object rest
, frame
;
2113 if (!FRAME_XIC_FONTSET (f
))
2116 /* See if there is another frame sharing the same fontset. */
2117 FOR_EACH_FRAME (rest
, frame
)
2119 struct frame
*cf
= XFRAME (frame
);
2120 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
2121 && FRAME_X_DISPLAY_INFO (cf
) == FRAME_X_DISPLAY_INFO (f
)
2122 && FRAME_XIC_FONTSET (cf
) == FRAME_XIC_FONTSET (f
))
2130 /* The fontset is not used anymore. It is safe to free it. */
2131 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
2133 if (FRAME_XIC_BASE_FONTNAME (f
))
2134 xfree (FRAME_XIC_BASE_FONTNAME (f
));
2135 FRAME_XIC_BASE_FONTNAME (f
) = NULL
;
2136 FRAME_XIC_FONTSET (f
) = NULL
;
2140 /* Value is the best input style, given user preferences USER (already
2141 checked to be supported by Emacs), and styles supported by the
2142 input method XIM. */
2145 best_xim_style (XIMStyles
*user
, XIMStyles
*xim
)
2149 for (i
= 0; i
< user
->count_styles
; ++i
)
2150 for (j
= 0; j
< xim
->count_styles
; ++j
)
2151 if (user
->supported_styles
[i
] == xim
->supported_styles
[j
])
2152 return user
->supported_styles
[i
];
2154 /* Return the default style. */
2155 return XIMPreeditNothing
| XIMStatusNothing
;
2158 /* Create XIC for frame F. */
2160 static XIMStyle xic_style
;
2163 create_frame_xic (struct frame
*f
)
2167 XFontSet xfs
= NULL
;
2172 /* Create X fontset. */
2173 xfs
= xic_create_xfontset (f
);
2174 xim
= FRAME_X_XIM (f
);
2179 XVaNestedList preedit_attr
;
2180 XVaNestedList status_attr
;
2182 s_area
.x
= 0; s_area
.y
= 0; s_area
.width
= 1; s_area
.height
= 1;
2183 spot
.x
= 0; spot
.y
= 1;
2185 /* Determine XIC style. */
2188 XIMStyles supported_list
;
2189 supported_list
.count_styles
= (sizeof supported_xim_styles
2190 / sizeof supported_xim_styles
[0]);
2191 supported_list
.supported_styles
= supported_xim_styles
;
2192 xic_style
= best_xim_style (&supported_list
,
2193 FRAME_X_XIM_STYLES (f
));
2196 preedit_attr
= XVaCreateNestedList (0,
2199 FRAME_FOREGROUND_PIXEL (f
),
2201 FRAME_BACKGROUND_PIXEL (f
),
2202 (xic_style
& XIMPreeditPosition
2207 status_attr
= XVaCreateNestedList (0,
2213 FRAME_FOREGROUND_PIXEL (f
),
2215 FRAME_BACKGROUND_PIXEL (f
),
2218 xic
= XCreateIC (xim
,
2219 XNInputStyle
, xic_style
,
2220 XNClientWindow
, FRAME_X_WINDOW (f
),
2221 XNFocusWindow
, FRAME_X_WINDOW (f
),
2222 XNStatusAttributes
, status_attr
,
2223 XNPreeditAttributes
, preedit_attr
,
2225 XFree (preedit_attr
);
2226 XFree (status_attr
);
2229 FRAME_XIC (f
) = xic
;
2230 FRAME_XIC_STYLE (f
) = xic_style
;
2231 FRAME_XIC_FONTSET (f
) = xfs
;
2235 /* Destroy XIC and free XIC fontset of frame F, if any. */
2238 free_frame_xic (struct frame
*f
)
2240 if (FRAME_XIC (f
) == NULL
)
2243 XDestroyIC (FRAME_XIC (f
));
2244 xic_free_xfontset (f
);
2246 FRAME_XIC (f
) = NULL
;
2250 /* Place preedit area for XIC of window W's frame to specified
2251 pixel position X/Y. X and Y are relative to window W. */
2254 xic_set_preeditarea (struct window
*w
, int x
, int y
)
2256 struct frame
*f
= XFRAME (w
->frame
);
2260 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
) + WINDOW_LEFT_FRINGE_WIDTH (w
);
2261 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
2262 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
2263 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2268 /* Place status area for XIC in bottom right corner of frame F.. */
2271 xic_set_statusarea (struct frame
*f
)
2273 XIC xic
= FRAME_XIC (f
);
2278 /* Negotiate geometry of status area. If input method has existing
2279 status area, use its current size. */
2280 area
.x
= area
.y
= area
.width
= area
.height
= 0;
2281 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
2282 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2285 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
2286 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2289 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
2291 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
2292 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2296 area
.width
= needed
->width
;
2297 area
.height
= needed
->height
;
2298 area
.x
= FRAME_PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
2299 area
.y
= (FRAME_PIXEL_HEIGHT (f
) - area
.height
2300 - FRAME_MENUBAR_HEIGHT (f
)
2301 - FRAME_TOOLBAR_TOP_HEIGHT (f
)
2302 - FRAME_INTERNAL_BORDER_WIDTH (f
));
2305 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
2306 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2311 /* Set X fontset for XIC of frame F, using base font name
2312 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2315 xic_set_xfontset (struct frame
*f
, const char *base_fontname
)
2320 xic_free_xfontset (f
);
2322 xfs
= xic_create_xfontset (f
);
2324 attr
= XVaCreateNestedList (0, XNFontSet
, xfs
, NULL
);
2325 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
2326 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2327 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
2328 XSetICValues (FRAME_XIC (f
), XNStatusAttributes
, attr
, NULL
);
2331 FRAME_XIC_FONTSET (f
) = xfs
;
2334 #endif /* HAVE_X_I18N */
2338 #ifdef USE_X_TOOLKIT
2340 /* Create and set up the X widget for frame F. */
2343 x_window (struct frame
*f
, long window_prompting
, int minibuffer_only
)
2345 XClassHint class_hints
;
2346 XSetWindowAttributes attributes
;
2347 unsigned long attribute_mask
;
2348 Widget shell_widget
;
2350 Widget frame_widget
;
2356 /* Use the resource name as the top-level widget name
2357 for looking up resources. Make a non-Lisp copy
2358 for the window manager, so GC relocation won't bother it.
2360 Elsewhere we specify the window name for the window manager. */
2363 char *str
= SSDATA (Vx_resource_name
);
2364 f
->namebuf
= xmalloc (strlen (str
) + 1);
2365 strcpy (f
->namebuf
, str
);
2369 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2370 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2371 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2372 XtSetArg (al
[ac
], XtNborderWidth
, f
->border_width
); ac
++;
2373 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2374 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2375 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2376 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2377 applicationShellWidgetClass
,
2378 FRAME_X_DISPLAY (f
), al
, ac
);
2380 f
->output_data
.x
->widget
= shell_widget
;
2381 /* maybe_set_screen_title_format (shell_widget); */
2383 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2384 (widget_value
*) NULL
,
2385 shell_widget
, False
,
2389 (lw_callback
) NULL
);
2392 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2393 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2394 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2395 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2396 XtSetValues (pane_widget
, al
, ac
);
2397 f
->output_data
.x
->column_widget
= pane_widget
;
2399 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2400 the emacs screen when changing menubar. This reduces flickering. */
2403 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2404 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2405 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2406 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2407 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2408 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2409 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2410 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2411 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2412 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
2415 f
->output_data
.x
->edit_widget
= frame_widget
;
2417 XtManageChild (frame_widget
);
2419 /* Do some needed geometry management. */
2421 char *tem
, shell_position
[sizeof "=x++" + 4 * INT_STRLEN_BOUND (int)];
2424 int extra_borders
= 0;
2426 = (f
->output_data
.x
->menubar_widget
2427 ? (f
->output_data
.x
->menubar_widget
->core
.height
2428 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
2431 #if 0 /* Experimentally, we now get the right results
2432 for -geometry -0-0 without this. 24 Aug 96, rms. */
2433 if (FRAME_EXTERNAL_MENU_BAR (f
))
2436 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2437 menubar_size
+= ibw
;
2441 f
->output_data
.x
->menubar_height
= menubar_size
;
2444 /* Motif seems to need this amount added to the sizes
2445 specified for the shell widget. The Athena/Lucid widgets don't.
2446 Both conclusions reached experimentally. -- rms. */
2447 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
2448 &extra_borders
, NULL
);
2452 /* Convert our geometry parameters into a geometry string
2454 Note that we do not specify here whether the position
2455 is a user-specified or program-specified one.
2456 We pass that information later, in x_wm_set_size_hints. */
2458 int left
= f
->left_pos
;
2459 int xneg
= window_prompting
& XNegative
;
2460 int top
= f
->top_pos
;
2461 int yneg
= window_prompting
& YNegative
;
2467 if (window_prompting
& USPosition
)
2468 sprintf (shell_position
, "=%dx%d%c%d%c%d",
2469 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2470 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
2471 (xneg
? '-' : '+'), left
,
2472 (yneg
? '-' : '+'), top
);
2475 sprintf (shell_position
, "=%dx%d",
2476 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2477 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
2479 /* Setting x and y when the position is not specified in
2480 the geometry string will set program position in the WM hints.
2481 If Emacs had just one program position, we could set it in
2482 fallback resources, but since each make-frame call can specify
2483 different program positions, this is easier. */
2484 XtSetArg (gal
[gac
], XtNx
, left
); gac
++;
2485 XtSetArg (gal
[gac
], XtNy
, top
); gac
++;
2489 /* We don't free this because we don't know whether
2490 it is safe to free it while the frame exists.
2491 It isn't worth the trouble of arranging to free it
2492 when the frame is deleted. */
2493 tem
= xstrdup (shell_position
);
2494 XtSetArg (gal
[gac
], XtNgeometry
, tem
); gac
++;
2495 XtSetValues (shell_widget
, gal
, gac
);
2498 XtManageChild (pane_widget
);
2499 XtRealizeWidget (shell_widget
);
2501 if (FRAME_X_EMBEDDED_P (f
))
2502 XReparentWindow (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
),
2503 f
->output_data
.x
->parent_desc
, 0, 0);
2505 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2507 validate_x_resource_name ();
2509 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2510 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2511 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2514 FRAME_XIC (f
) = NULL
;
2516 create_frame_xic (f
);
2519 f
->output_data
.x
->wm_hints
.input
= True
;
2520 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2521 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2522 &f
->output_data
.x
->wm_hints
);
2524 hack_wm_protocols (f
, shell_widget
);
2527 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2530 /* Do a stupid property change to force the server to generate a
2531 PropertyNotify event so that the event_stream server timestamp will
2532 be initialized to something relevant to the time we created the window.
2534 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2535 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2536 XA_ATOM
, 32, PropModeAppend
,
2537 (unsigned char*) NULL
, 0);
2539 /* Make all the standard events reach the Emacs frame. */
2540 attributes
.event_mask
= STANDARD_EVENT_SET
;
2545 /* XIM server might require some X events. */
2546 unsigned long fevent
= NoEventMask
;
2547 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2548 attributes
.event_mask
|= fevent
;
2550 #endif /* HAVE_X_I18N */
2552 attribute_mask
= CWEventMask
;
2553 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2554 attribute_mask
, &attributes
);
2556 XtMapWidget (frame_widget
);
2558 /* x_set_name normally ignores requests to set the name if the
2559 requested name is the same as the current name. This is the one
2560 place where that assumption isn't correct; f->name is set, but
2561 the X server hasn't been told. */
2564 int explicit = f
->explicit_name
;
2566 f
->explicit_name
= 0;
2568 fset_name (f
, Qnil
);
2569 x_set_name (f
, name
, explicit);
2572 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2573 f
->output_data
.x
->current_cursor
2574 = f
->output_data
.x
->text_cursor
);
2578 /* This is a no-op, except under Motif. Make sure main areas are
2579 set to something reasonable, in case we get an error later. */
2580 lw_set_main_areas (pane_widget
, 0, frame_widget
);
2583 #else /* not USE_X_TOOLKIT */
2586 x_window (FRAME_PTR f
)
2588 if (! xg_create_frame_widgets (f
))
2589 error ("Unable to create window");
2592 FRAME_XIC (f
) = NULL
;
2596 create_frame_xic (f
);
2599 /* XIM server might require some X events. */
2600 unsigned long fevent
= NoEventMask
;
2601 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2603 if (fevent
!= NoEventMask
)
2605 XSetWindowAttributes attributes
;
2606 XWindowAttributes wattr
;
2607 unsigned long attribute_mask
;
2609 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2611 attributes
.event_mask
= wattr
.your_event_mask
| fevent
;
2612 attribute_mask
= CWEventMask
;
2613 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2614 attribute_mask
, &attributes
);
2622 #else /*! USE_GTK */
2623 /* Create and set up the X window for frame F. */
2626 x_window (struct frame
*f
)
2628 XClassHint class_hints
;
2629 XSetWindowAttributes attributes
;
2630 unsigned long attribute_mask
;
2632 attributes
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2633 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
2634 attributes
.bit_gravity
= StaticGravity
;
2635 attributes
.backing_store
= NotUseful
;
2636 attributes
.save_under
= True
;
2637 attributes
.event_mask
= STANDARD_EVENT_SET
;
2638 attributes
.colormap
= FRAME_X_COLORMAP (f
);
2639 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
2644 = XCreateWindow (FRAME_X_DISPLAY (f
),
2645 f
->output_data
.x
->parent_desc
,
2648 FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
),
2650 CopyFromParent
, /* depth */
2651 InputOutput
, /* class */
2653 attribute_mask
, &attributes
);
2658 create_frame_xic (f
);
2661 /* XIM server might require some X events. */
2662 unsigned long fevent
= NoEventMask
;
2663 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2664 attributes
.event_mask
|= fevent
;
2665 attribute_mask
= CWEventMask
;
2666 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2667 attribute_mask
, &attributes
);
2670 #endif /* HAVE_X_I18N */
2672 validate_x_resource_name ();
2674 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2675 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2676 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2678 /* The menubar is part of the ordinary display;
2679 it does not count in addition to the height of the window. */
2680 f
->output_data
.x
->menubar_height
= 0;
2682 /* This indicates that we use the "Passive Input" input model.
2683 Unless we do this, we don't get the Focus{In,Out} events that we
2684 need to draw the cursor correctly. Accursed bureaucrats.
2685 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2687 f
->output_data
.x
->wm_hints
.input
= True
;
2688 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2689 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2690 &f
->output_data
.x
->wm_hints
);
2691 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
2693 /* Request "save yourself" and "delete window" commands from wm. */
2696 protocols
[0] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2697 protocols
[1] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2698 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2701 /* x_set_name normally ignores requests to set the name if the
2702 requested name is the same as the current name. This is the one
2703 place where that assumption isn't correct; f->name is set, but
2704 the X server hasn't been told. */
2707 int explicit = f
->explicit_name
;
2709 f
->explicit_name
= 0;
2711 fset_name (f
, Qnil
);
2712 x_set_name (f
, name
, explicit);
2715 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2716 f
->output_data
.x
->current_cursor
2717 = f
->output_data
.x
->text_cursor
);
2721 if (FRAME_X_WINDOW (f
) == 0)
2722 error ("Unable to create window");
2725 #endif /* not USE_GTK */
2726 #endif /* not USE_X_TOOLKIT */
2728 /* Verify that the icon position args for this window are valid. */
2731 x_icon_verify (struct frame
*f
, Lisp_Object parms
)
2733 Lisp_Object icon_x
, icon_y
;
2735 /* Set the position of the icon. Note that twm groups all
2736 icons in an icon window. */
2737 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2738 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2739 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2741 CHECK_NUMBER (icon_x
);
2742 CHECK_NUMBER (icon_y
);
2744 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2745 error ("Both left and top icon corners of icon must be specified");
2748 /* Handle the icon stuff for this window. Perhaps later we might
2749 want an x_set_icon_position which can be called interactively as
2753 x_icon (struct frame
*f
, Lisp_Object parms
)
2755 Lisp_Object icon_x
, icon_y
;
2757 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2760 /* Set the position of the icon. Note that twm groups all
2761 icons in an icon window. */
2762 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2763 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2764 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2766 CHECK_TYPE_RANGED_INTEGER (int, icon_x
);
2767 CHECK_TYPE_RANGED_INTEGER (int, icon_y
);
2769 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2770 error ("Both left and top icon corners of icon must be specified");
2774 if (! EQ (icon_x
, Qunbound
))
2775 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2777 #if 0 /* x_get_arg removes the visibility parameter as a side effect,
2778 but x_create_frame still needs it. */
2779 /* Start up iconic or window? */
2780 x_wm_set_window_state
2781 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
2787 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
2794 /* Make the GCs needed for this window, setting the
2795 background, border and mouse colors; also create the
2796 mouse cursor and the gray border tile. */
2799 x_make_gc (struct frame
*f
)
2801 XGCValues gc_values
;
2805 /* Create the GCs of this frame.
2806 Note that many default values are used. */
2808 gc_values
.foreground
= FRAME_FOREGROUND_PIXEL (f
);
2809 gc_values
.background
= FRAME_BACKGROUND_PIXEL (f
);
2810 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2811 f
->output_data
.x
->normal_gc
2812 = XCreateGC (FRAME_X_DISPLAY (f
),
2814 GCLineWidth
| GCForeground
| GCBackground
,
2817 /* Reverse video style. */
2818 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2819 gc_values
.background
= FRAME_FOREGROUND_PIXEL (f
);
2820 f
->output_data
.x
->reverse_gc
2821 = XCreateGC (FRAME_X_DISPLAY (f
),
2823 GCForeground
| GCBackground
| GCLineWidth
,
2826 /* Cursor has cursor-color background, background-color foreground. */
2827 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2828 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
2829 gc_values
.fill_style
= FillOpaqueStippled
;
2830 f
->output_data
.x
->cursor_gc
2831 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2832 (GCForeground
| GCBackground
2833 | GCFillStyle
| GCLineWidth
),
2837 f
->output_data
.x
->white_relief
.gc
= 0;
2838 f
->output_data
.x
->black_relief
.gc
= 0;
2840 /* Create the gray border tile used when the pointer is not in
2841 the frame. Since this depends on the frame's pixel values,
2842 this must be done on a per-frame basis. */
2843 f
->output_data
.x
->border_tile
2844 = (XCreatePixmapFromBitmapData
2845 (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
2846 gray_bits
, gray_width
, gray_height
,
2847 FRAME_FOREGROUND_PIXEL (f
),
2848 FRAME_BACKGROUND_PIXEL (f
),
2849 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
2855 /* Free what was allocated in x_make_gc. */
2858 x_free_gcs (struct frame
*f
)
2860 Display
*dpy
= FRAME_X_DISPLAY (f
);
2864 if (f
->output_data
.x
->normal_gc
)
2866 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
2867 f
->output_data
.x
->normal_gc
= 0;
2870 if (f
->output_data
.x
->reverse_gc
)
2872 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
2873 f
->output_data
.x
->reverse_gc
= 0;
2876 if (f
->output_data
.x
->cursor_gc
)
2878 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
2879 f
->output_data
.x
->cursor_gc
= 0;
2882 if (f
->output_data
.x
->border_tile
)
2884 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
2885 f
->output_data
.x
->border_tile
= 0;
2892 /* Handler for signals raised during x_create_frame and
2893 x_create_tip_frame. FRAME is the frame which is partially
2897 unwind_create_frame (Lisp_Object frame
)
2899 struct frame
*f
= XFRAME (frame
);
2901 /* If frame is already dead, nothing to do. This can happen if the
2902 display is disconnected after the frame has become official, but
2903 before x_create_frame removes the unwind protect. */
2904 if (!FRAME_LIVE_P (f
))
2907 /* If frame is ``official'', nothing to do. */
2908 if (NILP (Fmemq (frame
, Vframe_list
)))
2910 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2911 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2914 x_free_frame_resources (f
);
2917 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2918 /* Check that reference counts are indeed correct. */
2919 eassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
2920 eassert (dpyinfo
->terminal
->image_cache
->refcount
== image_cache_refcount
);
2929 unwind_create_frame_1 (Lisp_Object val
)
2931 inhibit_lisp_code
= val
;
2936 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
2938 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2939 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
2941 Lisp_Object font
= Qnil
;
2942 if (EQ (font_param
, Qunbound
))
2945 if (NILP (font_param
))
2947 /* System font should take precedence over X resources. We suggest this
2948 regardless of font-use-system-font because .emacs may not have been
2950 const char *system_font
= xsettings_get_system_font ();
2952 font
= font_open_by_name (f
, build_unibyte_string (system_font
));
2956 font
= !NILP (font_param
) ? font_param
2957 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
2959 if (! FONTP (font
) && ! STRINGP (font
))
2964 /* This will find the normal Xft font. */
2967 "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1",
2968 "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2969 "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2970 /* This was formerly the first thing tried, but it finds
2971 too many fonts and takes too long. */
2972 "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1",
2973 /* If those didn't work, look for something which will
2975 "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1",
2980 for (i
= 0; names
[i
]; i
++)
2982 font
= font_open_by_name (f
, build_unibyte_string (names
[i
]));
2987 error ("No suitable font was found");
2989 else if (!NILP (font_param
))
2991 /* Remember the explicit font parameter, so we can re-apply it after
2992 we've applied the `default' face settings. */
2993 x_set_frame_parameters (f
, Fcons (Fcons (Qfont_param
, font_param
), Qnil
));
2996 /* This call will make X resources override any system font setting. */
2997 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
3001 DEFUN ("x-wm-set-size-hint", Fx_wm_set_size_hint
, Sx_wm_set_size_hint
,
3003 doc
: /* Send the size hints for frame FRAME to the window manager.
3004 If FRAME is nil, use the selected frame. */)
3009 frame
= selected_frame
;
3013 x_wm_set_size_hint (f
, 0, 0);
3019 set_machine_and_pid_properties (struct frame
*f
)
3021 long pid
= (long) getpid ();
3023 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME. */
3024 XSetWMProperties (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), NULL
, NULL
,
3025 NULL
, 0, NULL
, NULL
, NULL
);
3026 XChangeProperty (FRAME_X_DISPLAY (f
),
3027 FRAME_OUTER_WINDOW (f
),
3028 XInternAtom (FRAME_X_DISPLAY (f
),
3031 XA_CARDINAL
, 32, PropModeReplace
,
3032 (unsigned char *) &pid
, 1);
3035 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
3037 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
3038 Return an Emacs frame object.
3039 PARMS is an alist of frame parameters.
3040 If the parameters specify that the frame should not have a minibuffer,
3041 and do not specify a specific minibuffer window to use,
3042 then `default-minibuffer-frame' must be a frame whose minibuffer can
3043 be shared by the new frame.
3045 This function is an internal primitive--use `make-frame' instead. */)
3049 Lisp_Object frame
, tem
;
3051 int minibuffer_only
= 0;
3052 long window_prompting
= 0;
3054 ptrdiff_t count
= SPECPDL_INDEX ();
3055 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
3056 Lisp_Object display
;
3057 struct x_display_info
*dpyinfo
= NULL
;
3061 parms
= Fcopy_alist (parms
);
3063 /* Use this general default value to start with
3064 until we know if this frame has a specified name. */
3065 Vx_resource_name
= Vinvocation_name
;
3067 display
= x_get_arg (dpyinfo
, parms
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
3068 if (EQ (display
, Qunbound
))
3069 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
3070 if (EQ (display
, Qunbound
))
3072 dpyinfo
= check_x_display_info (display
);
3073 kb
= dpyinfo
->terminal
->kboard
;
3075 if (!dpyinfo
->terminal
->name
)
3076 error ("Terminal is not live, can't create new frames on it");
3078 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
3080 && ! EQ (name
, Qunbound
)
3082 error ("Invalid frame name--not a string or nil");
3085 Vx_resource_name
= name
;
3087 /* See if parent window is specified. */
3088 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
3089 if (EQ (parent
, Qunbound
))
3091 if (! NILP (parent
))
3092 CHECK_NUMBER (parent
);
3094 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
3095 /* No need to protect DISPLAY because that's not used after passing
3096 it to make_frame_without_minibuffer. */
3098 GCPRO4 (parms
, parent
, name
, frame
);
3099 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
3101 if (EQ (tem
, Qnone
) || NILP (tem
))
3102 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
3103 else if (EQ (tem
, Qonly
))
3105 f
= make_minibuffer_frame ();
3106 minibuffer_only
= 1;
3108 else if (WINDOWP (tem
))
3109 f
= make_frame_without_minibuffer (tem
, kb
, display
);
3113 XSETFRAME (frame
, f
);
3115 /* Note that X Windows does support scroll bars. */
3116 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
3118 f
->terminal
= dpyinfo
->terminal
;
3120 f
->output_method
= output_x_window
;
3121 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
3122 f
->output_data
.x
->icon_bitmap
= -1;
3123 FRAME_FONTSET (f
) = -1;
3124 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
3125 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
3126 #ifdef USE_TOOLKIT_SCROLL_BARS
3127 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
3128 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
3129 #endif /* USE_TOOLKIT_SCROLL_BARS */
3132 x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
3134 if (! STRINGP (f
->icon_name
))
3135 fset_icon_name (f
, Qnil
);
3137 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
3139 /* With FRAME_X_DISPLAY_INFO set up, this unwind-protect is safe. */
3140 record_unwind_protect (unwind_create_frame
, frame
);
3142 /* These colors will be set anyway later, but it's important
3143 to get the color reference counts right, so initialize them! */
3146 struct gcpro gcpro1
;
3148 /* Function x_decode_color can signal an error. Make
3149 sure to initialize color slots so that we won't try
3150 to free colors we haven't allocated. */
3151 FRAME_FOREGROUND_PIXEL (f
) = -1;
3152 FRAME_BACKGROUND_PIXEL (f
) = -1;
3153 f
->output_data
.x
->cursor_pixel
= -1;
3154 f
->output_data
.x
->cursor_foreground_pixel
= -1;
3155 f
->output_data
.x
->border_pixel
= -1;
3156 f
->output_data
.x
->mouse_pixel
= -1;
3158 black
= build_string ("black");
3160 FRAME_FOREGROUND_PIXEL (f
)
3161 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3162 FRAME_BACKGROUND_PIXEL (f
)
3163 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3164 f
->output_data
.x
->cursor_pixel
3165 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3166 f
->output_data
.x
->cursor_foreground_pixel
3167 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3168 f
->output_data
.x
->border_pixel
3169 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3170 f
->output_data
.x
->mouse_pixel
3171 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3175 /* Specify the parent under which to make this X window. */
3179 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
3180 f
->output_data
.x
->explicit_parent
= 1;
3184 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3185 f
->output_data
.x
->explicit_parent
= 0;
3188 /* Set the name; the functions to which we pass f expect the name to
3190 if (EQ (name
, Qunbound
) || NILP (name
))
3192 fset_name (f
, build_string (dpyinfo
->x_id_name
));
3193 f
->explicit_name
= 0;
3197 fset_name (f
, name
);
3198 f
->explicit_name
= 1;
3199 /* use the frame's title when getting resources for this frame. */
3200 specbind (Qx_resource_name
, name
);
3203 f
->resx
= dpyinfo
->resx
;
3204 f
->resy
= dpyinfo
->resy
;
3206 #ifdef HAVE_FREETYPE
3208 register_font_driver (&xftfont_driver
, f
);
3209 #else /* not HAVE_XFT */
3210 register_font_driver (&ftxfont_driver
, f
);
3211 #endif /* not HAVE_XFT */
3212 #endif /* HAVE_FREETYPE */
3213 register_font_driver (&xfont_driver
, f
);
3215 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
3216 "fontBackend", "FontBackend", RES_TYPE_STRING
);
3218 /* Extract the window parameters from the supplied values
3219 that are needed to determine window geometry. */
3220 x_default_font_parameter (f
, parms
);
3221 if (!FRAME_FONT (f
))
3223 delete_frame (frame
, Qnoelisp
);
3224 error ("Invalid frame font");
3227 /* Frame contents get displaced if an embedded X window has a border. */
3228 if (! FRAME_X_EMBEDDED_P (f
))
3229 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
3230 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
3232 /* This defaults to 1 in order to match xterm. We recognize either
3233 internalBorderWidth or internalBorder (which is what xterm calls
3235 if (NILP (Fassq (Qinternal_border_width
, parms
)))
3239 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
3240 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
3241 if (! EQ (value
, Qunbound
))
3242 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
3245 x_default_parameter (f
, parms
, Qinternal_border_width
,
3246 #ifdef USE_GTK /* We used to impose 0 in xg_create_frame_widgets. */
3251 "internalBorderWidth", "internalBorderWidth",
3253 x_default_parameter (f
, parms
, Qvertical_scroll_bars
,
3254 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
3259 "verticalScrollBars", "ScrollBars",
3262 /* Also do the stuff which must be set before the window exists. */
3263 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3264 "foreground", "Foreground", RES_TYPE_STRING
);
3265 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3266 "background", "Background", RES_TYPE_STRING
);
3267 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3268 "pointerColor", "Foreground", RES_TYPE_STRING
);
3269 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3270 "borderColor", "BorderColor", RES_TYPE_STRING
);
3271 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3272 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3273 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3274 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3275 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3276 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3277 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3278 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3280 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3281 "scrollBarForeground",
3282 "ScrollBarForeground", 1);
3283 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3284 "scrollBarBackground",
3285 "ScrollBarBackground", 0);
3288 image_cache_refcount
=
3289 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
3290 dpyinfo_refcount
= dpyinfo
->reference_count
;
3291 #endif /* GLYPH_DEBUG */
3293 /* Init faces before x_default_parameter is called for scroll-bar
3294 parameters because that function calls x_set_scroll_bar_width,
3295 which calls change_frame_size, which calls Fset_window_buffer,
3296 which runs hooks, which call Fvertical_motion. At the end, we
3297 end up in init_iterator with a null face cache, which should not
3299 init_frame_faces (f
);
3301 /* Set the menu-bar-lines and tool-bar-lines parameters. We don't
3302 look up the X resources controlling the menu-bar and tool-bar
3303 here; they are processed specially at startup, and reflected in
3304 the values of the mode variables.
3306 Avoid calling window-configuration-change-hook; otherwise we
3307 could get an infloop in next_frame since the frame is not yet in
3310 ptrdiff_t count2
= SPECPDL_INDEX ();
3311 record_unwind_protect (unwind_create_frame_1
, inhibit_lisp_code
);
3312 inhibit_lisp_code
= Qt
;
3314 x_default_parameter (f
, parms
, Qmenu_bar_lines
,
3315 NILP (Vmenu_bar_mode
)
3316 ? make_number (0) : make_number (1),
3317 NULL
, NULL
, RES_TYPE_NUMBER
);
3318 x_default_parameter (f
, parms
, Qtool_bar_lines
,
3319 NILP (Vtool_bar_mode
)
3320 ? make_number (0) : make_number (1),
3321 NULL
, NULL
, RES_TYPE_NUMBER
);
3323 unbind_to (count2
, Qnil
);
3326 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3327 "bufferPredicate", "BufferPredicate",
3329 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3330 "title", "Title", RES_TYPE_STRING
);
3331 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3332 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3333 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3334 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3335 x_default_parameter (f
, parms
, Qtool_bar_position
,
3336 f
->tool_bar_position
, 0, 0, RES_TYPE_SYMBOL
);
3338 /* Compute the size of the X window. */
3339 window_prompting
= x_figure_window_size (f
, parms
, 1);
3341 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3342 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3344 x_icon_verify (f
, parms
);
3346 /* Create the X widget or window. */
3347 #ifdef USE_X_TOOLKIT
3348 x_window (f
, window_prompting
, minibuffer_only
);
3356 /* Now consider the frame official. */
3357 f
->terminal
->reference_count
++;
3358 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
3359 Vframe_list
= Fcons (frame
, Vframe_list
);
3361 /* We need to do this after creating the X window, so that the
3362 icon-creation functions can say whose icon they're describing. */
3363 x_default_parameter (f
, parms
, Qicon_type
, Qt
,
3364 "bitmapIcon", "BitmapIcon", RES_TYPE_BOOLEAN
);
3366 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3367 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3368 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3369 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3370 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3371 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3372 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3373 "scrollBarWidth", "ScrollBarWidth",
3375 x_default_parameter (f
, parms
, Qalpha
, Qnil
,
3376 "alpha", "Alpha", RES_TYPE_NUMBER
);
3378 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
3379 Change will not be effected unless different from the current
3381 width
= FRAME_COLS (f
);
3382 height
= FRAME_LINES (f
);
3384 SET_FRAME_COLS (f
, 0);
3385 FRAME_LINES (f
) = 0;
3386 change_frame_size (f
, height
, width
, 1, 0, 0);
3388 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3389 /* Create the menu bar. */
3390 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3392 /* If this signals an error, we haven't set size hints for the
3393 frame and we didn't make it visible. */
3394 initialize_frame_menubar (f
);
3397 /* This is a no-op, except under Motif where it arranges the
3398 main window for the widgets on it. */
3399 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3400 f
->output_data
.x
->menubar_widget
,
3401 f
->output_data
.x
->edit_widget
);
3402 #endif /* not USE_GTK */
3404 #endif /* USE_X_TOOLKIT || USE_GTK */
3406 /* Tell the server what size and position, etc, we want, and how
3407 badly we want them. This should be done after we have the menu
3408 bar so that its size can be taken into account. */
3410 x_wm_set_size_hint (f
, window_prompting
, 0);
3413 /* Make the window appear on the frame and enable display, unless
3414 the caller says not to. However, with explicit parent, Emacs
3415 cannot control visibility, so don't try. */
3416 if (! f
->output_data
.x
->explicit_parent
)
3418 Lisp_Object visibility
;
3420 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3422 if (EQ (visibility
, Qunbound
))
3425 if (EQ (visibility
, Qicon
))
3426 x_iconify_frame (f
);
3427 else if (! NILP (visibility
))
3428 x_make_frame_visible (f
);
3431 /* Must have been Qnil. */
3437 /* Set machine name and pid for the purpose of window managers. */
3438 set_machine_and_pid_properties (f
);
3440 /* Set the WM leader property. GTK does this itself, so this is not
3441 needed when using GTK. */
3442 if (dpyinfo
->client_leader_window
!= 0)
3444 XChangeProperty (FRAME_X_DISPLAY (f
),
3445 FRAME_OUTER_WINDOW (f
),
3446 dpyinfo
->Xatom_wm_client_leader
,
3447 XA_WINDOW
, 32, PropModeReplace
,
3448 (unsigned char *) &dpyinfo
->client_leader_window
, 1);
3453 /* Initialize `default-minibuffer-frame' in case this is the first
3454 frame on this terminal. */
3455 if (FRAME_HAS_MINIBUF_P (f
)
3456 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
3457 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
3458 kset_default_minibuffer_frame (kb
, frame
);
3460 /* All remaining specified parameters, which have not been "used"
3461 by x_get_arg and friends, now go in the misc. alist of the frame. */
3462 for (tem
= parms
; CONSP (tem
); tem
= XCDR (tem
))
3463 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
3464 fset_param_alist (f
, Fcons (XCAR (tem
), f
->param_alist
));
3468 /* Make sure windows on this frame appear in calls to next-window
3469 and similar functions. */
3470 Vwindow_list
= Qnil
;
3472 return unbind_to (count
, frame
);
3476 /* FRAME is used only to get a handle on the X display. We don't pass the
3477 display info directly because we're called from frame.c, which doesn't
3478 know about that structure. */
3481 x_get_focus_frame (struct frame
*frame
)
3483 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (frame
);
3485 if (! dpyinfo
->x_focus_frame
)
3488 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3493 /* In certain situations, when the window manager follows a
3494 click-to-focus policy, there seems to be no way around calling
3495 XSetInputFocus to give another frame the input focus .
3497 In an ideal world, XSetInputFocus should generally be avoided so
3498 that applications don't interfere with the window manager's focus
3499 policy. But I think it's okay to use when it's clearly done
3500 following a user-command. */
3502 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
3503 doc
: /* Set the input focus to FRAME.
3504 FRAME nil means use the selected frame. */)
3507 struct frame
*f
= check_x_frame (frame
);
3508 Display
*dpy
= FRAME_X_DISPLAY (f
);
3511 x_catch_errors (dpy
);
3513 if (FRAME_X_EMBEDDED_P (f
))
3515 /* For Xembedded frames, normally the embedder forwards key
3516 events. See XEmbed Protocol Specification at
3517 http://freedesktop.org/wiki/Specifications/xembed-spec */
3518 xembed_request_focus (f
);
3522 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3523 RevertToParent
, CurrentTime
);
3524 x_ewmh_activate_frame (f
);
3527 x_uncatch_errors ();
3534 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
3535 doc
: /* Internal function called by `color-defined-p', which see
3536 .\(Note that the Nextstep version of this function ignores FRAME.) */)
3537 (Lisp_Object color
, Lisp_Object frame
)
3540 FRAME_PTR f
= check_x_frame (frame
);
3542 CHECK_STRING (color
);
3544 if (x_defined_color (f
, SSDATA (color
), &foo
, 0))
3550 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
3551 doc
: /* Internal function called by `color-values', which see. */)
3552 (Lisp_Object color
, Lisp_Object frame
)
3555 FRAME_PTR f
= check_x_frame (frame
);
3557 CHECK_STRING (color
);
3559 if (x_defined_color (f
, SSDATA (color
), &foo
, 0))
3560 return list3 (make_number (foo
.red
),
3561 make_number (foo
.green
),
3562 make_number (foo
.blue
));
3567 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
3568 doc
: /* Internal function called by `display-color-p', which see. */)
3569 (Lisp_Object terminal
)
3571 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3573 if (dpyinfo
->n_planes
<= 2)
3576 switch (dpyinfo
->visual
->class)
3589 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3591 doc
: /* Return t if the X display supports shades of gray.
3592 Note that color displays do support shades of gray.
3593 The optional argument TERMINAL specifies which display to ask about.
3594 TERMINAL should be a terminal object, a frame or a display name (a string).
3595 If omitted or nil, that stands for the selected frame's display. */)
3596 (Lisp_Object terminal
)
3598 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3600 if (dpyinfo
->n_planes
<= 1)
3603 switch (dpyinfo
->visual
->class)
3618 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3620 doc
: /* Return the width in pixels of the X display TERMINAL.
3621 The optional argument TERMINAL specifies which display to ask about.
3622 TERMINAL should be a terminal object, a frame or a display name (a string).
3623 If omitted or nil, that stands for the selected frame's display. */)
3624 (Lisp_Object terminal
)
3626 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3628 return make_number (x_display_pixel_width (dpyinfo
));
3631 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3632 Sx_display_pixel_height
, 0, 1, 0,
3633 doc
: /* Return the height in pixels of the X display TERMINAL.
3634 The optional argument TERMINAL specifies which display to ask about.
3635 TERMINAL should be a terminal object, a frame or a display name (a string).
3636 If omitted or nil, that stands for the selected frame's display. */)
3637 (Lisp_Object terminal
)
3639 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3641 return make_number (x_display_pixel_height (dpyinfo
));
3644 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3646 doc
: /* Return the number of bitplanes of the X display TERMINAL.
3647 The optional argument TERMINAL specifies which display to ask about.
3648 TERMINAL should be a terminal object, a frame or a display name (a string).
3649 If omitted or nil, that stands for the selected frame's display. */)
3650 (Lisp_Object terminal
)
3652 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3654 return make_number (dpyinfo
->n_planes
);
3657 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3659 doc
: /* Return the number of color cells of the X display TERMINAL.
3660 The optional argument TERMINAL specifies which display to ask about.
3661 TERMINAL should be a terminal object, a frame or a display name (a string).
3662 If omitted or nil, that stands for the selected frame's display. */)
3663 (Lisp_Object terminal
)
3665 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3667 int nr_planes
= DisplayPlanes (dpyinfo
->display
,
3668 XScreenNumberOfScreen (dpyinfo
->screen
));
3670 /* Truncate nr_planes to 24 to avoid integer overflow.
3671 Some displays says 32, but only 24 bits are actually significant.
3672 There are only very few and rare video cards that have more than
3673 24 significant bits. Also 24 bits is more than 16 million colors,
3674 it "should be enough for everyone". */
3675 if (nr_planes
> 24) nr_planes
= 24;
3677 return make_number (1 << nr_planes
);
3680 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3681 Sx_server_max_request_size
,
3683 doc
: /* Return the maximum request size of the X server of display TERMINAL.
3684 The optional argument TERMINAL specifies which display to ask about.
3685 TERMINAL should be a terminal object, a frame or a display name (a string).
3686 If omitted or nil, that stands for the selected frame's display. */)
3687 (Lisp_Object terminal
)
3689 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3691 return make_number (MAXREQUEST (dpyinfo
->display
));
3694 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3695 doc
: /* Return the "vendor ID" string of the X server of display TERMINAL.
3696 \(Labeling every distributor as a "vendor" embodies the false assumption
3697 that operating systems cannot be developed and distributed noncommercially.)
3698 The optional argument TERMINAL specifies which display to ask about.
3699 TERMINAL should be a terminal object, a frame or a display name (a string).
3700 If omitted or nil, that stands for the selected frame's display. */)
3701 (Lisp_Object terminal
)
3703 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3704 const char *vendor
= ServerVendor (dpyinfo
->display
);
3706 if (! vendor
) vendor
= "";
3707 return build_string (vendor
);
3710 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3711 doc
: /* Return the version numbers of the X server of display TERMINAL.
3712 The value is a list of three integers: the major and minor
3713 version numbers of the X Protocol in use, and the distributor-specific release
3714 number. See also the function `x-server-vendor'.
3716 The optional argument TERMINAL specifies which display to ask about.
3717 TERMINAL should be a terminal object, a frame or a display name (a string).
3718 If omitted or nil, that stands for the selected frame's display. */)
3719 (Lisp_Object terminal
)
3721 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3722 Display
*dpy
= dpyinfo
->display
;
3724 return Fcons (make_number (ProtocolVersion (dpy
)),
3725 Fcons (make_number (ProtocolRevision (dpy
)),
3726 Fcons (make_number (VendorRelease (dpy
)), Qnil
)));
3729 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3730 doc
: /* Return the number of screens on the X server of display TERMINAL.
3731 The optional argument TERMINAL specifies which display to ask about.
3732 TERMINAL should be a terminal object, a frame or a display name (a string).
3733 If omitted or nil, that stands for the selected frame's display. */)
3734 (Lisp_Object terminal
)
3736 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3738 return make_number (ScreenCount (dpyinfo
->display
));
3741 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3742 doc
: /* Return the height in millimeters of the X display TERMINAL.
3743 The optional argument TERMINAL specifies which display to ask about.
3744 TERMINAL should be a terminal object, a frame or a display name (a string).
3745 If omitted or nil, that stands for the selected frame's display. */)
3746 (Lisp_Object terminal
)
3748 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3750 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3753 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3754 doc
: /* Return the width in millimeters of the X display TERMINAL.
3755 The optional argument TERMINAL specifies which display to ask about.
3756 TERMINAL should be a terminal object, a frame or a display name (a string).
3757 If omitted or nil, that stands for the selected frame's display. */)
3758 (Lisp_Object terminal
)
3760 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3762 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3765 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3766 Sx_display_backing_store
, 0, 1, 0,
3767 doc
: /* Return an indication of whether X display TERMINAL does backing store.
3768 The value may be `always', `when-mapped', or `not-useful'.
3769 The optional argument TERMINAL specifies which display to ask about.
3770 TERMINAL should be a terminal object, a frame or a display name (a string).
3771 If omitted or nil, that stands for the selected frame's display. */)
3772 (Lisp_Object terminal
)
3774 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3777 switch (DoesBackingStore (dpyinfo
->screen
))
3780 result
= intern ("always");
3784 result
= intern ("when-mapped");
3788 result
= intern ("not-useful");
3792 error ("Strange value for BackingStore parameter of screen");
3799 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3800 Sx_display_visual_class
, 0, 1, 0,
3801 doc
: /* Return the visual class of the X display TERMINAL.
3802 The value is one of the symbols `static-gray', `gray-scale',
3803 `static-color', `pseudo-color', `true-color', or `direct-color'.
3805 The optional argument TERMINAL specifies which display to ask about.
3806 TERMINAL should a terminal object, a frame or a display name (a string).
3807 If omitted or nil, that stands for the selected frame's display. */)
3808 (Lisp_Object terminal
)
3810 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3813 switch (dpyinfo
->visual
->class)
3816 result
= intern ("static-gray");
3819 result
= intern ("gray-scale");
3822 result
= intern ("static-color");
3825 result
= intern ("pseudo-color");
3828 result
= intern ("true-color");
3831 result
= intern ("direct-color");
3834 error ("Display has an unknown visual class");
3841 DEFUN ("x-display-save-under", Fx_display_save_under
,
3842 Sx_display_save_under
, 0, 1, 0,
3843 doc
: /* Return t if the X display TERMINAL supports the save-under feature.
3844 The optional argument TERMINAL specifies which display to ask about.
3845 TERMINAL should be a terminal object, a frame or a display name (a string).
3846 If omitted or nil, that stands for the selected frame's display. */)
3847 (Lisp_Object terminal
)
3849 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3851 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3858 x_pixel_width (register struct frame
*f
)
3860 return FRAME_PIXEL_WIDTH (f
);
3864 x_pixel_height (register struct frame
*f
)
3866 return FRAME_PIXEL_HEIGHT (f
);
3870 x_char_width (register struct frame
*f
)
3872 return FRAME_COLUMN_WIDTH (f
);
3876 x_char_height (register struct frame
*f
)
3878 return FRAME_LINE_HEIGHT (f
);
3883 /************************************************************************
3885 ************************************************************************/
3888 /* Mapping visual names to visuals. */
3890 static struct visual_class
3897 {"StaticGray", StaticGray
},
3898 {"GrayScale", GrayScale
},
3899 {"StaticColor", StaticColor
},
3900 {"PseudoColor", PseudoColor
},
3901 {"TrueColor", TrueColor
},
3902 {"DirectColor", DirectColor
},
3907 #ifndef HAVE_XSCREENNUMBEROFSCREEN
3909 /* Value is the screen number of screen SCR. This is a substitute for
3910 the X function with the same name when that doesn't exist. */
3913 XScreenNumberOfScreen (scr
)
3914 register Screen
*scr
;
3916 Display
*dpy
= scr
->display
;
3919 for (i
= 0; i
< dpy
->nscreens
; ++i
)
3920 if (scr
== dpy
->screens
+ i
)
3926 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
3929 /* Select the visual that should be used on display DPYINFO. Set
3930 members of DPYINFO appropriately. Called from x_term_init. */
3933 select_visual (struct x_display_info
*dpyinfo
)
3935 Display
*dpy
= dpyinfo
->display
;
3936 Screen
*screen
= dpyinfo
->screen
;
3939 /* See if a visual is specified. */
3940 value
= display_x_get_resource (dpyinfo
,
3941 build_string ("visualClass"),
3942 build_string ("VisualClass"),
3944 if (STRINGP (value
))
3946 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
3947 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
3948 depth, a decimal number. NAME is compared with case ignored. */
3949 char *s
= alloca (SBYTES (value
) + 1);
3954 strcpy (s
, SSDATA (value
));
3955 dash
= strchr (s
, '-');
3958 dpyinfo
->n_planes
= atoi (dash
+ 1);
3962 /* We won't find a matching visual with depth 0, so that
3963 an error will be printed below. */
3964 dpyinfo
->n_planes
= 0;
3966 /* Determine the visual class. */
3967 for (i
= 0; visual_classes
[i
].name
; ++i
)
3968 if (xstrcasecmp (s
, visual_classes
[i
].name
) == 0)
3970 class = visual_classes
[i
].class;
3974 /* Look up a matching visual for the specified class. */
3976 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
3977 dpyinfo
->n_planes
, class, &vinfo
))
3978 fatal ("Invalid visual specification `%s'", SDATA (value
));
3980 dpyinfo
->visual
= vinfo
.visual
;
3985 XVisualInfo
*vinfo
, vinfo_template
;
3987 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
3989 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
3990 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
3991 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
3992 &vinfo_template
, &n_visuals
);
3994 fatal ("Can't get proper X visual info");
3996 dpyinfo
->n_planes
= vinfo
->depth
;
4002 /* Return the X display structure for the display named NAME.
4003 Open a new connection if necessary. */
4005 static struct x_display_info
*
4006 x_display_info_for_name (Lisp_Object name
)
4009 struct x_display_info
*dpyinfo
;
4011 CHECK_STRING (name
);
4014 if (! EQ (Vinitial_window_system
, intern ("x")))
4015 error ("Not using X Windows"); /* That doesn't stop us anymore. */
4018 for (dpyinfo
= x_display_list
, names
= x_display_name_list
;
4020 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
4023 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
4028 /* Use this general default value to start with. */
4029 Vx_resource_name
= Vinvocation_name
;
4031 validate_x_resource_name ();
4033 dpyinfo
= x_term_init (name
, (char *)0,
4034 SSDATA (Vx_resource_name
));
4037 error ("Cannot connect to X server %s", SDATA (name
));
4040 XSETFASTINT (Vwindow_system_version
, 11);
4046 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4048 doc
: /* Open a connection to a display server.
4049 DISPLAY is the name of the display to connect to.
4050 Optional second arg XRM-STRING is a string of resources in xrdb format.
4051 If the optional third arg MUST-SUCCEED is non-nil,
4052 terminate Emacs if we can't open the connection.
4053 \(In the Nextstep version, the last two arguments are currently ignored.) */)
4054 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
4057 struct x_display_info
*dpyinfo
;
4059 CHECK_STRING (display
);
4060 if (! NILP (xrm_string
))
4061 CHECK_STRING (xrm_string
);
4064 if (! EQ (Vinitial_window_system
, intern ("x")))
4065 error ("Not using X Windows"); /* That doesn't stop us anymore. */
4068 if (! NILP (xrm_string
))
4069 xrm_option
= SSDATA (xrm_string
);
4071 xrm_option
= (char *) 0;
4073 validate_x_resource_name ();
4075 /* This is what opens the connection and sets x_current_display.
4076 This also initializes many symbols, such as those used for input. */
4077 dpyinfo
= x_term_init (display
, xrm_option
,
4078 SSDATA (Vx_resource_name
));
4082 if (!NILP (must_succeed
))
4083 fatal ("Cannot connect to X server %s.\n\
4084 Check the DISPLAY environment variable or use `-d'.\n\
4085 Also use the `xauth' program to verify that you have the proper\n\
4086 authorization information needed to connect the X server.\n\
4087 An insecure way to solve the problem may be to use `xhost'.\n",
4090 error ("Cannot connect to X server %s", SDATA (display
));
4095 XSETFASTINT (Vwindow_system_version
, 11);
4099 DEFUN ("x-close-connection", Fx_close_connection
,
4100 Sx_close_connection
, 1, 1, 0,
4101 doc
: /* Close the connection to TERMINAL's X server.
4102 For TERMINAL, specify a terminal object, a frame or a display name (a
4103 string). If TERMINAL is nil, that stands for the selected frame's
4105 (Lisp_Object terminal
)
4107 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4109 if (dpyinfo
->reference_count
> 0)
4110 error ("Display still has frames on it");
4112 x_delete_terminal (dpyinfo
->terminal
);
4117 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4118 doc
: /* Return the list of display names that Emacs has connections to. */)
4121 Lisp_Object tail
, result
;
4124 for (tail
= x_display_name_list
; CONSP (tail
); tail
= XCDR (tail
))
4125 result
= Fcons (XCAR (XCAR (tail
)), result
);
4130 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4131 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
4132 This function only has an effect on X Windows. With MS Windows, it is
4133 defined but does nothing.
4135 If ON is nil, allow buffering of requests.
4136 Turning on synchronization prohibits the Xlib routines from buffering
4137 requests and seriously degrades performance, but makes debugging much
4139 The optional second argument TERMINAL specifies which display to act on.
4140 TERMINAL should be a terminal object, a frame or a display name (a string).
4141 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
4142 (Lisp_Object on
, Lisp_Object terminal
)
4144 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4146 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
4151 /* Wait for responses to all X commands issued so far for frame F. */
4154 x_sync (FRAME_PTR f
)
4157 XSync (FRAME_X_DISPLAY (f
), False
);
4162 /***********************************************************************
4164 ***********************************************************************/
4166 DEFUN ("x-change-window-property", Fx_change_window_property
,
4167 Sx_change_window_property
, 2, 6, 0,
4168 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
4169 PROP must be a string. VALUE may be a string or a list of conses,
4170 numbers and/or strings. If an element in the list is a string, it is
4171 converted to an atom and the value of the atom is used. If an element
4172 is a cons, it is converted to a 32 bit number where the car is the 16
4173 top bits and the cdr is the lower 16 bits.
4175 FRAME nil or omitted means use the selected frame.
4176 If TYPE is given and non-nil, it is the name of the type of VALUE.
4177 If TYPE is not given or nil, the type is STRING.
4178 FORMAT gives the size in bits of each element if VALUE is a list.
4179 It must be one of 8, 16 or 32.
4180 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4181 If OUTER-P is non-nil, the property is changed for the outer X window of
4182 FRAME. Default is to change on the edit X window. */)
4183 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
,
4184 Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
4186 struct frame
*f
= check_x_frame (frame
);
4188 Atom target_type
= XA_STRING
;
4189 int element_format
= 8;
4190 unsigned char *data
;
4194 CHECK_STRING (prop
);
4196 if (! NILP (format
))
4198 CHECK_NUMBER (format
);
4200 if (XINT (format
) != 8 && XINT (format
) != 16
4201 && XINT (format
) != 32)
4202 error ("FORMAT must be one of 8, 16 or 32");
4203 element_format
= XINT (format
);
4210 nelements
= x_check_property_data (value
);
4211 if (nelements
== -1)
4212 error ("Bad data in VALUE, must be number, string or cons");
4214 /* The man page for XChangeProperty:
4215 "If the specified format is 32, the property data must be a
4217 This applies even if long is more than 32 bits. The X library
4218 converts to 32 bits before sending to the X server. */
4219 elsize
= element_format
== 32 ? sizeof (long) : element_format
>> 3;
4220 data
= xnmalloc (nelements
, elsize
);
4222 x_fill_property_data (FRAME_X_DISPLAY (f
), value
, data
, element_format
);
4226 CHECK_STRING (value
);
4227 data
= SDATA (value
);
4228 if (INT_MAX
< SBYTES (value
))
4229 error ("VALUE too long");
4230 nelements
= SBYTES (value
);
4234 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4237 CHECK_STRING (type
);
4238 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
4241 if (! NILP (outer_p
)) w
= FRAME_OUTER_WINDOW (f
);
4242 else w
= FRAME_X_WINDOW (f
);
4244 XChangeProperty (FRAME_X_DISPLAY (f
), w
,
4245 prop_atom
, target_type
, element_format
, PropModeReplace
,
4248 if (CONSP (value
)) xfree (data
);
4250 /* Make sure the property is set when we return. */
4251 XFlush (FRAME_X_DISPLAY (f
));
4258 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
4259 Sx_delete_window_property
, 1, 2, 0,
4260 doc
: /* Remove window property PROP from X window of FRAME.
4261 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4262 (Lisp_Object prop
, Lisp_Object frame
)
4264 struct frame
*f
= check_x_frame (frame
);
4267 CHECK_STRING (prop
);
4269 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4270 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
4272 /* Make sure the property is removed when we return. */
4273 XFlush (FRAME_X_DISPLAY (f
));
4280 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
4282 doc
: /* Value is the value of window property PROP on FRAME.
4283 If FRAME is nil or omitted, use the selected frame.
4285 On X Windows, the following optional arguments are also accepted:
4286 If TYPE is nil or omitted, get the property as a string.
4287 Otherwise TYPE is the name of the atom that denotes the type expected.
4288 If SOURCE is non-nil, get the property on that window instead of from
4289 FRAME. The number 0 denotes the root window.
4290 If DELETE-P is non-nil, delete the property after retrieving it.
4291 If VECTOR-RET-P is non-nil, don't return a string but a vector of values.
4293 On MS Windows, this function accepts but ignores those optional arguments.
4295 Value is nil if FRAME hasn't a property with name PROP or if PROP has
4296 no value of TYPE (always string in the MS Windows case). */)
4297 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
,
4298 Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
4300 struct frame
*f
= check_x_frame (frame
);
4303 Lisp_Object prop_value
= Qnil
;
4304 unsigned char *tmp_data
= NULL
;
4306 Atom target_type
= XA_STRING
;
4308 unsigned long actual_size
, bytes_remaining
;
4309 Window target_window
= FRAME_X_WINDOW (f
);
4310 struct gcpro gcpro1
;
4312 GCPRO1 (prop_value
);
4313 CHECK_STRING (prop
);
4315 if (! NILP (source
))
4317 CONS_TO_INTEGER (source
, Window
, target_window
);
4318 if (! target_window
)
4319 target_window
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4325 if (strcmp ("AnyPropertyType", SSDATA (type
)) == 0)
4326 target_type
= AnyPropertyType
;
4328 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
4331 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4332 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4333 prop_atom
, 0, 0, False
, target_type
,
4334 &actual_type
, &actual_format
, &actual_size
,
4335 &bytes_remaining
, &tmp_data
);
4338 int size
= bytes_remaining
;
4343 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4344 prop_atom
, 0, bytes_remaining
,
4345 ! NILP (delete_p
), target_type
,
4346 &actual_type
, &actual_format
,
4347 &actual_size
, &bytes_remaining
,
4349 if (rc
== Success
&& tmp_data
)
4351 /* The man page for XGetWindowProperty says:
4352 "If the returned format is 32, the returned data is represented
4353 as a long array and should be cast to that type to obtain the
4355 This applies even if long is more than 32 bits, the X library
4356 converts from 32 bit elements received from the X server to long
4357 and passes the long array to us. Thus, for that case memcpy can not
4358 be used. We convert to a 32 bit type here, because so much code
4361 The bytes and offsets passed to XGetWindowProperty refers to the
4362 property and those are indeed in 32 bit quantities if format is
4365 if (32 < BITS_PER_LONG
&& actual_format
== 32)
4368 int *idata
= (int *) tmp_data
;
4369 long *ldata
= (long *) tmp_data
;
4371 for (i
= 0; i
< actual_size
; ++i
)
4372 idata
[i
] = (int) ldata
[i
];
4375 if (NILP (vector_ret_p
))
4376 prop_value
= make_string ((char *) tmp_data
, size
);
4378 prop_value
= x_property_data_to_lisp (f
,
4385 if (tmp_data
) XFree (tmp_data
);
4395 /***********************************************************************
4397 ***********************************************************************/
4399 /* Timer function of hourglass_atimer. TIMER is equal to
4402 Display an hourglass pointer on all frames by mapping the frames'
4403 hourglass_window. Set the hourglass_p flag in the frames'
4404 output_data.x structure to indicate that an hourglass cursor is
4405 shown on the frames. */
4408 show_hourglass (struct atimer
*timer
)
4410 /* The timer implementation will cancel this timer automatically
4411 after this function has run. Set hourglass_atimer to null
4412 so that we know the timer doesn't have to be canceled. */
4413 hourglass_atimer
= NULL
;
4415 if (!hourglass_shown_p
)
4417 Lisp_Object rest
, frame
;
4421 FOR_EACH_FRAME (rest
, frame
)
4423 struct frame
*f
= XFRAME (frame
);
4425 if (FRAME_LIVE_P (f
) && FRAME_X_P (f
) && FRAME_X_DISPLAY (f
))
4427 Display
*dpy
= FRAME_X_DISPLAY (f
);
4429 #ifdef USE_X_TOOLKIT
4430 if (f
->output_data
.x
->widget
)
4432 if (FRAME_OUTER_WINDOW (f
))
4435 f
->output_data
.x
->hourglass_p
= 1;
4437 if (!f
->output_data
.x
->hourglass_window
)
4439 unsigned long mask
= CWCursor
;
4440 XSetWindowAttributes attrs
;
4442 Window parent
= FRAME_X_WINDOW (f
);
4444 Window parent
= FRAME_OUTER_WINDOW (f
);
4446 attrs
.cursor
= f
->output_data
.x
->hourglass_cursor
;
4448 f
->output_data
.x
->hourglass_window
4449 = XCreateWindow (dpy
, parent
,
4450 0, 0, 32000, 32000, 0, 0,
4456 XMapRaised (dpy
, f
->output_data
.x
->hourglass_window
);
4462 hourglass_shown_p
= 1;
4468 /* Hide the hourglass pointer on all frames, if it is currently
4472 hide_hourglass (void)
4474 if (hourglass_shown_p
)
4476 Lisp_Object rest
, frame
;
4479 FOR_EACH_FRAME (rest
, frame
)
4481 struct frame
*f
= XFRAME (frame
);
4484 /* Watch out for newly created frames. */
4485 && f
->output_data
.x
->hourglass_window
)
4487 XUnmapWindow (FRAME_X_DISPLAY (f
),
4488 f
->output_data
.x
->hourglass_window
);
4489 /* Sync here because XTread_socket looks at the
4490 hourglass_p flag that is reset to zero below. */
4491 XSync (FRAME_X_DISPLAY (f
), False
);
4492 f
->output_data
.x
->hourglass_p
= 0;
4496 hourglass_shown_p
= 0;
4503 /***********************************************************************
4505 ***********************************************************************/
4507 static Lisp_Object
x_create_tip_frame (struct x_display_info
*,
4508 Lisp_Object
, Lisp_Object
);
4509 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
4510 Lisp_Object
, int, int, int *, int *);
4512 /* The frame of a currently visible tooltip. */
4514 Lisp_Object tip_frame
;
4516 /* If non-nil, a timer started that hides the last tooltip when it
4519 static Lisp_Object tip_timer
;
4522 /* If non-nil, a vector of 3 elements containing the last args
4523 with which x-show-tip was called. See there. */
4525 static Lisp_Object last_show_tip_args
;
4529 unwind_create_tip_frame (Lisp_Object frame
)
4531 Lisp_Object deleted
;
4533 deleted
= unwind_create_frame (frame
);
4534 if (EQ (deleted
, Qt
))
4544 /* Create a frame for a tooltip on the display described by DPYINFO.
4545 PARMS is a list of frame parameters. TEXT is the string to
4546 display in the tip frame. Value is the frame.
4548 Note that functions called here, esp. x_default_parameter can
4549 signal errors, for instance when a specified color name is
4550 undefined. We have to make sure that we're in a consistent state
4551 when this happens. */
4554 x_create_tip_frame (struct x_display_info
*dpyinfo
,
4562 ptrdiff_t count
= SPECPDL_INDEX ();
4563 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4564 int face_change_count_before
= face_change_count
;
4566 struct buffer
*old_buffer
;
4570 if (!dpyinfo
->terminal
->name
)
4571 error ("Terminal is not live, can't create new frames on it");
4573 parms
= Fcopy_alist (parms
);
4575 /* Get the name of the frame to use for resource lookup. */
4576 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
4578 && !EQ (name
, Qunbound
)
4580 error ("Invalid frame name--not a string or nil");
4583 GCPRO3 (parms
, name
, frame
);
4585 XSETFRAME (frame
, f
);
4587 buffer
= Fget_buffer_create (build_string (" *tip*"));
4588 /* Use set_window_buffer instead of Fset_window_buffer (see
4589 discussion of bug#11984, bug#12025, bug#12026). */
4590 set_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, 0, 0);
4591 old_buffer
= current_buffer
;
4592 set_buffer_internal_1 (XBUFFER (buffer
));
4593 bset_truncate_lines (current_buffer
, Qnil
);
4594 specbind (Qinhibit_read_only
, Qt
);
4595 specbind (Qinhibit_modification_hooks
, Qt
);
4598 set_buffer_internal_1 (old_buffer
);
4600 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
4601 record_unwind_protect (unwind_create_tip_frame
, frame
);
4603 f
->terminal
= dpyinfo
->terminal
;
4605 /* By setting the output method, we're essentially saying that
4606 the frame is live, as per FRAME_LIVE_P. If we get a signal
4607 from this point on, x_destroy_window might screw up reference
4609 f
->output_method
= output_x_window
;
4610 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
4611 f
->output_data
.x
->icon_bitmap
= -1;
4612 FRAME_FONTSET (f
) = -1;
4613 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
4614 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
4615 #ifdef USE_TOOLKIT_SCROLL_BARS
4616 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
4617 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
4618 #endif /* USE_TOOLKIT_SCROLL_BARS */
4619 fset_icon_name (f
, Qnil
);
4620 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
4621 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4622 f
->output_data
.x
->explicit_parent
= 0;
4624 /* These colors will be set anyway later, but it's important
4625 to get the color reference counts right, so initialize them! */
4628 struct gcpro gcpro1
;
4630 /* Function x_decode_color can signal an error. Make
4631 sure to initialize color slots so that we won't try
4632 to free colors we haven't allocated. */
4633 FRAME_FOREGROUND_PIXEL (f
) = -1;
4634 FRAME_BACKGROUND_PIXEL (f
) = -1;
4635 f
->output_data
.x
->cursor_pixel
= -1;
4636 f
->output_data
.x
->cursor_foreground_pixel
= -1;
4637 f
->output_data
.x
->border_pixel
= -1;
4638 f
->output_data
.x
->mouse_pixel
= -1;
4640 black
= build_string ("black");
4642 FRAME_FOREGROUND_PIXEL (f
)
4643 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4644 FRAME_BACKGROUND_PIXEL (f
)
4645 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4646 f
->output_data
.x
->cursor_pixel
4647 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4648 f
->output_data
.x
->cursor_foreground_pixel
4649 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4650 f
->output_data
.x
->border_pixel
4651 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4652 f
->output_data
.x
->mouse_pixel
4653 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4657 /* Set the name; the functions to which we pass f expect the name to
4659 if (EQ (name
, Qunbound
) || NILP (name
))
4661 fset_name (f
, build_string (dpyinfo
->x_id_name
));
4662 f
->explicit_name
= 0;
4666 fset_name (f
, name
);
4667 f
->explicit_name
= 1;
4668 /* use the frame's title when getting resources for this frame. */
4669 specbind (Qx_resource_name
, name
);
4672 f
->resx
= dpyinfo
->resx
;
4673 f
->resy
= dpyinfo
->resy
;
4675 register_font_driver (&xfont_driver
, f
);
4676 #ifdef HAVE_FREETYPE
4678 register_font_driver (&xftfont_driver
, f
);
4679 #else /* not HAVE_XFT */
4680 register_font_driver (&ftxfont_driver
, f
);
4681 #endif /* not HAVE_XFT */
4682 #endif /* HAVE_FREETYPE */
4684 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
4685 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4687 /* Extract the window parameters from the supplied values that are
4688 needed to determine window geometry. */
4689 x_default_font_parameter (f
, parms
);
4691 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
4692 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4694 /* This defaults to 2 in order to match xterm. We recognize either
4695 internalBorderWidth or internalBorder (which is what xterm calls
4697 if (NILP (Fassq (Qinternal_border_width
, parms
)))
4701 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
4702 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
4703 if (! EQ (value
, Qunbound
))
4704 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
4708 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
4709 "internalBorderWidth", "internalBorderWidth",
4712 /* Also do the stuff which must be set before the window exists. */
4713 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
4714 "foreground", "Foreground", RES_TYPE_STRING
);
4715 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
4716 "background", "Background", RES_TYPE_STRING
);
4717 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
4718 "pointerColor", "Foreground", RES_TYPE_STRING
);
4719 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
4720 "cursorColor", "Foreground", RES_TYPE_STRING
);
4721 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
4722 "borderColor", "BorderColor", RES_TYPE_STRING
);
4725 image_cache_refcount
=
4726 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
4727 dpyinfo_refcount
= dpyinfo
->reference_count
;
4728 #endif /* GLYPH_DEBUG */
4730 /* Init faces before x_default_parameter is called for scroll-bar
4731 parameters because that function calls x_set_scroll_bar_width,
4732 which calls change_frame_size, which calls Fset_window_buffer,
4733 which runs hooks, which call Fvertical_motion. At the end, we
4734 end up in init_iterator with a null face cache, which should not
4736 init_frame_faces (f
);
4738 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4740 x_figure_window_size (f
, parms
, 0);
4743 XSetWindowAttributes attrs
;
4745 Atom type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_net_window_type_tooltip
;
4748 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
;
4749 if (DoesSaveUnders (dpyinfo
->screen
))
4750 mask
|= CWSaveUnder
;
4752 /* Window managers look at the override-redirect flag to determine
4753 whether or net to give windows a decoration (Xlib spec, chapter
4755 attrs
.override_redirect
= True
;
4756 attrs
.save_under
= True
;
4757 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
4758 /* Arrange for getting MapNotify and UnmapNotify events. */
4759 attrs
.event_mask
= StructureNotifyMask
;
4761 = FRAME_X_WINDOW (f
)
4762 = XCreateWindow (FRAME_X_DISPLAY (f
),
4763 FRAME_X_DISPLAY_INFO (f
)->root_window
,
4764 /* x, y, width, height */
4768 CopyFromParent
, InputOutput
, CopyFromParent
,
4770 XChangeProperty (FRAME_X_DISPLAY (f
), tip_window
,
4771 FRAME_X_DISPLAY_INFO (f
)->Xatom_net_window_type
,
4772 XA_ATOM
, 32, PropModeReplace
,
4773 (unsigned char *)&type
, 1);
4779 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
4780 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4781 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
4782 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4783 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
4784 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4786 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4787 Change will not be effected unless different from the current
4789 width
= FRAME_COLS (f
);
4790 height
= FRAME_LINES (f
);
4791 SET_FRAME_COLS (f
, 0);
4792 FRAME_LINES (f
) = 0;
4793 change_frame_size (f
, height
, width
, 1, 0, 0);
4795 /* Add `tooltip' frame parameter's default value. */
4796 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
4797 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qtooltip
, Qt
), Qnil
));
4799 /* FIXME - can this be done in a similar way to normal frames?
4800 http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00641.html */
4802 /* Set the `display-type' frame parameter before setting up faces. */
4804 Lisp_Object disptype
;
4806 if (FRAME_X_DISPLAY_INFO (f
)->n_planes
== 1)
4807 disptype
= intern ("mono");
4808 else if (FRAME_X_DISPLAY_INFO (f
)->visual
->class == GrayScale
4809 || FRAME_X_DISPLAY_INFO (f
)->visual
->class == StaticGray
)
4810 disptype
= intern ("grayscale");
4812 disptype
= intern ("color");
4814 if (NILP (Fframe_parameter (frame
, Qdisplay_type
)))
4815 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qdisplay_type
, disptype
),
4819 /* Set up faces after all frame parameters are known. This call
4820 also merges in face attributes specified for new frames.
4822 Frame parameters may be changed if .Xdefaults contains
4823 specifications for the default font. For example, if there is an
4824 `Emacs.default.attributeBackground: pink', the `background-color'
4825 attribute of the frame get's set, which let's the internal border
4826 of the tooltip frame appear in pink. Prevent this. */
4828 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
4830 /* Set tip_frame here, so that */
4832 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
4834 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
4835 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
4843 /* Now that the frame will be official, it counts as a reference to
4844 its display and terminal. */
4845 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
4846 f
->terminal
->reference_count
++;
4848 /* It is now ok to make the frame official even if we get an error
4849 below. And the frame needs to be on Vframe_list or making it
4850 visible won't work. */
4851 Vframe_list
= Fcons (frame
, Vframe_list
);
4854 /* Setting attributes of faces of the tooltip frame from resources
4855 and similar will increment face_change_count, which leads to the
4856 clearing of all current matrices. Since this isn't necessary
4857 here, avoid it by resetting face_change_count to the value it
4858 had before we created the tip frame. */
4859 face_change_count
= face_change_count_before
;
4861 /* Discard the unwind_protect. */
4862 return unbind_to (count
, frame
);
4866 /* Compute where to display tip frame F. PARMS is the list of frame
4867 parameters for F. DX and DY are specified offsets from the current
4868 location of the mouse. WIDTH and HEIGHT are the width and height
4869 of the tooltip. Return coordinates relative to the root window of
4870 the display in *ROOT_X, and *ROOT_Y. */
4873 compute_tip_xy (struct frame
*f
, Lisp_Object parms
, Lisp_Object dx
, Lisp_Object dy
, int width
, int height
, int *root_x
, int *root_y
)
4875 Lisp_Object left
, top
;
4880 /* User-specified position? */
4881 left
= Fcdr (Fassq (Qleft
, parms
));
4882 top
= Fcdr (Fassq (Qtop
, parms
));
4884 /* Move the tooltip window where the mouse pointer is. Resize and
4886 if (!INTEGERP (left
) || !INTEGERP (top
))
4889 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
4890 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
4895 *root_y
= XINT (top
);
4896 else if (*root_y
+ XINT (dy
) <= 0)
4897 *root_y
= 0; /* Can happen for negative dy */
4898 else if (*root_y
+ XINT (dy
) + height
4899 <= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
)))
4900 /* It fits below the pointer */
4901 *root_y
+= XINT (dy
);
4902 else if (height
+ XINT (dy
) <= *root_y
)
4903 /* It fits above the pointer. */
4904 *root_y
-= height
+ XINT (dy
);
4906 /* Put it on the top. */
4909 if (INTEGERP (left
))
4910 *root_x
= XINT (left
);
4911 else if (*root_x
+ XINT (dx
) <= 0)
4912 *root_x
= 0; /* Can happen for negative dx */
4913 else if (*root_x
+ XINT (dx
) + width
4914 <= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
)))
4915 /* It fits to the right of the pointer. */
4916 *root_x
+= XINT (dx
);
4917 else if (width
+ XINT (dx
) <= *root_x
)
4918 /* It fits to the left of the pointer. */
4919 *root_x
-= width
+ XINT (dx
);
4921 /* Put it left-justified on the screen--it ought to fit that way. */
4926 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
4927 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
4928 A tooltip window is a small X window displaying a string.
4930 This is an internal function; Lisp code should call `tooltip-show'.
4932 FRAME nil or omitted means use the selected frame.
4934 PARMS is an optional list of frame parameters which can be used to
4935 change the tooltip's appearance.
4937 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
4938 means use the default timeout of 5 seconds.
4940 If the list of frame parameters PARMS contains a `left' parameters,
4941 the tooltip is displayed at that x-position. Otherwise it is
4942 displayed at the mouse position, with offset DX added (default is 5 if
4943 DX isn't specified). Likewise for the y-position; if a `top' frame
4944 parameter is specified, it determines the y-position of the tooltip
4945 window, otherwise it is displayed at the mouse position, with offset
4946 DY added (default is -10).
4948 A tooltip's maximum size is specified by `x-max-tooltip-size'.
4949 Text larger than the specified size is clipped. */)
4950 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
4955 struct buffer
*old_buffer
;
4956 struct text_pos pos
;
4957 int i
, width
, height
, seen_reversed_p
;
4958 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
4959 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
4960 ptrdiff_t count
= SPECPDL_INDEX ();
4962 specbind (Qinhibit_redisplay
, Qt
);
4964 GCPRO4 (string
, parms
, frame
, timeout
);
4966 CHECK_STRING (string
);
4967 if (SCHARS (string
) == 0)
4968 string
= make_unibyte_string (" ", 1);
4970 f
= check_x_frame (frame
);
4972 timeout
= make_number (5);
4974 CHECK_NATNUM (timeout
);
4977 dx
= make_number (5);
4982 dy
= make_number (-10);
4987 if (x_gtk_use_system_tooltips
)
4991 /* Hide a previous tip, if any. */
4995 if ((ok
= xg_prepare_tooltip (f
, string
, &width
, &height
)) != 0)
4997 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
4998 xg_show_tooltip (f
, root_x
, root_y
);
4999 /* This is used in Fx_hide_tip. */
5000 XSETFRAME (tip_frame
, f
);
5003 if (ok
) goto start_timer
;
5005 #endif /* USE_GTK */
5007 if (NILP (last_show_tip_args
))
5008 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5010 if (!NILP (tip_frame
))
5012 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5013 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5014 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5016 if (EQ (frame
, last_frame
)
5017 && !NILP (Fequal (last_string
, string
))
5018 && !NILP (Fequal (last_parms
, parms
)))
5020 struct frame
*tip_f
= XFRAME (tip_frame
);
5022 /* Only DX and DY have changed. */
5023 if (!NILP (tip_timer
))
5025 Lisp_Object timer
= tip_timer
;
5027 call1 (Qcancel_timer
, timer
);
5031 compute_tip_xy (tip_f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (tip_f
),
5032 FRAME_PIXEL_HEIGHT (tip_f
), &root_x
, &root_y
);
5033 XMoveWindow (FRAME_X_DISPLAY (tip_f
), FRAME_X_WINDOW (tip_f
),
5040 /* Hide a previous tip, if any. */
5043 ASET (last_show_tip_args
, 0, string
);
5044 ASET (last_show_tip_args
, 1, frame
);
5045 ASET (last_show_tip_args
, 2, parms
);
5047 /* Add default values to frame parameters. */
5048 if (NILP (Fassq (Qname
, parms
)))
5049 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5050 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5051 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5052 if (NILP (Fassq (Qborder_width
, parms
)))
5053 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5054 if (NILP (Fassq (Qborder_color
, parms
)))
5055 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5056 if (NILP (Fassq (Qbackground_color
, parms
)))
5057 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5060 /* Create a frame for the tooltip, and record it in the global
5061 variable tip_frame. */
5062 frame
= x_create_tip_frame (FRAME_X_DISPLAY_INFO (f
), parms
, string
);
5065 /* Set up the frame's root window. */
5066 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5067 wset_left_col (w
, make_number (0));
5068 wset_top_line (w
, make_number (0));
5070 if (CONSP (Vx_max_tooltip_size
)
5071 && RANGED_INTEGERP (1, XCAR (Vx_max_tooltip_size
), INT_MAX
)
5072 && RANGED_INTEGERP (1, XCDR (Vx_max_tooltip_size
), INT_MAX
))
5074 wset_total_cols (w
, XCAR (Vx_max_tooltip_size
));
5075 wset_total_lines (w
, XCDR (Vx_max_tooltip_size
));
5079 wset_total_cols (w
, make_number (80));
5080 wset_total_lines (w
, make_number (40));
5083 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
5085 w
->pseudo_window_p
= 1;
5087 /* Display the tooltip text in a temporary buffer. */
5088 old_buffer
= current_buffer
;
5089 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
5090 bset_truncate_lines (current_buffer
, Qnil
);
5091 clear_glyph_matrix (w
->desired_matrix
);
5092 clear_glyph_matrix (w
->current_matrix
);
5093 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5094 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5096 /* Compute width and height of the tooltip. */
5097 width
= height
= seen_reversed_p
= 0;
5098 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5100 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5104 /* Stop at the first empty row at the end. */
5105 if (!row
->enabled_p
|| !row
->displays_text_p
)
5108 /* Let the row go over the full width of the frame. */
5109 row
->full_width_p
= 1;
5111 row_width
= row
->pixel_width
;
5112 if (row
->used
[TEXT_AREA
])
5114 /* There's a glyph at the end of rows that is used to place
5115 the cursor there. Don't include the width of this glyph. */
5116 if (!row
->reversed_p
)
5118 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5119 if (INTEGERP (last
->object
))
5120 row_width
-= last
->pixel_width
;
5124 /* There could be a stretch glyph at the beginning of R2L
5125 rows that is produced by extend_face_to_end_of_line.
5126 Don't count that glyph. */
5127 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
5129 if (g
->type
== STRETCH_GLYPH
&& INTEGERP (g
->object
))
5131 row_width
-= g
->pixel_width
;
5132 seen_reversed_p
= 1;
5137 height
+= row
->height
;
5138 width
= max (width
, row_width
);
5141 /* If we've seen partial-length R2L rows, we need to re-adjust the
5142 tool-tip frame width and redisplay it again, to avoid over-wide
5143 tips due to the stretch glyph that extends R2L lines to full
5144 width of the frame. */
5145 if (seen_reversed_p
)
5147 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns,
5149 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
5150 wset_total_cols (w
, make_number (width
));
5151 FRAME_TOTAL_COLS (f
) = width
;
5153 clear_glyph_matrix (w
->desired_matrix
);
5154 clear_glyph_matrix (w
->current_matrix
);
5155 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
5157 /* Recompute width and height of the tooltip. */
5158 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5160 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5164 if (!row
->enabled_p
|| !row
->displays_text_p
)
5166 row
->full_width_p
= 1;
5167 row_width
= row
->pixel_width
;
5168 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
5170 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5171 if (INTEGERP (last
->object
))
5172 row_width
-= last
->pixel_width
;
5175 height
+= row
->height
;
5176 width
= max (width
, row_width
);
5180 /* Add the frame's internal border to the width and height the X
5181 window should have. */
5182 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5183 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5185 /* Move the tooltip window where the mouse pointer is. Resize and
5187 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5190 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5191 root_x
, root_y
, width
, height
);
5192 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5195 /* Draw into the window. */
5196 w
->must_be_updated_p
= 1;
5197 update_single_window (w
, 1);
5199 /* Restore original current buffer. */
5200 set_buffer_internal_1 (old_buffer
);
5201 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5204 /* Let the tip disappear after timeout seconds. */
5205 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5206 intern ("x-hide-tip"));
5209 return unbind_to (count
, Qnil
);
5213 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5214 doc
: /* Hide the current tooltip window, if there is any.
5215 Value is t if tooltip was open, nil otherwise. */)
5219 Lisp_Object deleted
, frame
, timer
;
5220 struct gcpro gcpro1
, gcpro2
;
5222 /* Return quickly if nothing to do. */
5223 if (NILP (tip_timer
) && NILP (tip_frame
))
5228 GCPRO2 (frame
, timer
);
5229 tip_frame
= tip_timer
= deleted
= Qnil
;
5231 count
= SPECPDL_INDEX ();
5232 specbind (Qinhibit_redisplay
, Qt
);
5233 specbind (Qinhibit_quit
, Qt
);
5236 call1 (Qcancel_timer
, timer
);
5240 /* When using system tooltip, tip_frame is the Emacs frame on which
5241 the tip is shown. */
5242 struct frame
*f
= XFRAME (frame
);
5243 if (FRAME_LIVE_P (f
) && xg_hide_tooltip (f
))
5250 delete_frame (frame
, Qnil
);
5254 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5255 redisplay procedure is not called when a tip frame over menu
5256 items is unmapped. Redisplay the menu manually... */
5259 struct frame
*f
= SELECTED_FRAME ();
5260 w
= f
->output_data
.x
->menubar_widget
;
5262 if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f
)->screen
)
5266 xlwmenu_redisplay (w
);
5270 #endif /* USE_LUCID */
5274 return unbind_to (count
, deleted
);
5279 /***********************************************************************
5280 File selection dialog
5281 ***********************************************************************/
5283 DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog
,
5284 Sx_uses_old_gtk_dialog
,
5286 doc
: /* Return t if the old Gtk+ file selection dialog is used. */)
5293 && xg_uses_old_file_dialog ())
5301 /* Callback for "OK" and "Cancel" on file selection dialog. */
5304 file_dialog_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5306 int *result
= (int *) client_data
;
5307 XmAnyCallbackStruct
*cb
= (XmAnyCallbackStruct
*) call_data
;
5308 *result
= cb
->reason
;
5312 /* Callback for unmapping a file selection dialog. This is used to
5313 capture the case where a dialog is closed via a window manager's
5314 closer button, for example. Using a XmNdestroyCallback didn't work
5318 file_dialog_unmap_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5320 int *result
= (int *) client_data
;
5321 *result
= XmCR_CANCEL
;
5325 clean_up_file_dialog (Lisp_Object arg
)
5327 struct Lisp_Save_Value
*p
= XSAVE_VALUE (arg
);
5328 Widget dialog
= (Widget
) p
->pointer
;
5332 XtUnmanageChild (dialog
);
5333 XtDestroyWidget (dialog
);
5334 x_menu_set_in_use (0);
5341 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5342 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5343 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5344 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5345 or directory must exist.
5347 This function is only defined on MS Windows, and X Windows with the
5348 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5349 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5350 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5353 struct frame
*f
= SELECTED_FRAME ();
5354 Lisp_Object file
= Qnil
;
5355 Lisp_Object decoded_file
;
5356 Widget dialog
, text
, help
;
5359 XmString dir_xmstring
, pattern_xmstring
;
5360 ptrdiff_t count
= SPECPDL_INDEX ();
5361 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5365 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5367 if (popup_activated ())
5368 error ("Trying to use a menu from within a menu-entry");
5370 CHECK_STRING (prompt
);
5373 /* Prevent redisplay. */
5374 specbind (Qinhibit_redisplay
, Qt
);
5378 /* Create the dialog with PROMPT as title, using DIR as initial
5379 directory and using "*" as pattern. */
5380 dir
= Fexpand_file_name (dir
, Qnil
);
5381 dir_xmstring
= XmStringCreateLocalized (SSDATA (dir
));
5382 pattern_xmstring
= XmStringCreateLocalized ("*");
5384 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
5385 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
5386 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
5387 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
5388 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
5389 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
5391 XmStringFree (dir_xmstring
);
5392 XmStringFree (pattern_xmstring
);
5394 /* Add callbacks for OK and Cancel. */
5395 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
5396 (XtPointer
) &result
);
5397 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
5398 (XtPointer
) &result
);
5399 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
5400 (XtPointer
) &result
);
5402 /* Remove the help button since we can't display help. */
5403 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
5404 XtUnmanageChild (help
);
5406 /* Mark OK button as default. */
5407 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
5408 XmNshowAsDefault
, True
, NULL
);
5410 /* If MUSTMATCH is non-nil, disable the file entry field of the
5411 dialog, so that the user must select a file from the files list
5412 box. We can't remove it because we wouldn't have a way to get at
5413 the result file name, then. */
5414 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5415 if (!NILP (mustmatch
))
5418 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
5419 XtSetSensitive (text
, False
);
5420 XtSetSensitive (label
, False
);
5423 /* Manage the dialog, so that list boxes get filled. */
5424 XtManageChild (dialog
);
5426 if (STRINGP (default_filename
))
5428 XmString default_xmstring
;
5429 Widget wtext
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5430 Widget list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
5432 XmTextPosition last_pos
= XmTextFieldGetLastPosition (wtext
);
5433 XmTextFieldReplace (wtext
, 0, last_pos
,
5434 (SSDATA (Ffile_name_nondirectory (default_filename
))));
5436 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5437 must include the path for this to work. */
5439 default_xmstring
= XmStringCreateLocalized (SSDATA (default_filename
));
5441 if (XmListItemExists (list
, default_xmstring
))
5443 int item_pos
= XmListItemPos (list
, default_xmstring
);
5444 /* Select the item and scroll it into view. */
5445 XmListSelectPos (list
, item_pos
, True
);
5446 XmListSetPos (list
, item_pos
);
5449 XmStringFree (default_xmstring
);
5452 record_unwind_protect (clean_up_file_dialog
, make_save_value (dialog
, 0));
5454 /* Process events until the user presses Cancel or OK. */
5455 x_menu_set_in_use (1);
5460 x_menu_wait_for_event (0);
5461 XtAppNextEvent (Xt_app_con
, &event
);
5462 if (event
.type
== KeyPress
5463 && FRAME_X_DISPLAY (f
) == event
.xkey
.display
)
5465 KeySym keysym
= XLookupKeysym (&event
.xkey
, 0);
5467 /* Pop down on C-g. */
5468 if (keysym
== XK_g
&& (event
.xkey
.state
& ControlMask
) != 0)
5469 XtUnmanageChild (dialog
);
5472 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
));
5475 /* Get the result. */
5476 if (result
== XmCR_OK
)
5478 XmString text_string
;
5481 XtVaGetValues (dialog
, XmNtextString
, &text_string
, NULL
);
5482 XmStringGetLtoR (text_string
, XmFONTLIST_DEFAULT_TAG
, &data
);
5483 XmStringFree (text_string
);
5484 file
= build_string (data
);
5493 /* Make "Cancel" equivalent to C-g. */
5495 Fsignal (Qquit
, Qnil
);
5497 decoded_file
= DECODE_FILE (file
);
5499 return unbind_to (count
, decoded_file
);
5502 #endif /* USE_MOTIF */
5507 clean_up_dialog (Lisp_Object arg
)
5509 x_menu_set_in_use (0);
5514 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5515 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5516 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5517 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5518 or directory must exist.
5520 This function is only defined on MS Windows, and X Windows with the
5521 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5522 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5523 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5525 FRAME_PTR f
= SELECTED_FRAME ();
5527 Lisp_Object file
= Qnil
;
5528 Lisp_Object decoded_file
;
5529 ptrdiff_t count
= SPECPDL_INDEX ();
5530 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5535 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5537 if (popup_activated ())
5538 error ("Trying to use a menu from within a menu-entry");
5540 CHECK_STRING (prompt
);
5543 /* Prevent redisplay. */
5544 specbind (Qinhibit_redisplay
, Qt
);
5545 record_unwind_protect (clean_up_dialog
, Qnil
);
5549 if (STRINGP (default_filename
))
5550 cdef_file
= SSDATA (default_filename
);
5552 cdef_file
= SSDATA (dir
);
5554 fn
= xg_get_file_name (f
, SSDATA (prompt
), cdef_file
,
5556 ! NILP (only_dir_p
));
5560 file
= build_string (fn
);
5567 /* Make "Cancel" equivalent to C-g. */
5569 Fsignal (Qquit
, Qnil
);
5571 decoded_file
= DECODE_FILE (file
);
5573 return unbind_to (count
, decoded_file
);
5577 #ifdef HAVE_FREETYPE
5579 DEFUN ("x-select-font", Fx_select_font
, Sx_select_font
, 0, 2, 0,
5580 doc
: /* Read a font using a GTK dialog.
5581 Return either a font spec (for GTK versions >= 3.2) or a string
5582 containing a GTK-style font name.
5584 FRAME is the frame on which to pop up the font chooser. If omitted or
5585 nil, it defaults to the selected frame. */)
5586 (Lisp_Object frame
, Lisp_Object ignored
)
5588 FRAME_PTR f
= check_x_frame (frame
);
5590 Lisp_Object font_param
;
5591 char *default_name
= NULL
;
5592 struct gcpro gcpro1
, gcpro2
;
5593 ptrdiff_t count
= SPECPDL_INDEX ();
5597 if (popup_activated ())
5598 error ("Trying to use a menu from within a menu-entry");
5600 /* Prevent redisplay. */
5601 specbind (Qinhibit_redisplay
, Qt
);
5602 record_unwind_protect (clean_up_dialog
, Qnil
);
5606 GCPRO2 (font_param
, font
);
5608 XSETFONT (font
, FRAME_FONT (f
));
5609 font_param
= Ffont_get (font
, intern (":name"));
5610 if (STRINGP (font_param
))
5611 default_name
= xstrdup (SSDATA (font_param
));
5614 font_param
= Fframe_parameter (frame
, Qfont_param
);
5615 if (STRINGP (font_param
))
5616 default_name
= xstrdup (SSDATA (font_param
));
5619 font
= xg_get_font (f
, default_name
);
5620 xfree (default_name
);
5625 Fsignal (Qquit
, Qnil
);
5627 return unbind_to (count
, font
);
5629 #endif /* HAVE_FREETYPE */
5631 #endif /* USE_GTK */
5634 /***********************************************************************
5636 ***********************************************************************/
5638 #ifdef HAVE_XKBGETKEYBOARD
5639 #include <X11/XKBlib.h>
5640 #include <X11/keysym.h>
5643 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
5644 Sx_backspace_delete_keys_p
, 0, 1, 0,
5645 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
5646 FRAME nil means use the selected frame.
5647 Value is t if we know that both keys are present, and are mapped to the
5648 usual X keysyms. Value is `lambda' if we cannot determine if both keys are
5649 present and mapped to the usual X keysyms. */)
5652 #ifdef HAVE_XKBGETKEYBOARD
5654 struct frame
*f
= check_x_frame (frame
);
5655 Display
*dpy
= FRAME_X_DISPLAY (f
);
5656 Lisp_Object have_keys
;
5657 int major
, minor
, op
, event
, error_code
;
5661 /* Check library version in case we're dynamically linked. */
5662 major
= XkbMajorVersion
;
5663 minor
= XkbMinorVersion
;
5664 if (!XkbLibraryVersion (&major
, &minor
))
5670 /* Check that the server supports XKB. */
5671 major
= XkbMajorVersion
;
5672 minor
= XkbMinorVersion
;
5673 if (!XkbQueryExtension (dpy
, &op
, &event
, &error_code
, &major
, &minor
))
5679 /* In this code we check that the keyboard has physical keys with names
5680 that start with BKSP (Backspace) and DELE (Delete), and that they
5681 generate keysym XK_BackSpace and XK_Delete respectively.
5682 This function is used to test if normal-erase-is-backspace should be
5684 An alternative approach would be to just check if XK_BackSpace and
5685 XK_Delete are mapped to any key. But if any of those are mapped to
5686 some non-intuitive key combination (Meta-Shift-Ctrl-whatever) and the
5687 user doesn't know about it, it is better to return false here.
5688 It is more obvious to the user what to do if she/he has two keys
5689 clearly marked with names/symbols and one key does something not
5690 expected (i.e. she/he then tries the other).
5691 The cases where Backspace/Delete is mapped to some other key combination
5692 are rare, and in those cases, normal-erase-is-backspace can be turned on
5696 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
5699 int delete_keycode
= 0, backspace_keycode
= 0, i
;
5701 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
5703 for (i
= kb
->min_key_code
;
5704 (i
< kb
->max_key_code
5705 && (delete_keycode
== 0 || backspace_keycode
== 0));
5708 /* The XKB symbolic key names can be seen most easily in
5709 the PS file generated by `xkbprint -label name
5711 if (memcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
5713 else if (memcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
5714 backspace_keycode
= i
;
5717 XkbFreeNames (kb
, 0, True
);
5720 XkbFreeClientMap (kb
, 0, True
);
5723 && backspace_keycode
5724 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
5725 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
5730 #else /* not HAVE_XKBGETKEYBOARD */
5732 #endif /* not HAVE_XKBGETKEYBOARD */
5737 /***********************************************************************
5739 ***********************************************************************/
5741 /* Keep this list in the same order as frame_parms in frame.c.
5742 Use 0 for unsupported frame parameters. */
5744 frame_parm_handler x_frame_parm_handlers
[] =
5748 x_set_background_color
,
5754 x_set_foreground_color
,
5757 x_set_internal_border_width
,
5758 x_set_menu_bar_lines
,
5760 x_explicitly_set_name
,
5761 x_set_scroll_bar_width
,
5764 x_set_vertical_scroll_bars
,
5766 x_set_tool_bar_lines
,
5767 x_set_scroll_bar_foreground
,
5768 x_set_scroll_bar_background
,
5778 x_set_tool_bar_position
,
5784 /* This is zero if not using X windows. */
5787 /* The section below is built by the lisp expression at the top of the file,
5788 just above where these variables are declared. */
5789 /*&&& init symbols here &&&*/
5790 DEFSYM (Qsuppress_icon
, "suppress-icon");
5791 DEFSYM (Qundefined_color
, "undefined-color");
5792 DEFSYM (Qcompound_text
, "compound-text");
5793 DEFSYM (Qcancel_timer
, "cancel-timer");
5794 DEFSYM (Qfont_param
, "font-parameter");
5795 /* This is the end of symbol initialization. */
5797 Fput (Qundefined_color
, Qerror_conditions
,
5798 listn (CONSTYPE_PURE
, 2, Qundefined_color
, Qerror
));
5799 Fput (Qundefined_color
, Qerror_message
,
5800 build_pure_c_string ("Undefined color"));
5802 DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape
,
5803 doc
: /* The shape of the pointer when over text.
5804 Changing the value does not affect existing frames
5805 unless you set the mouse color. */);
5806 Vx_pointer_shape
= Qnil
;
5808 #if 0 /* This doesn't really do anything. */
5809 DEFVAR_LISP ("x-nontext-pointer-shape", Vx_nontext_pointer_shape
,
5810 doc
: /* The shape of the pointer when not over text.
5811 This variable takes effect when you create a new frame
5812 or when you set the mouse color. */);
5814 Vx_nontext_pointer_shape
= Qnil
;
5816 DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape
,
5817 doc
: /* The shape of the pointer when Emacs is busy.
5818 This variable takes effect when you create a new frame
5819 or when you set the mouse color. */);
5820 Vx_hourglass_pointer_shape
= Qnil
;
5822 #if 0 /* This doesn't really do anything. */
5823 DEFVAR_LISP ("x-mode-pointer-shape", Vx_mode_pointer_shape
,
5824 doc
: /* The shape of the pointer when over the mode line.
5825 This variable takes effect when you create a new frame
5826 or when you set the mouse color. */);
5828 Vx_mode_pointer_shape
= Qnil
;
5830 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
5831 Vx_sensitive_text_pointer_shape
,
5832 doc
: /* The shape of the pointer when over mouse-sensitive text.
5833 This variable takes effect when you create a new frame
5834 or when you set the mouse color. */);
5835 Vx_sensitive_text_pointer_shape
= Qnil
;
5837 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
5838 Vx_window_horizontal_drag_shape
,
5839 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
5840 This variable takes effect when you create a new frame
5841 or when you set the mouse color. */);
5842 Vx_window_horizontal_drag_shape
= Qnil
;
5844 DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel
,
5845 doc
: /* A string indicating the foreground color of the cursor box. */);
5846 Vx_cursor_fore_pixel
= Qnil
;
5848 DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size
,
5849 doc
: /* Maximum size for tooltips.
5850 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
5851 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
5853 DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager
,
5854 doc
: /* Non-nil if no X window manager is in use.
5855 Emacs doesn't try to figure this out; this is always nil
5856 unless you set it to something else. */);
5857 /* We don't have any way to find this out, so set it to nil
5858 and maybe the user would like to set it to t. */
5859 Vx_no_window_manager
= Qnil
;
5861 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
5862 Vx_pixel_size_width_font_regexp
,
5863 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
5865 Since Emacs gets width of a font matching with this regexp from
5866 PIXEL_SIZE field of the name, font finding mechanism gets faster for
5867 such a font. This is especially effective for such large fonts as
5868 Chinese, Japanese, and Korean. */);
5869 Vx_pixel_size_width_font_regexp
= Qnil
;
5871 /* This is not ifdef:ed, so other builds than GTK can customize it. */
5872 DEFVAR_BOOL ("x-gtk-use-old-file-dialog", x_gtk_use_old_file_dialog
,
5873 doc
: /* Non-nil means prompt with the old GTK file selection dialog.
5874 If nil or if the file selection dialog is not available, the new GTK file
5875 chooser is used instead. To turn off all file dialogs set the
5876 variable `use-file-dialog'. */);
5877 x_gtk_use_old_file_dialog
= 0;
5879 DEFVAR_BOOL ("x-gtk-show-hidden-files", x_gtk_show_hidden_files
,
5880 doc
: /* If non-nil, the GTK file chooser will by default show hidden files.
5881 Note that this is just the default, there is a toggle button on the file
5882 chooser to show or not show hidden files on a case by case basis. */);
5883 x_gtk_show_hidden_files
= 0;
5885 DEFVAR_BOOL ("x-gtk-file-dialog-help-text", x_gtk_file_dialog_help_text
,
5886 doc
: /* If non-nil, the GTK file chooser will show additional help text.
5887 If more space for files in the file chooser dialog is wanted, set this to nil
5888 to turn the additional text off. */);
5889 x_gtk_file_dialog_help_text
= 1;
5891 DEFVAR_BOOL ("x-gtk-whole-detached-tool-bar", x_gtk_whole_detached_tool_bar
,
5892 doc
: /* If non-nil, a detached tool bar is shown in full.
5893 The default is to just show an arrow and pressing on that arrow shows
5894 the tool bar buttons. */);
5895 x_gtk_whole_detached_tool_bar
= 0;
5897 DEFVAR_BOOL ("x-gtk-use-system-tooltips", x_gtk_use_system_tooltips
,
5898 doc
: /* If non-nil with a Gtk+ built Emacs, the Gtk+ tooltip is used.
5899 Otherwise use Emacs own tooltip implementation.
5900 When using Gtk+ tooltips, the tooltip face is not used. */);
5901 x_gtk_use_system_tooltips
= 1;
5903 Fprovide (intern_c_string ("x"), Qnil
);
5905 #ifdef USE_X_TOOLKIT
5906 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
5908 Fprovide (intern_c_string ("motif"), Qnil
);
5910 DEFVAR_LISP ("motif-version-string", Vmotif_version_string
,
5911 doc
: /* Version info for LessTif/Motif. */);
5912 Vmotif_version_string
= build_string (XmVERSION_STRING
);
5913 #endif /* USE_MOTIF */
5914 #endif /* USE_X_TOOLKIT */
5917 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
5918 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
5919 But for a user it is a toolkit for X, and indeed, configure
5920 accepts --with-x-toolkit=gtk. */
5921 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
5922 Fprovide (intern_c_string ("gtk"), Qnil
);
5923 Fprovide (intern_c_string ("move-toolbar"), Qnil
);
5925 DEFVAR_LISP ("gtk-version-string", Vgtk_version_string
,
5926 doc
: /* Version info for GTK+. */);
5928 char gtk_version
[sizeof ".." + 3 * INT_STRLEN_BOUND (int)];
5929 int len
= sprintf (gtk_version
, "%d.%d.%d",
5930 GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
);
5931 Vgtk_version_string
= make_pure_string (gtk_version
, len
, len
, 0);
5933 #endif /* USE_GTK */
5935 /* X window properties. */
5936 defsubr (&Sx_change_window_property
);
5937 defsubr (&Sx_delete_window_property
);
5938 defsubr (&Sx_window_property
);
5940 defsubr (&Sxw_display_color_p
);
5941 defsubr (&Sx_display_grayscale_p
);
5942 defsubr (&Sxw_color_defined_p
);
5943 defsubr (&Sxw_color_values
);
5944 defsubr (&Sx_server_max_request_size
);
5945 defsubr (&Sx_server_vendor
);
5946 defsubr (&Sx_server_version
);
5947 defsubr (&Sx_display_pixel_width
);
5948 defsubr (&Sx_display_pixel_height
);
5949 defsubr (&Sx_display_mm_width
);
5950 defsubr (&Sx_display_mm_height
);
5951 defsubr (&Sx_display_screens
);
5952 defsubr (&Sx_display_planes
);
5953 defsubr (&Sx_display_color_cells
);
5954 defsubr (&Sx_display_visual_class
);
5955 defsubr (&Sx_display_backing_store
);
5956 defsubr (&Sx_display_save_under
);
5957 defsubr (&Sx_wm_set_size_hint
);
5958 defsubr (&Sx_create_frame
);
5959 defsubr (&Sx_open_connection
);
5960 defsubr (&Sx_close_connection
);
5961 defsubr (&Sx_display_list
);
5962 defsubr (&Sx_synchronize
);
5963 defsubr (&Sx_focus_frame
);
5964 defsubr (&Sx_backspace_delete_keys_p
);
5966 /* Setting callback functions for fontset handler. */
5967 check_window_system_func
= check_x
;
5969 defsubr (&Sx_show_tip
);
5970 defsubr (&Sx_hide_tip
);
5972 staticpro (&tip_timer
);
5974 staticpro (&tip_frame
);
5976 last_show_tip_args
= Qnil
;
5977 staticpro (&last_show_tip_args
);
5979 defsubr (&Sx_uses_old_gtk_dialog
);
5980 #if defined (USE_MOTIF) || defined (USE_GTK)
5981 defsubr (&Sx_file_dialog
);
5984 #if defined (USE_GTK) && defined (HAVE_FREETYPE)
5985 defsubr (&Sx_select_font
);
5989 #endif /* HAVE_X_WINDOWS */