1 /* Functions for the X window system.
3 Copyright (C) 1989, 1992-2015 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
30 #include "character.h"
32 #include "intervals.h"
33 #include "dispextern.h"
35 #include "blockinput.h"
41 #include "termhooks.h"
46 #include <sys/types.h>
49 #include "bitmaps/gray.xbm"
50 #include "xsettings.h"
53 #include <X11/extensions/Xrandr.h>
56 #include <X11/extensions/Xinerama.h>
64 #include <X11/Shell.h>
68 #include <X11/Xaw3d/Paned.h>
69 #include <X11/Xaw3d/Label.h>
70 #else /* !HAVE_XAW3D */
71 #include <X11/Xaw/Paned.h>
72 #include <X11/Xaw/Label.h>
73 #endif /* HAVE_XAW3D */
74 #endif /* USE_MOTIF */
77 #undef USG /* ####KLUDGE for Solaris 2.2 and up */
80 #ifdef USG /* Pacify gcc -Wunused-macros. */
88 #include "../lwlib/lwlib.h"
92 #include <Xm/DialogS.h>
93 #include <Xm/FileSB.h>
99 #include "../lwlib/xlwmenu.h"
102 #if !defined (NO_EDITRES)
104 extern void _XEditResCheckMessages (Widget
, XtPointer
, XEvent
*, Boolean
*);
105 #endif /* not defined NO_EDITRES */
107 /* Unique id counter for widgets created by the Lucid Widget Library. */
109 extern LWLIB_ID widget_id_tick
;
113 #endif /* USE_MOTIF */
115 #endif /* USE_X_TOOLKIT */
121 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
124 static ptrdiff_t image_cache_refcount
;
125 static int dpyinfo_refcount
;
128 static struct x_display_info
*x_display_info_for_name (Lisp_Object
);
130 /* Let the user specify an X display with a Lisp object.
131 OBJECT may be nil, a frame or a terminal object.
132 nil stands for the selected frame--or, if that is not an X frame,
133 the first X display on the list. */
135 struct x_display_info
*
136 check_x_display_info (Lisp_Object object
)
138 struct x_display_info
*dpyinfo
= NULL
;
142 struct frame
*sf
= XFRAME (selected_frame
);
144 if (FRAME_X_P (sf
) && FRAME_LIVE_P (sf
))
145 dpyinfo
= FRAME_DISPLAY_INFO (sf
);
146 else if (x_display_list
!= 0)
147 dpyinfo
= x_display_list
;
149 error ("X windows are not in use or not initialized");
151 else if (TERMINALP (object
))
153 struct terminal
*t
= decode_live_terminal (object
);
155 if (t
->type
!= output_x_window
)
156 error ("Terminal %d is not an X display", t
->id
);
158 dpyinfo
= t
->display_info
.x
;
160 else if (STRINGP (object
))
161 dpyinfo
= x_display_info_for_name (object
);
164 struct frame
*f
= decode_window_system_frame (object
);
165 dpyinfo
= FRAME_DISPLAY_INFO (f
);
171 /* Store the screen positions of frame F into XPTR and YPTR.
172 These are the positions of the containing window manager window,
173 not Emacs's own window. */
176 x_real_positions (struct frame
*f
, int *xptr
, int *yptr
)
178 int win_x
, win_y
, outer_x
IF_LINT (= 0), outer_y
IF_LINT (= 0);
179 int real_x
= 0, real_y
= 0;
180 bool had_errors
= false;
181 Window win
= f
->output_data
.x
->parent_desc
;
183 unsigned long actual_size
, bytes_remaining
;
184 int rc
, actual_format
;
185 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
187 Display
*dpy
= FRAME_X_DISPLAY (f
);
188 unsigned char *tmp_data
= NULL
;
189 Atom target_type
= XA_CARDINAL
;
193 x_catch_errors (dpy
);
195 if (win
== dpyinfo
->root_window
)
196 win
= FRAME_OUTER_WINDOW (f
);
198 /* This loop traverses up the containment tree until we hit the root
199 window. Window managers may intersect many windows between our window
200 and the root window. The window we find just before the root window
201 should be the outer WM window. */
204 Window wm_window
, rootw
;
205 Window
*tmp_children
;
206 unsigned int tmp_nchildren
;
209 success
= XQueryTree (FRAME_X_DISPLAY (f
), win
, &rootw
,
210 &wm_window
, &tmp_children
, &tmp_nchildren
);
212 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
214 /* Don't free tmp_children if XQueryTree failed. */
218 XFree (tmp_children
);
220 if (wm_window
== rootw
|| had_errors
)
231 /* Get the real coordinates for the WM window upper left corner */
232 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
233 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
235 /* Translate real coordinates to coordinates relative to our
236 window. For our window, the upper left corner is 0, 0.
237 Since the upper left corner of the WM window is outside
238 our window, win_x and win_y will be negative:
240 ------------------ ---> x
242 | ----------------- v y
245 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
247 /* From-window, to-window. */
248 FRAME_DISPLAY_INFO (f
)->root_window
,
251 /* From-position, to-position. */
252 real_x
, real_y
, &win_x
, &win_y
,
257 if (FRAME_X_WINDOW (f
) == FRAME_OUTER_WINDOW (f
))
264 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
266 /* From-window, to-window. */
267 FRAME_DISPLAY_INFO (f
)->root_window
,
268 FRAME_OUTER_WINDOW (f
),
270 /* From-position, to-position. */
271 real_x
, real_y
, &outer_x
, &outer_y
,
277 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
281 if (dpyinfo
->root_window
== f
->output_data
.x
->parent_desc
)
283 /* Try _NET_FRAME_EXTENTS if our parent is the root window. */
284 rc
= XGetWindowProperty (dpy
, win
, dpyinfo
->Xatom_net_frame_extents
,
285 0, max_len
, False
, target_type
,
286 &actual_type
, &actual_format
, &actual_size
,
287 &bytes_remaining
, &tmp_data
);
289 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
290 && actual_size
== 4 && actual_format
== 32)
294 long *fe
= (long *)tmp_data
;
296 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
297 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
305 if (tmp_data
) XFree (tmp_data
);
311 if (had_errors
) return;
313 f
->x_pixels_diff
= -win_x
;
314 f
->y_pixels_diff
= -win_y
;
316 FRAME_X_OUTPUT (f
)->x_pixels_outer_diff
= -outer_x
;
317 FRAME_X_OUTPUT (f
)->y_pixels_outer_diff
= -outer_y
;
323 /* Get the mouse position in frame relative coordinates. */
326 x_relative_mouse_position (struct frame
*f
, int *x
, int *y
)
328 Window root
, dummy_window
;
331 eassert (FRAME_X_P (f
));
335 XQueryPointer (FRAME_X_DISPLAY (f
),
336 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
338 /* The root window which contains the pointer. */
341 /* Window pointer is on, not used */
344 /* The position on that root window. */
347 /* x/y in dummy_window coordinates, not used. */
350 /* Modifier keys and pointer buttons, about which
352 (unsigned int *) &dummy
);
356 /* Translate root window coordinates to window coordinates. */
357 *x
-= f
->left_pos
+ FRAME_OUTER_TO_INNER_DIFF_X (f
);
358 *y
-= f
->top_pos
+ FRAME_OUTER_TO_INNER_DIFF_Y (f
);
361 /* Gamma-correct COLOR on frame F. */
364 gamma_correct (struct frame
*f
, XColor
*color
)
368 color
->red
= pow (color
->red
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
369 color
->green
= pow (color
->green
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
370 color
->blue
= pow (color
->blue
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
375 /* Decide if color named COLOR_NAME is valid for use on frame F. If
376 so, return the RGB values in COLOR. If ALLOC_P,
377 allocate the color. Value is false if COLOR_NAME is invalid, or
378 no color could be allocated. */
381 x_defined_color (struct frame
*f
, const char *color_name
,
382 XColor
*color
, bool alloc_p
)
384 bool success_p
= false;
385 Display
*dpy
= FRAME_X_DISPLAY (f
);
386 Colormap cmap
= FRAME_X_COLORMAP (f
);
390 success_p
= xg_check_special_colors (f
, color_name
, color
);
393 success_p
= XParseColor (dpy
, cmap
, color_name
, color
) != 0;
394 if (success_p
&& alloc_p
)
395 success_p
= x_alloc_nearest_color (f
, cmap
, color
);
402 /* Return the pixel color value for color COLOR_NAME on frame F. If F
403 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
404 Signal an error if color can't be allocated. */
407 x_decode_color (struct frame
*f
, Lisp_Object color_name
, int mono_color
)
411 CHECK_STRING (color_name
);
413 #if false /* Don't do this. It's wrong when we're not using the default
414 colormap, it makes freeing difficult, and it's probably not
415 an important optimization. */
416 if (strcmp (SDATA (color_name
), "black") == 0)
417 return BLACK_PIX_DEFAULT (f
);
418 else if (strcmp (SDATA (color_name
), "white") == 0)
419 return WHITE_PIX_DEFAULT (f
);
422 /* Return MONO_COLOR for monochrome frames. */
423 if (FRAME_DISPLAY_INFO (f
)->n_planes
== 1)
426 /* x_defined_color is responsible for coping with failures
427 by looking for a near-miss. */
428 if (x_defined_color (f
, SSDATA (color_name
), &cdef
, true))
431 signal_error ("Undefined color", color_name
);
436 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
437 the previous value of that parameter, NEW_VALUE is the new value.
438 See also the comment of wait_for_wm in struct x_output. */
441 x_set_wait_for_wm (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
443 f
->output_data
.x
->wait_for_wm
= !NILP (new_value
);
447 x_set_tool_bar_position (struct frame
*f
,
448 Lisp_Object new_value
,
449 Lisp_Object old_value
)
451 Lisp_Object choice
= list4 (Qleft
, Qright
, Qtop
, Qbottom
);
453 if (!NILP (Fmemq (new_value
, choice
)))
456 if (!EQ (new_value
, old_value
))
458 xg_change_toolbar_position (f
, new_value
);
459 fset_tool_bar_position (f
, new_value
);
462 if (!EQ (new_value
, Qtop
))
463 error ("The only supported tool bar position is top");
467 wrong_choice (choice
, new_value
);
472 /* Set icon from FILE for frame F. By using GTK functions the icon
473 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
476 xg_set_icon (struct frame
*f
, Lisp_Object file
)
481 found
= x_find_image_file (file
);
487 char *filename
= SSDATA (found
);
490 pixbuf
= gdk_pixbuf_new_from_file (filename
, &err
);
494 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
496 g_object_unref (pixbuf
);
510 xg_set_icon_from_xpm_data (struct frame
*f
, const char **data
)
512 GdkPixbuf
*pixbuf
= gdk_pixbuf_new_from_xpm_data (data
);
517 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)), pixbuf
);
518 g_object_unref (pixbuf
);
524 /* Functions called only from `x_set_frame_param'
525 to set individual parameters.
527 If FRAME_X_WINDOW (f) is 0,
528 the frame is being created and its X-window does not exist yet.
529 In that case, just record the parameter's new value
530 in the standard place; do not attempt to change the window. */
533 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
535 struct x_output
*x
= f
->output_data
.x
;
536 unsigned long fg
, old_fg
;
538 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
539 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
540 FRAME_FOREGROUND_PIXEL (f
) = fg
;
542 if (FRAME_X_WINDOW (f
) != 0)
544 Display
*dpy
= FRAME_X_DISPLAY (f
);
547 XSetForeground (dpy
, x
->normal_gc
, fg
);
548 XSetBackground (dpy
, x
->reverse_gc
, fg
);
550 if (x
->cursor_pixel
== old_fg
)
552 unload_color (f
, x
->cursor_pixel
);
553 x
->cursor_pixel
= x_copy_color (f
, fg
);
554 XSetBackground (dpy
, x
->cursor_gc
, x
->cursor_pixel
);
559 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
561 if (FRAME_VISIBLE_P (f
))
565 unload_color (f
, old_fg
);
569 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
571 struct x_output
*x
= f
->output_data
.x
;
574 bg
= x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
575 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
576 FRAME_BACKGROUND_PIXEL (f
) = bg
;
578 if (FRAME_X_WINDOW (f
) != 0)
580 Display
*dpy
= FRAME_X_DISPLAY (f
);
583 XSetBackground (dpy
, x
->normal_gc
, bg
);
584 XSetForeground (dpy
, x
->reverse_gc
, bg
);
585 XSetWindowBackground (dpy
, FRAME_X_WINDOW (f
), bg
);
586 XSetForeground (dpy
, x
->cursor_gc
, bg
);
589 xg_set_background_color (f
, bg
);
592 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
593 toolkit scroll bars. */
596 for (bar
= FRAME_SCROLL_BARS (f
);
598 bar
= XSCROLL_BAR (bar
)->next
)
600 Window window
= XSCROLL_BAR (bar
)->x_window
;
601 XSetWindowBackground (dpy
, window
, bg
);
604 #endif /* USE_TOOLKIT_SCROLL_BARS */
607 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
609 if (FRAME_VISIBLE_P (f
))
615 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
617 struct x_output
*x
= f
->output_data
.x
;
618 Display
*dpy
= FRAME_X_DISPLAY (f
);
619 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
620 Cursor hourglass_cursor
, horizontal_drag_cursor
, vertical_drag_cursor
;
621 unsigned long pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
622 unsigned long mask_color
= FRAME_BACKGROUND_PIXEL (f
);
624 /* Don't let pointers be invisible. */
625 if (mask_color
== pixel
)
627 x_free_colors (f
, &pixel
, 1);
628 pixel
= x_copy_color (f
, FRAME_FOREGROUND_PIXEL (f
));
631 unload_color (f
, x
->mouse_pixel
);
632 x
->mouse_pixel
= pixel
;
636 /* It's not okay to crash if the user selects a screwy cursor. */
637 x_catch_errors (dpy
);
639 if (!NILP (Vx_pointer_shape
))
641 CHECK_NUMBER (Vx_pointer_shape
);
642 cursor
= XCreateFontCursor (dpy
, XINT (Vx_pointer_shape
));
645 cursor
= XCreateFontCursor (dpy
, XC_xterm
);
646 x_check_errors (dpy
, "bad text pointer cursor: %s");
648 if (!NILP (Vx_nontext_pointer_shape
))
650 CHECK_NUMBER (Vx_nontext_pointer_shape
);
652 = XCreateFontCursor (dpy
, XINT (Vx_nontext_pointer_shape
));
655 nontext_cursor
= XCreateFontCursor (dpy
, XC_left_ptr
);
656 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
658 if (!NILP (Vx_hourglass_pointer_shape
))
660 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
662 = XCreateFontCursor (dpy
, XINT (Vx_hourglass_pointer_shape
));
665 hourglass_cursor
= XCreateFontCursor (dpy
, XC_watch
);
666 x_check_errors (dpy
, "bad hourglass pointer cursor: %s");
668 if (!NILP (Vx_mode_pointer_shape
))
670 CHECK_NUMBER (Vx_mode_pointer_shape
);
671 mode_cursor
= XCreateFontCursor (dpy
, XINT (Vx_mode_pointer_shape
));
674 mode_cursor
= XCreateFontCursor (dpy
, XC_xterm
);
675 x_check_errors (dpy
, "bad modeline pointer cursor: %s");
677 if (!NILP (Vx_sensitive_text_pointer_shape
))
679 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
681 = XCreateFontCursor (dpy
, XINT (Vx_sensitive_text_pointer_shape
));
684 hand_cursor
= XCreateFontCursor (dpy
, XC_hand2
);
686 if (!NILP (Vx_window_horizontal_drag_shape
))
688 CHECK_TYPE_RANGED_INTEGER (unsigned, Vx_window_horizontal_drag_shape
);
689 horizontal_drag_cursor
690 = XCreateFontCursor (dpy
, XINT (Vx_window_horizontal_drag_shape
));
693 horizontal_drag_cursor
694 = XCreateFontCursor (dpy
, XC_sb_h_double_arrow
);
696 if (!NILP (Vx_window_vertical_drag_shape
))
698 CHECK_NUMBER (Vx_window_vertical_drag_shape
);
700 = XCreateFontCursor (dpy
, XINT (Vx_window_vertical_drag_shape
));
704 = XCreateFontCursor (dpy
, XC_sb_v_double_arrow
);
706 /* Check and report errors with the above calls. */
707 x_check_errors (dpy
, "can't set cursor shape: %s");
711 XColor fore_color
, back_color
;
713 fore_color
.pixel
= x
->mouse_pixel
;
714 x_query_color (f
, &fore_color
);
715 back_color
.pixel
= mask_color
;
716 x_query_color (f
, &back_color
);
718 XRecolorCursor (dpy
, cursor
, &fore_color
, &back_color
);
719 XRecolorCursor (dpy
, nontext_cursor
, &fore_color
, &back_color
);
720 XRecolorCursor (dpy
, mode_cursor
, &fore_color
, &back_color
);
721 XRecolorCursor (dpy
, hand_cursor
, &fore_color
, &back_color
);
722 XRecolorCursor (dpy
, hourglass_cursor
, &fore_color
, &back_color
);
723 XRecolorCursor (dpy
, horizontal_drag_cursor
, &fore_color
, &back_color
);
724 XRecolorCursor (dpy
, vertical_drag_cursor
, &fore_color
, &back_color
);
727 if (FRAME_X_WINDOW (f
) != 0)
728 XDefineCursor (dpy
, FRAME_X_WINDOW (f
),
729 f
->output_data
.x
->current_cursor
= cursor
);
731 if (cursor
!= x
->text_cursor
732 && x
->text_cursor
!= 0)
733 XFreeCursor (dpy
, x
->text_cursor
);
734 x
->text_cursor
= cursor
;
736 if (nontext_cursor
!= x
->nontext_cursor
737 && x
->nontext_cursor
!= 0)
738 XFreeCursor (dpy
, x
->nontext_cursor
);
739 x
->nontext_cursor
= nontext_cursor
;
741 if (hourglass_cursor
!= x
->hourglass_cursor
742 && x
->hourglass_cursor
!= 0)
743 XFreeCursor (dpy
, x
->hourglass_cursor
);
744 x
->hourglass_cursor
= hourglass_cursor
;
746 if (mode_cursor
!= x
->modeline_cursor
747 && x
->modeline_cursor
!= 0)
748 XFreeCursor (dpy
, f
->output_data
.x
->modeline_cursor
);
749 x
->modeline_cursor
= mode_cursor
;
751 if (hand_cursor
!= x
->hand_cursor
752 && x
->hand_cursor
!= 0)
753 XFreeCursor (dpy
, x
->hand_cursor
);
754 x
->hand_cursor
= hand_cursor
;
756 if (horizontal_drag_cursor
!= x
->horizontal_drag_cursor
757 && x
->horizontal_drag_cursor
!= 0)
758 XFreeCursor (dpy
, x
->horizontal_drag_cursor
);
759 x
->horizontal_drag_cursor
= horizontal_drag_cursor
;
761 if (vertical_drag_cursor
!= x
->vertical_drag_cursor
762 && x
->vertical_drag_cursor
!= 0)
763 XFreeCursor (dpy
, x
->vertical_drag_cursor
);
764 x
->vertical_drag_cursor
= vertical_drag_cursor
;
769 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
773 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
775 unsigned long fore_pixel
, pixel
;
776 bool fore_pixel_allocated_p
= false, pixel_allocated_p
= false;
777 struct x_output
*x
= f
->output_data
.x
;
779 if (!NILP (Vx_cursor_fore_pixel
))
781 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
782 WHITE_PIX_DEFAULT (f
));
783 fore_pixel_allocated_p
= true;
786 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
788 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
789 pixel_allocated_p
= true;
791 /* Make sure that the cursor color differs from the background color. */
792 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
794 if (pixel_allocated_p
)
796 x_free_colors (f
, &pixel
, 1);
797 pixel_allocated_p
= false;
800 pixel
= x
->mouse_pixel
;
801 if (pixel
== fore_pixel
)
803 if (fore_pixel_allocated_p
)
805 x_free_colors (f
, &fore_pixel
, 1);
806 fore_pixel_allocated_p
= false;
808 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
812 unload_color (f
, x
->cursor_foreground_pixel
);
813 if (!fore_pixel_allocated_p
)
814 fore_pixel
= x_copy_color (f
, fore_pixel
);
815 x
->cursor_foreground_pixel
= fore_pixel
;
817 unload_color (f
, x
->cursor_pixel
);
818 if (!pixel_allocated_p
)
819 pixel
= x_copy_color (f
, pixel
);
820 x
->cursor_pixel
= pixel
;
822 if (FRAME_X_WINDOW (f
) != 0)
825 XSetBackground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, x
->cursor_pixel
);
826 XSetForeground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, fore_pixel
);
829 if (FRAME_VISIBLE_P (f
))
831 x_update_cursor (f
, false);
832 x_update_cursor (f
, true);
836 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
839 /* Set the border-color of frame F to pixel value PIX.
840 Note that this does not fully take effect if done before
841 F has an x-window. */
844 x_set_border_pixel (struct frame
*f
, int pix
)
846 unload_color (f
, f
->output_data
.x
->border_pixel
);
847 f
->output_data
.x
->border_pixel
= pix
;
849 if (FRAME_X_WINDOW (f
) != 0 && f
->border_width
> 0)
852 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), pix
);
855 if (FRAME_VISIBLE_P (f
))
860 /* Set the border-color of frame F to value described by ARG.
861 ARG can be a string naming a color.
862 The border-color is used for the border that is drawn by the X server.
863 Note that this does not fully take effect if done before
864 F has an x-window; it must be redone when the window is created.
866 Note: this is done in two routines because of the way X10 works.
868 Note: under X11, this is normally the province of the window manager,
869 and so emacs's border colors may be overridden. */
872 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
877 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
878 x_set_border_pixel (f
, pix
);
879 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
884 x_set_cursor_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
886 set_frame_cursor_types (f
, arg
);
890 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
896 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
899 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
904 result
= x_text_icon (f
,
905 SSDATA ((!NILP (f
->icon_name
)
909 result
= x_bitmap_icon (f
, arg
);
914 error ("No icon window available");
917 XFlush (FRAME_X_DISPLAY (f
));
922 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
928 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
931 else if (!NILP (arg
) || NILP (oldval
))
934 fset_icon_name (f
, arg
);
936 if (f
->output_data
.x
->icon_bitmap
!= 0)
941 result
= x_text_icon (f
,
942 SSDATA ((!NILP (f
->icon_name
)
951 error ("No icon window available");
954 XFlush (FRAME_X_DISPLAY (f
));
960 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
963 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
964 int olines
= FRAME_MENU_BAR_LINES (f
);
967 /* Right now, menu bars don't work properly in minibuf-only frames;
968 most of the commands try to apply themselves to the minibuffer
969 frame itself, and get an error because you can't switch buffers
970 in or split the minibuffer window. */
971 if (FRAME_MINIBUF_ONLY_P (f
))
974 if (TYPE_RANGED_INTEGERP (int, value
))
975 nlines
= XINT (value
);
979 /* Make sure we redisplay all windows in this frame. */
980 windows_or_buffers_changed
= 59;
982 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
983 FRAME_MENU_BAR_LINES (f
) = 0;
984 FRAME_MENU_BAR_HEIGHT (f
) = 0;
987 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
988 if (FRAME_X_P (f
) && f
->output_data
.x
->menubar_widget
== 0)
989 /* Make sure next redisplay shows the menu bar. */
990 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= true;
994 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
995 free_frame_menubar (f
);
996 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
998 f
->output_data
.x
->menubar_widget
= 0;
1000 #else /* not USE_X_TOOLKIT && not USE_GTK */
1001 FRAME_MENU_BAR_LINES (f
) = nlines
;
1002 FRAME_MENU_BAR_HEIGHT (f
) = nlines
* FRAME_LINE_HEIGHT (f
);
1003 adjust_frame_size (f
, -1, -1, 2, true, Qmenu_bar_lines
);
1004 if (FRAME_X_WINDOW (f
))
1005 x_clear_under_internal_border (f
);
1007 /* If the menu bar height gets changed, the internal border below
1008 the top margin has to be cleared. Also, if the menu bar gets
1009 larger, the area for the added lines has to be cleared except for
1010 the first menu bar line that is to be drawn later. */
1011 if (nlines
!= olines
)
1013 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1014 int width
= FRAME_PIXEL_WIDTH (f
);
1017 /* height can be zero here. */
1018 if (FRAME_X_WINDOW (f
) && height
> 0 && width
> 0)
1020 y
= FRAME_TOP_MARGIN_HEIGHT (f
);
1023 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1024 0, y
, width
, height
);
1028 if (nlines
> 1 && nlines
> olines
)
1030 y
= (olines
== 0 ? 1 : olines
) * FRAME_LINE_HEIGHT (f
);
1031 height
= nlines
* FRAME_LINE_HEIGHT (f
) - y
;
1034 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1035 0, y
, width
, height
);
1039 if (nlines
== 0 && WINDOWP (f
->menu_bar_window
))
1040 clear_glyph_matrix (XWINDOW (f
->menu_bar_window
)->current_matrix
);
1042 #endif /* not USE_X_TOOLKIT && not USE_GTK */
1043 adjust_frame_glyphs (f
);
1044 run_window_configuration_change_hook (f
);
1048 /* Set the number of lines used for the tool bar of frame F to VALUE.
1049 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1050 is the old number of tool bar lines. This function changes the
1051 height of all windows on frame F to match the new tool bar height.
1052 The frame's height doesn't change. */
1055 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1059 /* Treat tool bars like menu bars. */
1060 if (FRAME_MINIBUF_ONLY_P (f
))
1063 /* Use VALUE only if an int >= 0. */
1064 if (RANGED_INTEGERP (0, value
, INT_MAX
))
1065 nlines
= XFASTINT (value
);
1069 x_change_tool_bar_height (f
, nlines
* FRAME_LINE_HEIGHT (f
));
1073 /* Set the pixel height of the tool bar of frame F to HEIGHT. */
1075 x_change_tool_bar_height (struct frame
*f
, int height
)
1078 FRAME_TOOL_BAR_LINES (f
) = 0;
1079 FRAME_TOOL_BAR_HEIGHT (f
) = 0;
1082 FRAME_EXTERNAL_TOOL_BAR (f
) = true;
1083 if (FRAME_X_P (f
) && f
->output_data
.x
->toolbar_widget
== 0)
1084 /* Make sure next redisplay shows the tool bar. */
1085 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= true;
1086 update_frame_tool_bar (f
);
1090 if (FRAME_EXTERNAL_TOOL_BAR (f
))
1091 free_frame_tool_bar (f
);
1092 FRAME_EXTERNAL_TOOL_BAR (f
) = false;
1094 #else /* !USE_GTK */
1095 int unit
= FRAME_LINE_HEIGHT (f
);
1096 int old_height
= FRAME_TOOL_BAR_HEIGHT (f
);
1097 int lines
= (height
+ unit
- 1) / unit
;
1099 /* Make sure we redisplay all windows in this frame. */
1100 windows_or_buffers_changed
= 60;
1103 /* Recalculate tool bar and frame text sizes. */
1104 FRAME_TOOL_BAR_HEIGHT (f
) = height
;
1105 FRAME_TOOL_BAR_LINES (f
) = lines
;
1106 /* Store the `tool-bar-lines' and `height' frame parameters. */
1107 store_frame_param (f
, Qtool_bar_lines
, make_number (lines
));
1108 store_frame_param (f
, Qheight
, make_number (FRAME_LINES (f
)));
1110 /* We also have to make sure that the internal border at the top of
1111 the frame, below the menu bar or tool bar, is redrawn when the
1112 tool bar disappears. This is so because the internal border is
1113 below the tool bar if one is displayed, but is below the menu bar
1114 if there isn't a tool bar. The tool bar draws into the area
1115 below the menu bar. */
1116 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_HEIGHT (f
) == 0)
1119 clear_current_matrices (f
);
1122 if ((height
< old_height
) && WINDOWP (f
->tool_bar_window
))
1123 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1125 /* Recalculate toolbar height. */
1126 f
->n_tool_bar_rows
= 0;
1128 adjust_frame_size (f
, -1, -1,
1129 (!f
->tool_bar_redisplayed_once
? 1
1130 : (old_height
== 0 || height
== 0) ? 2
1132 false, Qtool_bar_lines
);
1134 /* adjust_frame_size might not have done anything, garbage frame
1136 adjust_frame_glyphs (f
);
1137 SET_FRAME_GARBAGED (f
);
1138 if (FRAME_X_WINDOW (f
))
1139 x_clear_under_internal_border (f
);
1141 #endif /* USE_GTK */
1146 x_set_internal_border_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1150 CHECK_TYPE_RANGED_INTEGER (int, arg
);
1151 border
= max (XINT (arg
), 0);
1153 if (border
!= FRAME_INTERNAL_BORDER_WIDTH (f
))
1155 FRAME_INTERNAL_BORDER_WIDTH (f
) = border
;
1157 #ifdef USE_X_TOOLKIT
1158 if (FRAME_X_OUTPUT (f
)->edit_widget
)
1159 widget_store_internal_border (FRAME_X_OUTPUT (f
)->edit_widget
);
1162 if (FRAME_X_WINDOW (f
) != 0)
1164 adjust_frame_size (f
, -1, -1, 3, false, Qinternal_border_width
);
1167 xg_clear_under_internal_border (f
);
1169 x_clear_under_internal_border (f
);
1177 /* Set the foreground color for scroll bars on frame F to VALUE.
1178 VALUE should be a string, a color name. If it isn't a string or
1179 isn't a valid color name, do nothing. OLDVAL is the old value of
1180 the frame parameter. */
1183 x_set_scroll_bar_foreground (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1185 unsigned long pixel
;
1187 if (STRINGP (value
))
1188 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
1192 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
1193 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
1195 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
1196 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1198 /* Remove all scroll bars because they have wrong colors. */
1199 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1200 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1201 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1202 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1204 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
1210 /* Set the background color for scroll bars on frame F to VALUE VALUE
1211 should be a string, a color name. If it isn't a string or isn't a
1212 valid color name, do nothing. OLDVAL is the old value of the frame
1216 x_set_scroll_bar_background (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1218 unsigned long pixel
;
1220 if (STRINGP (value
))
1221 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
1225 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
1226 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
1228 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
1229 /* Scrollbar shadow colors. */
1230 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
1232 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
1233 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
1235 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
1237 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
1238 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
1240 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
1242 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
1243 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1245 /* Remove all scroll bars because they have wrong colors. */
1246 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1247 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1248 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1249 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1251 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
1257 /* Encode Lisp string STRING as a text in a format appropriate for
1258 XICCC (X Inter Client Communication Conventions).
1260 This can call Lisp code, so callers must GCPRO.
1262 If STRING contains only ASCII characters, do no conversion and
1263 return the string data of STRING. Otherwise, encode the text by
1264 CODING_SYSTEM, and return a newly allocated memory area which
1265 should be freed by `xfree' by a caller.
1267 Store the byte length of resulting text in *TEXT_BYTES.
1269 If the text contains only ASCII and Latin-1, store true in *STRING_P,
1270 which means that the `encoding' of the result can be `STRING'.
1271 Otherwise store false in *STRINGP, which means that the `encoding' of
1272 the result should be `COMPOUND_TEXT'. */
1274 static unsigned char *
1275 x_encode_text (Lisp_Object string
, Lisp_Object coding_system
,
1276 ptrdiff_t *text_bytes
, bool *stringp
, bool *freep
)
1278 int result
= string_xstring_p (string
);
1279 struct coding_system coding
;
1283 /* No multibyte character in OBJ. We need not encode it. */
1284 *text_bytes
= SBYTES (string
);
1287 return SDATA (string
);
1290 setup_coding_system (coding_system
, &coding
);
1291 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
1292 /* We suppress producing escape sequences for composition. */
1293 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
1294 coding
.destination
= xnmalloc (SCHARS (string
), 2);
1295 coding
.dst_bytes
= SCHARS (string
) * 2;
1296 encode_coding_object (&coding
, string
, 0, 0,
1297 SCHARS (string
), SBYTES (string
), Qnil
);
1298 *text_bytes
= coding
.produced
;
1299 *stringp
= (result
== 1 || !EQ (coding_system
, Qcompound_text
));
1301 return coding
.destination
;
1305 /* Set the WM name to NAME for frame F. Also set the icon name.
1306 If the frame already has an icon name, use that, otherwise set the
1307 icon name to NAME. */
1310 x_set_name_internal (struct frame
*f
, Lisp_Object name
)
1312 if (FRAME_X_WINDOW (f
))
1316 XTextProperty text
, icon
;
1319 bool do_free_icon_value
= false, do_free_text_value
= false;
1320 Lisp_Object coding_system
;
1321 Lisp_Object encoded_name
;
1322 Lisp_Object encoded_icon_name
;
1323 struct gcpro gcpro1
;
1325 /* As ENCODE_UTF_8 may cause GC and relocation of string data,
1326 we use it before x_encode_text that may return string data. */
1328 encoded_name
= ENCODE_UTF_8 (name
);
1331 coding_system
= Qcompound_text
;
1332 /* Note: Encoding strategy
1334 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1335 text.encoding. But, there are non-internationalized window
1336 managers which don't support that encoding. So, if NAME
1337 contains only ASCII and 8859-1 characters, encode it by
1338 iso-latin-1, and use "STRING" in text.encoding hoping that
1339 such window managers at least analyze this format correctly,
1340 i.e. treat 8-bit bytes as 8859-1 characters.
1342 We may also be able to use "UTF8_STRING" in text.encoding
1343 in the future which can encode all Unicode characters.
1344 But, for the moment, there's no way to know that the
1345 current window manager supports it or not.
1347 Either way, we also set the _NET_WM_NAME and _NET_WM_ICON_NAME
1348 properties. Per the EWMH specification, those two properties
1349 are always UTF8_STRING. This matches what gtk_window_set_title()
1350 does in the USE_GTK case. */
1351 text
.value
= x_encode_text (name
, coding_system
, &bytes
,
1352 &stringp
, &do_free_text_value
);
1353 text
.encoding
= (stringp
? XA_STRING
1354 : FRAME_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1356 text
.nitems
= bytes
;
1358 if (!STRINGP (f
->icon_name
))
1361 encoded_icon_name
= encoded_name
;
1365 /* See the above comment "Note: Encoding strategy". */
1366 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, &bytes
,
1367 &stringp
, &do_free_icon_value
);
1368 icon
.encoding
= (stringp
? XA_STRING
1369 : FRAME_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1371 icon
.nitems
= bytes
;
1373 encoded_icon_name
= ENCODE_UTF_8 (f
->icon_name
);
1377 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1378 SSDATA (encoded_name
));
1379 #else /* not USE_GTK */
1380 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1381 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1382 FRAME_DISPLAY_INFO (f
)->Xatom_net_wm_name
,
1383 FRAME_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1385 SDATA (encoded_name
),
1386 SBYTES (encoded_name
));
1387 #endif /* not USE_GTK */
1389 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &icon
);
1390 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1391 FRAME_DISPLAY_INFO (f
)->Xatom_net_wm_icon_name
,
1392 FRAME_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1394 SDATA (encoded_icon_name
),
1395 SBYTES (encoded_icon_name
));
1397 if (do_free_icon_value
)
1399 if (do_free_text_value
)
1406 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1409 If EXPLICIT is true, that indicates that lisp code is setting the
1410 name; if NAME is a string, set F's name to NAME and set
1411 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1413 If EXPLICIT is false, that indicates that Emacs redisplay code is
1414 suggesting a new name, which lisp code should override; if
1415 F->explicit_name is set, ignore the new name; otherwise, set it. */
1418 x_set_name (struct frame
*f
, Lisp_Object name
, bool explicit)
1420 /* Make sure that requests from lisp code override requests from
1421 Emacs redisplay code. */
1424 /* If we're switching from explicit to implicit, we had better
1425 update the mode lines and thereby update the title. */
1426 if (f
->explicit_name
&& NILP (name
))
1427 update_mode_lines
= 37;
1429 f
->explicit_name
= ! NILP (name
);
1431 else if (f
->explicit_name
)
1434 /* If NAME is nil, set the name to the x_id_name. */
1437 /* Check for no change needed in this very common case
1438 before we do any consing. */
1439 if (!strcmp (FRAME_DISPLAY_INFO (f
)->x_id_name
,
1442 name
= build_string (FRAME_DISPLAY_INFO (f
)->x_id_name
);
1445 CHECK_STRING (name
);
1447 /* Don't change the name if it's already NAME. */
1448 if (! NILP (Fstring_equal (name
, f
->name
)))
1451 fset_name (f
, name
);
1453 /* For setting the frame title, the title parameter should override
1454 the name parameter. */
1455 if (! NILP (f
->title
))
1458 x_set_name_internal (f
, name
);
1461 /* This function should be called when the user's lisp code has
1462 specified a name for the frame; the name will override any set by the
1465 x_explicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1467 x_set_name (f
, arg
, true);
1470 /* This function should be called by Emacs redisplay code to set the
1471 name; names set this way will never override names set by the user's
1474 x_implicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1476 x_set_name (f
, arg
, false);
1479 /* Change the title of frame F to NAME.
1480 If NAME is nil, use the frame name as the title. */
1483 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1485 /* Don't change the title if it's already NAME. */
1486 if (EQ (name
, f
->title
))
1489 update_mode_lines
= 38;
1491 fset_title (f
, name
);
1496 CHECK_STRING (name
);
1498 x_set_name_internal (f
, name
);
1502 x_set_scroll_bar_default_width (struct frame
*f
)
1504 int unit
= FRAME_COLUMN_WIDTH (f
);
1505 #ifdef USE_TOOLKIT_SCROLL_BARS
1507 int minw
= xg_get_default_scrollbar_width ();
1511 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1512 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (minw
+ unit
- 1) / unit
;
1513 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = minw
;
1515 /* The width of a non-toolkit scrollbar is 14 pixels. */
1516 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + unit
- 1) / unit
;
1517 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
)
1518 = FRAME_CONFIG_SCROLL_BAR_COLS (f
) * unit
;
1523 x_set_scroll_bar_default_height (struct frame
*f
)
1525 int height
= FRAME_LINE_HEIGHT (f
);
1526 #ifdef USE_TOOLKIT_SCROLL_BARS
1528 int min_height
= xg_get_default_scrollbar_height ();
1530 int min_height
= 16;
1532 /* A minimum height of 14 doesn't look good for toolkit scroll bars. */
1533 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) = min_height
;
1534 FRAME_CONFIG_SCROLL_BAR_LINES (f
) = (min_height
+ height
- 1) / height
;
1536 /* The height of a non-toolkit scrollbar is 14 pixels. */
1537 FRAME_CONFIG_SCROLL_BAR_LINES (f
) = (14 + height
- 1) / height
;
1539 /* Use all of that space (aside from required margins) for the
1541 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) = 14;
1546 /* Record in frame F the specified or default value according to ALIST
1547 of the parameter named PROP (a Lisp symbol). If no value is
1548 specified for PROP, look for an X default for XPROP on the frame
1549 named NAME. If that is not found either, use the value DEFLT. */
1552 x_default_scroll_bar_color_parameter (struct frame
*f
,
1553 Lisp_Object alist
, Lisp_Object prop
,
1554 const char *xprop
, const char *xclass
,
1557 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1560 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
1561 if (EQ (tem
, Qunbound
))
1563 #ifdef USE_TOOLKIT_SCROLL_BARS
1565 /* See if an X resource for the scroll bar color has been
1567 AUTO_STRING (foreground
, "foreground");
1568 AUTO_STRING (background
, "foreground");
1569 AUTO_STRING (verticalScrollBar
, "verticalScrollBar");
1570 tem
= (display_x_get_resource
1571 (dpyinfo
, foreground_p
? foreground
: background
,
1572 empty_unibyte_string
,
1574 empty_unibyte_string
));
1577 /* If nothing has been specified, scroll bars will use a
1578 toolkit-dependent default. Because these defaults are
1579 difficult to get at without actually creating a scroll
1580 bar, use nil to indicate that no color has been
1585 #else /* not USE_TOOLKIT_SCROLL_BARS */
1589 #endif /* not USE_TOOLKIT_SCROLL_BARS */
1592 AUTO_FRAME_ARG (arg
, prop
, tem
);
1593 x_set_frame_parameters (f
, arg
);
1600 #ifdef USE_X_TOOLKIT
1602 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
1603 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
1604 already be present because of the toolkit (Motif adds some of them,
1605 for example, but Xt doesn't). */
1608 hack_wm_protocols (struct frame
*f
, Widget widget
)
1610 Display
*dpy
= XtDisplay (widget
);
1611 Window w
= XtWindow (widget
);
1612 bool need_delete
= true;
1613 bool need_focus
= true;
1614 bool need_save
= true;
1619 unsigned char *catoms
;
1621 unsigned long nitems
= 0;
1622 unsigned long bytes_after
;
1624 if ((XGetWindowProperty (dpy
, w
,
1625 FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1626 0, 100, False
, XA_ATOM
,
1627 &type
, &format
, &nitems
, &bytes_after
,
1630 && format
== 32 && type
== XA_ATOM
)
1632 Atom
*atoms
= (Atom
*) catoms
;
1637 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
1638 need_delete
= false;
1639 else if (atoms
[nitems
]
1640 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
1642 else if (atoms
[nitems
]
1643 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
1654 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
1656 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
1658 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
1660 XChangeProperty (dpy
, w
, FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1661 XA_ATOM
, 32, PropModeAppend
,
1662 (unsigned char *) props
, count
);
1670 /* Support routines for XIC (X Input Context). */
1674 static XFontSet
xic_create_xfontset (struct frame
*);
1675 static XIMStyle
best_xim_style (XIMStyles
*);
1678 /* Supported XIM styles, ordered by preference. */
1680 static const XIMStyle supported_xim_styles
[] =
1682 XIMPreeditPosition
| XIMStatusArea
,
1683 XIMPreeditPosition
| XIMStatusNothing
,
1684 XIMPreeditPosition
| XIMStatusNone
,
1685 XIMPreeditNothing
| XIMStatusArea
,
1686 XIMPreeditNothing
| XIMStatusNothing
,
1687 XIMPreeditNothing
| XIMStatusNone
,
1688 XIMPreeditNone
| XIMStatusArea
,
1689 XIMPreeditNone
| XIMStatusNothing
,
1690 XIMPreeditNone
| XIMStatusNone
,
1695 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1696 /* Create an X fontset on frame F with base font name BASE_FONTNAME. */
1698 static const char xic_default_fontset
[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
1700 /* Create an Xt fontset spec from the name of a base font.
1701 If `motif' is True use the Motif syntax. */
1703 xic_create_fontsetname (const char *base_fontname
, bool motif
)
1705 const char *sep
= motif
? ";" : ",";
1709 /* Make a fontset name from the base font name. */
1710 if (xic_default_fontset
== base_fontname
)
1712 /* There is no base font name, use the default. */
1713 fontsetname
= xmalloc (strlen (base_fontname
) + 2);
1714 z
= stpcpy (fontsetname
, base_fontname
);
1718 /* Make a fontset name from the base font name.
1719 The font set will be made of the following elements:
1721 - the base font where the charset spec is replaced by -*-*.
1722 - the same but with the family also replaced with -*-*-. */
1723 const char *p
= base_fontname
;
1726 for (i
= 0; *p
; p
++)
1730 /* As the font name doesn't conform to XLFD, we can't
1731 modify it to generalize it to allcs and allfamilies.
1732 Use the specified font plus the default. */
1733 fontsetname
= xmalloc (strlen (base_fontname
)
1734 + strlen (xic_default_fontset
) + 3);
1735 z
= stpcpy (fontsetname
, base_fontname
);
1736 z
= stpcpy (z
, sep
);
1737 z
= stpcpy (z
, xic_default_fontset
);
1742 const char *p1
= NULL
, *p2
= NULL
, *p3
= NULL
;
1743 char *font_allcs
= NULL
;
1744 char *font_allfamilies
= NULL
;
1745 char *font_all
= NULL
;
1746 const char *allcs
= "*-*-*-*-*-*-*";
1747 const char *allfamilies
= "-*-*-";
1748 const char *all
= "*-*-*-*-";
1751 for (i
= 0, p
= base_fontname
; i
< 8; p
++)
1764 /* If base_fontname specifies ADSTYLE, make it a
1768 ptrdiff_t diff
= (p2
- p3
) - 2;
1770 base
= alloca (strlen (base_fontname
) + 1);
1771 memcpy (base
, base_fontname
, p3
- base_fontname
);
1772 base
[p3
- base_fontname
] = '*';
1773 base
[(p3
- base_fontname
) + 1] = '-';
1774 strcpy (base
+ (p3
- base_fontname
) + 2, p2
);
1775 p
= base
+ (p
- base_fontname
) - diff
;
1776 p1
= base
+ (p1
- base_fontname
);
1777 p2
= base
+ (p2
- base_fontname
) - diff
;
1778 base_fontname
= base
;
1781 /* Build the font spec that matches all charsets. */
1782 len
= p
- base_fontname
+ strlen (allcs
) + 1;
1783 font_allcs
= alloca (len
);
1784 memcpy (font_allcs
, base_fontname
, p
- base_fontname
);
1785 strcpy (font_allcs
+ (p
- base_fontname
), allcs
);
1787 /* Build the font spec that matches all families and
1789 len
= p
- p1
+ strlen (allcs
) + strlen (allfamilies
) + 1;
1790 font_allfamilies
= alloca (len
);
1791 strcpy (font_allfamilies
, allfamilies
);
1792 memcpy (font_allfamilies
+ strlen (allfamilies
), p1
, p
- p1
);
1793 strcpy (font_allfamilies
+ strlen (allfamilies
) + (p
- p1
), allcs
);
1795 /* Build the font spec that matches all. */
1796 len
= p
- p2
+ strlen (allcs
) + strlen (all
) + strlen (allfamilies
) + 1;
1797 font_all
= alloca (len
);
1798 z
= stpcpy (font_all
, allfamilies
);
1799 z
= stpcpy (z
, all
);
1800 memcpy (z
, p2
, p
- p2
);
1801 strcpy (z
+ (p
- p2
), allcs
);
1803 /* Build the actual font set name. */
1804 len
= strlen (base_fontname
) + strlen (font_allcs
)
1805 + strlen (font_allfamilies
) + strlen (font_all
) + 5;
1806 fontsetname
= xmalloc (len
);
1807 z
= stpcpy (fontsetname
, base_fontname
);
1808 z
= stpcpy (z
, sep
);
1809 z
= stpcpy (z
, font_allcs
);
1810 z
= stpcpy (z
, sep
);
1811 z
= stpcpy (z
, font_allfamilies
);
1812 z
= stpcpy (z
, sep
);
1813 z
= stpcpy (z
, font_all
);
1820 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
1822 #ifdef DEBUG_XIC_FONTSET
1824 print_fontset_result (XFontSet xfs
, char *name
, char **missing_list
,
1828 fprintf (stderr
, "XIC Fontset created: %s\n", name
);
1831 fprintf (stderr
, "XIC Fontset failed: %s\n", name
);
1832 while (missing_count
-- > 0)
1834 fprintf (stderr
, " missing: %s\n", *missing_list
);
1843 xic_create_xfontset (struct frame
*f
)
1845 XFontSet xfs
= NULL
;
1846 struct font
*font
= FRAME_FONT (f
);
1847 int pixel_size
= font
->pixel_size
;
1848 Lisp_Object rest
, frame
;
1850 /* See if there is another frame already using same fontset. */
1851 FOR_EACH_FRAME (rest
, frame
)
1853 struct frame
*cf
= XFRAME (frame
);
1855 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
1856 && FRAME_DISPLAY_INFO (cf
) == FRAME_DISPLAY_INFO (f
)
1858 && FRAME_FONT (f
)->pixel_size
== pixel_size
)
1860 xfs
= FRAME_XIC_FONTSET (cf
);
1868 char **missing_list
;
1871 const char *xlfd_format
= "-*-*-medium-r-normal--%d-*-*-*-*-*";
1873 sprintf (buf
, xlfd_format
, pixel_size
);
1874 missing_list
= NULL
;
1875 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
1876 &missing_list
, &missing_count
, &def_string
);
1877 #ifdef DEBUG_XIC_FONTSET
1878 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
1881 XFreeStringList (missing_list
);
1884 /* List of pixel sizes most likely available. Find one that
1885 is closest to pixel_size. */
1886 int sizes
[] = {0, 8, 10, 11, 12, 14, 17, 18, 20, 24, 26, 34, 0};
1887 int *smaller
, *larger
;
1889 for (smaller
= sizes
; smaller
[1]; smaller
++)
1890 if (smaller
[1] >= pixel_size
)
1892 larger
= smaller
+ 1;
1893 if (*larger
== pixel_size
)
1895 while (*smaller
|| *larger
)
1900 this_size
= *smaller
--;
1901 else if (! *smaller
)
1902 this_size
= *larger
++;
1903 else if (pixel_size
- *smaller
< *larger
- pixel_size
)
1904 this_size
= *smaller
--;
1906 this_size
= *larger
++;
1907 sprintf (buf
, xlfd_format
, this_size
);
1908 missing_list
= NULL
;
1909 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
1910 &missing_list
, &missing_count
, &def_string
);
1911 #ifdef DEBUG_XIC_FONTSET
1912 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
1915 XFreeStringList (missing_list
);
1922 const char *last_resort
= "-*-*-*-r-normal--*-*-*-*-*-*";
1924 missing_list
= NULL
;
1925 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), last_resort
,
1926 &missing_list
, &missing_count
, &def_string
);
1927 #ifdef DEBUG_XIC_FONTSET
1928 print_fontset_result (xfs
, last_resort
, missing_list
, missing_count
);
1931 XFreeStringList (missing_list
);
1939 /* Free the X fontset of frame F if it is the last frame using it. */
1942 xic_free_xfontset (struct frame
*f
)
1944 Lisp_Object rest
, frame
;
1945 bool shared_p
= false;
1947 if (!FRAME_XIC_FONTSET (f
))
1950 /* See if there is another frame sharing the same fontset. */
1951 FOR_EACH_FRAME (rest
, frame
)
1953 struct frame
*cf
= XFRAME (frame
);
1954 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
1955 && FRAME_DISPLAY_INFO (cf
) == FRAME_DISPLAY_INFO (f
)
1956 && FRAME_XIC_FONTSET (cf
) == FRAME_XIC_FONTSET (f
))
1964 /* The fontset is not used anymore. It is safe to free it. */
1965 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
1967 FRAME_XIC_FONTSET (f
) = NULL
;
1971 /* Value is the best input style, given user preferences USER (already
1972 checked to be supported by Emacs), and styles supported by the
1973 input method XIM. */
1976 best_xim_style (XIMStyles
*xim
)
1979 int nr_supported
= ARRAYELTS (supported_xim_styles
);
1981 for (i
= 0; i
< nr_supported
; ++i
)
1982 for (j
= 0; j
< xim
->count_styles
; ++j
)
1983 if (supported_xim_styles
[i
] == xim
->supported_styles
[j
])
1984 return supported_xim_styles
[i
];
1986 /* Return the default style. */
1987 return XIMPreeditNothing
| XIMStatusNothing
;
1990 /* Create XIC for frame F. */
1993 create_frame_xic (struct frame
*f
)
1997 XFontSet xfs
= NULL
;
1998 XVaNestedList status_attr
= NULL
;
1999 XVaNestedList preedit_attr
= NULL
;
2007 xim
= FRAME_X_XIM (f
);
2011 /* Determine XIC style. */
2012 xic_style
= best_xim_style (FRAME_X_XIM_STYLES (f
));
2014 /* Create X fontset. */
2015 if (xic_style
& (XIMPreeditPosition
| XIMStatusArea
))
2017 xfs
= xic_create_xfontset (f
);
2021 FRAME_XIC_FONTSET (f
) = xfs
;
2024 if (xic_style
& XIMPreeditPosition
)
2026 spot
.x
= 0; spot
.y
= 1;
2027 preedit_attr
= XVaCreateNestedList (0,
2030 FRAME_FOREGROUND_PIXEL (f
),
2032 FRAME_BACKGROUND_PIXEL (f
),
2033 (xic_style
& XIMPreeditPosition
2043 if (xic_style
& XIMStatusArea
)
2045 s_area
.x
= 0; s_area
.y
= 0; s_area
.width
= 1; s_area
.height
= 1;
2046 status_attr
= XVaCreateNestedList (0,
2052 FRAME_FOREGROUND_PIXEL (f
),
2054 FRAME_BACKGROUND_PIXEL (f
),
2061 if (preedit_attr
&& status_attr
)
2062 xic
= XCreateIC (xim
,
2063 XNInputStyle
, xic_style
,
2064 XNClientWindow
, FRAME_X_WINDOW (f
),
2065 XNFocusWindow
, FRAME_X_WINDOW (f
),
2066 XNStatusAttributes
, status_attr
,
2067 XNPreeditAttributes
, preedit_attr
,
2069 else if (preedit_attr
)
2070 xic
= XCreateIC (xim
,
2071 XNInputStyle
, xic_style
,
2072 XNClientWindow
, FRAME_X_WINDOW (f
),
2073 XNFocusWindow
, FRAME_X_WINDOW (f
),
2074 XNPreeditAttributes
, preedit_attr
,
2076 else if (status_attr
)
2077 xic
= XCreateIC (xim
,
2078 XNInputStyle
, xic_style
,
2079 XNClientWindow
, FRAME_X_WINDOW (f
),
2080 XNFocusWindow
, FRAME_X_WINDOW (f
),
2081 XNStatusAttributes
, status_attr
,
2084 xic
= XCreateIC (xim
,
2085 XNInputStyle
, xic_style
,
2086 XNClientWindow
, FRAME_X_WINDOW (f
),
2087 XNFocusWindow
, FRAME_X_WINDOW (f
),
2093 FRAME_XIC (f
) = xic
;
2094 FRAME_XIC_STYLE (f
) = xic_style
;
2095 xfs
= NULL
; /* Don't free below. */
2103 XFree (preedit_attr
);
2106 XFree (status_attr
);
2110 /* Destroy XIC and free XIC fontset of frame F, if any. */
2113 free_frame_xic (struct frame
*f
)
2115 if (FRAME_XIC (f
) == NULL
)
2118 XDestroyIC (FRAME_XIC (f
));
2119 xic_free_xfontset (f
);
2121 FRAME_XIC (f
) = NULL
;
2125 /* Place preedit area for XIC of window W's frame to specified
2126 pixel position X/Y. X and Y are relative to window W. */
2129 xic_set_preeditarea (struct window
*w
, int x
, int y
)
2131 struct frame
*f
= XFRAME (w
->frame
);
2135 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
) + WINDOW_LEFT_FRINGE_WIDTH (w
);
2136 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
2137 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
2138 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2143 /* Place status area for XIC in bottom right corner of frame F.. */
2146 xic_set_statusarea (struct frame
*f
)
2148 XIC xic
= FRAME_XIC (f
);
2153 /* Negotiate geometry of status area. If input method has existing
2154 status area, use its current size. */
2155 area
.x
= area
.y
= area
.width
= area
.height
= 0;
2156 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
2157 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2160 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
2161 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2164 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
2166 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
2167 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2171 area
.width
= needed
->width
;
2172 area
.height
= needed
->height
;
2173 area
.x
= FRAME_PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
2174 area
.y
= (FRAME_PIXEL_HEIGHT (f
) - area
.height
2175 - FRAME_MENUBAR_HEIGHT (f
)
2176 - FRAME_TOOLBAR_TOP_HEIGHT (f
)
2177 - FRAME_INTERNAL_BORDER_WIDTH (f
));
2180 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
2181 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2186 /* Set X fontset for XIC of frame F, using base font name
2187 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2190 xic_set_xfontset (struct frame
*f
, const char *base_fontname
)
2195 xic_free_xfontset (f
);
2197 xfs
= xic_create_xfontset (f
);
2199 attr
= XVaCreateNestedList (0, XNFontSet
, xfs
, NULL
);
2200 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
2201 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2202 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
2203 XSetICValues (FRAME_XIC (f
), XNStatusAttributes
, attr
, NULL
);
2206 FRAME_XIC_FONTSET (f
) = xfs
;
2209 #endif /* HAVE_X_I18N */
2213 #ifdef USE_X_TOOLKIT
2215 /* Create and set up the X widget for frame F. */
2218 x_window (struct frame
*f
, long window_prompting
)
2220 XClassHint class_hints
;
2221 XSetWindowAttributes attributes
;
2222 unsigned long attribute_mask
;
2223 Widget shell_widget
;
2225 Widget frame_widget
;
2231 /* Use the resource name as the top-level widget name
2232 for looking up resources. Make a non-Lisp copy
2233 for the window manager, so GC relocation won't bother it.
2235 Elsewhere we specify the window name for the window manager. */
2236 f
->namebuf
= xlispstrdup (Vx_resource_name
);
2239 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2240 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2241 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2242 XtSetArg (al
[ac
], XtNborderWidth
, f
->border_width
); ac
++;
2243 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2244 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2245 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2246 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2247 applicationShellWidgetClass
,
2248 FRAME_X_DISPLAY (f
), al
, ac
);
2250 f
->output_data
.x
->widget
= shell_widget
;
2251 /* maybe_set_screen_title_format (shell_widget); */
2253 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2254 NULL
, shell_widget
, False
,
2255 NULL
, NULL
, NULL
, NULL
);
2258 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2259 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2260 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2261 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2262 XtSetValues (pane_widget
, al
, ac
);
2263 f
->output_data
.x
->column_widget
= pane_widget
;
2265 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2266 the emacs screen when changing menubar. This reduces flickering. */
2269 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2270 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2271 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2272 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2273 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2274 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2275 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2276 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2277 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2278 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
2281 f
->output_data
.x
->edit_widget
= frame_widget
;
2283 XtManageChild (frame_widget
);
2285 /* Do some needed geometry management. */
2289 int extra_borders
= 0;
2291 = (f
->output_data
.x
->menubar_widget
2292 ? (f
->output_data
.x
->menubar_widget
->core
.height
2293 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
2296 #if false /* Experimentally, we now get the right results
2297 for -geometry -0-0 without this. 24 Aug 96, rms. */
2298 if (FRAME_EXTERNAL_MENU_BAR (f
))
2301 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2302 menubar_size
+= ibw
;
2306 FRAME_MENUBAR_HEIGHT (f
) = menubar_size
;
2309 /* Motif seems to need this amount added to the sizes
2310 specified for the shell widget. The Athena/Lucid widgets don't.
2311 Both conclusions reached experimentally. -- rms. */
2312 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
2313 &extra_borders
, NULL
);
2317 f
->shell_position
= xmalloc (sizeof "=x++" + 4 * INT_STRLEN_BOUND (int));
2319 /* Convert our geometry parameters into a geometry string
2321 Note that we do not specify here whether the position
2322 is a user-specified or program-specified one.
2323 We pass that information later, in x_wm_set_size_hints. */
2325 int left
= f
->left_pos
;
2326 bool xneg
= (window_prompting
& XNegative
) != 0;
2327 int top
= f
->top_pos
;
2328 bool yneg
= (window_prompting
& YNegative
) != 0;
2334 if (window_prompting
& USPosition
)
2335 sprintf (f
->shell_position
, "=%dx%d%c%d%c%d",
2336 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2337 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
2338 (xneg
? '-' : '+'), left
,
2339 (yneg
? '-' : '+'), top
);
2342 sprintf (f
->shell_position
, "=%dx%d",
2343 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2344 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
2346 /* Setting x and y when the position is not specified in
2347 the geometry string will set program position in the WM hints.
2348 If Emacs had just one program position, we could set it in
2349 fallback resources, but since each make-frame call can specify
2350 different program positions, this is easier. */
2351 XtSetArg (gal
[gac
], XtNx
, left
); gac
++;
2352 XtSetArg (gal
[gac
], XtNy
, top
); gac
++;
2356 XtSetArg (gal
[gac
], XtNgeometry
, f
->shell_position
); gac
++;
2357 XtSetValues (shell_widget
, gal
, gac
);
2360 XtManageChild (pane_widget
);
2361 XtRealizeWidget (shell_widget
);
2363 if (FRAME_X_EMBEDDED_P (f
))
2364 XReparentWindow (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
),
2365 f
->output_data
.x
->parent_desc
, 0, 0);
2367 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2369 validate_x_resource_name ();
2371 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2372 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2373 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2376 FRAME_XIC (f
) = NULL
;
2378 create_frame_xic (f
);
2381 f
->output_data
.x
->wm_hints
.input
= True
;
2382 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2383 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2384 &f
->output_data
.x
->wm_hints
);
2386 hack_wm_protocols (f
, shell_widget
);
2389 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2392 /* Do a stupid property change to force the server to generate a
2393 PropertyNotify event so that the event_stream server timestamp will
2394 be initialized to something relevant to the time we created the window.
2396 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2397 FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2398 XA_ATOM
, 32, PropModeAppend
, NULL
, 0);
2400 /* Make all the standard events reach the Emacs frame. */
2401 attributes
.event_mask
= STANDARD_EVENT_SET
;
2406 /* XIM server might require some X events. */
2407 unsigned long fevent
= NoEventMask
;
2408 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2409 attributes
.event_mask
|= fevent
;
2411 #endif /* HAVE_X_I18N */
2413 attribute_mask
= CWEventMask
;
2414 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2415 attribute_mask
, &attributes
);
2417 XtMapWidget (frame_widget
);
2419 /* x_set_name normally ignores requests to set the name if the
2420 requested name is the same as the current name. This is the one
2421 place where that assumption isn't correct; f->name is set, but
2422 the X server hasn't been told. */
2425 bool explicit = f
->explicit_name
;
2427 f
->explicit_name
= false;
2429 fset_name (f
, Qnil
);
2430 x_set_name (f
, name
, explicit);
2433 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2434 f
->output_data
.x
->current_cursor
2435 = f
->output_data
.x
->text_cursor
);
2439 /* This is a no-op, except under Motif. Make sure main areas are
2440 set to something reasonable, in case we get an error later. */
2441 lw_set_main_areas (pane_widget
, 0, frame_widget
);
2444 #else /* not USE_X_TOOLKIT */
2447 x_window (struct frame
*f
)
2449 if (! xg_create_frame_widgets (f
))
2450 error ("Unable to create window");
2453 FRAME_XIC (f
) = NULL
;
2457 create_frame_xic (f
);
2460 /* XIM server might require some X events. */
2461 unsigned long fevent
= NoEventMask
;
2462 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2464 if (fevent
!= NoEventMask
)
2466 XSetWindowAttributes attributes
;
2467 XWindowAttributes wattr
;
2468 unsigned long attribute_mask
;
2470 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2472 attributes
.event_mask
= wattr
.your_event_mask
| fevent
;
2473 attribute_mask
= CWEventMask
;
2474 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2475 attribute_mask
, &attributes
);
2483 #else /*! USE_GTK */
2484 /* Create and set up the X window for frame F. */
2487 x_window (struct frame
*f
)
2489 XClassHint class_hints
;
2490 XSetWindowAttributes attributes
;
2491 unsigned long attribute_mask
;
2493 attributes
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2494 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
2495 attributes
.bit_gravity
= StaticGravity
;
2496 attributes
.backing_store
= NotUseful
;
2497 attributes
.save_under
= True
;
2498 attributes
.event_mask
= STANDARD_EVENT_SET
;
2499 attributes
.colormap
= FRAME_X_COLORMAP (f
);
2500 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
2505 = XCreateWindow (FRAME_X_DISPLAY (f
),
2506 f
->output_data
.x
->parent_desc
,
2509 FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
),
2511 CopyFromParent
, /* depth */
2512 InputOutput
, /* class */
2514 attribute_mask
, &attributes
);
2519 create_frame_xic (f
);
2522 /* XIM server might require some X events. */
2523 unsigned long fevent
= NoEventMask
;
2524 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2525 attributes
.event_mask
|= fevent
;
2526 attribute_mask
= CWEventMask
;
2527 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2528 attribute_mask
, &attributes
);
2531 #endif /* HAVE_X_I18N */
2533 validate_x_resource_name ();
2535 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2536 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2537 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2539 /* This indicates that we use the "Passive Input" input model.
2540 Unless we do this, we don't get the Focus{In,Out} events that we
2541 need to draw the cursor correctly. Accursed bureaucrats.
2542 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2544 f
->output_data
.x
->wm_hints
.input
= True
;
2545 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2546 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2547 &f
->output_data
.x
->wm_hints
);
2548 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
2550 /* Request "save yourself" and "delete window" commands from wm. */
2553 protocols
[0] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2554 protocols
[1] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2555 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2558 /* x_set_name normally ignores requests to set the name if the
2559 requested name is the same as the current name. This is the one
2560 place where that assumption isn't correct; f->name is set, but
2561 the X server hasn't been told. */
2564 bool explicit = f
->explicit_name
;
2566 f
->explicit_name
= false;
2568 fset_name (f
, Qnil
);
2569 x_set_name (f
, name
, explicit);
2572 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2573 f
->output_data
.x
->current_cursor
2574 = f
->output_data
.x
->text_cursor
);
2578 if (FRAME_X_WINDOW (f
) == 0)
2579 error ("Unable to create window");
2582 #endif /* not USE_GTK */
2583 #endif /* not USE_X_TOOLKIT */
2585 /* Verify that the icon position args for this window are valid. */
2588 x_icon_verify (struct frame
*f
, Lisp_Object parms
)
2590 Lisp_Object icon_x
, icon_y
;
2592 /* Set the position of the icon. Note that twm groups all
2593 icons in an icon window. */
2594 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2595 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2596 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2598 CHECK_NUMBER (icon_x
);
2599 CHECK_NUMBER (icon_y
);
2601 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2602 error ("Both left and top icon corners of icon must be specified");
2605 /* Handle the icon stuff for this window. Perhaps later we might
2606 want an x_set_icon_position which can be called interactively as
2610 x_icon (struct frame
*f
, Lisp_Object parms
)
2612 /* Set the position of the icon. Note that twm groups all
2613 icons in an icon window. */
2615 = x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2617 = x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2618 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2620 CHECK_TYPE_RANGED_INTEGER (int, icon_x
);
2621 CHECK_TYPE_RANGED_INTEGER (int, icon_y
);
2623 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2624 error ("Both left and top icon corners of icon must be specified");
2628 if (! EQ (icon_x
, Qunbound
))
2629 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2631 #if false /* x_get_arg removes the visibility parameter as a side effect,
2632 but x_create_frame still needs it. */
2633 /* Start up iconic or window? */
2634 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2635 x_wm_set_window_state
2636 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
2642 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
2649 /* Make the GCs needed for this window, setting the
2650 background, border and mouse colors; also create the
2651 mouse cursor and the gray border tile. */
2654 x_make_gc (struct frame
*f
)
2656 XGCValues gc_values
;
2660 /* Create the GCs of this frame.
2661 Note that many default values are used. */
2663 gc_values
.foreground
= FRAME_FOREGROUND_PIXEL (f
);
2664 gc_values
.background
= FRAME_BACKGROUND_PIXEL (f
);
2665 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2666 f
->output_data
.x
->normal_gc
2667 = XCreateGC (FRAME_X_DISPLAY (f
),
2669 GCLineWidth
| GCForeground
| GCBackground
,
2672 /* Reverse video style. */
2673 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2674 gc_values
.background
= FRAME_FOREGROUND_PIXEL (f
);
2675 f
->output_data
.x
->reverse_gc
2676 = XCreateGC (FRAME_X_DISPLAY (f
),
2678 GCForeground
| GCBackground
| GCLineWidth
,
2681 /* Cursor has cursor-color background, background-color foreground. */
2682 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2683 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
2684 gc_values
.fill_style
= FillOpaqueStippled
;
2685 f
->output_data
.x
->cursor_gc
2686 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2687 (GCForeground
| GCBackground
2688 | GCFillStyle
| GCLineWidth
),
2691 /* Create the gray border tile used when the pointer is not in
2692 the frame. Since this depends on the frame's pixel values,
2693 this must be done on a per-frame basis. */
2694 f
->output_data
.x
->border_tile
2695 = (XCreatePixmapFromBitmapData
2696 (FRAME_X_DISPLAY (f
), FRAME_DISPLAY_INFO (f
)->root_window
,
2697 gray_bits
, gray_width
, gray_height
,
2698 FRAME_FOREGROUND_PIXEL (f
),
2699 FRAME_BACKGROUND_PIXEL (f
),
2700 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
2706 /* Free what was allocated in x_make_gc. */
2709 x_free_gcs (struct frame
*f
)
2711 Display
*dpy
= FRAME_X_DISPLAY (f
);
2715 if (f
->output_data
.x
->normal_gc
)
2717 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
2718 f
->output_data
.x
->normal_gc
= 0;
2721 if (f
->output_data
.x
->reverse_gc
)
2723 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
2724 f
->output_data
.x
->reverse_gc
= 0;
2727 if (f
->output_data
.x
->cursor_gc
)
2729 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
2730 f
->output_data
.x
->cursor_gc
= 0;
2733 if (f
->output_data
.x
->border_tile
)
2735 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
2736 f
->output_data
.x
->border_tile
= 0;
2743 /* Handler for signals raised during x_create_frame and
2744 x_create_tip_frame. FRAME is the frame which is partially
2748 unwind_create_frame (Lisp_Object frame
)
2750 struct frame
*f
= XFRAME (frame
);
2752 /* If frame is already dead, nothing to do. This can happen if the
2753 display is disconnected after the frame has become official, but
2754 before x_create_frame removes the unwind protect. */
2755 if (!FRAME_LIVE_P (f
))
2758 /* If frame is ``official'', nothing to do. */
2759 if (NILP (Fmemq (frame
, Vframe_list
)))
2761 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2762 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2765 x_free_frame_resources (f
);
2768 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2769 /* Check that reference counts are indeed correct. */
2770 eassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
2771 eassert (dpyinfo
->terminal
->image_cache
->refcount
== image_cache_refcount
);
2780 do_unwind_create_frame (Lisp_Object frame
)
2782 unwind_create_frame (frame
);
2786 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
2788 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2789 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
2791 Lisp_Object font
= Qnil
;
2792 if (EQ (font_param
, Qunbound
))
2795 if (NILP (font_param
))
2797 /* System font should take precedence over X resources. We suggest this
2798 regardless of font-use-system-font because .emacs may not have been
2800 const char *system_font
= xsettings_get_system_font ();
2802 font
= font_open_by_name (f
, build_unibyte_string (system_font
));
2806 font
= !NILP (font_param
) ? font_param
2807 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
2809 if (! FONTP (font
) && ! STRINGP (font
))
2814 /* This will find the normal Xft font. */
2817 "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1",
2818 "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2819 "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2820 /* This was formerly the first thing tried, but it finds
2821 too many fonts and takes too long. */
2822 "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1",
2823 /* If those didn't work, look for something which will
2825 "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1",
2830 for (i
= 0; names
[i
]; i
++)
2832 font
= font_open_by_name (f
, build_unibyte_string (names
[i
]));
2837 error ("No suitable font was found");
2839 else if (!NILP (font_param
))
2841 /* Remember the explicit font parameter, so we can re-apply it after
2842 we've applied the `default' face settings. */
2843 AUTO_FRAME_ARG (arg
, Qfont_param
, font_param
);
2844 x_set_frame_parameters (f
, arg
);
2847 /* This call will make X resources override any system font setting. */
2848 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
2852 DEFUN ("x-wm-set-size-hint", Fx_wm_set_size_hint
, Sx_wm_set_size_hint
,
2854 doc
: /* Send the size hints for frame FRAME to the window manager.
2855 If FRAME is omitted or nil, use the selected frame.
2856 Signal error if FRAME is not an X frame. */)
2859 struct frame
*f
= decode_window_system_frame (frame
);
2862 x_wm_set_size_hint (f
, 0, false);
2868 set_machine_and_pid_properties (struct frame
*f
)
2870 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME. */
2871 XSetWMProperties (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), NULL
, NULL
,
2872 NULL
, 0, NULL
, NULL
, NULL
);
2873 pid_t pid
= getpid ();
2874 if (pid
<= 0xffffffffu
)
2876 unsigned long xpid
= pid
;
2877 XChangeProperty (FRAME_X_DISPLAY (f
),
2878 FRAME_OUTER_WINDOW (f
),
2879 XInternAtom (FRAME_X_DISPLAY (f
),
2882 XA_CARDINAL
, 32, PropModeReplace
,
2883 (unsigned char *) &xpid
, 1);
2887 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
2889 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
2890 Return an Emacs frame object. PARMS is an alist of frame parameters.
2891 If the parameters specify that the frame should not have a minibuffer,
2892 and do not specify a specific minibuffer window to use, then
2893 `default-minibuffer-frame' must be a frame whose minibuffer can be
2894 shared by the new frame.
2896 This function is an internal primitive--use `make-frame' instead. */)
2900 Lisp_Object frame
, tem
;
2902 bool minibuffer_only
= false;
2903 long window_prompting
= 0;
2904 ptrdiff_t count
= SPECPDL_INDEX ();
2905 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
2906 Lisp_Object display
;
2907 struct x_display_info
*dpyinfo
= NULL
;
2911 parms
= Fcopy_alist (parms
);
2913 /* Use this general default value to start with
2914 until we know if this frame has a specified name. */
2915 Vx_resource_name
= Vinvocation_name
;
2917 display
= x_get_arg (dpyinfo
, parms
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
2918 if (EQ (display
, Qunbound
))
2919 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
2920 if (EQ (display
, Qunbound
))
2922 dpyinfo
= check_x_display_info (display
);
2923 kb
= dpyinfo
->terminal
->kboard
;
2925 if (!dpyinfo
->terminal
->name
)
2926 error ("Terminal is not live, can't create new frames on it");
2928 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
2930 && ! EQ (name
, Qunbound
)
2932 error ("Invalid frame name--not a string or nil");
2935 Vx_resource_name
= name
;
2937 /* See if parent window is specified. */
2938 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
2939 if (EQ (parent
, Qunbound
))
2941 if (! NILP (parent
))
2942 CHECK_NUMBER (parent
);
2944 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
2945 /* No need to protect DISPLAY because that's not used after passing
2946 it to make_frame_without_minibuffer. */
2948 GCPRO4 (parms
, parent
, name
, frame
);
2949 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
2951 if (EQ (tem
, Qnone
) || NILP (tem
))
2952 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
2953 else if (EQ (tem
, Qonly
))
2955 f
= make_minibuffer_frame ();
2956 minibuffer_only
= true;
2958 else if (WINDOWP (tem
))
2959 f
= make_frame_without_minibuffer (tem
, kb
, display
);
2961 f
= make_frame (true);
2963 XSETFRAME (frame
, f
);
2965 f
->terminal
= dpyinfo
->terminal
;
2967 f
->output_method
= output_x_window
;
2968 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
2969 f
->output_data
.x
->icon_bitmap
= -1;
2970 FRAME_FONTSET (f
) = -1;
2971 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
2972 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
2973 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
2974 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
2975 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
2976 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
2977 f
->output_data
.x
->white_relief
.pixel
= -1;
2978 f
->output_data
.x
->black_relief
.pixel
= -1;
2981 x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
2983 if (! STRINGP (f
->icon_name
))
2984 fset_icon_name (f
, Qnil
);
2986 FRAME_DISPLAY_INFO (f
) = dpyinfo
;
2988 /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe. */
2989 record_unwind_protect (do_unwind_create_frame
, frame
);
2991 /* These colors will be set anyway later, but it's important
2992 to get the color reference counts right, so initialize them! */
2995 struct gcpro gcpro1
;
2997 /* Function x_decode_color can signal an error. Make
2998 sure to initialize color slots so that we won't try
2999 to free colors we haven't allocated. */
3000 FRAME_FOREGROUND_PIXEL (f
) = -1;
3001 FRAME_BACKGROUND_PIXEL (f
) = -1;
3002 f
->output_data
.x
->cursor_pixel
= -1;
3003 f
->output_data
.x
->cursor_foreground_pixel
= -1;
3004 f
->output_data
.x
->border_pixel
= -1;
3005 f
->output_data
.x
->mouse_pixel
= -1;
3007 black
= build_string ("black");
3009 FRAME_FOREGROUND_PIXEL (f
)
3010 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3011 FRAME_BACKGROUND_PIXEL (f
)
3012 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3013 f
->output_data
.x
->cursor_pixel
3014 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3015 f
->output_data
.x
->cursor_foreground_pixel
3016 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3017 f
->output_data
.x
->border_pixel
3018 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3019 f
->output_data
.x
->mouse_pixel
3020 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3024 /* Specify the parent under which to make this X window. */
3027 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
3028 f
->output_data
.x
->explicit_parent
= true;
3032 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
3033 f
->output_data
.x
->explicit_parent
= false;
3036 /* Set the name; the functions to which we pass f expect the name to
3038 if (EQ (name
, Qunbound
) || NILP (name
))
3040 fset_name (f
, build_string (dpyinfo
->x_id_name
));
3041 f
->explicit_name
= false;
3045 fset_name (f
, name
);
3046 f
->explicit_name
= true;
3047 /* Use the frame's title when getting resources for this frame. */
3048 specbind (Qx_resource_name
, name
);
3051 #ifdef HAVE_FREETYPE
3053 register_font_driver (&xftfont_driver
, f
);
3054 #else /* not HAVE_XFT */
3055 register_font_driver (&ftxfont_driver
, f
);
3056 #endif /* not HAVE_XFT */
3057 #endif /* HAVE_FREETYPE */
3058 register_font_driver (&xfont_driver
, f
);
3060 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
3061 "fontBackend", "FontBackend", RES_TYPE_STRING
);
3063 /* Extract the window parameters from the supplied values
3064 that are needed to determine window geometry. */
3065 x_default_font_parameter (f
, parms
);
3066 if (!FRAME_FONT (f
))
3068 delete_frame (frame
, Qnoelisp
);
3069 error ("Invalid frame font");
3072 /* Frame contents get displaced if an embedded X window has a border. */
3073 if (! FRAME_X_EMBEDDED_P (f
))
3074 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
3075 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
3077 /* This defaults to 1 in order to match xterm. We recognize either
3078 internalBorderWidth or internalBorder (which is what xterm calls
3080 if (NILP (Fassq (Qinternal_border_width
, parms
)))
3084 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
3085 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
3086 if (! EQ (value
, Qunbound
))
3087 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
3090 x_default_parameter (f
, parms
, Qinternal_border_width
,
3091 #ifdef USE_GTK /* We used to impose 0 in xg_create_frame_widgets. */
3096 "internalBorderWidth", "internalBorderWidth",
3098 x_default_parameter (f
, parms
, Qright_divider_width
, make_number (0),
3099 NULL
, NULL
, RES_TYPE_NUMBER
);
3100 x_default_parameter (f
, parms
, Qbottom_divider_width
, make_number (0),
3101 NULL
, NULL
, RES_TYPE_NUMBER
);
3102 x_default_parameter (f
, parms
, Qvertical_scroll_bars
,
3103 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
3108 "verticalScrollBars", "ScrollBars",
3110 x_default_parameter (f
, parms
, Qhorizontal_scroll_bars
, Qnil
,
3111 "horizontalScrollBars", "ScrollBars",
3113 /* Also do the stuff which must be set before the window exists. */
3114 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3115 "foreground", "Foreground", RES_TYPE_STRING
);
3116 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3117 "background", "Background", RES_TYPE_STRING
);
3118 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3119 "pointerColor", "Foreground", RES_TYPE_STRING
);
3120 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3121 "borderColor", "BorderColor", RES_TYPE_STRING
);
3122 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3123 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3124 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3125 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3126 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3127 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3128 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3129 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3131 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3132 "scrollBarForeground",
3133 "ScrollBarForeground", true);
3134 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3135 "scrollBarBackground",
3136 "ScrollBarBackground", false);
3139 image_cache_refcount
=
3140 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
3141 dpyinfo_refcount
= dpyinfo
->reference_count
;
3142 #endif /* GLYPH_DEBUG */
3144 /* Init faces before x_default_parameter is called for the
3145 scroll-bar-width parameter because otherwise we end up in
3146 init_iterator with a null face cache, which should not happen. */
3147 init_frame_faces (f
);
3149 /* The following call of change_frame_size is needed since otherwise
3150 x_set_tool_bar_lines will already work with the character sizes
3151 installed by init_frame_faces while the frame's pixel size is
3152 still calculated from a character size of 1 and we subsequently
3153 hit the (height >= 0) assertion in window_box_height.
3155 The non-pixelwise code apparently worked around this because it
3156 had one frame line vs one toolbar line which left us with a zero
3157 root window height which was obviously wrong as well ... */
3158 adjust_frame_size (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
),
3159 FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
), 5, true,
3162 /* Set the menu-bar-lines and tool-bar-lines parameters. We don't
3163 look up the X resources controlling the menu-bar and tool-bar
3164 here; they are processed specially at startup, and reflected in
3165 the values of the mode variables. */
3167 x_default_parameter (f
, parms
, Qmenu_bar_lines
,
3168 NILP (Vmenu_bar_mode
)
3169 ? make_number (0) : make_number (1),
3170 NULL
, NULL
, RES_TYPE_NUMBER
);
3171 x_default_parameter (f
, parms
, Qtool_bar_lines
,
3172 NILP (Vtool_bar_mode
)
3173 ? make_number (0) : make_number (1),
3174 NULL
, NULL
, RES_TYPE_NUMBER
);
3176 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3177 "bufferPredicate", "BufferPredicate",
3179 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3180 "title", "Title", RES_TYPE_STRING
);
3181 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3182 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3183 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3184 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3185 x_default_parameter (f
, parms
, Qtool_bar_position
,
3186 FRAME_TOOL_BAR_POSITION (f
), 0, 0, RES_TYPE_SYMBOL
);
3188 /* Compute the size of the X window. */
3189 window_prompting
= x_figure_window_size (f
, parms
, true);
3191 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3192 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3194 x_icon_verify (f
, parms
);
3196 /* Create the X widget or window. */
3197 #ifdef USE_X_TOOLKIT
3198 x_window (f
, window_prompting
);
3206 /* Now consider the frame official. */
3207 f
->terminal
->reference_count
++;
3208 FRAME_DISPLAY_INFO (f
)->reference_count
++;
3209 Vframe_list
= Fcons (frame
, Vframe_list
);
3211 /* We need to do this after creating the X window, so that the
3212 icon-creation functions can say whose icon they're describing. */
3213 x_default_parameter (f
, parms
, Qicon_type
, Qt
,
3214 "bitmapIcon", "BitmapIcon", RES_TYPE_BOOLEAN
);
3216 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3217 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3218 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3219 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3220 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3221 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3222 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3223 "scrollBarWidth", "ScrollBarWidth",
3225 x_default_parameter (f
, parms
, Qscroll_bar_height
, Qnil
,
3226 "scrollBarHeight", "ScrollBarHeight",
3228 x_default_parameter (f
, parms
, Qalpha
, Qnil
,
3229 "alpha", "Alpha", RES_TYPE_NUMBER
);
3231 /* Consider frame official, now. */
3232 f
->can_x_set_window_size
= true;
3234 adjust_frame_size (f
, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
), 0, true,
3237 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3238 /* Create the menu bar. */
3239 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3241 /* If this signals an error, we haven't set size hints for the
3242 frame and we didn't make it visible. */
3243 initialize_frame_menubar (f
);
3246 /* This is a no-op, except under Motif where it arranges the
3247 main window for the widgets on it. */
3248 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3249 f
->output_data
.x
->menubar_widget
,
3250 f
->output_data
.x
->edit_widget
);
3251 #endif /* not USE_GTK */
3253 #endif /* USE_X_TOOLKIT || USE_GTK */
3255 /* Tell the server what size and position, etc, we want, and how
3256 badly we want them. This should be done after we have the menu
3257 bar so that its size can be taken into account. */
3259 x_wm_set_size_hint (f
, window_prompting
, false);
3262 /* Make the window appear on the frame and enable display, unless
3263 the caller says not to. However, with explicit parent, Emacs
3264 cannot control visibility, so don't try. */
3265 if (! f
->output_data
.x
->explicit_parent
)
3267 Lisp_Object visibility
;
3269 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3271 if (EQ (visibility
, Qunbound
))
3274 if (EQ (visibility
, Qicon
))
3275 x_iconify_frame (f
);
3276 else if (! NILP (visibility
))
3277 x_make_frame_visible (f
);
3280 /* Must have been Qnil. */
3286 /* Set machine name and pid for the purpose of window managers. */
3287 set_machine_and_pid_properties (f
);
3289 /* Set the WM leader property. GTK does this itself, so this is not
3290 needed when using GTK. */
3291 if (dpyinfo
->client_leader_window
!= 0)
3293 XChangeProperty (FRAME_X_DISPLAY (f
),
3294 FRAME_OUTER_WINDOW (f
),
3295 dpyinfo
->Xatom_wm_client_leader
,
3296 XA_WINDOW
, 32, PropModeReplace
,
3297 (unsigned char *) &dpyinfo
->client_leader_window
, 1);
3302 /* Initialize `default-minibuffer-frame' in case this is the first
3303 frame on this terminal. */
3304 if (FRAME_HAS_MINIBUF_P (f
)
3305 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
3306 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
3307 kset_default_minibuffer_frame (kb
, frame
);
3309 /* All remaining specified parameters, which have not been "used"
3310 by x_get_arg and friends, now go in the misc. alist of the frame. */
3311 for (tem
= parms
; CONSP (tem
); tem
= XCDR (tem
))
3312 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
3313 fset_param_alist (f
, Fcons (XCAR (tem
), f
->param_alist
));
3317 /* Make sure windows on this frame appear in calls to next-window
3318 and similar functions. */
3319 Vwindow_list
= Qnil
;
3321 return unbind_to (count
, frame
);
3325 /* FRAME is used only to get a handle on the X display. We don't pass the
3326 display info directly because we're called from frame.c, which doesn't
3327 know about that structure. */
3330 x_get_focus_frame (struct frame
*frame
)
3332 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (frame
);
3334 if (! dpyinfo
->x_focus_frame
)
3337 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3342 /* In certain situations, when the window manager follows a
3343 click-to-focus policy, there seems to be no way around calling
3344 XSetInputFocus to give another frame the input focus .
3346 In an ideal world, XSetInputFocus should generally be avoided so
3347 that applications don't interfere with the window manager's focus
3348 policy. But I think it's okay to use when it's clearly done
3349 following a user-command. */
3352 x_focus_frame (struct frame
*f
)
3354 Display
*dpy
= FRAME_X_DISPLAY (f
);
3357 x_catch_errors (dpy
);
3359 if (FRAME_X_EMBEDDED_P (f
))
3361 /* For Xembedded frames, normally the embedder forwards key
3362 events. See XEmbed Protocol Specification at
3363 http://freedesktop.org/wiki/Specifications/xembed-spec */
3364 xembed_request_focus (f
);
3368 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3369 RevertToParent
, CurrentTime
);
3370 x_ewmh_activate_frame (f
);
3373 x_uncatch_errors ();
3378 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
3379 doc
: /* Internal function called by `color-defined-p', which see
3380 .\(Note that the Nextstep version of this function ignores FRAME.) */)
3381 (Lisp_Object color
, Lisp_Object frame
)
3384 struct frame
*f
= decode_window_system_frame (frame
);
3386 CHECK_STRING (color
);
3388 if (x_defined_color (f
, SSDATA (color
), &foo
, false))
3394 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
3395 doc
: /* Internal function called by `color-values', which see. */)
3396 (Lisp_Object color
, Lisp_Object frame
)
3399 struct frame
*f
= decode_window_system_frame (frame
);
3401 CHECK_STRING (color
);
3403 if (x_defined_color (f
, SSDATA (color
), &foo
, false))
3404 return list3i (foo
.red
, foo
.green
, foo
.blue
);
3409 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
3410 doc
: /* Internal function called by `display-color-p', which see. */)
3411 (Lisp_Object terminal
)
3413 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3415 if (dpyinfo
->n_planes
<= 2)
3418 switch (dpyinfo
->visual
->class)
3431 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3433 doc
: /* Return t if the X display supports shades of gray.
3434 Note that color displays do support shades of gray.
3435 The optional argument TERMINAL specifies which display to ask about.
3436 TERMINAL should be a terminal object, a frame or a display name (a string).
3437 If omitted or nil, that stands for the selected frame's display. */)
3438 (Lisp_Object terminal
)
3440 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3442 if (dpyinfo
->n_planes
<= 1)
3445 switch (dpyinfo
->visual
->class)
3460 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3462 doc
: /* Return the width in pixels of the X display TERMINAL.
3463 The optional argument TERMINAL specifies which display to ask about.
3464 TERMINAL should be a terminal object, a frame or a display name (a string).
3465 If omitted or nil, that stands for the selected frame's display.
3467 On \"multi-monitor\" setups this refers to the pixel width for all
3468 physical monitors associated with TERMINAL. To get information for
3469 each physical monitor, use `display-monitor-attributes-list'. */)
3470 (Lisp_Object terminal
)
3472 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3474 return make_number (x_display_pixel_width (dpyinfo
));
3477 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3478 Sx_display_pixel_height
, 0, 1, 0,
3479 doc
: /* Return the height in pixels of the X display TERMINAL.
3480 The optional argument TERMINAL specifies which display to ask about.
3481 TERMINAL should be a terminal object, a frame or a display name (a string).
3482 If omitted or nil, that stands for the selected frame's display.
3484 On \"multi-monitor\" setups this refers to the pixel height for all
3485 physical monitors associated with TERMINAL. To get information for
3486 each physical monitor, use `display-monitor-attributes-list'. */)
3487 (Lisp_Object terminal
)
3489 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3491 return make_number (x_display_pixel_height (dpyinfo
));
3494 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3496 doc
: /* Return the number of bitplanes of the X display TERMINAL.
3497 The optional argument TERMINAL specifies which display to ask about.
3498 TERMINAL should be a terminal object, a frame or a display name (a string).
3499 If omitted or nil, that stands for the selected frame's display. */)
3500 (Lisp_Object terminal
)
3502 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3504 return make_number (dpyinfo
->n_planes
);
3507 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3509 doc
: /* Return the number of color cells of the X display TERMINAL.
3510 The optional argument TERMINAL specifies which display to ask about.
3511 TERMINAL should be a terminal object, a frame or a display name (a string).
3512 If omitted or nil, that stands for the selected frame's display. */)
3513 (Lisp_Object terminal
)
3515 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3517 int nr_planes
= DisplayPlanes (dpyinfo
->display
,
3518 XScreenNumberOfScreen (dpyinfo
->screen
));
3520 /* Truncate nr_planes to 24 to avoid integer overflow.
3521 Some displays says 32, but only 24 bits are actually significant.
3522 There are only very few and rare video cards that have more than
3523 24 significant bits. Also 24 bits is more than 16 million colors,
3524 it "should be enough for everyone". */
3525 if (nr_planes
> 24) nr_planes
= 24;
3527 return make_number (1 << nr_planes
);
3530 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3531 Sx_server_max_request_size
,
3533 doc
: /* Return the maximum request size of the X server of display TERMINAL.
3534 The optional argument TERMINAL specifies which display to ask about.
3535 TERMINAL should be a terminal object, a frame or a display name (a string).
3536 If omitted or nil, that stands for the selected frame's display. */)
3537 (Lisp_Object terminal
)
3539 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3541 return make_number (MAXREQUEST (dpyinfo
->display
));
3544 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3545 doc
: /* Return the "vendor ID" string of the X server of display TERMINAL.
3546 \(Labeling every distributor as a "vendor" embodies the false assumption
3547 that operating systems cannot be developed and distributed noncommercially.)
3548 The optional argument TERMINAL specifies which display to ask about.
3549 TERMINAL should be a terminal object, a frame or a display name (a string).
3550 If omitted or nil, that stands for the selected frame's display. */)
3551 (Lisp_Object terminal
)
3553 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3554 const char *vendor
= ServerVendor (dpyinfo
->display
);
3556 if (! vendor
) vendor
= "";
3557 return build_string (vendor
);
3560 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3561 doc
: /* Return the version numbers of the X server of display TERMINAL.
3562 The value is a list of three integers: the major and minor
3563 version numbers of the X Protocol in use, and the distributor-specific release
3564 number. See also the function `x-server-vendor'.
3566 The optional argument TERMINAL specifies which display to ask about.
3567 TERMINAL should be a terminal object, a frame or a display name (a string).
3568 If omitted or nil, that stands for the selected frame's display. */)
3569 (Lisp_Object terminal
)
3571 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3572 Display
*dpy
= dpyinfo
->display
;
3574 return list3i (ProtocolVersion (dpy
), ProtocolRevision (dpy
),
3575 VendorRelease (dpy
));
3578 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3579 doc
: /* Return the number of screens on the X server of display TERMINAL.
3580 The optional argument TERMINAL specifies which display to ask about.
3581 TERMINAL should be a terminal object, a frame or a display name (a string).
3582 If omitted or nil, that stands for the selected frame's display. */)
3583 (Lisp_Object terminal
)
3585 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3587 return make_number (ScreenCount (dpyinfo
->display
));
3590 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3591 doc
: /* Return the height in millimeters of the X display TERMINAL.
3592 The optional argument TERMINAL specifies which display to ask about.
3593 TERMINAL should be a terminal object, a frame or a display name (a string).
3594 If omitted or nil, that stands for the selected frame's display.
3596 On \"multi-monitor\" setups this refers to the height in millimeters for
3597 all physical monitors associated with TERMINAL. To get information
3598 for each physical monitor, use `display-monitor-attributes-list'. */)
3599 (Lisp_Object terminal
)
3601 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3603 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3606 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3607 doc
: /* Return the width in millimeters of the X display TERMINAL.
3608 The optional argument TERMINAL specifies which display to ask about.
3609 TERMINAL should be a terminal object, a frame or a display name (a string).
3610 If omitted or nil, that stands for the selected frame's display.
3612 On \"multi-monitor\" setups this refers to the width in millimeters for
3613 all physical monitors associated with TERMINAL. To get information
3614 for each physical monitor, use `display-monitor-attributes-list'. */)
3615 (Lisp_Object terminal
)
3617 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3619 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3622 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3623 Sx_display_backing_store
, 0, 1, 0,
3624 doc
: /* Return an indication of whether X display TERMINAL does backing store.
3625 The value may be `always', `when-mapped', or `not-useful'.
3626 The optional argument TERMINAL specifies which display to ask about.
3627 TERMINAL should be a terminal object, a frame or a display name (a string).
3628 If omitted or nil, that stands for the selected frame's display. */)
3629 (Lisp_Object terminal
)
3631 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3634 switch (DoesBackingStore (dpyinfo
->screen
))
3637 result
= intern ("always");
3641 result
= intern ("when-mapped");
3645 result
= intern ("not-useful");
3649 error ("Strange value for BackingStore parameter of screen");
3655 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3656 Sx_display_visual_class
, 0, 1, 0,
3657 doc
: /* Return the visual class of the X display TERMINAL.
3658 The value is one of the symbols `static-gray', `gray-scale',
3659 `static-color', `pseudo-color', `true-color', or `direct-color'.
3661 The optional argument TERMINAL specifies which display to ask about.
3662 TERMINAL should a terminal object, a frame or a display name (a string).
3663 If omitted or nil, that stands for the selected frame's display. */)
3664 (Lisp_Object terminal
)
3666 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3669 switch (dpyinfo
->visual
->class)
3672 result
= intern ("static-gray");
3675 result
= intern ("gray-scale");
3678 result
= intern ("static-color");
3681 result
= intern ("pseudo-color");
3684 result
= intern ("true-color");
3687 result
= intern ("direct-color");
3690 error ("Display has an unknown visual class");
3696 DEFUN ("x-display-save-under", Fx_display_save_under
,
3697 Sx_display_save_under
, 0, 1, 0,
3698 doc
: /* Return t if the X display TERMINAL supports the save-under feature.
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 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3712 /* Store the geometry of the workarea on display DPYINFO into *RECT.
3713 Return false if and only if the workarea information cannot be
3714 obtained via the _NET_WORKAREA root window property. */
3716 #if ! GTK_CHECK_VERSION (3, 4, 0)
3718 x_get_net_workarea (struct x_display_info
*dpyinfo
, XRectangle
*rect
)
3720 Display
*dpy
= dpyinfo
->display
;
3721 long offset
, max_len
;
3722 Atom target_type
, actual_type
;
3723 unsigned long actual_size
, bytes_remaining
;
3724 int rc
, actual_format
;
3725 unsigned char *tmp_data
= NULL
;
3726 bool result
= false;
3728 x_catch_errors (dpy
);
3731 target_type
= XA_CARDINAL
;
3732 rc
= XGetWindowProperty (dpy
, dpyinfo
->root_window
,
3733 dpyinfo
->Xatom_net_current_desktop
,
3734 offset
, max_len
, False
, target_type
,
3735 &actual_type
, &actual_format
, &actual_size
,
3736 &bytes_remaining
, &tmp_data
);
3737 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
3738 && actual_format
== 32 && actual_size
== max_len
)
3740 long current_desktop
= ((long *) tmp_data
)[0];
3745 offset
= 4 * current_desktop
;
3747 rc
= XGetWindowProperty (dpy
, dpyinfo
->root_window
,
3748 dpyinfo
->Xatom_net_workarea
,
3749 offset
, max_len
, False
, target_type
,
3750 &actual_type
, &actual_format
, &actual_size
,
3751 &bytes_remaining
, &tmp_data
);
3752 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
3753 && actual_format
== 32 && actual_size
== max_len
)
3755 long *values
= (long *) tmp_data
;
3757 rect
->x
= values
[0];
3758 rect
->y
= values
[1];
3759 rect
->width
= values
[2];
3760 rect
->height
= values
[3];
3770 x_uncatch_errors ();
3778 /* Return monitor number where F is "most" or closest to. */
3780 x_get_monitor_for_frame (struct frame
*f
,
3781 struct MonitorInfo
*monitors
,
3785 int area
= 0, dist
= -1;
3786 int best_area
= -1, best_dist
= -1;
3789 if (n_monitors
== 1) return 0;
3790 frect
.x
= f
->left_pos
;
3791 frect
.y
= f
->top_pos
;
3792 frect
.width
= FRAME_PIXEL_WIDTH (f
);
3793 frect
.height
= FRAME_PIXEL_HEIGHT (f
);
3795 for (i
= 0; i
< n_monitors
; ++i
)
3797 struct MonitorInfo
*mi
= &monitors
[i
];
3801 if (mi
->geom
.width
== 0) continue;
3803 if (x_intersect_rectangles (&mi
->geom
, &frect
, &res
))
3805 a
= res
.width
* res
.height
;
3813 if (a
== 0 && area
== 0)
3816 if (frect
.x
+ frect
.width
< mi
->geom
.x
)
3817 dx
= mi
->geom
.x
- frect
.x
+ frect
.width
;
3818 else if (frect
.x
> mi
->geom
.x
+ mi
->geom
.width
)
3819 dx
= frect
.x
- mi
->geom
.x
+ mi
->geom
.width
;
3822 if (frect
.y
+ frect
.height
< mi
->geom
.y
)
3823 dy
= mi
->geom
.y
- frect
.y
+ frect
.height
;
3824 else if (frect
.y
> mi
->geom
.y
+ mi
->geom
.height
)
3825 dy
= frect
.y
- mi
->geom
.y
+ mi
->geom
.height
;
3830 if (dist
== -1 || dist
> d
)
3838 return best_area
!= -1 ? best_area
: (best_dist
!= -1 ? best_dist
: 0);
3842 x_make_monitor_attribute_list (struct MonitorInfo
*monitors
,
3844 int primary_monitor
,
3845 struct x_display_info
*dpyinfo
,
3848 Lisp_Object monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
3849 Lisp_Object frame
, rest
;
3851 FOR_EACH_FRAME (rest
, frame
)
3853 struct frame
*f
= XFRAME (frame
);
3855 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
3856 && !EQ (frame
, tip_frame
))
3858 int i
= x_get_monitor_for_frame (f
, monitors
, n_monitors
);
3859 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
3863 return make_monitor_attribute_list (monitors
, n_monitors
, primary_monitor
,
3864 monitor_frames
, source
);
3868 x_get_monitor_attributes_fallback (struct x_display_info
*dpyinfo
)
3870 struct MonitorInfo monitor
;
3871 XRectangle workarea_r
;
3873 /* Fallback: treat (possibly) multiple physical monitors as if they
3874 formed a single monitor as a whole. This should provide a
3875 consistent result at least on single monitor environments. */
3876 monitor
.geom
.x
= monitor
.geom
.y
= 0;
3877 monitor
.geom
.width
= x_display_pixel_width (dpyinfo
);
3878 monitor
.geom
.height
= x_display_pixel_height (dpyinfo
);
3879 monitor
.mm_width
= WidthMMOfScreen (dpyinfo
->screen
);
3880 monitor
.mm_height
= HeightMMOfScreen (dpyinfo
->screen
);
3881 monitor
.name
= xstrdup ("combined screen");
3883 if (x_get_net_workarea (dpyinfo
, &workarea_r
))
3884 monitor
.work
= workarea_r
;
3886 monitor
.work
= monitor
.geom
;
3887 return x_make_monitor_attribute_list (&monitor
, 1, 0, dpyinfo
, "fallback");
3891 #ifdef HAVE_XINERAMA
3893 x_get_monitor_attributes_xinerama (struct x_display_info
*dpyinfo
)
3896 Lisp_Object attributes_list
= Qnil
;
3897 Display
*dpy
= dpyinfo
->display
;
3898 XineramaScreenInfo
*info
= XineramaQueryScreens (dpy
, &n_monitors
);
3899 struct MonitorInfo
*monitors
;
3900 double mm_width_per_pixel
, mm_height_per_pixel
;
3902 if (! info
|| n_monitors
== 0)
3906 return attributes_list
;
3909 mm_width_per_pixel
= ((double) WidthMMOfScreen (dpyinfo
->screen
)
3910 / x_display_pixel_width (dpyinfo
));
3911 mm_height_per_pixel
= ((double) HeightMMOfScreen (dpyinfo
->screen
)
3912 / x_display_pixel_height (dpyinfo
));
3913 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
3914 for (i
= 0; i
< n_monitors
; ++i
)
3916 struct MonitorInfo
*mi
= &monitors
[i
];
3917 XRectangle workarea_r
;
3919 mi
->geom
.x
= info
[i
].x_org
;
3920 mi
->geom
.y
= info
[i
].y_org
;
3921 mi
->geom
.width
= info
[i
].width
;
3922 mi
->geom
.height
= info
[i
].height
;
3923 mi
->mm_width
= mi
->geom
.width
* mm_width_per_pixel
+ 0.5;
3924 mi
->mm_height
= mi
->geom
.height
* mm_height_per_pixel
+ 0.5;
3927 /* Xinerama usually have primary monitor first, just use that. */
3928 if (i
== 0 && x_get_net_workarea (dpyinfo
, &workarea_r
))
3930 mi
->work
= workarea_r
;
3931 if (! x_intersect_rectangles (&mi
->geom
, &mi
->work
, &mi
->work
))
3932 mi
->work
= mi
->geom
;
3935 mi
->work
= mi
->geom
;
3939 attributes_list
= x_make_monitor_attribute_list (monitors
,
3944 free_monitors (monitors
, n_monitors
);
3945 return attributes_list
;
3947 #endif /* HAVE_XINERAMA */
3952 x_get_monitor_attributes_xrandr (struct x_display_info
*dpyinfo
)
3954 Lisp_Object attributes_list
= Qnil
;
3955 XRRScreenResources
*resources
;
3956 Display
*dpy
= dpyinfo
->display
;
3957 int i
, n_monitors
, primary
= -1;
3958 RROutput pxid
= None
;
3959 struct MonitorInfo
*monitors
;
3961 #ifdef HAVE_XRRGETSCREENRESOURCESCURRENT
3962 resources
= XRRGetScreenResourcesCurrent (dpy
, dpyinfo
->root_window
);
3964 resources
= XRRGetScreenResources (dpy
, dpyinfo
->root_window
);
3966 if (! resources
|| resources
->noutput
== 0)
3969 XRRFreeScreenResources (resources
);
3972 n_monitors
= resources
->noutput
;
3973 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
3975 #ifdef HAVE_XRRGETOUTPUTPRIMARY
3976 pxid
= XRRGetOutputPrimary (dpy
, dpyinfo
->root_window
);
3979 for (i
= 0; i
< n_monitors
; ++i
)
3981 XRROutputInfo
*info
= XRRGetOutputInfo (dpy
, resources
,
3982 resources
->outputs
[i
]);
3983 Connection conn
= info
? info
->connection
: RR_Disconnected
;
3984 RRCrtc id
= info
? info
->crtc
: None
;
3986 if (strcmp (info
->name
, "default") == 0)
3988 /* Non XRandr 1.2 driver, does not give useful data. */
3989 XRRFreeOutputInfo (info
);
3990 XRRFreeScreenResources (resources
);
3991 free_monitors (monitors
, n_monitors
);
3995 if (conn
!= RR_Disconnected
&& id
!= None
)
3997 XRRCrtcInfo
*crtc
= XRRGetCrtcInfo (dpy
, resources
, id
);
3998 struct MonitorInfo
*mi
= &monitors
[i
];
3999 XRectangle workarea_r
;
4003 XRRFreeOutputInfo (info
);
4007 mi
->geom
.x
= crtc
->x
;
4008 mi
->geom
.y
= crtc
->y
;
4009 mi
->geom
.width
= crtc
->width
;
4010 mi
->geom
.height
= crtc
->height
;
4011 mi
->mm_width
= info
->mm_width
;
4012 mi
->mm_height
= info
->mm_height
;
4013 mi
->name
= xstrdup (info
->name
);
4015 if (pxid
!= None
&& pxid
== resources
->outputs
[i
])
4017 else if (primary
== -1 && strcmp (info
->name
, "LVDS") == 0)
4020 if (i
== primary
&& x_get_net_workarea (dpyinfo
, &workarea_r
))
4022 mi
->work
= workarea_r
;
4023 if (! x_intersect_rectangles (&mi
->geom
, &mi
->work
, &mi
->work
))
4024 mi
->work
= mi
->geom
;
4027 mi
->work
= mi
->geom
;
4029 XRRFreeCrtcInfo (crtc
);
4031 XRRFreeOutputInfo (info
);
4033 XRRFreeScreenResources (resources
);
4035 attributes_list
= x_make_monitor_attribute_list (monitors
,
4040 free_monitors (monitors
, n_monitors
);
4041 return attributes_list
;
4043 #endif /* HAVE_XRANDR */
4046 x_get_monitor_attributes (struct x_display_info
*dpyinfo
)
4048 Lisp_Object attributes_list
= Qnil
;
4049 Display
*dpy
= dpyinfo
->display
;
4051 (void) dpy
; /* Suppress unused variable warning. */
4054 int xrr_event_base
, xrr_error_base
;
4055 bool xrr_ok
= false;
4056 xrr_ok
= XRRQueryExtension (dpy
, &xrr_event_base
, &xrr_error_base
);
4059 int xrr_major
, xrr_minor
;
4060 XRRQueryVersion (dpy
, &xrr_major
, &xrr_minor
);
4061 xrr_ok
= (xrr_major
== 1 && xrr_minor
>= 2) || xrr_major
> 1;
4065 attributes_list
= x_get_monitor_attributes_xrandr (dpyinfo
);
4066 #endif /* HAVE_XRANDR */
4068 #ifdef HAVE_XINERAMA
4069 if (NILP (attributes_list
))
4071 int xin_event_base
, xin_error_base
;
4072 bool xin_ok
= false;
4073 xin_ok
= XineramaQueryExtension (dpy
, &xin_event_base
, &xin_error_base
);
4074 if (xin_ok
&& XineramaIsActive (dpy
))
4075 attributes_list
= x_get_monitor_attributes_xinerama (dpyinfo
);
4077 #endif /* HAVE_XINERAMA */
4079 if (NILP (attributes_list
))
4080 attributes_list
= x_get_monitor_attributes_fallback (dpyinfo
);
4082 return attributes_list
;
4085 #endif /* !USE_GTK */
4087 DEFUN ("x-display-monitor-attributes-list", Fx_display_monitor_attributes_list
,
4088 Sx_display_monitor_attributes_list
,
4090 doc
: /* Return a list of physical monitor attributes on the X display TERMINAL.
4092 The optional argument TERMINAL specifies which display to ask about.
4093 TERMINAL should be a terminal object, a frame or a display name (a string).
4094 If omitted or nil, that stands for the selected frame's display.
4096 In addition to the standard attribute keys listed in
4097 `display-monitor-attributes-list', the following keys are contained in
4100 source -- String describing the source from which multi-monitor
4101 information is obtained, one of \"Gdk\", \"XRandr\",
4102 \"Xinerama\", or \"fallback\"
4104 Internal use only, use `display-monitor-attributes-list' instead. */)
4105 (Lisp_Object terminal
)
4107 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4108 Lisp_Object attributes_list
= Qnil
;
4111 double mm_width_per_pixel
, mm_height_per_pixel
;
4114 gint primary_monitor
= 0, n_monitors
, i
;
4115 Lisp_Object monitor_frames
, rest
, frame
;
4116 static const char *source
= "Gdk";
4117 struct MonitorInfo
*monitors
;
4120 mm_width_per_pixel
= ((double) WidthMMOfScreen (dpyinfo
->screen
)
4121 / x_display_pixel_width (dpyinfo
));
4122 mm_height_per_pixel
= ((double) HeightMMOfScreen (dpyinfo
->screen
)
4123 / x_display_pixel_height (dpyinfo
));
4124 gdpy
= gdk_x11_lookup_xdisplay (dpyinfo
->display
);
4125 gscreen
= gdk_display_get_default_screen (gdpy
);
4126 #if GTK_CHECK_VERSION (2, 20, 0)
4127 primary_monitor
= gdk_screen_get_primary_monitor (gscreen
);
4129 n_monitors
= gdk_screen_get_n_monitors (gscreen
);
4130 monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
4131 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
4133 FOR_EACH_FRAME (rest
, frame
)
4135 struct frame
*f
= XFRAME (frame
);
4137 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
4138 && !EQ (frame
, tip_frame
))
4140 GdkWindow
*gwin
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
4142 i
= gdk_screen_get_monitor_at_window (gscreen
, gwin
);
4143 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
4147 for (i
= 0; i
< n_monitors
; ++i
)
4149 gint width_mm
= -1, height_mm
= -1;
4150 GdkRectangle rec
, work
;
4151 struct MonitorInfo
*mi
= &monitors
[i
];
4153 gdk_screen_get_monitor_geometry (gscreen
, i
, &rec
);
4155 #if GTK_CHECK_VERSION (2, 14, 0)
4156 width_mm
= gdk_screen_get_monitor_width_mm (gscreen
, i
);
4157 height_mm
= gdk_screen_get_monitor_height_mm (gscreen
, i
);
4160 width_mm
= rec
.width
* mm_width_per_pixel
+ 0.5;
4162 height_mm
= rec
.height
* mm_height_per_pixel
+ 0.5;
4164 #if GTK_CHECK_VERSION (3, 4, 0)
4165 gdk_screen_get_monitor_workarea (gscreen
, i
, &work
);
4167 /* Emulate the behavior of GTK+ 3.4. */
4169 XRectangle workarea_r
;
4171 if (i
== primary_monitor
&& x_get_net_workarea (dpyinfo
, &workarea_r
))
4173 work
.x
= workarea_r
.x
;
4174 work
.y
= workarea_r
.y
;
4175 work
.width
= workarea_r
.width
;
4176 work
.height
= workarea_r
.height
;
4177 if (! gdk_rectangle_intersect (&rec
, &work
, &work
))
4188 mi
->geom
.width
= rec
.width
;
4189 mi
->geom
.height
= rec
.height
;
4190 mi
->work
.x
= work
.x
;
4191 mi
->work
.y
= work
.y
;
4192 mi
->work
.width
= work
.width
;
4193 mi
->work
.height
= work
.height
;
4194 mi
->mm_width
= width_mm
;
4195 mi
->mm_height
= height_mm
;
4197 #if GTK_CHECK_VERSION (2, 14, 0)
4198 mi
->name
= gdk_screen_get_monitor_plug_name (gscreen
, i
);
4202 attributes_list
= make_monitor_attribute_list (monitors
,
4208 #else /* not USE_GTK */
4211 attributes_list
= x_get_monitor_attributes (dpyinfo
);
4214 #endif /* not USE_GTK */
4216 return attributes_list
;
4219 DEFUN ("x-frame-geometry", Fx_frame_geometry
, Sx_frame_geometry
, 0, 1, 0,
4220 doc
: /* Return geometric attributes of frame FRAME.
4222 FRAME must be a live frame and defaults to the selected one.
4224 The return value is an association list containing the following
4225 elements (all size values are in pixels).
4227 - `frame-outer-size' is a cons of the outer width and height of FRAME.
4228 The outer size include the title bar and the external borders as well
4229 as any menu and/or tool bar of frame.
4231 - `border' is a cons of the horizontal and vertical width of FRAME's
4234 - `title-bar-height' is the height of the title bar of FRAME.
4236 - `menu-bar-external' if `t' means the menu bar is external (not
4237 included in the inner edges of FRAME).
4239 - `menu-bar-size' is a cons of the width and height of the menu bar of
4242 - `tool-bar-external' if `t' means the tool bar is external (not
4243 included in the inner edges of FRAME).
4245 - `tool-bar-side' tells tells on which side the tool bar on FRAME is and
4246 can be one of `left', `top', `right' or `bottom'.
4248 - `tool-bar-size' is a cons of the width and height of the tool bar of
4251 - `frame-inner-size' is a cons of the inner width and height of FRAME.
4252 This excludes FRAME's title bar and external border as well as any
4253 external menu and/or tool bar. */)
4256 struct frame
*f
= decode_live_frame (frame
);
4257 int inner_width
= FRAME_PIXEL_WIDTH (f
);
4258 int inner_height
= FRAME_PIXEL_HEIGHT (f
);
4259 int outer_width
, outer_height
, border
, title
;
4260 Lisp_Object fullscreen
= Fframe_parameter (frame
, Qfullscreen
);
4261 int menu_bar_height
, menu_bar_width
, tool_bar_height
, tool_bar_width
;
4263 border
= FRAME_OUTER_TO_INNER_DIFF_X (f
);
4264 title
= FRAME_X_OUTPUT (f
)->y_pixels_outer_diff
- border
;
4266 outer_width
= FRAME_PIXEL_WIDTH (f
) + 2 * border
;
4267 outer_height
= (FRAME_PIXEL_HEIGHT (f
)
4268 + FRAME_OUTER_TO_INNER_DIFF_Y (f
)
4269 + FRAME_OUTER_TO_INNER_DIFF_X (f
));
4271 #if defined (USE_GTK)
4273 bool tool_bar_left_right
= (EQ (FRAME_TOOL_BAR_POSITION (f
), Qleft
)
4274 || EQ (FRAME_TOOL_BAR_POSITION (f
), Qright
));
4276 tool_bar_width
= (tool_bar_left_right
4277 ? FRAME_TOOLBAR_WIDTH (f
)
4278 : FRAME_PIXEL_WIDTH (f
));
4279 tool_bar_height
= (tool_bar_left_right
4280 ? FRAME_PIXEL_HEIGHT (f
)
4281 : FRAME_TOOLBAR_HEIGHT (f
));
4282 if (tool_bar_left_right
)
4283 /* For some reason FRAME_OUTER_TO_INNER_DIFF_X does not count the
4284 width of a tool bar. */
4285 outer_width
+= FRAME_TOOLBAR_WIDTH (f
);
4288 tool_bar_height
= FRAME_TOOL_BAR_HEIGHT (f
);
4289 tool_bar_width
= ((tool_bar_height
> 0)
4290 ? outer_width
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
)
4294 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
4295 menu_bar_height
= FRAME_MENUBAR_HEIGHT (f
);
4297 menu_bar_height
= FRAME_MENU_BAR_HEIGHT (f
);
4300 menu_bar_width
= ((menu_bar_height
> 0)
4301 ? outer_width
- 2 * border
4304 if (!FRAME_EXTERNAL_MENU_BAR (f
))
4305 inner_height
-= menu_bar_height
;
4306 if (!FRAME_EXTERNAL_TOOL_BAR (f
))
4307 inner_height
-= tool_bar_height
;
4310 listn (CONSTYPE_PURE
, 10,
4311 Fcons (Qframe_position
,
4312 Fcons (make_number (f
->left_pos
), make_number (f
->top_pos
))),
4313 Fcons (Qframe_outer_size
,
4314 Fcons (make_number (outer_width
), make_number (outer_height
))),
4315 Fcons (Qexternal_border_size
,
4316 ((EQ (fullscreen
, Qfullboth
) || EQ (fullscreen
, Qfullscreen
))
4317 ? Fcons (make_number (0), make_number (0))
4318 : Fcons (make_number (border
), make_number (border
)))),
4319 Fcons (Qtitle_height
,
4320 ((EQ (fullscreen
, Qfullboth
) || EQ (fullscreen
, Qfullscreen
))
4322 : make_number (title
))),
4323 Fcons (Qmenu_bar_external
, FRAME_EXTERNAL_MENU_BAR (f
) ? Qt
: Qnil
),
4324 Fcons (Qmenu_bar_size
,
4325 Fcons (make_number (menu_bar_width
),
4326 make_number (menu_bar_height
))),
4327 Fcons (Qtool_bar_external
, FRAME_EXTERNAL_TOOL_BAR (f
) ? Qt
: Qnil
),
4328 Fcons (Qtool_bar_position
, FRAME_TOOL_BAR_POSITION (f
)),
4329 Fcons (Qtool_bar_size
,
4330 Fcons (make_number (tool_bar_width
),
4331 make_number (tool_bar_height
))),
4332 Fcons (Qframe_inner_size
,
4333 Fcons (make_number (inner_width
),
4334 make_number (inner_height
))));
4337 /************************************************************************
4339 ************************************************************************/
4342 /* Mapping visual names to visuals. */
4344 static struct visual_class
4351 {"StaticGray", StaticGray
},
4352 {"GrayScale", GrayScale
},
4353 {"StaticColor", StaticColor
},
4354 {"PseudoColor", PseudoColor
},
4355 {"TrueColor", TrueColor
},
4356 {"DirectColor", DirectColor
},
4361 #ifndef HAVE_XSCREENNUMBEROFSCREEN
4363 /* Value is the screen number of screen SCR. This is a substitute for
4364 the X function with the same name when that doesn't exist. */
4367 XScreenNumberOfScreen (scr
)
4368 register Screen
*scr
;
4370 Display
*dpy
= scr
->display
;
4373 for (i
= 0; i
< dpy
->nscreens
; ++i
)
4374 if (scr
== dpy
->screens
+ i
)
4380 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
4383 /* Select the visual that should be used on display DPYINFO. Set
4384 members of DPYINFO appropriately. Called from x_term_init. */
4387 select_visual (struct x_display_info
*dpyinfo
)
4389 Display
*dpy
= dpyinfo
->display
;
4390 Screen
*screen
= dpyinfo
->screen
;
4392 /* See if a visual is specified. */
4393 AUTO_STRING (visualClass
, "visualClass");
4394 AUTO_STRING (VisualClass
, "VisualClass");
4395 Lisp_Object value
= display_x_get_resource (dpyinfo
, visualClass
,
4396 VisualClass
, Qnil
, Qnil
);
4398 if (STRINGP (value
))
4400 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
4401 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
4402 depth, a decimal number. NAME is compared with case ignored. */
4403 char *s
= alloca (SBYTES (value
) + 1);
4408 lispstpcpy (s
, value
);
4409 dash
= strchr (s
, '-');
4412 dpyinfo
->n_planes
= atoi (dash
+ 1);
4416 /* We won't find a matching visual with depth 0, so that
4417 an error will be printed below. */
4418 dpyinfo
->n_planes
= 0;
4420 /* Determine the visual class. */
4421 for (i
= 0; visual_classes
[i
].name
; ++i
)
4422 if (xstrcasecmp (s
, visual_classes
[i
].name
) == 0)
4424 class = visual_classes
[i
].class;
4428 /* Look up a matching visual for the specified class. */
4430 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
4431 dpyinfo
->n_planes
, class, &vinfo
))
4432 fatal ("Invalid visual specification `%s'", SDATA (value
));
4434 dpyinfo
->visual
= vinfo
.visual
;
4439 XVisualInfo
*vinfo
, vinfo_template
;
4441 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
4443 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
4444 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
4445 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
4446 &vinfo_template
, &n_visuals
);
4448 fatal ("Can't get proper X visual info");
4450 dpyinfo
->n_planes
= vinfo
->depth
;
4456 /* Return the X display structure for the display named NAME.
4457 Open a new connection if necessary. */
4459 static struct x_display_info
*
4460 x_display_info_for_name (Lisp_Object name
)
4462 struct x_display_info
*dpyinfo
;
4464 CHECK_STRING (name
);
4466 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
4467 if (!NILP (Fstring_equal (XCAR (dpyinfo
->name_list_element
), name
)))
4470 /* Use this general default value to start with. */
4471 Vx_resource_name
= Vinvocation_name
;
4473 validate_x_resource_name ();
4475 dpyinfo
= x_term_init (name
, 0, SSDATA (Vx_resource_name
));
4478 error ("Cannot connect to X server %s", SDATA (name
));
4480 XSETFASTINT (Vwindow_system_version
, 11);
4486 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4488 doc
: /* Open a connection to a display server.
4489 DISPLAY is the name of the display to connect to.
4490 Optional second arg XRM-STRING is a string of resources in xrdb format.
4491 If the optional third arg MUST-SUCCEED is non-nil,
4492 terminate Emacs if we can't open the connection.
4493 \(In the Nextstep version, the last two arguments are currently ignored.) */)
4494 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
4497 struct x_display_info
*dpyinfo
;
4499 CHECK_STRING (display
);
4500 if (! NILP (xrm_string
))
4501 CHECK_STRING (xrm_string
);
4503 xrm_option
= NILP (xrm_string
) ? 0 : SSDATA (xrm_string
);
4505 validate_x_resource_name ();
4507 /* This is what opens the connection and sets x_current_display.
4508 This also initializes many symbols, such as those used for input. */
4509 dpyinfo
= x_term_init (display
, xrm_option
,
4510 SSDATA (Vx_resource_name
));
4514 if (!NILP (must_succeed
))
4515 fatal ("Cannot connect to X server %s.\n\
4516 Check the DISPLAY environment variable or use `-d'.\n\
4517 Also use the `xauth' program to verify that you have the proper\n\
4518 authorization information needed to connect the X server.\n\
4519 An insecure way to solve the problem may be to use `xhost'.\n",
4522 error ("Cannot connect to X server %s", SDATA (display
));
4525 XSETFASTINT (Vwindow_system_version
, 11);
4529 DEFUN ("x-close-connection", Fx_close_connection
,
4530 Sx_close_connection
, 1, 1, 0,
4531 doc
: /* Close the connection to TERMINAL's X server.
4532 For TERMINAL, specify a terminal object, a frame or a display name (a
4533 string). If TERMINAL is nil, that stands for the selected frame's
4535 (Lisp_Object terminal
)
4537 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4539 if (dpyinfo
->reference_count
> 0)
4540 error ("Display still has frames on it");
4542 x_delete_terminal (dpyinfo
->terminal
);
4547 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4548 doc
: /* Return the list of display names that Emacs has connections to. */)
4551 Lisp_Object result
= Qnil
;
4552 struct x_display_info
*xdi
;
4554 for (xdi
= x_display_list
; xdi
; xdi
= xdi
->next
)
4555 result
= Fcons (XCAR (xdi
->name_list_element
), result
);
4560 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4561 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
4562 This function only has an effect on X Windows. With MS Windows, it is
4563 defined but does nothing.
4565 If ON is nil, allow buffering of requests.
4566 Turning on synchronization prohibits the Xlib routines from buffering
4567 requests and seriously degrades performance, but makes debugging much
4569 The optional second argument TERMINAL specifies which display to act on.
4570 TERMINAL should be a terminal object, a frame or a display name (a string).
4571 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
4572 (Lisp_Object on
, Lisp_Object terminal
)
4574 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4576 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
4581 /* Wait for responses to all X commands issued so far for frame F. */
4584 x_sync (struct frame
*f
)
4587 XSync (FRAME_X_DISPLAY (f
), False
);
4592 /***********************************************************************
4594 ***********************************************************************/
4596 DEFUN ("x-change-window-property", Fx_change_window_property
,
4597 Sx_change_window_property
, 2, 6, 0,
4598 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
4599 PROP must be a string. VALUE may be a string or a list of conses,
4600 numbers and/or strings. If an element in the list is a string, it is
4601 converted to an atom and the value of the atom is used. If an element
4602 is a cons, it is converted to a 32 bit number where the car is the 16
4603 top bits and the cdr is the lower 16 bits.
4605 FRAME nil or omitted means use the selected frame.
4606 If TYPE is given and non-nil, it is the name of the type of VALUE.
4607 If TYPE is not given or nil, the type is STRING.
4608 FORMAT gives the size in bits of each element if VALUE is a list.
4609 It must be one of 8, 16 or 32.
4610 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4611 If OUTER-P is non-nil, the property is changed for the outer X window of
4612 FRAME. Default is to change on the edit X window. */)
4613 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
,
4614 Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
4616 struct frame
*f
= decode_window_system_frame (frame
);
4618 Atom target_type
= XA_STRING
;
4619 int element_format
= 8;
4620 unsigned char *data
;
4624 CHECK_STRING (prop
);
4626 if (! NILP (format
))
4628 CHECK_NUMBER (format
);
4630 if (XINT (format
) != 8 && XINT (format
) != 16
4631 && XINT (format
) != 32)
4632 error ("FORMAT must be one of 8, 16 or 32");
4633 element_format
= XINT (format
);
4640 nelements
= x_check_property_data (value
);
4641 if (nelements
== -1)
4642 error ("Bad data in VALUE, must be number, string or cons");
4644 /* The man page for XChangeProperty:
4645 "If the specified format is 32, the property data must be a
4647 This applies even if long is more than 32 bits. The X library
4648 converts to 32 bits before sending to the X server. */
4649 elsize
= element_format
== 32 ? sizeof (long) : element_format
>> 3;
4650 data
= xnmalloc (nelements
, elsize
);
4652 x_fill_property_data (FRAME_X_DISPLAY (f
), value
, data
, element_format
);
4656 CHECK_STRING (value
);
4657 data
= SDATA (value
);
4658 if (INT_MAX
< SBYTES (value
))
4659 error ("VALUE too long");
4660 nelements
= SBYTES (value
);
4664 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4667 CHECK_STRING (type
);
4668 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
4671 if (! NILP (outer_p
)) w
= FRAME_OUTER_WINDOW (f
);
4672 else w
= FRAME_X_WINDOW (f
);
4674 XChangeProperty (FRAME_X_DISPLAY (f
), w
,
4675 prop_atom
, target_type
, element_format
, PropModeReplace
,
4678 if (CONSP (value
)) xfree (data
);
4680 /* Make sure the property is set when we return. */
4681 XFlush (FRAME_X_DISPLAY (f
));
4688 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
4689 Sx_delete_window_property
, 1, 2, 0,
4690 doc
: /* Remove window property PROP from X window of FRAME.
4691 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4692 (Lisp_Object prop
, Lisp_Object frame
)
4694 struct frame
*f
= decode_window_system_frame (frame
);
4697 CHECK_STRING (prop
);
4699 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4700 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
4702 /* Make sure the property is removed when we return. */
4703 XFlush (FRAME_X_DISPLAY (f
));
4711 x_window_property_intern (struct frame
*f
,
4712 Window target_window
,
4715 Lisp_Object delete_p
,
4716 Lisp_Object vector_ret_p
,
4719 unsigned char *tmp_data
= NULL
;
4720 Lisp_Object prop_value
= Qnil
;
4723 unsigned long actual_size
, bytes_remaining
;
4725 struct gcpro gcpro1
;
4727 GCPRO1 (prop_value
);
4729 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4730 prop_atom
, 0, 0, False
, target_type
,
4731 &actual_type
, &actual_format
, &actual_size
,
4732 &bytes_remaining
, &tmp_data
);
4734 *found
= actual_format
!= 0;
4736 if (rc
== Success
&& *found
)
4741 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4742 prop_atom
, 0, bytes_remaining
,
4743 ! NILP (delete_p
), target_type
,
4744 &actual_type
, &actual_format
,
4745 &actual_size
, &bytes_remaining
,
4747 if (rc
== Success
&& tmp_data
)
4749 /* The man page for XGetWindowProperty says:
4750 "If the returned format is 32, the returned data is represented
4751 as a long array and should be cast to that type to obtain the
4753 This applies even if long is more than 32 bits, the X library
4754 converts from 32 bit elements received from the X server to long
4755 and passes the long array to us. Thus, for that case memcpy can not
4756 be used. We convert to a 32 bit type here, because so much code
4759 The bytes and offsets passed to XGetWindowProperty refers to the
4760 property and those are indeed in 32 bit quantities if format is
4763 if (BITS_PER_LONG
> 32 && actual_format
== 32)
4766 int *idata
= (int *) tmp_data
;
4767 long *ldata
= (long *) tmp_data
;
4769 for (i
= 0; i
< actual_size
; ++i
)
4770 idata
[i
] = (int) ldata
[i
];
4773 if (NILP (vector_ret_p
))
4774 prop_value
= make_string ((char *) tmp_data
, actual_size
);
4776 prop_value
= x_property_data_to_lisp (f
,
4783 if (tmp_data
) XFree (tmp_data
);
4790 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
4792 doc
: /* Value is the value of window property PROP on FRAME.
4793 If FRAME is nil or omitted, use the selected frame.
4795 On X Windows, the following optional arguments are also accepted:
4796 If TYPE is nil or omitted, get the property as a string.
4797 Otherwise TYPE is the name of the atom that denotes the type expected.
4798 If SOURCE is non-nil, get the property on that window instead of from
4799 FRAME. The number 0 denotes the root window.
4800 If DELETE-P is non-nil, delete the property after retrieving it.
4801 If VECTOR-RET-P is non-nil, don't return a string but a vector of values.
4803 On MS Windows, this function accepts but ignores those optional arguments.
4805 Value is nil if FRAME hasn't a property with name PROP or if PROP has
4806 no value of TYPE (always string in the MS Windows case). */)
4807 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
,
4808 Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
4810 struct frame
*f
= decode_window_system_frame (frame
);
4812 Lisp_Object prop_value
= Qnil
;
4813 Atom target_type
= XA_STRING
;
4814 Window target_window
= FRAME_X_WINDOW (f
);
4815 struct gcpro gcpro1
;
4818 GCPRO1 (prop_value
);
4819 CHECK_STRING (prop
);
4821 if (! NILP (source
))
4823 CONS_TO_INTEGER (source
, Window
, target_window
);
4824 if (! target_window
)
4825 target_window
= FRAME_DISPLAY_INFO (f
)->root_window
;
4831 if (strcmp ("AnyPropertyType", SSDATA (type
)) == 0)
4832 target_type
= AnyPropertyType
;
4834 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
4837 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4838 prop_value
= x_window_property_intern (f
,
4845 if (NILP (prop_value
)
4848 && target_window
!= FRAME_OUTER_WINDOW (f
))
4850 prop_value
= x_window_property_intern (f
,
4851 FRAME_OUTER_WINDOW (f
),
4865 /***********************************************************************
4867 ***********************************************************************/
4869 static Lisp_Object
x_create_tip_frame (struct x_display_info
*,
4870 Lisp_Object
, Lisp_Object
);
4871 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
4872 Lisp_Object
, int, int, int *, int *);
4874 /* The frame of a currently visible tooltip. */
4876 Lisp_Object tip_frame
;
4878 /* If non-nil, a timer started that hides the last tooltip when it
4881 static Lisp_Object tip_timer
;
4884 /* If non-nil, a vector of 3 elements containing the last args
4885 with which x-show-tip was called. See there. */
4887 static Lisp_Object last_show_tip_args
;
4891 unwind_create_tip_frame (Lisp_Object frame
)
4893 Lisp_Object deleted
;
4895 deleted
= unwind_create_frame (frame
);
4896 if (EQ (deleted
, Qt
))
4904 /* Create a frame for a tooltip on the display described by DPYINFO.
4905 PARMS is a list of frame parameters. TEXT is the string to
4906 display in the tip frame. Value is the frame.
4908 Note that functions called here, esp. x_default_parameter can
4909 signal errors, for instance when a specified color name is
4910 undefined. We have to make sure that we're in a consistent state
4911 when this happens. */
4914 x_create_tip_frame (struct x_display_info
*dpyinfo
,
4922 ptrdiff_t count
= SPECPDL_INDEX ();
4923 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4924 int face_change_count_before
= face_change_count
;
4926 struct buffer
*old_buffer
;
4928 if (!dpyinfo
->terminal
->name
)
4929 error ("Terminal is not live, can't create new frames on it");
4931 parms
= Fcopy_alist (parms
);
4933 /* Get the name of the frame to use for resource lookup. */
4934 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
4936 && !EQ (name
, Qunbound
)
4938 error ("Invalid frame name--not a string or nil");
4941 GCPRO3 (parms
, name
, frame
);
4942 f
= make_frame (true);
4943 XSETFRAME (frame
, f
);
4945 AUTO_STRING (tip
, " *tip*");
4946 buffer
= Fget_buffer_create (tip
);
4947 /* Use set_window_buffer instead of Fset_window_buffer (see
4948 discussion of bug#11984, bug#12025, bug#12026). */
4949 set_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, false, false);
4950 old_buffer
= current_buffer
;
4951 set_buffer_internal_1 (XBUFFER (buffer
));
4952 bset_truncate_lines (current_buffer
, Qnil
);
4953 specbind (Qinhibit_read_only
, Qt
);
4954 specbind (Qinhibit_modification_hooks
, Qt
);
4957 set_buffer_internal_1 (old_buffer
);
4959 record_unwind_protect (unwind_create_tip_frame
, frame
);
4961 f
->terminal
= dpyinfo
->terminal
;
4963 /* By setting the output method, we're essentially saying that
4964 the frame is live, as per FRAME_LIVE_P. If we get a signal
4965 from this point on, x_destroy_window might screw up reference
4967 f
->output_method
= output_x_window
;
4968 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
4969 f
->output_data
.x
->icon_bitmap
= -1;
4970 FRAME_FONTSET (f
) = -1;
4971 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
4972 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
4973 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
4974 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
4975 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
4976 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
4977 f
->output_data
.x
->white_relief
.pixel
= -1;
4978 f
->output_data
.x
->black_relief
.pixel
= -1;
4980 fset_icon_name (f
, Qnil
);
4981 FRAME_DISPLAY_INFO (f
) = dpyinfo
;
4982 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
4983 f
->output_data
.x
->explicit_parent
= false;
4985 /* These colors will be set anyway later, but it's important
4986 to get the color reference counts right, so initialize them! */
4989 struct gcpro gcpro1
;
4991 /* Function x_decode_color can signal an error. Make
4992 sure to initialize color slots so that we won't try
4993 to free colors we haven't allocated. */
4994 FRAME_FOREGROUND_PIXEL (f
) = -1;
4995 FRAME_BACKGROUND_PIXEL (f
) = -1;
4996 f
->output_data
.x
->cursor_pixel
= -1;
4997 f
->output_data
.x
->cursor_foreground_pixel
= -1;
4998 f
->output_data
.x
->border_pixel
= -1;
4999 f
->output_data
.x
->mouse_pixel
= -1;
5001 black
= build_string ("black");
5003 FRAME_FOREGROUND_PIXEL (f
)
5004 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5005 FRAME_BACKGROUND_PIXEL (f
)
5006 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5007 f
->output_data
.x
->cursor_pixel
5008 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5009 f
->output_data
.x
->cursor_foreground_pixel
5010 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5011 f
->output_data
.x
->border_pixel
5012 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5013 f
->output_data
.x
->mouse_pixel
5014 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5018 /* Set the name; the functions to which we pass f expect the name to
5020 if (EQ (name
, Qunbound
) || NILP (name
))
5022 fset_name (f
, build_string (dpyinfo
->x_id_name
));
5023 f
->explicit_name
= false;
5027 fset_name (f
, name
);
5028 f
->explicit_name
= true;
5029 /* use the frame's title when getting resources for this frame. */
5030 specbind (Qx_resource_name
, name
);
5033 register_font_driver (&xfont_driver
, f
);
5034 #ifdef HAVE_FREETYPE
5036 register_font_driver (&xftfont_driver
, f
);
5037 #else /* not HAVE_XFT */
5038 register_font_driver (&ftxfont_driver
, f
);
5039 #endif /* not HAVE_XFT */
5040 #endif /* HAVE_FREETYPE */
5042 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5043 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5045 /* Extract the window parameters from the supplied values that are
5046 needed to determine window geometry. */
5047 x_default_font_parameter (f
, parms
);
5049 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
5050 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5052 /* This defaults to 2 in order to match xterm. We recognize either
5053 internalBorderWidth or internalBorder (which is what xterm calls
5055 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5059 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5060 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5061 if (! EQ (value
, Qunbound
))
5062 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5066 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5067 "internalBorderWidth", "internalBorderWidth",
5069 x_default_parameter (f
, parms
, Qright_divider_width
, make_number (0),
5070 NULL
, NULL
, RES_TYPE_NUMBER
);
5071 x_default_parameter (f
, parms
, Qbottom_divider_width
, make_number (0),
5072 NULL
, NULL
, RES_TYPE_NUMBER
);
5074 /* Also do the stuff which must be set before the window exists. */
5075 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5076 "foreground", "Foreground", RES_TYPE_STRING
);
5077 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5078 "background", "Background", RES_TYPE_STRING
);
5079 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5080 "pointerColor", "Foreground", RES_TYPE_STRING
);
5081 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5082 "cursorColor", "Foreground", RES_TYPE_STRING
);
5083 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5084 "borderColor", "BorderColor", RES_TYPE_STRING
);
5087 image_cache_refcount
=
5088 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
5089 dpyinfo_refcount
= dpyinfo
->reference_count
;
5090 #endif /* GLYPH_DEBUG */
5092 /* Init faces before x_default_parameter is called for the
5093 scroll-bar-width parameter because otherwise we end up in
5094 init_iterator with a null face cache, which should not happen. */
5095 init_frame_faces (f
);
5097 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5099 x_figure_window_size (f
, parms
, false);
5102 XSetWindowAttributes attrs
;
5104 Atom type
= FRAME_DISPLAY_INFO (f
)->Xatom_net_window_type_tooltip
;
5107 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
;
5108 if (DoesSaveUnders (dpyinfo
->screen
))
5109 mask
|= CWSaveUnder
;
5111 /* Window managers look at the override-redirect flag to determine
5112 whether or net to give windows a decoration (Xlib spec, chapter
5114 attrs
.override_redirect
= True
;
5115 attrs
.save_under
= True
;
5116 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
5117 /* Arrange for getting MapNotify and UnmapNotify events. */
5118 attrs
.event_mask
= StructureNotifyMask
;
5120 = FRAME_X_WINDOW (f
)
5121 = XCreateWindow (FRAME_X_DISPLAY (f
),
5122 FRAME_DISPLAY_INFO (f
)->root_window
,
5123 /* x, y, width, height */
5127 CopyFromParent
, InputOutput
, CopyFromParent
,
5129 XChangeProperty (FRAME_X_DISPLAY (f
), tip_window
,
5130 FRAME_DISPLAY_INFO (f
)->Xatom_net_window_type
,
5131 XA_ATOM
, 32, PropModeReplace
,
5132 (unsigned char *)&type
, 1);
5138 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5139 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5140 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5141 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5142 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5143 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5145 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
5146 Change will not be effected unless different from the current
5148 width
= FRAME_COLS (f
);
5149 height
= FRAME_LINES (f
);
5150 SET_FRAME_COLS (f
, 0);
5151 SET_FRAME_LINES (f
, 0);
5152 change_frame_size (f
, width
, height
, true, false, false, false);
5154 /* Add `tooltip' frame parameter's default value. */
5155 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5157 AUTO_FRAME_ARG (arg
, Qtooltip
, Qt
);
5158 Fmodify_frame_parameters (frame
, arg
);
5161 /* FIXME - can this be done in a similar way to normal frames?
5162 http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00641.html */
5164 /* Set the `display-type' frame parameter before setting up faces. */
5166 Lisp_Object disptype
;
5168 if (FRAME_DISPLAY_INFO (f
)->n_planes
== 1)
5169 disptype
= intern ("mono");
5170 else if (FRAME_DISPLAY_INFO (f
)->visual
->class == GrayScale
5171 || FRAME_DISPLAY_INFO (f
)->visual
->class == StaticGray
)
5172 disptype
= intern ("grayscale");
5174 disptype
= intern ("color");
5176 if (NILP (Fframe_parameter (frame
, Qdisplay_type
)))
5178 AUTO_FRAME_ARG (arg
, Qdisplay_type
, disptype
);
5179 Fmodify_frame_parameters (frame
, arg
);
5183 /* Set up faces after all frame parameters are known. This call
5184 also merges in face attributes specified for new frames.
5186 Frame parameters may be changed if .Xdefaults contains
5187 specifications for the default font. For example, if there is an
5188 `Emacs.default.attributeBackground: pink', the `background-color'
5189 attribute of the frame get's set, which let's the internal border
5190 of the tooltip frame appear in pink. Prevent this. */
5192 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5194 /* Set tip_frame here, so that */
5196 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5198 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5200 AUTO_FRAME_ARG (arg
, Qbackground_color
, bg
);
5201 Fmodify_frame_parameters (frame
, arg
);
5209 /* Now that the frame will be official, it counts as a reference to
5210 its display and terminal. */
5211 FRAME_DISPLAY_INFO (f
)->reference_count
++;
5212 f
->terminal
->reference_count
++;
5214 /* It is now ok to make the frame official even if we get an error
5215 below. And the frame needs to be on Vframe_list or making it
5216 visible won't work. */
5217 Vframe_list
= Fcons (frame
, Vframe_list
);
5218 f
->can_x_set_window_size
= true;
5220 /* Setting attributes of faces of the tooltip frame from resources
5221 and similar will increment face_change_count, which leads to the
5222 clearing of all current matrices. Since this isn't necessary
5223 here, avoid it by resetting face_change_count to the value it
5224 had before we created the tip frame. */
5225 face_change_count
= face_change_count_before
;
5227 /* Discard the unwind_protect. */
5228 return unbind_to (count
, frame
);
5232 /* Compute where to display tip frame F. PARMS is the list of frame
5233 parameters for F. DX and DY are specified offsets from the current
5234 location of the mouse. WIDTH and HEIGHT are the width and height
5235 of the tooltip. Return coordinates relative to the root window of
5236 the display in *ROOT_X, and *ROOT_Y. */
5239 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
)
5241 Lisp_Object left
, top
;
5246 /* User-specified position? */
5247 left
= Fcdr (Fassq (Qleft
, parms
));
5248 top
= Fcdr (Fassq (Qtop
, parms
));
5250 /* Move the tooltip window where the mouse pointer is. Resize and
5252 if (!INTEGERP (left
) || !INTEGERP (top
))
5255 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_DISPLAY_INFO (f
)->root_window
,
5256 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
5261 *root_y
= XINT (top
);
5262 else if (*root_y
+ XINT (dy
) <= 0)
5263 *root_y
= 0; /* Can happen for negative dy */
5264 else if (*root_y
+ XINT (dy
) + height
5265 <= x_display_pixel_height (FRAME_DISPLAY_INFO (f
)))
5266 /* It fits below the pointer */
5267 *root_y
+= XINT (dy
);
5268 else if (height
+ XINT (dy
) <= *root_y
)
5269 /* It fits above the pointer. */
5270 *root_y
-= height
+ XINT (dy
);
5272 /* Put it on the top. */
5275 if (INTEGERP (left
))
5276 *root_x
= XINT (left
);
5277 else if (*root_x
+ XINT (dx
) <= 0)
5278 *root_x
= 0; /* Can happen for negative dx */
5279 else if (*root_x
+ XINT (dx
) + width
5280 <= x_display_pixel_width (FRAME_DISPLAY_INFO (f
)))
5281 /* It fits to the right of the pointer. */
5282 *root_x
+= XINT (dx
);
5283 else if (width
+ XINT (dx
) <= *root_x
)
5284 /* It fits to the left of the pointer. */
5285 *root_x
-= width
+ XINT (dx
);
5287 /* Put it left-justified on the screen--it ought to fit that way. */
5292 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5293 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
5294 A tooltip window is a small X window displaying a string.
5296 This is an internal function; Lisp code should call `tooltip-show'.
5298 FRAME nil or omitted means use the selected frame.
5300 PARMS is an optional list of frame parameters which can be used to
5301 change the tooltip's appearance.
5303 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5304 means use the default timeout of 5 seconds.
5306 If the list of frame parameters PARMS contains a `left' parameters,
5307 the tooltip is displayed at that x-position. Otherwise it is
5308 displayed at the mouse position, with offset DX added (default is 5 if
5309 DX isn't specified). Likewise for the y-position; if a `top' frame
5310 parameter is specified, it determines the y-position of the tooltip
5311 window, otherwise it is displayed at the mouse position, with offset
5312 DY added (default is -10).
5314 A tooltip's maximum size is specified by `x-max-tooltip-size'.
5315 Text larger than the specified size is clipped. */)
5316 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
5321 struct buffer
*old_buffer
;
5322 struct text_pos pos
;
5323 int i
, width
, height
;
5324 bool seen_reversed_p
;
5325 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5326 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5327 ptrdiff_t count
= SPECPDL_INDEX ();
5329 specbind (Qinhibit_redisplay
, Qt
);
5331 GCPRO4 (string
, parms
, frame
, timeout
);
5333 CHECK_STRING (string
);
5334 if (SCHARS (string
) == 0)
5335 string
= make_unibyte_string (" ", 1);
5337 f
= decode_window_system_frame (frame
);
5339 timeout
= make_number (5);
5341 CHECK_NATNUM (timeout
);
5344 dx
= make_number (5);
5349 dy
= make_number (-10);
5354 if (x_gtk_use_system_tooltips
)
5358 /* Hide a previous tip, if any. */
5362 ok
= xg_prepare_tooltip (f
, string
, &width
, &height
);
5365 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5366 xg_show_tooltip (f
, root_x
, root_y
);
5367 /* This is used in Fx_hide_tip. */
5368 XSETFRAME (tip_frame
, f
);
5371 if (ok
) goto start_timer
;
5373 #endif /* USE_GTK */
5375 if (NILP (last_show_tip_args
))
5376 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5378 if (!NILP (tip_frame
))
5380 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5381 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5382 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5384 if (EQ (frame
, last_frame
)
5385 && !NILP (Fequal (last_string
, string
))
5386 && !NILP (Fequal (last_parms
, parms
)))
5388 struct frame
*tip_f
= XFRAME (tip_frame
);
5390 /* Only DX and DY have changed. */
5391 if (!NILP (tip_timer
))
5393 Lisp_Object timer
= tip_timer
;
5395 call1 (Qcancel_timer
, timer
);
5399 compute_tip_xy (tip_f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (tip_f
),
5400 FRAME_PIXEL_HEIGHT (tip_f
), &root_x
, &root_y
);
5401 XMoveWindow (FRAME_X_DISPLAY (tip_f
), FRAME_X_WINDOW (tip_f
),
5408 /* Hide a previous tip, if any. */
5411 ASET (last_show_tip_args
, 0, string
);
5412 ASET (last_show_tip_args
, 1, frame
);
5413 ASET (last_show_tip_args
, 2, parms
);
5415 /* Add default values to frame parameters. */
5416 if (NILP (Fassq (Qname
, parms
)))
5417 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5418 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5419 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5420 if (NILP (Fassq (Qborder_width
, parms
)))
5421 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5422 if (NILP (Fassq (Qbottom_divider_width
, parms
)))
5423 parms
= Fcons (Fcons (Qbottom_divider_width
, make_number (0)), parms
);
5424 if (NILP (Fassq (Qright_divider_width
, parms
)))
5425 parms
= Fcons (Fcons (Qright_divider_width
, make_number (0)), parms
);
5426 if (NILP (Fassq (Qborder_color
, parms
)))
5427 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5428 if (NILP (Fassq (Qbackground_color
, parms
)))
5429 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5432 /* Create a frame for the tooltip, and record it in the global
5433 variable tip_frame. */
5434 frame
= x_create_tip_frame (FRAME_DISPLAY_INFO (f
), parms
, string
);
5437 /* Set up the frame's root window. */
5438 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5444 if (CONSP (Vx_max_tooltip_size
)
5445 && RANGED_INTEGERP (1, XCAR (Vx_max_tooltip_size
), INT_MAX
)
5446 && RANGED_INTEGERP (1, XCDR (Vx_max_tooltip_size
), INT_MAX
))
5448 w
->total_cols
= XFASTINT (XCAR (Vx_max_tooltip_size
));
5449 w
->total_lines
= XFASTINT (XCDR (Vx_max_tooltip_size
));
5454 w
->total_lines
= 40;
5457 w
->pixel_width
= w
->total_cols
* FRAME_COLUMN_WIDTH (f
);
5458 w
->pixel_height
= w
->total_lines
* FRAME_LINE_HEIGHT (f
);
5460 FRAME_TOTAL_COLS (f
) = w
->total_cols
;
5461 adjust_frame_glyphs (f
);
5462 w
->pseudo_window_p
= true;
5464 /* Display the tooltip text in a temporary buffer. */
5465 old_buffer
= current_buffer
;
5466 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->contents
));
5467 bset_truncate_lines (current_buffer
, Qnil
);
5468 clear_glyph_matrix (w
->desired_matrix
);
5469 clear_glyph_matrix (w
->current_matrix
);
5470 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5471 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5473 /* Compute width and height of the tooltip. */
5475 seen_reversed_p
= false;
5476 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5478 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5482 /* Stop at the first empty row at the end. */
5483 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5486 /* Let the row go over the full width of the frame. */
5487 row
->full_width_p
= true;
5489 row_width
= row
->pixel_width
;
5490 if (row
->used
[TEXT_AREA
])
5492 /* There's a glyph at the end of rows that is used to place
5493 the cursor there. Don't include the width of this glyph. */
5494 if (!row
->reversed_p
)
5496 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5497 if (NILP (last
->object
))
5498 row_width
-= last
->pixel_width
;
5502 /* There could be a stretch glyph at the beginning of R2L
5503 rows that is produced by extend_face_to_end_of_line.
5504 Don't count that glyph. */
5505 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
5507 if (g
->type
== STRETCH_GLYPH
&& NILP (g
->object
))
5509 row_width
-= g
->pixel_width
;
5510 seen_reversed_p
= true;
5515 height
+= row
->height
;
5516 width
= max (width
, row_width
);
5519 /* If we've seen partial-length R2L rows, we need to re-adjust the
5520 tool-tip frame width and redisplay it again, to avoid over-wide
5521 tips due to the stretch glyph that extends R2L lines to full
5522 width of the frame. */
5523 if (seen_reversed_p
)
5525 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns,
5527 w
->pixel_width
= width
;
5528 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
5529 w
->total_cols
= width
;
5530 FRAME_TOTAL_COLS (f
) = width
;
5531 SET_FRAME_WIDTH (f
, width
);
5532 adjust_frame_glyphs (f
);
5533 clear_glyph_matrix (w
->desired_matrix
);
5534 clear_glyph_matrix (w
->current_matrix
);
5535 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
5537 /* Recompute width and height of the tooltip. */
5538 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5540 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5544 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5546 row
->full_width_p
= true;
5547 row_width
= row
->pixel_width
;
5548 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
5550 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5551 if (NILP (last
->object
))
5552 row_width
-= last
->pixel_width
;
5555 height
+= row
->height
;
5556 width
= max (width
, row_width
);
5560 /* Add the frame's internal border to the width and height the X
5561 window should have. */
5562 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5563 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5565 /* Move the tooltip window where the mouse pointer is. Resize and
5567 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5570 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5571 root_x
, root_y
, width
, height
);
5572 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5575 /* Draw into the window. */
5576 w
->must_be_updated_p
= true;
5577 update_single_window (w
);
5579 /* Restore original current buffer. */
5580 set_buffer_internal_1 (old_buffer
);
5581 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5584 /* Let the tip disappear after timeout seconds. */
5585 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5586 intern ("x-hide-tip"));
5589 return unbind_to (count
, Qnil
);
5593 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5594 doc
: /* Hide the current tooltip window, if there is any.
5595 Value is t if tooltip was open, nil otherwise. */)
5599 Lisp_Object deleted
, frame
, timer
;
5600 struct gcpro gcpro1
, gcpro2
;
5602 /* Return quickly if nothing to do. */
5603 if (NILP (tip_timer
) && NILP (tip_frame
))
5608 GCPRO2 (frame
, timer
);
5609 tip_frame
= tip_timer
= deleted
= Qnil
;
5611 count
= SPECPDL_INDEX ();
5612 specbind (Qinhibit_redisplay
, Qt
);
5613 specbind (Qinhibit_quit
, Qt
);
5616 call1 (Qcancel_timer
, timer
);
5620 /* When using system tooltip, tip_frame is the Emacs frame on which
5621 the tip is shown. */
5622 struct frame
*f
= XFRAME (frame
);
5623 if (FRAME_LIVE_P (f
) && xg_hide_tooltip (f
))
5630 delete_frame (frame
, Qnil
);
5634 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5635 redisplay procedure is not called when a tip frame over menu
5636 items is unmapped. Redisplay the menu manually... */
5639 struct frame
*f
= SELECTED_FRAME ();
5640 w
= f
->output_data
.x
->menubar_widget
;
5642 if (!DoesSaveUnders (FRAME_DISPLAY_INFO (f
)->screen
)
5646 xlwmenu_redisplay (w
);
5650 #endif /* USE_LUCID */
5654 return unbind_to (count
, deleted
);
5659 /***********************************************************************
5660 File selection dialog
5661 ***********************************************************************/
5663 DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog
,
5664 Sx_uses_old_gtk_dialog
,
5666 doc
: /* Return t if the old Gtk+ file selection dialog is used. */)
5672 && window_system_available (SELECTED_FRAME ())
5673 && xg_uses_old_file_dialog ())
5681 /* Callback for "OK" and "Cancel" on file selection dialog. */
5684 file_dialog_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5686 int *result
= client_data
;
5687 XmAnyCallbackStruct
*cb
= call_data
;
5688 *result
= cb
->reason
;
5692 /* Callback for unmapping a file selection dialog. This is used to
5693 capture the case where a dialog is closed via a window manager's
5694 closer button, for example. Using a XmNdestroyCallback didn't work
5698 file_dialog_unmap_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5700 int *result
= client_data
;
5701 *result
= XmCR_CANCEL
;
5705 clean_up_file_dialog (void *arg
)
5707 Widget dialog
= arg
;
5711 XtUnmanageChild (dialog
);
5712 XtDestroyWidget (dialog
);
5713 x_menu_set_in_use (false);
5718 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5719 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5720 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5721 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5722 or directory must exist.
5724 This function is only defined on NS, MS Windows, and X Windows with the
5725 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5726 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.
5727 On Windows 7 and later, the file selection dialog "remembers" the last
5728 directory where the user selected a file, and will open that directory
5729 instead of DIR on subsequent invocations of this function with the same
5730 value of DIR as in previous invocations; this is standard Windows behavior. */)
5731 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
,
5732 Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5735 struct frame
*f
= SELECTED_FRAME ();
5736 Lisp_Object file
= Qnil
;
5737 Lisp_Object decoded_file
;
5738 Widget dialog
, text
, help
;
5741 XmString dir_xmstring
, pattern_xmstring
;
5742 ptrdiff_t count
= SPECPDL_INDEX ();
5743 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5745 check_window_system (f
);
5747 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5749 if (popup_activated ())
5750 error ("Trying to use a menu from within a menu-entry");
5752 CHECK_STRING (prompt
);
5755 /* Prevent redisplay. */
5756 specbind (Qinhibit_redisplay
, Qt
);
5760 /* Create the dialog with PROMPT as title, using DIR as initial
5761 directory and using "*" as pattern. */
5762 dir
= Fexpand_file_name (dir
, Qnil
);
5763 dir_xmstring
= XmStringCreateLocalized (SSDATA (dir
));
5764 pattern_xmstring
= XmStringCreateLocalized ("*");
5766 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
5767 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
5768 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
5769 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
5770 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
5771 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
5773 XmStringFree (dir_xmstring
);
5774 XmStringFree (pattern_xmstring
);
5776 /* Add callbacks for OK and Cancel. */
5777 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
5778 (XtPointer
) &result
);
5779 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
5780 (XtPointer
) &result
);
5781 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
5782 (XtPointer
) &result
);
5784 /* Remove the help button since we can't display help. */
5785 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
5786 XtUnmanageChild (help
);
5788 /* Mark OK button as default. */
5789 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
5790 XmNshowAsDefault
, True
, NULL
);
5792 /* If MUSTMATCH is non-nil, disable the file entry field of the
5793 dialog, so that the user must select a file from the files list
5794 box. We can't remove it because we wouldn't have a way to get at
5795 the result file name, then. */
5796 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5797 if (!NILP (mustmatch
))
5800 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
5801 XtSetSensitive (text
, False
);
5802 XtSetSensitive (label
, False
);
5805 /* Manage the dialog, so that list boxes get filled. */
5806 XtManageChild (dialog
);
5808 if (STRINGP (default_filename
))
5810 XmString default_xmstring
;
5811 Widget wtext
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5812 Widget list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
5814 XmTextPosition last_pos
= XmTextFieldGetLastPosition (wtext
);
5815 XmTextFieldReplace (wtext
, 0, last_pos
,
5816 (SSDATA (Ffile_name_nondirectory (default_filename
))));
5818 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5819 must include the path for this to work. */
5821 default_xmstring
= XmStringCreateLocalized (SSDATA (default_filename
));
5823 if (XmListItemExists (list
, default_xmstring
))
5825 int item_pos
= XmListItemPos (list
, default_xmstring
);
5826 /* Select the item and scroll it into view. */
5827 XmListSelectPos (list
, item_pos
, True
);
5828 XmListSetPos (list
, item_pos
);
5831 XmStringFree (default_xmstring
);
5834 record_unwind_protect_ptr (clean_up_file_dialog
, dialog
);
5836 /* Process events until the user presses Cancel or OK. */
5837 x_menu_set_in_use (true);
5842 x_menu_wait_for_event (0);
5843 XtAppNextEvent (Xt_app_con
, &event
);
5844 if (event
.type
== KeyPress
5845 && FRAME_X_DISPLAY (f
) == event
.xkey
.display
)
5847 KeySym keysym
= XLookupKeysym (&event
.xkey
, 0);
5849 /* Pop down on C-g. */
5850 if (keysym
== XK_g
&& (event
.xkey
.state
& ControlMask
) != 0)
5851 XtUnmanageChild (dialog
);
5854 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
));
5857 /* Get the result. */
5858 if (result
== XmCR_OK
)
5860 XmString text_string
;
5863 XtVaGetValues (dialog
, XmNtextString
, &text_string
, NULL
);
5864 XmStringGetLtoR (text_string
, XmFONTLIST_DEFAULT_TAG
, &data
);
5865 XmStringFree (text_string
);
5866 file
= build_string (data
);
5875 /* Make "Cancel" equivalent to C-g. */
5877 Fsignal (Qquit
, Qnil
);
5879 decoded_file
= DECODE_FILE (file
);
5881 return unbind_to (count
, decoded_file
);
5884 #endif /* USE_MOTIF */
5889 clean_up_dialog (void)
5891 x_menu_set_in_use (false);
5894 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5895 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5896 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5897 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5898 or directory must exist.
5900 This function is only defined on NS, MS Windows, and X Windows with the
5901 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5902 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.
5903 On Windows 7 and later, the file selection dialog "remembers" the last
5904 directory where the user selected a file, and will open that directory
5905 instead of DIR on subsequent invocations of this function with the same
5906 value of DIR as in previous invocations; this is standard Windows behavior. */)
5907 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5909 struct frame
*f
= SELECTED_FRAME ();
5911 Lisp_Object file
= Qnil
;
5912 Lisp_Object decoded_file
;
5913 ptrdiff_t count
= SPECPDL_INDEX ();
5914 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5917 check_window_system (f
);
5919 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5921 if (popup_activated ())
5922 error ("Trying to use a menu from within a menu-entry");
5924 CHECK_STRING (prompt
);
5927 /* Prevent redisplay. */
5928 specbind (Qinhibit_redisplay
, Qt
);
5929 record_unwind_protect_void (clean_up_dialog
);
5933 if (STRINGP (default_filename
))
5934 cdef_file
= SSDATA (default_filename
);
5936 cdef_file
= SSDATA (dir
);
5938 fn
= xg_get_file_name (f
, SSDATA (prompt
), cdef_file
,
5940 ! NILP (only_dir_p
));
5944 file
= build_string (fn
);
5951 /* Make "Cancel" equivalent to C-g. */
5953 Fsignal (Qquit
, Qnil
);
5955 decoded_file
= DECODE_FILE (file
);
5957 return unbind_to (count
, decoded_file
);
5961 #ifdef HAVE_FREETYPE
5963 DEFUN ("x-select-font", Fx_select_font
, Sx_select_font
, 0, 2, 0,
5964 doc
: /* Read a font using a GTK dialog.
5965 Return either a font spec (for GTK versions >= 3.2) or a string
5966 containing a GTK-style font name.
5968 FRAME is the frame on which to pop up the font chooser. If omitted or
5969 nil, it defaults to the selected frame. */)
5970 (Lisp_Object frame
, Lisp_Object ignored
)
5972 struct frame
*f
= decode_window_system_frame (frame
);
5974 Lisp_Object font_param
;
5975 char *default_name
= NULL
;
5976 struct gcpro gcpro1
, gcpro2
;
5977 ptrdiff_t count
= SPECPDL_INDEX ();
5979 if (popup_activated ())
5980 error ("Trying to use a menu from within a menu-entry");
5982 /* Prevent redisplay. */
5983 specbind (Qinhibit_redisplay
, Qt
);
5984 record_unwind_protect_void (clean_up_dialog
);
5988 GCPRO2 (font_param
, font
);
5990 XSETFONT (font
, FRAME_FONT (f
));
5991 font_param
= Ffont_get (font
, intern (":name"));
5992 if (STRINGP (font_param
))
5993 default_name
= xlispstrdup (font_param
);
5996 font_param
= Fframe_parameter (frame
, Qfont_param
);
5997 if (STRINGP (font_param
))
5998 default_name
= xlispstrdup (font_param
);
6001 font
= xg_get_font (f
, default_name
);
6002 xfree (default_name
);
6007 Fsignal (Qquit
, Qnil
);
6009 return unbind_to (count
, font
);
6011 #endif /* HAVE_FREETYPE */
6013 #endif /* USE_GTK */
6016 /***********************************************************************
6018 ***********************************************************************/
6021 #include <X11/XKBlib.h>
6022 #include <X11/keysym.h>
6025 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
6026 Sx_backspace_delete_keys_p
, 0, 1, 0,
6027 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
6028 FRAME nil means use the selected frame.
6029 Value is t if we know that both keys are present, and are mapped to the
6030 usual X keysyms. Value is `lambda' if we cannot determine if both keys are
6031 present and mapped to the usual X keysyms. */)
6038 struct frame
*f
= decode_window_system_frame (frame
);
6039 Display
*dpy
= FRAME_X_DISPLAY (f
);
6040 Lisp_Object have_keys
;
6041 int major
, minor
, op
, event
, error_code
;
6045 /* Check library version in case we're dynamically linked. */
6046 major
= XkbMajorVersion
;
6047 minor
= XkbMinorVersion
;
6048 if (!XkbLibraryVersion (&major
, &minor
))
6054 /* Check that the server supports XKB. */
6055 major
= XkbMajorVersion
;
6056 minor
= XkbMinorVersion
;
6057 if (!XkbQueryExtension (dpy
, &op
, &event
, &error_code
, &major
, &minor
))
6063 /* In this code we check that the keyboard has physical keys with names
6064 that start with BKSP (Backspace) and DELE (Delete), and that they
6065 generate keysym XK_BackSpace and XK_Delete respectively.
6066 This function is used to test if normal-erase-is-backspace should be
6068 An alternative approach would be to just check if XK_BackSpace and
6069 XK_Delete are mapped to any key. But if any of those are mapped to
6070 some non-intuitive key combination (Meta-Shift-Ctrl-whatever) and the
6071 user doesn't know about it, it is better to return false here.
6072 It is more obvious to the user what to do if she/he has two keys
6073 clearly marked with names/symbols and one key does something not
6074 expected (i.e. she/he then tries the other).
6075 The cases where Backspace/Delete is mapped to some other key combination
6076 are rare, and in those cases, normal-erase-is-backspace can be turned on
6080 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
6083 int delete_keycode
= 0, backspace_keycode
= 0, i
;
6085 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
6087 for (i
= kb
->min_key_code
;
6088 (i
< kb
->max_key_code
6089 && (delete_keycode
== 0 || backspace_keycode
== 0));
6092 /* The XKB symbolic key names can be seen most easily in
6093 the PS file generated by `xkbprint -label name
6095 if (memcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
6097 else if (memcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
6098 backspace_keycode
= i
;
6101 XkbFreeNames (kb
, 0, True
);
6104 /* As of libX11-1.6.2, XkbGetMap manual says that you should use
6105 XkbFreeClientMap to free the data returned by XkbGetMap. But
6106 this function just frees the data referenced from KB and not
6107 KB itself. To free KB as well, call XkbFreeKeyboard. */
6108 XkbFreeKeyboard (kb
, XkbAllMapComponentsMask
, True
);
6111 && backspace_keycode
6112 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
6113 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
6123 /***********************************************************************
6125 ***********************************************************************/
6127 /* Keep this list in the same order as frame_parms in frame.c.
6128 Use 0 for unsupported frame parameters. */
6130 frame_parm_handler x_frame_parm_handlers
[] =
6134 x_set_background_color
,
6140 x_set_foreground_color
,
6143 x_set_internal_border_width
,
6144 x_set_right_divider_width
,
6145 x_set_bottom_divider_width
,
6146 x_set_menu_bar_lines
,
6148 x_explicitly_set_name
,
6149 x_set_scroll_bar_width
,
6150 x_set_scroll_bar_height
,
6153 x_set_vertical_scroll_bars
,
6154 x_set_horizontal_scroll_bars
,
6156 x_set_tool_bar_lines
,
6157 x_set_scroll_bar_foreground
,
6158 x_set_scroll_bar_background
,
6168 x_set_tool_bar_position
,
6174 DEFSYM (Qundefined_color
, "undefined-color");
6175 DEFSYM (Qcompound_text
, "compound-text");
6176 DEFSYM (Qcancel_timer
, "cancel-timer");
6177 DEFSYM (Qfont_param
, "font-parameter");
6179 Fput (Qundefined_color
, Qerror_conditions
,
6180 listn (CONSTYPE_PURE
, 2, Qundefined_color
, Qerror
));
6181 Fput (Qundefined_color
, Qerror_message
,
6182 build_pure_c_string ("Undefined color"));
6184 DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape
,
6185 doc
: /* The shape of the pointer when over text.
6186 Changing the value does not affect existing frames
6187 unless you set the mouse color. */);
6188 Vx_pointer_shape
= Qnil
;
6190 #if false /* This doesn't really do anything. */
6191 DEFVAR_LISP ("x-nontext-pointer-shape", Vx_nontext_pointer_shape
,
6192 doc
: /* The shape of the pointer when not over text.
6193 This variable takes effect when you create a new frame
6194 or when you set the mouse color. */);
6196 Vx_nontext_pointer_shape
= Qnil
;
6198 DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape
,
6199 doc
: /* The shape of the pointer when Emacs is busy.
6200 This variable takes effect when you create a new frame
6201 or when you set the mouse color. */);
6202 Vx_hourglass_pointer_shape
= Qnil
;
6204 #if false /* This doesn't really do anything. */
6205 DEFVAR_LISP ("x-mode-pointer-shape", Vx_mode_pointer_shape
,
6206 doc
: /* The shape of the pointer when over the mode line.
6207 This variable takes effect when you create a new frame
6208 or when you set the mouse color. */);
6210 Vx_mode_pointer_shape
= Qnil
;
6212 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
6213 Vx_sensitive_text_pointer_shape
,
6214 doc
: /* The shape of the pointer when over mouse-sensitive text.
6215 This variable takes effect when you create a new frame
6216 or when you set the mouse color. */);
6217 Vx_sensitive_text_pointer_shape
= Qnil
;
6219 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
6220 Vx_window_horizontal_drag_shape
,
6221 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
6222 This variable takes effect when you create a new frame
6223 or when you set the mouse color. */);
6224 Vx_window_horizontal_drag_shape
= Qnil
;
6226 DEFVAR_LISP ("x-window-vertical-drag-cursor",
6227 Vx_window_vertical_drag_shape
,
6228 doc
: /* Pointer shape to use for indicating a window can be dragged vertically.
6229 This variable takes effect when you create a new frame
6230 or when you set the mouse color. */);
6231 Vx_window_vertical_drag_shape
= Qnil
;
6233 DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel
,
6234 doc
: /* A string indicating the foreground color of the cursor box. */);
6235 Vx_cursor_fore_pixel
= Qnil
;
6237 DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size
,
6238 doc
: /* Maximum size for tooltips.
6239 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
6240 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
6242 DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager
,
6243 doc
: /* Non-nil if no X window manager is in use.
6244 Emacs doesn't try to figure this out; this is always nil
6245 unless you set it to something else. */);
6246 /* We don't have any way to find this out, so set it to nil
6247 and maybe the user would like to set it to t. */
6248 Vx_no_window_manager
= Qnil
;
6250 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
6251 Vx_pixel_size_width_font_regexp
,
6252 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
6254 Since Emacs gets width of a font matching with this regexp from
6255 PIXEL_SIZE field of the name, font finding mechanism gets faster for
6256 such a font. This is especially effective for such large fonts as
6257 Chinese, Japanese, and Korean. */);
6258 Vx_pixel_size_width_font_regexp
= Qnil
;
6260 /* This is not ifdef:ed, so other builds than GTK can customize it. */
6261 DEFVAR_BOOL ("x-gtk-use-old-file-dialog", x_gtk_use_old_file_dialog
,
6262 doc
: /* Non-nil means prompt with the old GTK file selection dialog.
6263 If nil or if the file selection dialog is not available, the new GTK file
6264 chooser is used instead. To turn off all file dialogs set the
6265 variable `use-file-dialog'. */);
6266 x_gtk_use_old_file_dialog
= false;
6268 DEFVAR_BOOL ("x-gtk-show-hidden-files", x_gtk_show_hidden_files
,
6269 doc
: /* If non-nil, the GTK file chooser will by default show hidden files.
6270 Note that this is just the default, there is a toggle button on the file
6271 chooser to show or not show hidden files on a case by case basis. */);
6272 x_gtk_show_hidden_files
= false;
6274 DEFVAR_BOOL ("x-gtk-file-dialog-help-text", x_gtk_file_dialog_help_text
,
6275 doc
: /* If non-nil, the GTK file chooser will show additional help text.
6276 If more space for files in the file chooser dialog is wanted, set this to nil
6277 to turn the additional text off. */);
6278 x_gtk_file_dialog_help_text
= true;
6280 DEFVAR_BOOL ("x-gtk-use-system-tooltips", x_gtk_use_system_tooltips
,
6281 doc
: /* If non-nil with a Gtk+ built Emacs, the Gtk+ tooltip is used.
6282 Otherwise use Emacs own tooltip implementation.
6283 When using Gtk+ tooltips, the tooltip face is not used. */);
6284 x_gtk_use_system_tooltips
= true;
6286 /* Tell Emacs about this window system. */
6287 Fprovide (Qx
, Qnil
);
6289 #ifdef USE_X_TOOLKIT
6290 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
6292 Fprovide (intern_c_string ("motif"), Qnil
);
6294 DEFVAR_LISP ("motif-version-string", Vmotif_version_string
,
6295 doc
: /* Version info for LessTif/Motif. */);
6296 Vmotif_version_string
= build_string (XmVERSION_STRING
);
6297 #endif /* USE_MOTIF */
6298 #endif /* USE_X_TOOLKIT */
6301 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
6302 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
6303 But for a user it is a toolkit for X, and indeed, configure
6304 accepts --with-x-toolkit=gtk. */
6305 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
6306 Fprovide (intern_c_string ("gtk"), Qnil
);
6307 Fprovide (intern_c_string ("move-toolbar"), Qnil
);
6309 DEFVAR_LISP ("gtk-version-string", Vgtk_version_string
,
6310 doc
: /* Version info for GTK+. */);
6312 char gtk_version
[sizeof ".." + 3 * INT_STRLEN_BOUND (int)];
6313 int len
= sprintf (gtk_version
, "%d.%d.%d",
6314 GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
);
6315 Vgtk_version_string
= make_pure_string (gtk_version
, len
, len
, false);
6317 #endif /* USE_GTK */
6319 /* X window properties. */
6320 defsubr (&Sx_change_window_property
);
6321 defsubr (&Sx_delete_window_property
);
6322 defsubr (&Sx_window_property
);
6324 defsubr (&Sxw_display_color_p
);
6325 defsubr (&Sx_display_grayscale_p
);
6326 defsubr (&Sxw_color_defined_p
);
6327 defsubr (&Sxw_color_values
);
6328 defsubr (&Sx_server_max_request_size
);
6329 defsubr (&Sx_server_vendor
);
6330 defsubr (&Sx_server_version
);
6331 defsubr (&Sx_display_pixel_width
);
6332 defsubr (&Sx_display_pixel_height
);
6333 defsubr (&Sx_display_mm_width
);
6334 defsubr (&Sx_display_mm_height
);
6335 defsubr (&Sx_display_screens
);
6336 defsubr (&Sx_display_planes
);
6337 defsubr (&Sx_display_color_cells
);
6338 defsubr (&Sx_display_visual_class
);
6339 defsubr (&Sx_display_backing_store
);
6340 defsubr (&Sx_display_save_under
);
6341 defsubr (&Sx_display_monitor_attributes_list
);
6342 defsubr (&Sx_frame_geometry
);
6343 defsubr (&Sx_wm_set_size_hint
);
6344 defsubr (&Sx_create_frame
);
6345 defsubr (&Sx_open_connection
);
6346 defsubr (&Sx_close_connection
);
6347 defsubr (&Sx_display_list
);
6348 defsubr (&Sx_synchronize
);
6349 defsubr (&Sx_backspace_delete_keys_p
);
6351 defsubr (&Sx_show_tip
);
6352 defsubr (&Sx_hide_tip
);
6354 staticpro (&tip_timer
);
6356 staticpro (&tip_frame
);
6358 last_show_tip_args
= Qnil
;
6359 staticpro (&last_show_tip_args
);
6361 defsubr (&Sx_uses_old_gtk_dialog
);
6362 #if defined (USE_MOTIF) || defined (USE_GTK)
6363 defsubr (&Sx_file_dialog
);
6366 #if defined (USE_GTK) && defined (HAVE_FREETYPE)
6367 defsubr (&Sx_select_font
);