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
;
1098 Lisp_Object fullscreen
;
1100 /* Make sure we redisplay all windows in this frame. */
1101 windows_or_buffers_changed
= 60;
1104 /* Recalculate tool bar and frame text sizes. */
1105 FRAME_TOOL_BAR_HEIGHT (f
) = height
;
1106 FRAME_TOOL_BAR_LINES (f
) = lines
;
1107 /* Store the `tool-bar-lines' and `height' frame parameters. */
1108 store_frame_param (f
, Qtool_bar_lines
, make_number (lines
));
1109 store_frame_param (f
, Qheight
, make_number (FRAME_LINES (f
)));
1111 /* We also have to make sure that the internal border at the top of
1112 the frame, below the menu bar or tool bar, is redrawn when the
1113 tool bar disappears. This is so because the internal border is
1114 below the tool bar if one is displayed, but is below the menu bar
1115 if there isn't a tool bar. The tool bar draws into the area
1116 below the menu bar. */
1117 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_HEIGHT (f
) == 0)
1120 clear_current_matrices (f
);
1123 if ((height
< old_height
) && WINDOWP (f
->tool_bar_window
))
1124 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1126 /* Recalculate toolbar height. */
1127 f
->n_tool_bar_rows
= 0;
1129 adjust_frame_size (f
, -1, -1,
1130 ((!f
->tool_bar_redisplayed_once
1131 && (NILP (fullscreen
=
1132 get_frame_param (f
, Qfullscreen
))
1133 || EQ (fullscreen
, Qfullwidth
))) ? 1
1134 : (old_height
== 0 || height
== 0) ? 2
1136 false, Qtool_bar_lines
);
1138 /* adjust_frame_size might not have done anything, garbage frame
1140 adjust_frame_glyphs (f
);
1141 SET_FRAME_GARBAGED (f
);
1142 if (FRAME_X_WINDOW (f
))
1143 x_clear_under_internal_border (f
);
1145 #endif /* USE_GTK */
1150 x_set_internal_border_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1154 CHECK_TYPE_RANGED_INTEGER (int, arg
);
1155 border
= max (XINT (arg
), 0);
1157 if (border
!= FRAME_INTERNAL_BORDER_WIDTH (f
))
1159 FRAME_INTERNAL_BORDER_WIDTH (f
) = border
;
1161 #ifdef USE_X_TOOLKIT
1162 if (FRAME_X_OUTPUT (f
)->edit_widget
)
1163 widget_store_internal_border (FRAME_X_OUTPUT (f
)->edit_widget
);
1166 if (FRAME_X_WINDOW (f
) != 0)
1168 adjust_frame_size (f
, -1, -1, 3, false, Qinternal_border_width
);
1171 xg_clear_under_internal_border (f
);
1173 x_clear_under_internal_border (f
);
1181 /* Set the foreground color for scroll bars on frame F to VALUE.
1182 VALUE should be a string, a color name. If it isn't a string or
1183 isn't a valid color name, do nothing. OLDVAL is the old value of
1184 the frame parameter. */
1187 x_set_scroll_bar_foreground (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1189 unsigned long pixel
;
1191 if (STRINGP (value
))
1192 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
1196 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
1197 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
1199 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
1200 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1202 /* Remove all scroll bars because they have wrong colors. */
1203 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1204 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1205 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1206 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1208 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
1214 /* Set the background color for scroll bars on frame F to VALUE VALUE
1215 should be a string, a color name. If it isn't a string or isn't a
1216 valid color name, do nothing. OLDVAL is the old value of the frame
1220 x_set_scroll_bar_background (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1222 unsigned long pixel
;
1224 if (STRINGP (value
))
1225 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
1229 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
1230 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
1232 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
1233 /* Scrollbar shadow colors. */
1234 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
1236 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
1237 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
1239 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
1241 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
1242 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
1244 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
1246 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
1247 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1249 /* Remove all scroll bars because they have wrong colors. */
1250 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1251 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1252 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1253 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1255 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
1261 /* Encode Lisp string STRING as a text in a format appropriate for
1262 XICCC (X Inter Client Communication Conventions).
1264 This can call Lisp code, so callers must GCPRO.
1266 If STRING contains only ASCII characters, do no conversion and
1267 return the string data of STRING. Otherwise, encode the text by
1268 CODING_SYSTEM, and return a newly allocated memory area which
1269 should be freed by `xfree' by a caller.
1271 Store the byte length of resulting text in *TEXT_BYTES.
1273 If the text contains only ASCII and Latin-1, store true in *STRING_P,
1274 which means that the `encoding' of the result can be `STRING'.
1275 Otherwise store false in *STRINGP, which means that the `encoding' of
1276 the result should be `COMPOUND_TEXT'. */
1278 static unsigned char *
1279 x_encode_text (Lisp_Object string
, Lisp_Object coding_system
,
1280 ptrdiff_t *text_bytes
, bool *stringp
, bool *freep
)
1282 int result
= string_xstring_p (string
);
1283 struct coding_system coding
;
1287 /* No multibyte character in OBJ. We need not encode it. */
1288 *text_bytes
= SBYTES (string
);
1291 return SDATA (string
);
1294 setup_coding_system (coding_system
, &coding
);
1295 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
1296 /* We suppress producing escape sequences for composition. */
1297 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
1298 coding
.destination
= xnmalloc (SCHARS (string
), 2);
1299 coding
.dst_bytes
= SCHARS (string
) * 2;
1300 encode_coding_object (&coding
, string
, 0, 0,
1301 SCHARS (string
), SBYTES (string
), Qnil
);
1302 *text_bytes
= coding
.produced
;
1303 *stringp
= (result
== 1 || !EQ (coding_system
, Qcompound_text
));
1305 return coding
.destination
;
1309 /* Set the WM name to NAME for frame F. Also set the icon name.
1310 If the frame already has an icon name, use that, otherwise set the
1311 icon name to NAME. */
1314 x_set_name_internal (struct frame
*f
, Lisp_Object name
)
1316 if (FRAME_X_WINDOW (f
))
1320 XTextProperty text
, icon
;
1323 bool do_free_icon_value
= false, do_free_text_value
= false;
1324 Lisp_Object coding_system
;
1325 Lisp_Object encoded_name
;
1326 Lisp_Object encoded_icon_name
;
1327 struct gcpro gcpro1
;
1329 /* As ENCODE_UTF_8 may cause GC and relocation of string data,
1330 we use it before x_encode_text that may return string data. */
1332 encoded_name
= ENCODE_UTF_8 (name
);
1335 coding_system
= Qcompound_text
;
1336 /* Note: Encoding strategy
1338 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1339 text.encoding. But, there are non-internationalized window
1340 managers which don't support that encoding. So, if NAME
1341 contains only ASCII and 8859-1 characters, encode it by
1342 iso-latin-1, and use "STRING" in text.encoding hoping that
1343 such window managers at least analyze this format correctly,
1344 i.e. treat 8-bit bytes as 8859-1 characters.
1346 We may also be able to use "UTF8_STRING" in text.encoding
1347 in the future which can encode all Unicode characters.
1348 But, for the moment, there's no way to know that the
1349 current window manager supports it or not.
1351 Either way, we also set the _NET_WM_NAME and _NET_WM_ICON_NAME
1352 properties. Per the EWMH specification, those two properties
1353 are always UTF8_STRING. This matches what gtk_window_set_title()
1354 does in the USE_GTK case. */
1355 text
.value
= x_encode_text (name
, coding_system
, &bytes
,
1356 &stringp
, &do_free_text_value
);
1357 text
.encoding
= (stringp
? XA_STRING
1358 : FRAME_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1360 text
.nitems
= bytes
;
1362 if (!STRINGP (f
->icon_name
))
1365 encoded_icon_name
= encoded_name
;
1369 /* See the above comment "Note: Encoding strategy". */
1370 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, &bytes
,
1371 &stringp
, &do_free_icon_value
);
1372 icon
.encoding
= (stringp
? XA_STRING
1373 : FRAME_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1375 icon
.nitems
= bytes
;
1377 encoded_icon_name
= ENCODE_UTF_8 (f
->icon_name
);
1381 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1382 SSDATA (encoded_name
));
1383 #else /* not USE_GTK */
1384 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1385 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1386 FRAME_DISPLAY_INFO (f
)->Xatom_net_wm_name
,
1387 FRAME_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1389 SDATA (encoded_name
),
1390 SBYTES (encoded_name
));
1391 #endif /* not USE_GTK */
1393 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &icon
);
1394 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1395 FRAME_DISPLAY_INFO (f
)->Xatom_net_wm_icon_name
,
1396 FRAME_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1398 SDATA (encoded_icon_name
),
1399 SBYTES (encoded_icon_name
));
1401 if (do_free_icon_value
)
1403 if (do_free_text_value
)
1410 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1413 If EXPLICIT is true, that indicates that lisp code is setting the
1414 name; if NAME is a string, set F's name to NAME and set
1415 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1417 If EXPLICIT is false, that indicates that Emacs redisplay code is
1418 suggesting a new name, which lisp code should override; if
1419 F->explicit_name is set, ignore the new name; otherwise, set it. */
1422 x_set_name (struct frame
*f
, Lisp_Object name
, bool explicit)
1424 /* Make sure that requests from lisp code override requests from
1425 Emacs redisplay code. */
1428 /* If we're switching from explicit to implicit, we had better
1429 update the mode lines and thereby update the title. */
1430 if (f
->explicit_name
&& NILP (name
))
1431 update_mode_lines
= 37;
1433 f
->explicit_name
= ! NILP (name
);
1435 else if (f
->explicit_name
)
1438 /* If NAME is nil, set the name to the x_id_name. */
1441 /* Check for no change needed in this very common case
1442 before we do any consing. */
1443 if (!strcmp (FRAME_DISPLAY_INFO (f
)->x_id_name
,
1446 name
= build_string (FRAME_DISPLAY_INFO (f
)->x_id_name
);
1449 CHECK_STRING (name
);
1451 /* Don't change the name if it's already NAME. */
1452 if (! NILP (Fstring_equal (name
, f
->name
)))
1455 fset_name (f
, name
);
1457 /* For setting the frame title, the title parameter should override
1458 the name parameter. */
1459 if (! NILP (f
->title
))
1462 x_set_name_internal (f
, name
);
1465 /* This function should be called when the user's lisp code has
1466 specified a name for the frame; the name will override any set by the
1469 x_explicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1471 x_set_name (f
, arg
, true);
1474 /* This function should be called by Emacs redisplay code to set the
1475 name; names set this way will never override names set by the user's
1478 x_implicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1480 x_set_name (f
, arg
, false);
1483 /* Change the title of frame F to NAME.
1484 If NAME is nil, use the frame name as the title. */
1487 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1489 /* Don't change the title if it's already NAME. */
1490 if (EQ (name
, f
->title
))
1493 update_mode_lines
= 38;
1495 fset_title (f
, name
);
1500 CHECK_STRING (name
);
1502 x_set_name_internal (f
, name
);
1506 x_set_scroll_bar_default_width (struct frame
*f
)
1508 int unit
= FRAME_COLUMN_WIDTH (f
);
1509 #ifdef USE_TOOLKIT_SCROLL_BARS
1511 int minw
= xg_get_default_scrollbar_width ();
1515 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1516 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (minw
+ unit
- 1) / unit
;
1517 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = minw
;
1519 /* The width of a non-toolkit scrollbar is 14 pixels. */
1520 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + unit
- 1) / unit
;
1521 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
)
1522 = FRAME_CONFIG_SCROLL_BAR_COLS (f
) * unit
;
1527 x_set_scroll_bar_default_height (struct frame
*f
)
1529 int height
= FRAME_LINE_HEIGHT (f
);
1530 #ifdef USE_TOOLKIT_SCROLL_BARS
1532 int min_height
= xg_get_default_scrollbar_height ();
1534 int min_height
= 16;
1536 /* A minimum height of 14 doesn't look good for toolkit scroll bars. */
1537 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) = min_height
;
1538 FRAME_CONFIG_SCROLL_BAR_LINES (f
) = (min_height
+ height
- 1) / height
;
1540 /* The height of a non-toolkit scrollbar is 14 pixels. */
1541 FRAME_CONFIG_SCROLL_BAR_LINES (f
) = (14 + height
- 1) / height
;
1543 /* Use all of that space (aside from required margins) for the
1545 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) = 14;
1550 /* Record in frame F the specified or default value according to ALIST
1551 of the parameter named PROP (a Lisp symbol). If no value is
1552 specified for PROP, look for an X default for XPROP on the frame
1553 named NAME. If that is not found either, use the value DEFLT. */
1556 x_default_scroll_bar_color_parameter (struct frame
*f
,
1557 Lisp_Object alist
, Lisp_Object prop
,
1558 const char *xprop
, const char *xclass
,
1561 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1564 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
1565 if (EQ (tem
, Qunbound
))
1567 #ifdef USE_TOOLKIT_SCROLL_BARS
1569 /* See if an X resource for the scroll bar color has been
1571 AUTO_STRING (foreground
, "foreground");
1572 AUTO_STRING (background
, "foreground");
1573 AUTO_STRING (verticalScrollBar
, "verticalScrollBar");
1574 tem
= (display_x_get_resource
1575 (dpyinfo
, foreground_p
? foreground
: background
,
1576 empty_unibyte_string
,
1578 empty_unibyte_string
));
1581 /* If nothing has been specified, scroll bars will use a
1582 toolkit-dependent default. Because these defaults are
1583 difficult to get at without actually creating a scroll
1584 bar, use nil to indicate that no color has been
1589 #else /* not USE_TOOLKIT_SCROLL_BARS */
1593 #endif /* not USE_TOOLKIT_SCROLL_BARS */
1596 AUTO_FRAME_ARG (arg
, prop
, tem
);
1597 x_set_frame_parameters (f
, arg
);
1604 #ifdef USE_X_TOOLKIT
1606 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
1607 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
1608 already be present because of the toolkit (Motif adds some of them,
1609 for example, but Xt doesn't). */
1612 hack_wm_protocols (struct frame
*f
, Widget widget
)
1614 Display
*dpy
= XtDisplay (widget
);
1615 Window w
= XtWindow (widget
);
1616 bool need_delete
= true;
1617 bool need_focus
= true;
1618 bool need_save
= true;
1623 unsigned char *catoms
;
1625 unsigned long nitems
= 0;
1626 unsigned long bytes_after
;
1628 if ((XGetWindowProperty (dpy
, w
,
1629 FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1630 0, 100, False
, XA_ATOM
,
1631 &type
, &format
, &nitems
, &bytes_after
,
1634 && format
== 32 && type
== XA_ATOM
)
1636 Atom
*atoms
= (Atom
*) catoms
;
1641 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
1642 need_delete
= false;
1643 else if (atoms
[nitems
]
1644 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
1646 else if (atoms
[nitems
]
1647 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
1658 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
1660 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
1662 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
1664 XChangeProperty (dpy
, w
, FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1665 XA_ATOM
, 32, PropModeAppend
,
1666 (unsigned char *) props
, count
);
1674 /* Support routines for XIC (X Input Context). */
1678 static XFontSet
xic_create_xfontset (struct frame
*);
1679 static XIMStyle
best_xim_style (XIMStyles
*);
1682 /* Supported XIM styles, ordered by preference. */
1684 static const XIMStyle supported_xim_styles
[] =
1686 XIMPreeditPosition
| XIMStatusArea
,
1687 XIMPreeditPosition
| XIMStatusNothing
,
1688 XIMPreeditPosition
| XIMStatusNone
,
1689 XIMPreeditNothing
| XIMStatusArea
,
1690 XIMPreeditNothing
| XIMStatusNothing
,
1691 XIMPreeditNothing
| XIMStatusNone
,
1692 XIMPreeditNone
| XIMStatusArea
,
1693 XIMPreeditNone
| XIMStatusNothing
,
1694 XIMPreeditNone
| XIMStatusNone
,
1699 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1700 /* Create an X fontset on frame F with base font name BASE_FONTNAME. */
1702 static const char xic_default_fontset
[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
1704 /* Create an Xt fontset spec from the name of a base font.
1705 If `motif' is True use the Motif syntax. */
1707 xic_create_fontsetname (const char *base_fontname
, bool motif
)
1709 const char *sep
= motif
? ";" : ",";
1713 /* Make a fontset name from the base font name. */
1714 if (xic_default_fontset
== base_fontname
)
1716 /* There is no base font name, use the default. */
1717 fontsetname
= xmalloc (strlen (base_fontname
) + 2);
1718 z
= stpcpy (fontsetname
, base_fontname
);
1722 /* Make a fontset name from the base font name.
1723 The font set will be made of the following elements:
1725 - the base font where the charset spec is replaced by -*-*.
1726 - the same but with the family also replaced with -*-*-. */
1727 const char *p
= base_fontname
;
1730 for (i
= 0; *p
; p
++)
1734 /* As the font name doesn't conform to XLFD, we can't
1735 modify it to generalize it to allcs and allfamilies.
1736 Use the specified font plus the default. */
1737 fontsetname
= xmalloc (strlen (base_fontname
)
1738 + strlen (xic_default_fontset
) + 3);
1739 z
= stpcpy (fontsetname
, base_fontname
);
1740 z
= stpcpy (z
, sep
);
1741 z
= stpcpy (z
, xic_default_fontset
);
1746 const char *p1
= NULL
, *p2
= NULL
, *p3
= NULL
;
1747 char *font_allcs
= NULL
;
1748 char *font_allfamilies
= NULL
;
1749 char *font_all
= NULL
;
1750 const char *allcs
= "*-*-*-*-*-*-*";
1751 const char *allfamilies
= "-*-*-";
1752 const char *all
= "*-*-*-*-";
1755 for (i
= 0, p
= base_fontname
; i
< 8; p
++)
1768 /* If base_fontname specifies ADSTYLE, make it a
1772 ptrdiff_t diff
= (p2
- p3
) - 2;
1774 base
= alloca (strlen (base_fontname
) + 1);
1775 memcpy (base
, base_fontname
, p3
- base_fontname
);
1776 base
[p3
- base_fontname
] = '*';
1777 base
[(p3
- base_fontname
) + 1] = '-';
1778 strcpy (base
+ (p3
- base_fontname
) + 2, p2
);
1779 p
= base
+ (p
- base_fontname
) - diff
;
1780 p1
= base
+ (p1
- base_fontname
);
1781 p2
= base
+ (p2
- base_fontname
) - diff
;
1782 base_fontname
= base
;
1785 /* Build the font spec that matches all charsets. */
1786 len
= p
- base_fontname
+ strlen (allcs
) + 1;
1787 font_allcs
= alloca (len
);
1788 memcpy (font_allcs
, base_fontname
, p
- base_fontname
);
1789 strcpy (font_allcs
+ (p
- base_fontname
), allcs
);
1791 /* Build the font spec that matches all families and
1793 len
= p
- p1
+ strlen (allcs
) + strlen (allfamilies
) + 1;
1794 font_allfamilies
= alloca (len
);
1795 strcpy (font_allfamilies
, allfamilies
);
1796 memcpy (font_allfamilies
+ strlen (allfamilies
), p1
, p
- p1
);
1797 strcpy (font_allfamilies
+ strlen (allfamilies
) + (p
- p1
), allcs
);
1799 /* Build the font spec that matches all. */
1800 len
= p
- p2
+ strlen (allcs
) + strlen (all
) + strlen (allfamilies
) + 1;
1801 font_all
= alloca (len
);
1802 z
= stpcpy (font_all
, allfamilies
);
1803 z
= stpcpy (z
, all
);
1804 memcpy (z
, p2
, p
- p2
);
1805 strcpy (z
+ (p
- p2
), allcs
);
1807 /* Build the actual font set name. */
1808 len
= strlen (base_fontname
) + strlen (font_allcs
)
1809 + strlen (font_allfamilies
) + strlen (font_all
) + 5;
1810 fontsetname
= xmalloc (len
);
1811 z
= stpcpy (fontsetname
, base_fontname
);
1812 z
= stpcpy (z
, sep
);
1813 z
= stpcpy (z
, font_allcs
);
1814 z
= stpcpy (z
, sep
);
1815 z
= stpcpy (z
, font_allfamilies
);
1816 z
= stpcpy (z
, sep
);
1817 z
= stpcpy (z
, font_all
);
1824 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
1826 #ifdef DEBUG_XIC_FONTSET
1828 print_fontset_result (XFontSet xfs
, char *name
, char **missing_list
,
1832 fprintf (stderr
, "XIC Fontset created: %s\n", name
);
1835 fprintf (stderr
, "XIC Fontset failed: %s\n", name
);
1836 while (missing_count
-- > 0)
1838 fprintf (stderr
, " missing: %s\n", *missing_list
);
1847 xic_create_xfontset (struct frame
*f
)
1849 XFontSet xfs
= NULL
;
1850 struct font
*font
= FRAME_FONT (f
);
1851 int pixel_size
= font
->pixel_size
;
1852 Lisp_Object rest
, frame
;
1854 /* See if there is another frame already using same fontset. */
1855 FOR_EACH_FRAME (rest
, frame
)
1857 struct frame
*cf
= XFRAME (frame
);
1859 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
1860 && FRAME_DISPLAY_INFO (cf
) == FRAME_DISPLAY_INFO (f
)
1862 && FRAME_FONT (f
)->pixel_size
== pixel_size
)
1864 xfs
= FRAME_XIC_FONTSET (cf
);
1872 char **missing_list
;
1875 const char *xlfd_format
= "-*-*-medium-r-normal--%d-*-*-*-*-*";
1877 sprintf (buf
, xlfd_format
, pixel_size
);
1878 missing_list
= NULL
;
1879 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
1880 &missing_list
, &missing_count
, &def_string
);
1881 #ifdef DEBUG_XIC_FONTSET
1882 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
1885 XFreeStringList (missing_list
);
1888 /* List of pixel sizes most likely available. Find one that
1889 is closest to pixel_size. */
1890 int sizes
[] = {0, 8, 10, 11, 12, 14, 17, 18, 20, 24, 26, 34, 0};
1891 int *smaller
, *larger
;
1893 for (smaller
= sizes
; smaller
[1]; smaller
++)
1894 if (smaller
[1] >= pixel_size
)
1896 larger
= smaller
+ 1;
1897 if (*larger
== pixel_size
)
1899 while (*smaller
|| *larger
)
1904 this_size
= *smaller
--;
1905 else if (! *smaller
)
1906 this_size
= *larger
++;
1907 else if (pixel_size
- *smaller
< *larger
- pixel_size
)
1908 this_size
= *smaller
--;
1910 this_size
= *larger
++;
1911 sprintf (buf
, xlfd_format
, this_size
);
1912 missing_list
= NULL
;
1913 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
1914 &missing_list
, &missing_count
, &def_string
);
1915 #ifdef DEBUG_XIC_FONTSET
1916 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
1919 XFreeStringList (missing_list
);
1926 const char *last_resort
= "-*-*-*-r-normal--*-*-*-*-*-*";
1928 missing_list
= NULL
;
1929 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), last_resort
,
1930 &missing_list
, &missing_count
, &def_string
);
1931 #ifdef DEBUG_XIC_FONTSET
1932 print_fontset_result (xfs
, last_resort
, missing_list
, missing_count
);
1935 XFreeStringList (missing_list
);
1943 /* Free the X fontset of frame F if it is the last frame using it. */
1946 xic_free_xfontset (struct frame
*f
)
1948 Lisp_Object rest
, frame
;
1949 bool shared_p
= false;
1951 if (!FRAME_XIC_FONTSET (f
))
1954 /* See if there is another frame sharing the same fontset. */
1955 FOR_EACH_FRAME (rest
, frame
)
1957 struct frame
*cf
= XFRAME (frame
);
1958 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
1959 && FRAME_DISPLAY_INFO (cf
) == FRAME_DISPLAY_INFO (f
)
1960 && FRAME_XIC_FONTSET (cf
) == FRAME_XIC_FONTSET (f
))
1968 /* The fontset is not used anymore. It is safe to free it. */
1969 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
1971 FRAME_XIC_FONTSET (f
) = NULL
;
1975 /* Value is the best input style, given user preferences USER (already
1976 checked to be supported by Emacs), and styles supported by the
1977 input method XIM. */
1980 best_xim_style (XIMStyles
*xim
)
1983 int nr_supported
= ARRAYELTS (supported_xim_styles
);
1985 for (i
= 0; i
< nr_supported
; ++i
)
1986 for (j
= 0; j
< xim
->count_styles
; ++j
)
1987 if (supported_xim_styles
[i
] == xim
->supported_styles
[j
])
1988 return supported_xim_styles
[i
];
1990 /* Return the default style. */
1991 return XIMPreeditNothing
| XIMStatusNothing
;
1994 /* Create XIC for frame F. */
1997 create_frame_xic (struct frame
*f
)
2001 XFontSet xfs
= NULL
;
2002 XVaNestedList status_attr
= NULL
;
2003 XVaNestedList preedit_attr
= NULL
;
2011 xim
= FRAME_X_XIM (f
);
2015 /* Determine XIC style. */
2016 xic_style
= best_xim_style (FRAME_X_XIM_STYLES (f
));
2018 /* Create X fontset. */
2019 if (xic_style
& (XIMPreeditPosition
| XIMStatusArea
))
2021 xfs
= xic_create_xfontset (f
);
2025 FRAME_XIC_FONTSET (f
) = xfs
;
2028 if (xic_style
& XIMPreeditPosition
)
2030 spot
.x
= 0; spot
.y
= 1;
2031 preedit_attr
= XVaCreateNestedList (0,
2034 FRAME_FOREGROUND_PIXEL (f
),
2036 FRAME_BACKGROUND_PIXEL (f
),
2037 (xic_style
& XIMPreeditPosition
2047 if (xic_style
& XIMStatusArea
)
2049 s_area
.x
= 0; s_area
.y
= 0; s_area
.width
= 1; s_area
.height
= 1;
2050 status_attr
= XVaCreateNestedList (0,
2056 FRAME_FOREGROUND_PIXEL (f
),
2058 FRAME_BACKGROUND_PIXEL (f
),
2065 if (preedit_attr
&& status_attr
)
2066 xic
= XCreateIC (xim
,
2067 XNInputStyle
, xic_style
,
2068 XNClientWindow
, FRAME_X_WINDOW (f
),
2069 XNFocusWindow
, FRAME_X_WINDOW (f
),
2070 XNStatusAttributes
, status_attr
,
2071 XNPreeditAttributes
, preedit_attr
,
2073 else if (preedit_attr
)
2074 xic
= XCreateIC (xim
,
2075 XNInputStyle
, xic_style
,
2076 XNClientWindow
, FRAME_X_WINDOW (f
),
2077 XNFocusWindow
, FRAME_X_WINDOW (f
),
2078 XNPreeditAttributes
, preedit_attr
,
2080 else if (status_attr
)
2081 xic
= XCreateIC (xim
,
2082 XNInputStyle
, xic_style
,
2083 XNClientWindow
, FRAME_X_WINDOW (f
),
2084 XNFocusWindow
, FRAME_X_WINDOW (f
),
2085 XNStatusAttributes
, status_attr
,
2088 xic
= XCreateIC (xim
,
2089 XNInputStyle
, xic_style
,
2090 XNClientWindow
, FRAME_X_WINDOW (f
),
2091 XNFocusWindow
, FRAME_X_WINDOW (f
),
2097 FRAME_XIC (f
) = xic
;
2098 FRAME_XIC_STYLE (f
) = xic_style
;
2099 xfs
= NULL
; /* Don't free below. */
2107 XFree (preedit_attr
);
2110 XFree (status_attr
);
2114 /* Destroy XIC and free XIC fontset of frame F, if any. */
2117 free_frame_xic (struct frame
*f
)
2119 if (FRAME_XIC (f
) == NULL
)
2122 XDestroyIC (FRAME_XIC (f
));
2123 xic_free_xfontset (f
);
2125 FRAME_XIC (f
) = NULL
;
2129 /* Place preedit area for XIC of window W's frame to specified
2130 pixel position X/Y. X and Y are relative to window W. */
2133 xic_set_preeditarea (struct window
*w
, int x
, int y
)
2135 struct frame
*f
= XFRAME (w
->frame
);
2139 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
) + WINDOW_LEFT_FRINGE_WIDTH (w
);
2140 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
2141 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
2142 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2147 /* Place status area for XIC in bottom right corner of frame F.. */
2150 xic_set_statusarea (struct frame
*f
)
2152 XIC xic
= FRAME_XIC (f
);
2157 /* Negotiate geometry of status area. If input method has existing
2158 status area, use its current size. */
2159 area
.x
= area
.y
= area
.width
= area
.height
= 0;
2160 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
2161 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2164 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
2165 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2168 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
2170 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
2171 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2175 area
.width
= needed
->width
;
2176 area
.height
= needed
->height
;
2177 area
.x
= FRAME_PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
2178 area
.y
= (FRAME_PIXEL_HEIGHT (f
) - area
.height
2179 - FRAME_MENUBAR_HEIGHT (f
)
2180 - FRAME_TOOLBAR_TOP_HEIGHT (f
)
2181 - FRAME_INTERNAL_BORDER_WIDTH (f
));
2184 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
2185 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2190 /* Set X fontset for XIC of frame F, using base font name
2191 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2194 xic_set_xfontset (struct frame
*f
, const char *base_fontname
)
2199 xic_free_xfontset (f
);
2201 xfs
= xic_create_xfontset (f
);
2203 attr
= XVaCreateNestedList (0, XNFontSet
, xfs
, NULL
);
2204 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
2205 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2206 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
2207 XSetICValues (FRAME_XIC (f
), XNStatusAttributes
, attr
, NULL
);
2210 FRAME_XIC_FONTSET (f
) = xfs
;
2213 #endif /* HAVE_X_I18N */
2217 #ifdef USE_X_TOOLKIT
2219 /* Create and set up the X widget for frame F. */
2222 x_window (struct frame
*f
, long window_prompting
)
2224 XClassHint class_hints
;
2225 XSetWindowAttributes attributes
;
2226 unsigned long attribute_mask
;
2227 Widget shell_widget
;
2229 Widget frame_widget
;
2235 /* Use the resource name as the top-level widget name
2236 for looking up resources. Make a non-Lisp copy
2237 for the window manager, so GC relocation won't bother it.
2239 Elsewhere we specify the window name for the window manager. */
2240 f
->namebuf
= xlispstrdup (Vx_resource_name
);
2243 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2244 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2245 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2246 XtSetArg (al
[ac
], XtNborderWidth
, f
->border_width
); ac
++;
2247 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2248 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2249 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2250 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2251 applicationShellWidgetClass
,
2252 FRAME_X_DISPLAY (f
), al
, ac
);
2254 f
->output_data
.x
->widget
= shell_widget
;
2255 /* maybe_set_screen_title_format (shell_widget); */
2257 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2258 NULL
, shell_widget
, False
,
2259 NULL
, NULL
, NULL
, NULL
);
2262 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2263 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2264 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2265 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2266 XtSetValues (pane_widget
, al
, ac
);
2267 f
->output_data
.x
->column_widget
= pane_widget
;
2269 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2270 the emacs screen when changing menubar. This reduces flickering. */
2273 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2274 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2275 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2276 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2277 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2278 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2279 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2280 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2281 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2282 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
2285 f
->output_data
.x
->edit_widget
= frame_widget
;
2287 XtManageChild (frame_widget
);
2289 /* Do some needed geometry management. */
2293 int extra_borders
= 0;
2295 = (f
->output_data
.x
->menubar_widget
2296 ? (f
->output_data
.x
->menubar_widget
->core
.height
2297 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
2300 #if false /* Experimentally, we now get the right results
2301 for -geometry -0-0 without this. 24 Aug 96, rms. */
2302 if (FRAME_EXTERNAL_MENU_BAR (f
))
2305 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2306 menubar_size
+= ibw
;
2310 FRAME_MENUBAR_HEIGHT (f
) = menubar_size
;
2313 /* Motif seems to need this amount added to the sizes
2314 specified for the shell widget. The Athena/Lucid widgets don't.
2315 Both conclusions reached experimentally. -- rms. */
2316 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
2317 &extra_borders
, NULL
);
2321 f
->shell_position
= xmalloc (sizeof "=x++" + 4 * INT_STRLEN_BOUND (int));
2323 /* Convert our geometry parameters into a geometry string
2325 Note that we do not specify here whether the position
2326 is a user-specified or program-specified one.
2327 We pass that information later, in x_wm_set_size_hints. */
2329 int left
= f
->left_pos
;
2330 bool xneg
= (window_prompting
& XNegative
) != 0;
2331 int top
= f
->top_pos
;
2332 bool yneg
= (window_prompting
& YNegative
) != 0;
2338 if (window_prompting
& USPosition
)
2339 sprintf (f
->shell_position
, "=%dx%d%c%d%c%d",
2340 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2341 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
2342 (xneg
? '-' : '+'), left
,
2343 (yneg
? '-' : '+'), top
);
2346 sprintf (f
->shell_position
, "=%dx%d",
2347 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2348 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
2350 /* Setting x and y when the position is not specified in
2351 the geometry string will set program position in the WM hints.
2352 If Emacs had just one program position, we could set it in
2353 fallback resources, but since each make-frame call can specify
2354 different program positions, this is easier. */
2355 XtSetArg (gal
[gac
], XtNx
, left
); gac
++;
2356 XtSetArg (gal
[gac
], XtNy
, top
); gac
++;
2360 XtSetArg (gal
[gac
], XtNgeometry
, f
->shell_position
); gac
++;
2361 XtSetValues (shell_widget
, gal
, gac
);
2364 XtManageChild (pane_widget
);
2365 XtRealizeWidget (shell_widget
);
2367 if (FRAME_X_EMBEDDED_P (f
))
2368 XReparentWindow (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
),
2369 f
->output_data
.x
->parent_desc
, 0, 0);
2371 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2373 validate_x_resource_name ();
2375 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2376 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2377 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2380 FRAME_XIC (f
) = NULL
;
2382 create_frame_xic (f
);
2385 f
->output_data
.x
->wm_hints
.input
= True
;
2386 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2387 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2388 &f
->output_data
.x
->wm_hints
);
2390 hack_wm_protocols (f
, shell_widget
);
2393 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2396 /* Do a stupid property change to force the server to generate a
2397 PropertyNotify event so that the event_stream server timestamp will
2398 be initialized to something relevant to the time we created the window.
2400 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2401 FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2402 XA_ATOM
, 32, PropModeAppend
, NULL
, 0);
2404 /* Make all the standard events reach the Emacs frame. */
2405 attributes
.event_mask
= STANDARD_EVENT_SET
;
2410 /* XIM server might require some X events. */
2411 unsigned long fevent
= NoEventMask
;
2412 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2413 attributes
.event_mask
|= fevent
;
2415 #endif /* HAVE_X_I18N */
2417 attribute_mask
= CWEventMask
;
2418 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2419 attribute_mask
, &attributes
);
2421 XtMapWidget (frame_widget
);
2423 /* x_set_name normally ignores requests to set the name if the
2424 requested name is the same as the current name. This is the one
2425 place where that assumption isn't correct; f->name is set, but
2426 the X server hasn't been told. */
2429 bool explicit = f
->explicit_name
;
2431 f
->explicit_name
= false;
2433 fset_name (f
, Qnil
);
2434 x_set_name (f
, name
, explicit);
2437 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2438 f
->output_data
.x
->current_cursor
2439 = f
->output_data
.x
->text_cursor
);
2443 /* This is a no-op, except under Motif. Make sure main areas are
2444 set to something reasonable, in case we get an error later. */
2445 lw_set_main_areas (pane_widget
, 0, frame_widget
);
2448 #else /* not USE_X_TOOLKIT */
2451 x_window (struct frame
*f
)
2453 if (! xg_create_frame_widgets (f
))
2454 error ("Unable to create window");
2457 FRAME_XIC (f
) = NULL
;
2461 create_frame_xic (f
);
2464 /* XIM server might require some X events. */
2465 unsigned long fevent
= NoEventMask
;
2466 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2468 if (fevent
!= NoEventMask
)
2470 XSetWindowAttributes attributes
;
2471 XWindowAttributes wattr
;
2472 unsigned long attribute_mask
;
2474 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2476 attributes
.event_mask
= wattr
.your_event_mask
| fevent
;
2477 attribute_mask
= CWEventMask
;
2478 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2479 attribute_mask
, &attributes
);
2487 #else /*! USE_GTK */
2488 /* Create and set up the X window for frame F. */
2491 x_window (struct frame
*f
)
2493 XClassHint class_hints
;
2494 XSetWindowAttributes attributes
;
2495 unsigned long attribute_mask
;
2497 attributes
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2498 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
2499 attributes
.bit_gravity
= StaticGravity
;
2500 attributes
.backing_store
= NotUseful
;
2501 attributes
.save_under
= True
;
2502 attributes
.event_mask
= STANDARD_EVENT_SET
;
2503 attributes
.colormap
= FRAME_X_COLORMAP (f
);
2504 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
2509 = XCreateWindow (FRAME_X_DISPLAY (f
),
2510 f
->output_data
.x
->parent_desc
,
2513 FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
),
2515 CopyFromParent
, /* depth */
2516 InputOutput
, /* class */
2518 attribute_mask
, &attributes
);
2523 create_frame_xic (f
);
2526 /* XIM server might require some X events. */
2527 unsigned long fevent
= NoEventMask
;
2528 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2529 attributes
.event_mask
|= fevent
;
2530 attribute_mask
= CWEventMask
;
2531 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2532 attribute_mask
, &attributes
);
2535 #endif /* HAVE_X_I18N */
2537 validate_x_resource_name ();
2539 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2540 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2541 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2543 /* This indicates that we use the "Passive Input" input model.
2544 Unless we do this, we don't get the Focus{In,Out} events that we
2545 need to draw the cursor correctly. Accursed bureaucrats.
2546 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2548 f
->output_data
.x
->wm_hints
.input
= True
;
2549 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2550 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2551 &f
->output_data
.x
->wm_hints
);
2552 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
2554 /* Request "save yourself" and "delete window" commands from wm. */
2557 protocols
[0] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2558 protocols
[1] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2559 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2562 /* x_set_name normally ignores requests to set the name if the
2563 requested name is the same as the current name. This is the one
2564 place where that assumption isn't correct; f->name is set, but
2565 the X server hasn't been told. */
2568 bool explicit = f
->explicit_name
;
2570 f
->explicit_name
= false;
2572 fset_name (f
, Qnil
);
2573 x_set_name (f
, name
, explicit);
2576 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2577 f
->output_data
.x
->current_cursor
2578 = f
->output_data
.x
->text_cursor
);
2582 if (FRAME_X_WINDOW (f
) == 0)
2583 error ("Unable to create window");
2586 #endif /* not USE_GTK */
2587 #endif /* not USE_X_TOOLKIT */
2589 /* Verify that the icon position args for this window are valid. */
2592 x_icon_verify (struct frame
*f
, Lisp_Object parms
)
2594 Lisp_Object icon_x
, icon_y
;
2596 /* Set the position of the icon. Note that twm groups all
2597 icons in an icon window. */
2598 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2599 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2600 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2602 CHECK_NUMBER (icon_x
);
2603 CHECK_NUMBER (icon_y
);
2605 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2606 error ("Both left and top icon corners of icon must be specified");
2609 /* Handle the icon stuff for this window. Perhaps later we might
2610 want an x_set_icon_position which can be called interactively as
2614 x_icon (struct frame
*f
, Lisp_Object parms
)
2616 /* Set the position of the icon. Note that twm groups all
2617 icons in an icon window. */
2619 = x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2621 = x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2622 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2624 CHECK_TYPE_RANGED_INTEGER (int, icon_x
);
2625 CHECK_TYPE_RANGED_INTEGER (int, icon_y
);
2627 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2628 error ("Both left and top icon corners of icon must be specified");
2632 if (! EQ (icon_x
, Qunbound
))
2633 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2635 #if false /* x_get_arg removes the visibility parameter as a side effect,
2636 but x_create_frame still needs it. */
2637 /* Start up iconic or window? */
2638 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2639 x_wm_set_window_state
2640 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
2646 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
2653 /* Make the GCs needed for this window, setting the
2654 background, border and mouse colors; also create the
2655 mouse cursor and the gray border tile. */
2658 x_make_gc (struct frame
*f
)
2660 XGCValues gc_values
;
2664 /* Create the GCs of this frame.
2665 Note that many default values are used. */
2667 gc_values
.foreground
= FRAME_FOREGROUND_PIXEL (f
);
2668 gc_values
.background
= FRAME_BACKGROUND_PIXEL (f
);
2669 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2670 f
->output_data
.x
->normal_gc
2671 = XCreateGC (FRAME_X_DISPLAY (f
),
2673 GCLineWidth
| GCForeground
| GCBackground
,
2676 /* Reverse video style. */
2677 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2678 gc_values
.background
= FRAME_FOREGROUND_PIXEL (f
);
2679 f
->output_data
.x
->reverse_gc
2680 = XCreateGC (FRAME_X_DISPLAY (f
),
2682 GCForeground
| GCBackground
| GCLineWidth
,
2685 /* Cursor has cursor-color background, background-color foreground. */
2686 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2687 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
2688 gc_values
.fill_style
= FillOpaqueStippled
;
2689 f
->output_data
.x
->cursor_gc
2690 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2691 (GCForeground
| GCBackground
2692 | GCFillStyle
| GCLineWidth
),
2695 /* Create the gray border tile used when the pointer is not in
2696 the frame. Since this depends on the frame's pixel values,
2697 this must be done on a per-frame basis. */
2698 f
->output_data
.x
->border_tile
2699 = (XCreatePixmapFromBitmapData
2700 (FRAME_X_DISPLAY (f
), FRAME_DISPLAY_INFO (f
)->root_window
,
2701 gray_bits
, gray_width
, gray_height
,
2702 FRAME_FOREGROUND_PIXEL (f
),
2703 FRAME_BACKGROUND_PIXEL (f
),
2704 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
2710 /* Free what was allocated in x_make_gc. */
2713 x_free_gcs (struct frame
*f
)
2715 Display
*dpy
= FRAME_X_DISPLAY (f
);
2719 if (f
->output_data
.x
->normal_gc
)
2721 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
2722 f
->output_data
.x
->normal_gc
= 0;
2725 if (f
->output_data
.x
->reverse_gc
)
2727 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
2728 f
->output_data
.x
->reverse_gc
= 0;
2731 if (f
->output_data
.x
->cursor_gc
)
2733 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
2734 f
->output_data
.x
->cursor_gc
= 0;
2737 if (f
->output_data
.x
->border_tile
)
2739 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
2740 f
->output_data
.x
->border_tile
= 0;
2747 /* Handler for signals raised during x_create_frame and
2748 x_create_tip_frame. FRAME is the frame which is partially
2752 unwind_create_frame (Lisp_Object frame
)
2754 struct frame
*f
= XFRAME (frame
);
2756 /* If frame is already dead, nothing to do. This can happen if the
2757 display is disconnected after the frame has become official, but
2758 before x_create_frame removes the unwind protect. */
2759 if (!FRAME_LIVE_P (f
))
2762 /* If frame is ``official'', nothing to do. */
2763 if (NILP (Fmemq (frame
, Vframe_list
)))
2765 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2766 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2769 x_free_frame_resources (f
);
2772 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2773 /* Check that reference counts are indeed correct. */
2774 eassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
2775 eassert (dpyinfo
->terminal
->image_cache
->refcount
== image_cache_refcount
);
2784 do_unwind_create_frame (Lisp_Object frame
)
2786 unwind_create_frame (frame
);
2790 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
2792 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2793 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
2795 Lisp_Object font
= Qnil
;
2796 if (EQ (font_param
, Qunbound
))
2799 if (NILP (font_param
))
2801 /* System font should take precedence over X resources. We suggest this
2802 regardless of font-use-system-font because .emacs may not have been
2804 const char *system_font
= xsettings_get_system_font ();
2806 font
= font_open_by_name (f
, build_unibyte_string (system_font
));
2810 font
= !NILP (font_param
) ? font_param
2811 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
2813 if (! FONTP (font
) && ! STRINGP (font
))
2818 /* This will find the normal Xft font. */
2821 "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1",
2822 "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2823 "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2824 /* This was formerly the first thing tried, but it finds
2825 too many fonts and takes too long. */
2826 "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1",
2827 /* If those didn't work, look for something which will
2829 "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1",
2834 for (i
= 0; names
[i
]; i
++)
2836 font
= font_open_by_name (f
, build_unibyte_string (names
[i
]));
2841 error ("No suitable font was found");
2843 else if (!NILP (font_param
))
2845 /* Remember the explicit font parameter, so we can re-apply it after
2846 we've applied the `default' face settings. */
2847 AUTO_FRAME_ARG (arg
, Qfont_param
, font_param
);
2848 x_set_frame_parameters (f
, arg
);
2851 /* This call will make X resources override any system font setting. */
2852 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
2856 DEFUN ("x-wm-set-size-hint", Fx_wm_set_size_hint
, Sx_wm_set_size_hint
,
2858 doc
: /* Send the size hints for frame FRAME to the window manager.
2859 If FRAME is omitted or nil, use the selected frame.
2860 Signal error if FRAME is not an X frame. */)
2863 struct frame
*f
= decode_window_system_frame (frame
);
2866 x_wm_set_size_hint (f
, 0, false);
2872 set_machine_and_pid_properties (struct frame
*f
)
2874 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME. */
2875 XSetWMProperties (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), NULL
, NULL
,
2876 NULL
, 0, NULL
, NULL
, NULL
);
2877 pid_t pid
= getpid ();
2878 if (pid
<= 0xffffffffu
)
2880 unsigned long xpid
= pid
;
2881 XChangeProperty (FRAME_X_DISPLAY (f
),
2882 FRAME_OUTER_WINDOW (f
),
2883 XInternAtom (FRAME_X_DISPLAY (f
),
2886 XA_CARDINAL
, 32, PropModeReplace
,
2887 (unsigned char *) &xpid
, 1);
2891 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
2893 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
2894 Return an Emacs frame object. PARMS is an alist of frame parameters.
2895 If the parameters specify that the frame should not have a minibuffer,
2896 and do not specify a specific minibuffer window to use, then
2897 `default-minibuffer-frame' must be a frame whose minibuffer can be
2898 shared by the new frame.
2900 This function is an internal primitive--use `make-frame' instead. */)
2904 Lisp_Object frame
, tem
;
2906 bool minibuffer_only
= false;
2907 long window_prompting
= 0;
2908 ptrdiff_t count
= SPECPDL_INDEX ();
2909 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
2910 Lisp_Object display
;
2911 struct x_display_info
*dpyinfo
= NULL
;
2915 parms
= Fcopy_alist (parms
);
2917 /* Use this general default value to start with
2918 until we know if this frame has a specified name. */
2919 Vx_resource_name
= Vinvocation_name
;
2921 display
= x_get_arg (dpyinfo
, parms
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
2922 if (EQ (display
, Qunbound
))
2923 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
2924 if (EQ (display
, Qunbound
))
2926 dpyinfo
= check_x_display_info (display
);
2927 kb
= dpyinfo
->terminal
->kboard
;
2929 if (!dpyinfo
->terminal
->name
)
2930 error ("Terminal is not live, can't create new frames on it");
2932 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
2934 && ! EQ (name
, Qunbound
)
2936 error ("Invalid frame name--not a string or nil");
2939 Vx_resource_name
= name
;
2941 /* See if parent window is specified. */
2942 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
2943 if (EQ (parent
, Qunbound
))
2945 if (! NILP (parent
))
2946 CHECK_NUMBER (parent
);
2948 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
2949 /* No need to protect DISPLAY because that's not used after passing
2950 it to make_frame_without_minibuffer. */
2952 GCPRO4 (parms
, parent
, name
, frame
);
2953 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
2955 if (EQ (tem
, Qnone
) || NILP (tem
))
2956 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
2957 else if (EQ (tem
, Qonly
))
2959 f
= make_minibuffer_frame ();
2960 minibuffer_only
= true;
2962 else if (WINDOWP (tem
))
2963 f
= make_frame_without_minibuffer (tem
, kb
, display
);
2965 f
= make_frame (true);
2967 XSETFRAME (frame
, f
);
2969 f
->terminal
= dpyinfo
->terminal
;
2971 f
->output_method
= output_x_window
;
2972 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
2973 f
->output_data
.x
->icon_bitmap
= -1;
2974 FRAME_FONTSET (f
) = -1;
2975 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
2976 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
2977 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
2978 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
2979 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
2980 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
2981 f
->output_data
.x
->white_relief
.pixel
= -1;
2982 f
->output_data
.x
->black_relief
.pixel
= -1;
2985 x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
2987 if (! STRINGP (f
->icon_name
))
2988 fset_icon_name (f
, Qnil
);
2990 FRAME_DISPLAY_INFO (f
) = dpyinfo
;
2992 /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe. */
2993 record_unwind_protect (do_unwind_create_frame
, frame
);
2995 /* These colors will be set anyway later, but it's important
2996 to get the color reference counts right, so initialize them! */
2999 struct gcpro gcpro1
;
3001 /* Function x_decode_color can signal an error. Make
3002 sure to initialize color slots so that we won't try
3003 to free colors we haven't allocated. */
3004 FRAME_FOREGROUND_PIXEL (f
) = -1;
3005 FRAME_BACKGROUND_PIXEL (f
) = -1;
3006 f
->output_data
.x
->cursor_pixel
= -1;
3007 f
->output_data
.x
->cursor_foreground_pixel
= -1;
3008 f
->output_data
.x
->border_pixel
= -1;
3009 f
->output_data
.x
->mouse_pixel
= -1;
3011 black
= build_string ("black");
3013 FRAME_FOREGROUND_PIXEL (f
)
3014 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3015 FRAME_BACKGROUND_PIXEL (f
)
3016 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3017 f
->output_data
.x
->cursor_pixel
3018 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3019 f
->output_data
.x
->cursor_foreground_pixel
3020 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3021 f
->output_data
.x
->border_pixel
3022 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3023 f
->output_data
.x
->mouse_pixel
3024 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3028 /* Specify the parent under which to make this X window. */
3031 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
3032 f
->output_data
.x
->explicit_parent
= true;
3036 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
3037 f
->output_data
.x
->explicit_parent
= false;
3040 /* Set the name; the functions to which we pass f expect the name to
3042 if (EQ (name
, Qunbound
) || NILP (name
))
3044 fset_name (f
, build_string (dpyinfo
->x_id_name
));
3045 f
->explicit_name
= false;
3049 fset_name (f
, name
);
3050 f
->explicit_name
= true;
3051 /* Use the frame's title when getting resources for this frame. */
3052 specbind (Qx_resource_name
, name
);
3055 #ifdef HAVE_FREETYPE
3057 register_font_driver (&xftfont_driver
, f
);
3058 #else /* not HAVE_XFT */
3059 register_font_driver (&ftxfont_driver
, f
);
3060 #endif /* not HAVE_XFT */
3061 #endif /* HAVE_FREETYPE */
3062 register_font_driver (&xfont_driver
, f
);
3064 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
3065 "fontBackend", "FontBackend", RES_TYPE_STRING
);
3067 /* Extract the window parameters from the supplied values
3068 that are needed to determine window geometry. */
3069 x_default_font_parameter (f
, parms
);
3070 if (!FRAME_FONT (f
))
3072 delete_frame (frame
, Qnoelisp
);
3073 error ("Invalid frame font");
3076 /* Frame contents get displaced if an embedded X window has a border. */
3077 if (! FRAME_X_EMBEDDED_P (f
))
3078 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
3079 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
3081 /* This defaults to 1 in order to match xterm. We recognize either
3082 internalBorderWidth or internalBorder (which is what xterm calls
3084 if (NILP (Fassq (Qinternal_border_width
, parms
)))
3088 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
3089 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
3090 if (! EQ (value
, Qunbound
))
3091 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
3094 x_default_parameter (f
, parms
, Qinternal_border_width
,
3095 #ifdef USE_GTK /* We used to impose 0 in xg_create_frame_widgets. */
3100 "internalBorderWidth", "internalBorderWidth",
3102 x_default_parameter (f
, parms
, Qright_divider_width
, make_number (0),
3103 NULL
, NULL
, RES_TYPE_NUMBER
);
3104 x_default_parameter (f
, parms
, Qbottom_divider_width
, make_number (0),
3105 NULL
, NULL
, RES_TYPE_NUMBER
);
3106 x_default_parameter (f
, parms
, Qvertical_scroll_bars
,
3107 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
3112 "verticalScrollBars", "ScrollBars",
3114 x_default_parameter (f
, parms
, Qhorizontal_scroll_bars
, Qnil
,
3115 "horizontalScrollBars", "ScrollBars",
3117 /* Also do the stuff which must be set before the window exists. */
3118 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3119 "foreground", "Foreground", RES_TYPE_STRING
);
3120 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3121 "background", "Background", RES_TYPE_STRING
);
3122 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3123 "pointerColor", "Foreground", RES_TYPE_STRING
);
3124 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3125 "borderColor", "BorderColor", RES_TYPE_STRING
);
3126 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3127 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3128 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3129 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3130 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3131 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3132 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3133 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3135 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3136 "scrollBarForeground",
3137 "ScrollBarForeground", true);
3138 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3139 "scrollBarBackground",
3140 "ScrollBarBackground", false);
3143 image_cache_refcount
=
3144 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
3145 dpyinfo_refcount
= dpyinfo
->reference_count
;
3146 #endif /* GLYPH_DEBUG */
3148 /* Init faces before x_default_parameter is called for the
3149 scroll-bar-width parameter because otherwise we end up in
3150 init_iterator with a null face cache, which should not happen. */
3151 init_frame_faces (f
);
3153 /* The following call of change_frame_size is needed since otherwise
3154 x_set_tool_bar_lines will already work with the character sizes
3155 installed by init_frame_faces while the frame's pixel size is
3156 still calculated from a character size of 1 and we subsequently
3157 hit the (height >= 0) assertion in window_box_height.
3159 The non-pixelwise code apparently worked around this because it
3160 had one frame line vs one toolbar line which left us with a zero
3161 root window height which was obviously wrong as well ... */
3162 adjust_frame_size (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
),
3163 FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
), 5, true,
3166 /* Set the menu-bar-lines and tool-bar-lines parameters. We don't
3167 look up the X resources controlling the menu-bar and tool-bar
3168 here; they are processed specially at startup, and reflected in
3169 the values of the mode variables. */
3171 x_default_parameter (f
, parms
, Qmenu_bar_lines
,
3172 NILP (Vmenu_bar_mode
)
3173 ? make_number (0) : make_number (1),
3174 NULL
, NULL
, RES_TYPE_NUMBER
);
3175 x_default_parameter (f
, parms
, Qtool_bar_lines
,
3176 NILP (Vtool_bar_mode
)
3177 ? make_number (0) : make_number (1),
3178 NULL
, NULL
, RES_TYPE_NUMBER
);
3180 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3181 "bufferPredicate", "BufferPredicate",
3183 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3184 "title", "Title", RES_TYPE_STRING
);
3185 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3186 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3187 x_default_parameter (f
, parms
, Qtool_bar_position
,
3188 FRAME_TOOL_BAR_POSITION (f
), 0, 0, RES_TYPE_SYMBOL
);
3190 /* Compute the size of the X window. */
3191 window_prompting
= x_figure_window_size (f
, parms
, true);
3193 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3194 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3196 x_icon_verify (f
, parms
);
3198 /* Create the X widget or window. */
3199 #ifdef USE_X_TOOLKIT
3200 x_window (f
, window_prompting
);
3208 /* Now consider the frame official. */
3209 f
->terminal
->reference_count
++;
3210 FRAME_DISPLAY_INFO (f
)->reference_count
++;
3211 Vframe_list
= Fcons (frame
, Vframe_list
);
3213 /* We need to do this after creating the X window, so that the
3214 icon-creation functions can say whose icon they're describing. */
3215 x_default_parameter (f
, parms
, Qicon_type
, Qt
,
3216 "bitmapIcon", "BitmapIcon", RES_TYPE_BOOLEAN
);
3218 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3219 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3220 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3221 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3222 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3223 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3224 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3225 "scrollBarWidth", "ScrollBarWidth",
3227 x_default_parameter (f
, parms
, Qscroll_bar_height
, Qnil
,
3228 "scrollBarHeight", "ScrollBarHeight",
3230 x_default_parameter (f
, parms
, Qalpha
, Qnil
,
3231 "alpha", "Alpha", RES_TYPE_NUMBER
);
3233 /* Consider frame official, now. */
3234 f
->can_x_set_window_size
= true;
3236 adjust_frame_size (f
, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
), 0, true,
3239 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3240 /* Create the menu bar. */
3241 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3243 /* If this signals an error, we haven't set size hints for the
3244 frame and we didn't make it visible. */
3245 initialize_frame_menubar (f
);
3248 /* This is a no-op, except under Motif where it arranges the
3249 main window for the widgets on it. */
3250 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3251 f
->output_data
.x
->menubar_widget
,
3252 f
->output_data
.x
->edit_widget
);
3253 #endif /* not USE_GTK */
3255 #endif /* USE_X_TOOLKIT || USE_GTK */
3257 /* Tell the server what size and position, etc, we want, and how
3258 badly we want them. This should be done after we have the menu
3259 bar so that its size can be taken into account. */
3261 x_wm_set_size_hint (f
, window_prompting
, false);
3264 /* Process fullscreen parameter here in the hope that normalizing a
3265 fullheight/fullwidth frame will produce the size set by the last
3266 adjust_frame_size call. */
3267 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3268 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3270 /* Make the window appear on the frame and enable display, unless
3271 the caller says not to. However, with explicit parent, Emacs
3272 cannot control visibility, so don't try. */
3273 if (! f
->output_data
.x
->explicit_parent
)
3275 Lisp_Object visibility
;
3277 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3279 if (EQ (visibility
, Qunbound
))
3282 if (EQ (visibility
, Qicon
))
3283 x_iconify_frame (f
);
3284 else if (! NILP (visibility
))
3285 x_make_frame_visible (f
);
3288 /* Must have been Qnil. */
3294 /* Set machine name and pid for the purpose of window managers. */
3295 set_machine_and_pid_properties (f
);
3297 /* Set the WM leader property. GTK does this itself, so this is not
3298 needed when using GTK. */
3299 if (dpyinfo
->client_leader_window
!= 0)
3301 XChangeProperty (FRAME_X_DISPLAY (f
),
3302 FRAME_OUTER_WINDOW (f
),
3303 dpyinfo
->Xatom_wm_client_leader
,
3304 XA_WINDOW
, 32, PropModeReplace
,
3305 (unsigned char *) &dpyinfo
->client_leader_window
, 1);
3310 /* Initialize `default-minibuffer-frame' in case this is the first
3311 frame on this terminal. */
3312 if (FRAME_HAS_MINIBUF_P (f
)
3313 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
3314 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
3315 kset_default_minibuffer_frame (kb
, frame
);
3317 /* All remaining specified parameters, which have not been "used"
3318 by x_get_arg and friends, now go in the misc. alist of the frame. */
3319 for (tem
= parms
; CONSP (tem
); tem
= XCDR (tem
))
3320 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
3321 fset_param_alist (f
, Fcons (XCAR (tem
), f
->param_alist
));
3325 /* Make sure windows on this frame appear in calls to next-window
3326 and similar functions. */
3327 Vwindow_list
= Qnil
;
3329 return unbind_to (count
, frame
);
3333 /* FRAME is used only to get a handle on the X display. We don't pass the
3334 display info directly because we're called from frame.c, which doesn't
3335 know about that structure. */
3338 x_get_focus_frame (struct frame
*frame
)
3340 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (frame
);
3342 if (! dpyinfo
->x_focus_frame
)
3345 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3350 /* In certain situations, when the window manager follows a
3351 click-to-focus policy, there seems to be no way around calling
3352 XSetInputFocus to give another frame the input focus .
3354 In an ideal world, XSetInputFocus should generally be avoided so
3355 that applications don't interfere with the window manager's focus
3356 policy. But I think it's okay to use when it's clearly done
3357 following a user-command. */
3360 x_focus_frame (struct frame
*f
)
3362 Display
*dpy
= FRAME_X_DISPLAY (f
);
3365 x_catch_errors (dpy
);
3367 if (FRAME_X_EMBEDDED_P (f
))
3369 /* For Xembedded frames, normally the embedder forwards key
3370 events. See XEmbed Protocol Specification at
3371 http://freedesktop.org/wiki/Specifications/xembed-spec */
3372 xembed_request_focus (f
);
3376 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3377 RevertToParent
, CurrentTime
);
3378 x_ewmh_activate_frame (f
);
3381 x_uncatch_errors ();
3386 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
3387 doc
: /* Internal function called by `color-defined-p', which see
3388 .\(Note that the Nextstep version of this function ignores FRAME.) */)
3389 (Lisp_Object color
, Lisp_Object frame
)
3392 struct frame
*f
= decode_window_system_frame (frame
);
3394 CHECK_STRING (color
);
3396 if (x_defined_color (f
, SSDATA (color
), &foo
, false))
3402 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
3403 doc
: /* Internal function called by `color-values', which see. */)
3404 (Lisp_Object color
, Lisp_Object frame
)
3407 struct frame
*f
= decode_window_system_frame (frame
);
3409 CHECK_STRING (color
);
3411 if (x_defined_color (f
, SSDATA (color
), &foo
, false))
3412 return list3i (foo
.red
, foo
.green
, foo
.blue
);
3417 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
3418 doc
: /* Internal function called by `display-color-p', which see. */)
3419 (Lisp_Object terminal
)
3421 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3423 if (dpyinfo
->n_planes
<= 2)
3426 switch (dpyinfo
->visual
->class)
3439 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3441 doc
: /* Return t if the X display supports shades of gray.
3442 Note that color displays do support shades of gray.
3443 The optional argument TERMINAL specifies which display to ask about.
3444 TERMINAL should be a terminal object, a frame or a display name (a string).
3445 If omitted or nil, that stands for the selected frame's display. */)
3446 (Lisp_Object terminal
)
3448 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3450 if (dpyinfo
->n_planes
<= 1)
3453 switch (dpyinfo
->visual
->class)
3468 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3470 doc
: /* Return the width in pixels of the X display TERMINAL.
3471 The optional argument TERMINAL specifies which display to ask about.
3472 TERMINAL should be a terminal object, a frame or a display name (a string).
3473 If omitted or nil, that stands for the selected frame's display.
3475 On \"multi-monitor\" setups this refers to the pixel width for all
3476 physical monitors associated with TERMINAL. To get information for
3477 each physical monitor, use `display-monitor-attributes-list'. */)
3478 (Lisp_Object terminal
)
3480 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3482 return make_number (x_display_pixel_width (dpyinfo
));
3485 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3486 Sx_display_pixel_height
, 0, 1, 0,
3487 doc
: /* Return the height in pixels of the X display TERMINAL.
3488 The optional argument TERMINAL specifies which display to ask about.
3489 TERMINAL should be a terminal object, a frame or a display name (a string).
3490 If omitted or nil, that stands for the selected frame's display.
3492 On \"multi-monitor\" setups this refers to the pixel height for all
3493 physical monitors associated with TERMINAL. To get information for
3494 each physical monitor, use `display-monitor-attributes-list'. */)
3495 (Lisp_Object terminal
)
3497 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3499 return make_number (x_display_pixel_height (dpyinfo
));
3502 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3504 doc
: /* Return the number of bitplanes of the X display TERMINAL.
3505 The optional argument TERMINAL specifies which display to ask about.
3506 TERMINAL should be a terminal object, a frame or a display name (a string).
3507 If omitted or nil, that stands for the selected frame's display. */)
3508 (Lisp_Object terminal
)
3510 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3512 return make_number (dpyinfo
->n_planes
);
3515 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3517 doc
: /* Return the number of color cells of the X display TERMINAL.
3518 The optional argument TERMINAL specifies which display to ask about.
3519 TERMINAL should be a terminal object, a frame or a display name (a string).
3520 If omitted or nil, that stands for the selected frame's display. */)
3521 (Lisp_Object terminal
)
3523 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3525 int nr_planes
= DisplayPlanes (dpyinfo
->display
,
3526 XScreenNumberOfScreen (dpyinfo
->screen
));
3528 /* Truncate nr_planes to 24 to avoid integer overflow.
3529 Some displays says 32, but only 24 bits are actually significant.
3530 There are only very few and rare video cards that have more than
3531 24 significant bits. Also 24 bits is more than 16 million colors,
3532 it "should be enough for everyone". */
3533 if (nr_planes
> 24) nr_planes
= 24;
3535 return make_number (1 << nr_planes
);
3538 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3539 Sx_server_max_request_size
,
3541 doc
: /* Return the maximum request size of the X server of display TERMINAL.
3542 The optional argument TERMINAL specifies which display to ask about.
3543 TERMINAL should be a terminal object, a frame or a display name (a string).
3544 If omitted or nil, that stands for the selected frame's display. */)
3545 (Lisp_Object terminal
)
3547 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3549 return make_number (MAXREQUEST (dpyinfo
->display
));
3552 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3553 doc
: /* Return the "vendor ID" string of the GUI software on TERMINAL.
3555 \(Labeling every distributor as a "vendor" embodies the false assumption
3556 that operating systems cannot be developed and distributed noncommercially.)
3557 The optional argument TERMINAL specifies which display to ask about.
3559 For GNU and Unix systems, this queries the X server software; for
3560 MS-Windows, this queries the OS.
3562 TERMINAL should be a terminal object, a frame or a display name (a string).
3563 If omitted or nil, that stands for the selected frame's display. */)
3564 (Lisp_Object terminal
)
3566 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3567 const char *vendor
= ServerVendor (dpyinfo
->display
);
3569 if (! vendor
) vendor
= "";
3570 return build_string (vendor
);
3573 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3574 doc
: /* Return the version numbers of the GUI software on TERMINAL.
3575 The value is a list of three integers specifying the version of the GUI
3578 For GNU and Unix system, the first 2 numbers are the version of the X
3579 Protocol used on TERMINAL and the 3rd number is the distributor-specific
3580 release number. For MS-Windows, the 3 numbers report the version and
3581 the build number of the OS.
3583 See also the function `x-server-vendor'.
3585 The optional argument TERMINAL specifies which display to ask about.
3586 TERMINAL should be a terminal object, a frame or a display name (a string).
3587 If omitted or nil, that stands for the selected frame's display. */)
3588 (Lisp_Object terminal
)
3590 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3591 Display
*dpy
= dpyinfo
->display
;
3593 return list3i (ProtocolVersion (dpy
), ProtocolRevision (dpy
),
3594 VendorRelease (dpy
));
3597 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3598 doc
: /* Return the number of screens on the X server of display TERMINAL.
3599 The optional argument TERMINAL specifies which display to ask about.
3600 TERMINAL should be a terminal object, a frame or a display name (a string).
3601 If omitted or nil, that stands for the selected frame's display. */)
3602 (Lisp_Object terminal
)
3604 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3606 return make_number (ScreenCount (dpyinfo
->display
));
3609 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3610 doc
: /* Return the height in millimeters of the X display TERMINAL.
3611 The optional argument TERMINAL specifies which display to ask about.
3612 TERMINAL should be a terminal object, a frame or a display name (a string).
3613 If omitted or nil, that stands for the selected frame's display.
3615 On \"multi-monitor\" setups this refers to the height in millimeters for
3616 all physical monitors associated with TERMINAL. To get information
3617 for each physical monitor, use `display-monitor-attributes-list'. */)
3618 (Lisp_Object terminal
)
3620 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3622 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3625 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3626 doc
: /* Return the width in millimeters of the X display TERMINAL.
3627 The optional argument TERMINAL specifies which display to ask about.
3628 TERMINAL should be a terminal object, a frame or a display name (a string).
3629 If omitted or nil, that stands for the selected frame's display.
3631 On \"multi-monitor\" setups this refers to the width in millimeters for
3632 all physical monitors associated with TERMINAL. To get information
3633 for each physical monitor, use `display-monitor-attributes-list'. */)
3634 (Lisp_Object terminal
)
3636 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3638 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3641 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3642 Sx_display_backing_store
, 0, 1, 0,
3643 doc
: /* Return an indication of whether X display TERMINAL does backing store.
3644 The value may be `always', `when-mapped', or `not-useful'.
3645 The optional argument TERMINAL specifies which display to ask about.
3646 TERMINAL should be a terminal object, a frame or a display name (a string).
3647 If omitted or nil, that stands for the selected frame's display. */)
3648 (Lisp_Object terminal
)
3650 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3653 switch (DoesBackingStore (dpyinfo
->screen
))
3656 result
= intern ("always");
3660 result
= intern ("when-mapped");
3664 result
= intern ("not-useful");
3668 error ("Strange value for BackingStore parameter of screen");
3674 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3675 Sx_display_visual_class
, 0, 1, 0,
3676 doc
: /* Return the visual class of the X display TERMINAL.
3677 The value is one of the symbols `static-gray', `gray-scale',
3678 `static-color', `pseudo-color', `true-color', or `direct-color'.
3680 The optional argument TERMINAL specifies which display to ask about.
3681 TERMINAL should a terminal object, a frame or a display name (a string).
3682 If omitted or nil, that stands for the selected frame's display. */)
3683 (Lisp_Object terminal
)
3685 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3688 switch (dpyinfo
->visual
->class)
3691 result
= intern ("static-gray");
3694 result
= intern ("gray-scale");
3697 result
= intern ("static-color");
3700 result
= intern ("pseudo-color");
3703 result
= intern ("true-color");
3706 result
= intern ("direct-color");
3709 error ("Display has an unknown visual class");
3715 DEFUN ("x-display-save-under", Fx_display_save_under
,
3716 Sx_display_save_under
, 0, 1, 0,
3717 doc
: /* Return t if the X display TERMINAL supports the save-under feature.
3718 The optional argument TERMINAL specifies which display to ask about.
3719 TERMINAL should be a terminal object, a frame or a display name (a string).
3720 If omitted or nil, that stands for the selected frame's display. */)
3721 (Lisp_Object terminal
)
3723 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3725 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3731 /* Store the geometry of the workarea on display DPYINFO into *RECT.
3732 Return false if and only if the workarea information cannot be
3733 obtained via the _NET_WORKAREA root window property. */
3735 #if ! GTK_CHECK_VERSION (3, 4, 0)
3737 x_get_net_workarea (struct x_display_info
*dpyinfo
, XRectangle
*rect
)
3739 Display
*dpy
= dpyinfo
->display
;
3740 long offset
, max_len
;
3741 Atom target_type
, actual_type
;
3742 unsigned long actual_size
, bytes_remaining
;
3743 int rc
, actual_format
;
3744 unsigned char *tmp_data
= NULL
;
3745 bool result
= false;
3747 x_catch_errors (dpy
);
3750 target_type
= XA_CARDINAL
;
3751 rc
= XGetWindowProperty (dpy
, dpyinfo
->root_window
,
3752 dpyinfo
->Xatom_net_current_desktop
,
3753 offset
, max_len
, False
, target_type
,
3754 &actual_type
, &actual_format
, &actual_size
,
3755 &bytes_remaining
, &tmp_data
);
3756 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
3757 && actual_format
== 32 && actual_size
== max_len
)
3759 long current_desktop
= ((long *) tmp_data
)[0];
3764 offset
= 4 * current_desktop
;
3766 rc
= XGetWindowProperty (dpy
, dpyinfo
->root_window
,
3767 dpyinfo
->Xatom_net_workarea
,
3768 offset
, max_len
, False
, target_type
,
3769 &actual_type
, &actual_format
, &actual_size
,
3770 &bytes_remaining
, &tmp_data
);
3771 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
3772 && actual_format
== 32 && actual_size
== max_len
)
3774 long *values
= (long *) tmp_data
;
3776 rect
->x
= values
[0];
3777 rect
->y
= values
[1];
3778 rect
->width
= values
[2];
3779 rect
->height
= values
[3];
3789 x_uncatch_errors ();
3797 /* Return monitor number where F is "most" or closest to. */
3799 x_get_monitor_for_frame (struct frame
*f
,
3800 struct MonitorInfo
*monitors
,
3804 int area
= 0, dist
= -1;
3805 int best_area
= -1, best_dist
= -1;
3808 if (n_monitors
== 1) return 0;
3809 frect
.x
= f
->left_pos
;
3810 frect
.y
= f
->top_pos
;
3811 frect
.width
= FRAME_PIXEL_WIDTH (f
);
3812 frect
.height
= FRAME_PIXEL_HEIGHT (f
);
3814 for (i
= 0; i
< n_monitors
; ++i
)
3816 struct MonitorInfo
*mi
= &monitors
[i
];
3820 if (mi
->geom
.width
== 0) continue;
3822 if (x_intersect_rectangles (&mi
->geom
, &frect
, &res
))
3824 a
= res
.width
* res
.height
;
3832 if (a
== 0 && area
== 0)
3835 if (frect
.x
+ frect
.width
< mi
->geom
.x
)
3836 dx
= mi
->geom
.x
- frect
.x
+ frect
.width
;
3837 else if (frect
.x
> mi
->geom
.x
+ mi
->geom
.width
)
3838 dx
= frect
.x
- mi
->geom
.x
+ mi
->geom
.width
;
3841 if (frect
.y
+ frect
.height
< mi
->geom
.y
)
3842 dy
= mi
->geom
.y
- frect
.y
+ frect
.height
;
3843 else if (frect
.y
> mi
->geom
.y
+ mi
->geom
.height
)
3844 dy
= frect
.y
- mi
->geom
.y
+ mi
->geom
.height
;
3849 if (dist
== -1 || dist
> d
)
3857 return best_area
!= -1 ? best_area
: (best_dist
!= -1 ? best_dist
: 0);
3861 x_make_monitor_attribute_list (struct MonitorInfo
*monitors
,
3863 int primary_monitor
,
3864 struct x_display_info
*dpyinfo
,
3867 Lisp_Object monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
3868 Lisp_Object frame
, rest
;
3870 FOR_EACH_FRAME (rest
, frame
)
3872 struct frame
*f
= XFRAME (frame
);
3874 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
3875 && !EQ (frame
, tip_frame
))
3877 int i
= x_get_monitor_for_frame (f
, monitors
, n_monitors
);
3878 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
3882 return make_monitor_attribute_list (monitors
, n_monitors
, primary_monitor
,
3883 monitor_frames
, source
);
3887 x_get_monitor_attributes_fallback (struct x_display_info
*dpyinfo
)
3889 struct MonitorInfo monitor
;
3890 XRectangle workarea_r
;
3892 /* Fallback: treat (possibly) multiple physical monitors as if they
3893 formed a single monitor as a whole. This should provide a
3894 consistent result at least on single monitor environments. */
3895 monitor
.geom
.x
= monitor
.geom
.y
= 0;
3896 monitor
.geom
.width
= x_display_pixel_width (dpyinfo
);
3897 monitor
.geom
.height
= x_display_pixel_height (dpyinfo
);
3898 monitor
.mm_width
= WidthMMOfScreen (dpyinfo
->screen
);
3899 monitor
.mm_height
= HeightMMOfScreen (dpyinfo
->screen
);
3900 monitor
.name
= xstrdup ("combined screen");
3902 if (x_get_net_workarea (dpyinfo
, &workarea_r
))
3903 monitor
.work
= workarea_r
;
3905 monitor
.work
= monitor
.geom
;
3906 return x_make_monitor_attribute_list (&monitor
, 1, 0, dpyinfo
, "fallback");
3910 #ifdef HAVE_XINERAMA
3912 x_get_monitor_attributes_xinerama (struct x_display_info
*dpyinfo
)
3915 Lisp_Object attributes_list
= Qnil
;
3916 Display
*dpy
= dpyinfo
->display
;
3917 XineramaScreenInfo
*info
= XineramaQueryScreens (dpy
, &n_monitors
);
3918 struct MonitorInfo
*monitors
;
3919 double mm_width_per_pixel
, mm_height_per_pixel
;
3921 if (! info
|| n_monitors
== 0)
3925 return attributes_list
;
3928 mm_width_per_pixel
= ((double) WidthMMOfScreen (dpyinfo
->screen
)
3929 / x_display_pixel_width (dpyinfo
));
3930 mm_height_per_pixel
= ((double) HeightMMOfScreen (dpyinfo
->screen
)
3931 / x_display_pixel_height (dpyinfo
));
3932 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
3933 for (i
= 0; i
< n_monitors
; ++i
)
3935 struct MonitorInfo
*mi
= &monitors
[i
];
3936 XRectangle workarea_r
;
3938 mi
->geom
.x
= info
[i
].x_org
;
3939 mi
->geom
.y
= info
[i
].y_org
;
3940 mi
->geom
.width
= info
[i
].width
;
3941 mi
->geom
.height
= info
[i
].height
;
3942 mi
->mm_width
= mi
->geom
.width
* mm_width_per_pixel
+ 0.5;
3943 mi
->mm_height
= mi
->geom
.height
* mm_height_per_pixel
+ 0.5;
3946 /* Xinerama usually have primary monitor first, just use that. */
3947 if (i
== 0 && x_get_net_workarea (dpyinfo
, &workarea_r
))
3949 mi
->work
= workarea_r
;
3950 if (! x_intersect_rectangles (&mi
->geom
, &mi
->work
, &mi
->work
))
3951 mi
->work
= mi
->geom
;
3954 mi
->work
= mi
->geom
;
3958 attributes_list
= x_make_monitor_attribute_list (monitors
,
3963 free_monitors (monitors
, n_monitors
);
3964 return attributes_list
;
3966 #endif /* HAVE_XINERAMA */
3971 x_get_monitor_attributes_xrandr (struct x_display_info
*dpyinfo
)
3973 Lisp_Object attributes_list
= Qnil
;
3974 XRRScreenResources
*resources
;
3975 Display
*dpy
= dpyinfo
->display
;
3976 int i
, n_monitors
, primary
= -1;
3977 RROutput pxid
= None
;
3978 struct MonitorInfo
*monitors
;
3980 #ifdef HAVE_XRRGETSCREENRESOURCESCURRENT
3981 resources
= XRRGetScreenResourcesCurrent (dpy
, dpyinfo
->root_window
);
3983 resources
= XRRGetScreenResources (dpy
, dpyinfo
->root_window
);
3985 if (! resources
|| resources
->noutput
== 0)
3988 XRRFreeScreenResources (resources
);
3991 n_monitors
= resources
->noutput
;
3992 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
3994 #ifdef HAVE_XRRGETOUTPUTPRIMARY
3995 pxid
= XRRGetOutputPrimary (dpy
, dpyinfo
->root_window
);
3998 for (i
= 0; i
< n_monitors
; ++i
)
4000 XRROutputInfo
*info
= XRRGetOutputInfo (dpy
, resources
,
4001 resources
->outputs
[i
]);
4002 Connection conn
= info
? info
->connection
: RR_Disconnected
;
4003 RRCrtc id
= info
? info
->crtc
: None
;
4005 if (strcmp (info
->name
, "default") == 0)
4007 /* Non XRandr 1.2 driver, does not give useful data. */
4008 XRRFreeOutputInfo (info
);
4009 XRRFreeScreenResources (resources
);
4010 free_monitors (monitors
, n_monitors
);
4014 if (conn
!= RR_Disconnected
&& id
!= None
)
4016 XRRCrtcInfo
*crtc
= XRRGetCrtcInfo (dpy
, resources
, id
);
4017 struct MonitorInfo
*mi
= &monitors
[i
];
4018 XRectangle workarea_r
;
4022 XRRFreeOutputInfo (info
);
4026 mi
->geom
.x
= crtc
->x
;
4027 mi
->geom
.y
= crtc
->y
;
4028 mi
->geom
.width
= crtc
->width
;
4029 mi
->geom
.height
= crtc
->height
;
4030 mi
->mm_width
= info
->mm_width
;
4031 mi
->mm_height
= info
->mm_height
;
4032 mi
->name
= xstrdup (info
->name
);
4034 if (pxid
!= None
&& pxid
== resources
->outputs
[i
])
4036 else if (primary
== -1 && strcmp (info
->name
, "LVDS") == 0)
4039 if (i
== primary
&& x_get_net_workarea (dpyinfo
, &workarea_r
))
4041 mi
->work
= workarea_r
;
4042 if (! x_intersect_rectangles (&mi
->geom
, &mi
->work
, &mi
->work
))
4043 mi
->work
= mi
->geom
;
4046 mi
->work
= mi
->geom
;
4048 XRRFreeCrtcInfo (crtc
);
4050 XRRFreeOutputInfo (info
);
4052 XRRFreeScreenResources (resources
);
4054 attributes_list
= x_make_monitor_attribute_list (monitors
,
4059 free_monitors (monitors
, n_monitors
);
4060 return attributes_list
;
4062 #endif /* HAVE_XRANDR */
4065 x_get_monitor_attributes (struct x_display_info
*dpyinfo
)
4067 Lisp_Object attributes_list
= Qnil
;
4068 Display
*dpy
= dpyinfo
->display
;
4070 (void) dpy
; /* Suppress unused variable warning. */
4073 int xrr_event_base
, xrr_error_base
;
4074 bool xrr_ok
= false;
4075 xrr_ok
= XRRQueryExtension (dpy
, &xrr_event_base
, &xrr_error_base
);
4078 int xrr_major
, xrr_minor
;
4079 XRRQueryVersion (dpy
, &xrr_major
, &xrr_minor
);
4080 xrr_ok
= (xrr_major
== 1 && xrr_minor
>= 2) || xrr_major
> 1;
4084 attributes_list
= x_get_monitor_attributes_xrandr (dpyinfo
);
4085 #endif /* HAVE_XRANDR */
4087 #ifdef HAVE_XINERAMA
4088 if (NILP (attributes_list
))
4090 int xin_event_base
, xin_error_base
;
4091 bool xin_ok
= false;
4092 xin_ok
= XineramaQueryExtension (dpy
, &xin_event_base
, &xin_error_base
);
4093 if (xin_ok
&& XineramaIsActive (dpy
))
4094 attributes_list
= x_get_monitor_attributes_xinerama (dpyinfo
);
4096 #endif /* HAVE_XINERAMA */
4098 if (NILP (attributes_list
))
4099 attributes_list
= x_get_monitor_attributes_fallback (dpyinfo
);
4101 return attributes_list
;
4104 #endif /* !USE_GTK */
4106 DEFUN ("x-display-monitor-attributes-list", Fx_display_monitor_attributes_list
,
4107 Sx_display_monitor_attributes_list
,
4109 doc
: /* Return a list of physical monitor attributes on the X display TERMINAL.
4111 The optional argument TERMINAL specifies which display to ask about.
4112 TERMINAL should be a terminal object, a frame or a display name (a string).
4113 If omitted or nil, that stands for the selected frame's display.
4115 In addition to the standard attribute keys listed in
4116 `display-monitor-attributes-list', the following keys are contained in
4119 source -- String describing the source from which multi-monitor
4120 information is obtained, one of \"Gdk\", \"XRandr\",
4121 \"Xinerama\", or \"fallback\"
4123 Internal use only, use `display-monitor-attributes-list' instead. */)
4124 (Lisp_Object terminal
)
4126 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4127 Lisp_Object attributes_list
= Qnil
;
4130 double mm_width_per_pixel
, mm_height_per_pixel
;
4133 gint primary_monitor
= 0, n_monitors
, i
;
4134 Lisp_Object monitor_frames
, rest
, frame
;
4135 static const char *source
= "Gdk";
4136 struct MonitorInfo
*monitors
;
4139 mm_width_per_pixel
= ((double) WidthMMOfScreen (dpyinfo
->screen
)
4140 / x_display_pixel_width (dpyinfo
));
4141 mm_height_per_pixel
= ((double) HeightMMOfScreen (dpyinfo
->screen
)
4142 / x_display_pixel_height (dpyinfo
));
4143 gdpy
= gdk_x11_lookup_xdisplay (dpyinfo
->display
);
4144 gscreen
= gdk_display_get_default_screen (gdpy
);
4145 #if GTK_CHECK_VERSION (2, 20, 0)
4146 primary_monitor
= gdk_screen_get_primary_monitor (gscreen
);
4148 n_monitors
= gdk_screen_get_n_monitors (gscreen
);
4149 monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
4150 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
4152 FOR_EACH_FRAME (rest
, frame
)
4154 struct frame
*f
= XFRAME (frame
);
4156 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
4157 && !EQ (frame
, tip_frame
))
4159 GdkWindow
*gwin
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
4161 i
= gdk_screen_get_monitor_at_window (gscreen
, gwin
);
4162 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
4166 for (i
= 0; i
< n_monitors
; ++i
)
4168 gint width_mm
= -1, height_mm
= -1;
4169 GdkRectangle rec
, work
;
4170 struct MonitorInfo
*mi
= &monitors
[i
];
4172 gdk_screen_get_monitor_geometry (gscreen
, i
, &rec
);
4174 #if GTK_CHECK_VERSION (2, 14, 0)
4175 width_mm
= gdk_screen_get_monitor_width_mm (gscreen
, i
);
4176 height_mm
= gdk_screen_get_monitor_height_mm (gscreen
, i
);
4179 width_mm
= rec
.width
* mm_width_per_pixel
+ 0.5;
4181 height_mm
= rec
.height
* mm_height_per_pixel
+ 0.5;
4183 #if GTK_CHECK_VERSION (3, 4, 0)
4184 gdk_screen_get_monitor_workarea (gscreen
, i
, &work
);
4186 /* Emulate the behavior of GTK+ 3.4. */
4188 XRectangle workarea_r
;
4190 if (i
== primary_monitor
&& x_get_net_workarea (dpyinfo
, &workarea_r
))
4192 work
.x
= workarea_r
.x
;
4193 work
.y
= workarea_r
.y
;
4194 work
.width
= workarea_r
.width
;
4195 work
.height
= workarea_r
.height
;
4196 if (! gdk_rectangle_intersect (&rec
, &work
, &work
))
4207 mi
->geom
.width
= rec
.width
;
4208 mi
->geom
.height
= rec
.height
;
4209 mi
->work
.x
= work
.x
;
4210 mi
->work
.y
= work
.y
;
4211 mi
->work
.width
= work
.width
;
4212 mi
->work
.height
= work
.height
;
4213 mi
->mm_width
= width_mm
;
4214 mi
->mm_height
= height_mm
;
4216 #if GTK_CHECK_VERSION (2, 14, 0)
4217 mi
->name
= gdk_screen_get_monitor_plug_name (gscreen
, i
);
4221 attributes_list
= make_monitor_attribute_list (monitors
,
4227 #else /* not USE_GTK */
4230 attributes_list
= x_get_monitor_attributes (dpyinfo
);
4233 #endif /* not USE_GTK */
4235 return attributes_list
;
4238 DEFUN ("x-frame-geometry", Fx_frame_geometry
, Sx_frame_geometry
, 0, 1, 0,
4239 doc
: /* Return geometric attributes of frame FRAME.
4241 FRAME must be a live frame and defaults to the selected one.
4243 The return value is an association list containing the following
4244 elements (all size values are in pixels).
4246 - `frame-outer-size' is a cons of the outer width and height of FRAME.
4247 The outer size include the title bar and the external borders as well
4248 as any menu and/or tool bar of frame.
4250 - `border' is a cons of the horizontal and vertical width of FRAME's
4253 - `title-bar-height' is the height of the title bar of FRAME.
4255 - `menu-bar-external' if `t' means the menu bar is external (not
4256 included in the inner edges of FRAME).
4258 - `menu-bar-size' is a cons of the width and height of the menu bar of
4261 - `tool-bar-external' if `t' means the tool bar is external (not
4262 included in the inner edges of FRAME).
4264 - `tool-bar-side' tells tells on which side the tool bar on FRAME is and
4265 can be one of `left', `top', `right' or `bottom'.
4267 - `tool-bar-size' is a cons of the width and height of the tool bar of
4270 - `frame-inner-size' is a cons of the inner width and height of FRAME.
4271 This excludes FRAME's title bar and external border as well as any
4272 external menu and/or tool bar. */)
4275 struct frame
*f
= decode_live_frame (frame
);
4276 int inner_width
= FRAME_PIXEL_WIDTH (f
);
4277 int inner_height
= FRAME_PIXEL_HEIGHT (f
);
4278 int outer_width
, outer_height
, border
, title
;
4279 Lisp_Object fullscreen
= Fframe_parameter (frame
, Qfullscreen
);
4280 int menu_bar_height
, menu_bar_width
, tool_bar_height
, tool_bar_width
;
4282 border
= FRAME_OUTER_TO_INNER_DIFF_X (f
);
4283 title
= FRAME_X_OUTPUT (f
)->y_pixels_outer_diff
- border
;
4285 outer_width
= FRAME_PIXEL_WIDTH (f
) + 2 * border
;
4286 outer_height
= (FRAME_PIXEL_HEIGHT (f
)
4287 + FRAME_OUTER_TO_INNER_DIFF_Y (f
)
4288 + FRAME_OUTER_TO_INNER_DIFF_X (f
));
4290 #if defined (USE_GTK)
4292 bool tool_bar_left_right
= (EQ (FRAME_TOOL_BAR_POSITION (f
), Qleft
)
4293 || EQ (FRAME_TOOL_BAR_POSITION (f
), Qright
));
4295 tool_bar_width
= (tool_bar_left_right
4296 ? FRAME_TOOLBAR_WIDTH (f
)
4297 : FRAME_PIXEL_WIDTH (f
));
4298 tool_bar_height
= (tool_bar_left_right
4299 ? FRAME_PIXEL_HEIGHT (f
)
4300 : FRAME_TOOLBAR_HEIGHT (f
));
4301 if (tool_bar_left_right
)
4302 /* For some reason FRAME_OUTER_TO_INNER_DIFF_X does not count the
4303 width of a tool bar. */
4304 outer_width
+= FRAME_TOOLBAR_WIDTH (f
);
4307 tool_bar_height
= FRAME_TOOL_BAR_HEIGHT (f
);
4308 tool_bar_width
= ((tool_bar_height
> 0)
4309 ? outer_width
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
)
4313 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
4314 menu_bar_height
= FRAME_MENUBAR_HEIGHT (f
);
4316 menu_bar_height
= FRAME_MENU_BAR_HEIGHT (f
);
4319 menu_bar_width
= ((menu_bar_height
> 0)
4320 ? outer_width
- 2 * border
4323 if (!FRAME_EXTERNAL_MENU_BAR (f
))
4324 inner_height
-= menu_bar_height
;
4325 if (!FRAME_EXTERNAL_TOOL_BAR (f
))
4326 inner_height
-= tool_bar_height
;
4329 listn (CONSTYPE_HEAP
, 10,
4330 Fcons (Qframe_position
,
4331 Fcons (make_number (f
->left_pos
), make_number (f
->top_pos
))),
4332 Fcons (Qframe_outer_size
,
4333 Fcons (make_number (outer_width
), make_number (outer_height
))),
4334 Fcons (Qexternal_border_size
,
4335 ((EQ (fullscreen
, Qfullboth
) || EQ (fullscreen
, Qfullscreen
))
4336 ? Fcons (make_number (0), make_number (0))
4337 : Fcons (make_number (border
), make_number (border
)))),
4338 Fcons (Qtitle_height
,
4339 ((EQ (fullscreen
, Qfullboth
) || EQ (fullscreen
, Qfullscreen
))
4341 : make_number (title
))),
4342 Fcons (Qmenu_bar_external
, FRAME_EXTERNAL_MENU_BAR (f
) ? Qt
: Qnil
),
4343 Fcons (Qmenu_bar_size
,
4344 Fcons (make_number (menu_bar_width
),
4345 make_number (menu_bar_height
))),
4346 Fcons (Qtool_bar_external
, FRAME_EXTERNAL_TOOL_BAR (f
) ? Qt
: Qnil
),
4347 Fcons (Qtool_bar_position
, FRAME_TOOL_BAR_POSITION (f
)),
4348 Fcons (Qtool_bar_size
,
4349 Fcons (make_number (tool_bar_width
),
4350 make_number (tool_bar_height
))),
4351 Fcons (Qframe_inner_size
,
4352 Fcons (make_number (inner_width
),
4353 make_number (inner_height
))));
4356 /************************************************************************
4358 ************************************************************************/
4361 /* Mapping visual names to visuals. */
4363 static struct visual_class
4370 {"StaticGray", StaticGray
},
4371 {"GrayScale", GrayScale
},
4372 {"StaticColor", StaticColor
},
4373 {"PseudoColor", PseudoColor
},
4374 {"TrueColor", TrueColor
},
4375 {"DirectColor", DirectColor
},
4380 #ifndef HAVE_XSCREENNUMBEROFSCREEN
4382 /* Value is the screen number of screen SCR. This is a substitute for
4383 the X function with the same name when that doesn't exist. */
4386 XScreenNumberOfScreen (scr
)
4387 register Screen
*scr
;
4389 Display
*dpy
= scr
->display
;
4392 for (i
= 0; i
< dpy
->nscreens
; ++i
)
4393 if (scr
== dpy
->screens
+ i
)
4399 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
4402 /* Select the visual that should be used on display DPYINFO. Set
4403 members of DPYINFO appropriately. Called from x_term_init. */
4406 select_visual (struct x_display_info
*dpyinfo
)
4408 Display
*dpy
= dpyinfo
->display
;
4409 Screen
*screen
= dpyinfo
->screen
;
4411 /* See if a visual is specified. */
4412 AUTO_STRING (visualClass
, "visualClass");
4413 AUTO_STRING (VisualClass
, "VisualClass");
4414 Lisp_Object value
= display_x_get_resource (dpyinfo
, visualClass
,
4415 VisualClass
, Qnil
, Qnil
);
4417 if (STRINGP (value
))
4419 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
4420 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
4421 depth, a decimal number. NAME is compared with case ignored. */
4422 char *s
= alloca (SBYTES (value
) + 1);
4427 lispstpcpy (s
, value
);
4428 dash
= strchr (s
, '-');
4431 dpyinfo
->n_planes
= atoi (dash
+ 1);
4435 /* We won't find a matching visual with depth 0, so that
4436 an error will be printed below. */
4437 dpyinfo
->n_planes
= 0;
4439 /* Determine the visual class. */
4440 for (i
= 0; visual_classes
[i
].name
; ++i
)
4441 if (xstrcasecmp (s
, visual_classes
[i
].name
) == 0)
4443 class = visual_classes
[i
].class;
4447 /* Look up a matching visual for the specified class. */
4449 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
4450 dpyinfo
->n_planes
, class, &vinfo
))
4451 fatal ("Invalid visual specification `%s'", SDATA (value
));
4453 dpyinfo
->visual
= vinfo
.visual
;
4458 XVisualInfo
*vinfo
, vinfo_template
;
4460 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
4462 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
4463 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
4464 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
4465 &vinfo_template
, &n_visuals
);
4467 fatal ("Can't get proper X visual info");
4469 dpyinfo
->n_planes
= vinfo
->depth
;
4475 /* Return the X display structure for the display named NAME.
4476 Open a new connection if necessary. */
4478 static struct x_display_info
*
4479 x_display_info_for_name (Lisp_Object name
)
4481 struct x_display_info
*dpyinfo
;
4483 CHECK_STRING (name
);
4485 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
4486 if (!NILP (Fstring_equal (XCAR (dpyinfo
->name_list_element
), name
)))
4489 /* Use this general default value to start with. */
4490 Vx_resource_name
= Vinvocation_name
;
4492 validate_x_resource_name ();
4494 dpyinfo
= x_term_init (name
, 0, SSDATA (Vx_resource_name
));
4497 error ("Cannot connect to X server %s", SDATA (name
));
4499 XSETFASTINT (Vwindow_system_version
, 11);
4505 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4507 doc
: /* Open a connection to a display server.
4508 DISPLAY is the name of the display to connect to.
4509 Optional second arg XRM-STRING is a string of resources in xrdb format.
4510 If the optional third arg MUST-SUCCEED is non-nil,
4511 terminate Emacs if we can't open the connection.
4512 \(In the Nextstep version, the last two arguments are currently ignored.) */)
4513 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
4516 struct x_display_info
*dpyinfo
;
4518 CHECK_STRING (display
);
4519 if (! NILP (xrm_string
))
4520 CHECK_STRING (xrm_string
);
4522 xrm_option
= NILP (xrm_string
) ? 0 : SSDATA (xrm_string
);
4524 validate_x_resource_name ();
4526 /* This is what opens the connection and sets x_current_display.
4527 This also initializes many symbols, such as those used for input. */
4528 dpyinfo
= x_term_init (display
, xrm_option
,
4529 SSDATA (Vx_resource_name
));
4533 if (!NILP (must_succeed
))
4534 fatal ("Cannot connect to X server %s.\n\
4535 Check the DISPLAY environment variable or use `-d'.\n\
4536 Also use the `xauth' program to verify that you have the proper\n\
4537 authorization information needed to connect the X server.\n\
4538 An insecure way to solve the problem may be to use `xhost'.\n",
4541 error ("Cannot connect to X server %s", SDATA (display
));
4544 XSETFASTINT (Vwindow_system_version
, 11);
4548 DEFUN ("x-close-connection", Fx_close_connection
,
4549 Sx_close_connection
, 1, 1, 0,
4550 doc
: /* Close the connection to TERMINAL's X server.
4551 For TERMINAL, specify a terminal object, a frame or a display name (a
4552 string). If TERMINAL is nil, that stands for the selected frame's
4554 (Lisp_Object terminal
)
4556 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4558 if (dpyinfo
->reference_count
> 0)
4559 error ("Display still has frames on it");
4561 x_delete_terminal (dpyinfo
->terminal
);
4566 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4567 doc
: /* Return the list of display names that Emacs has connections to. */)
4570 Lisp_Object result
= Qnil
;
4571 struct x_display_info
*xdi
;
4573 for (xdi
= x_display_list
; xdi
; xdi
= xdi
->next
)
4574 result
= Fcons (XCAR (xdi
->name_list_element
), result
);
4579 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4580 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
4581 This function only has an effect on X Windows. With MS Windows, it is
4582 defined but does nothing.
4584 If ON is nil, allow buffering of requests.
4585 Turning on synchronization prohibits the Xlib routines from buffering
4586 requests and seriously degrades performance, but makes debugging much
4588 The optional second argument TERMINAL specifies which display to act on.
4589 TERMINAL should be a terminal object, a frame or a display name (a string).
4590 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
4591 (Lisp_Object on
, Lisp_Object terminal
)
4593 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4595 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
4600 /* Wait for responses to all X commands issued so far for frame F. */
4603 x_sync (struct frame
*f
)
4606 XSync (FRAME_X_DISPLAY (f
), False
);
4611 /***********************************************************************
4613 ***********************************************************************/
4615 DEFUN ("x-change-window-property", Fx_change_window_property
,
4616 Sx_change_window_property
, 2, 6, 0,
4617 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
4618 PROP must be a string. VALUE may be a string or a list of conses,
4619 numbers and/or strings. If an element in the list is a string, it is
4620 converted to an atom and the value of the atom is used. If an element
4621 is a cons, it is converted to a 32 bit number where the car is the 16
4622 top bits and the cdr is the lower 16 bits.
4624 FRAME nil or omitted means use the selected frame.
4625 If TYPE is given and non-nil, it is the name of the type of VALUE.
4626 If TYPE is not given or nil, the type is STRING.
4627 FORMAT gives the size in bits of each element if VALUE is a list.
4628 It must be one of 8, 16 or 32.
4629 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4630 If OUTER-P is non-nil, the property is changed for the outer X window of
4631 FRAME. Default is to change on the edit X window. */)
4632 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
,
4633 Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
4635 struct frame
*f
= decode_window_system_frame (frame
);
4637 Atom target_type
= XA_STRING
;
4638 int element_format
= 8;
4639 unsigned char *data
;
4643 CHECK_STRING (prop
);
4645 if (! NILP (format
))
4647 CHECK_NUMBER (format
);
4649 if (XINT (format
) != 8 && XINT (format
) != 16
4650 && XINT (format
) != 32)
4651 error ("FORMAT must be one of 8, 16 or 32");
4652 element_format
= XINT (format
);
4659 nelements
= x_check_property_data (value
);
4660 if (nelements
== -1)
4661 error ("Bad data in VALUE, must be number, string or cons");
4663 /* The man page for XChangeProperty:
4664 "If the specified format is 32, the property data must be a
4666 This applies even if long is more than 32 bits. The X library
4667 converts to 32 bits before sending to the X server. */
4668 elsize
= element_format
== 32 ? sizeof (long) : element_format
>> 3;
4669 data
= xnmalloc (nelements
, elsize
);
4671 x_fill_property_data (FRAME_X_DISPLAY (f
), value
, data
, element_format
);
4675 CHECK_STRING (value
);
4676 data
= SDATA (value
);
4677 if (INT_MAX
< SBYTES (value
))
4678 error ("VALUE too long");
4679 nelements
= SBYTES (value
);
4683 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4686 CHECK_STRING (type
);
4687 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
4690 if (! NILP (outer_p
)) w
= FRAME_OUTER_WINDOW (f
);
4691 else w
= FRAME_X_WINDOW (f
);
4693 XChangeProperty (FRAME_X_DISPLAY (f
), w
,
4694 prop_atom
, target_type
, element_format
, PropModeReplace
,
4697 if (CONSP (value
)) xfree (data
);
4699 /* Make sure the property is set when we return. */
4700 XFlush (FRAME_X_DISPLAY (f
));
4707 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
4708 Sx_delete_window_property
, 1, 2, 0,
4709 doc
: /* Remove window property PROP from X window of FRAME.
4710 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4711 (Lisp_Object prop
, Lisp_Object frame
)
4713 struct frame
*f
= decode_window_system_frame (frame
);
4716 CHECK_STRING (prop
);
4718 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4719 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
4721 /* Make sure the property is removed when we return. */
4722 XFlush (FRAME_X_DISPLAY (f
));
4730 x_window_property_intern (struct frame
*f
,
4731 Window target_window
,
4734 Lisp_Object delete_p
,
4735 Lisp_Object vector_ret_p
,
4738 unsigned char *tmp_data
= NULL
;
4739 Lisp_Object prop_value
= Qnil
;
4742 unsigned long actual_size
, bytes_remaining
;
4744 struct gcpro gcpro1
;
4746 GCPRO1 (prop_value
);
4748 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4749 prop_atom
, 0, 0, False
, target_type
,
4750 &actual_type
, &actual_format
, &actual_size
,
4751 &bytes_remaining
, &tmp_data
);
4753 *found
= actual_format
!= 0;
4755 if (rc
== Success
&& *found
)
4760 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4761 prop_atom
, 0, bytes_remaining
,
4762 ! NILP (delete_p
), target_type
,
4763 &actual_type
, &actual_format
,
4764 &actual_size
, &bytes_remaining
,
4766 if (rc
== Success
&& tmp_data
)
4768 /* The man page for XGetWindowProperty says:
4769 "If the returned format is 32, the returned data is represented
4770 as a long array and should be cast to that type to obtain the
4772 This applies even if long is more than 32 bits, the X library
4773 converts from 32 bit elements received from the X server to long
4774 and passes the long array to us. Thus, for that case memcpy can not
4775 be used. We convert to a 32 bit type here, because so much code
4778 The bytes and offsets passed to XGetWindowProperty refers to the
4779 property and those are indeed in 32 bit quantities if format is
4782 if (BITS_PER_LONG
> 32 && actual_format
== 32)
4785 int *idata
= (int *) tmp_data
;
4786 long *ldata
= (long *) tmp_data
;
4788 for (i
= 0; i
< actual_size
; ++i
)
4789 idata
[i
] = (int) ldata
[i
];
4792 if (NILP (vector_ret_p
))
4793 prop_value
= make_string ((char *) tmp_data
, actual_size
);
4795 prop_value
= x_property_data_to_lisp (f
,
4802 if (tmp_data
) XFree (tmp_data
);
4809 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
4811 doc
: /* Value is the value of window property PROP on FRAME.
4812 If FRAME is nil or omitted, use the selected frame.
4814 On X Windows, the following optional arguments are also accepted:
4815 If TYPE is nil or omitted, get the property as a string.
4816 Otherwise TYPE is the name of the atom that denotes the type expected.
4817 If SOURCE is non-nil, get the property on that window instead of from
4818 FRAME. The number 0 denotes the root window.
4819 If DELETE-P is non-nil, delete the property after retrieving it.
4820 If VECTOR-RET-P is non-nil, don't return a string but a vector of values.
4822 On MS Windows, this function accepts but ignores those optional arguments.
4824 Value is nil if FRAME hasn't a property with name PROP or if PROP has
4825 no value of TYPE (always string in the MS Windows case). */)
4826 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
,
4827 Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
4829 struct frame
*f
= decode_window_system_frame (frame
);
4831 Lisp_Object prop_value
= Qnil
;
4832 Atom target_type
= XA_STRING
;
4833 Window target_window
= FRAME_X_WINDOW (f
);
4834 struct gcpro gcpro1
;
4837 GCPRO1 (prop_value
);
4838 CHECK_STRING (prop
);
4840 if (! NILP (source
))
4842 CONS_TO_INTEGER (source
, Window
, target_window
);
4843 if (! target_window
)
4844 target_window
= FRAME_DISPLAY_INFO (f
)->root_window
;
4850 if (strcmp ("AnyPropertyType", SSDATA (type
)) == 0)
4851 target_type
= AnyPropertyType
;
4853 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
4856 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4857 prop_value
= x_window_property_intern (f
,
4864 if (NILP (prop_value
)
4867 && target_window
!= FRAME_OUTER_WINDOW (f
))
4869 prop_value
= x_window_property_intern (f
,
4870 FRAME_OUTER_WINDOW (f
),
4884 /***********************************************************************
4886 ***********************************************************************/
4888 static Lisp_Object
x_create_tip_frame (struct x_display_info
*,
4889 Lisp_Object
, Lisp_Object
);
4890 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
4891 Lisp_Object
, int, int, int *, int *);
4893 /* The frame of a currently visible tooltip. */
4895 Lisp_Object tip_frame
;
4897 /* If non-nil, a timer started that hides the last tooltip when it
4900 static Lisp_Object tip_timer
;
4903 /* If non-nil, a vector of 3 elements containing the last args
4904 with which x-show-tip was called. See there. */
4906 static Lisp_Object last_show_tip_args
;
4910 unwind_create_tip_frame (Lisp_Object frame
)
4912 Lisp_Object deleted
;
4914 deleted
= unwind_create_frame (frame
);
4915 if (EQ (deleted
, Qt
))
4923 /* Create a frame for a tooltip on the display described by DPYINFO.
4924 PARMS is a list of frame parameters. TEXT is the string to
4925 display in the tip frame. Value is the frame.
4927 Note that functions called here, esp. x_default_parameter can
4928 signal errors, for instance when a specified color name is
4929 undefined. We have to make sure that we're in a consistent state
4930 when this happens. */
4933 x_create_tip_frame (struct x_display_info
*dpyinfo
,
4941 ptrdiff_t count
= SPECPDL_INDEX ();
4942 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4943 bool face_change_before
= face_change
;
4945 struct buffer
*old_buffer
;
4947 if (!dpyinfo
->terminal
->name
)
4948 error ("Terminal is not live, can't create new frames on it");
4950 parms
= Fcopy_alist (parms
);
4952 /* Get the name of the frame to use for resource lookup. */
4953 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
4955 && !EQ (name
, Qunbound
)
4957 error ("Invalid frame name--not a string or nil");
4960 GCPRO3 (parms
, name
, frame
);
4961 f
= make_frame (true);
4962 XSETFRAME (frame
, f
);
4964 AUTO_STRING (tip
, " *tip*");
4965 buffer
= Fget_buffer_create (tip
);
4966 /* Use set_window_buffer instead of Fset_window_buffer (see
4967 discussion of bug#11984, bug#12025, bug#12026). */
4968 set_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, false, false);
4969 old_buffer
= current_buffer
;
4970 set_buffer_internal_1 (XBUFFER (buffer
));
4971 bset_truncate_lines (current_buffer
, Qnil
);
4972 specbind (Qinhibit_read_only
, Qt
);
4973 specbind (Qinhibit_modification_hooks
, Qt
);
4976 set_buffer_internal_1 (old_buffer
);
4978 record_unwind_protect (unwind_create_tip_frame
, frame
);
4980 f
->terminal
= dpyinfo
->terminal
;
4982 /* By setting the output method, we're essentially saying that
4983 the frame is live, as per FRAME_LIVE_P. If we get a signal
4984 from this point on, x_destroy_window might screw up reference
4986 f
->output_method
= output_x_window
;
4987 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
4988 f
->output_data
.x
->icon_bitmap
= -1;
4989 FRAME_FONTSET (f
) = -1;
4990 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
4991 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
4992 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
4993 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
4994 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
4995 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
4996 f
->output_data
.x
->white_relief
.pixel
= -1;
4997 f
->output_data
.x
->black_relief
.pixel
= -1;
4999 fset_icon_name (f
, Qnil
);
5000 FRAME_DISPLAY_INFO (f
) = dpyinfo
;
5001 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5002 f
->output_data
.x
->explicit_parent
= false;
5004 /* These colors will be set anyway later, but it's important
5005 to get the color reference counts right, so initialize them! */
5008 struct gcpro gcpro1
;
5010 /* Function x_decode_color can signal an error. Make
5011 sure to initialize color slots so that we won't try
5012 to free colors we haven't allocated. */
5013 FRAME_FOREGROUND_PIXEL (f
) = -1;
5014 FRAME_BACKGROUND_PIXEL (f
) = -1;
5015 f
->output_data
.x
->cursor_pixel
= -1;
5016 f
->output_data
.x
->cursor_foreground_pixel
= -1;
5017 f
->output_data
.x
->border_pixel
= -1;
5018 f
->output_data
.x
->mouse_pixel
= -1;
5020 black
= build_string ("black");
5022 FRAME_FOREGROUND_PIXEL (f
)
5023 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5024 FRAME_BACKGROUND_PIXEL (f
)
5025 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5026 f
->output_data
.x
->cursor_pixel
5027 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5028 f
->output_data
.x
->cursor_foreground_pixel
5029 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5030 f
->output_data
.x
->border_pixel
5031 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5032 f
->output_data
.x
->mouse_pixel
5033 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5037 /* Set the name; the functions to which we pass f expect the name to
5039 if (EQ (name
, Qunbound
) || NILP (name
))
5041 fset_name (f
, build_string (dpyinfo
->x_id_name
));
5042 f
->explicit_name
= false;
5046 fset_name (f
, name
);
5047 f
->explicit_name
= true;
5048 /* use the frame's title when getting resources for this frame. */
5049 specbind (Qx_resource_name
, name
);
5052 register_font_driver (&xfont_driver
, f
);
5053 #ifdef HAVE_FREETYPE
5055 register_font_driver (&xftfont_driver
, f
);
5056 #else /* not HAVE_XFT */
5057 register_font_driver (&ftxfont_driver
, f
);
5058 #endif /* not HAVE_XFT */
5059 #endif /* HAVE_FREETYPE */
5061 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5062 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5064 /* Extract the window parameters from the supplied values that are
5065 needed to determine window geometry. */
5066 x_default_font_parameter (f
, parms
);
5068 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
5069 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5071 /* This defaults to 2 in order to match xterm. We recognize either
5072 internalBorderWidth or internalBorder (which is what xterm calls
5074 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5078 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5079 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5080 if (! EQ (value
, Qunbound
))
5081 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5085 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5086 "internalBorderWidth", "internalBorderWidth",
5088 x_default_parameter (f
, parms
, Qright_divider_width
, make_number (0),
5089 NULL
, NULL
, RES_TYPE_NUMBER
);
5090 x_default_parameter (f
, parms
, Qbottom_divider_width
, make_number (0),
5091 NULL
, NULL
, RES_TYPE_NUMBER
);
5093 /* Also do the stuff which must be set before the window exists. */
5094 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5095 "foreground", "Foreground", RES_TYPE_STRING
);
5096 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5097 "background", "Background", RES_TYPE_STRING
);
5098 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5099 "pointerColor", "Foreground", RES_TYPE_STRING
);
5100 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5101 "cursorColor", "Foreground", RES_TYPE_STRING
);
5102 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5103 "borderColor", "BorderColor", RES_TYPE_STRING
);
5106 image_cache_refcount
=
5107 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
5108 dpyinfo_refcount
= dpyinfo
->reference_count
;
5109 #endif /* GLYPH_DEBUG */
5111 /* Init faces before x_default_parameter is called for the
5112 scroll-bar-width parameter because otherwise we end up in
5113 init_iterator with a null face cache, which should not happen. */
5114 init_frame_faces (f
);
5116 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5118 x_figure_window_size (f
, parms
, false);
5121 XSetWindowAttributes attrs
;
5123 Atom type
= FRAME_DISPLAY_INFO (f
)->Xatom_net_window_type_tooltip
;
5126 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
;
5127 if (DoesSaveUnders (dpyinfo
->screen
))
5128 mask
|= CWSaveUnder
;
5130 /* Window managers look at the override-redirect flag to determine
5131 whether or net to give windows a decoration (Xlib spec, chapter
5133 attrs
.override_redirect
= True
;
5134 attrs
.save_under
= True
;
5135 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
5136 /* Arrange for getting MapNotify and UnmapNotify events. */
5137 attrs
.event_mask
= StructureNotifyMask
;
5139 = FRAME_X_WINDOW (f
)
5140 = XCreateWindow (FRAME_X_DISPLAY (f
),
5141 FRAME_DISPLAY_INFO (f
)->root_window
,
5142 /* x, y, width, height */
5146 CopyFromParent
, InputOutput
, CopyFromParent
,
5148 XChangeProperty (FRAME_X_DISPLAY (f
), tip_window
,
5149 FRAME_DISPLAY_INFO (f
)->Xatom_net_window_type
,
5150 XA_ATOM
, 32, PropModeReplace
,
5151 (unsigned char *)&type
, 1);
5157 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5158 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5159 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5160 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5161 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5162 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5164 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
5165 Change will not be effected unless different from the current
5167 width
= FRAME_COLS (f
);
5168 height
= FRAME_LINES (f
);
5169 SET_FRAME_COLS (f
, 0);
5170 SET_FRAME_LINES (f
, 0);
5171 change_frame_size (f
, width
, height
, true, false, false, false);
5173 /* Add `tooltip' frame parameter's default value. */
5174 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5176 AUTO_FRAME_ARG (arg
, Qtooltip
, Qt
);
5177 Fmodify_frame_parameters (frame
, arg
);
5180 /* FIXME - can this be done in a similar way to normal frames?
5181 http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00641.html */
5183 /* Set the `display-type' frame parameter before setting up faces. */
5185 Lisp_Object disptype
;
5187 if (FRAME_DISPLAY_INFO (f
)->n_planes
== 1)
5188 disptype
= intern ("mono");
5189 else if (FRAME_DISPLAY_INFO (f
)->visual
->class == GrayScale
5190 || FRAME_DISPLAY_INFO (f
)->visual
->class == StaticGray
)
5191 disptype
= intern ("grayscale");
5193 disptype
= intern ("color");
5195 if (NILP (Fframe_parameter (frame
, Qdisplay_type
)))
5197 AUTO_FRAME_ARG (arg
, Qdisplay_type
, disptype
);
5198 Fmodify_frame_parameters (frame
, arg
);
5202 /* Set up faces after all frame parameters are known. This call
5203 also merges in face attributes specified for new frames.
5205 Frame parameters may be changed if .Xdefaults contains
5206 specifications for the default font. For example, if there is an
5207 `Emacs.default.attributeBackground: pink', the `background-color'
5208 attribute of the frame get's set, which let's the internal border
5209 of the tooltip frame appear in pink. Prevent this. */
5211 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5213 /* Set tip_frame here, so that */
5215 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5217 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5219 AUTO_FRAME_ARG (arg
, Qbackground_color
, bg
);
5220 Fmodify_frame_parameters (frame
, arg
);
5228 /* Now that the frame will be official, it counts as a reference to
5229 its display and terminal. */
5230 FRAME_DISPLAY_INFO (f
)->reference_count
++;
5231 f
->terminal
->reference_count
++;
5233 /* It is now ok to make the frame official even if we get an error
5234 below. And the frame needs to be on Vframe_list or making it
5235 visible won't work. */
5236 Vframe_list
= Fcons (frame
, Vframe_list
);
5237 f
->can_x_set_window_size
= true;
5239 /* Setting attributes of faces of the tooltip frame from resources
5240 and similar will set face_change, which leads to the clearing of
5241 all current matrices. Since this isn't necessary here, avoid it
5242 by resetting face_change to the value it had before we created
5244 face_change
= face_change_before
;
5246 /* Discard the unwind_protect. */
5247 return unbind_to (count
, frame
);
5251 /* Compute where to display tip frame F. PARMS is the list of frame
5252 parameters for F. DX and DY are specified offsets from the current
5253 location of the mouse. WIDTH and HEIGHT are the width and height
5254 of the tooltip. Return coordinates relative to the root window of
5255 the display in *ROOT_X, and *ROOT_Y. */
5258 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
)
5260 Lisp_Object left
, top
;
5265 /* User-specified position? */
5266 left
= Fcdr (Fassq (Qleft
, parms
));
5267 top
= Fcdr (Fassq (Qtop
, parms
));
5269 /* Move the tooltip window where the mouse pointer is. Resize and
5271 if (!INTEGERP (left
) || !INTEGERP (top
))
5274 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_DISPLAY_INFO (f
)->root_window
,
5275 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
5280 *root_y
= XINT (top
);
5281 else if (*root_y
+ XINT (dy
) <= 0)
5282 *root_y
= 0; /* Can happen for negative dy */
5283 else if (*root_y
+ XINT (dy
) + height
5284 <= x_display_pixel_height (FRAME_DISPLAY_INFO (f
)))
5285 /* It fits below the pointer */
5286 *root_y
+= XINT (dy
);
5287 else if (height
+ XINT (dy
) <= *root_y
)
5288 /* It fits above the pointer. */
5289 *root_y
-= height
+ XINT (dy
);
5291 /* Put it on the top. */
5294 if (INTEGERP (left
))
5295 *root_x
= XINT (left
);
5296 else if (*root_x
+ XINT (dx
) <= 0)
5297 *root_x
= 0; /* Can happen for negative dx */
5298 else if (*root_x
+ XINT (dx
) + width
5299 <= x_display_pixel_width (FRAME_DISPLAY_INFO (f
)))
5300 /* It fits to the right of the pointer. */
5301 *root_x
+= XINT (dx
);
5302 else if (width
+ XINT (dx
) <= *root_x
)
5303 /* It fits to the left of the pointer. */
5304 *root_x
-= width
+ XINT (dx
);
5306 /* Put it left-justified on the screen--it ought to fit that way. */
5311 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5312 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
5313 A tooltip window is a small X window displaying a string.
5315 This is an internal function; Lisp code should call `tooltip-show'.
5317 FRAME nil or omitted means use the selected frame.
5319 PARMS is an optional list of frame parameters which can be used to
5320 change the tooltip's appearance.
5322 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5323 means use the default timeout of 5 seconds.
5325 If the list of frame parameters PARMS contains a `left' parameters,
5326 the tooltip is displayed at that x-position. Otherwise it is
5327 displayed at the mouse position, with offset DX added (default is 5 if
5328 DX isn't specified). Likewise for the y-position; if a `top' frame
5329 parameter is specified, it determines the y-position of the tooltip
5330 window, otherwise it is displayed at the mouse position, with offset
5331 DY added (default is -10).
5333 A tooltip's maximum size is specified by `x-max-tooltip-size'.
5334 Text larger than the specified size is clipped. */)
5335 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
5340 struct buffer
*old_buffer
;
5341 struct text_pos pos
;
5342 int i
, width
, height
;
5343 bool seen_reversed_p
;
5344 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5345 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5346 ptrdiff_t count
= SPECPDL_INDEX ();
5348 specbind (Qinhibit_redisplay
, Qt
);
5350 GCPRO4 (string
, parms
, frame
, timeout
);
5352 CHECK_STRING (string
);
5353 if (SCHARS (string
) == 0)
5354 string
= make_unibyte_string (" ", 1);
5356 f
= decode_window_system_frame (frame
);
5358 timeout
= make_number (5);
5360 CHECK_NATNUM (timeout
);
5363 dx
= make_number (5);
5368 dy
= make_number (-10);
5373 if (x_gtk_use_system_tooltips
)
5377 /* Hide a previous tip, if any. */
5381 ok
= xg_prepare_tooltip (f
, string
, &width
, &height
);
5384 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5385 xg_show_tooltip (f
, root_x
, root_y
);
5386 /* This is used in Fx_hide_tip. */
5387 XSETFRAME (tip_frame
, f
);
5390 if (ok
) goto start_timer
;
5392 #endif /* USE_GTK */
5394 if (NILP (last_show_tip_args
))
5395 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5397 if (!NILP (tip_frame
))
5399 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5400 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5401 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5403 if (EQ (frame
, last_frame
)
5404 && !NILP (Fequal (last_string
, string
))
5405 && !NILP (Fequal (last_parms
, parms
)))
5407 struct frame
*tip_f
= XFRAME (tip_frame
);
5409 /* Only DX and DY have changed. */
5410 if (!NILP (tip_timer
))
5412 Lisp_Object timer
= tip_timer
;
5414 call1 (Qcancel_timer
, timer
);
5418 compute_tip_xy (tip_f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (tip_f
),
5419 FRAME_PIXEL_HEIGHT (tip_f
), &root_x
, &root_y
);
5420 XMoveWindow (FRAME_X_DISPLAY (tip_f
), FRAME_X_WINDOW (tip_f
),
5427 /* Hide a previous tip, if any. */
5430 ASET (last_show_tip_args
, 0, string
);
5431 ASET (last_show_tip_args
, 1, frame
);
5432 ASET (last_show_tip_args
, 2, parms
);
5434 /* Add default values to frame parameters. */
5435 if (NILP (Fassq (Qname
, parms
)))
5436 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5437 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5438 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5439 if (NILP (Fassq (Qborder_width
, parms
)))
5440 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5441 if (NILP (Fassq (Qbottom_divider_width
, parms
)))
5442 parms
= Fcons (Fcons (Qbottom_divider_width
, make_number (0)), parms
);
5443 if (NILP (Fassq (Qright_divider_width
, parms
)))
5444 parms
= Fcons (Fcons (Qright_divider_width
, make_number (0)), parms
);
5445 if (NILP (Fassq (Qborder_color
, parms
)))
5446 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5447 if (NILP (Fassq (Qbackground_color
, parms
)))
5448 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5451 /* Create a frame for the tooltip, and record it in the global
5452 variable tip_frame. */
5453 frame
= x_create_tip_frame (FRAME_DISPLAY_INFO (f
), parms
, string
);
5456 /* Set up the frame's root window. */
5457 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5463 if (CONSP (Vx_max_tooltip_size
)
5464 && RANGED_INTEGERP (1, XCAR (Vx_max_tooltip_size
), INT_MAX
)
5465 && RANGED_INTEGERP (1, XCDR (Vx_max_tooltip_size
), INT_MAX
))
5467 w
->total_cols
= XFASTINT (XCAR (Vx_max_tooltip_size
));
5468 w
->total_lines
= XFASTINT (XCDR (Vx_max_tooltip_size
));
5473 w
->total_lines
= 40;
5476 w
->pixel_width
= w
->total_cols
* FRAME_COLUMN_WIDTH (f
);
5477 w
->pixel_height
= w
->total_lines
* FRAME_LINE_HEIGHT (f
);
5479 FRAME_TOTAL_COLS (f
) = w
->total_cols
;
5480 adjust_frame_glyphs (f
);
5481 w
->pseudo_window_p
= true;
5483 /* Display the tooltip text in a temporary buffer. */
5484 old_buffer
= current_buffer
;
5485 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->contents
));
5486 bset_truncate_lines (current_buffer
, Qnil
);
5487 clear_glyph_matrix (w
->desired_matrix
);
5488 clear_glyph_matrix (w
->current_matrix
);
5489 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5490 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5492 /* Compute width and height of the tooltip. */
5494 seen_reversed_p
= false;
5495 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5497 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5501 /* Stop at the first empty row at the end. */
5502 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5505 /* Let the row go over the full width of the frame. */
5506 row
->full_width_p
= true;
5508 row_width
= row
->pixel_width
;
5509 if (row
->used
[TEXT_AREA
])
5511 /* There's a glyph at the end of rows that is used to place
5512 the cursor there. Don't include the width of this glyph. */
5513 if (!row
->reversed_p
)
5515 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5516 if (NILP (last
->object
))
5517 row_width
-= last
->pixel_width
;
5521 /* There could be a stretch glyph at the beginning of R2L
5522 rows that is produced by extend_face_to_end_of_line.
5523 Don't count that glyph. */
5524 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
5526 if (g
->type
== STRETCH_GLYPH
&& NILP (g
->object
))
5528 row_width
-= g
->pixel_width
;
5529 seen_reversed_p
= true;
5534 height
+= row
->height
;
5535 width
= max (width
, row_width
);
5538 /* If we've seen partial-length R2L rows, we need to re-adjust the
5539 tool-tip frame width and redisplay it again, to avoid over-wide
5540 tips due to the stretch glyph that extends R2L lines to full
5541 width of the frame. */
5542 if (seen_reversed_p
)
5544 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns,
5546 w
->pixel_width
= width
;
5547 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
5548 w
->total_cols
= width
;
5549 FRAME_TOTAL_COLS (f
) = width
;
5550 SET_FRAME_WIDTH (f
, width
);
5551 adjust_frame_glyphs (f
);
5552 clear_glyph_matrix (w
->desired_matrix
);
5553 clear_glyph_matrix (w
->current_matrix
);
5554 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
5556 /* Recompute width and height of the tooltip. */
5557 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5559 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5563 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5565 row
->full_width_p
= true;
5566 row_width
= row
->pixel_width
;
5567 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
5569 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5570 if (NILP (last
->object
))
5571 row_width
-= last
->pixel_width
;
5574 height
+= row
->height
;
5575 width
= max (width
, row_width
);
5579 /* Add the frame's internal border to the width and height the X
5580 window should have. */
5581 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5582 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5584 /* Move the tooltip window where the mouse pointer is. Resize and
5586 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5589 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5590 root_x
, root_y
, width
, height
);
5591 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5594 /* Draw into the window. */
5595 w
->must_be_updated_p
= true;
5596 update_single_window (w
);
5598 /* Restore original current buffer. */
5599 set_buffer_internal_1 (old_buffer
);
5600 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5603 /* Let the tip disappear after timeout seconds. */
5604 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5605 intern ("x-hide-tip"));
5608 return unbind_to (count
, Qnil
);
5612 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5613 doc
: /* Hide the current tooltip window, if there is any.
5614 Value is t if tooltip was open, nil otherwise. */)
5618 Lisp_Object deleted
, frame
, timer
;
5619 struct gcpro gcpro1
, gcpro2
;
5621 /* Return quickly if nothing to do. */
5622 if (NILP (tip_timer
) && NILP (tip_frame
))
5627 GCPRO2 (frame
, timer
);
5628 tip_frame
= tip_timer
= deleted
= Qnil
;
5630 count
= SPECPDL_INDEX ();
5631 specbind (Qinhibit_redisplay
, Qt
);
5632 specbind (Qinhibit_quit
, Qt
);
5635 call1 (Qcancel_timer
, timer
);
5639 /* When using system tooltip, tip_frame is the Emacs frame on which
5640 the tip is shown. */
5641 struct frame
*f
= XFRAME (frame
);
5642 if (FRAME_LIVE_P (f
) && xg_hide_tooltip (f
))
5649 delete_frame (frame
, Qnil
);
5653 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5654 redisplay procedure is not called when a tip frame over menu
5655 items is unmapped. Redisplay the menu manually... */
5658 struct frame
*f
= SELECTED_FRAME ();
5659 w
= f
->output_data
.x
->menubar_widget
;
5661 if (!DoesSaveUnders (FRAME_DISPLAY_INFO (f
)->screen
)
5665 xlwmenu_redisplay (w
);
5669 #endif /* USE_LUCID */
5673 return unbind_to (count
, deleted
);
5678 /***********************************************************************
5679 File selection dialog
5680 ***********************************************************************/
5682 DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog
,
5683 Sx_uses_old_gtk_dialog
,
5685 doc
: /* Return t if the old Gtk+ file selection dialog is used. */)
5691 && window_system_available (SELECTED_FRAME ())
5692 && xg_uses_old_file_dialog ())
5700 /* Callback for "OK" and "Cancel" on file selection dialog. */
5703 file_dialog_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5705 int *result
= client_data
;
5706 XmAnyCallbackStruct
*cb
= call_data
;
5707 *result
= cb
->reason
;
5711 /* Callback for unmapping a file selection dialog. This is used to
5712 capture the case where a dialog is closed via a window manager's
5713 closer button, for example. Using a XmNdestroyCallback didn't work
5717 file_dialog_unmap_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5719 int *result
= client_data
;
5720 *result
= XmCR_CANCEL
;
5724 clean_up_file_dialog (void *arg
)
5726 Widget dialog
= arg
;
5730 XtUnmanageChild (dialog
);
5731 XtDestroyWidget (dialog
);
5732 x_menu_set_in_use (false);
5737 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5738 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5739 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5740 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5741 or directory must exist.
5743 This function is only defined on NS, MS Windows, and X Windows with the
5744 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5745 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.
5746 On Windows 7 and later, the file selection dialog "remembers" the last
5747 directory where the user selected a file, and will open that directory
5748 instead of DIR on subsequent invocations of this function with the same
5749 value of DIR as in previous invocations; this is standard Windows behavior. */)
5750 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
,
5751 Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5754 struct frame
*f
= SELECTED_FRAME ();
5755 Lisp_Object file
= Qnil
;
5756 Lisp_Object decoded_file
;
5757 Widget dialog
, text
, help
;
5760 XmString dir_xmstring
, pattern_xmstring
;
5761 ptrdiff_t count
= SPECPDL_INDEX ();
5762 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5764 check_window_system (f
);
5766 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5768 if (popup_activated ())
5769 error ("Trying to use a menu from within a menu-entry");
5771 CHECK_STRING (prompt
);
5774 /* Prevent redisplay. */
5775 specbind (Qinhibit_redisplay
, Qt
);
5779 /* Create the dialog with PROMPT as title, using DIR as initial
5780 directory and using "*" as pattern. */
5781 dir
= Fexpand_file_name (dir
, Qnil
);
5782 dir_xmstring
= XmStringCreateLocalized (SSDATA (dir
));
5783 pattern_xmstring
= XmStringCreateLocalized ("*");
5785 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
5786 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
5787 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
5788 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
5789 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
5790 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
5792 XmStringFree (dir_xmstring
);
5793 XmStringFree (pattern_xmstring
);
5795 /* Add callbacks for OK and Cancel. */
5796 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
5797 (XtPointer
) &result
);
5798 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
5799 (XtPointer
) &result
);
5800 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
5801 (XtPointer
) &result
);
5803 /* Remove the help button since we can't display help. */
5804 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
5805 XtUnmanageChild (help
);
5807 /* Mark OK button as default. */
5808 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
5809 XmNshowAsDefault
, True
, NULL
);
5811 /* If MUSTMATCH is non-nil, disable the file entry field of the
5812 dialog, so that the user must select a file from the files list
5813 box. We can't remove it because we wouldn't have a way to get at
5814 the result file name, then. */
5815 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5816 if (!NILP (mustmatch
))
5819 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
5820 XtSetSensitive (text
, False
);
5821 XtSetSensitive (label
, False
);
5824 /* Manage the dialog, so that list boxes get filled. */
5825 XtManageChild (dialog
);
5827 if (STRINGP (default_filename
))
5829 XmString default_xmstring
;
5830 Widget wtext
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5831 Widget list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
5833 XmTextPosition last_pos
= XmTextFieldGetLastPosition (wtext
);
5834 XmTextFieldReplace (wtext
, 0, last_pos
,
5835 (SSDATA (Ffile_name_nondirectory (default_filename
))));
5837 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5838 must include the path for this to work. */
5840 default_xmstring
= XmStringCreateLocalized (SSDATA (default_filename
));
5842 if (XmListItemExists (list
, default_xmstring
))
5844 int item_pos
= XmListItemPos (list
, default_xmstring
);
5845 /* Select the item and scroll it into view. */
5846 XmListSelectPos (list
, item_pos
, True
);
5847 XmListSetPos (list
, item_pos
);
5850 XmStringFree (default_xmstring
);
5853 record_unwind_protect_ptr (clean_up_file_dialog
, dialog
);
5855 /* Process events until the user presses Cancel or OK. */
5856 x_menu_set_in_use (true);
5861 x_menu_wait_for_event (0);
5862 XtAppNextEvent (Xt_app_con
, &event
);
5863 if (event
.type
== KeyPress
5864 && FRAME_X_DISPLAY (f
) == event
.xkey
.display
)
5866 KeySym keysym
= XLookupKeysym (&event
.xkey
, 0);
5868 /* Pop down on C-g. */
5869 if (keysym
== XK_g
&& (event
.xkey
.state
& ControlMask
) != 0)
5870 XtUnmanageChild (dialog
);
5873 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
));
5876 /* Get the result. */
5877 if (result
== XmCR_OK
)
5879 XmString text_string
;
5882 XtVaGetValues (dialog
, XmNtextString
, &text_string
, NULL
);
5883 XmStringGetLtoR (text_string
, XmFONTLIST_DEFAULT_TAG
, &data
);
5884 XmStringFree (text_string
);
5885 file
= build_string (data
);
5894 /* Make "Cancel" equivalent to C-g. */
5896 Fsignal (Qquit
, Qnil
);
5898 decoded_file
= DECODE_FILE (file
);
5900 return unbind_to (count
, decoded_file
);
5903 #endif /* USE_MOTIF */
5908 clean_up_dialog (void)
5910 x_menu_set_in_use (false);
5913 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5914 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5915 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5916 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5917 or directory must exist.
5919 This function is only defined on NS, MS Windows, and X Windows with the
5920 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5921 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.
5922 On Windows 7 and later, the file selection dialog "remembers" the last
5923 directory where the user selected a file, and will open that directory
5924 instead of DIR on subsequent invocations of this function with the same
5925 value of DIR as in previous invocations; this is standard Windows behavior. */)
5926 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5928 struct frame
*f
= SELECTED_FRAME ();
5930 Lisp_Object file
= Qnil
;
5931 Lisp_Object decoded_file
;
5932 ptrdiff_t count
= SPECPDL_INDEX ();
5933 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5936 check_window_system (f
);
5938 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5940 if (popup_activated ())
5941 error ("Trying to use a menu from within a menu-entry");
5943 CHECK_STRING (prompt
);
5946 /* Prevent redisplay. */
5947 specbind (Qinhibit_redisplay
, Qt
);
5948 record_unwind_protect_void (clean_up_dialog
);
5952 if (STRINGP (default_filename
))
5953 cdef_file
= SSDATA (default_filename
);
5955 cdef_file
= SSDATA (dir
);
5957 fn
= xg_get_file_name (f
, SSDATA (prompt
), cdef_file
,
5959 ! NILP (only_dir_p
));
5963 file
= build_string (fn
);
5970 /* Make "Cancel" equivalent to C-g. */
5972 Fsignal (Qquit
, Qnil
);
5974 decoded_file
= DECODE_FILE (file
);
5976 return unbind_to (count
, decoded_file
);
5980 #ifdef HAVE_FREETYPE
5982 DEFUN ("x-select-font", Fx_select_font
, Sx_select_font
, 0, 2, 0,
5983 doc
: /* Read a font using a GTK dialog.
5984 Return either a font spec (for GTK versions >= 3.2) or a string
5985 containing a GTK-style font name.
5987 FRAME is the frame on which to pop up the font chooser. If omitted or
5988 nil, it defaults to the selected frame. */)
5989 (Lisp_Object frame
, Lisp_Object ignored
)
5991 struct frame
*f
= decode_window_system_frame (frame
);
5993 Lisp_Object font_param
;
5994 char *default_name
= NULL
;
5995 struct gcpro gcpro1
, gcpro2
;
5996 ptrdiff_t count
= SPECPDL_INDEX ();
5998 if (popup_activated ())
5999 error ("Trying to use a menu from within a menu-entry");
6001 /* Prevent redisplay. */
6002 specbind (Qinhibit_redisplay
, Qt
);
6003 record_unwind_protect_void (clean_up_dialog
);
6007 GCPRO2 (font_param
, font
);
6009 XSETFONT (font
, FRAME_FONT (f
));
6010 font_param
= Ffont_get (font
, intern (":name"));
6011 if (STRINGP (font_param
))
6012 default_name
= xlispstrdup (font_param
);
6015 font_param
= Fframe_parameter (frame
, Qfont_param
);
6016 if (STRINGP (font_param
))
6017 default_name
= xlispstrdup (font_param
);
6020 font
= xg_get_font (f
, default_name
);
6021 xfree (default_name
);
6026 Fsignal (Qquit
, Qnil
);
6028 return unbind_to (count
, font
);
6030 #endif /* HAVE_FREETYPE */
6032 #endif /* USE_GTK */
6035 /***********************************************************************
6037 ***********************************************************************/
6040 #include <X11/XKBlib.h>
6041 #include <X11/keysym.h>
6044 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
6045 Sx_backspace_delete_keys_p
, 0, 1, 0,
6046 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
6047 FRAME nil means use the selected frame.
6048 Value is t if we know that both keys are present, and are mapped to the
6049 usual X keysyms. Value is `lambda' if we cannot determine if both keys are
6050 present and mapped to the usual X keysyms. */)
6057 struct frame
*f
= decode_window_system_frame (frame
);
6058 Display
*dpy
= FRAME_X_DISPLAY (f
);
6059 Lisp_Object have_keys
;
6060 int major
, minor
, op
, event
, error_code
;
6064 /* Check library version in case we're dynamically linked. */
6065 major
= XkbMajorVersion
;
6066 minor
= XkbMinorVersion
;
6067 if (!XkbLibraryVersion (&major
, &minor
))
6073 /* Check that the server supports XKB. */
6074 major
= XkbMajorVersion
;
6075 minor
= XkbMinorVersion
;
6076 if (!XkbQueryExtension (dpy
, &op
, &event
, &error_code
, &major
, &minor
))
6082 /* In this code we check that the keyboard has physical keys with names
6083 that start with BKSP (Backspace) and DELE (Delete), and that they
6084 generate keysym XK_BackSpace and XK_Delete respectively.
6085 This function is used to test if normal-erase-is-backspace should be
6087 An alternative approach would be to just check if XK_BackSpace and
6088 XK_Delete are mapped to any key. But if any of those are mapped to
6089 some non-intuitive key combination (Meta-Shift-Ctrl-whatever) and the
6090 user doesn't know about it, it is better to return false here.
6091 It is more obvious to the user what to do if she/he has two keys
6092 clearly marked with names/symbols and one key does something not
6093 expected (i.e. she/he then tries the other).
6094 The cases where Backspace/Delete is mapped to some other key combination
6095 are rare, and in those cases, normal-erase-is-backspace can be turned on
6099 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
6102 int delete_keycode
= 0, backspace_keycode
= 0, i
;
6104 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
6106 for (i
= kb
->min_key_code
;
6107 (i
< kb
->max_key_code
6108 && (delete_keycode
== 0 || backspace_keycode
== 0));
6111 /* The XKB symbolic key names can be seen most easily in
6112 the PS file generated by `xkbprint -label name
6114 if (memcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
6116 else if (memcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
6117 backspace_keycode
= i
;
6120 XkbFreeNames (kb
, 0, True
);
6123 /* As of libX11-1.6.2, XkbGetMap manual says that you should use
6124 XkbFreeClientMap to free the data returned by XkbGetMap. But
6125 this function just frees the data referenced from KB and not
6126 KB itself. To free KB as well, call XkbFreeKeyboard. */
6127 XkbFreeKeyboard (kb
, XkbAllMapComponentsMask
, True
);
6130 && backspace_keycode
6131 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
6132 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
6142 /***********************************************************************
6144 ***********************************************************************/
6146 /* Keep this list in the same order as frame_parms in frame.c.
6147 Use 0 for unsupported frame parameters. */
6149 frame_parm_handler x_frame_parm_handlers
[] =
6153 x_set_background_color
,
6159 x_set_foreground_color
,
6162 x_set_internal_border_width
,
6163 x_set_right_divider_width
,
6164 x_set_bottom_divider_width
,
6165 x_set_menu_bar_lines
,
6167 x_explicitly_set_name
,
6168 x_set_scroll_bar_width
,
6169 x_set_scroll_bar_height
,
6172 x_set_vertical_scroll_bars
,
6173 x_set_horizontal_scroll_bars
,
6175 x_set_tool_bar_lines
,
6176 x_set_scroll_bar_foreground
,
6177 x_set_scroll_bar_background
,
6187 x_set_tool_bar_position
,
6193 DEFSYM (Qundefined_color
, "undefined-color");
6194 DEFSYM (Qcompound_text
, "compound-text");
6195 DEFSYM (Qcancel_timer
, "cancel-timer");
6196 DEFSYM (Qfont_param
, "font-parameter");
6198 Fput (Qundefined_color
, Qerror_conditions
,
6199 listn (CONSTYPE_PURE
, 2, Qundefined_color
, Qerror
));
6200 Fput (Qundefined_color
, Qerror_message
,
6201 build_pure_c_string ("Undefined color"));
6203 DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape
,
6204 doc
: /* The shape of the pointer when over text.
6205 Changing the value does not affect existing frames
6206 unless you set the mouse color. */);
6207 Vx_pointer_shape
= Qnil
;
6209 #if false /* This doesn't really do anything. */
6210 DEFVAR_LISP ("x-nontext-pointer-shape", Vx_nontext_pointer_shape
,
6211 doc
: /* The shape of the pointer when not over text.
6212 This variable takes effect when you create a new frame
6213 or when you set the mouse color. */);
6215 Vx_nontext_pointer_shape
= Qnil
;
6217 DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape
,
6218 doc
: /* The shape of the pointer when Emacs is busy.
6219 This variable takes effect when you create a new frame
6220 or when you set the mouse color. */);
6221 Vx_hourglass_pointer_shape
= Qnil
;
6223 #if false /* This doesn't really do anything. */
6224 DEFVAR_LISP ("x-mode-pointer-shape", Vx_mode_pointer_shape
,
6225 doc
: /* The shape of the pointer when over the mode line.
6226 This variable takes effect when you create a new frame
6227 or when you set the mouse color. */);
6229 Vx_mode_pointer_shape
= Qnil
;
6231 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
6232 Vx_sensitive_text_pointer_shape
,
6233 doc
: /* The shape of the pointer when over mouse-sensitive text.
6234 This variable takes effect when you create a new frame
6235 or when you set the mouse color. */);
6236 Vx_sensitive_text_pointer_shape
= Qnil
;
6238 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
6239 Vx_window_horizontal_drag_shape
,
6240 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
6241 This variable takes effect when you create a new frame
6242 or when you set the mouse color. */);
6243 Vx_window_horizontal_drag_shape
= Qnil
;
6245 DEFVAR_LISP ("x-window-vertical-drag-cursor",
6246 Vx_window_vertical_drag_shape
,
6247 doc
: /* Pointer shape to use for indicating a window can be dragged vertically.
6248 This variable takes effect when you create a new frame
6249 or when you set the mouse color. */);
6250 Vx_window_vertical_drag_shape
= Qnil
;
6252 DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel
,
6253 doc
: /* A string indicating the foreground color of the cursor box. */);
6254 Vx_cursor_fore_pixel
= Qnil
;
6256 DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size
,
6257 doc
: /* Maximum size for tooltips.
6258 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
6259 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
6261 DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager
,
6262 doc
: /* Non-nil if no X window manager is in use.
6263 Emacs doesn't try to figure this out; this is always nil
6264 unless you set it to something else. */);
6265 /* We don't have any way to find this out, so set it to nil
6266 and maybe the user would like to set it to t. */
6267 Vx_no_window_manager
= Qnil
;
6269 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
6270 Vx_pixel_size_width_font_regexp
,
6271 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
6273 Since Emacs gets width of a font matching with this regexp from
6274 PIXEL_SIZE field of the name, font finding mechanism gets faster for
6275 such a font. This is especially effective for such large fonts as
6276 Chinese, Japanese, and Korean. */);
6277 Vx_pixel_size_width_font_regexp
= Qnil
;
6279 /* This is not ifdef:ed, so other builds than GTK can customize it. */
6280 DEFVAR_BOOL ("x-gtk-use-old-file-dialog", x_gtk_use_old_file_dialog
,
6281 doc
: /* Non-nil means prompt with the old GTK file selection dialog.
6282 If nil or if the file selection dialog is not available, the new GTK file
6283 chooser is used instead. To turn off all file dialogs set the
6284 variable `use-file-dialog'. */);
6285 x_gtk_use_old_file_dialog
= false;
6287 DEFVAR_BOOL ("x-gtk-show-hidden-files", x_gtk_show_hidden_files
,
6288 doc
: /* If non-nil, the GTK file chooser will by default show hidden files.
6289 Note that this is just the default, there is a toggle button on the file
6290 chooser to show or not show hidden files on a case by case basis. */);
6291 x_gtk_show_hidden_files
= false;
6293 DEFVAR_BOOL ("x-gtk-file-dialog-help-text", x_gtk_file_dialog_help_text
,
6294 doc
: /* If non-nil, the GTK file chooser will show additional help text.
6295 If more space for files in the file chooser dialog is wanted, set this to nil
6296 to turn the additional text off. */);
6297 x_gtk_file_dialog_help_text
= true;
6299 DEFVAR_BOOL ("x-gtk-use-system-tooltips", x_gtk_use_system_tooltips
,
6300 doc
: /* If non-nil with a Gtk+ built Emacs, the Gtk+ tooltip is used.
6301 Otherwise use Emacs own tooltip implementation.
6302 When using Gtk+ tooltips, the tooltip face is not used. */);
6303 x_gtk_use_system_tooltips
= true;
6305 /* Tell Emacs about this window system. */
6306 Fprovide (Qx
, Qnil
);
6308 #ifdef USE_X_TOOLKIT
6309 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
6311 Fprovide (intern_c_string ("motif"), Qnil
);
6313 DEFVAR_LISP ("motif-version-string", Vmotif_version_string
,
6314 doc
: /* Version info for LessTif/Motif. */);
6315 Vmotif_version_string
= build_string (XmVERSION_STRING
);
6316 #endif /* USE_MOTIF */
6317 #endif /* USE_X_TOOLKIT */
6320 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
6321 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
6322 But for a user it is a toolkit for X, and indeed, configure
6323 accepts --with-x-toolkit=gtk. */
6324 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
6325 Fprovide (intern_c_string ("gtk"), Qnil
);
6326 Fprovide (intern_c_string ("move-toolbar"), Qnil
);
6328 DEFVAR_LISP ("gtk-version-string", Vgtk_version_string
,
6329 doc
: /* Version info for GTK+. */);
6331 char gtk_version
[sizeof ".." + 3 * INT_STRLEN_BOUND (int)];
6332 int len
= sprintf (gtk_version
, "%d.%d.%d",
6333 GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
);
6334 Vgtk_version_string
= make_pure_string (gtk_version
, len
, len
, false);
6336 #endif /* USE_GTK */
6338 /* X window properties. */
6339 defsubr (&Sx_change_window_property
);
6340 defsubr (&Sx_delete_window_property
);
6341 defsubr (&Sx_window_property
);
6343 defsubr (&Sxw_display_color_p
);
6344 defsubr (&Sx_display_grayscale_p
);
6345 defsubr (&Sxw_color_defined_p
);
6346 defsubr (&Sxw_color_values
);
6347 defsubr (&Sx_server_max_request_size
);
6348 defsubr (&Sx_server_vendor
);
6349 defsubr (&Sx_server_version
);
6350 defsubr (&Sx_display_pixel_width
);
6351 defsubr (&Sx_display_pixel_height
);
6352 defsubr (&Sx_display_mm_width
);
6353 defsubr (&Sx_display_mm_height
);
6354 defsubr (&Sx_display_screens
);
6355 defsubr (&Sx_display_planes
);
6356 defsubr (&Sx_display_color_cells
);
6357 defsubr (&Sx_display_visual_class
);
6358 defsubr (&Sx_display_backing_store
);
6359 defsubr (&Sx_display_save_under
);
6360 defsubr (&Sx_display_monitor_attributes_list
);
6361 defsubr (&Sx_frame_geometry
);
6362 defsubr (&Sx_wm_set_size_hint
);
6363 defsubr (&Sx_create_frame
);
6364 defsubr (&Sx_open_connection
);
6365 defsubr (&Sx_close_connection
);
6366 defsubr (&Sx_display_list
);
6367 defsubr (&Sx_synchronize
);
6368 defsubr (&Sx_backspace_delete_keys_p
);
6370 defsubr (&Sx_show_tip
);
6371 defsubr (&Sx_hide_tip
);
6373 staticpro (&tip_timer
);
6375 staticpro (&tip_frame
);
6377 last_show_tip_args
= Qnil
;
6378 staticpro (&last_show_tip_args
);
6380 defsubr (&Sx_uses_old_gtk_dialog
);
6381 #if defined (USE_MOTIF) || defined (USE_GTK)
6382 defsubr (&Sx_file_dialog
);
6385 #if defined (USE_GTK) && defined (HAVE_FREETYPE)
6386 defsubr (&Sx_select_font
);