1 /* Functions for the X window system.
2 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
31 /* This makes the fields of a Display accessible, in Xlib header files. */
33 #define XLIB_ILLEGAL_ACCESS
40 #include "intervals.h"
41 #include "dispextern.h"
43 #include "blockinput.h"
45 #include "character.h"
50 #include "termhooks.h"
58 #include <sys/types.h>
61 #if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */
62 #include "bitmaps/gray.xbm"
64 #include <X11/bitmaps/gray>
67 #include "xsettings.h"
74 #include <X11/Shell.h>
78 #include <X11/Xaw3d/Paned.h>
79 #include <X11/Xaw3d/Label.h>
80 #else /* !HAVE_XAW3D */
81 #include <X11/Xaw/Paned.h>
82 #include <X11/Xaw/Label.h>
83 #endif /* HAVE_XAW3D */
84 #endif /* USE_MOTIF */
87 #undef USG /* ####KLUDGE for Solaris 2.2 and up */
96 #include "../lwlib/lwlib.h"
100 #include <Xm/DialogS.h>
101 #include <Xm/FileSB.h>
105 #include "../lwlib/xlwmenu.h"
108 #if !defined(NO_EDITRES)
110 extern void _XEditResCheckMessages ();
111 #endif /* not defined NO_EDITRES */
113 /* Unique id counter for widgets created by the Lucid Widget Library. */
115 extern LWLIB_ID widget_id_tick
;
117 extern void free_frame_menubar ();
118 extern double atof ();
122 /* LessTif/Motif version info. */
124 static Lisp_Object Vmotif_version_string
;
126 #endif /* USE_MOTIF */
128 #endif /* USE_X_TOOLKIT */
132 /* GTK+ version info */
134 static Lisp_Object Vgtk_version_string
;
138 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
140 /* The gray bitmap `bitmaps/gray'. This is done because xterm.c uses
141 it, and including `bitmaps/gray' more than once is a problem when
142 config.h defines `static' as an empty replacement string. */
144 int gray_bitmap_width
= gray_width
;
145 int gray_bitmap_height
= gray_height
;
146 char *gray_bitmap_bits
= gray_bits
;
148 /* Non-zero means prompt with the old GTK file selection dialog. */
150 int x_gtk_use_old_file_dialog
;
152 /* If non-zero, by default show hidden files in the GTK file chooser. */
154 int x_gtk_show_hidden_files
;
156 /* If non-zero, don't show additional help text in the GTK file chooser. */
158 int x_gtk_file_dialog_help_text
;
160 /* If non-zero, don't collapse to tool bar when it is detached. */
162 int x_gtk_whole_detached_tool_bar
;
164 /* If non-zero, use Gtk+ tooltips. */
166 static int x_gtk_use_system_tooltips
;
168 /* The background and shape of the mouse pointer, and shape when not
169 over text or in the modeline. */
171 Lisp_Object Vx_pointer_shape
, Vx_nontext_pointer_shape
, Vx_mode_pointer_shape
;
172 Lisp_Object Vx_hourglass_pointer_shape
;
174 /* The shape when over mouse-sensitive text. */
176 Lisp_Object Vx_sensitive_text_pointer_shape
;
178 /* If non-nil, the pointer shape to indicate that windows can be
179 dragged horizontally. */
181 Lisp_Object Vx_window_horizontal_drag_shape
;
183 /* Color of chars displayed in cursor box. */
185 Lisp_Object Vx_cursor_fore_pixel
;
187 /* Nonzero if using X. */
191 /* Non nil if no window manager is in use. */
193 Lisp_Object Vx_no_window_manager
;
195 /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */
197 Lisp_Object Vx_pixel_size_width_font_regexp
;
200 Lisp_Object Qsuppress_icon
;
201 Lisp_Object Qundefined_color
;
202 Lisp_Object Qcompound_text
, Qcancel_timer
;
203 Lisp_Object Qfont_param
;
206 int image_cache_refcount
, dpyinfo_refcount
;
209 #if defined (USE_GTK) && defined (HAVE_FREETYPE)
210 char *x_last_font_name
;
214 /* Error if we are not connected to X. */
220 error ("X windows are not in use or not initialized");
223 /* Nonzero if we can use mouse menus.
224 You should not call this unless HAVE_MENUS is defined. */
232 /* Extract a frame as a FRAME_PTR, defaulting to the selected frame
233 and checking validity for X. */
236 check_x_frame (Lisp_Object frame
)
241 frame
= selected_frame
;
242 CHECK_LIVE_FRAME (frame
);
245 error ("Non-X frame used");
249 /* Let the user specify an X display with a Lisp object.
250 OBJECT may be nil, a frame or a terminal object.
251 nil stands for the selected frame--or, if that is not an X frame,
252 the first X display on the list. */
254 struct x_display_info
*
255 check_x_display_info (Lisp_Object object
)
257 struct x_display_info
*dpyinfo
= NULL
;
261 struct frame
*sf
= XFRAME (selected_frame
);
263 if (FRAME_X_P (sf
) && FRAME_LIVE_P (sf
))
264 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
265 else if (x_display_list
!= 0)
266 dpyinfo
= x_display_list
;
268 error ("X windows are not in use or not initialized");
270 else if (TERMINALP (object
))
272 struct terminal
*t
= get_terminal (object
, 1);
274 if (t
->type
!= output_x_window
)
275 error ("Terminal %d is not an X display", XINT (object
));
277 dpyinfo
= t
->display_info
.x
;
279 else if (STRINGP (object
))
280 dpyinfo
= x_display_info_for_name (object
);
283 FRAME_PTR f
= check_x_frame (object
);
284 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
291 /* Return the Emacs frame-object corresponding to an X window.
292 It could be the frame's main window or an icon window. */
294 /* This function can be called during GC, so use GC_xxx type test macros. */
297 x_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
299 Lisp_Object tail
, frame
;
302 if (wdesc
== None
) return 0;
304 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
310 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
312 if (f
->output_data
.x
->hourglass_window
== wdesc
)
315 if ((f
->output_data
.x
->edit_widget
316 && XtWindow (f
->output_data
.x
->edit_widget
) == wdesc
)
317 /* A tooltip frame? */
318 || (!f
->output_data
.x
->edit_widget
319 && FRAME_X_WINDOW (f
) == wdesc
)
320 || f
->output_data
.x
->icon_desc
== wdesc
)
322 #else /* not USE_X_TOOLKIT */
324 if (f
->output_data
.x
->edit_widget
)
326 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
327 struct x_output
*x
= f
->output_data
.x
;
328 if (gwdesc
!= 0 && gwdesc
== x
->edit_widget
)
332 if (FRAME_X_WINDOW (f
) == wdesc
333 || f
->output_data
.x
->icon_desc
== wdesc
)
335 #endif /* not USE_X_TOOLKIT */
340 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
341 /* Like x_window_to_frame but also compares the window with the widget's
345 x_any_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
347 Lisp_Object tail
, frame
;
348 struct frame
*f
, *found
;
351 if (wdesc
== None
) return NULL
;
354 for (tail
= Vframe_list
; CONSP (tail
) && !found
; tail
= XCDR (tail
))
361 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
363 /* This frame matches if the window is any of its widgets. */
364 x
= f
->output_data
.x
;
365 if (x
->hourglass_window
== wdesc
)
370 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
372 && gtk_widget_get_toplevel (gwdesc
) == x
->widget
)
375 if (wdesc
== XtWindow (x
->widget
)
376 || wdesc
== XtWindow (x
->column_widget
)
377 || wdesc
== XtWindow (x
->edit_widget
))
379 /* Match if the window is this frame's menubar. */
380 else if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
384 else if (FRAME_X_WINDOW (f
) == wdesc
)
385 /* A tooltip frame. */
393 /* Likewise, but consider only the menu bar widget. */
396 x_menubar_window_to_frame (struct x_display_info
*dpyinfo
, XEvent
*event
)
398 Window wdesc
= event
->xany
.window
;
399 Lisp_Object tail
, frame
;
403 if (wdesc
== None
) return 0;
405 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
411 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
413 x
= f
->output_data
.x
;
415 if (x
->menubar_widget
&& xg_event_is_for_menubar (f
, event
))
418 /* Match if the window is this frame's menubar. */
419 if (x
->menubar_widget
420 && lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
427 /* Return the frame whose principal (outermost) window is WDESC.
428 If WDESC is some other (smaller) window, we return 0. */
431 x_top_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
433 Lisp_Object tail
, frame
;
437 if (wdesc
== None
) return 0;
439 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
445 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
447 x
= f
->output_data
.x
;
451 /* This frame matches if the window is its topmost widget. */
453 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
454 if (gwdesc
== x
->widget
)
457 if (wdesc
== XtWindow (x
->widget
))
459 #if 0 /* I don't know why it did this,
460 but it seems logically wrong,
461 and it causes trouble for MapNotify events. */
462 /* Match if the window is this frame's menubar. */
463 if (x
->menubar_widget
464 && wdesc
== XtWindow (x
->menubar_widget
))
469 else if (FRAME_X_WINDOW (f
) == wdesc
)
475 #endif /* USE_X_TOOLKIT || USE_GTK */
479 static void x_default_font_parameter (struct frame
*, Lisp_Object
);
481 static Lisp_Object
unwind_create_frame (Lisp_Object
);
482 static Lisp_Object
unwind_create_tip_frame (Lisp_Object
);
484 void x_set_foreground_color (struct frame
*, Lisp_Object
, Lisp_Object
);
485 static void x_set_wait_for_wm (struct frame
*, Lisp_Object
, Lisp_Object
);
486 void x_set_background_color (struct frame
*, Lisp_Object
, Lisp_Object
);
487 void x_set_mouse_color (struct frame
*, Lisp_Object
, Lisp_Object
);
488 void x_set_cursor_color (struct frame
*, Lisp_Object
, Lisp_Object
);
489 void x_set_border_color (struct frame
*, Lisp_Object
, Lisp_Object
);
490 void x_set_cursor_type (struct frame
*, Lisp_Object
, Lisp_Object
);
491 void x_set_icon_type (struct frame
*, Lisp_Object
, Lisp_Object
);
492 void x_set_icon_name (struct frame
*, Lisp_Object
, Lisp_Object
);
493 void x_explicitly_set_name (struct frame
*, Lisp_Object
, Lisp_Object
);
494 void x_set_menu_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
495 void x_set_title (struct frame
*, Lisp_Object
, Lisp_Object
);
496 void x_set_tool_bar_lines (struct frame
*, Lisp_Object
, Lisp_Object
);
497 void x_set_scroll_bar_foreground (struct frame
*, Lisp_Object
,
499 void x_set_scroll_bar_background (struct frame
*, Lisp_Object
,
501 static Lisp_Object
x_default_scroll_bar_color_parameter (struct frame
*,
504 const char *, const char *,
508 /* Store the screen positions of frame F into XPTR and YPTR.
509 These are the positions of the containing window manager window,
510 not Emacs's own window. */
513 x_real_positions (FRAME_PTR f
, int *xptr
, int *yptr
)
515 int win_x
, win_y
, outer_x
, outer_y
;
516 int real_x
= 0, real_y
= 0;
518 Window win
= f
->output_data
.x
->parent_desc
;
522 x_catch_errors (FRAME_X_DISPLAY (f
));
524 if (win
== FRAME_X_DISPLAY_INFO (f
)->root_window
)
525 win
= FRAME_OUTER_WINDOW (f
);
527 /* This loop traverses up the containment tree until we hit the root
528 window. Window managers may intersect many windows between our window
529 and the root window. The window we find just before the root window
530 should be the outer WM window. */
533 Window wm_window
, rootw
;
534 Window
*tmp_children
;
535 unsigned int tmp_nchildren
;
538 success
= XQueryTree (FRAME_X_DISPLAY (f
), win
, &rootw
,
539 &wm_window
, &tmp_children
, &tmp_nchildren
);
541 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
543 /* Don't free tmp_children if XQueryTree failed. */
547 XFree ((char *) tmp_children
);
549 if (wm_window
== rootw
|| had_errors
)
560 /* Get the real coordinates for the WM window upper left corner */
561 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
562 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
564 /* Translate real coordinates to coordinates relative to our
565 window. For our window, the upper left corner is 0, 0.
566 Since the upper left corner of the WM window is outside
567 our window, win_x and win_y will be negative:
569 ------------------ ---> x
571 | ----------------- v y
574 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
576 /* From-window, to-window. */
577 FRAME_X_DISPLAY_INFO (f
)->root_window
,
580 /* From-position, to-position. */
581 real_x
, real_y
, &win_x
, &win_y
,
586 if (FRAME_X_WINDOW (f
) == FRAME_OUTER_WINDOW (f
))
593 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
595 /* From-window, to-window. */
596 FRAME_X_DISPLAY_INFO (f
)->root_window
,
597 FRAME_OUTER_WINDOW (f
),
599 /* From-position, to-position. */
600 real_x
, real_y
, &outer_x
, &outer_y
,
606 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
613 if (had_errors
) return;
615 f
->x_pixels_diff
= -win_x
;
616 f
->y_pixels_diff
= -win_y
;
618 FRAME_X_OUTPUT (f
)->x_pixels_outer_diff
= -outer_x
;
619 FRAME_X_OUTPUT (f
)->y_pixels_outer_diff
= -outer_y
;
628 /* Gamma-correct COLOR on frame F. */
631 gamma_correct (struct frame
*f
, XColor
*color
)
635 color
->red
= pow (color
->red
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
636 color
->green
= pow (color
->green
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
637 color
->blue
= pow (color
->blue
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
642 /* Decide if color named COLOR_NAME is valid for use on frame F. If
643 so, return the RGB values in COLOR. If ALLOC_P is non-zero,
644 allocate the color. Value is zero if COLOR_NAME is invalid, or
645 no color could be allocated. */
648 x_defined_color (struct frame
*f
, const char *color_name
,
649 XColor
*color
, int alloc_p
)
652 Display
*dpy
= FRAME_X_DISPLAY (f
);
653 Colormap cmap
= FRAME_X_COLORMAP (f
);
656 success_p
= XParseColor (dpy
, cmap
, color_name
, color
);
657 if (success_p
&& alloc_p
)
658 success_p
= x_alloc_nearest_color (f
, cmap
, color
);
665 /* Return the pixel color value for color COLOR_NAME on frame F. If F
666 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
667 Signal an error if color can't be allocated. */
670 x_decode_color (FRAME_PTR f
, Lisp_Object color_name
, int mono_color
)
674 CHECK_STRING (color_name
);
676 #if 0 /* Don't do this. It's wrong when we're not using the default
677 colormap, it makes freeing difficult, and it's probably not
678 an important optimization. */
679 if (strcmp (SDATA (color_name
), "black") == 0)
680 return BLACK_PIX_DEFAULT (f
);
681 else if (strcmp (SDATA (color_name
), "white") == 0)
682 return WHITE_PIX_DEFAULT (f
);
685 /* Return MONO_COLOR for monochrome frames. */
686 if (FRAME_X_DISPLAY_INFO (f
)->n_planes
== 1)
689 /* x_defined_color is responsible for coping with failures
690 by looking for a near-miss. */
691 if (x_defined_color (f
, SDATA (color_name
), &cdef
, 1))
694 signal_error ("Undefined color", color_name
);
699 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
700 the previous value of that parameter, NEW_VALUE is the new value.
701 See also the comment of wait_for_wm in struct x_output. */
704 x_set_wait_for_wm (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
706 f
->output_data
.x
->wait_for_wm
= !NILP (new_value
);
710 x_set_tool_bar_position (struct frame
*f
,
711 Lisp_Object new_value
,
712 Lisp_Object old_value
)
714 if (! EQ (new_value
, Qleft
) && ! EQ (new_value
, Qright
)
715 && ! EQ (new_value
, Qbottom
) && ! EQ (new_value
, Qtop
))
717 if (EQ (new_value
, old_value
)) return;
720 if (xg_change_toolbar_position (f
, new_value
))
721 f
->tool_bar_position
= new_value
;
727 /* Set icon from FILE for frame F. By using GTK functions the icon
728 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
731 xg_set_icon (FRAME_PTR f
, Lisp_Object file
)
736 found
= x_find_image_file (file
);
742 char *filename
= (char *) SDATA (found
);
745 pixbuf
= gdk_pixbuf_new_from_file (filename
, &err
);
749 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
751 g_object_unref (pixbuf
);
765 xg_set_icon_from_xpm_data (FRAME_PTR f
, const char **data
)
768 GdkPixbuf
*pixbuf
= gdk_pixbuf_new_from_xpm_data (data
);
773 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)), pixbuf
);
774 g_object_unref (pixbuf
);
780 /* Functions called only from `x_set_frame_param'
781 to set individual parameters.
783 If FRAME_X_WINDOW (f) is 0,
784 the frame is being created and its X-window does not exist yet.
785 In that case, just record the parameter's new value
786 in the standard place; do not attempt to change the window. */
789 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
791 struct x_output
*x
= f
->output_data
.x
;
792 unsigned long fg
, old_fg
;
794 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
795 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
796 FRAME_FOREGROUND_PIXEL (f
) = fg
;
798 if (FRAME_X_WINDOW (f
) != 0)
800 Display
*dpy
= FRAME_X_DISPLAY (f
);
803 XSetForeground (dpy
, x
->normal_gc
, fg
);
804 XSetBackground (dpy
, x
->reverse_gc
, fg
);
806 if (x
->cursor_pixel
== old_fg
)
808 unload_color (f
, x
->cursor_pixel
);
809 x
->cursor_pixel
= x_copy_color (f
, fg
);
810 XSetBackground (dpy
, x
->cursor_gc
, x
->cursor_pixel
);
815 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
817 if (FRAME_VISIBLE_P (f
))
821 unload_color (f
, old_fg
);
825 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
827 struct x_output
*x
= f
->output_data
.x
;
830 bg
= x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
831 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
832 FRAME_BACKGROUND_PIXEL (f
) = bg
;
834 if (FRAME_X_WINDOW (f
) != 0)
836 Display
*dpy
= FRAME_X_DISPLAY (f
);
839 XSetBackground (dpy
, x
->normal_gc
, bg
);
840 XSetForeground (dpy
, x
->reverse_gc
, bg
);
841 XSetWindowBackground (dpy
, FRAME_X_WINDOW (f
), bg
);
842 XSetForeground (dpy
, x
->cursor_gc
, bg
);
845 xg_set_background_color (f
, bg
);
848 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
849 toolkit scroll bars. */
852 for (bar
= FRAME_SCROLL_BARS (f
);
854 bar
= XSCROLL_BAR (bar
)->next
)
856 Window window
= XSCROLL_BAR (bar
)->x_window
;
857 XSetWindowBackground (dpy
, window
, bg
);
860 #endif /* USE_TOOLKIT_SCROLL_BARS */
863 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
865 if (FRAME_VISIBLE_P (f
))
871 make_invisible_cursor (struct frame
*f
)
873 Display
*dpy
= FRAME_X_DISPLAY (f
);
874 static char const no_data
[] = { 0 };
879 x_catch_errors (dpy
);
880 pix
= XCreateBitmapFromData (dpy
, FRAME_X_DISPLAY_INFO (f
)->root_window
,
882 if (! x_had_errors_p (dpy
) && pix
!= None
)
885 col
.red
= col
.green
= col
.blue
= 0;
886 col
.flags
= DoRed
| DoGreen
| DoBlue
;
887 c
= XCreatePixmapCursor (dpy
, pix
, pix
, &col
, &col
, 0, 0);
888 if (x_had_errors_p (dpy
) || c
== None
)
890 XFreePixmap (dpy
, pix
);
899 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
901 struct x_output
*x
= f
->output_data
.x
;
902 Display
*dpy
= FRAME_X_DISPLAY (f
);
903 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
904 Cursor hourglass_cursor
, horizontal_drag_cursor
;
905 unsigned long pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
906 unsigned long mask_color
= FRAME_BACKGROUND_PIXEL (f
);
908 /* Don't let pointers be invisible. */
909 if (mask_color
== pixel
)
911 x_free_colors (f
, &pixel
, 1);
912 pixel
= x_copy_color (f
, FRAME_FOREGROUND_PIXEL (f
));
915 unload_color (f
, x
->mouse_pixel
);
916 x
->mouse_pixel
= pixel
;
920 /* It's not okay to crash if the user selects a screwy cursor. */
921 x_catch_errors (dpy
);
923 if (!NILP (Vx_pointer_shape
))
925 CHECK_NUMBER (Vx_pointer_shape
);
926 cursor
= XCreateFontCursor (dpy
, XINT (Vx_pointer_shape
));
929 cursor
= XCreateFontCursor (dpy
, XC_xterm
);
930 x_check_errors (dpy
, "bad text pointer cursor: %s");
932 if (!NILP (Vx_nontext_pointer_shape
))
934 CHECK_NUMBER (Vx_nontext_pointer_shape
);
936 = XCreateFontCursor (dpy
, XINT (Vx_nontext_pointer_shape
));
939 nontext_cursor
= XCreateFontCursor (dpy
, XC_left_ptr
);
940 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
942 if (!NILP (Vx_hourglass_pointer_shape
))
944 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
946 = XCreateFontCursor (dpy
, XINT (Vx_hourglass_pointer_shape
));
949 hourglass_cursor
= XCreateFontCursor (dpy
, XC_watch
);
950 x_check_errors (dpy
, "bad hourglass pointer cursor: %s");
952 if (!NILP (Vx_mode_pointer_shape
))
954 CHECK_NUMBER (Vx_mode_pointer_shape
);
955 mode_cursor
= XCreateFontCursor (dpy
, XINT (Vx_mode_pointer_shape
));
958 mode_cursor
= XCreateFontCursor (dpy
, XC_xterm
);
959 x_check_errors (dpy
, "bad modeline pointer cursor: %s");
961 if (!NILP (Vx_sensitive_text_pointer_shape
))
963 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
965 = XCreateFontCursor (dpy
, XINT (Vx_sensitive_text_pointer_shape
));
968 hand_cursor
= XCreateFontCursor (dpy
, XC_hand2
);
970 if (!NILP (Vx_window_horizontal_drag_shape
))
972 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
973 horizontal_drag_cursor
974 = XCreateFontCursor (dpy
, XINT (Vx_window_horizontal_drag_shape
));
977 horizontal_drag_cursor
978 = XCreateFontCursor (dpy
, XC_sb_h_double_arrow
);
980 /* Check and report errors with the above calls. */
981 x_check_errors (dpy
, "can't set cursor shape: %s");
985 XColor fore_color
, back_color
;
987 fore_color
.pixel
= x
->mouse_pixel
;
988 x_query_color (f
, &fore_color
);
989 back_color
.pixel
= mask_color
;
990 x_query_color (f
, &back_color
);
992 XRecolorCursor (dpy
, cursor
, &fore_color
, &back_color
);
993 XRecolorCursor (dpy
, nontext_cursor
, &fore_color
, &back_color
);
994 XRecolorCursor (dpy
, mode_cursor
, &fore_color
, &back_color
);
995 XRecolorCursor (dpy
, hand_cursor
, &fore_color
, &back_color
);
996 XRecolorCursor (dpy
, hourglass_cursor
, &fore_color
, &back_color
);
997 XRecolorCursor (dpy
, horizontal_drag_cursor
, &fore_color
, &back_color
);
1000 if (FRAME_X_WINDOW (f
) != 0)
1001 XDefineCursor (dpy
, FRAME_X_WINDOW (f
),
1002 f
->output_data
.x
->current_cursor
= cursor
);
1004 if (FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
== 0)
1005 FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
= make_invisible_cursor (f
);
1007 if (cursor
!= x
->text_cursor
1008 && x
->text_cursor
!= 0)
1009 XFreeCursor (dpy
, x
->text_cursor
);
1010 x
->text_cursor
= cursor
;
1012 if (nontext_cursor
!= x
->nontext_cursor
1013 && x
->nontext_cursor
!= 0)
1014 XFreeCursor (dpy
, x
->nontext_cursor
);
1015 x
->nontext_cursor
= nontext_cursor
;
1017 if (hourglass_cursor
!= x
->hourglass_cursor
1018 && x
->hourglass_cursor
!= 0)
1019 XFreeCursor (dpy
, x
->hourglass_cursor
);
1020 x
->hourglass_cursor
= hourglass_cursor
;
1022 if (mode_cursor
!= x
->modeline_cursor
1023 && x
->modeline_cursor
!= 0)
1024 XFreeCursor (dpy
, f
->output_data
.x
->modeline_cursor
);
1025 x
->modeline_cursor
= mode_cursor
;
1027 if (hand_cursor
!= x
->hand_cursor
1028 && x
->hand_cursor
!= 0)
1029 XFreeCursor (dpy
, x
->hand_cursor
);
1030 x
->hand_cursor
= hand_cursor
;
1032 if (horizontal_drag_cursor
!= x
->horizontal_drag_cursor
1033 && x
->horizontal_drag_cursor
!= 0)
1034 XFreeCursor (dpy
, x
->horizontal_drag_cursor
);
1035 x
->horizontal_drag_cursor
= horizontal_drag_cursor
;
1040 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
1044 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1046 unsigned long fore_pixel
, pixel
;
1047 int fore_pixel_allocated_p
= 0, pixel_allocated_p
= 0;
1048 struct x_output
*x
= f
->output_data
.x
;
1050 if (!NILP (Vx_cursor_fore_pixel
))
1052 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
1053 WHITE_PIX_DEFAULT (f
));
1054 fore_pixel_allocated_p
= 1;
1057 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1059 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1060 pixel_allocated_p
= 1;
1062 /* Make sure that the cursor color differs from the background color. */
1063 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
1065 if (pixel_allocated_p
)
1067 x_free_colors (f
, &pixel
, 1);
1068 pixel_allocated_p
= 0;
1071 pixel
= x
->mouse_pixel
;
1072 if (pixel
== fore_pixel
)
1074 if (fore_pixel_allocated_p
)
1076 x_free_colors (f
, &fore_pixel
, 1);
1077 fore_pixel_allocated_p
= 0;
1079 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
1083 unload_color (f
, x
->cursor_foreground_pixel
);
1084 if (!fore_pixel_allocated_p
)
1085 fore_pixel
= x_copy_color (f
, fore_pixel
);
1086 x
->cursor_foreground_pixel
= fore_pixel
;
1088 unload_color (f
, x
->cursor_pixel
);
1089 if (!pixel_allocated_p
)
1090 pixel
= x_copy_color (f
, pixel
);
1091 x
->cursor_pixel
= pixel
;
1093 if (FRAME_X_WINDOW (f
) != 0)
1096 XSetBackground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, x
->cursor_pixel
);
1097 XSetForeground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, fore_pixel
);
1100 if (FRAME_VISIBLE_P (f
))
1102 x_update_cursor (f
, 0);
1103 x_update_cursor (f
, 1);
1107 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1110 /* Set the border-color of frame F to pixel value PIX.
1111 Note that this does not fully take effect if done before
1112 F has an x-window. */
1115 x_set_border_pixel (struct frame
*f
, int pix
)
1117 unload_color (f
, f
->output_data
.x
->border_pixel
);
1118 f
->output_data
.x
->border_pixel
= pix
;
1120 if (FRAME_X_WINDOW (f
) != 0 && f
->border_width
> 0)
1123 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1124 (unsigned long)pix
);
1127 if (FRAME_VISIBLE_P (f
))
1132 /* Set the border-color of frame F to value described by ARG.
1133 ARG can be a string naming a color.
1134 The border-color is used for the border that is drawn by the X server.
1135 Note that this does not fully take effect if done before
1136 F has an x-window; it must be redone when the window is created.
1138 Note: this is done in two routines because of the way X10 works.
1140 Note: under X11, this is normally the province of the window manager,
1141 and so emacs' border colors may be overridden. */
1144 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1149 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1150 x_set_border_pixel (f
, pix
);
1151 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1156 x_set_cursor_type (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1158 set_frame_cursor_types (f
, arg
);
1160 /* Make sure the cursor gets redrawn. */
1161 cursor_type_changed
= 1;
1165 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1171 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1174 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1179 result
= x_text_icon (f
,
1180 (char *) SDATA ((!NILP (f
->icon_name
)
1184 result
= x_bitmap_icon (f
, arg
);
1189 error ("No icon window available");
1192 XFlush (FRAME_X_DISPLAY (f
));
1197 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1203 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1206 else if (!NILP (arg
) || NILP (oldval
))
1211 if (f
->output_data
.x
->icon_bitmap
!= 0)
1216 result
= x_text_icon (f
,
1217 (char *) SDATA ((!NILP (f
->icon_name
)
1226 error ("No icon window available");
1229 XFlush (FRAME_X_DISPLAY (f
));
1235 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1238 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
1239 int olines
= FRAME_MENU_BAR_LINES (f
);
1242 /* Right now, menu bars don't work properly in minibuf-only frames;
1243 most of the commands try to apply themselves to the minibuffer
1244 frame itself, and get an error because you can't switch buffers
1245 in or split the minibuffer window. */
1246 if (FRAME_MINIBUF_ONLY_P (f
))
1249 if (INTEGERP (value
))
1250 nlines
= XINT (value
);
1254 /* Make sure we redisplay all windows in this frame. */
1255 windows_or_buffers_changed
++;
1257 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
1258 FRAME_MENU_BAR_LINES (f
) = 0;
1261 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1262 if (FRAME_X_P (f
) && f
->output_data
.x
->menubar_widget
== 0)
1263 /* Make sure next redisplay shows the menu bar. */
1264 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= Qt
;
1268 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1269 free_frame_menubar (f
);
1270 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1272 f
->output_data
.x
->menubar_widget
= 0;
1274 #else /* not USE_X_TOOLKIT && not USE_GTK */
1275 FRAME_MENU_BAR_LINES (f
) = nlines
;
1276 change_window_heights (f
->root_window
, nlines
- olines
);
1278 /* If the menu bar height gets changed, the internal border below
1279 the top margin has to be cleared. Also, if the menu bar gets
1280 larger, the area for the added lines has to be cleared except for
1281 the first menu bar line that is to be drawn later. */
1282 if (nlines
!= olines
)
1284 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1285 int width
= FRAME_PIXEL_WIDTH (f
);
1288 /* height can be zero here. */
1289 if (height
> 0 && width
> 0)
1291 y
= FRAME_TOP_MARGIN_HEIGHT (f
);
1294 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1295 0, y
, width
, height
, False
);
1299 if (nlines
> 1 && nlines
> olines
)
1301 y
= (olines
== 0 ? 1 : olines
) * FRAME_LINE_HEIGHT (f
);
1302 height
= nlines
* FRAME_LINE_HEIGHT (f
) - y
;
1305 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1306 0, y
, width
, height
, False
);
1310 if (nlines
== 0 && WINDOWP (f
->menu_bar_window
))
1311 clear_glyph_matrix (XWINDOW (f
->menu_bar_window
)->current_matrix
);
1313 #endif /* not USE_X_TOOLKIT && not USE_GTK */
1318 /* Set the number of lines used for the tool bar of frame F to VALUE.
1319 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1320 is the old number of tool bar lines. This function changes the
1321 height of all windows on frame F to match the new tool bar height.
1322 The frame's height doesn't change. */
1325 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1327 int delta
, nlines
, root_height
;
1328 Lisp_Object root_window
;
1330 /* Treat tool bars like menu bars. */
1331 if (FRAME_MINIBUF_ONLY_P (f
))
1334 /* Use VALUE only if an integer >= 0. */
1335 if (INTEGERP (value
) && XINT (value
) >= 0)
1336 nlines
= XFASTINT (value
);
1341 FRAME_TOOL_BAR_LINES (f
) = 0;
1344 FRAME_EXTERNAL_TOOL_BAR (f
) = 1;
1345 if (FRAME_X_P (f
) && f
->output_data
.x
->toolbar_widget
== 0)
1346 /* Make sure next redisplay shows the tool bar. */
1347 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= Qt
;
1348 update_frame_tool_bar (f
);
1352 if (FRAME_EXTERNAL_TOOL_BAR (f
))
1353 free_frame_tool_bar (f
);
1354 FRAME_EXTERNAL_TOOL_BAR (f
) = 0;
1360 /* Make sure we redisplay all windows in this frame. */
1361 ++windows_or_buffers_changed
;
1363 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1365 /* Don't resize the tool-bar to more than we have room for. */
1366 root_window
= FRAME_ROOT_WINDOW (f
);
1367 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1368 if (root_height
- delta
< 1)
1370 delta
= root_height
- 1;
1371 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1374 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1375 change_window_heights (root_window
, delta
);
1378 /* We also have to make sure that the internal border at the top of
1379 the frame, below the menu bar or tool bar, is redrawn when the
1380 tool bar disappears. This is so because the internal border is
1381 below the tool bar if one is displayed, but is below the menu bar
1382 if there isn't a tool bar. The tool bar draws into the area
1383 below the menu bar. */
1384 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1387 clear_current_matrices (f
);
1390 /* If the tool bar gets smaller, the internal border below it
1391 has to be cleared. It was formerly part of the display
1392 of the larger tool bar, and updating windows won't clear it. */
1395 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1396 int width
= FRAME_PIXEL_WIDTH (f
);
1397 int y
= (FRAME_MENU_BAR_LINES (f
) + nlines
) * FRAME_LINE_HEIGHT (f
);
1399 /* height can be zero here. */
1400 if (height
> 0 && width
> 0)
1403 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1404 0, y
, width
, height
, False
);
1408 if (WINDOWP (f
->tool_bar_window
))
1409 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1414 /* Set the foreground color for scroll bars on frame F to VALUE.
1415 VALUE should be a string, a color name. If it isn't a string or
1416 isn't a valid color name, do nothing. OLDVAL is the old value of
1417 the frame parameter. */
1420 x_set_scroll_bar_foreground (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1422 unsigned long pixel
;
1424 if (STRINGP (value
))
1425 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
1429 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
1430 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
1432 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
1433 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1435 /* Remove all scroll bars because they have wrong colors. */
1436 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1437 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1438 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1439 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1441 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
1447 /* Set the background color for scroll bars on frame F to VALUE VALUE
1448 should be a string, a color name. If it isn't a string or isn't a
1449 valid color name, do nothing. OLDVAL is the old value of the frame
1453 x_set_scroll_bar_background (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1455 unsigned long pixel
;
1457 if (STRINGP (value
))
1458 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
1462 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
1463 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
1465 #ifdef USE_TOOLKIT_SCROLL_BARS
1466 /* Scrollbar shadow colors. */
1467 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
1469 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
1470 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
1472 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
1474 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
1475 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
1477 #endif /* USE_TOOLKIT_SCROLL_BARS */
1479 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
1480 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1482 /* Remove all scroll bars because they have wrong colors. */
1483 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1484 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1485 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1486 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1488 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
1494 /* Encode Lisp string STRING as a text in a format appropriate for
1495 XICCC (X Inter Client Communication Conventions).
1497 This can call Lisp code, so callers must GCPRO.
1499 If STRING contains only ASCII characters, do no conversion and
1500 return the string data of STRING. Otherwise, encode the text by
1501 CODING_SYSTEM, and return a newly allocated memory area which
1502 should be freed by `xfree' by a caller.
1504 SELECTIONP non-zero means the string is being encoded for an X
1505 selection, so it is safe to run pre-write conversions (which
1508 Store the byte length of resulting text in *TEXT_BYTES.
1510 If the text contains only ASCII and Latin-1, store 1 in *STRING_P,
1511 which means that the `encoding' of the result can be `STRING'.
1512 Otherwise store 0 in *STRINGP, which means that the `encoding' of
1513 the result should be `COMPOUND_TEXT'. */
1515 static unsigned char *
1516 x_encode_text (Lisp_Object string
, Lisp_Object coding_system
, int selectionp
, int *text_bytes
, int *stringp
, int *freep
)
1518 int result
= string_xstring_p (string
);
1519 struct coding_system coding
;
1523 /* No multibyte character in OBJ. We need not encode it. */
1524 *text_bytes
= SBYTES (string
);
1527 return SDATA (string
);
1530 setup_coding_system (coding_system
, &coding
);
1531 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
1532 /* We suppress producing escape sequences for composition. */
1533 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
1534 coding
.dst_bytes
= SCHARS (string
) * 2;
1535 coding
.destination
= (unsigned char *) xmalloc (coding
.dst_bytes
);
1536 encode_coding_object (&coding
, string
, 0, 0,
1537 SCHARS (string
), SBYTES (string
), Qnil
);
1538 *text_bytes
= coding
.produced
;
1539 *stringp
= (result
== 1 || !EQ (coding_system
, Qcompound_text
));
1541 return coding
.destination
;
1545 /* Set the WM name to NAME for frame F. Also set the icon name.
1546 If the frame already has an icon name, use that, otherwise set the
1547 icon name to NAME. */
1550 x_set_name_internal (FRAME_PTR f
, Lisp_Object name
)
1552 if (FRAME_X_WINDOW (f
))
1556 XTextProperty text
, icon
;
1558 int do_free_icon_value
= 0, do_free_text_value
= 0;
1559 Lisp_Object coding_system
;
1560 Lisp_Object encoded_name
;
1561 Lisp_Object encoded_icon_name
;
1562 struct gcpro gcpro1
;
1564 /* As ENCODE_UTF_8 may cause GC and relocation of string data,
1565 we use it before x_encode_text that may return string data. */
1567 encoded_name
= ENCODE_UTF_8 (name
);
1570 coding_system
= Qcompound_text
;
1571 /* Note: Encoding strategy
1573 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1574 text.encoding. But, there are non-internationalized window
1575 managers which don't support that encoding. So, if NAME
1576 contains only ASCII and 8859-1 characters, encode it by
1577 iso-latin-1, and use "STRING" in text.encoding hoping that
1578 such window managers at least analyze this format correctly,
1579 i.e. treat 8-bit bytes as 8859-1 characters.
1581 We may also be able to use "UTF8_STRING" in text.encoding
1582 in the future which can encode all Unicode characters.
1583 But, for the moment, there's no way to know that the
1584 current window manager supports it or not.
1586 Either way, we also set the _NET_WM_NAME and _NET_WM_ICON_NAME
1587 properties. Per the EWMH specification, those two properties
1588 are always UTF8_STRING. This matches what gtk_window_set_title()
1589 does in the USE_GTK case. */
1590 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
,
1591 &do_free_text_value
);
1592 text
.encoding
= (stringp
? XA_STRING
1593 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1595 text
.nitems
= bytes
;
1597 if (!STRINGP (f
->icon_name
))
1600 encoded_icon_name
= encoded_name
;
1604 /* See the above comment "Note: Encoding strategy". */
1605 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
1606 &bytes
, &stringp
, &do_free_icon_value
);
1607 icon
.encoding
= (stringp
? XA_STRING
1608 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1610 icon
.nitems
= bytes
;
1612 encoded_icon_name
= ENCODE_UTF_8 (f
->icon_name
);
1616 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1617 (char *) SDATA (encoded_name
));
1618 #else /* not USE_GTK */
1619 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1620 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1621 FRAME_X_DISPLAY_INFO (f
)->Xatom_net_wm_name
,
1622 FRAME_X_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1624 (char *) SDATA (encoded_name
),
1625 SBYTES (encoded_name
));
1626 #endif /* not USE_GTK */
1628 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &icon
);
1629 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1630 FRAME_X_DISPLAY_INFO (f
)->Xatom_net_wm_icon_name
,
1631 FRAME_X_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1633 (char *) SDATA (encoded_icon_name
),
1634 SBYTES (encoded_icon_name
));
1636 if (do_free_icon_value
)
1638 if (do_free_text_value
)
1645 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1648 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1649 name; if NAME is a string, set F's name to NAME and set
1650 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1652 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1653 suggesting a new name, which lisp code should override; if
1654 F->explicit_name is set, ignore the new name; otherwise, set it. */
1657 x_set_name (struct frame
*f
, Lisp_Object name
, int explicit)
1659 /* Make sure that requests from lisp code override requests from
1660 Emacs redisplay code. */
1663 /* If we're switching from explicit to implicit, we had better
1664 update the mode lines and thereby update the title. */
1665 if (f
->explicit_name
&& NILP (name
))
1666 update_mode_lines
= 1;
1668 f
->explicit_name
= ! NILP (name
);
1670 else if (f
->explicit_name
)
1673 /* If NAME is nil, set the name to the x_id_name. */
1676 /* Check for no change needed in this very common case
1677 before we do any consing. */
1678 if (!strcmp (FRAME_X_DISPLAY_INFO (f
)->x_id_name
,
1681 name
= build_string (FRAME_X_DISPLAY_INFO (f
)->x_id_name
);
1684 CHECK_STRING (name
);
1686 /* Don't change the name if it's already NAME. */
1687 if (! NILP (Fstring_equal (name
, f
->name
)))
1692 /* For setting the frame title, the title parameter should override
1693 the name parameter. */
1694 if (! NILP (f
->title
))
1697 x_set_name_internal (f
, name
);
1700 /* This function should be called when the user's lisp code has
1701 specified a name for the frame; the name will override any set by the
1704 x_explicitly_set_name (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1706 x_set_name (f
, arg
, 1);
1709 /* This function should be called by Emacs redisplay code to set the
1710 name; names set this way will never override names set by the user's
1713 x_implicitly_set_name (FRAME_PTR f
, Lisp_Object arg
, Lisp_Object oldval
)
1715 x_set_name (f
, arg
, 0);
1718 /* Change the title of frame F to NAME.
1719 If NAME is nil, use the frame name as the title. */
1722 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1724 /* Don't change the title if it's already NAME. */
1725 if (EQ (name
, f
->title
))
1728 update_mode_lines
= 1;
1735 CHECK_STRING (name
);
1737 x_set_name_internal (f
, name
);
1741 x_set_scroll_bar_default_width (struct frame
*f
)
1743 int wid
= FRAME_COLUMN_WIDTH (f
);
1745 #ifdef USE_TOOLKIT_SCROLL_BARS
1746 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1747 int width
= 16 + 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1748 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (width
+ wid
- 1) / wid
;
1749 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = width
;
1751 /* Make the actual width at least 14 pixels and a multiple of a
1753 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
1755 /* Use all of that space (aside from required margins) for the
1757 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = 0;
1762 /* Record in frame F the specified or default value according to ALIST
1763 of the parameter named PROP (a Lisp symbol). If no value is
1764 specified for PROP, look for an X default for XPROP on the frame
1765 named NAME. If that is not found either, use the value DEFLT. */
1768 x_default_scroll_bar_color_parameter (struct frame
*f
,
1769 Lisp_Object alist
, Lisp_Object prop
,
1770 const char *xprop
, const char *xclass
,
1773 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1776 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
1777 if (EQ (tem
, Qunbound
))
1779 #ifdef USE_TOOLKIT_SCROLL_BARS
1781 /* See if an X resource for the scroll bar color has been
1783 tem
= display_x_get_resource (dpyinfo
,
1784 build_string (foreground_p
1787 empty_unibyte_string
,
1788 build_string ("verticalScrollBar"),
1789 empty_unibyte_string
);
1792 /* If nothing has been specified, scroll bars will use a
1793 toolkit-dependent default. Because these defaults are
1794 difficult to get at without actually creating a scroll
1795 bar, use nil to indicate that no color has been
1800 #else /* not USE_TOOLKIT_SCROLL_BARS */
1804 #endif /* not USE_TOOLKIT_SCROLL_BARS */
1807 x_set_frame_parameters (f
, Fcons (Fcons (prop
, tem
), Qnil
));
1814 #ifdef USE_X_TOOLKIT
1816 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
1817 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
1818 already be present because of the toolkit (Motif adds some of them,
1819 for example, but Xt doesn't). */
1822 hack_wm_protocols (FRAME_PTR f
, Widget widget
)
1824 Display
*dpy
= XtDisplay (widget
);
1825 Window w
= XtWindow (widget
);
1826 int need_delete
= 1;
1833 unsigned char *catoms
;
1835 unsigned long nitems
= 0;
1836 unsigned long bytes_after
;
1838 if ((XGetWindowProperty (dpy
, w
,
1839 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1840 (long)0, (long)100, False
, XA_ATOM
,
1841 &type
, &format
, &nitems
, &bytes_after
,
1844 && format
== 32 && type
== XA_ATOM
)
1846 Atom
*atoms
= (Atom
*) catoms
;
1851 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
1853 else if (atoms
[nitems
]
1854 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
1856 else if (atoms
[nitems
]
1857 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
1868 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
1870 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
1872 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
1874 XChangeProperty (dpy
, w
, FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1875 XA_ATOM
, 32, PropModeAppend
,
1876 (unsigned char *) props
, count
);
1884 /* Support routines for XIC (X Input Context). */
1888 static XFontSet
xic_create_xfontset (struct frame
*);
1889 static XIMStyle
best_xim_style (XIMStyles
*, XIMStyles
*);
1892 /* Supported XIM styles, ordered by preference. */
1894 static XIMStyle supported_xim_styles
[] =
1896 XIMPreeditPosition
| XIMStatusArea
,
1897 XIMPreeditPosition
| XIMStatusNothing
,
1898 XIMPreeditPosition
| XIMStatusNone
,
1899 XIMPreeditNothing
| XIMStatusArea
,
1900 XIMPreeditNothing
| XIMStatusNothing
,
1901 XIMPreeditNothing
| XIMStatusNone
,
1902 XIMPreeditNone
| XIMStatusArea
,
1903 XIMPreeditNone
| XIMStatusNothing
,
1904 XIMPreeditNone
| XIMStatusNone
,
1909 /* Create an X fontset on frame F with base font name BASE_FONTNAME. */
1911 const char xic_defaut_fontset
[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
1913 /* Create an Xt fontset spec from the name of a base font.
1914 If `motif' is True use the Motif syntax. */
1916 xic_create_fontsetname (const char *base_fontname
, int motif
)
1918 const char *sep
= motif
? ";" : ",";
1921 /* Make a fontset name from the base font name. */
1922 if (xic_defaut_fontset
== base_fontname
)
1923 { /* There is no base font name, use the default. */
1924 int len
= strlen (base_fontname
) + 2;
1925 fontsetname
= xmalloc (len
);
1926 memset (fontsetname
, 0, len
);
1927 strcpy (fontsetname
, base_fontname
);
1931 /* Make a fontset name from the base font name.
1932 The font set will be made of the following elements:
1934 - the base font where the charset spec is replaced by -*-*.
1935 - the same but with the family also replaced with -*-*-. */
1936 const char *p
= base_fontname
;
1939 for (i
= 0; *p
; p
++)
1942 { /* As the font name doesn't conform to XLFD, we can't
1943 modify it to generalize it to allcs and allfamilies.
1944 Use the specified font plus the default. */
1945 int len
= strlen (base_fontname
) + strlen (xic_defaut_fontset
) + 3;
1946 fontsetname
= xmalloc (len
);
1947 memset (fontsetname
, 0, len
);
1948 strcpy (fontsetname
, base_fontname
);
1949 strcat (fontsetname
, sep
);
1950 strcat (fontsetname
, xic_defaut_fontset
);
1955 const char *p1
= NULL
, *p2
= NULL
, *p3
= NULL
;
1956 char *font_allcs
= NULL
;
1957 char *font_allfamilies
= NULL
;
1958 char *font_all
= NULL
;
1959 const char *allcs
= "*-*-*-*-*-*-*";
1960 const char *allfamilies
= "-*-*-";
1961 const char *all
= "*-*-*-*-";
1964 for (i
= 0, p
= base_fontname
; i
< 8; p
++)
1977 /* If base_fontname specifies ADSTYLE, make it a
1981 int diff
= (p2
- p3
) - 2;
1983 base
= alloca (strlen (base_fontname
) + 1);
1984 memcpy (base
, base_fontname
, p3
- base_fontname
);
1985 base
[p3
- base_fontname
] = '*';
1986 base
[(p3
- base_fontname
) + 1] = '-';
1987 strcpy (base
+ (p3
- base_fontname
) + 2, p2
);
1988 p
= base
+ (p
- base_fontname
) - diff
;
1989 p1
= base
+ (p1
- base_fontname
);
1990 p2
= base
+ (p2
- base_fontname
) - diff
;
1991 base_fontname
= base
;
1994 /* Build the font spec that matches all charsets. */
1995 len
= p
- base_fontname
+ strlen (allcs
) + 1;
1996 font_allcs
= (char *) alloca (len
);
1997 memset (font_allcs
, 0, len
);
1998 memcpy (font_allcs
, base_fontname
, p
- base_fontname
);
1999 strcat (font_allcs
, allcs
);
2001 /* Build the font spec that matches all families and
2003 len
= p
- p1
+ strlen (allcs
) + strlen (allfamilies
) + 1;
2004 font_allfamilies
= (char *) alloca (len
);
2005 memset (font_allfamilies
, 0, len
);
2006 strcpy (font_allfamilies
, allfamilies
);
2007 memcpy (font_allfamilies
+ strlen (allfamilies
), p1
, p
- p1
);
2008 strcat (font_allfamilies
, allcs
);
2010 /* Build the font spec that matches all. */
2011 len
= p
- p2
+ strlen (allcs
) + strlen (all
) + strlen (allfamilies
) + 1;
2012 font_all
= (char *) alloca (len
);
2013 memset (font_all
, 0, len
);
2014 strcpy (font_all
, allfamilies
);
2015 strcat (font_all
, all
);
2016 memcpy (font_all
+ strlen (all
) + strlen (allfamilies
), p2
, p
- p2
);
2017 strcat (font_all
, allcs
);
2019 /* Build the actual font set name. */
2020 len
= strlen (base_fontname
) + strlen (font_allcs
)
2021 + strlen (font_allfamilies
) + strlen (font_all
) + 5;
2022 fontsetname
= xmalloc (len
);
2023 memset (fontsetname
, 0, len
);
2024 strcpy (fontsetname
, base_fontname
);
2025 strcat (fontsetname
, sep
);
2026 strcat (fontsetname
, font_allcs
);
2027 strcat (fontsetname
, sep
);
2028 strcat (fontsetname
, font_allfamilies
);
2029 strcat (fontsetname
, sep
);
2030 strcat (fontsetname
, font_all
);
2034 strcat (fontsetname
, ":");
2038 #ifdef DEBUG_XIC_FONTSET
2040 print_fontset_result (xfs
, name
, missing_list
, missing_count
)
2043 char **missing_list
;
2047 fprintf (stderr
, "XIC Fontset created: %s\n", name
);
2050 fprintf (stderr
, "XIC Fontset failed: %s\n", name
);
2051 while (missing_count
-- > 0)
2053 fprintf (stderr
, " missing: %s\n", *missing_list
);
2062 xic_create_xfontset (struct frame
*f
)
2064 XFontSet xfs
= NULL
;
2065 struct font
*font
= FRAME_FONT (f
);
2066 int pixel_size
= font
->pixel_size
;
2067 Lisp_Object rest
, frame
;
2069 /* See if there is another frame already using same fontset. */
2070 FOR_EACH_FRAME (rest
, frame
)
2072 struct frame
*cf
= XFRAME (frame
);
2074 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
2075 && FRAME_X_DISPLAY_INFO (cf
) == FRAME_X_DISPLAY_INFO (f
)
2077 && FRAME_FONT (f
)->pixel_size
== pixel_size
)
2079 xfs
= FRAME_XIC_FONTSET (cf
);
2087 char **missing_list
;
2090 const char *xlfd_format
= "-*-*-medium-r-normal--%d-*-*-*-*-*";
2092 sprintf (buf
, xlfd_format
, pixel_size
);
2093 missing_list
= NULL
;
2094 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
2095 &missing_list
, &missing_count
, &def_string
);
2096 #ifdef DEBUG_XIC_FONTSET
2097 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
2100 XFreeStringList (missing_list
);
2103 /* List of pixel sizes most likely available. Find one that
2104 is closest to pixel_size. */
2105 int sizes
[] = {0, 8, 10, 11, 12, 14, 17, 18, 20, 24, 26, 34, 0};
2106 int *smaller
, *larger
;
2108 for (smaller
= sizes
; smaller
[1]; smaller
++)
2109 if (smaller
[1] >= pixel_size
)
2111 larger
= smaller
+ 1;
2112 if (*larger
== pixel_size
)
2114 while (*smaller
|| *larger
)
2119 this_size
= *smaller
--;
2120 else if (! *smaller
)
2121 this_size
= *larger
++;
2122 else if (pixel_size
- *smaller
< *larger
- pixel_size
)
2123 this_size
= *smaller
--;
2125 this_size
= *larger
++;
2126 sprintf (buf
, xlfd_format
, this_size
);
2127 missing_list
= NULL
;
2128 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
2129 &missing_list
, &missing_count
, &def_string
);
2130 #ifdef DEBUG_XIC_FONTSET
2131 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
2134 XFreeStringList (missing_list
);
2141 const char *last_resort
= "-*-*-*-r-normal--*-*-*-*-*-*";
2143 missing_list
= NULL
;
2144 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), last_resort
,
2145 &missing_list
, &missing_count
, &def_string
);
2146 #ifdef DEBUG_XIC_FONTSET
2147 print_fontset_result (xfs
, last_resort
, missing_list
, missing_count
);
2150 XFreeStringList (missing_list
);
2158 /* Free the X fontset of frame F if it is the last frame using it. */
2161 xic_free_xfontset (struct frame
*f
)
2163 Lisp_Object rest
, frame
;
2166 if (!FRAME_XIC_FONTSET (f
))
2169 /* See if there is another frame sharing the same fontset. */
2170 FOR_EACH_FRAME (rest
, frame
)
2172 struct frame
*cf
= XFRAME (frame
);
2173 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
2174 && FRAME_X_DISPLAY_INFO (cf
) == FRAME_X_DISPLAY_INFO (f
)
2175 && FRAME_XIC_FONTSET (cf
) == FRAME_XIC_FONTSET (f
))
2183 /* The fontset is not used anymore. It is safe to free it. */
2184 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
2186 if (FRAME_XIC_BASE_FONTNAME (f
))
2187 xfree (FRAME_XIC_BASE_FONTNAME (f
));
2188 FRAME_XIC_BASE_FONTNAME (f
) = NULL
;
2189 FRAME_XIC_FONTSET (f
) = NULL
;
2193 /* Value is the best input style, given user preferences USER (already
2194 checked to be supported by Emacs), and styles supported by the
2195 input method XIM. */
2198 best_xim_style (XIMStyles
*user
, XIMStyles
*xim
)
2202 for (i
= 0; i
< user
->count_styles
; ++i
)
2203 for (j
= 0; j
< xim
->count_styles
; ++j
)
2204 if (user
->supported_styles
[i
] == xim
->supported_styles
[j
])
2205 return user
->supported_styles
[i
];
2207 /* Return the default style. */
2208 return XIMPreeditNothing
| XIMStatusNothing
;
2211 /* Create XIC for frame F. */
2213 static XIMStyle xic_style
;
2216 create_frame_xic (struct frame
*f
)
2220 XFontSet xfs
= NULL
;
2225 /* Create X fontset. */
2226 xfs
= xic_create_xfontset (f
);
2227 xim
= FRAME_X_XIM (f
);
2232 XVaNestedList preedit_attr
;
2233 XVaNestedList status_attr
;
2235 s_area
.x
= 0; s_area
.y
= 0; s_area
.width
= 1; s_area
.height
= 1;
2236 spot
.x
= 0; spot
.y
= 1;
2238 /* Determine XIC style. */
2241 XIMStyles supported_list
;
2242 supported_list
.count_styles
= (sizeof supported_xim_styles
2243 / sizeof supported_xim_styles
[0]);
2244 supported_list
.supported_styles
= supported_xim_styles
;
2245 xic_style
= best_xim_style (&supported_list
,
2246 FRAME_X_XIM_STYLES (f
));
2249 preedit_attr
= XVaCreateNestedList (0,
2252 FRAME_FOREGROUND_PIXEL (f
),
2254 FRAME_BACKGROUND_PIXEL (f
),
2255 (xic_style
& XIMPreeditPosition
2260 status_attr
= XVaCreateNestedList (0,
2266 FRAME_FOREGROUND_PIXEL (f
),
2268 FRAME_BACKGROUND_PIXEL (f
),
2271 xic
= XCreateIC (xim
,
2272 XNInputStyle
, xic_style
,
2273 XNClientWindow
, FRAME_X_WINDOW (f
),
2274 XNFocusWindow
, FRAME_X_WINDOW (f
),
2275 XNStatusAttributes
, status_attr
,
2276 XNPreeditAttributes
, preedit_attr
,
2278 XFree (preedit_attr
);
2279 XFree (status_attr
);
2282 FRAME_XIC (f
) = xic
;
2283 FRAME_XIC_STYLE (f
) = xic_style
;
2284 FRAME_XIC_FONTSET (f
) = xfs
;
2288 /* Destroy XIC and free XIC fontset of frame F, if any. */
2291 free_frame_xic (struct frame
*f
)
2293 if (FRAME_XIC (f
) == NULL
)
2296 XDestroyIC (FRAME_XIC (f
));
2297 xic_free_xfontset (f
);
2299 FRAME_XIC (f
) = NULL
;
2303 /* Place preedit area for XIC of window W's frame to specified
2304 pixel position X/Y. X and Y are relative to window W. */
2307 xic_set_preeditarea (struct window
*w
, int x
, int y
)
2309 struct frame
*f
= XFRAME (w
->frame
);
2313 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
) + WINDOW_LEFT_FRINGE_WIDTH (w
);
2314 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
2315 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
2316 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2321 /* Place status area for XIC in bottom right corner of frame F.. */
2324 xic_set_statusarea (struct frame
*f
)
2326 XIC xic
= FRAME_XIC (f
);
2331 /* Negotiate geometry of status area. If input method has existing
2332 status area, use its current size. */
2333 area
.x
= area
.y
= area
.width
= area
.height
= 0;
2334 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
2335 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2338 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
2339 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2342 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
2344 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
2345 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2349 area
.width
= needed
->width
;
2350 area
.height
= needed
->height
;
2351 area
.x
= FRAME_PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
2352 area
.y
= (FRAME_PIXEL_HEIGHT (f
) - area
.height
2353 - FRAME_MENUBAR_HEIGHT (f
)
2354 - FRAME_TOOLBAR_TOP_HEIGHT (f
)
2355 - FRAME_INTERNAL_BORDER_WIDTH (f
));
2358 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
2359 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2364 /* Set X fontset for XIC of frame F, using base font name
2365 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2368 xic_set_xfontset (struct frame
*f
, const char *base_fontname
)
2373 xic_free_xfontset (f
);
2375 xfs
= xic_create_xfontset (f
);
2377 attr
= XVaCreateNestedList (0, XNFontSet
, xfs
, NULL
);
2378 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
2379 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2380 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
2381 XSetICValues (FRAME_XIC (f
), XNStatusAttributes
, attr
, NULL
);
2384 FRAME_XIC_FONTSET (f
) = xfs
;
2387 #endif /* HAVE_X_I18N */
2391 #ifdef USE_X_TOOLKIT
2393 /* Create and set up the X widget for frame F. */
2396 x_window (struct frame
*f
, long window_prompting
, int minibuffer_only
)
2398 XClassHint class_hints
;
2399 XSetWindowAttributes attributes
;
2400 unsigned long attribute_mask
;
2401 Widget shell_widget
;
2403 Widget frame_widget
;
2409 /* Use the resource name as the top-level widget name
2410 for looking up resources. Make a non-Lisp copy
2411 for the window manager, so GC relocation won't bother it.
2413 Elsewhere we specify the window name for the window manager. */
2416 char *str
= (char *) SDATA (Vx_resource_name
);
2417 f
->namebuf
= (char *) xmalloc (strlen (str
) + 1);
2418 strcpy (f
->namebuf
, str
);
2422 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2423 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2424 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2425 XtSetArg (al
[ac
], XtNborderWidth
, f
->border_width
); ac
++;
2426 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2427 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2428 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2429 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2430 applicationShellWidgetClass
,
2431 FRAME_X_DISPLAY (f
), al
, ac
);
2433 f
->output_data
.x
->widget
= shell_widget
;
2434 /* maybe_set_screen_title_format (shell_widget); */
2436 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2437 (widget_value
*) NULL
,
2438 shell_widget
, False
,
2442 (lw_callback
) NULL
);
2445 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2446 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2447 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2448 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2449 XtSetValues (pane_widget
, al
, ac
);
2450 f
->output_data
.x
->column_widget
= pane_widget
;
2452 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2453 the emacs screen when changing menubar. This reduces flickering. */
2456 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2457 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2458 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2459 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2460 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2461 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2462 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2463 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2464 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2465 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
2468 f
->output_data
.x
->edit_widget
= frame_widget
;
2470 XtManageChild (frame_widget
);
2472 /* Do some needed geometry management. */
2475 char *tem
, shell_position
[32];
2478 int extra_borders
= 0;
2480 = (f
->output_data
.x
->menubar_widget
2481 ? (f
->output_data
.x
->menubar_widget
->core
.height
2482 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
2485 #if 0 /* Experimentally, we now get the right results
2486 for -geometry -0-0 without this. 24 Aug 96, rms. */
2487 if (FRAME_EXTERNAL_MENU_BAR (f
))
2490 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2491 menubar_size
+= ibw
;
2495 f
->output_data
.x
->menubar_height
= menubar_size
;
2498 /* Motif seems to need this amount added to the sizes
2499 specified for the shell widget. The Athena/Lucid widgets don't.
2500 Both conclusions reached experimentally. -- rms. */
2501 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
2502 &extra_borders
, NULL
);
2506 /* Convert our geometry parameters into a geometry string
2508 Note that we do not specify here whether the position
2509 is a user-specified or program-specified one.
2510 We pass that information later, in x_wm_set_size_hints. */
2512 int left
= f
->left_pos
;
2513 int xneg
= window_prompting
& XNegative
;
2514 int top
= f
->top_pos
;
2515 int yneg
= window_prompting
& YNegative
;
2521 if (window_prompting
& USPosition
)
2522 sprintf (shell_position
, "=%dx%d%c%d%c%d",
2523 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2524 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
2525 (xneg
? '-' : '+'), left
,
2526 (yneg
? '-' : '+'), top
);
2529 sprintf (shell_position
, "=%dx%d",
2530 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2531 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
2533 /* Setting x and y when the position is not specified in
2534 the geometry string will set program position in the WM hints.
2535 If Emacs had just one program position, we could set it in
2536 fallback resources, but since each make-frame call can specify
2537 different program positions, this is easier. */
2538 XtSetArg (al
[ac
], XtNx
, left
); ac
++;
2539 XtSetArg (al
[ac
], XtNy
, top
); ac
++;
2543 len
= strlen (shell_position
) + 1;
2544 /* We don't free this because we don't know whether
2545 it is safe to free it while the frame exists.
2546 It isn't worth the trouble of arranging to free it
2547 when the frame is deleted. */
2548 tem
= (char *) xmalloc (len
);
2549 strncpy (tem
, shell_position
, len
);
2550 XtSetArg (al
[ac
], XtNgeometry
, tem
); ac
++;
2551 XtSetValues (shell_widget
, al
, ac
);
2554 XtManageChild (pane_widget
);
2555 XtRealizeWidget (shell_widget
);
2557 if (FRAME_X_EMBEDDED_P (f
))
2558 XReparentWindow (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
),
2559 f
->output_data
.x
->parent_desc
, 0, 0);
2561 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2563 validate_x_resource_name ();
2565 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
2566 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
2567 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2570 FRAME_XIC (f
) = NULL
;
2572 create_frame_xic (f
);
2575 f
->output_data
.x
->wm_hints
.input
= True
;
2576 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2577 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2578 &f
->output_data
.x
->wm_hints
);
2580 hack_wm_protocols (f
, shell_widget
);
2583 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2586 /* Do a stupid property change to force the server to generate a
2587 PropertyNotify event so that the event_stream server timestamp will
2588 be initialized to something relevant to the time we created the window.
2590 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2591 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2592 XA_ATOM
, 32, PropModeAppend
,
2593 (unsigned char*) NULL
, 0);
2595 /* Make all the standard events reach the Emacs frame. */
2596 attributes
.event_mask
= STANDARD_EVENT_SET
;
2601 /* XIM server might require some X events. */
2602 unsigned long fevent
= NoEventMask
;
2603 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2604 attributes
.event_mask
|= fevent
;
2606 #endif /* HAVE_X_I18N */
2608 attribute_mask
= CWEventMask
;
2609 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2610 attribute_mask
, &attributes
);
2612 XtMapWidget (frame_widget
);
2614 /* x_set_name normally ignores requests to set the name if the
2615 requested name is the same as the current name. This is the one
2616 place where that assumption isn't correct; f->name is set, but
2617 the X server hasn't been told. */
2620 int explicit = f
->explicit_name
;
2622 f
->explicit_name
= 0;
2625 x_set_name (f
, name
, explicit);
2628 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2629 f
->output_data
.x
->current_cursor
2630 = f
->output_data
.x
->text_cursor
);
2634 /* This is a no-op, except under Motif. Make sure main areas are
2635 set to something reasonable, in case we get an error later. */
2636 lw_set_main_areas (pane_widget
, 0, frame_widget
);
2639 #else /* not USE_X_TOOLKIT */
2642 x_window (FRAME_PTR f
)
2644 if (! xg_create_frame_widgets (f
))
2645 error ("Unable to create window");
2648 FRAME_XIC (f
) = NULL
;
2652 create_frame_xic (f
);
2655 /* XIM server might require some X events. */
2656 unsigned long fevent
= NoEventMask
;
2657 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2659 if (fevent
!= NoEventMask
)
2661 XSetWindowAttributes attributes
;
2662 XWindowAttributes wattr
;
2663 unsigned long attribute_mask
;
2665 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2667 attributes
.event_mask
= wattr
.your_event_mask
| fevent
;
2668 attribute_mask
= CWEventMask
;
2669 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2670 attribute_mask
, &attributes
);
2678 #else /*! USE_GTK */
2679 /* Create and set up the X window for frame F. */
2682 x_window (struct frame
*f
)
2684 XClassHint class_hints
;
2685 XSetWindowAttributes attributes
;
2686 unsigned long attribute_mask
;
2688 attributes
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2689 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
2690 attributes
.bit_gravity
= StaticGravity
;
2691 attributes
.backing_store
= NotUseful
;
2692 attributes
.save_under
= True
;
2693 attributes
.event_mask
= STANDARD_EVENT_SET
;
2694 attributes
.colormap
= FRAME_X_COLORMAP (f
);
2695 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
2700 = XCreateWindow (FRAME_X_DISPLAY (f
),
2701 f
->output_data
.x
->parent_desc
,
2704 FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
),
2706 CopyFromParent
, /* depth */
2707 InputOutput
, /* class */
2709 attribute_mask
, &attributes
);
2714 create_frame_xic (f
);
2717 /* XIM server might require some X events. */
2718 unsigned long fevent
= NoEventMask
;
2719 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2720 attributes
.event_mask
|= fevent
;
2721 attribute_mask
= CWEventMask
;
2722 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2723 attribute_mask
, &attributes
);
2726 #endif /* HAVE_X_I18N */
2728 validate_x_resource_name ();
2730 class_hints
.res_name
= (char *) SDATA (Vx_resource_name
);
2731 class_hints
.res_class
= (char *) SDATA (Vx_resource_class
);
2732 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2734 /* The menubar is part of the ordinary display;
2735 it does not count in addition to the height of the window. */
2736 f
->output_data
.x
->menubar_height
= 0;
2738 /* This indicates that we use the "Passive Input" input model.
2739 Unless we do this, we don't get the Focus{In,Out} events that we
2740 need to draw the cursor correctly. Accursed bureaucrats.
2741 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2743 f
->output_data
.x
->wm_hints
.input
= True
;
2744 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2745 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2746 &f
->output_data
.x
->wm_hints
);
2747 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
2749 /* Request "save yourself" and "delete window" commands from wm. */
2752 protocols
[0] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2753 protocols
[1] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2754 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2757 /* x_set_name normally ignores requests to set the name if the
2758 requested name is the same as the current name. This is the one
2759 place where that assumption isn't correct; f->name is set, but
2760 the X server hasn't been told. */
2763 int explicit = f
->explicit_name
;
2765 f
->explicit_name
= 0;
2768 x_set_name (f
, name
, explicit);
2771 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2772 f
->output_data
.x
->current_cursor
2773 = f
->output_data
.x
->text_cursor
);
2777 if (FRAME_X_WINDOW (f
) == 0)
2778 error ("Unable to create window");
2781 #endif /* not USE_GTK */
2782 #endif /* not USE_X_TOOLKIT */
2784 /* Verify that the icon position args for this window are valid. */
2787 x_icon_verify (struct frame
*f
, Lisp_Object parms
)
2789 Lisp_Object icon_x
, icon_y
;
2791 /* Set the position of the icon. Note that twm groups all
2792 icons in an icon window. */
2793 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2794 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2795 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2797 CHECK_NUMBER (icon_x
);
2798 CHECK_NUMBER (icon_y
);
2800 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2801 error ("Both left and top icon corners of icon must be specified");
2804 /* Handle the icon stuff for this window. Perhaps later we might
2805 want an x_set_icon_position which can be called interactively as
2809 x_icon (struct frame
*f
, Lisp_Object parms
)
2811 Lisp_Object icon_x
, icon_y
;
2813 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2816 /* Set the position of the icon. Note that twm groups all
2817 icons in an icon window. */
2818 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2819 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2820 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2822 CHECK_NUMBER (icon_x
);
2823 CHECK_NUMBER (icon_y
);
2825 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2826 error ("Both left and top icon corners of icon must be specified");
2830 if (! EQ (icon_x
, Qunbound
))
2831 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2833 #if 0 /* x_get_arg removes the visibility parameter as a side effect,
2834 but x_create_frame still needs it. */
2835 /* Start up iconic or window? */
2836 x_wm_set_window_state
2837 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
2843 x_text_icon (f
, (char *) SDATA ((!NILP (f
->icon_name
)
2850 /* Make the GCs needed for this window, setting the
2851 background, border and mouse colors; also create the
2852 mouse cursor and the gray border tile. */
2855 x_make_gc (struct frame
*f
)
2857 XGCValues gc_values
;
2861 /* Create the GCs of this frame.
2862 Note that many default values are used. */
2864 gc_values
.foreground
= FRAME_FOREGROUND_PIXEL (f
);
2865 gc_values
.background
= FRAME_BACKGROUND_PIXEL (f
);
2866 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2867 f
->output_data
.x
->normal_gc
2868 = XCreateGC (FRAME_X_DISPLAY (f
),
2870 GCLineWidth
| GCForeground
| GCBackground
,
2873 /* Reverse video style. */
2874 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2875 gc_values
.background
= FRAME_FOREGROUND_PIXEL (f
);
2876 f
->output_data
.x
->reverse_gc
2877 = XCreateGC (FRAME_X_DISPLAY (f
),
2879 GCForeground
| GCBackground
| GCLineWidth
,
2882 /* Cursor has cursor-color background, background-color foreground. */
2883 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2884 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
2885 gc_values
.fill_style
= FillOpaqueStippled
;
2886 f
->output_data
.x
->cursor_gc
2887 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2888 (GCForeground
| GCBackground
2889 | GCFillStyle
| GCLineWidth
),
2893 f
->output_data
.x
->white_relief
.gc
= 0;
2894 f
->output_data
.x
->black_relief
.gc
= 0;
2896 /* Create the gray border tile used when the pointer is not in
2897 the frame. Since this depends on the frame's pixel values,
2898 this must be done on a per-frame basis. */
2899 f
->output_data
.x
->border_tile
2900 = (XCreatePixmapFromBitmapData
2901 (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
2902 gray_bits
, gray_width
, gray_height
,
2903 FRAME_FOREGROUND_PIXEL (f
),
2904 FRAME_BACKGROUND_PIXEL (f
),
2905 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
2911 /* Free what was allocated in x_make_gc. */
2914 x_free_gcs (struct frame
*f
)
2916 Display
*dpy
= FRAME_X_DISPLAY (f
);
2920 if (f
->output_data
.x
->normal_gc
)
2922 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
2923 f
->output_data
.x
->normal_gc
= 0;
2926 if (f
->output_data
.x
->reverse_gc
)
2928 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
2929 f
->output_data
.x
->reverse_gc
= 0;
2932 if (f
->output_data
.x
->cursor_gc
)
2934 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
2935 f
->output_data
.x
->cursor_gc
= 0;
2938 if (f
->output_data
.x
->border_tile
)
2940 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
2941 f
->output_data
.x
->border_tile
= 0;
2948 /* Handler for signals raised during x_create_frame and
2949 x_create_top_frame. FRAME is the frame which is partially
2953 unwind_create_frame (Lisp_Object frame
)
2955 struct frame
*f
= XFRAME (frame
);
2957 /* If frame is already dead, nothing to do. This can happen if the
2958 display is disconnected after the frame has become official, but
2959 before x_create_frame removes the unwind protect. */
2960 if (!FRAME_LIVE_P (f
))
2963 /* If frame is ``official'', nothing to do. */
2964 if (!CONSP (Vframe_list
) || !EQ (XCAR (Vframe_list
), frame
))
2967 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2970 x_free_frame_resources (f
);
2973 /* Check that reference counts are indeed correct. */
2974 xassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
2975 xassert (dpyinfo
->image_cache
->refcount
== image_cache_refcount
);
2985 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
2987 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2988 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
2990 Lisp_Object font
= Qnil
;
2991 if (EQ (font_param
, Qunbound
))
2994 if (NILP (font_param
))
2996 /* System font should take precedendce over X resources. We suggest this
2997 regardless of font-use-system-font because .emacs may not have been
2999 const char *system_font
= xsettings_get_system_font ();
3002 char *name
= xstrdup (system_font
);
3003 font
= font_open_by_name (f
, name
);
3009 font
= !NILP (font_param
) ? font_param
3010 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
3012 if (! FONTP (font
) && ! STRINGP (font
))
3017 /* This will find the normal Xft font. */
3020 "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1",
3021 "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
3022 "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
3023 /* This was formerly the first thing tried, but it finds
3024 too many fonts and takes too long. */
3025 "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1",
3026 /* If those didn't work, look for something which will
3028 "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1",
3033 for (i
= 0; names
[i
]; i
++)
3035 font
= font_open_by_name (f
, names
[i
]);
3040 error ("No suitable font was found");
3042 else if (!NILP (font_param
))
3044 /* Remember the explicit font parameter, so we can re-apply it after
3045 we've applied the `default' face settings. */
3046 x_set_frame_parameters (f
, Fcons (Fcons (Qfont_param
, font_param
), Qnil
));
3049 /* This call will make X resources override any system font setting. */
3050 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
3054 DEFUN ("x-wm-set-size-hint", Fx_wm_set_size_hint
, Sx_wm_set_size_hint
,
3056 doc
: /* Send the size hints for frame FRAME to the window manager.
3057 If FRAME is nil, use the selected frame. */)
3062 frame
= selected_frame
;
3066 x_wm_set_size_hint (f
, 0, 0);
3072 set_machine_and_pid_properties (struct frame
*f
)
3074 /* See the above comment "Note: Encoding strategy". */
3077 int do_free_text_value
= 0;
3078 long pid
= (long) getpid ();
3080 text
.value
= x_encode_text (Vsystem_name
,
3081 Qcompound_text
, 0, &bytes
, &stringp
,
3082 &do_free_text_value
);
3083 text
.encoding
= (stringp
? XA_STRING
3084 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
3086 text
.nitems
= bytes
;
3087 XSetWMClientMachine (FRAME_X_DISPLAY (f
),
3088 FRAME_OUTER_WINDOW (f
),
3090 if (do_free_text_value
)
3093 XChangeProperty (FRAME_X_DISPLAY (f
),
3094 FRAME_OUTER_WINDOW (f
),
3095 XInternAtom (FRAME_X_DISPLAY (f
),
3098 XA_CARDINAL
, 32, PropModeReplace
,
3099 (unsigned char *) &pid
, 1);
3102 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
3104 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
3105 Return an Emacs frame object.
3106 PARMS is an alist of frame parameters.
3107 If the parameters specify that the frame should not have a minibuffer,
3108 and do not specify a specific minibuffer window to use,
3109 then `default-minibuffer-frame' must be a frame whose minibuffer can
3110 be shared by the new frame.
3112 This function is an internal primitive--use `make-frame' instead. */)
3116 Lisp_Object frame
, tem
;
3118 int minibuffer_only
= 0;
3119 long window_prompting
= 0;
3121 int count
= SPECPDL_INDEX ();
3122 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
3123 Lisp_Object display
;
3124 struct x_display_info
*dpyinfo
= NULL
;
3128 parms
= Fcopy_alist (parms
);
3130 /* Use this general default value to start with
3131 until we know if this frame has a specified name. */
3132 Vx_resource_name
= Vinvocation_name
;
3134 display
= x_get_arg (dpyinfo
, parms
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
3135 if (EQ (display
, Qunbound
))
3136 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
3137 if (EQ (display
, Qunbound
))
3139 dpyinfo
= check_x_display_info (display
);
3140 kb
= dpyinfo
->terminal
->kboard
;
3142 if (!dpyinfo
->terminal
->name
)
3143 error ("Terminal is not live, can't create new frames on it");
3145 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
3147 && ! EQ (name
, Qunbound
)
3149 error ("Invalid frame name--not a string or nil");
3152 Vx_resource_name
= name
;
3154 /* See if parent window is specified. */
3155 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
3156 if (EQ (parent
, Qunbound
))
3158 if (! NILP (parent
))
3159 CHECK_NUMBER (parent
);
3161 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
3162 /* No need to protect DISPLAY because that's not used after passing
3163 it to make_frame_without_minibuffer. */
3165 GCPRO4 (parms
, parent
, name
, frame
);
3166 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
3168 if (EQ (tem
, Qnone
) || NILP (tem
))
3169 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
3170 else if (EQ (tem
, Qonly
))
3172 f
= make_minibuffer_frame ();
3173 minibuffer_only
= 1;
3175 else if (WINDOWP (tem
))
3176 f
= make_frame_without_minibuffer (tem
, kb
, display
);
3180 XSETFRAME (frame
, f
);
3182 /* Note that X Windows does support scroll bars. */
3183 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 1;
3185 f
->terminal
= dpyinfo
->terminal
;
3186 f
->terminal
->reference_count
++;
3188 f
->output_method
= output_x_window
;
3189 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
3190 memset (f
->output_data
.x
, 0, sizeof (struct x_output
));
3191 f
->output_data
.x
->icon_bitmap
= -1;
3192 FRAME_FONTSET (f
) = -1;
3193 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
3194 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
3195 #ifdef USE_TOOLKIT_SCROLL_BARS
3196 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
3197 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
3198 #endif /* USE_TOOLKIT_SCROLL_BARS */
3201 = x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
3203 if (! STRINGP (f
->icon_name
))
3204 f
->icon_name
= Qnil
;
3206 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
3208 /* With FRAME_X_DISPLAY_INFO set up, this unwind-protect is safe. */
3209 record_unwind_protect (unwind_create_frame
, frame
);
3211 image_cache_refcount
= FRAME_IMAGE_CACHE (f
)->refcount
;
3212 dpyinfo_refcount
= dpyinfo
->reference_count
;
3213 #endif /* GLYPH_DEBUG */
3215 /* These colors will be set anyway later, but it's important
3216 to get the color reference counts right, so initialize them! */
3219 struct gcpro gcpro1
;
3221 /* Function x_decode_color can signal an error. Make
3222 sure to initialize color slots so that we won't try
3223 to free colors we haven't allocated. */
3224 FRAME_FOREGROUND_PIXEL (f
) = -1;
3225 FRAME_BACKGROUND_PIXEL (f
) = -1;
3226 f
->output_data
.x
->cursor_pixel
= -1;
3227 f
->output_data
.x
->cursor_foreground_pixel
= -1;
3228 f
->output_data
.x
->border_pixel
= -1;
3229 f
->output_data
.x
->mouse_pixel
= -1;
3231 black
= build_string ("black");
3233 FRAME_FOREGROUND_PIXEL (f
)
3234 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3235 FRAME_BACKGROUND_PIXEL (f
)
3236 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3237 f
->output_data
.x
->cursor_pixel
3238 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3239 f
->output_data
.x
->cursor_foreground_pixel
3240 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3241 f
->output_data
.x
->border_pixel
3242 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3243 f
->output_data
.x
->mouse_pixel
3244 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3248 /* Specify the parent under which to make this X window. */
3252 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
3253 f
->output_data
.x
->explicit_parent
= 1;
3257 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3258 f
->output_data
.x
->explicit_parent
= 0;
3261 /* Set the name; the functions to which we pass f expect the name to
3263 if (EQ (name
, Qunbound
) || NILP (name
))
3265 f
->name
= build_string (dpyinfo
->x_id_name
);
3266 f
->explicit_name
= 0;
3271 f
->explicit_name
= 1;
3272 /* use the frame's title when getting resources for this frame. */
3273 specbind (Qx_resource_name
, name
);
3276 f
->resx
= dpyinfo
->resx
;
3277 f
->resy
= dpyinfo
->resy
;
3279 #ifdef HAVE_FREETYPE
3281 register_font_driver (&xftfont_driver
, f
);
3282 #else /* not HAVE_XFT */
3283 register_font_driver (&ftxfont_driver
, f
);
3284 #endif /* not HAVE_XFT */
3285 #endif /* HAVE_FREETYPE */
3286 register_font_driver (&xfont_driver
, f
);
3288 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
3289 "fontBackend", "FontBackend", RES_TYPE_STRING
);
3291 /* Extract the window parameters from the supplied values
3292 that are needed to determine window geometry. */
3293 x_default_font_parameter (f
, parms
);
3294 if (!FRAME_FONT (f
))
3296 delete_frame (frame
, Qnoelisp
);
3297 error ("Invalid frame font");
3300 /* Frame contents get displaced if an embedded X window has a border. */
3301 if (! FRAME_X_EMBEDDED_P (f
))
3302 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
3303 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
3305 /* This defaults to 1 in order to match xterm. We recognize either
3306 internalBorderWidth or internalBorder (which is what xterm calls
3308 if (NILP (Fassq (Qinternal_border_width
, parms
)))
3312 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
3313 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
3314 if (! EQ (value
, Qunbound
))
3315 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
3318 x_default_parameter (f
, parms
, Qinternal_border_width
,
3319 #ifdef USE_GTK /* We used to impose 0 in xg_create_frame_widgets. */
3324 "internalBorderWidth", "internalBorderWidth",
3326 x_default_parameter (f
, parms
, Qvertical_scroll_bars
,
3327 #if defined(USE_GTK) && defined(USE_TOOLKIT_SCROLL_BARS)
3332 "verticalScrollBars", "ScrollBars",
3335 /* Also do the stuff which must be set before the window exists. */
3336 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3337 "foreground", "Foreground", RES_TYPE_STRING
);
3338 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3339 "background", "Background", RES_TYPE_STRING
);
3340 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3341 "pointerColor", "Foreground", RES_TYPE_STRING
);
3342 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
3343 "cursorColor", "Foreground", RES_TYPE_STRING
);
3344 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3345 "borderColor", "BorderColor", RES_TYPE_STRING
);
3346 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3347 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3348 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3349 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3350 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3351 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3352 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3353 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3355 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3356 "scrollBarForeground",
3357 "ScrollBarForeground", 1);
3358 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3359 "scrollBarBackground",
3360 "ScrollBarBackground", 0);
3362 /* Init faces before x_default_parameter is called for scroll-bar
3363 parameters because that function calls x_set_scroll_bar_width,
3364 which calls change_frame_size, which calls Fset_window_buffer,
3365 which runs hooks, which call Fvertical_motion. At the end, we
3366 end up in init_iterator with a null face cache, which should not
3368 init_frame_faces (f
);
3370 /* The X resources controlling the menu-bar and tool-bar are
3371 processed specially at startup, and reflected in the mode
3372 variables; ignore them here. */
3373 x_default_parameter (f
, parms
, Qmenu_bar_lines
,
3374 NILP (Vmenu_bar_mode
)
3375 ? make_number (0) : make_number (1),
3376 NULL
, NULL
, RES_TYPE_NUMBER
);
3377 x_default_parameter (f
, parms
, Qtool_bar_lines
,
3378 NILP (Vtool_bar_mode
)
3379 ? make_number (0) : make_number (1),
3380 NULL
, NULL
, RES_TYPE_NUMBER
);
3382 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3383 "bufferPredicate", "BufferPredicate",
3385 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3386 "title", "Title", RES_TYPE_STRING
);
3387 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3388 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3389 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3390 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3392 /* Compute the size of the X window. */
3393 window_prompting
= x_figure_window_size (f
, parms
, 1);
3395 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3396 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3398 x_icon_verify (f
, parms
);
3400 /* Create the X widget or window. */
3401 #ifdef USE_X_TOOLKIT
3402 x_window (f
, window_prompting
, minibuffer_only
);
3410 /* Now consider the frame official. */
3411 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
3412 Vframe_list
= Fcons (frame
, Vframe_list
);
3414 /* We need to do this after creating the X window, so that the
3415 icon-creation functions can say whose icon they're describing. */
3416 x_default_parameter (f
, parms
, Qicon_type
, Qt
,
3417 "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL
);
3419 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3420 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3421 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3422 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3423 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3424 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3425 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3426 "scrollBarWidth", "ScrollBarWidth",
3428 x_default_parameter (f
, parms
, Qalpha
, Qnil
,
3429 "alpha", "Alpha", RES_TYPE_NUMBER
);
3431 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
3432 Change will not be effected unless different from the current
3434 width
= FRAME_COLS (f
);
3435 height
= FRAME_LINES (f
);
3437 SET_FRAME_COLS (f
, 0);
3438 FRAME_LINES (f
) = 0;
3439 change_frame_size (f
, height
, width
, 1, 0, 0);
3441 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3442 /* Create the menu bar. */
3443 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3445 /* If this signals an error, we haven't set size hints for the
3446 frame and we didn't make it visible. */
3447 initialize_frame_menubar (f
);
3450 /* This is a no-op, except under Motif where it arranges the
3451 main window for the widgets on it. */
3452 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3453 f
->output_data
.x
->menubar_widget
,
3454 f
->output_data
.x
->edit_widget
);
3455 #endif /* not USE_GTK */
3457 #endif /* USE_X_TOOLKIT || USE_GTK */
3459 /* Tell the server what size and position, etc, we want, and how
3460 badly we want them. This should be done after we have the menu
3461 bar so that its size can be taken into account. */
3463 x_wm_set_size_hint (f
, window_prompting
, 0);
3466 /* Make the window appear on the frame and enable display, unless
3467 the caller says not to. However, with explicit parent, Emacs
3468 cannot control visibility, so don't try. */
3469 if (! f
->output_data
.x
->explicit_parent
)
3471 Lisp_Object visibility
;
3473 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3475 if (EQ (visibility
, Qunbound
))
3478 if (EQ (visibility
, Qicon
))
3479 x_iconify_frame (f
);
3480 else if (! NILP (visibility
))
3481 x_make_frame_visible (f
);
3483 /* Must have been Qnil. */
3489 /* Set machine name and pid for the purpose of window managers. */
3490 set_machine_and_pid_properties(f
);
3492 /* Set the WM leader property. GTK does this itself, so this is not
3493 needed when using GTK. */
3494 if (dpyinfo
->client_leader_window
!= 0)
3496 XChangeProperty (FRAME_X_DISPLAY (f
),
3497 FRAME_OUTER_WINDOW (f
),
3498 dpyinfo
->Xatom_wm_client_leader
,
3499 XA_WINDOW
, 32, PropModeReplace
,
3500 (unsigned char *) &dpyinfo
->client_leader_window
, 1);
3505 /* Initialize `default-minibuffer-frame' in case this is the first
3506 frame on this terminal. */
3507 if (FRAME_HAS_MINIBUF_P (f
)
3508 && (!FRAMEP (kb
->Vdefault_minibuffer_frame
)
3509 || !FRAME_LIVE_P (XFRAME (kb
->Vdefault_minibuffer_frame
))))
3510 kb
->Vdefault_minibuffer_frame
= frame
;
3512 /* All remaining specified parameters, which have not been "used"
3513 by x_get_arg and friends, now go in the misc. alist of the frame. */
3514 for (tem
= parms
; CONSP (tem
); tem
= XCDR (tem
))
3515 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
3516 f
->param_alist
= Fcons (XCAR (tem
), f
->param_alist
);
3520 /* Make sure windows on this frame appear in calls to next-window
3521 and similar functions. */
3522 Vwindow_list
= Qnil
;
3524 return unbind_to (count
, frame
);
3528 /* FRAME is used only to get a handle on the X display. We don't pass the
3529 display info directly because we're called from frame.c, which doesn't
3530 know about that structure. */
3533 x_get_focus_frame (struct frame
*frame
)
3535 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (frame
);
3537 if (! dpyinfo
->x_focus_frame
)
3540 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3545 /* In certain situations, when the window manager follows a
3546 click-to-focus policy, there seems to be no way around calling
3547 XSetInputFocus to give another frame the input focus .
3549 In an ideal world, XSetInputFocus should generally be avoided so
3550 that applications don't interfere with the window manager's focus
3551 policy. But I think it's okay to use when it's clearly done
3552 following a user-command. */
3554 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
3555 doc
: /* Set the input focus to FRAME.
3556 FRAME nil means use the selected frame. */)
3559 struct frame
*f
= check_x_frame (frame
);
3560 Display
*dpy
= FRAME_X_DISPLAY (f
);
3563 x_catch_errors (dpy
);
3564 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3565 RevertToParent
, CurrentTime
);
3566 x_ewmh_activate_frame (f
);
3567 x_uncatch_errors ();
3574 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
3575 doc
: /* Internal function called by `color-defined-p', which see. */)
3576 (Lisp_Object color
, Lisp_Object frame
)
3579 FRAME_PTR f
= check_x_frame (frame
);
3581 CHECK_STRING (color
);
3583 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
3589 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
3590 doc
: /* Internal function called by `color-values', which see. */)
3591 (Lisp_Object color
, Lisp_Object frame
)
3594 FRAME_PTR f
= check_x_frame (frame
);
3596 CHECK_STRING (color
);
3598 if (x_defined_color (f
, SDATA (color
), &foo
, 0))
3599 return list3 (make_number (foo
.red
),
3600 make_number (foo
.green
),
3601 make_number (foo
.blue
));
3606 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
3607 doc
: /* Internal function called by `display-color-p', which see. */)
3608 (Lisp_Object terminal
)
3610 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3612 if (dpyinfo
->n_planes
<= 2)
3615 switch (dpyinfo
->visual
->class)
3628 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3630 doc
: /* Return t if the X display supports shades of gray.
3631 Note that color displays do support shades of gray.
3632 The optional argument TERMINAL specifies which display to ask about.
3633 TERMINAL should be a terminal object, a frame or a display name (a string).
3634 If omitted or nil, that stands for the selected frame's display. */)
3635 (Lisp_Object terminal
)
3637 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3639 if (dpyinfo
->n_planes
<= 1)
3642 switch (dpyinfo
->visual
->class)
3657 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3659 doc
: /* Return the width in pixels 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 return make_number (x_display_pixel_width (dpyinfo
));
3670 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3671 Sx_display_pixel_height
, 0, 1, 0,
3672 doc
: /* Return the height in pixels of the X display TERMINAL.
3673 The optional argument TERMINAL specifies which display to ask about.
3674 TERMINAL should be a terminal object, a frame or a display name (a string).
3675 If omitted or nil, that stands for the selected frame's display. */)
3676 (Lisp_Object terminal
)
3678 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3680 return make_number (x_display_pixel_height (dpyinfo
));
3683 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3685 doc
: /* Return the number of bitplanes of the X display TERMINAL.
3686 The optional argument TERMINAL specifies which display to ask about.
3687 TERMINAL should be a terminal object, a frame or a display name (a string).
3688 If omitted or nil, that stands for the selected frame's display. */)
3689 (Lisp_Object terminal
)
3691 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3693 return make_number (dpyinfo
->n_planes
);
3696 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3698 doc
: /* Return the number of color cells of the X display TERMINAL.
3699 The optional argument TERMINAL specifies which display to ask about.
3700 TERMINAL should be a terminal object, a frame or a display name (a string).
3701 If omitted or nil, that stands for the selected frame's display. */)
3702 (Lisp_Object terminal
)
3704 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3706 int nr_planes
= DisplayPlanes (dpyinfo
->display
,
3707 XScreenNumberOfScreen (dpyinfo
->screen
));
3709 /* Truncate nr_planes to 24 to avoid integer overflow.
3710 Some displays says 32, but only 24 bits are actually significant.
3711 There are only very few and rare video cards that have more than
3712 24 significant bits. Also 24 bits is more than 16 million colors,
3713 it "should be enough for everyone". */
3714 if (nr_planes
> 24) nr_planes
= 24;
3716 return make_number (1 << nr_planes
);
3719 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3720 Sx_server_max_request_size
,
3722 doc
: /* Return the maximum request size of the X server of display TERMINAL.
3723 The optional argument TERMINAL specifies which display to ask about.
3724 TERMINAL should be a terminal object, a frame or a display name (a string).
3725 If omitted or nil, that stands for the selected frame's display. */)
3726 (Lisp_Object terminal
)
3728 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3730 return make_number (MAXREQUEST (dpyinfo
->display
));
3733 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3734 doc
: /* Return the "vendor ID" string of the X server of display TERMINAL.
3735 \(Labelling every distributor as a "vendor" embodies the false assumption
3736 that operating systems cannot be developed and distributed noncommercially.)
3737 The optional argument TERMINAL specifies which display to ask about.
3738 TERMINAL should be a terminal object, a frame or a display name (a string).
3739 If omitted or nil, that stands for the selected frame's display. */)
3740 (Lisp_Object terminal
)
3742 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3743 const char *vendor
= ServerVendor (dpyinfo
->display
);
3745 if (! vendor
) vendor
= "";
3746 return build_string (vendor
);
3749 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3750 doc
: /* Return the version numbers of the X server of display TERMINAL.
3751 The value is a list of three integers: the major and minor
3752 version numbers of the X Protocol in use, and the distributor-specific release
3753 number. See also the function `x-server-vendor'.
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
);
3761 Display
*dpy
= dpyinfo
->display
;
3763 return Fcons (make_number (ProtocolVersion (dpy
)),
3764 Fcons (make_number (ProtocolRevision (dpy
)),
3765 Fcons (make_number (VendorRelease (dpy
)), Qnil
)));
3768 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3769 doc
: /* Return the number of screens on the X server of display TERMINAL.
3770 The optional argument TERMINAL specifies which display to ask about.
3771 TERMINAL should be a terminal object, a frame or a display name (a string).
3772 If omitted or nil, that stands for the selected frame's display. */)
3773 (Lisp_Object terminal
)
3775 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3777 return make_number (ScreenCount (dpyinfo
->display
));
3780 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3781 doc
: /* Return the height in millimeters of the X display TERMINAL.
3782 The optional argument TERMINAL specifies which display to ask about.
3783 TERMINAL should be a terminal object, a frame or a display name (a string).
3784 If omitted or nil, that stands for the selected frame's display. */)
3785 (Lisp_Object terminal
)
3787 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3789 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3792 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3793 doc
: /* Return the width in millimeters of the X display TERMINAL.
3794 The optional argument TERMINAL specifies which display to ask about.
3795 TERMINAL should be a terminal object, a frame or a display name (a string).
3796 If omitted or nil, that stands for the selected frame's display. */)
3797 (Lisp_Object terminal
)
3799 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3801 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3804 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3805 Sx_display_backing_store
, 0, 1, 0,
3806 doc
: /* Return an indication of whether X display TERMINAL does backing store.
3807 The value may be `always', `when-mapped', or `not-useful'.
3808 The optional argument TERMINAL specifies which display to ask about.
3809 TERMINAL should be a terminal object, a frame or a display name (a string).
3810 If omitted or nil, that stands for the selected frame's display. */)
3811 (Lisp_Object terminal
)
3813 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3816 switch (DoesBackingStore (dpyinfo
->screen
))
3819 result
= intern ("always");
3823 result
= intern ("when-mapped");
3827 result
= intern ("not-useful");
3831 error ("Strange value for BackingStore parameter of screen");
3838 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3839 Sx_display_visual_class
, 0, 1, 0,
3840 doc
: /* Return the visual class of the X display TERMINAL.
3841 The value is one of the symbols `static-gray', `gray-scale',
3842 `static-color', `pseudo-color', `true-color', or `direct-color'.
3844 The optional argument TERMINAL specifies which display to ask about.
3845 TERMINAL should 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
);
3852 switch (dpyinfo
->visual
->class)
3855 result
= intern ("static-gray");
3858 result
= intern ("gray-scale");
3861 result
= intern ("static-color");
3864 result
= intern ("pseudo-color");
3867 result
= intern ("true-color");
3870 result
= intern ("direct-color");
3873 error ("Display has an unknown visual class");
3880 DEFUN ("x-display-save-under", Fx_display_save_under
,
3881 Sx_display_save_under
, 0, 1, 0,
3882 doc
: /* Return t if the X display TERMINAL supports the save-under feature.
3883 The optional argument TERMINAL specifies which display to ask about.
3884 TERMINAL should be a terminal object, a frame or a display name (a string).
3885 If omitted or nil, that stands for the selected frame's display. */)
3886 (Lisp_Object terminal
)
3888 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3890 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3897 x_pixel_width (register struct frame
*f
)
3899 return FRAME_PIXEL_WIDTH (f
);
3903 x_pixel_height (register struct frame
*f
)
3905 return FRAME_PIXEL_HEIGHT (f
);
3909 x_char_width (register struct frame
*f
)
3911 return FRAME_COLUMN_WIDTH (f
);
3915 x_char_height (register struct frame
*f
)
3917 return FRAME_LINE_HEIGHT (f
);
3921 x_screen_planes (register struct frame
*f
)
3923 return FRAME_X_DISPLAY_INFO (f
)->n_planes
;
3928 /************************************************************************
3930 ************************************************************************/
3933 /* Mapping visual names to visuals. */
3935 static struct visual_class
3942 {"StaticGray", StaticGray
},
3943 {"GrayScale", GrayScale
},
3944 {"StaticColor", StaticColor
},
3945 {"PseudoColor", PseudoColor
},
3946 {"TrueColor", TrueColor
},
3947 {"DirectColor", DirectColor
},
3952 #ifndef HAVE_XSCREENNUMBEROFSCREEN
3954 /* Value is the screen number of screen SCR. This is a substitute for
3955 the X function with the same name when that doesn't exist. */
3958 XScreenNumberOfScreen (scr
)
3959 register Screen
*scr
;
3961 Display
*dpy
= scr
->display
;
3964 for (i
= 0; i
< dpy
->nscreens
; ++i
)
3965 if (scr
== dpy
->screens
+ i
)
3971 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
3974 /* Select the visual that should be used on display DPYINFO. Set
3975 members of DPYINFO appropriately. Called from x_term_init. */
3978 select_visual (struct x_display_info
*dpyinfo
)
3980 Display
*dpy
= dpyinfo
->display
;
3981 Screen
*screen
= dpyinfo
->screen
;
3984 /* See if a visual is specified. */
3985 value
= display_x_get_resource (dpyinfo
,
3986 build_string ("visualClass"),
3987 build_string ("VisualClass"),
3989 if (STRINGP (value
))
3991 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
3992 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
3993 depth, a decimal number. NAME is compared with case ignored. */
3994 char *s
= (char *) alloca (SBYTES (value
) + 1);
3999 strcpy (s
, SDATA (value
));
4000 dash
= strchr (s
, '-');
4003 dpyinfo
->n_planes
= atoi (dash
+ 1);
4007 /* We won't find a matching visual with depth 0, so that
4008 an error will be printed below. */
4009 dpyinfo
->n_planes
= 0;
4011 /* Determine the visual class. */
4012 for (i
= 0; visual_classes
[i
].name
; ++i
)
4013 if (xstrcasecmp (s
, visual_classes
[i
].name
) == 0)
4015 class = visual_classes
[i
].class;
4019 /* Look up a matching visual for the specified class. */
4021 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
4022 dpyinfo
->n_planes
, class, &vinfo
))
4023 fatal ("Invalid visual specification `%s'", SDATA (value
));
4025 dpyinfo
->visual
= vinfo
.visual
;
4030 XVisualInfo
*vinfo
, vinfo_template
;
4032 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
4034 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
4035 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
4036 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
4037 &vinfo_template
, &n_visuals
);
4039 fatal ("Can't get proper X visual info");
4041 dpyinfo
->n_planes
= vinfo
->depth
;
4042 XFree ((char *) vinfo
);
4047 /* Return the X display structure for the display named NAME.
4048 Open a new connection if necessary. */
4050 struct x_display_info
*
4051 x_display_info_for_name (Lisp_Object name
)
4054 struct x_display_info
*dpyinfo
;
4056 CHECK_STRING (name
);
4059 if (! EQ (Vinitial_window_system
, intern ("x")))
4060 error ("Not using X Windows"); /* That doesn't stop us anymore. */
4063 for (dpyinfo
= x_display_list
, names
= x_display_name_list
;
4065 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
4068 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
4073 /* Use this general default value to start with. */
4074 Vx_resource_name
= Vinvocation_name
;
4076 validate_x_resource_name ();
4078 dpyinfo
= x_term_init (name
, (char *)0,
4079 (char *) SDATA (Vx_resource_name
));
4082 error ("Cannot connect to X server %s", SDATA (name
));
4085 XSETFASTINT (Vwindow_system_version
, 11);
4091 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4093 doc
: /* Open a connection to an X server.
4094 DISPLAY is the name of the display to connect to.
4095 Optional second arg XRM-STRING is a string of resources in xrdb format.
4096 If the optional third arg MUST-SUCCEED is non-nil,
4097 terminate Emacs if we can't open the connection. */)
4098 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
4100 unsigned char *xrm_option
;
4101 struct x_display_info
*dpyinfo
;
4103 CHECK_STRING (display
);
4104 if (! NILP (xrm_string
))
4105 CHECK_STRING (xrm_string
);
4108 if (! EQ (Vinitial_window_system
, intern ("x")))
4109 error ("Not using X Windows"); /* That doesn't stop us anymore. */
4112 if (! NILP (xrm_string
))
4113 xrm_option
= (unsigned char *) SDATA (xrm_string
);
4115 xrm_option
= (unsigned char *) 0;
4117 validate_x_resource_name ();
4119 /* This is what opens the connection and sets x_current_display.
4120 This also initializes many symbols, such as those used for input. */
4121 dpyinfo
= x_term_init (display
, xrm_option
,
4122 (char *) SDATA (Vx_resource_name
));
4126 if (!NILP (must_succeed
))
4127 fatal ("Cannot connect to X server %s.\n\
4128 Check the DISPLAY environment variable or use `-d'.\n\
4129 Also use the `xauth' program to verify that you have the proper\n\
4130 authorization information needed to connect the X server.\n\
4131 An insecure way to solve the problem may be to use `xhost'.\n",
4134 error ("Cannot connect to X server %s", SDATA (display
));
4139 XSETFASTINT (Vwindow_system_version
, 11);
4143 DEFUN ("x-close-connection", Fx_close_connection
,
4144 Sx_close_connection
, 1, 1, 0,
4145 doc
: /* Close the connection to TERMINAL's X server.
4146 For TERMINAL, specify a terminal object, a frame or a display name (a
4147 string). If TERMINAL is nil, that stands for the selected frame's
4149 (Lisp_Object terminal
)
4151 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4153 if (dpyinfo
->reference_count
> 0)
4154 error ("Display still has frames on it");
4156 x_delete_terminal (dpyinfo
->terminal
);
4161 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4162 doc
: /* Return the list of display names that Emacs has connections to. */)
4165 Lisp_Object tail
, result
;
4168 for (tail
= x_display_name_list
; CONSP (tail
); tail
= XCDR (tail
))
4169 result
= Fcons (XCAR (XCAR (tail
)), result
);
4174 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4175 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
4176 If ON is nil, allow buffering of requests.
4177 Turning on synchronization prohibits the Xlib routines from buffering
4178 requests and seriously degrades performance, but makes debugging much
4180 The optional second argument TERMINAL specifies which display to act on.
4181 TERMINAL should be a terminal object, a frame or a display name (a string).
4182 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
4183 (Lisp_Object on
, Lisp_Object terminal
)
4185 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4187 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
4192 /* Wait for responses to all X commands issued so far for frame F. */
4195 x_sync (FRAME_PTR f
)
4198 XSync (FRAME_X_DISPLAY (f
), False
);
4203 /***********************************************************************
4205 ***********************************************************************/
4207 DEFUN ("x-change-window-property", Fx_change_window_property
,
4208 Sx_change_window_property
, 2, 6, 0,
4209 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
4210 PROP must be a string.
4211 VALUE may be a string or a list of conses, numbers and/or strings.
4212 If an element in the list is a string, it is converted to
4213 an Atom and the value of the Atom is used. If an element is a cons,
4214 it is converted to a 32 bit number where the car is the 16 top bits and the
4215 cdr is the lower 16 bits.
4216 FRAME nil or omitted means use the selected frame.
4217 If TYPE is given and non-nil, it is the name of the type of VALUE.
4218 If TYPE is not given or nil, the type is STRING.
4219 FORMAT gives the size in bits of each element if VALUE is a list.
4220 It must be one of 8, 16 or 32.
4221 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4222 If OUTER_P is non-nil, the property is changed for the outer X window of
4223 FRAME. Default is to change on the edit X window.
4226 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
, Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
4228 struct frame
*f
= check_x_frame (frame
);
4230 Atom target_type
= XA_STRING
;
4231 int element_format
= 8;
4232 unsigned char *data
;
4236 CHECK_STRING (prop
);
4238 if (! NILP (format
))
4240 CHECK_NUMBER (format
);
4241 element_format
= XFASTINT (format
);
4243 if (element_format
!= 8 && element_format
!= 16
4244 && element_format
!= 32)
4245 error ("FORMAT must be one of 8, 16 or 32");
4250 nelements
= x_check_property_data (value
);
4251 if (nelements
== -1)
4252 error ("Bad data in VALUE, must be number, string or cons");
4254 if (element_format
== 8)
4255 data
= (unsigned char *) xmalloc (nelements
);
4256 else if (element_format
== 16)
4257 data
= (unsigned char *) xmalloc (nelements
*2);
4258 else /* format == 32 */
4259 /* The man page for XChangeProperty:
4260 "If the specified format is 32, the property data must be a
4262 This applies even if long is more than 64 bits. The X library
4263 converts to 32 bits before sending to the X server. */
4264 data
= (unsigned char *) xmalloc (nelements
* sizeof(long));
4266 x_fill_property_data (FRAME_X_DISPLAY (f
), value
, data
, element_format
);
4270 CHECK_STRING (value
);
4271 data
= SDATA (value
);
4272 nelements
= SCHARS (value
);
4276 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4279 CHECK_STRING (type
);
4280 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (type
), False
);
4283 if (! NILP (outer_p
)) w
= FRAME_OUTER_WINDOW (f
);
4284 else w
= FRAME_X_WINDOW (f
);
4286 XChangeProperty (FRAME_X_DISPLAY (f
), w
,
4287 prop_atom
, target_type
, element_format
, PropModeReplace
,
4290 if (CONSP (value
)) xfree (data
);
4292 /* Make sure the property is set when we return. */
4293 XFlush (FRAME_X_DISPLAY (f
));
4300 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
4301 Sx_delete_window_property
, 1, 2, 0,
4302 doc
: /* Remove window property PROP from X window of FRAME.
4303 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4304 (Lisp_Object prop
, Lisp_Object frame
)
4306 struct frame
*f
= check_x_frame (frame
);
4309 CHECK_STRING (prop
);
4311 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4312 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
4314 /* Make sure the property is removed when we return. */
4315 XFlush (FRAME_X_DISPLAY (f
));
4322 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
4324 doc
: /* Value is the value of window property PROP on FRAME.
4325 If FRAME is nil or omitted, use the selected frame.
4326 If TYPE is nil or omitted, get the property as a string. Otherwise TYPE
4327 is the name of the Atom that denotes the type expected.
4328 If SOURCE is non-nil, get the property on that window instead of from
4329 FRAME. The number 0 denotes the root window.
4330 If DELETE_P is non-nil, delete the property after retreiving it.
4331 If VECTOR_RET_P is non-nil, don't return a string but a vector of values.
4333 Value is nil if FRAME hasn't a property with name PROP or if PROP has
4334 no value of TYPE. */)
4335 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
, Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
4337 struct frame
*f
= check_x_frame (frame
);
4340 Lisp_Object prop_value
= Qnil
;
4341 unsigned char *tmp_data
= NULL
;
4343 Atom target_type
= XA_STRING
;
4345 unsigned long actual_size
, bytes_remaining
;
4346 Window target_window
= FRAME_X_WINDOW (f
);
4347 struct gcpro gcpro1
;
4349 GCPRO1 (prop_value
);
4350 CHECK_STRING (prop
);
4352 if (! NILP (source
))
4354 if (NUMBERP (source
))
4356 if (FLOATP (source
))
4357 target_window
= (Window
) XFLOAT (source
);
4359 target_window
= XFASTINT (source
);
4361 if (target_window
== 0)
4362 target_window
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4364 else if (CONSP (source
))
4365 target_window
= cons_to_long (source
);
4371 if (strcmp ("AnyPropertyType", SDATA (type
)) == 0)
4372 target_type
= AnyPropertyType
;
4374 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (type
), False
);
4377 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SDATA (prop
), False
);
4378 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4379 prop_atom
, 0, 0, False
, target_type
,
4380 &actual_type
, &actual_format
, &actual_size
,
4381 &bytes_remaining
, &tmp_data
);
4384 int size
= bytes_remaining
;
4389 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4390 prop_atom
, 0, bytes_remaining
,
4391 ! NILP (delete_p
), target_type
,
4392 &actual_type
, &actual_format
,
4393 &actual_size
, &bytes_remaining
,
4395 if (rc
== Success
&& tmp_data
)
4397 /* The man page for XGetWindowProperty says:
4398 "If the returned format is 32, the returned data is represented
4399 as a long array and should be cast to that type to obtain the
4401 This applies even if long is more than 32 bits, the X library
4402 converts from 32 bit elements received from the X server to long
4403 and passes the long array to us. Thus, for that case memcpy can not
4404 be used. We convert to a 32 bit type here, because so much code
4407 The bytes and offsets passed to XGetWindowProperty refers to the
4408 property and those are indeed in 32 bit quantities if format is
4411 if (actual_format
== 32 && actual_format
< BITS_PER_LONG
)
4414 int *idata
= (int *) tmp_data
;
4415 long *ldata
= (long *) tmp_data
;
4417 for (i
= 0; i
< actual_size
; ++i
)
4418 idata
[i
] = (int) ldata
[i
];
4421 if (NILP (vector_ret_p
))
4422 prop_value
= make_string (tmp_data
, size
);
4424 prop_value
= x_property_data_to_lisp (f
,
4431 if (tmp_data
) XFree (tmp_data
);
4441 /***********************************************************************
4443 ***********************************************************************/
4445 /* Timer function of hourglass_atimer. TIMER is equal to
4448 Display an hourglass pointer on all frames by mapping the frames'
4449 hourglass_window. Set the hourglass_p flag in the frames'
4450 output_data.x structure to indicate that an hourglass cursor is
4451 shown on the frames. */
4454 show_hourglass (struct atimer
*timer
)
4456 /* The timer implementation will cancel this timer automatically
4457 after this function has run. Set hourglass_atimer to null
4458 so that we know the timer doesn't have to be canceled. */
4459 hourglass_atimer
= NULL
;
4461 if (!hourglass_shown_p
)
4463 Lisp_Object rest
, frame
;
4467 FOR_EACH_FRAME (rest
, frame
)
4469 struct frame
*f
= XFRAME (frame
);
4471 if (FRAME_LIVE_P (f
) && FRAME_X_P (f
) && FRAME_X_DISPLAY (f
))
4473 Display
*dpy
= FRAME_X_DISPLAY (f
);
4475 #ifdef USE_X_TOOLKIT
4476 if (f
->output_data
.x
->widget
)
4478 if (FRAME_OUTER_WINDOW (f
))
4481 f
->output_data
.x
->hourglass_p
= 1;
4483 if (!f
->output_data
.x
->hourglass_window
)
4485 unsigned long mask
= CWCursor
;
4486 XSetWindowAttributes attrs
;
4488 Window parent
= FRAME_X_WINDOW (f
);
4490 Window parent
= FRAME_OUTER_WINDOW (f
);
4492 attrs
.cursor
= f
->output_data
.x
->hourglass_cursor
;
4494 f
->output_data
.x
->hourglass_window
4495 = XCreateWindow (dpy
, parent
,
4496 0, 0, 32000, 32000, 0, 0,
4502 XMapRaised (dpy
, f
->output_data
.x
->hourglass_window
);
4508 hourglass_shown_p
= 1;
4514 /* Hide the hourglass pointer on all frames, if it is currently
4518 hide_hourglass (void)
4520 if (hourglass_shown_p
)
4522 Lisp_Object rest
, frame
;
4525 FOR_EACH_FRAME (rest
, frame
)
4527 struct frame
*f
= XFRAME (frame
);
4530 /* Watch out for newly created frames. */
4531 && f
->output_data
.x
->hourglass_window
)
4533 XUnmapWindow (FRAME_X_DISPLAY (f
),
4534 f
->output_data
.x
->hourglass_window
);
4535 /* Sync here because XTread_socket looks at the
4536 hourglass_p flag that is reset to zero below. */
4537 XSync (FRAME_X_DISPLAY (f
), False
);
4538 f
->output_data
.x
->hourglass_p
= 0;
4542 hourglass_shown_p
= 0;
4549 /***********************************************************************
4551 ***********************************************************************/
4553 static Lisp_Object
x_create_tip_frame (struct x_display_info
*,
4554 Lisp_Object
, Lisp_Object
);
4555 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
4556 Lisp_Object
, int, int, int *, int *);
4558 /* The frame of a currently visible tooltip. */
4560 Lisp_Object tip_frame
;
4562 /* If non-nil, a timer started that hides the last tooltip when it
4565 Lisp_Object tip_timer
;
4568 /* If non-nil, a vector of 3 elements containing the last args
4569 with which x-show-tip was called. See there. */
4571 Lisp_Object last_show_tip_args
;
4573 /* Maximum size for tooltips; a cons (COLUMNS . ROWS). */
4575 Lisp_Object Vx_max_tooltip_size
;
4579 unwind_create_tip_frame (Lisp_Object frame
)
4581 Lisp_Object deleted
;
4583 deleted
= unwind_create_frame (frame
);
4584 if (EQ (deleted
, Qt
))
4594 /* Create a frame for a tooltip on the display described by DPYINFO.
4595 PARMS is a list of frame parameters. TEXT is the string to
4596 display in the tip frame. Value is the frame.
4598 Note that functions called here, esp. x_default_parameter can
4599 signal errors, for instance when a specified color name is
4600 undefined. We have to make sure that we're in a consistent state
4601 when this happens. */
4604 x_create_tip_frame (struct x_display_info
*dpyinfo
,
4609 Lisp_Object frame
, tem
;
4611 long window_prompting
= 0;
4613 int count
= SPECPDL_INDEX ();
4614 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4615 int face_change_count_before
= face_change_count
;
4617 struct buffer
*old_buffer
;
4621 if (!dpyinfo
->terminal
->name
)
4622 error ("Terminal is not live, can't create new frames on it");
4624 parms
= Fcopy_alist (parms
);
4626 /* Get the name of the frame to use for resource lookup. */
4627 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
4629 && !EQ (name
, Qunbound
)
4631 error ("Invalid frame name--not a string or nil");
4634 GCPRO3 (parms
, name
, frame
);
4636 XSETFRAME (frame
, f
);
4638 buffer
= Fget_buffer_create (build_string (" *tip*"));
4639 Fset_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, Qnil
);
4640 old_buffer
= current_buffer
;
4641 set_buffer_internal_1 (XBUFFER (buffer
));
4642 current_buffer
->truncate_lines
= Qnil
;
4643 specbind (Qinhibit_read_only
, Qt
);
4644 specbind (Qinhibit_modification_hooks
, Qt
);
4647 set_buffer_internal_1 (old_buffer
);
4649 FRAME_CAN_HAVE_SCROLL_BARS (f
) = 0;
4650 record_unwind_protect (unwind_create_tip_frame
, frame
);
4652 f
->terminal
= dpyinfo
->terminal
;
4653 f
->terminal
->reference_count
++;
4655 /* By setting the output method, we're essentially saying that
4656 the frame is live, as per FRAME_LIVE_P. If we get a signal
4657 from this point on, x_destroy_window might screw up reference
4659 f
->output_method
= output_x_window
;
4660 f
->output_data
.x
= (struct x_output
*) xmalloc (sizeof (struct x_output
));
4661 memset (f
->output_data
.x
, 0, sizeof (struct x_output
));
4662 f
->output_data
.x
->icon_bitmap
= -1;
4663 FRAME_FONTSET (f
) = -1;
4664 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
4665 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
4666 #ifdef USE_TOOLKIT_SCROLL_BARS
4667 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
4668 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
4669 #endif /* USE_TOOLKIT_SCROLL_BARS */
4670 f
->icon_name
= Qnil
;
4671 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
4673 image_cache_refcount
= FRAME_IMAGE_CACHE (f
)->refcount
;
4674 dpyinfo_refcount
= dpyinfo
->reference_count
;
4675 #endif /* GLYPH_DEBUG */
4676 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4677 f
->output_data
.x
->explicit_parent
= 0;
4679 /* These colors will be set anyway later, but it's important
4680 to get the color reference counts right, so initialize them! */
4683 struct gcpro gcpro1
;
4685 /* Function x_decode_color can signal an error. Make
4686 sure to initialize color slots so that we won't try
4687 to free colors we haven't allocated. */
4688 FRAME_FOREGROUND_PIXEL (f
) = -1;
4689 FRAME_BACKGROUND_PIXEL (f
) = -1;
4690 f
->output_data
.x
->cursor_pixel
= -1;
4691 f
->output_data
.x
->cursor_foreground_pixel
= -1;
4692 f
->output_data
.x
->border_pixel
= -1;
4693 f
->output_data
.x
->mouse_pixel
= -1;
4695 black
= build_string ("black");
4697 FRAME_FOREGROUND_PIXEL (f
)
4698 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4699 FRAME_BACKGROUND_PIXEL (f
)
4700 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4701 f
->output_data
.x
->cursor_pixel
4702 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4703 f
->output_data
.x
->cursor_foreground_pixel
4704 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4705 f
->output_data
.x
->border_pixel
4706 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4707 f
->output_data
.x
->mouse_pixel
4708 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4712 /* Set the name; the functions to which we pass f expect the name to
4714 if (EQ (name
, Qunbound
) || NILP (name
))
4716 f
->name
= build_string (dpyinfo
->x_id_name
);
4717 f
->explicit_name
= 0;
4722 f
->explicit_name
= 1;
4723 /* use the frame's title when getting resources for this frame. */
4724 specbind (Qx_resource_name
, name
);
4727 f
->resx
= dpyinfo
->resx
;
4728 f
->resy
= dpyinfo
->resy
;
4730 register_font_driver (&xfont_driver
, f
);
4731 #ifdef HAVE_FREETYPE
4733 register_font_driver (&xftfont_driver
, f
);
4734 #else /* not HAVE_XFT */
4735 register_font_driver (&ftxfont_driver
, f
);
4736 #endif /* not HAVE_XFT */
4737 #endif /* HAVE_FREETYPE */
4739 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
4740 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4742 /* Extract the window parameters from the supplied values that are
4743 needed to determine window geometry. */
4744 x_default_font_parameter (f
, parms
);
4746 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
4747 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4749 /* This defaults to 2 in order to match xterm. We recognize either
4750 internalBorderWidth or internalBorder (which is what xterm calls
4752 if (NILP (Fassq (Qinternal_border_width
, parms
)))
4756 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
4757 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
4758 if (! EQ (value
, Qunbound
))
4759 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
4763 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
4764 "internalBorderWidth", "internalBorderWidth",
4767 /* Also do the stuff which must be set before the window exists. */
4768 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
4769 "foreground", "Foreground", RES_TYPE_STRING
);
4770 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
4771 "background", "Background", RES_TYPE_STRING
);
4772 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
4773 "pointerColor", "Foreground", RES_TYPE_STRING
);
4774 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
4775 "cursorColor", "Foreground", RES_TYPE_STRING
);
4776 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
4777 "borderColor", "BorderColor", RES_TYPE_STRING
);
4779 /* Init faces before x_default_parameter is called for scroll-bar
4780 parameters because that function calls x_set_scroll_bar_width,
4781 which calls change_frame_size, which calls Fset_window_buffer,
4782 which runs hooks, which call Fvertical_motion. At the end, we
4783 end up in init_iterator with a null face cache, which should not
4785 init_frame_faces (f
);
4787 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4789 window_prompting
= x_figure_window_size (f
, parms
, 0);
4792 XSetWindowAttributes attrs
;
4794 Atom type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_net_window_type_tooltip
;
4797 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
;
4798 if (DoesSaveUnders (dpyinfo
->screen
))
4799 mask
|= CWSaveUnder
;
4801 /* Window managers look at the override-redirect flag to determine
4802 whether or net to give windows a decoration (Xlib spec, chapter
4804 attrs
.override_redirect
= True
;
4805 attrs
.save_under
= True
;
4806 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
4807 /* Arrange for getting MapNotify and UnmapNotify events. */
4808 attrs
.event_mask
= StructureNotifyMask
;
4810 = FRAME_X_WINDOW (f
)
4811 = XCreateWindow (FRAME_X_DISPLAY (f
),
4812 FRAME_X_DISPLAY_INFO (f
)->root_window
,
4813 /* x, y, width, height */
4817 CopyFromParent
, InputOutput
, CopyFromParent
,
4819 XChangeProperty (FRAME_X_DISPLAY (f
), tip_window
,
4820 FRAME_X_DISPLAY_INFO (f
)->Xatom_net_window_type
,
4821 XA_ATOM
, 32, PropModeReplace
,
4822 (unsigned char *)&type
, 1);
4828 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
4829 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4830 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
4831 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4832 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
4833 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
4835 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
4836 Change will not be effected unless different from the current
4838 width
= FRAME_COLS (f
);
4839 height
= FRAME_LINES (f
);
4840 SET_FRAME_COLS (f
, 0);
4841 FRAME_LINES (f
) = 0;
4842 change_frame_size (f
, height
, width
, 1, 0, 0);
4844 /* Add `tooltip' frame parameter's default value. */
4845 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
4846 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qtooltip
, Qt
), Qnil
));
4848 /* FIXME - can this be done in a similar way to normal frames?
4849 http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00641.html */
4851 /* Set the `display-type' frame parameter before setting up faces. */
4853 Lisp_Object disptype
;
4855 if (FRAME_X_DISPLAY_INFO (f
)->n_planes
== 1)
4856 disptype
= intern ("mono");
4857 else if (FRAME_X_DISPLAY_INFO (f
)->visual
->class == GrayScale
4858 || FRAME_X_DISPLAY_INFO (f
)->visual
->class == StaticGray
)
4859 disptype
= intern ("grayscale");
4861 disptype
= intern ("color");
4863 if (NILP (Fframe_parameter (frame
, Qdisplay_type
)))
4864 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qdisplay_type
, disptype
),
4868 /* Set up faces after all frame parameters are known. This call
4869 also merges in face attributes specified for new frames.
4871 Frame parameters may be changed if .Xdefaults contains
4872 specifications for the default font. For example, if there is an
4873 `Emacs.default.attributeBackground: pink', the `background-color'
4874 attribute of the frame get's set, which let's the internal border
4875 of the tooltip frame appear in pink. Prevent this. */
4877 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
4879 /* Set tip_frame here, so that */
4881 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
4883 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
4884 Fmodify_frame_parameters (frame
, Fcons (Fcons (Qbackground_color
, bg
),
4892 /* It is now ok to make the frame official even if we get an error
4893 below. And the frame needs to be on Vframe_list or making it
4894 visible won't work. */
4895 Vframe_list
= Fcons (frame
, Vframe_list
);
4897 /* Now that the frame is official, it counts as a reference to
4899 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
4901 /* Setting attributes of faces of the tooltip frame from resources
4902 and similar will increment face_change_count, which leads to the
4903 clearing of all current matrices. Since this isn't necessary
4904 here, avoid it by resetting face_change_count to the value it
4905 had before we created the tip frame. */
4906 face_change_count
= face_change_count_before
;
4908 /* Discard the unwind_protect. */
4909 return unbind_to (count
, frame
);
4913 /* Compute where to display tip frame F. PARMS is the list of frame
4914 parameters for F. DX and DY are specified offsets from the current
4915 location of the mouse. WIDTH and HEIGHT are the width and height
4916 of the tooltip. Return coordinates relative to the root window of
4917 the display in *ROOT_X, and *ROOT_Y. */
4920 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
)
4922 Lisp_Object left
, top
;
4927 /* User-specified position? */
4928 left
= Fcdr (Fassq (Qleft
, parms
));
4929 top
= Fcdr (Fassq (Qtop
, parms
));
4931 /* Move the tooltip window where the mouse pointer is. Resize and
4933 if (!INTEGERP (left
) || !INTEGERP (top
))
4936 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
4937 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
4942 *root_y
= XINT (top
);
4943 else if (*root_y
+ XINT (dy
) <= 0)
4944 *root_y
= 0; /* Can happen for negative dy */
4945 else if (*root_y
+ XINT (dy
) + height
4946 <= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
)))
4947 /* It fits below the pointer */
4948 *root_y
+= XINT (dy
);
4949 else if (height
+ XINT (dy
) <= *root_y
)
4950 /* It fits above the pointer. */
4951 *root_y
-= height
+ XINT (dy
);
4953 /* Put it on the top. */
4956 if (INTEGERP (left
))
4957 *root_x
= XINT (left
);
4958 else if (*root_x
+ XINT (dx
) <= 0)
4959 *root_x
= 0; /* Can happen for negative dx */
4960 else if (*root_x
+ XINT (dx
) + width
4961 <= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
)))
4962 /* It fits to the right of the pointer. */
4963 *root_x
+= XINT (dx
);
4964 else if (width
+ XINT (dx
) <= *root_x
)
4965 /* It fits to the left of the pointer. */
4966 *root_x
-= width
+ XINT (dx
);
4968 /* Put it left-justified on the screen--it ought to fit that way. */
4973 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
4974 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
4975 A tooltip window is a small X window displaying a string.
4977 This is an internal function; Lisp code should call `tooltip-show'.
4979 FRAME nil or omitted means use the selected frame.
4981 PARMS is an optional list of frame parameters which can be used to
4982 change the tooltip's appearance.
4984 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
4985 means use the default timeout of 5 seconds.
4987 If the list of frame parameters PARAMS contains a `left' parameters,
4988 the tooltip is displayed at that x-position. Otherwise it is
4989 displayed at the mouse position, with offset DX added (default is 5 if
4990 DX isn't specified). Likewise for the y-position; if a `top' frame
4991 parameter is specified, it determines the y-position of the tooltip
4992 window, otherwise it is displayed at the mouse position, with offset
4993 DY added (default is -10).
4995 A tooltip's maximum size is specified by `x-max-tooltip-size'.
4996 Text larger than the specified size is clipped. */)
4997 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
5002 struct buffer
*old_buffer
;
5003 struct text_pos pos
;
5004 int i
, width
, height
;
5005 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5006 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5007 int count
= SPECPDL_INDEX ();
5009 specbind (Qinhibit_redisplay
, Qt
);
5011 GCPRO4 (string
, parms
, frame
, timeout
);
5013 CHECK_STRING (string
);
5014 if (SCHARS (string
) == 0)
5015 string
= make_unibyte_string (" ", 1);
5017 f
= check_x_frame (frame
);
5019 timeout
= make_number (5);
5021 CHECK_NATNUM (timeout
);
5024 dx
= make_number (5);
5029 dy
= make_number (-10);
5034 if (x_gtk_use_system_tooltips
)
5038 /* Hide a previous tip, if any. */
5042 if ((ok
= xg_prepare_tooltip (f
, string
, &width
, &height
)) != 0)
5044 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5045 xg_show_tooltip (f
, root_x
, root_y
);
5046 /* This is used in Fx_hide_tip. */
5047 XSETFRAME (tip_frame
, f
);
5050 if (ok
) goto start_timer
;
5052 #endif /* USE_GTK */
5054 if (NILP (last_show_tip_args
))
5055 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5057 if (!NILP (tip_frame
))
5059 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5060 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5061 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5063 if (EQ (frame
, last_frame
)
5064 && !NILP (Fequal (last_string
, string
))
5065 && !NILP (Fequal (last_parms
, parms
)))
5067 struct frame
*f
= XFRAME (tip_frame
);
5069 /* Only DX and DY have changed. */
5070 if (!NILP (tip_timer
))
5072 Lisp_Object timer
= tip_timer
;
5074 call1 (Qcancel_timer
, timer
);
5078 compute_tip_xy (f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (f
),
5079 FRAME_PIXEL_HEIGHT (f
), &root_x
, &root_y
);
5080 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5087 /* Hide a previous tip, if any. */
5090 ASET (last_show_tip_args
, 0, string
);
5091 ASET (last_show_tip_args
, 1, frame
);
5092 ASET (last_show_tip_args
, 2, parms
);
5094 /* Add default values to frame parameters. */
5095 if (NILP (Fassq (Qname
, parms
)))
5096 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5097 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5098 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5099 if (NILP (Fassq (Qborder_width
, parms
)))
5100 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5101 if (NILP (Fassq (Qborder_color
, parms
)))
5102 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5103 if (NILP (Fassq (Qbackground_color
, parms
)))
5104 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5107 /* Create a frame for the tooltip, and record it in the global
5108 variable tip_frame. */
5109 frame
= x_create_tip_frame (FRAME_X_DISPLAY_INFO (f
), parms
, string
);
5112 /* Set up the frame's root window. */
5113 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5114 w
->left_col
= w
->top_line
= make_number (0);
5116 if (CONSP (Vx_max_tooltip_size
)
5117 && INTEGERP (XCAR (Vx_max_tooltip_size
))
5118 && XINT (XCAR (Vx_max_tooltip_size
)) > 0
5119 && INTEGERP (XCDR (Vx_max_tooltip_size
))
5120 && XINT (XCDR (Vx_max_tooltip_size
)) > 0)
5122 w
->total_cols
= XCAR (Vx_max_tooltip_size
);
5123 w
->total_lines
= XCDR (Vx_max_tooltip_size
);
5127 w
->total_cols
= make_number (80);
5128 w
->total_lines
= make_number (40);
5131 FRAME_TOTAL_COLS (f
) = XINT (w
->total_cols
);
5133 w
->pseudo_window_p
= 1;
5135 /* Display the tooltip text in a temporary buffer. */
5136 old_buffer
= current_buffer
;
5137 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->buffer
));
5138 current_buffer
->truncate_lines
= Qnil
;
5139 clear_glyph_matrix (w
->desired_matrix
);
5140 clear_glyph_matrix (w
->current_matrix
);
5141 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5142 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5144 /* Compute width and height of the tooltip. */
5146 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5148 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5152 /* Stop at the first empty row at the end. */
5153 if (!row
->enabled_p
|| !row
->displays_text_p
)
5156 /* Let the row go over the full width of the frame. */
5157 row
->full_width_p
= 1;
5159 row_width
= row
->pixel_width
;
5160 /* There's a glyph at the end of rows that is used to place
5161 the cursor there. Don't include the width of this glyph. */
5162 if (row
->used
[TEXT_AREA
])
5164 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5165 if (INTEGERP (last
->object
))
5166 row_width
-= last
->pixel_width
;
5169 height
+= row
->height
;
5170 width
= max (width
, row_width
);
5173 /* Add the frame's internal border to the width and height the X
5174 window should have. */
5175 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5176 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5178 /* Move the tooltip window where the mouse pointer is. Resize and
5180 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5183 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5184 root_x
, root_y
, width
, height
);
5185 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5188 /* Draw into the window. */
5189 w
->must_be_updated_p
= 1;
5190 update_single_window (w
, 1);
5192 /* Restore original current buffer. */
5193 set_buffer_internal_1 (old_buffer
);
5194 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5197 /* Let the tip disappear after timeout seconds. */
5198 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5199 intern ("x-hide-tip"));
5202 return unbind_to (count
, Qnil
);
5206 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5207 doc
: /* Hide the current tooltip window, if there is any.
5208 Value is t if tooltip was open, nil otherwise. */)
5212 Lisp_Object deleted
, frame
, timer
;
5213 struct gcpro gcpro1
, gcpro2
;
5216 /* Return quickly if nothing to do. */
5217 if (NILP (tip_timer
) && NILP (tip_frame
))
5222 GCPRO2 (frame
, timer
);
5223 tip_frame
= tip_timer
= deleted
= Qnil
;
5225 count
= SPECPDL_INDEX ();
5226 specbind (Qinhibit_redisplay
, Qt
);
5227 specbind (Qinhibit_quit
, Qt
);
5230 call1 (Qcancel_timer
, timer
);
5233 /* When using system tooltip, tip_frame is the Emacs frame on which
5234 the tip is shown. */
5236 if (xg_hide_tooltip (f
))
5242 delete_frame (frame
, Qnil
);
5246 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5247 redisplay procedure is not called when a tip frame over menu
5248 items is unmapped. Redisplay the menu manually... */
5251 f
= SELECTED_FRAME ();
5252 w
= f
->output_data
.x
->menubar_widget
;
5254 if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f
)->screen
)
5258 xlwmenu_redisplay (w
);
5262 #endif /* USE_LUCID */
5266 return unbind_to (count
, deleted
);
5271 /***********************************************************************
5272 File selection dialog
5273 ***********************************************************************/
5275 DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog
,
5276 Sx_uses_old_gtk_dialog
,
5278 doc
: /* Return t if the old Gtk+ file selection dialog is used. */)
5285 && xg_uses_old_file_dialog ())
5293 /* Callback for "OK" and "Cancel" on file selection dialog. */
5296 file_dialog_cb (widget
, client_data
, call_data
)
5298 XtPointer call_data
, client_data
;
5300 int *result
= (int *) client_data
;
5301 XmAnyCallbackStruct
*cb
= (XmAnyCallbackStruct
*) call_data
;
5302 *result
= cb
->reason
;
5306 /* Callback for unmapping a file selection dialog. This is used to
5307 capture the case where a dialog is closed via a window manager's
5308 closer button, for example. Using a XmNdestroyCallback didn't work
5312 file_dialog_unmap_cb (widget
, client_data
, call_data
)
5314 XtPointer call_data
, client_data
;
5316 int *result
= (int *) client_data
;
5317 *result
= XmCR_CANCEL
;
5321 clean_up_file_dialog (arg
)
5324 struct Lisp_Save_Value
*p
= XSAVE_VALUE (arg
);
5325 Widget dialog
= (Widget
) p
->pointer
;
5329 XtUnmanageChild (dialog
);
5330 XtDestroyWidget (dialog
);
5331 x_menu_set_in_use (0);
5338 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5339 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5340 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5341 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5342 or directory must exist. ONLY-DIR-P is ignored." */)
5343 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5346 struct frame
*f
= SELECTED_FRAME ();
5347 Lisp_Object file
= Qnil
;
5348 Lisp_Object decoded_file
;
5349 Widget dialog
, text
, help
;
5352 XmString dir_xmstring
, pattern_xmstring
;
5353 int count
= SPECPDL_INDEX ();
5354 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5358 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5360 if (popup_activated ())
5361 error ("Trying to use a menu from within a menu-entry");
5363 CHECK_STRING (prompt
);
5366 /* Prevent redisplay. */
5367 specbind (Qinhibit_redisplay
, Qt
);
5371 /* Create the dialog with PROMPT as title, using DIR as initial
5372 directory and using "*" as pattern. */
5373 dir
= Fexpand_file_name (dir
, Qnil
);
5374 dir_xmstring
= XmStringCreateLocalized (SDATA (dir
));
5375 pattern_xmstring
= XmStringCreateLocalized ("*");
5377 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
5378 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
5379 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
5380 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
5381 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
5382 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
5384 XmStringFree (dir_xmstring
);
5385 XmStringFree (pattern_xmstring
);
5387 /* Add callbacks for OK and Cancel. */
5388 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
5389 (XtPointer
) &result
);
5390 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
5391 (XtPointer
) &result
);
5392 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
5393 (XtPointer
) &result
);
5395 /* Remove the help button since we can't display help. */
5396 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
5397 XtUnmanageChild (help
);
5399 /* Mark OK button as default. */
5400 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
5401 XmNshowAsDefault
, True
, NULL
);
5403 /* If MUSTMATCH is non-nil, disable the file entry field of the
5404 dialog, so that the user must select a file from the files list
5405 box. We can't remove it because we wouldn't have a way to get at
5406 the result file name, then. */
5407 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5408 if (!NILP (mustmatch
))
5411 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
5412 XtSetSensitive (text
, False
);
5413 XtSetSensitive (label
, False
);
5416 /* Manage the dialog, so that list boxes get filled. */
5417 XtManageChild (dialog
);
5419 if (STRINGP (default_filename
))
5421 XmString default_xmstring
;
5422 Widget wtext
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5423 Widget list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
5425 XmTextPosition last_pos
= XmTextFieldGetLastPosition (wtext
);
5426 XmTextFieldReplace (wtext
, 0, last_pos
,
5427 (SDATA (Ffile_name_nondirectory (default_filename
))));
5429 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5430 must include the path for this to work. */
5432 default_xmstring
= XmStringCreateLocalized (SDATA (default_filename
));
5434 if (XmListItemExists (list
, default_xmstring
))
5436 int item_pos
= XmListItemPos (list
, default_xmstring
);
5437 /* Select the item and scroll it into view. */
5438 XmListSelectPos (list
, item_pos
, True
);
5439 XmListSetPos (list
, item_pos
);
5442 XmStringFree (default_xmstring
);
5445 record_unwind_protect (clean_up_file_dialog
, make_save_value (dialog
, 0));
5447 /* Process events until the user presses Cancel or OK. */
5448 x_menu_set_in_use (1);
5453 x_menu_wait_for_event (0);
5454 XtAppNextEvent (Xt_app_con
, &event
);
5455 if (event
.type
== KeyPress
5456 && FRAME_X_DISPLAY (f
) == event
.xkey
.display
)
5458 KeySym keysym
= XLookupKeysym (&event
.xkey
, 0);
5460 /* Pop down on C-g. */
5461 if (keysym
== XK_g
&& (event
.xkey
.state
& ControlMask
) != 0)
5462 XtUnmanageChild (dialog
);
5465 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
));
5468 /* Get the result. */
5469 if (result
== XmCR_OK
)
5474 XtVaGetValues (dialog
, XmNtextString
, &text
, NULL
);
5475 XmStringGetLtoR (text
, XmFONTLIST_DEFAULT_TAG
, &data
);
5476 XmStringFree (text
);
5477 file
= build_string (data
);
5486 /* Make "Cancel" equivalent to C-g. */
5488 Fsignal (Qquit
, Qnil
);
5490 decoded_file
= DECODE_FILE (file
);
5492 return unbind_to (count
, decoded_file
);
5495 #endif /* USE_MOTIF */
5500 clean_up_dialog (Lisp_Object arg
)
5502 x_menu_set_in_use (0);
5507 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5508 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5509 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5510 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5511 or directory must exist. If ONLY-DIR-P is non-nil, the user can only select
5513 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5515 FRAME_PTR f
= SELECTED_FRAME ();
5517 Lisp_Object file
= Qnil
;
5518 Lisp_Object decoded_file
;
5519 int count
= SPECPDL_INDEX ();
5520 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5525 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5527 if (popup_activated ())
5528 error ("Trying to use a menu from within a menu-entry");
5530 CHECK_STRING (prompt
);
5533 /* Prevent redisplay. */
5534 specbind (Qinhibit_redisplay
, Qt
);
5535 record_unwind_protect (clean_up_dialog
, Qnil
);
5539 if (STRINGP (default_filename
))
5540 cdef_file
= SDATA (default_filename
);
5542 cdef_file
= SDATA (dir
);
5544 fn
= xg_get_file_name (f
, SDATA (prompt
), cdef_file
,
5546 ! NILP (only_dir_p
));
5550 file
= build_string (fn
);
5557 /* Make "Cancel" equivalent to C-g. */
5559 Fsignal (Qquit
, Qnil
);
5561 decoded_file
= DECODE_FILE (file
);
5563 return unbind_to (count
, decoded_file
);
5567 #ifdef HAVE_FREETYPE
5569 DEFUN ("x-select-font", Fx_select_font
, Sx_select_font
, 0, 2, 0,
5570 doc
: /* Read a font name using a GTK font selection dialog.
5571 Return a GTK-style font string corresponding to the selection.
5573 If FRAME is omitted or nil, it defaults to the selected frame. */)
5574 (Lisp_Object frame
, Lisp_Object ignored
)
5576 FRAME_PTR f
= check_x_frame (frame
);
5579 Lisp_Object font_param
;
5580 char *default_name
= NULL
;
5581 struct gcpro gcpro1
, gcpro2
;
5582 int count
= SPECPDL_INDEX ();
5586 if (popup_activated ())
5587 error ("Trying to use a menu from within a menu-entry");
5589 /* Prevent redisplay. */
5590 specbind (Qinhibit_redisplay
, Qt
);
5591 record_unwind_protect (clean_up_dialog
, Qnil
);
5595 GCPRO2(font_param
, font
);
5597 XSETFONT (font
, FRAME_FONT (f
));
5598 font_param
= Ffont_get (font
, intern (":name"));
5599 if (STRINGP (font_param
))
5600 default_name
= xstrdup (SDATA (font_param
));
5603 font_param
= Fframe_parameter (frame
, Qfont_param
);
5604 if (STRINGP (font_param
))
5605 default_name
= xstrdup (SDATA (font_param
));
5608 if (default_name
== NULL
&& x_last_font_name
!= NULL
)
5609 default_name
= xstrdup (x_last_font_name
);
5611 /* Convert fontconfig names to Gtk names, i.e. remove - before number */
5614 char *p
= strrchr (default_name
, '-');
5618 while (isdigit (*ep
))
5620 if (*ep
== '\0') *p
= ' ';
5624 name
= xg_get_font_name (f
, default_name
);
5625 xfree (default_name
);
5629 font
= build_string (name
);
5630 g_free (x_last_font_name
);
5631 x_last_font_name
= name
;
5637 Fsignal (Qquit
, Qnil
);
5639 return unbind_to (count
, font
);
5641 #endif /* HAVE_FREETYPE */
5643 #endif /* USE_GTK */
5646 /***********************************************************************
5648 ***********************************************************************/
5650 #ifdef HAVE_XKBGETKEYBOARD
5651 #include <X11/XKBlib.h>
5652 #include <X11/keysym.h>
5655 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
5656 Sx_backspace_delete_keys_p
, 0, 1, 0,
5657 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
5658 FRAME nil means use the selected frame.
5659 Value is t if we know that both keys are present, and are mapped to the
5660 usual X keysyms. Value is `lambda' if we cannot determine if both keys are
5661 present and mapped to the usual X keysyms. */)
5664 #ifdef HAVE_XKBGETKEYBOARD
5666 struct frame
*f
= check_x_frame (frame
);
5667 Display
*dpy
= FRAME_X_DISPLAY (f
);
5668 Lisp_Object have_keys
;
5669 int major
, minor
, op
, event
, error
;
5673 /* Check library version in case we're dynamically linked. */
5674 major
= XkbMajorVersion
;
5675 minor
= XkbMinorVersion
;
5676 if (!XkbLibraryVersion (&major
, &minor
))
5682 /* Check that the server supports XKB. */
5683 major
= XkbMajorVersion
;
5684 minor
= XkbMinorVersion
;
5685 if (!XkbQueryExtension (dpy
, &op
, &event
, &error
, &major
, &minor
))
5691 /* In this code we check that the keyboard has physical keys with names
5692 that start with BKSP (Backspace) and DELE (Delete), and that they
5693 generate keysym XK_BackSpace and XK_Delete respectively.
5694 This function is used to test if normal-erase-is-backspace should be
5696 An alternative approach would be to just check if XK_BackSpace and
5697 XK_Delete are mapped to any key. But if any of those are mapped to
5698 some non-intuitive key combination (Meta-Shift-Ctrl-whatever) and the
5699 user doesn't know about it, it is better to return false here.
5700 It is more obvious to the user what to do if she/he has two keys
5701 clearly marked with names/symbols and one key does something not
5702 expected (i.e. she/he then tries the other).
5703 The cases where Backspace/Delete is mapped to some other key combination
5704 are rare, and in those cases, normal-erase-is-backspace can be turned on
5708 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
5711 int delete_keycode
= 0, backspace_keycode
= 0, i
;
5713 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
5715 for (i
= kb
->min_key_code
;
5716 (i
< kb
->max_key_code
5717 && (delete_keycode
== 0 || backspace_keycode
== 0));
5720 /* The XKB symbolic key names can be seen most easily in
5721 the PS file generated by `xkbprint -label name
5723 if (memcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
5725 else if (memcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
5726 backspace_keycode
= i
;
5729 XkbFreeNames (kb
, 0, True
);
5732 XkbFreeClientMap (kb
, 0, True
);
5735 && backspace_keycode
5736 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
5737 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
5742 #else /* not HAVE_XKBGETKEYBOARD */
5744 #endif /* not HAVE_XKBGETKEYBOARD */
5749 /***********************************************************************
5751 ***********************************************************************/
5753 /* Keep this list in the same order as frame_parms in frame.c.
5754 Use 0 for unsupported frame parameters. */
5756 frame_parm_handler x_frame_parm_handlers
[] =
5760 x_set_background_color
,
5766 x_set_foreground_color
,
5769 x_set_internal_border_width
,
5770 x_set_menu_bar_lines
,
5772 x_explicitly_set_name
,
5773 x_set_scroll_bar_width
,
5776 x_set_vertical_scroll_bars
,
5778 x_set_tool_bar_lines
,
5779 x_set_scroll_bar_foreground
,
5780 x_set_scroll_bar_background
,
5790 x_set_tool_bar_position
,
5796 /* This is zero if not using X windows. */
5799 /* The section below is built by the lisp expression at the top of the file,
5800 just above where these variables are declared. */
5801 /*&&& init symbols here &&&*/
5802 Qnone
= intern_c_string ("none");
5804 Qsuppress_icon
= intern_c_string ("suppress-icon");
5805 staticpro (&Qsuppress_icon
);
5806 Qundefined_color
= intern_c_string ("undefined-color");
5807 staticpro (&Qundefined_color
);
5808 Qcompound_text
= intern_c_string ("compound-text");
5809 staticpro (&Qcompound_text
);
5810 Qcancel_timer
= intern_c_string ("cancel-timer");
5811 staticpro (&Qcancel_timer
);
5812 Qfont_param
= intern_c_string ("font-parameter");
5813 staticpro (&Qfont_param
);
5814 /* This is the end of symbol initialization. */
5816 /* Text property `display' should be nonsticky by default. */
5817 Vtext_property_default_nonsticky
5818 = Fcons (Fcons (Qdisplay
, Qt
), Vtext_property_default_nonsticky
);
5821 Fput (Qundefined_color
, Qerror_conditions
,
5822 pure_cons (Qundefined_color
, pure_cons (Qerror
, Qnil
)));
5823 Fput (Qundefined_color
, Qerror_message
,
5824 make_pure_c_string ("Undefined color"));
5826 DEFVAR_LISP ("x-pointer-shape", &Vx_pointer_shape
,
5827 doc
: /* The shape of the pointer when over text.
5828 Changing the value does not affect existing frames
5829 unless you set the mouse color. */);
5830 Vx_pointer_shape
= Qnil
;
5832 #if 0 /* This doesn't really do anything. */
5833 DEFVAR_LISP ("x-nontext-pointer-shape", &Vx_nontext_pointer_shape
,
5834 doc
: /* The shape of the pointer when not over text.
5835 This variable takes effect when you create a new frame
5836 or when you set the mouse color. */);
5838 Vx_nontext_pointer_shape
= Qnil
;
5840 DEFVAR_LISP ("x-hourglass-pointer-shape", &Vx_hourglass_pointer_shape
,
5841 doc
: /* The shape of the pointer when Emacs is busy.
5842 This variable takes effect when you create a new frame
5843 or when you set the mouse color. */);
5844 Vx_hourglass_pointer_shape
= Qnil
;
5846 #if 0 /* This doesn't really do anything. */
5847 DEFVAR_LISP ("x-mode-pointer-shape", &Vx_mode_pointer_shape
,
5848 doc
: /* The shape of the pointer when over the mode line.
5849 This variable takes effect when you create a new frame
5850 or when you set the mouse color. */);
5852 Vx_mode_pointer_shape
= Qnil
;
5854 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
5855 &Vx_sensitive_text_pointer_shape
,
5856 doc
: /* The shape of the pointer when over mouse-sensitive text.
5857 This variable takes effect when you create a new frame
5858 or when you set the mouse color. */);
5859 Vx_sensitive_text_pointer_shape
= Qnil
;
5861 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
5862 &Vx_window_horizontal_drag_shape
,
5863 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
5864 This variable takes effect when you create a new frame
5865 or when you set the mouse color. */);
5866 Vx_window_horizontal_drag_shape
= Qnil
;
5868 DEFVAR_LISP ("x-cursor-fore-pixel", &Vx_cursor_fore_pixel
,
5869 doc
: /* A string indicating the foreground color of the cursor box. */);
5870 Vx_cursor_fore_pixel
= Qnil
;
5872 DEFVAR_LISP ("x-max-tooltip-size", &Vx_max_tooltip_size
,
5873 doc
: /* Maximum size for tooltips. Value is a pair (COLUMNS . ROWS).
5874 Text larger than this is clipped. */);
5875 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
5877 DEFVAR_LISP ("x-no-window-manager", &Vx_no_window_manager
,
5878 doc
: /* Non-nil if no X window manager is in use.
5879 Emacs doesn't try to figure this out; this is always nil
5880 unless you set it to something else. */);
5881 /* We don't have any way to find this out, so set it to nil
5882 and maybe the user would like to set it to t. */
5883 Vx_no_window_manager
= Qnil
;
5885 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
5886 &Vx_pixel_size_width_font_regexp
,
5887 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
5889 Since Emacs gets width of a font matching with this regexp from
5890 PIXEL_SIZE field of the name, font finding mechanism gets faster for
5891 such a font. This is especially effective for such large fonts as
5892 Chinese, Japanese, and Korean. */);
5893 Vx_pixel_size_width_font_regexp
= Qnil
;
5895 /* This is not ifdef:ed, so other builds than GTK can customize it. */
5896 DEFVAR_BOOL ("x-gtk-use-old-file-dialog", &x_gtk_use_old_file_dialog
,
5897 doc
: /* *Non-nil means prompt with the old GTK file selection dialog.
5898 If nil or if the file selection dialog is not available, the new GTK file
5899 chooser is used instead. To turn off all file dialogs set the
5900 variable `use-file-dialog'. */);
5901 x_gtk_use_old_file_dialog
= 0;
5903 DEFVAR_BOOL ("x-gtk-show-hidden-files", &x_gtk_show_hidden_files
,
5904 doc
: /* *If non-nil, the GTK file chooser will by default show hidden files.
5905 Note that this is just the default, there is a toggle button on the file
5906 chooser to show or not show hidden files on a case by case basis. */);
5907 x_gtk_show_hidden_files
= 0;
5909 DEFVAR_BOOL ("x-gtk-file-dialog-help-text", &x_gtk_file_dialog_help_text
,
5910 doc
: /* *If non-nil, the GTK file chooser will show additional help text.
5911 If more space for files in the file chooser dialog is wanted, set this to nil
5912 to turn the additional text off. */);
5913 x_gtk_file_dialog_help_text
= 1;
5915 DEFVAR_BOOL ("x-gtk-whole-detached-tool-bar", &x_gtk_whole_detached_tool_bar
,
5916 doc
: /* *If non-nil, a detached tool bar is shown in full.
5917 The default is to just show an arrow and pressing on that arrow shows
5918 the tool bar buttons. */);
5919 x_gtk_whole_detached_tool_bar
= 0;
5921 DEFVAR_BOOL ("x-gtk-use-system-tooltips", &x_gtk_use_system_tooltips
,
5922 doc
: /* *If non-nil with a Gtk+ built Emacs, the Gtk+ toolip is used.
5923 Otherwise use Emacs own tooltip implementation.
5924 When using Gtk+ tooltips, the tooltip face is not used. */);
5925 x_gtk_use_system_tooltips
= 1;
5927 Fprovide (intern_c_string ("x"), Qnil
);
5929 #ifdef USE_X_TOOLKIT
5930 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
5932 Fprovide (intern_c_string ("motif"), Qnil
);
5934 DEFVAR_LISP ("motif-version-string", &Vmotif_version_string
,
5935 doc
: /* Version info for LessTif/Motif. */);
5936 Vmotif_version_string
= build_string (XmVERSION_STRING
);
5937 #endif /* USE_MOTIF */
5938 #endif /* USE_X_TOOLKIT */
5941 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
5942 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
5943 But for a user it is a toolkit for X, and indeed, configure
5944 accepts --with-x-toolkit=gtk. */
5945 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
5946 Fprovide (intern_c_string ("gtk"), Qnil
);
5947 Fprovide (intern_c_string ("move-toolbar"), Qnil
);
5949 DEFVAR_LISP ("gtk-version-string", &Vgtk_version_string
,
5950 doc
: /* Version info for GTK+. */);
5952 char gtk_version
[40];
5953 g_snprintf (gtk_version
, sizeof (gtk_version
), "%u.%u.%u",
5954 GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
);
5955 Vgtk_version_string
= make_pure_string (gtk_version
, strlen (gtk_version
), strlen (gtk_version
), 0);
5957 #endif /* USE_GTK */
5959 /* X window properties. */
5960 defsubr (&Sx_change_window_property
);
5961 defsubr (&Sx_delete_window_property
);
5962 defsubr (&Sx_window_property
);
5964 defsubr (&Sxw_display_color_p
);
5965 defsubr (&Sx_display_grayscale_p
);
5966 defsubr (&Sxw_color_defined_p
);
5967 defsubr (&Sxw_color_values
);
5968 defsubr (&Sx_server_max_request_size
);
5969 defsubr (&Sx_server_vendor
);
5970 defsubr (&Sx_server_version
);
5971 defsubr (&Sx_display_pixel_width
);
5972 defsubr (&Sx_display_pixel_height
);
5973 defsubr (&Sx_display_mm_width
);
5974 defsubr (&Sx_display_mm_height
);
5975 defsubr (&Sx_display_screens
);
5976 defsubr (&Sx_display_planes
);
5977 defsubr (&Sx_display_color_cells
);
5978 defsubr (&Sx_display_visual_class
);
5979 defsubr (&Sx_display_backing_store
);
5980 defsubr (&Sx_display_save_under
);
5981 defsubr (&Sx_wm_set_size_hint
);
5982 defsubr (&Sx_create_frame
);
5983 defsubr (&Sx_open_connection
);
5984 defsubr (&Sx_close_connection
);
5985 defsubr (&Sx_display_list
);
5986 defsubr (&Sx_synchronize
);
5987 defsubr (&Sx_focus_frame
);
5988 defsubr (&Sx_backspace_delete_keys_p
);
5990 /* Setting callback functions for fontset handler. */
5991 check_window_system_func
= check_x
;
5993 defsubr (&Sx_show_tip
);
5994 defsubr (&Sx_hide_tip
);
5996 staticpro (&tip_timer
);
5998 staticpro (&tip_frame
);
6000 last_show_tip_args
= Qnil
;
6001 staticpro (&last_show_tip_args
);
6003 defsubr (&Sx_uses_old_gtk_dialog
);
6004 #if defined (USE_MOTIF) || defined (USE_GTK)
6005 defsubr (&Sx_file_dialog
);
6008 #if defined (USE_GTK) && defined (HAVE_FREETYPE)
6009 defsubr (&Sx_select_font
);
6010 x_last_font_name
= NULL
;
6014 #endif /* HAVE_X_WINDOWS */
6016 /* arch-tag: 55040d02-5485-4d58-8b22-95a7a05f3288
6017 (do not change this comment) */