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 /* Return the screen positions and offsets of frame F.
172 Store the offsets between FRAME_OUTER_WINDOW and the containing
173 window manager window into LEFT_OFFSET_X, RIGHT_OFFSET_X,
174 TOP_OFFSET_Y and BOTTOM_OFFSET_Y.
175 Store the offsets between FRAME_X_WINDOW and the containing
176 window manager window into X_PIXELS_DIFF and Y_PIXELS_DIFF.
177 Store the screen positions of frame F into XPTR and YPTR.
178 These are the positions of the containing window manager window,
179 not Emacs's own window. */
181 x_real_pos_and_offsets (struct frame
*f
,
185 int *bottom_offset_y
,
191 int win_x
, win_y
, outer_x
IF_LINT (= 0), outer_y
IF_LINT (= 0);
192 int real_x
= 0, real_y
= 0;
193 bool had_errors
= false;
194 Window win
= f
->output_data
.x
->parent_desc
;
196 unsigned long actual_size
, bytes_remaining
;
197 int rc
, actual_format
;
198 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
200 Display
*dpy
= FRAME_X_DISPLAY (f
);
201 unsigned char *tmp_data
= NULL
;
202 Atom target_type
= XA_CARDINAL
;
203 unsigned int ow
IF_LINT (= 0), oh
IF_LINT (= 0);
207 x_catch_errors (dpy
);
209 if (win
== dpyinfo
->root_window
)
210 win
= FRAME_OUTER_WINDOW (f
);
212 /* This loop traverses up the containment tree until we hit the root
213 window. Window managers may intersect many windows between our window
214 and the root window. The window we find just before the root window
215 should be the outer WM window. */
218 Window wm_window
, rootw
;
219 Window
*tmp_children
;
220 unsigned int tmp_nchildren
;
223 success
= XQueryTree (FRAME_X_DISPLAY (f
), win
, &rootw
,
224 &wm_window
, &tmp_children
, &tmp_nchildren
);
226 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
228 /* Don't free tmp_children if XQueryTree failed. */
232 XFree (tmp_children
);
234 if (wm_window
== rootw
|| had_errors
)
245 /* Get the real coordinates for the WM window upper left corner */
246 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
247 &rootw
, &real_x
, &real_y
, &ow
, &oh
, &ign
, &ign
);
249 /* Translate real coordinates to coordinates relative to our
250 window. For our window, the upper left corner is 0, 0.
251 Since the upper left corner of the WM window is outside
252 our window, win_x and win_y will be negative:
254 ------------------ ---> x
256 | ----------------- v y
259 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
261 /* From-window, to-window. */
262 FRAME_DISPLAY_INFO (f
)->root_window
,
265 /* From-position, to-position. */
266 real_x
, real_y
, &win_x
, &win_y
,
271 if (FRAME_X_WINDOW (f
) == FRAME_OUTER_WINDOW (f
))
278 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
280 /* From-window, to-window. */
281 FRAME_DISPLAY_INFO (f
)->root_window
,
282 FRAME_OUTER_WINDOW (f
),
284 /* From-position, to-position. */
285 real_x
, real_y
, &outer_x
, &outer_y
,
291 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
295 if (dpyinfo
->root_window
== f
->output_data
.x
->parent_desc
)
297 /* Try _NET_FRAME_EXTENTS if our parent is the root window. */
298 rc
= XGetWindowProperty (dpy
, win
, dpyinfo
->Xatom_net_frame_extents
,
299 0, max_len
, False
, target_type
,
300 &actual_type
, &actual_format
, &actual_size
,
301 &bytes_remaining
, &tmp_data
);
303 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
304 && actual_size
== 4 && actual_format
== 32)
308 long *fe
= (long *)tmp_data
;
310 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
311 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
319 if (tmp_data
) XFree (tmp_data
);
325 if (had_errors
) return;
327 if (x_pixels_diff
) *x_pixels_diff
= -win_x
;
328 if (y_pixels_diff
) *y_pixels_diff
= -win_y
;
330 if (left_offset_x
) *left_offset_x
= -outer_x
;
331 if (top_offset_y
) *top_offset_y
= -outer_x
;
333 if (xptr
) *xptr
= real_x
;
334 if (yptr
) *yptr
= real_y
;
336 if (right_offset_x
|| bottom_offset_y
)
338 unsigned int ign
, fw
, fh
;
341 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
342 &rootw
, &ign
, &ign
, &fw
, &fh
, &ign
, &ign
);
343 if (right_offset_x
) *right_offset_x
= ow
- fw
+ outer_x
;
344 if (bottom_offset_y
) *bottom_offset_y
= oh
- fh
+ outer_y
;
348 /* Store the screen positions of frame F into XPTR and YPTR.
349 These are the positions of the containing window manager window,
350 not Emacs's own window. */
353 x_real_positions (struct frame
*f
, int *xptr
, int *yptr
)
355 x_real_pos_and_offsets (f
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, xptr
, yptr
);
359 /* Get the mouse position in frame relative coordinates. */
362 x_relative_mouse_position (struct frame
*f
, int *x
, int *y
)
364 Window root
, dummy_window
;
367 eassert (FRAME_X_P (f
));
371 XQueryPointer (FRAME_X_DISPLAY (f
),
372 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
374 /* The root window which contains the pointer. */
377 /* Window pointer is on, not used */
380 /* The position on that root window. */
383 /* x/y in dummy_window coordinates, not used. */
386 /* Modifier keys and pointer buttons, about which
388 (unsigned int *) &dummy
);
390 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
392 /* From-window, to-window. */
393 FRAME_DISPLAY_INFO (f
)->root_window
,
396 /* From-position, to-position. */
405 /* Gamma-correct COLOR on frame F. */
408 gamma_correct (struct frame
*f
, XColor
*color
)
412 color
->red
= pow (color
->red
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
413 color
->green
= pow (color
->green
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
414 color
->blue
= pow (color
->blue
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
419 /* Decide if color named COLOR_NAME is valid for use on frame F. If
420 so, return the RGB values in COLOR. If ALLOC_P,
421 allocate the color. Value is false if COLOR_NAME is invalid, or
422 no color could be allocated. */
425 x_defined_color (struct frame
*f
, const char *color_name
,
426 XColor
*color
, bool alloc_p
)
428 bool success_p
= false;
429 Display
*dpy
= FRAME_X_DISPLAY (f
);
430 Colormap cmap
= FRAME_X_COLORMAP (f
);
434 success_p
= xg_check_special_colors (f
, color_name
, color
);
437 success_p
= XParseColor (dpy
, cmap
, color_name
, color
) != 0;
438 if (success_p
&& alloc_p
)
439 success_p
= x_alloc_nearest_color (f
, cmap
, color
);
446 /* Return the pixel color value for color COLOR_NAME on frame F. If F
447 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
448 Signal an error if color can't be allocated. */
451 x_decode_color (struct frame
*f
, Lisp_Object color_name
, int mono_color
)
455 CHECK_STRING (color_name
);
457 #if false /* Don't do this. It's wrong when we're not using the default
458 colormap, it makes freeing difficult, and it's probably not
459 an important optimization. */
460 if (strcmp (SDATA (color_name
), "black") == 0)
461 return BLACK_PIX_DEFAULT (f
);
462 else if (strcmp (SDATA (color_name
), "white") == 0)
463 return WHITE_PIX_DEFAULT (f
);
466 /* Return MONO_COLOR for monochrome frames. */
467 if (FRAME_DISPLAY_INFO (f
)->n_planes
== 1)
470 /* x_defined_color is responsible for coping with failures
471 by looking for a near-miss. */
472 if (x_defined_color (f
, SSDATA (color_name
), &cdef
, true))
475 signal_error ("Undefined color", color_name
);
480 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
481 the previous value of that parameter, NEW_VALUE is the new value.
482 See also the comment of wait_for_wm in struct x_output. */
485 x_set_wait_for_wm (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
487 f
->output_data
.x
->wait_for_wm
= !NILP (new_value
);
491 x_set_tool_bar_position (struct frame
*f
,
492 Lisp_Object new_value
,
493 Lisp_Object old_value
)
495 Lisp_Object choice
= list4 (Qleft
, Qright
, Qtop
, Qbottom
);
497 if (!NILP (Fmemq (new_value
, choice
)))
500 if (!EQ (new_value
, old_value
))
502 xg_change_toolbar_position (f
, new_value
);
503 fset_tool_bar_position (f
, new_value
);
506 if (!EQ (new_value
, Qtop
))
507 error ("The only supported tool bar position is top");
511 wrong_choice (choice
, new_value
);
516 /* Set icon from FILE for frame F. By using GTK functions the icon
517 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
520 xg_set_icon (struct frame
*f
, Lisp_Object file
)
525 found
= x_find_image_file (file
);
531 char *filename
= SSDATA (found
);
534 pixbuf
= gdk_pixbuf_new_from_file (filename
, &err
);
538 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
540 g_object_unref (pixbuf
);
554 xg_set_icon_from_xpm_data (struct frame
*f
, const char **data
)
556 GdkPixbuf
*pixbuf
= gdk_pixbuf_new_from_xpm_data (data
);
561 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)), pixbuf
);
562 g_object_unref (pixbuf
);
568 /* Functions called only from `x_set_frame_param'
569 to set individual parameters.
571 If FRAME_X_WINDOW (f) is 0,
572 the frame is being created and its X-window does not exist yet.
573 In that case, just record the parameter's new value
574 in the standard place; do not attempt to change the window. */
577 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
579 struct x_output
*x
= f
->output_data
.x
;
580 unsigned long fg
, old_fg
;
582 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
583 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
584 FRAME_FOREGROUND_PIXEL (f
) = fg
;
586 if (FRAME_X_WINDOW (f
) != 0)
588 Display
*dpy
= FRAME_X_DISPLAY (f
);
591 XSetForeground (dpy
, x
->normal_gc
, fg
);
592 XSetBackground (dpy
, x
->reverse_gc
, fg
);
594 if (x
->cursor_pixel
== old_fg
)
596 unload_color (f
, x
->cursor_pixel
);
597 x
->cursor_pixel
= x_copy_color (f
, fg
);
598 XSetBackground (dpy
, x
->cursor_gc
, x
->cursor_pixel
);
603 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
605 if (FRAME_VISIBLE_P (f
))
609 unload_color (f
, old_fg
);
613 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
615 struct x_output
*x
= f
->output_data
.x
;
618 bg
= x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
619 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
620 FRAME_BACKGROUND_PIXEL (f
) = bg
;
622 if (FRAME_X_WINDOW (f
) != 0)
624 Display
*dpy
= FRAME_X_DISPLAY (f
);
627 XSetBackground (dpy
, x
->normal_gc
, bg
);
628 XSetForeground (dpy
, x
->reverse_gc
, bg
);
629 XSetWindowBackground (dpy
, FRAME_X_WINDOW (f
), bg
);
630 XSetForeground (dpy
, x
->cursor_gc
, bg
);
633 xg_set_background_color (f
, bg
);
636 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
637 toolkit scroll bars. */
640 for (bar
= FRAME_SCROLL_BARS (f
);
642 bar
= XSCROLL_BAR (bar
)->next
)
644 Window window
= XSCROLL_BAR (bar
)->x_window
;
645 XSetWindowBackground (dpy
, window
, bg
);
648 #endif /* USE_TOOLKIT_SCROLL_BARS */
651 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
653 if (FRAME_VISIBLE_P (f
))
659 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
661 struct x_output
*x
= f
->output_data
.x
;
662 Display
*dpy
= FRAME_X_DISPLAY (f
);
663 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
664 Cursor hourglass_cursor
, horizontal_drag_cursor
, vertical_drag_cursor
;
665 unsigned long pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
666 unsigned long mask_color
= FRAME_BACKGROUND_PIXEL (f
);
668 /* Don't let pointers be invisible. */
669 if (mask_color
== pixel
)
671 x_free_colors (f
, &pixel
, 1);
672 pixel
= x_copy_color (f
, FRAME_FOREGROUND_PIXEL (f
));
675 unload_color (f
, x
->mouse_pixel
);
676 x
->mouse_pixel
= pixel
;
680 /* It's not okay to crash if the user selects a screwy cursor. */
681 x_catch_errors (dpy
);
683 if (!NILP (Vx_pointer_shape
))
685 CHECK_NUMBER (Vx_pointer_shape
);
686 cursor
= XCreateFontCursor (dpy
, XINT (Vx_pointer_shape
));
689 cursor
= XCreateFontCursor (dpy
, XC_xterm
);
690 x_check_errors (dpy
, "bad text pointer cursor: %s");
692 if (!NILP (Vx_nontext_pointer_shape
))
694 CHECK_NUMBER (Vx_nontext_pointer_shape
);
696 = XCreateFontCursor (dpy
, XINT (Vx_nontext_pointer_shape
));
699 nontext_cursor
= XCreateFontCursor (dpy
, XC_left_ptr
);
700 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
702 if (!NILP (Vx_hourglass_pointer_shape
))
704 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
706 = XCreateFontCursor (dpy
, XINT (Vx_hourglass_pointer_shape
));
709 hourglass_cursor
= XCreateFontCursor (dpy
, XC_watch
);
710 x_check_errors (dpy
, "bad hourglass pointer cursor: %s");
712 if (!NILP (Vx_mode_pointer_shape
))
714 CHECK_NUMBER (Vx_mode_pointer_shape
);
715 mode_cursor
= XCreateFontCursor (dpy
, XINT (Vx_mode_pointer_shape
));
718 mode_cursor
= XCreateFontCursor (dpy
, XC_xterm
);
719 x_check_errors (dpy
, "bad modeline pointer cursor: %s");
721 if (!NILP (Vx_sensitive_text_pointer_shape
))
723 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
725 = XCreateFontCursor (dpy
, XINT (Vx_sensitive_text_pointer_shape
));
728 hand_cursor
= XCreateFontCursor (dpy
, XC_hand2
);
730 if (!NILP (Vx_window_horizontal_drag_shape
))
732 CHECK_TYPE_RANGED_INTEGER (unsigned, Vx_window_horizontal_drag_shape
);
733 horizontal_drag_cursor
734 = XCreateFontCursor (dpy
, XINT (Vx_window_horizontal_drag_shape
));
737 horizontal_drag_cursor
738 = XCreateFontCursor (dpy
, XC_sb_h_double_arrow
);
740 if (!NILP (Vx_window_vertical_drag_shape
))
742 CHECK_NUMBER (Vx_window_vertical_drag_shape
);
744 = XCreateFontCursor (dpy
, XINT (Vx_window_vertical_drag_shape
));
748 = XCreateFontCursor (dpy
, XC_sb_v_double_arrow
);
750 /* Check and report errors with the above calls. */
751 x_check_errors (dpy
, "can't set cursor shape: %s");
755 XColor fore_color
, back_color
;
757 fore_color
.pixel
= x
->mouse_pixel
;
758 x_query_color (f
, &fore_color
);
759 back_color
.pixel
= mask_color
;
760 x_query_color (f
, &back_color
);
762 XRecolorCursor (dpy
, cursor
, &fore_color
, &back_color
);
763 XRecolorCursor (dpy
, nontext_cursor
, &fore_color
, &back_color
);
764 XRecolorCursor (dpy
, mode_cursor
, &fore_color
, &back_color
);
765 XRecolorCursor (dpy
, hand_cursor
, &fore_color
, &back_color
);
766 XRecolorCursor (dpy
, hourglass_cursor
, &fore_color
, &back_color
);
767 XRecolorCursor (dpy
, horizontal_drag_cursor
, &fore_color
, &back_color
);
768 XRecolorCursor (dpy
, vertical_drag_cursor
, &fore_color
, &back_color
);
771 if (FRAME_X_WINDOW (f
) != 0)
772 XDefineCursor (dpy
, FRAME_X_WINDOW (f
),
773 f
->output_data
.x
->current_cursor
= cursor
);
775 if (cursor
!= x
->text_cursor
776 && x
->text_cursor
!= 0)
777 XFreeCursor (dpy
, x
->text_cursor
);
778 x
->text_cursor
= cursor
;
780 if (nontext_cursor
!= x
->nontext_cursor
781 && x
->nontext_cursor
!= 0)
782 XFreeCursor (dpy
, x
->nontext_cursor
);
783 x
->nontext_cursor
= nontext_cursor
;
785 if (hourglass_cursor
!= x
->hourglass_cursor
786 && x
->hourglass_cursor
!= 0)
787 XFreeCursor (dpy
, x
->hourglass_cursor
);
788 x
->hourglass_cursor
= hourglass_cursor
;
790 if (mode_cursor
!= x
->modeline_cursor
791 && x
->modeline_cursor
!= 0)
792 XFreeCursor (dpy
, f
->output_data
.x
->modeline_cursor
);
793 x
->modeline_cursor
= mode_cursor
;
795 if (hand_cursor
!= x
->hand_cursor
796 && x
->hand_cursor
!= 0)
797 XFreeCursor (dpy
, x
->hand_cursor
);
798 x
->hand_cursor
= hand_cursor
;
800 if (horizontal_drag_cursor
!= x
->horizontal_drag_cursor
801 && x
->horizontal_drag_cursor
!= 0)
802 XFreeCursor (dpy
, x
->horizontal_drag_cursor
);
803 x
->horizontal_drag_cursor
= horizontal_drag_cursor
;
805 if (vertical_drag_cursor
!= x
->vertical_drag_cursor
806 && x
->vertical_drag_cursor
!= 0)
807 XFreeCursor (dpy
, x
->vertical_drag_cursor
);
808 x
->vertical_drag_cursor
= vertical_drag_cursor
;
813 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
817 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
819 unsigned long fore_pixel
, pixel
;
820 bool fore_pixel_allocated_p
= false, pixel_allocated_p
= false;
821 struct x_output
*x
= f
->output_data
.x
;
823 if (!NILP (Vx_cursor_fore_pixel
))
825 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
826 WHITE_PIX_DEFAULT (f
));
827 fore_pixel_allocated_p
= true;
830 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
832 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
833 pixel_allocated_p
= true;
835 /* Make sure that the cursor color differs from the background color. */
836 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
838 if (pixel_allocated_p
)
840 x_free_colors (f
, &pixel
, 1);
841 pixel_allocated_p
= false;
844 pixel
= x
->mouse_pixel
;
845 if (pixel
== fore_pixel
)
847 if (fore_pixel_allocated_p
)
849 x_free_colors (f
, &fore_pixel
, 1);
850 fore_pixel_allocated_p
= false;
852 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
856 unload_color (f
, x
->cursor_foreground_pixel
);
857 if (!fore_pixel_allocated_p
)
858 fore_pixel
= x_copy_color (f
, fore_pixel
);
859 x
->cursor_foreground_pixel
= fore_pixel
;
861 unload_color (f
, x
->cursor_pixel
);
862 if (!pixel_allocated_p
)
863 pixel
= x_copy_color (f
, pixel
);
864 x
->cursor_pixel
= pixel
;
866 if (FRAME_X_WINDOW (f
) != 0)
869 XSetBackground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, x
->cursor_pixel
);
870 XSetForeground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, fore_pixel
);
873 if (FRAME_VISIBLE_P (f
))
875 x_update_cursor (f
, false);
876 x_update_cursor (f
, true);
880 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
883 /* Set the border-color of frame F to pixel value PIX.
884 Note that this does not fully take effect if done before
885 F has an x-window. */
888 x_set_border_pixel (struct frame
*f
, int pix
)
890 unload_color (f
, f
->output_data
.x
->border_pixel
);
891 f
->output_data
.x
->border_pixel
= pix
;
893 if (FRAME_X_WINDOW (f
) != 0 && f
->border_width
> 0)
896 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), pix
);
899 if (FRAME_VISIBLE_P (f
))
904 /* Set the border-color of frame F to value described by ARG.
905 ARG can be a string naming a color.
906 The border-color is used for the border that is drawn by the X server.
907 Note that this does not fully take effect if done before
908 F has an x-window; it must be redone when the window is created.
910 Note: this is done in two routines because of the way X10 works.
912 Note: under X11, this is normally the province of the window manager,
913 and so emacs's border colors may be overridden. */
916 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
921 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
922 x_set_border_pixel (f
, pix
);
923 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
928 x_set_cursor_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
930 set_frame_cursor_types (f
, arg
);
934 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
940 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
943 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
948 result
= x_text_icon (f
,
949 SSDATA ((!NILP (f
->icon_name
)
953 result
= x_bitmap_icon (f
, arg
);
958 error ("No icon window available");
961 XFlush (FRAME_X_DISPLAY (f
));
966 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
972 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
975 else if (!NILP (arg
) || NILP (oldval
))
978 fset_icon_name (f
, arg
);
980 if (f
->output_data
.x
->icon_bitmap
!= 0)
985 result
= x_text_icon (f
,
986 SSDATA ((!NILP (f
->icon_name
)
995 error ("No icon window available");
998 XFlush (FRAME_X_DISPLAY (f
));
1004 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1007 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
1008 int olines
= FRAME_MENU_BAR_LINES (f
);
1011 /* Right now, menu bars don't work properly in minibuf-only frames;
1012 most of the commands try to apply themselves to the minibuffer
1013 frame itself, and get an error because you can't switch buffers
1014 in or split the minibuffer window. */
1015 if (FRAME_MINIBUF_ONLY_P (f
))
1018 if (TYPE_RANGED_INTEGERP (int, value
))
1019 nlines
= XINT (value
);
1023 /* Make sure we redisplay all windows in this frame. */
1024 windows_or_buffers_changed
= 59;
1026 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
1027 FRAME_MENU_BAR_LINES (f
) = 0;
1028 FRAME_MENU_BAR_HEIGHT (f
) = 0;
1031 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1032 if (FRAME_X_P (f
) && f
->output_data
.x
->menubar_widget
== 0)
1033 /* Make sure next redisplay shows the menu bar. */
1034 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= true;
1038 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1039 free_frame_menubar (f
);
1040 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1042 f
->output_data
.x
->menubar_widget
= 0;
1044 #else /* not USE_X_TOOLKIT && not USE_GTK */
1045 FRAME_MENU_BAR_LINES (f
) = nlines
;
1046 FRAME_MENU_BAR_HEIGHT (f
) = nlines
* FRAME_LINE_HEIGHT (f
);
1047 adjust_frame_size (f
, -1, -1, 2, true, Qmenu_bar_lines
);
1048 if (FRAME_X_WINDOW (f
))
1049 x_clear_under_internal_border (f
);
1051 /* If the menu bar height gets changed, the internal border below
1052 the top margin has to be cleared. Also, if the menu bar gets
1053 larger, the area for the added lines has to be cleared except for
1054 the first menu bar line that is to be drawn later. */
1055 if (nlines
!= olines
)
1057 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1058 int width
= FRAME_PIXEL_WIDTH (f
);
1061 /* height can be zero here. */
1062 if (FRAME_X_WINDOW (f
) && height
> 0 && width
> 0)
1064 y
= FRAME_TOP_MARGIN_HEIGHT (f
);
1067 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1068 0, y
, width
, height
);
1072 if (nlines
> 1 && nlines
> olines
)
1074 y
= (olines
== 0 ? 1 : olines
) * FRAME_LINE_HEIGHT (f
);
1075 height
= nlines
* FRAME_LINE_HEIGHT (f
) - y
;
1078 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1079 0, y
, width
, height
);
1083 if (nlines
== 0 && WINDOWP (f
->menu_bar_window
))
1084 clear_glyph_matrix (XWINDOW (f
->menu_bar_window
)->current_matrix
);
1086 #endif /* not USE_X_TOOLKIT && not USE_GTK */
1087 adjust_frame_glyphs (f
);
1088 run_window_configuration_change_hook (f
);
1092 /* Set the number of lines used for the tool bar of frame F to VALUE.
1093 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1094 is the old number of tool bar lines. This function changes the
1095 height of all windows on frame F to match the new tool bar height.
1096 The frame's height doesn't change. */
1099 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1103 /* Treat tool bars like menu bars. */
1104 if (FRAME_MINIBUF_ONLY_P (f
))
1107 /* Use VALUE only if an int >= 0. */
1108 if (RANGED_INTEGERP (0, value
, INT_MAX
))
1109 nlines
= XFASTINT (value
);
1113 x_change_tool_bar_height (f
, nlines
* FRAME_LINE_HEIGHT (f
));
1117 /* Set the pixel height of the tool bar of frame F to HEIGHT. */
1119 x_change_tool_bar_height (struct frame
*f
, int height
)
1122 FRAME_TOOL_BAR_LINES (f
) = 0;
1123 FRAME_TOOL_BAR_HEIGHT (f
) = 0;
1126 FRAME_EXTERNAL_TOOL_BAR (f
) = true;
1127 if (FRAME_X_P (f
) && f
->output_data
.x
->toolbar_widget
== 0)
1128 /* Make sure next redisplay shows the tool bar. */
1129 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= true;
1130 update_frame_tool_bar (f
);
1134 if (FRAME_EXTERNAL_TOOL_BAR (f
))
1135 free_frame_tool_bar (f
);
1136 FRAME_EXTERNAL_TOOL_BAR (f
) = false;
1138 #else /* !USE_GTK */
1139 int unit
= FRAME_LINE_HEIGHT (f
);
1140 int old_height
= FRAME_TOOL_BAR_HEIGHT (f
);
1141 int lines
= (height
+ unit
- 1) / unit
;
1142 Lisp_Object fullscreen
;
1144 /* Make sure we redisplay all windows in this frame. */
1145 windows_or_buffers_changed
= 60;
1148 /* Recalculate tool bar and frame text sizes. */
1149 FRAME_TOOL_BAR_HEIGHT (f
) = height
;
1150 FRAME_TOOL_BAR_LINES (f
) = lines
;
1151 /* Store the `tool-bar-lines' and `height' frame parameters. */
1152 store_frame_param (f
, Qtool_bar_lines
, make_number (lines
));
1153 store_frame_param (f
, Qheight
, make_number (FRAME_LINES (f
)));
1155 /* We also have to make sure that the internal border at the top of
1156 the frame, below the menu bar or tool bar, is redrawn when the
1157 tool bar disappears. This is so because the internal border is
1158 below the tool bar if one is displayed, but is below the menu bar
1159 if there isn't a tool bar. The tool bar draws into the area
1160 below the menu bar. */
1161 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_HEIGHT (f
) == 0)
1164 clear_current_matrices (f
);
1167 if ((height
< old_height
) && WINDOWP (f
->tool_bar_window
))
1168 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1170 /* Recalculate toolbar height. */
1171 f
->n_tool_bar_rows
= 0;
1173 adjust_frame_size (f
, -1, -1,
1174 ((!f
->tool_bar_redisplayed_once
1175 && (NILP (fullscreen
=
1176 get_frame_param (f
, Qfullscreen
))
1177 || EQ (fullscreen
, Qfullwidth
))) ? 1
1178 : (old_height
== 0 || height
== 0) ? 2
1180 false, Qtool_bar_lines
);
1182 /* adjust_frame_size might not have done anything, garbage frame
1184 adjust_frame_glyphs (f
);
1185 SET_FRAME_GARBAGED (f
);
1186 if (FRAME_X_WINDOW (f
))
1187 x_clear_under_internal_border (f
);
1189 #endif /* USE_GTK */
1194 x_set_internal_border_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1198 CHECK_TYPE_RANGED_INTEGER (int, arg
);
1199 border
= max (XINT (arg
), 0);
1201 if (border
!= FRAME_INTERNAL_BORDER_WIDTH (f
))
1203 FRAME_INTERNAL_BORDER_WIDTH (f
) = border
;
1205 #ifdef USE_X_TOOLKIT
1206 if (FRAME_X_OUTPUT (f
)->edit_widget
)
1207 widget_store_internal_border (FRAME_X_OUTPUT (f
)->edit_widget
);
1210 if (FRAME_X_WINDOW (f
) != 0)
1212 adjust_frame_size (f
, -1, -1, 3, false, Qinternal_border_width
);
1215 xg_clear_under_internal_border (f
);
1217 x_clear_under_internal_border (f
);
1225 /* Set the foreground color for scroll bars on frame F to VALUE.
1226 VALUE should be a string, a color name. If it isn't a string or
1227 isn't a valid color name, do nothing. OLDVAL is the old value of
1228 the frame parameter. */
1231 x_set_scroll_bar_foreground (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1233 unsigned long pixel
;
1235 if (STRINGP (value
))
1236 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
1240 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
1241 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
1243 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
1244 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1246 /* Remove all scroll bars because they have wrong colors. */
1247 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1248 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1249 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1250 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1252 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
1258 /* Set the background color for scroll bars on frame F to VALUE VALUE
1259 should be a string, a color name. If it isn't a string or isn't a
1260 valid color name, do nothing. OLDVAL is the old value of the frame
1264 x_set_scroll_bar_background (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1266 unsigned long pixel
;
1268 if (STRINGP (value
))
1269 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
1273 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
1274 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
1276 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
1277 /* Scrollbar shadow colors. */
1278 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
1280 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
1281 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
1283 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
1285 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
1286 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
1288 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
1290 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
1291 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1293 /* Remove all scroll bars because they have wrong colors. */
1294 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1295 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1296 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1297 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1299 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
1305 /* Encode Lisp string STRING as a text in a format appropriate for
1306 XICCC (X Inter Client Communication Conventions).
1308 This can call Lisp code, so callers must GCPRO.
1310 If STRING contains only ASCII characters, do no conversion and
1311 return the string data of STRING. Otherwise, encode the text by
1312 CODING_SYSTEM, and return a newly allocated memory area which
1313 should be freed by `xfree' by a caller.
1315 Store the byte length of resulting text in *TEXT_BYTES.
1317 If the text contains only ASCII and Latin-1, store true in *STRING_P,
1318 which means that the `encoding' of the result can be `STRING'.
1319 Otherwise store false in *STRINGP, which means that the `encoding' of
1320 the result should be `COMPOUND_TEXT'. */
1322 static unsigned char *
1323 x_encode_text (Lisp_Object string
, Lisp_Object coding_system
,
1324 ptrdiff_t *text_bytes
, bool *stringp
, bool *freep
)
1326 int result
= string_xstring_p (string
);
1327 struct coding_system coding
;
1331 /* No multibyte character in OBJ. We need not encode it. */
1332 *text_bytes
= SBYTES (string
);
1335 return SDATA (string
);
1338 setup_coding_system (coding_system
, &coding
);
1339 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
1340 /* We suppress producing escape sequences for composition. */
1341 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
1342 coding
.destination
= xnmalloc (SCHARS (string
), 2);
1343 coding
.dst_bytes
= SCHARS (string
) * 2;
1344 encode_coding_object (&coding
, string
, 0, 0,
1345 SCHARS (string
), SBYTES (string
), Qnil
);
1346 *text_bytes
= coding
.produced
;
1347 *stringp
= (result
== 1 || !EQ (coding_system
, Qcompound_text
));
1349 return coding
.destination
;
1353 /* Set the WM name to NAME for frame F. Also set the icon name.
1354 If the frame already has an icon name, use that, otherwise set the
1355 icon name to NAME. */
1358 x_set_name_internal (struct frame
*f
, Lisp_Object name
)
1360 if (FRAME_X_WINDOW (f
))
1364 XTextProperty text
, icon
;
1367 bool do_free_icon_value
= false, do_free_text_value
= false;
1368 Lisp_Object coding_system
;
1369 Lisp_Object encoded_name
;
1370 Lisp_Object encoded_icon_name
;
1371 struct gcpro gcpro1
;
1373 /* As ENCODE_UTF_8 may cause GC and relocation of string data,
1374 we use it before x_encode_text that may return string data. */
1376 encoded_name
= ENCODE_UTF_8 (name
);
1379 coding_system
= Qcompound_text
;
1380 /* Note: Encoding strategy
1382 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1383 text.encoding. But, there are non-internationalized window
1384 managers which don't support that encoding. So, if NAME
1385 contains only ASCII and 8859-1 characters, encode it by
1386 iso-latin-1, and use "STRING" in text.encoding hoping that
1387 such window managers at least analyze this format correctly,
1388 i.e. treat 8-bit bytes as 8859-1 characters.
1390 We may also be able to use "UTF8_STRING" in text.encoding
1391 in the future which can encode all Unicode characters.
1392 But, for the moment, there's no way to know that the
1393 current window manager supports it or not.
1395 Either way, we also set the _NET_WM_NAME and _NET_WM_ICON_NAME
1396 properties. Per the EWMH specification, those two properties
1397 are always UTF8_STRING. This matches what gtk_window_set_title()
1398 does in the USE_GTK case. */
1399 text
.value
= x_encode_text (name
, coding_system
, &bytes
,
1400 &stringp
, &do_free_text_value
);
1401 text
.encoding
= (stringp
? XA_STRING
1402 : FRAME_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1404 text
.nitems
= bytes
;
1406 if (!STRINGP (f
->icon_name
))
1409 encoded_icon_name
= encoded_name
;
1413 /* See the above comment "Note: Encoding strategy". */
1414 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, &bytes
,
1415 &stringp
, &do_free_icon_value
);
1416 icon
.encoding
= (stringp
? XA_STRING
1417 : FRAME_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1419 icon
.nitems
= bytes
;
1421 encoded_icon_name
= ENCODE_UTF_8 (f
->icon_name
);
1425 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1426 SSDATA (encoded_name
));
1427 #else /* not USE_GTK */
1428 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1429 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1430 FRAME_DISPLAY_INFO (f
)->Xatom_net_wm_name
,
1431 FRAME_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1433 SDATA (encoded_name
),
1434 SBYTES (encoded_name
));
1435 #endif /* not USE_GTK */
1437 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &icon
);
1438 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1439 FRAME_DISPLAY_INFO (f
)->Xatom_net_wm_icon_name
,
1440 FRAME_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1442 SDATA (encoded_icon_name
),
1443 SBYTES (encoded_icon_name
));
1445 if (do_free_icon_value
)
1447 if (do_free_text_value
)
1454 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1457 If EXPLICIT is true, that indicates that lisp code is setting the
1458 name; if NAME is a string, set F's name to NAME and set
1459 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1461 If EXPLICIT is false, that indicates that Emacs redisplay code is
1462 suggesting a new name, which lisp code should override; if
1463 F->explicit_name is set, ignore the new name; otherwise, set it. */
1466 x_set_name (struct frame
*f
, Lisp_Object name
, bool explicit)
1468 /* Make sure that requests from lisp code override requests from
1469 Emacs redisplay code. */
1472 /* If we're switching from explicit to implicit, we had better
1473 update the mode lines and thereby update the title. */
1474 if (f
->explicit_name
&& NILP (name
))
1475 update_mode_lines
= 37;
1477 f
->explicit_name
= ! NILP (name
);
1479 else if (f
->explicit_name
)
1482 /* If NAME is nil, set the name to the x_id_name. */
1485 /* Check for no change needed in this very common case
1486 before we do any consing. */
1487 if (!strcmp (FRAME_DISPLAY_INFO (f
)->x_id_name
,
1490 name
= build_string (FRAME_DISPLAY_INFO (f
)->x_id_name
);
1493 CHECK_STRING (name
);
1495 /* Don't change the name if it's already NAME. */
1496 if (! NILP (Fstring_equal (name
, f
->name
)))
1499 fset_name (f
, name
);
1501 /* For setting the frame title, the title parameter should override
1502 the name parameter. */
1503 if (! NILP (f
->title
))
1506 x_set_name_internal (f
, name
);
1509 /* This function should be called when the user's lisp code has
1510 specified a name for the frame; the name will override any set by the
1513 x_explicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1515 x_set_name (f
, arg
, true);
1518 /* This function should be called by Emacs redisplay code to set the
1519 name; names set this way will never override names set by the user's
1522 x_implicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1524 x_set_name (f
, arg
, false);
1527 /* Change the title of frame F to NAME.
1528 If NAME is nil, use the frame name as the title. */
1531 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1533 /* Don't change the title if it's already NAME. */
1534 if (EQ (name
, f
->title
))
1537 update_mode_lines
= 38;
1539 fset_title (f
, name
);
1544 CHECK_STRING (name
);
1546 x_set_name_internal (f
, name
);
1550 x_set_scroll_bar_default_width (struct frame
*f
)
1552 int unit
= FRAME_COLUMN_WIDTH (f
);
1553 #ifdef USE_TOOLKIT_SCROLL_BARS
1555 int minw
= xg_get_default_scrollbar_width ();
1559 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1560 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (minw
+ unit
- 1) / unit
;
1561 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = minw
;
1563 /* The width of a non-toolkit scrollbar is 14 pixels. */
1564 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + unit
- 1) / unit
;
1565 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
)
1566 = FRAME_CONFIG_SCROLL_BAR_COLS (f
) * unit
;
1571 x_set_scroll_bar_default_height (struct frame
*f
)
1573 int height
= FRAME_LINE_HEIGHT (f
);
1574 #ifdef USE_TOOLKIT_SCROLL_BARS
1576 int min_height
= xg_get_default_scrollbar_height ();
1578 int min_height
= 16;
1580 /* A minimum height of 14 doesn't look good for toolkit scroll bars. */
1581 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) = min_height
;
1582 FRAME_CONFIG_SCROLL_BAR_LINES (f
) = (min_height
+ height
- 1) / height
;
1584 /* The height of a non-toolkit scrollbar is 14 pixels. */
1585 FRAME_CONFIG_SCROLL_BAR_LINES (f
) = (14 + height
- 1) / height
;
1587 /* Use all of that space (aside from required margins) for the
1589 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) = 14;
1594 /* Record in frame F the specified or default value according to ALIST
1595 of the parameter named PROP (a Lisp symbol). If no value is
1596 specified for PROP, look for an X default for XPROP on the frame
1597 named NAME. If that is not found either, use the value DEFLT. */
1600 x_default_scroll_bar_color_parameter (struct frame
*f
,
1601 Lisp_Object alist
, Lisp_Object prop
,
1602 const char *xprop
, const char *xclass
,
1605 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1608 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
1609 if (EQ (tem
, Qunbound
))
1611 #ifdef USE_TOOLKIT_SCROLL_BARS
1613 /* See if an X resource for the scroll bar color has been
1615 AUTO_STRING (foreground
, "foreground");
1616 AUTO_STRING (background
, "foreground");
1617 AUTO_STRING (verticalScrollBar
, "verticalScrollBar");
1618 tem
= (display_x_get_resource
1619 (dpyinfo
, foreground_p
? foreground
: background
,
1620 empty_unibyte_string
,
1622 empty_unibyte_string
));
1625 /* If nothing has been specified, scroll bars will use a
1626 toolkit-dependent default. Because these defaults are
1627 difficult to get at without actually creating a scroll
1628 bar, use nil to indicate that no color has been
1633 #else /* not USE_TOOLKIT_SCROLL_BARS */
1637 #endif /* not USE_TOOLKIT_SCROLL_BARS */
1640 AUTO_FRAME_ARG (arg
, prop
, tem
);
1641 x_set_frame_parameters (f
, arg
);
1648 #ifdef USE_X_TOOLKIT
1650 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
1651 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
1652 already be present because of the toolkit (Motif adds some of them,
1653 for example, but Xt doesn't). */
1656 hack_wm_protocols (struct frame
*f
, Widget widget
)
1658 Display
*dpy
= XtDisplay (widget
);
1659 Window w
= XtWindow (widget
);
1660 bool need_delete
= true;
1661 bool need_focus
= true;
1662 bool need_save
= true;
1667 unsigned char *catoms
;
1669 unsigned long nitems
= 0;
1670 unsigned long bytes_after
;
1672 if ((XGetWindowProperty (dpy
, w
,
1673 FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1674 0, 100, False
, XA_ATOM
,
1675 &type
, &format
, &nitems
, &bytes_after
,
1678 && format
== 32 && type
== XA_ATOM
)
1680 Atom
*atoms
= (Atom
*) catoms
;
1685 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
1686 need_delete
= false;
1687 else if (atoms
[nitems
]
1688 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
1690 else if (atoms
[nitems
]
1691 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
1702 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
1704 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
1706 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
1708 XChangeProperty (dpy
, w
, FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1709 XA_ATOM
, 32, PropModeAppend
,
1710 (unsigned char *) props
, count
);
1718 /* Support routines for XIC (X Input Context). */
1722 static XFontSet
xic_create_xfontset (struct frame
*);
1723 static XIMStyle
best_xim_style (XIMStyles
*);
1726 /* Supported XIM styles, ordered by preference. */
1728 static const XIMStyle supported_xim_styles
[] =
1730 XIMPreeditPosition
| XIMStatusArea
,
1731 XIMPreeditPosition
| XIMStatusNothing
,
1732 XIMPreeditPosition
| XIMStatusNone
,
1733 XIMPreeditNothing
| XIMStatusArea
,
1734 XIMPreeditNothing
| XIMStatusNothing
,
1735 XIMPreeditNothing
| XIMStatusNone
,
1736 XIMPreeditNone
| XIMStatusArea
,
1737 XIMPreeditNone
| XIMStatusNothing
,
1738 XIMPreeditNone
| XIMStatusNone
,
1743 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1744 /* Create an X fontset on frame F with base font name BASE_FONTNAME. */
1746 static const char xic_default_fontset
[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
1748 /* Create an Xt fontset spec from the name of a base font.
1749 If `motif' is True use the Motif syntax. */
1751 xic_create_fontsetname (const char *base_fontname
, bool motif
)
1753 const char *sep
= motif
? ";" : ",";
1757 /* Make a fontset name from the base font name. */
1758 if (xic_default_fontset
== base_fontname
)
1760 /* There is no base font name, use the default. */
1761 fontsetname
= xmalloc (strlen (base_fontname
) + 2);
1762 z
= stpcpy (fontsetname
, base_fontname
);
1766 /* Make a fontset name from the base font name.
1767 The font set will be made of the following elements:
1769 - the base font where the charset spec is replaced by -*-*.
1770 - the same but with the family also replaced with -*-*-. */
1771 const char *p
= base_fontname
;
1774 for (i
= 0; *p
; p
++)
1778 /* As the font name doesn't conform to XLFD, we can't
1779 modify it to generalize it to allcs and allfamilies.
1780 Use the specified font plus the default. */
1781 fontsetname
= xmalloc (strlen (base_fontname
)
1782 + strlen (xic_default_fontset
) + 3);
1783 z
= stpcpy (fontsetname
, base_fontname
);
1784 z
= stpcpy (z
, sep
);
1785 z
= stpcpy (z
, xic_default_fontset
);
1790 const char *p1
= NULL
, *p2
= NULL
, *p3
= NULL
;
1791 char *font_allcs
= NULL
;
1792 char *font_allfamilies
= NULL
;
1793 char *font_all
= NULL
;
1794 const char *allcs
= "*-*-*-*-*-*-*";
1795 const char *allfamilies
= "-*-*-";
1796 const char *all
= "*-*-*-*-";
1799 for (i
= 0, p
= base_fontname
; i
< 8; p
++)
1812 /* If base_fontname specifies ADSTYLE, make it a
1816 ptrdiff_t diff
= (p2
- p3
) - 2;
1818 base
= alloca (strlen (base_fontname
) + 1);
1819 memcpy (base
, base_fontname
, p3
- base_fontname
);
1820 base
[p3
- base_fontname
] = '*';
1821 base
[(p3
- base_fontname
) + 1] = '-';
1822 strcpy (base
+ (p3
- base_fontname
) + 2, p2
);
1823 p
= base
+ (p
- base_fontname
) - diff
;
1824 p1
= base
+ (p1
- base_fontname
);
1825 p2
= base
+ (p2
- base_fontname
) - diff
;
1826 base_fontname
= base
;
1829 /* Build the font spec that matches all charsets. */
1830 len
= p
- base_fontname
+ strlen (allcs
) + 1;
1831 font_allcs
= alloca (len
);
1832 memcpy (font_allcs
, base_fontname
, p
- base_fontname
);
1833 strcpy (font_allcs
+ (p
- base_fontname
), allcs
);
1835 /* Build the font spec that matches all families and
1837 len
= p
- p1
+ strlen (allcs
) + strlen (allfamilies
) + 1;
1838 font_allfamilies
= alloca (len
);
1839 strcpy (font_allfamilies
, allfamilies
);
1840 memcpy (font_allfamilies
+ strlen (allfamilies
), p1
, p
- p1
);
1841 strcpy (font_allfamilies
+ strlen (allfamilies
) + (p
- p1
), allcs
);
1843 /* Build the font spec that matches all. */
1844 len
= p
- p2
+ strlen (allcs
) + strlen (all
) + strlen (allfamilies
) + 1;
1845 font_all
= alloca (len
);
1846 z
= stpcpy (font_all
, allfamilies
);
1847 z
= stpcpy (z
, all
);
1848 memcpy (z
, p2
, p
- p2
);
1849 strcpy (z
+ (p
- p2
), allcs
);
1851 /* Build the actual font set name. */
1852 len
= strlen (base_fontname
) + strlen (font_allcs
)
1853 + strlen (font_allfamilies
) + strlen (font_all
) + 5;
1854 fontsetname
= xmalloc (len
);
1855 z
= stpcpy (fontsetname
, base_fontname
);
1856 z
= stpcpy (z
, sep
);
1857 z
= stpcpy (z
, font_allcs
);
1858 z
= stpcpy (z
, sep
);
1859 z
= stpcpy (z
, font_allfamilies
);
1860 z
= stpcpy (z
, sep
);
1861 z
= stpcpy (z
, font_all
);
1868 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
1870 #ifdef DEBUG_XIC_FONTSET
1872 print_fontset_result (XFontSet xfs
, char *name
, char **missing_list
,
1876 fprintf (stderr
, "XIC Fontset created: %s\n", name
);
1879 fprintf (stderr
, "XIC Fontset failed: %s\n", name
);
1880 while (missing_count
-- > 0)
1882 fprintf (stderr
, " missing: %s\n", *missing_list
);
1891 xic_create_xfontset (struct frame
*f
)
1893 XFontSet xfs
= NULL
;
1894 struct font
*font
= FRAME_FONT (f
);
1895 int pixel_size
= font
->pixel_size
;
1896 Lisp_Object rest
, frame
;
1898 /* See if there is another frame already using same fontset. */
1899 FOR_EACH_FRAME (rest
, frame
)
1901 struct frame
*cf
= XFRAME (frame
);
1903 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
1904 && FRAME_DISPLAY_INFO (cf
) == FRAME_DISPLAY_INFO (f
)
1906 && FRAME_FONT (f
)->pixel_size
== pixel_size
)
1908 xfs
= FRAME_XIC_FONTSET (cf
);
1916 char **missing_list
;
1919 const char *xlfd_format
= "-*-*-medium-r-normal--%d-*-*-*-*-*";
1921 sprintf (buf
, xlfd_format
, pixel_size
);
1922 missing_list
= NULL
;
1923 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
1924 &missing_list
, &missing_count
, &def_string
);
1925 #ifdef DEBUG_XIC_FONTSET
1926 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
1929 XFreeStringList (missing_list
);
1932 /* List of pixel sizes most likely available. Find one that
1933 is closest to pixel_size. */
1934 int sizes
[] = {0, 8, 10, 11, 12, 14, 17, 18, 20, 24, 26, 34, 0};
1935 int *smaller
, *larger
;
1937 for (smaller
= sizes
; smaller
[1]; smaller
++)
1938 if (smaller
[1] >= pixel_size
)
1940 larger
= smaller
+ 1;
1941 if (*larger
== pixel_size
)
1943 while (*smaller
|| *larger
)
1948 this_size
= *smaller
--;
1949 else if (! *smaller
)
1950 this_size
= *larger
++;
1951 else if (pixel_size
- *smaller
< *larger
- pixel_size
)
1952 this_size
= *smaller
--;
1954 this_size
= *larger
++;
1955 sprintf (buf
, xlfd_format
, this_size
);
1956 missing_list
= NULL
;
1957 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
1958 &missing_list
, &missing_count
, &def_string
);
1959 #ifdef DEBUG_XIC_FONTSET
1960 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
1963 XFreeStringList (missing_list
);
1970 const char *last_resort
= "-*-*-*-r-normal--*-*-*-*-*-*";
1972 missing_list
= NULL
;
1973 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), last_resort
,
1974 &missing_list
, &missing_count
, &def_string
);
1975 #ifdef DEBUG_XIC_FONTSET
1976 print_fontset_result (xfs
, last_resort
, missing_list
, missing_count
);
1979 XFreeStringList (missing_list
);
1987 /* Free the X fontset of frame F if it is the last frame using it. */
1990 xic_free_xfontset (struct frame
*f
)
1992 Lisp_Object rest
, frame
;
1993 bool shared_p
= false;
1995 if (!FRAME_XIC_FONTSET (f
))
1998 /* See if there is another frame sharing the same fontset. */
1999 FOR_EACH_FRAME (rest
, frame
)
2001 struct frame
*cf
= XFRAME (frame
);
2002 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
2003 && FRAME_DISPLAY_INFO (cf
) == FRAME_DISPLAY_INFO (f
)
2004 && FRAME_XIC_FONTSET (cf
) == FRAME_XIC_FONTSET (f
))
2012 /* The fontset is not used anymore. It is safe to free it. */
2013 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
2015 FRAME_XIC_FONTSET (f
) = NULL
;
2019 /* Value is the best input style, given user preferences USER (already
2020 checked to be supported by Emacs), and styles supported by the
2021 input method XIM. */
2024 best_xim_style (XIMStyles
*xim
)
2027 int nr_supported
= ARRAYELTS (supported_xim_styles
);
2029 for (i
= 0; i
< nr_supported
; ++i
)
2030 for (j
= 0; j
< xim
->count_styles
; ++j
)
2031 if (supported_xim_styles
[i
] == xim
->supported_styles
[j
])
2032 return supported_xim_styles
[i
];
2034 /* Return the default style. */
2035 return XIMPreeditNothing
| XIMStatusNothing
;
2038 /* Create XIC for frame F. */
2041 create_frame_xic (struct frame
*f
)
2045 XFontSet xfs
= NULL
;
2046 XVaNestedList status_attr
= NULL
;
2047 XVaNestedList preedit_attr
= NULL
;
2055 xim
= FRAME_X_XIM (f
);
2059 /* Determine XIC style. */
2060 xic_style
= best_xim_style (FRAME_X_XIM_STYLES (f
));
2062 /* Create X fontset. */
2063 if (xic_style
& (XIMPreeditPosition
| XIMStatusArea
))
2065 xfs
= xic_create_xfontset (f
);
2069 FRAME_XIC_FONTSET (f
) = xfs
;
2072 if (xic_style
& XIMPreeditPosition
)
2074 spot
.x
= 0; spot
.y
= 1;
2075 preedit_attr
= XVaCreateNestedList (0,
2078 FRAME_FOREGROUND_PIXEL (f
),
2080 FRAME_BACKGROUND_PIXEL (f
),
2081 (xic_style
& XIMPreeditPosition
2091 if (xic_style
& XIMStatusArea
)
2093 s_area
.x
= 0; s_area
.y
= 0; s_area
.width
= 1; s_area
.height
= 1;
2094 status_attr
= XVaCreateNestedList (0,
2100 FRAME_FOREGROUND_PIXEL (f
),
2102 FRAME_BACKGROUND_PIXEL (f
),
2109 if (preedit_attr
&& status_attr
)
2110 xic
= XCreateIC (xim
,
2111 XNInputStyle
, xic_style
,
2112 XNClientWindow
, FRAME_X_WINDOW (f
),
2113 XNFocusWindow
, FRAME_X_WINDOW (f
),
2114 XNStatusAttributes
, status_attr
,
2115 XNPreeditAttributes
, preedit_attr
,
2117 else if (preedit_attr
)
2118 xic
= XCreateIC (xim
,
2119 XNInputStyle
, xic_style
,
2120 XNClientWindow
, FRAME_X_WINDOW (f
),
2121 XNFocusWindow
, FRAME_X_WINDOW (f
),
2122 XNPreeditAttributes
, preedit_attr
,
2124 else if (status_attr
)
2125 xic
= XCreateIC (xim
,
2126 XNInputStyle
, xic_style
,
2127 XNClientWindow
, FRAME_X_WINDOW (f
),
2128 XNFocusWindow
, FRAME_X_WINDOW (f
),
2129 XNStatusAttributes
, status_attr
,
2132 xic
= XCreateIC (xim
,
2133 XNInputStyle
, xic_style
,
2134 XNClientWindow
, FRAME_X_WINDOW (f
),
2135 XNFocusWindow
, FRAME_X_WINDOW (f
),
2141 FRAME_XIC (f
) = xic
;
2142 FRAME_XIC_STYLE (f
) = xic_style
;
2143 xfs
= NULL
; /* Don't free below. */
2151 XFree (preedit_attr
);
2154 XFree (status_attr
);
2158 /* Destroy XIC and free XIC fontset of frame F, if any. */
2161 free_frame_xic (struct frame
*f
)
2163 if (FRAME_XIC (f
) == NULL
)
2166 XDestroyIC (FRAME_XIC (f
));
2167 xic_free_xfontset (f
);
2169 FRAME_XIC (f
) = NULL
;
2173 /* Place preedit area for XIC of window W's frame to specified
2174 pixel position X/Y. X and Y are relative to window W. */
2177 xic_set_preeditarea (struct window
*w
, int x
, int y
)
2179 struct frame
*f
= XFRAME (w
->frame
);
2183 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
) + WINDOW_LEFT_FRINGE_WIDTH (w
);
2184 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
2185 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
2186 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2191 /* Place status area for XIC in bottom right corner of frame F.. */
2194 xic_set_statusarea (struct frame
*f
)
2196 XIC xic
= FRAME_XIC (f
);
2201 /* Negotiate geometry of status area. If input method has existing
2202 status area, use its current size. */
2203 area
.x
= area
.y
= area
.width
= area
.height
= 0;
2204 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
2205 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2208 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
2209 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2212 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
2214 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
2215 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2219 area
.width
= needed
->width
;
2220 area
.height
= needed
->height
;
2221 area
.x
= FRAME_PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
2222 area
.y
= (FRAME_PIXEL_HEIGHT (f
) - area
.height
2223 - FRAME_MENUBAR_HEIGHT (f
)
2224 - FRAME_TOOLBAR_TOP_HEIGHT (f
)
2225 - FRAME_INTERNAL_BORDER_WIDTH (f
));
2228 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
2229 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2234 /* Set X fontset for XIC of frame F, using base font name
2235 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2238 xic_set_xfontset (struct frame
*f
, const char *base_fontname
)
2243 xic_free_xfontset (f
);
2245 xfs
= xic_create_xfontset (f
);
2247 attr
= XVaCreateNestedList (0, XNFontSet
, xfs
, NULL
);
2248 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
2249 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2250 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
2251 XSetICValues (FRAME_XIC (f
), XNStatusAttributes
, attr
, NULL
);
2254 FRAME_XIC_FONTSET (f
) = xfs
;
2257 #endif /* HAVE_X_I18N */
2261 #ifdef USE_X_TOOLKIT
2263 /* Create and set up the X widget for frame F. */
2266 x_window (struct frame
*f
, long window_prompting
)
2268 XClassHint class_hints
;
2269 XSetWindowAttributes attributes
;
2270 unsigned long attribute_mask
;
2271 Widget shell_widget
;
2273 Widget frame_widget
;
2279 /* Use the resource name as the top-level widget name
2280 for looking up resources. Make a non-Lisp copy
2281 for the window manager, so GC relocation won't bother it.
2283 Elsewhere we specify the window name for the window manager. */
2284 f
->namebuf
= xlispstrdup (Vx_resource_name
);
2287 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2288 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2289 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2290 XtSetArg (al
[ac
], XtNborderWidth
, f
->border_width
); ac
++;
2291 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2292 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2293 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2294 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2295 applicationShellWidgetClass
,
2296 FRAME_X_DISPLAY (f
), al
, ac
);
2298 f
->output_data
.x
->widget
= shell_widget
;
2299 /* maybe_set_screen_title_format (shell_widget); */
2301 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2302 NULL
, shell_widget
, False
,
2303 NULL
, NULL
, NULL
, NULL
);
2306 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2307 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2308 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2309 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2310 XtSetValues (pane_widget
, al
, ac
);
2311 f
->output_data
.x
->column_widget
= pane_widget
;
2313 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2314 the emacs screen when changing menubar. This reduces flickering. */
2317 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2318 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2319 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2320 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2321 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2322 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2323 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2324 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2325 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2326 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
2329 f
->output_data
.x
->edit_widget
= frame_widget
;
2331 XtManageChild (frame_widget
);
2333 /* Do some needed geometry management. */
2337 int extra_borders
= 0;
2339 = (f
->output_data
.x
->menubar_widget
2340 ? (f
->output_data
.x
->menubar_widget
->core
.height
2341 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
2344 #if false /* Experimentally, we now get the right results
2345 for -geometry -0-0 without this. 24 Aug 96, rms. */
2346 if (FRAME_EXTERNAL_MENU_BAR (f
))
2349 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2350 menubar_size
+= ibw
;
2354 FRAME_MENUBAR_HEIGHT (f
) = menubar_size
;
2357 /* Motif seems to need this amount added to the sizes
2358 specified for the shell widget. The Athena/Lucid widgets don't.
2359 Both conclusions reached experimentally. -- rms. */
2360 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
2361 &extra_borders
, NULL
);
2365 f
->shell_position
= xmalloc (sizeof "=x++" + 4 * INT_STRLEN_BOUND (int));
2367 /* Convert our geometry parameters into a geometry string
2369 Note that we do not specify here whether the position
2370 is a user-specified or program-specified one.
2371 We pass that information later, in x_wm_set_size_hints. */
2373 int left
= f
->left_pos
;
2374 bool xneg
= (window_prompting
& XNegative
) != 0;
2375 int top
= f
->top_pos
;
2376 bool yneg
= (window_prompting
& YNegative
) != 0;
2382 if (window_prompting
& USPosition
)
2383 sprintf (f
->shell_position
, "=%dx%d%c%d%c%d",
2384 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2385 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
2386 (xneg
? '-' : '+'), left
,
2387 (yneg
? '-' : '+'), top
);
2390 sprintf (f
->shell_position
, "=%dx%d",
2391 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2392 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
2394 /* Setting x and y when the position is not specified in
2395 the geometry string will set program position in the WM hints.
2396 If Emacs had just one program position, we could set it in
2397 fallback resources, but since each make-frame call can specify
2398 different program positions, this is easier. */
2399 XtSetArg (gal
[gac
], XtNx
, left
); gac
++;
2400 XtSetArg (gal
[gac
], XtNy
, top
); gac
++;
2404 XtSetArg (gal
[gac
], XtNgeometry
, f
->shell_position
); gac
++;
2405 XtSetValues (shell_widget
, gal
, gac
);
2408 XtManageChild (pane_widget
);
2409 XtRealizeWidget (shell_widget
);
2411 if (FRAME_X_EMBEDDED_P (f
))
2412 XReparentWindow (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
),
2413 f
->output_data
.x
->parent_desc
, 0, 0);
2415 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2417 validate_x_resource_name ();
2419 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2420 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2421 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2424 FRAME_XIC (f
) = NULL
;
2426 create_frame_xic (f
);
2429 f
->output_data
.x
->wm_hints
.input
= True
;
2430 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2431 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2432 &f
->output_data
.x
->wm_hints
);
2434 hack_wm_protocols (f
, shell_widget
);
2437 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2440 /* Do a stupid property change to force the server to generate a
2441 PropertyNotify event so that the event_stream server timestamp will
2442 be initialized to something relevant to the time we created the window.
2444 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2445 FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2446 XA_ATOM
, 32, PropModeAppend
, NULL
, 0);
2448 /* Make all the standard events reach the Emacs frame. */
2449 attributes
.event_mask
= STANDARD_EVENT_SET
;
2454 /* XIM server might require some X events. */
2455 unsigned long fevent
= NoEventMask
;
2456 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2457 attributes
.event_mask
|= fevent
;
2459 #endif /* HAVE_X_I18N */
2461 attribute_mask
= CWEventMask
;
2462 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2463 attribute_mask
, &attributes
);
2465 XtMapWidget (frame_widget
);
2467 /* x_set_name normally ignores requests to set the name if the
2468 requested name is the same as the current name. This is the one
2469 place where that assumption isn't correct; f->name is set, but
2470 the X server hasn't been told. */
2473 bool explicit = f
->explicit_name
;
2475 f
->explicit_name
= false;
2477 fset_name (f
, Qnil
);
2478 x_set_name (f
, name
, explicit);
2481 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2482 f
->output_data
.x
->current_cursor
2483 = f
->output_data
.x
->text_cursor
);
2487 /* This is a no-op, except under Motif. Make sure main areas are
2488 set to something reasonable, in case we get an error later. */
2489 lw_set_main_areas (pane_widget
, 0, frame_widget
);
2492 #else /* not USE_X_TOOLKIT */
2495 x_window (struct frame
*f
)
2497 if (! xg_create_frame_widgets (f
))
2498 error ("Unable to create window");
2501 FRAME_XIC (f
) = NULL
;
2505 create_frame_xic (f
);
2508 /* XIM server might require some X events. */
2509 unsigned long fevent
= NoEventMask
;
2510 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2512 if (fevent
!= NoEventMask
)
2514 XSetWindowAttributes attributes
;
2515 XWindowAttributes wattr
;
2516 unsigned long attribute_mask
;
2518 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2520 attributes
.event_mask
= wattr
.your_event_mask
| fevent
;
2521 attribute_mask
= CWEventMask
;
2522 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2523 attribute_mask
, &attributes
);
2531 #else /*! USE_GTK */
2532 /* Create and set up the X window for frame F. */
2535 x_window (struct frame
*f
)
2537 XClassHint class_hints
;
2538 XSetWindowAttributes attributes
;
2539 unsigned long attribute_mask
;
2541 attributes
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2542 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
2543 attributes
.bit_gravity
= StaticGravity
;
2544 attributes
.backing_store
= NotUseful
;
2545 attributes
.save_under
= True
;
2546 attributes
.event_mask
= STANDARD_EVENT_SET
;
2547 attributes
.colormap
= FRAME_X_COLORMAP (f
);
2548 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
2553 = XCreateWindow (FRAME_X_DISPLAY (f
),
2554 f
->output_data
.x
->parent_desc
,
2557 FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
),
2559 CopyFromParent
, /* depth */
2560 InputOutput
, /* class */
2562 attribute_mask
, &attributes
);
2567 create_frame_xic (f
);
2570 /* XIM server might require some X events. */
2571 unsigned long fevent
= NoEventMask
;
2572 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2573 attributes
.event_mask
|= fevent
;
2574 attribute_mask
= CWEventMask
;
2575 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2576 attribute_mask
, &attributes
);
2579 #endif /* HAVE_X_I18N */
2581 validate_x_resource_name ();
2583 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2584 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2585 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2587 /* This indicates that we use the "Passive Input" input model.
2588 Unless we do this, we don't get the Focus{In,Out} events that we
2589 need to draw the cursor correctly. Accursed bureaucrats.
2590 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2592 f
->output_data
.x
->wm_hints
.input
= True
;
2593 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2594 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2595 &f
->output_data
.x
->wm_hints
);
2596 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
2598 /* Request "save yourself" and "delete window" commands from wm. */
2601 protocols
[0] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2602 protocols
[1] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2603 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2606 /* x_set_name normally ignores requests to set the name if the
2607 requested name is the same as the current name. This is the one
2608 place where that assumption isn't correct; f->name is set, but
2609 the X server hasn't been told. */
2612 bool explicit = f
->explicit_name
;
2614 f
->explicit_name
= false;
2616 fset_name (f
, Qnil
);
2617 x_set_name (f
, name
, explicit);
2620 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2621 f
->output_data
.x
->current_cursor
2622 = f
->output_data
.x
->text_cursor
);
2626 if (FRAME_X_WINDOW (f
) == 0)
2627 error ("Unable to create window");
2630 #endif /* not USE_GTK */
2631 #endif /* not USE_X_TOOLKIT */
2633 /* Verify that the icon position args for this window are valid. */
2636 x_icon_verify (struct frame
*f
, Lisp_Object parms
)
2638 Lisp_Object icon_x
, icon_y
;
2640 /* Set the position of the icon. Note that twm groups all
2641 icons in an icon window. */
2642 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2643 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2644 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2646 CHECK_NUMBER (icon_x
);
2647 CHECK_NUMBER (icon_y
);
2649 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2650 error ("Both left and top icon corners of icon must be specified");
2653 /* Handle the icon stuff for this window. Perhaps later we might
2654 want an x_set_icon_position which can be called interactively as
2658 x_icon (struct frame
*f
, Lisp_Object parms
)
2660 /* Set the position of the icon. Note that twm groups all
2661 icons in an icon window. */
2663 = x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2665 = x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2666 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2668 CHECK_TYPE_RANGED_INTEGER (int, icon_x
);
2669 CHECK_TYPE_RANGED_INTEGER (int, icon_y
);
2671 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2672 error ("Both left and top icon corners of icon must be specified");
2676 if (! EQ (icon_x
, Qunbound
))
2677 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2679 #if false /* x_get_arg removes the visibility parameter as a side effect,
2680 but x_create_frame still needs it. */
2681 /* Start up iconic or window? */
2682 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2683 x_wm_set_window_state
2684 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
2690 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
2697 /* Make the GCs needed for this window, setting the
2698 background, border and mouse colors; also create the
2699 mouse cursor and the gray border tile. */
2702 x_make_gc (struct frame
*f
)
2704 XGCValues gc_values
;
2708 /* Create the GCs of this frame.
2709 Note that many default values are used. */
2711 gc_values
.foreground
= FRAME_FOREGROUND_PIXEL (f
);
2712 gc_values
.background
= FRAME_BACKGROUND_PIXEL (f
);
2713 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2714 f
->output_data
.x
->normal_gc
2715 = XCreateGC (FRAME_X_DISPLAY (f
),
2717 GCLineWidth
| GCForeground
| GCBackground
,
2720 /* Reverse video style. */
2721 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2722 gc_values
.background
= FRAME_FOREGROUND_PIXEL (f
);
2723 f
->output_data
.x
->reverse_gc
2724 = XCreateGC (FRAME_X_DISPLAY (f
),
2726 GCForeground
| GCBackground
| GCLineWidth
,
2729 /* Cursor has cursor-color background, background-color foreground. */
2730 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2731 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
2732 gc_values
.fill_style
= FillOpaqueStippled
;
2733 f
->output_data
.x
->cursor_gc
2734 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2735 (GCForeground
| GCBackground
2736 | GCFillStyle
| GCLineWidth
),
2739 /* Create the gray border tile used when the pointer is not in
2740 the frame. Since this depends on the frame's pixel values,
2741 this must be done on a per-frame basis. */
2742 f
->output_data
.x
->border_tile
2743 = (XCreatePixmapFromBitmapData
2744 (FRAME_X_DISPLAY (f
), FRAME_DISPLAY_INFO (f
)->root_window
,
2745 gray_bits
, gray_width
, gray_height
,
2746 FRAME_FOREGROUND_PIXEL (f
),
2747 FRAME_BACKGROUND_PIXEL (f
),
2748 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
2754 /* Free what was allocated in x_make_gc. */
2757 x_free_gcs (struct frame
*f
)
2759 Display
*dpy
= FRAME_X_DISPLAY (f
);
2763 if (f
->output_data
.x
->normal_gc
)
2765 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
2766 f
->output_data
.x
->normal_gc
= 0;
2769 if (f
->output_data
.x
->reverse_gc
)
2771 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
2772 f
->output_data
.x
->reverse_gc
= 0;
2775 if (f
->output_data
.x
->cursor_gc
)
2777 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
2778 f
->output_data
.x
->cursor_gc
= 0;
2781 if (f
->output_data
.x
->border_tile
)
2783 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
2784 f
->output_data
.x
->border_tile
= 0;
2791 /* Handler for signals raised during x_create_frame and
2792 x_create_tip_frame. FRAME is the frame which is partially
2796 unwind_create_frame (Lisp_Object frame
)
2798 struct frame
*f
= XFRAME (frame
);
2800 /* If frame is already dead, nothing to do. This can happen if the
2801 display is disconnected after the frame has become official, but
2802 before x_create_frame removes the unwind protect. */
2803 if (!FRAME_LIVE_P (f
))
2806 /* If frame is ``official'', nothing to do. */
2807 if (NILP (Fmemq (frame
, Vframe_list
)))
2809 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2810 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2813 x_free_frame_resources (f
);
2816 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2817 /* Check that reference counts are indeed correct. */
2818 eassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
2819 eassert (dpyinfo
->terminal
->image_cache
->refcount
== image_cache_refcount
);
2828 do_unwind_create_frame (Lisp_Object frame
)
2830 unwind_create_frame (frame
);
2834 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
2836 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2837 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
2839 Lisp_Object font
= Qnil
;
2840 if (EQ (font_param
, Qunbound
))
2843 if (NILP (font_param
))
2845 /* System font should take precedence over X resources. We suggest this
2846 regardless of font-use-system-font because .emacs may not have been
2848 const char *system_font
= xsettings_get_system_font ();
2850 font
= font_open_by_name (f
, build_unibyte_string (system_font
));
2854 font
= !NILP (font_param
) ? font_param
2855 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
2857 if (! FONTP (font
) && ! STRINGP (font
))
2862 /* This will find the normal Xft font. */
2865 "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1",
2866 "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2867 "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2868 /* This was formerly the first thing tried, but it finds
2869 too many fonts and takes too long. */
2870 "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1",
2871 /* If those didn't work, look for something which will
2873 "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1",
2878 for (i
= 0; names
[i
]; i
++)
2880 font
= font_open_by_name (f
, build_unibyte_string (names
[i
]));
2885 error ("No suitable font was found");
2887 else if (!NILP (font_param
))
2889 /* Remember the explicit font parameter, so we can re-apply it after
2890 we've applied the `default' face settings. */
2891 AUTO_FRAME_ARG (arg
, Qfont_param
, font_param
);
2892 x_set_frame_parameters (f
, arg
);
2895 /* This call will make X resources override any system font setting. */
2896 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
2900 DEFUN ("x-wm-set-size-hint", Fx_wm_set_size_hint
, Sx_wm_set_size_hint
,
2902 doc
: /* Send the size hints for frame FRAME to the window manager.
2903 If FRAME is omitted or nil, use the selected frame.
2904 Signal error if FRAME is not an X frame. */)
2907 struct frame
*f
= decode_window_system_frame (frame
);
2910 x_wm_set_size_hint (f
, 0, false);
2916 set_machine_and_pid_properties (struct frame
*f
)
2918 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME. */
2919 XSetWMProperties (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), NULL
, NULL
,
2920 NULL
, 0, NULL
, NULL
, NULL
);
2921 pid_t pid
= getpid ();
2922 if (pid
<= 0xffffffffu
)
2924 unsigned long xpid
= pid
;
2925 XChangeProperty (FRAME_X_DISPLAY (f
),
2926 FRAME_OUTER_WINDOW (f
),
2927 XInternAtom (FRAME_X_DISPLAY (f
),
2930 XA_CARDINAL
, 32, PropModeReplace
,
2931 (unsigned char *) &xpid
, 1);
2935 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
2937 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
2938 Return an Emacs frame object. PARMS is an alist of frame parameters.
2939 If the parameters specify that the frame should not have a minibuffer,
2940 and do not specify a specific minibuffer window to use, then
2941 `default-minibuffer-frame' must be a frame whose minibuffer can be
2942 shared by the new frame.
2944 This function is an internal primitive--use `make-frame' instead. */)
2948 Lisp_Object frame
, tem
;
2950 bool minibuffer_only
= false;
2951 long window_prompting
= 0;
2952 ptrdiff_t count
= SPECPDL_INDEX ();
2953 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
2954 Lisp_Object display
;
2955 struct x_display_info
*dpyinfo
= NULL
;
2959 parms
= Fcopy_alist (parms
);
2961 /* Use this general default value to start with
2962 until we know if this frame has a specified name. */
2963 Vx_resource_name
= Vinvocation_name
;
2965 display
= x_get_arg (dpyinfo
, parms
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
2966 if (EQ (display
, Qunbound
))
2967 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
2968 if (EQ (display
, Qunbound
))
2970 dpyinfo
= check_x_display_info (display
);
2971 kb
= dpyinfo
->terminal
->kboard
;
2973 if (!dpyinfo
->terminal
->name
)
2974 error ("Terminal is not live, can't create new frames on it");
2976 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
2978 && ! EQ (name
, Qunbound
)
2980 error ("Invalid frame name--not a string or nil");
2983 Vx_resource_name
= name
;
2985 /* See if parent window is specified. */
2986 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
2987 if (EQ (parent
, Qunbound
))
2989 if (! NILP (parent
))
2990 CHECK_NUMBER (parent
);
2992 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
2993 /* No need to protect DISPLAY because that's not used after passing
2994 it to make_frame_without_minibuffer. */
2996 GCPRO4 (parms
, parent
, name
, frame
);
2997 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
2999 if (EQ (tem
, Qnone
) || NILP (tem
))
3000 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
3001 else if (EQ (tem
, Qonly
))
3003 f
= make_minibuffer_frame ();
3004 minibuffer_only
= true;
3006 else if (WINDOWP (tem
))
3007 f
= make_frame_without_minibuffer (tem
, kb
, display
);
3009 f
= make_frame (true);
3011 XSETFRAME (frame
, f
);
3013 f
->terminal
= dpyinfo
->terminal
;
3015 f
->output_method
= output_x_window
;
3016 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
3017 f
->output_data
.x
->icon_bitmap
= -1;
3018 FRAME_FONTSET (f
) = -1;
3019 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
3020 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
3021 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
3022 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
3023 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
3024 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
3025 f
->output_data
.x
->white_relief
.pixel
= -1;
3026 f
->output_data
.x
->black_relief
.pixel
= -1;
3029 x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
3031 if (! STRINGP (f
->icon_name
))
3032 fset_icon_name (f
, Qnil
);
3034 FRAME_DISPLAY_INFO (f
) = dpyinfo
;
3036 /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe. */
3037 record_unwind_protect (do_unwind_create_frame
, frame
);
3039 /* These colors will be set anyway later, but it's important
3040 to get the color reference counts right, so initialize them! */
3043 struct gcpro gcpro1
;
3045 /* Function x_decode_color can signal an error. Make
3046 sure to initialize color slots so that we won't try
3047 to free colors we haven't allocated. */
3048 FRAME_FOREGROUND_PIXEL (f
) = -1;
3049 FRAME_BACKGROUND_PIXEL (f
) = -1;
3050 f
->output_data
.x
->cursor_pixel
= -1;
3051 f
->output_data
.x
->cursor_foreground_pixel
= -1;
3052 f
->output_data
.x
->border_pixel
= -1;
3053 f
->output_data
.x
->mouse_pixel
= -1;
3055 black
= build_string ("black");
3057 FRAME_FOREGROUND_PIXEL (f
)
3058 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3059 FRAME_BACKGROUND_PIXEL (f
)
3060 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3061 f
->output_data
.x
->cursor_pixel
3062 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3063 f
->output_data
.x
->cursor_foreground_pixel
3064 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3065 f
->output_data
.x
->border_pixel
3066 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3067 f
->output_data
.x
->mouse_pixel
3068 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3072 /* Specify the parent under which to make this X window. */
3075 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
3076 f
->output_data
.x
->explicit_parent
= true;
3080 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
3081 f
->output_data
.x
->explicit_parent
= false;
3084 /* Set the name; the functions to which we pass f expect the name to
3086 if (EQ (name
, Qunbound
) || NILP (name
))
3088 fset_name (f
, build_string (dpyinfo
->x_id_name
));
3089 f
->explicit_name
= false;
3093 fset_name (f
, name
);
3094 f
->explicit_name
= true;
3095 /* Use the frame's title when getting resources for this frame. */
3096 specbind (Qx_resource_name
, name
);
3099 #ifdef HAVE_FREETYPE
3101 register_font_driver (&xftfont_driver
, f
);
3102 #else /* not HAVE_XFT */
3103 register_font_driver (&ftxfont_driver
, f
);
3104 #endif /* not HAVE_XFT */
3105 #endif /* HAVE_FREETYPE */
3106 register_font_driver (&xfont_driver
, f
);
3108 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
3109 "fontBackend", "FontBackend", RES_TYPE_STRING
);
3111 /* Extract the window parameters from the supplied values
3112 that are needed to determine window geometry. */
3113 x_default_font_parameter (f
, parms
);
3114 if (!FRAME_FONT (f
))
3116 delete_frame (frame
, Qnoelisp
);
3117 error ("Invalid frame font");
3120 /* Frame contents get displaced if an embedded X window has a border. */
3121 if (! FRAME_X_EMBEDDED_P (f
))
3122 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
3123 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
3125 /* This defaults to 1 in order to match xterm. We recognize either
3126 internalBorderWidth or internalBorder (which is what xterm calls
3128 if (NILP (Fassq (Qinternal_border_width
, parms
)))
3132 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
3133 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
3134 if (! EQ (value
, Qunbound
))
3135 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
3138 x_default_parameter (f
, parms
, Qinternal_border_width
,
3139 #ifdef USE_GTK /* We used to impose 0 in xg_create_frame_widgets. */
3144 "internalBorderWidth", "internalBorderWidth",
3146 x_default_parameter (f
, parms
, Qright_divider_width
, make_number (0),
3147 NULL
, NULL
, RES_TYPE_NUMBER
);
3148 x_default_parameter (f
, parms
, Qbottom_divider_width
, make_number (0),
3149 NULL
, NULL
, RES_TYPE_NUMBER
);
3150 x_default_parameter (f
, parms
, Qvertical_scroll_bars
,
3151 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
3156 "verticalScrollBars", "ScrollBars",
3158 x_default_parameter (f
, parms
, Qhorizontal_scroll_bars
, Qnil
,
3159 "horizontalScrollBars", "ScrollBars",
3161 /* Also do the stuff which must be set before the window exists. */
3162 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3163 "foreground", "Foreground", RES_TYPE_STRING
);
3164 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3165 "background", "Background", RES_TYPE_STRING
);
3166 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3167 "pointerColor", "Foreground", RES_TYPE_STRING
);
3168 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3169 "borderColor", "BorderColor", RES_TYPE_STRING
);
3170 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3171 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3172 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3173 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3174 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3175 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3176 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3177 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3179 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3180 "scrollBarForeground",
3181 "ScrollBarForeground", true);
3182 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3183 "scrollBarBackground",
3184 "ScrollBarBackground", false);
3187 image_cache_refcount
=
3188 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
3189 dpyinfo_refcount
= dpyinfo
->reference_count
;
3190 #endif /* GLYPH_DEBUG */
3192 /* Init faces before x_default_parameter is called for the
3193 scroll-bar-width parameter because otherwise we end up in
3194 init_iterator with a null face cache, which should not happen. */
3195 init_frame_faces (f
);
3197 /* The following call of change_frame_size is needed since otherwise
3198 x_set_tool_bar_lines will already work with the character sizes
3199 installed by init_frame_faces while the frame's pixel size is
3200 still calculated from a character size of 1 and we subsequently
3201 hit the (height >= 0) assertion in window_box_height.
3203 The non-pixelwise code apparently worked around this because it
3204 had one frame line vs one toolbar line which left us with a zero
3205 root window height which was obviously wrong as well ... */
3206 adjust_frame_size (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
),
3207 FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
), 5, true,
3210 /* Set the menu-bar-lines and tool-bar-lines parameters. We don't
3211 look up the X resources controlling the menu-bar and tool-bar
3212 here; they are processed specially at startup, and reflected in
3213 the values of the mode variables. */
3215 x_default_parameter (f
, parms
, Qmenu_bar_lines
,
3216 NILP (Vmenu_bar_mode
)
3217 ? make_number (0) : make_number (1),
3218 NULL
, NULL
, RES_TYPE_NUMBER
);
3219 x_default_parameter (f
, parms
, Qtool_bar_lines
,
3220 NILP (Vtool_bar_mode
)
3221 ? make_number (0) : make_number (1),
3222 NULL
, NULL
, RES_TYPE_NUMBER
);
3224 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3225 "bufferPredicate", "BufferPredicate",
3227 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3228 "title", "Title", RES_TYPE_STRING
);
3229 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3230 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3231 x_default_parameter (f
, parms
, Qtool_bar_position
,
3232 FRAME_TOOL_BAR_POSITION (f
), 0, 0, RES_TYPE_SYMBOL
);
3234 /* Compute the size of the X window. */
3235 window_prompting
= x_figure_window_size (f
, parms
, true);
3237 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3238 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3240 x_icon_verify (f
, parms
);
3242 /* Create the X widget or window. */
3243 #ifdef USE_X_TOOLKIT
3244 x_window (f
, window_prompting
);
3252 /* Now consider the frame official. */
3253 f
->terminal
->reference_count
++;
3254 FRAME_DISPLAY_INFO (f
)->reference_count
++;
3255 Vframe_list
= Fcons (frame
, Vframe_list
);
3257 /* We need to do this after creating the X window, so that the
3258 icon-creation functions can say whose icon they're describing. */
3259 x_default_parameter (f
, parms
, Qicon_type
, Qt
,
3260 "bitmapIcon", "BitmapIcon", RES_TYPE_BOOLEAN
);
3262 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3263 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3264 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3265 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3266 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3267 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3268 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3269 "scrollBarWidth", "ScrollBarWidth",
3271 x_default_parameter (f
, parms
, Qscroll_bar_height
, Qnil
,
3272 "scrollBarHeight", "ScrollBarHeight",
3274 x_default_parameter (f
, parms
, Qalpha
, Qnil
,
3275 "alpha", "Alpha", RES_TYPE_NUMBER
);
3277 /* Consider frame official, now. */
3278 f
->can_x_set_window_size
= true;
3280 adjust_frame_size (f
, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
), 0, true,
3283 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3284 /* Create the menu bar. */
3285 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3287 /* If this signals an error, we haven't set size hints for the
3288 frame and we didn't make it visible. */
3289 initialize_frame_menubar (f
);
3292 /* This is a no-op, except under Motif where it arranges the
3293 main window for the widgets on it. */
3294 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3295 f
->output_data
.x
->menubar_widget
,
3296 f
->output_data
.x
->edit_widget
);
3297 #endif /* not USE_GTK */
3299 #endif /* USE_X_TOOLKIT || USE_GTK */
3301 /* Tell the server what size and position, etc, we want, and how
3302 badly we want them. This should be done after we have the menu
3303 bar so that its size can be taken into account. */
3305 x_wm_set_size_hint (f
, window_prompting
, false);
3308 /* Process fullscreen parameter here in the hope that normalizing a
3309 fullheight/fullwidth frame will produce the size set by the last
3310 adjust_frame_size call. */
3311 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3312 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3314 /* Make the window appear on the frame and enable display, unless
3315 the caller says not to. However, with explicit parent, Emacs
3316 cannot control visibility, so don't try. */
3317 if (! f
->output_data
.x
->explicit_parent
)
3319 Lisp_Object visibility
;
3321 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3323 if (EQ (visibility
, Qunbound
))
3326 if (EQ (visibility
, Qicon
))
3327 x_iconify_frame (f
);
3328 else if (! NILP (visibility
))
3329 x_make_frame_visible (f
);
3332 /* Must have been Qnil. */
3338 /* Set machine name and pid for the purpose of window managers. */
3339 set_machine_and_pid_properties (f
);
3341 /* Set the WM leader property. GTK does this itself, so this is not
3342 needed when using GTK. */
3343 if (dpyinfo
->client_leader_window
!= 0)
3345 XChangeProperty (FRAME_X_DISPLAY (f
),
3346 FRAME_OUTER_WINDOW (f
),
3347 dpyinfo
->Xatom_wm_client_leader
,
3348 XA_WINDOW
, 32, PropModeReplace
,
3349 (unsigned char *) &dpyinfo
->client_leader_window
, 1);
3354 /* Initialize `default-minibuffer-frame' in case this is the first
3355 frame on this terminal. */
3356 if (FRAME_HAS_MINIBUF_P (f
)
3357 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
3358 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
3359 kset_default_minibuffer_frame (kb
, frame
);
3361 /* All remaining specified parameters, which have not been "used"
3362 by x_get_arg and friends, now go in the misc. alist of the frame. */
3363 for (tem
= parms
; CONSP (tem
); tem
= XCDR (tem
))
3364 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
3365 fset_param_alist (f
, Fcons (XCAR (tem
), f
->param_alist
));
3369 /* Make sure windows on this frame appear in calls to next-window
3370 and similar functions. */
3371 Vwindow_list
= Qnil
;
3373 return unbind_to (count
, frame
);
3377 /* FRAME is used only to get a handle on the X display. We don't pass the
3378 display info directly because we're called from frame.c, which doesn't
3379 know about that structure. */
3382 x_get_focus_frame (struct frame
*frame
)
3384 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (frame
);
3386 if (! dpyinfo
->x_focus_frame
)
3389 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3394 /* In certain situations, when the window manager follows a
3395 click-to-focus policy, there seems to be no way around calling
3396 XSetInputFocus to give another frame the input focus .
3398 In an ideal world, XSetInputFocus should generally be avoided so
3399 that applications don't interfere with the window manager's focus
3400 policy. But I think it's okay to use when it's clearly done
3401 following a user-command. */
3404 x_focus_frame (struct frame
*f
)
3406 Display
*dpy
= FRAME_X_DISPLAY (f
);
3409 x_catch_errors (dpy
);
3411 if (FRAME_X_EMBEDDED_P (f
))
3413 /* For Xembedded frames, normally the embedder forwards key
3414 events. See XEmbed Protocol Specification at
3415 http://freedesktop.org/wiki/Specifications/xembed-spec */
3416 xembed_request_focus (f
);
3420 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3421 RevertToParent
, CurrentTime
);
3422 x_ewmh_activate_frame (f
);
3425 x_uncatch_errors ();
3430 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
3431 doc
: /* Internal function called by `color-defined-p', which see
3432 .\(Note that the Nextstep version of this function ignores FRAME.) */)
3433 (Lisp_Object color
, Lisp_Object frame
)
3436 struct frame
*f
= decode_window_system_frame (frame
);
3438 CHECK_STRING (color
);
3440 if (x_defined_color (f
, SSDATA (color
), &foo
, false))
3446 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
3447 doc
: /* Internal function called by `color-values', which see. */)
3448 (Lisp_Object color
, Lisp_Object frame
)
3451 struct frame
*f
= decode_window_system_frame (frame
);
3453 CHECK_STRING (color
);
3455 if (x_defined_color (f
, SSDATA (color
), &foo
, false))
3456 return list3i (foo
.red
, foo
.green
, foo
.blue
);
3461 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
3462 doc
: /* Internal function called by `display-color-p', which see. */)
3463 (Lisp_Object terminal
)
3465 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3467 if (dpyinfo
->n_planes
<= 2)
3470 switch (dpyinfo
->visual
->class)
3483 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3485 doc
: /* Return t if the X display supports shades of gray.
3486 Note that color displays do support shades of gray.
3487 The optional argument TERMINAL specifies which display to ask about.
3488 TERMINAL should be a terminal object, a frame or a display name (a string).
3489 If omitted or nil, that stands for the selected frame's display. */)
3490 (Lisp_Object terminal
)
3492 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3494 if (dpyinfo
->n_planes
<= 1)
3497 switch (dpyinfo
->visual
->class)
3512 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3514 doc
: /* Return the width in pixels of the X display TERMINAL.
3515 The optional argument TERMINAL specifies which display to ask about.
3516 TERMINAL should be a terminal object, a frame or a display name (a string).
3517 If omitted or nil, that stands for the selected frame's display.
3519 On \"multi-monitor\" setups this refers to the pixel width for all
3520 physical monitors associated with TERMINAL. To get information for
3521 each physical monitor, use `display-monitor-attributes-list'. */)
3522 (Lisp_Object terminal
)
3524 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3526 return make_number (x_display_pixel_width (dpyinfo
));
3529 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3530 Sx_display_pixel_height
, 0, 1, 0,
3531 doc
: /* Return the height in pixels of the X display TERMINAL.
3532 The optional argument TERMINAL specifies which display to ask about.
3533 TERMINAL should be a terminal object, a frame or a display name (a string).
3534 If omitted or nil, that stands for the selected frame's display.
3536 On \"multi-monitor\" setups this refers to the pixel height for all
3537 physical monitors associated with TERMINAL. To get information for
3538 each physical monitor, use `display-monitor-attributes-list'. */)
3539 (Lisp_Object terminal
)
3541 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3543 return make_number (x_display_pixel_height (dpyinfo
));
3546 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3548 doc
: /* Return the number of bitplanes of the X display TERMINAL.
3549 The optional argument TERMINAL specifies which display to ask about.
3550 TERMINAL should be a terminal object, a frame or a display name (a string).
3551 If omitted or nil, that stands for the selected frame's display. */)
3552 (Lisp_Object terminal
)
3554 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3556 return make_number (dpyinfo
->n_planes
);
3559 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3561 doc
: /* Return the number of color cells of the X display TERMINAL.
3562 The optional argument TERMINAL specifies which display to ask about.
3563 TERMINAL should be a terminal object, a frame or a display name (a string).
3564 If omitted or nil, that stands for the selected frame's display. */)
3565 (Lisp_Object terminal
)
3567 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3569 int nr_planes
= DisplayPlanes (dpyinfo
->display
,
3570 XScreenNumberOfScreen (dpyinfo
->screen
));
3572 /* Truncate nr_planes to 24 to avoid integer overflow.
3573 Some displays says 32, but only 24 bits are actually significant.
3574 There are only very few and rare video cards that have more than
3575 24 significant bits. Also 24 bits is more than 16 million colors,
3576 it "should be enough for everyone". */
3577 if (nr_planes
> 24) nr_planes
= 24;
3579 return make_number (1 << nr_planes
);
3582 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3583 Sx_server_max_request_size
,
3585 doc
: /* Return the maximum request size of the X server of display TERMINAL.
3586 The optional argument TERMINAL specifies which display to ask about.
3587 TERMINAL should be a terminal object, a frame or a display name (a string).
3588 If omitted or nil, that stands for the selected frame's display. */)
3589 (Lisp_Object terminal
)
3591 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3593 return make_number (MAXREQUEST (dpyinfo
->display
));
3596 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3597 doc
: /* Return the "vendor ID" string of the GUI software on TERMINAL.
3599 \(Labeling every distributor as a "vendor" embodies the false assumption
3600 that operating systems cannot be developed and distributed noncommercially.)
3601 The optional argument TERMINAL specifies which display to ask about.
3603 For GNU and Unix systems, this queries the X server software; for
3604 MS-Windows, this queries the OS.
3606 TERMINAL should be a terminal object, a frame or a display name (a string).
3607 If omitted or nil, that stands for the selected frame's display. */)
3608 (Lisp_Object terminal
)
3610 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3611 const char *vendor
= ServerVendor (dpyinfo
->display
);
3613 if (! vendor
) vendor
= "";
3614 return build_string (vendor
);
3617 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3618 doc
: /* Return the version numbers of the GUI software on TERMINAL.
3619 The value is a list of three integers specifying the version of the GUI
3622 For GNU and Unix system, the first 2 numbers are the version of the X
3623 Protocol used on TERMINAL and the 3rd number is the distributor-specific
3624 release number. For MS-Windows, the 3 numbers report the version and
3625 the build number of the OS.
3627 See also the function `x-server-vendor'.
3629 The optional argument TERMINAL specifies which display to ask about.
3630 TERMINAL should be a terminal object, a frame or a display name (a string).
3631 If omitted or nil, that stands for the selected frame's display. */)
3632 (Lisp_Object terminal
)
3634 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3635 Display
*dpy
= dpyinfo
->display
;
3637 return list3i (ProtocolVersion (dpy
), ProtocolRevision (dpy
),
3638 VendorRelease (dpy
));
3641 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3642 doc
: /* Return the number of screens on the X server of display TERMINAL.
3643 The optional argument TERMINAL specifies which display to ask about.
3644 TERMINAL should be a terminal object, a frame or a display name (a string).
3645 If omitted or nil, that stands for the selected frame's display. */)
3646 (Lisp_Object terminal
)
3648 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3650 return make_number (ScreenCount (dpyinfo
->display
));
3653 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3654 doc
: /* Return the height in millimeters of the X display TERMINAL.
3655 The optional argument TERMINAL specifies which display to ask about.
3656 TERMINAL should be a terminal object, a frame or a display name (a string).
3657 If omitted or nil, that stands for the selected frame's display.
3659 On \"multi-monitor\" setups this refers to the height in millimeters for
3660 all physical monitors associated with TERMINAL. To get information
3661 for each physical monitor, use `display-monitor-attributes-list'. */)
3662 (Lisp_Object terminal
)
3664 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3666 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3669 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3670 doc
: /* Return the width in millimeters of the X display TERMINAL.
3671 The optional argument TERMINAL specifies which display to ask about.
3672 TERMINAL should be a terminal object, a frame or a display name (a string).
3673 If omitted or nil, that stands for the selected frame's display.
3675 On \"multi-monitor\" setups this refers to the width in millimeters for
3676 all physical monitors associated with TERMINAL. To get information
3677 for each physical monitor, use `display-monitor-attributes-list'. */)
3678 (Lisp_Object terminal
)
3680 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3682 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3685 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3686 Sx_display_backing_store
, 0, 1, 0,
3687 doc
: /* Return an indication of whether X display TERMINAL does backing store.
3688 The value may be `always', `when-mapped', or `not-useful'.
3689 The optional argument TERMINAL specifies which display to ask about.
3690 TERMINAL should be a terminal object, a frame or a display name (a string).
3691 If omitted or nil, that stands for the selected frame's display. */)
3692 (Lisp_Object terminal
)
3694 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3697 switch (DoesBackingStore (dpyinfo
->screen
))
3700 result
= intern ("always");
3704 result
= intern ("when-mapped");
3708 result
= intern ("not-useful");
3712 error ("Strange value for BackingStore parameter of screen");
3718 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3719 Sx_display_visual_class
, 0, 1, 0,
3720 doc
: /* Return the visual class of the X display TERMINAL.
3721 The value is one of the symbols `static-gray', `gray-scale',
3722 `static-color', `pseudo-color', `true-color', or `direct-color'.
3724 The optional argument TERMINAL specifies which display to ask about.
3725 TERMINAL should a terminal object, a frame or a display name (a string).
3726 If omitted or nil, that stands for the selected frame's display. */)
3727 (Lisp_Object terminal
)
3729 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3732 switch (dpyinfo
->visual
->class)
3735 result
= intern ("static-gray");
3738 result
= intern ("gray-scale");
3741 result
= intern ("static-color");
3744 result
= intern ("pseudo-color");
3747 result
= intern ("true-color");
3750 result
= intern ("direct-color");
3753 error ("Display has an unknown visual class");
3759 DEFUN ("x-display-save-under", Fx_display_save_under
,
3760 Sx_display_save_under
, 0, 1, 0,
3761 doc
: /* Return t if the X display TERMINAL supports the save-under feature.
3762 The optional argument TERMINAL specifies which display to ask about.
3763 TERMINAL should be a terminal object, a frame or a display name (a string).
3764 If omitted or nil, that stands for the selected frame's display. */)
3765 (Lisp_Object terminal
)
3767 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3769 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3775 /* Store the geometry of the workarea on display DPYINFO into *RECT.
3776 Return false if and only if the workarea information cannot be
3777 obtained via the _NET_WORKAREA root window property. */
3779 #if ! GTK_CHECK_VERSION (3, 4, 0)
3781 x_get_net_workarea (struct x_display_info
*dpyinfo
, XRectangle
*rect
)
3783 Display
*dpy
= dpyinfo
->display
;
3784 long offset
, max_len
;
3785 Atom target_type
, actual_type
;
3786 unsigned long actual_size
, bytes_remaining
;
3787 int rc
, actual_format
;
3788 unsigned char *tmp_data
= NULL
;
3789 bool result
= false;
3791 x_catch_errors (dpy
);
3794 target_type
= XA_CARDINAL
;
3795 rc
= XGetWindowProperty (dpy
, dpyinfo
->root_window
,
3796 dpyinfo
->Xatom_net_current_desktop
,
3797 offset
, max_len
, False
, target_type
,
3798 &actual_type
, &actual_format
, &actual_size
,
3799 &bytes_remaining
, &tmp_data
);
3800 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
3801 && actual_format
== 32 && actual_size
== max_len
)
3803 long current_desktop
= ((long *) tmp_data
)[0];
3808 offset
= 4 * current_desktop
;
3810 rc
= XGetWindowProperty (dpy
, dpyinfo
->root_window
,
3811 dpyinfo
->Xatom_net_workarea
,
3812 offset
, max_len
, False
, target_type
,
3813 &actual_type
, &actual_format
, &actual_size
,
3814 &bytes_remaining
, &tmp_data
);
3815 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
3816 && actual_format
== 32 && actual_size
== max_len
)
3818 long *values
= (long *) tmp_data
;
3820 rect
->x
= values
[0];
3821 rect
->y
= values
[1];
3822 rect
->width
= values
[2];
3823 rect
->height
= values
[3];
3833 x_uncatch_errors ();
3841 /* Return monitor number where F is "most" or closest to. */
3843 x_get_monitor_for_frame (struct frame
*f
,
3844 struct MonitorInfo
*monitors
,
3848 int area
= 0, dist
= -1;
3849 int best_area
= -1, best_dist
= -1;
3852 if (n_monitors
== 1) return 0;
3853 frect
.x
= f
->left_pos
;
3854 frect
.y
= f
->top_pos
;
3855 frect
.width
= FRAME_PIXEL_WIDTH (f
);
3856 frect
.height
= FRAME_PIXEL_HEIGHT (f
);
3858 for (i
= 0; i
< n_monitors
; ++i
)
3860 struct MonitorInfo
*mi
= &monitors
[i
];
3864 if (mi
->geom
.width
== 0) continue;
3866 if (x_intersect_rectangles (&mi
->geom
, &frect
, &res
))
3868 a
= res
.width
* res
.height
;
3876 if (a
== 0 && area
== 0)
3879 if (frect
.x
+ frect
.width
< mi
->geom
.x
)
3880 dx
= mi
->geom
.x
- frect
.x
+ frect
.width
;
3881 else if (frect
.x
> mi
->geom
.x
+ mi
->geom
.width
)
3882 dx
= frect
.x
- mi
->geom
.x
+ mi
->geom
.width
;
3885 if (frect
.y
+ frect
.height
< mi
->geom
.y
)
3886 dy
= mi
->geom
.y
- frect
.y
+ frect
.height
;
3887 else if (frect
.y
> mi
->geom
.y
+ mi
->geom
.height
)
3888 dy
= frect
.y
- mi
->geom
.y
+ mi
->geom
.height
;
3893 if (dist
== -1 || dist
> d
)
3901 return best_area
!= -1 ? best_area
: (best_dist
!= -1 ? best_dist
: 0);
3905 x_make_monitor_attribute_list (struct MonitorInfo
*monitors
,
3907 int primary_monitor
,
3908 struct x_display_info
*dpyinfo
,
3911 Lisp_Object monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
3912 Lisp_Object frame
, rest
;
3914 FOR_EACH_FRAME (rest
, frame
)
3916 struct frame
*f
= XFRAME (frame
);
3918 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
3919 && !EQ (frame
, tip_frame
))
3921 int i
= x_get_monitor_for_frame (f
, monitors
, n_monitors
);
3922 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
3926 return make_monitor_attribute_list (monitors
, n_monitors
, primary_monitor
,
3927 monitor_frames
, source
);
3931 x_get_monitor_attributes_fallback (struct x_display_info
*dpyinfo
)
3933 struct MonitorInfo monitor
;
3934 XRectangle workarea_r
;
3936 /* Fallback: treat (possibly) multiple physical monitors as if they
3937 formed a single monitor as a whole. This should provide a
3938 consistent result at least on single monitor environments. */
3939 monitor
.geom
.x
= monitor
.geom
.y
= 0;
3940 monitor
.geom
.width
= x_display_pixel_width (dpyinfo
);
3941 monitor
.geom
.height
= x_display_pixel_height (dpyinfo
);
3942 monitor
.mm_width
= WidthMMOfScreen (dpyinfo
->screen
);
3943 monitor
.mm_height
= HeightMMOfScreen (dpyinfo
->screen
);
3944 monitor
.name
= xstrdup ("combined screen");
3946 if (x_get_net_workarea (dpyinfo
, &workarea_r
))
3947 monitor
.work
= workarea_r
;
3949 monitor
.work
= monitor
.geom
;
3950 return x_make_monitor_attribute_list (&monitor
, 1, 0, dpyinfo
, "fallback");
3954 #ifdef HAVE_XINERAMA
3956 x_get_monitor_attributes_xinerama (struct x_display_info
*dpyinfo
)
3959 Lisp_Object attributes_list
= Qnil
;
3960 Display
*dpy
= dpyinfo
->display
;
3961 XineramaScreenInfo
*info
= XineramaQueryScreens (dpy
, &n_monitors
);
3962 struct MonitorInfo
*monitors
;
3963 double mm_width_per_pixel
, mm_height_per_pixel
;
3965 if (! info
|| n_monitors
== 0)
3969 return attributes_list
;
3972 mm_width_per_pixel
= ((double) WidthMMOfScreen (dpyinfo
->screen
)
3973 / x_display_pixel_width (dpyinfo
));
3974 mm_height_per_pixel
= ((double) HeightMMOfScreen (dpyinfo
->screen
)
3975 / x_display_pixel_height (dpyinfo
));
3976 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
3977 for (i
= 0; i
< n_monitors
; ++i
)
3979 struct MonitorInfo
*mi
= &monitors
[i
];
3980 XRectangle workarea_r
;
3982 mi
->geom
.x
= info
[i
].x_org
;
3983 mi
->geom
.y
= info
[i
].y_org
;
3984 mi
->geom
.width
= info
[i
].width
;
3985 mi
->geom
.height
= info
[i
].height
;
3986 mi
->mm_width
= mi
->geom
.width
* mm_width_per_pixel
+ 0.5;
3987 mi
->mm_height
= mi
->geom
.height
* mm_height_per_pixel
+ 0.5;
3990 /* Xinerama usually have primary monitor first, just use that. */
3991 if (i
== 0 && x_get_net_workarea (dpyinfo
, &workarea_r
))
3993 mi
->work
= workarea_r
;
3994 if (! x_intersect_rectangles (&mi
->geom
, &mi
->work
, &mi
->work
))
3995 mi
->work
= mi
->geom
;
3998 mi
->work
= mi
->geom
;
4002 attributes_list
= x_make_monitor_attribute_list (monitors
,
4007 free_monitors (monitors
, n_monitors
);
4008 return attributes_list
;
4010 #endif /* HAVE_XINERAMA */
4015 x_get_monitor_attributes_xrandr (struct x_display_info
*dpyinfo
)
4017 Lisp_Object attributes_list
= Qnil
;
4018 XRRScreenResources
*resources
;
4019 Display
*dpy
= dpyinfo
->display
;
4020 int i
, n_monitors
, primary
= -1;
4021 RROutput pxid
= None
;
4022 struct MonitorInfo
*monitors
;
4024 #ifdef HAVE_XRRGETSCREENRESOURCESCURRENT
4025 resources
= XRRGetScreenResourcesCurrent (dpy
, dpyinfo
->root_window
);
4027 resources
= XRRGetScreenResources (dpy
, dpyinfo
->root_window
);
4029 if (! resources
|| resources
->noutput
== 0)
4032 XRRFreeScreenResources (resources
);
4035 n_monitors
= resources
->noutput
;
4036 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
4038 #ifdef HAVE_XRRGETOUTPUTPRIMARY
4039 pxid
= XRRGetOutputPrimary (dpy
, dpyinfo
->root_window
);
4042 for (i
= 0; i
< n_monitors
; ++i
)
4044 XRROutputInfo
*info
= XRRGetOutputInfo (dpy
, resources
,
4045 resources
->outputs
[i
]);
4046 Connection conn
= info
? info
->connection
: RR_Disconnected
;
4047 RRCrtc id
= info
? info
->crtc
: None
;
4049 if (strcmp (info
->name
, "default") == 0)
4051 /* Non XRandr 1.2 driver, does not give useful data. */
4052 XRRFreeOutputInfo (info
);
4053 XRRFreeScreenResources (resources
);
4054 free_monitors (monitors
, n_monitors
);
4058 if (conn
!= RR_Disconnected
&& id
!= None
)
4060 XRRCrtcInfo
*crtc
= XRRGetCrtcInfo (dpy
, resources
, id
);
4061 struct MonitorInfo
*mi
= &monitors
[i
];
4062 XRectangle workarea_r
;
4066 XRRFreeOutputInfo (info
);
4070 mi
->geom
.x
= crtc
->x
;
4071 mi
->geom
.y
= crtc
->y
;
4072 mi
->geom
.width
= crtc
->width
;
4073 mi
->geom
.height
= crtc
->height
;
4074 mi
->mm_width
= info
->mm_width
;
4075 mi
->mm_height
= info
->mm_height
;
4076 mi
->name
= xstrdup (info
->name
);
4078 if (pxid
!= None
&& pxid
== resources
->outputs
[i
])
4080 else if (primary
== -1 && strcmp (info
->name
, "LVDS") == 0)
4083 if (i
== primary
&& x_get_net_workarea (dpyinfo
, &workarea_r
))
4085 mi
->work
= workarea_r
;
4086 if (! x_intersect_rectangles (&mi
->geom
, &mi
->work
, &mi
->work
))
4087 mi
->work
= mi
->geom
;
4090 mi
->work
= mi
->geom
;
4092 XRRFreeCrtcInfo (crtc
);
4094 XRRFreeOutputInfo (info
);
4096 XRRFreeScreenResources (resources
);
4098 attributes_list
= x_make_monitor_attribute_list (monitors
,
4103 free_monitors (monitors
, n_monitors
);
4104 return attributes_list
;
4106 #endif /* HAVE_XRANDR */
4109 x_get_monitor_attributes (struct x_display_info
*dpyinfo
)
4111 Lisp_Object attributes_list
= Qnil
;
4112 Display
*dpy
= dpyinfo
->display
;
4114 (void) dpy
; /* Suppress unused variable warning. */
4117 int xrr_event_base
, xrr_error_base
;
4118 bool xrr_ok
= false;
4119 xrr_ok
= XRRQueryExtension (dpy
, &xrr_event_base
, &xrr_error_base
);
4122 int xrr_major
, xrr_minor
;
4123 XRRQueryVersion (dpy
, &xrr_major
, &xrr_minor
);
4124 xrr_ok
= (xrr_major
== 1 && xrr_minor
>= 2) || xrr_major
> 1;
4128 attributes_list
= x_get_monitor_attributes_xrandr (dpyinfo
);
4129 #endif /* HAVE_XRANDR */
4131 #ifdef HAVE_XINERAMA
4132 if (NILP (attributes_list
))
4134 int xin_event_base
, xin_error_base
;
4135 bool xin_ok
= false;
4136 xin_ok
= XineramaQueryExtension (dpy
, &xin_event_base
, &xin_error_base
);
4137 if (xin_ok
&& XineramaIsActive (dpy
))
4138 attributes_list
= x_get_monitor_attributes_xinerama (dpyinfo
);
4140 #endif /* HAVE_XINERAMA */
4142 if (NILP (attributes_list
))
4143 attributes_list
= x_get_monitor_attributes_fallback (dpyinfo
);
4145 return attributes_list
;
4148 #endif /* !USE_GTK */
4150 DEFUN ("x-display-monitor-attributes-list", Fx_display_monitor_attributes_list
,
4151 Sx_display_monitor_attributes_list
,
4153 doc
: /* Return a list of physical monitor attributes on the X display TERMINAL.
4155 The optional argument TERMINAL specifies which display to ask about.
4156 TERMINAL should be a terminal object, a frame or a display name (a string).
4157 If omitted or nil, that stands for the selected frame's display.
4159 In addition to the standard attribute keys listed in
4160 `display-monitor-attributes-list', the following keys are contained in
4163 source -- String describing the source from which multi-monitor
4164 information is obtained, one of \"Gdk\", \"XRandr\",
4165 \"Xinerama\", or \"fallback\"
4167 Internal use only, use `display-monitor-attributes-list' instead. */)
4168 (Lisp_Object terminal
)
4170 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4171 Lisp_Object attributes_list
= Qnil
;
4174 double mm_width_per_pixel
, mm_height_per_pixel
;
4177 gint primary_monitor
= 0, n_monitors
, i
;
4178 Lisp_Object monitor_frames
, rest
, frame
;
4179 static const char *source
= "Gdk";
4180 struct MonitorInfo
*monitors
;
4183 mm_width_per_pixel
= ((double) WidthMMOfScreen (dpyinfo
->screen
)
4184 / x_display_pixel_width (dpyinfo
));
4185 mm_height_per_pixel
= ((double) HeightMMOfScreen (dpyinfo
->screen
)
4186 / x_display_pixel_height (dpyinfo
));
4187 gdpy
= gdk_x11_lookup_xdisplay (dpyinfo
->display
);
4188 gscreen
= gdk_display_get_default_screen (gdpy
);
4189 #if GTK_CHECK_VERSION (2, 20, 0)
4190 primary_monitor
= gdk_screen_get_primary_monitor (gscreen
);
4192 n_monitors
= gdk_screen_get_n_monitors (gscreen
);
4193 monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
4194 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
4196 FOR_EACH_FRAME (rest
, frame
)
4198 struct frame
*f
= XFRAME (frame
);
4200 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
4201 && !EQ (frame
, tip_frame
))
4203 GdkWindow
*gwin
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
4205 i
= gdk_screen_get_monitor_at_window (gscreen
, gwin
);
4206 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
4210 for (i
= 0; i
< n_monitors
; ++i
)
4212 gint width_mm
= -1, height_mm
= -1;
4213 GdkRectangle rec
, work
;
4214 struct MonitorInfo
*mi
= &monitors
[i
];
4216 gdk_screen_get_monitor_geometry (gscreen
, i
, &rec
);
4218 #if GTK_CHECK_VERSION (2, 14, 0)
4219 width_mm
= gdk_screen_get_monitor_width_mm (gscreen
, i
);
4220 height_mm
= gdk_screen_get_monitor_height_mm (gscreen
, i
);
4223 width_mm
= rec
.width
* mm_width_per_pixel
+ 0.5;
4225 height_mm
= rec
.height
* mm_height_per_pixel
+ 0.5;
4227 #if GTK_CHECK_VERSION (3, 4, 0)
4228 gdk_screen_get_monitor_workarea (gscreen
, i
, &work
);
4230 /* Emulate the behavior of GTK+ 3.4. */
4232 XRectangle workarea_r
;
4234 if (i
== primary_monitor
&& x_get_net_workarea (dpyinfo
, &workarea_r
))
4236 work
.x
= workarea_r
.x
;
4237 work
.y
= workarea_r
.y
;
4238 work
.width
= workarea_r
.width
;
4239 work
.height
= workarea_r
.height
;
4240 if (! gdk_rectangle_intersect (&rec
, &work
, &work
))
4251 mi
->geom
.width
= rec
.width
;
4252 mi
->geom
.height
= rec
.height
;
4253 mi
->work
.x
= work
.x
;
4254 mi
->work
.y
= work
.y
;
4255 mi
->work
.width
= work
.width
;
4256 mi
->work
.height
= work
.height
;
4257 mi
->mm_width
= width_mm
;
4258 mi
->mm_height
= height_mm
;
4260 #if GTK_CHECK_VERSION (2, 14, 0)
4261 mi
->name
= gdk_screen_get_monitor_plug_name (gscreen
, i
);
4265 attributes_list
= make_monitor_attribute_list (monitors
,
4271 #else /* not USE_GTK */
4274 attributes_list
= x_get_monitor_attributes (dpyinfo
);
4277 #endif /* not USE_GTK */
4279 return attributes_list
;
4282 DEFUN ("x-frame-geometry", Fx_frame_geometry
, Sx_frame_geometry
, 0, 1, 0,
4283 doc
: /* Return geometric attributes of frame FRAME.
4285 FRAME must be a live frame and defaults to the selected one.
4287 The return value is an association list containing the following
4288 elements (all size values are in pixels).
4290 - `frame-outer-size' is a cons of the outer width and height of FRAME.
4291 The outer size include the title bar and the external borders as well
4292 as any menu and/or tool bar of frame.
4294 - `border' is a cons of the horizontal and vertical width of FRAME's
4297 - `title-bar-height' is the height of the title bar of FRAME.
4299 - `menu-bar-external' if `t' means the menu bar is external (not
4300 included in the inner edges of FRAME).
4302 - `menu-bar-size' is a cons of the width and height of the menu bar of
4305 - `tool-bar-external' if `t' means the tool bar is external (not
4306 included in the inner edges of FRAME).
4308 - `tool-bar-side' tells tells on which side the tool bar on FRAME is and
4309 can be one of `left', `top', `right' or `bottom'.
4311 - `tool-bar-size' is a cons of the width and height of the tool bar of
4314 - `frame-inner-size' is a cons of the inner width and height of FRAME.
4315 This excludes FRAME's title bar and external border as well as any
4316 external menu and/or tool bar. */)
4319 struct frame
*f
= decode_live_frame (frame
);
4320 int inner_width
= FRAME_PIXEL_WIDTH (f
);
4321 int inner_height
= FRAME_PIXEL_HEIGHT (f
);
4322 int outer_width
, outer_height
, border
, title
;
4323 Lisp_Object fullscreen
= Fframe_parameter (frame
, Qfullscreen
);
4324 int menu_bar_height
, menu_bar_width
, tool_bar_height
, tool_bar_width
;
4326 int left_off
, right_off
, top_off
, bottom_off
;
4327 XWindowAttributes atts
;
4331 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &atts
);
4333 x_real_pos_and_offsets (f
, &left_off
, &right_off
, &top_off
, &bottom_off
,
4334 NULL
, NULL
, NULL
, NULL
);
4338 border
= atts
.border_width
;
4341 outer_width
= FRAME_PIXEL_WIDTH (f
) + 2 * border
+ right_off
+ left_off
;
4342 outer_height
= FRAME_PIXEL_HEIGHT (f
) + 2 * border
+ top_off
+ bottom_off
;
4344 #if defined (USE_GTK)
4346 bool tool_bar_left_right
= (EQ (FRAME_TOOL_BAR_POSITION (f
), Qleft
)
4347 || EQ (FRAME_TOOL_BAR_POSITION (f
), Qright
));
4349 tool_bar_width
= (tool_bar_left_right
4350 ? FRAME_TOOLBAR_WIDTH (f
)
4351 : FRAME_PIXEL_WIDTH (f
));
4352 tool_bar_height
= (tool_bar_left_right
4353 ? FRAME_PIXEL_HEIGHT (f
)
4354 : FRAME_TOOLBAR_HEIGHT (f
));
4357 tool_bar_height
= FRAME_TOOL_BAR_HEIGHT (f
);
4358 tool_bar_width
= tool_bar_height
> 0 ? FRAME_PIXEL_WIDTH (f
) : 0;
4361 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
4362 menu_bar_height
= FRAME_MENUBAR_HEIGHT (f
);
4364 menu_bar_height
= FRAME_MENU_BAR_HEIGHT (f
);
4367 menu_bar_width
= menu_bar_height
> 0 ? FRAME_PIXEL_WIDTH (f
) : 0;
4369 if (!FRAME_EXTERNAL_MENU_BAR (f
))
4370 inner_height
-= menu_bar_height
;
4371 if (!FRAME_EXTERNAL_TOOL_BAR (f
))
4372 inner_height
-= tool_bar_height
;
4375 listn (CONSTYPE_HEAP
, 10,
4376 Fcons (Qframe_position
,
4377 Fcons (make_number (f
->left_pos
), make_number (f
->top_pos
))),
4378 Fcons (Qframe_outer_size
,
4379 Fcons (make_number (outer_width
), make_number (outer_height
))),
4380 Fcons (Qexternal_border_size
,
4381 ((EQ (fullscreen
, Qfullboth
) || EQ (fullscreen
, Qfullscreen
))
4382 ? Fcons (make_number (0), make_number (0))
4383 : Fcons (make_number (border
), make_number (border
)))),
4384 Fcons (Qtitle_height
,
4385 ((EQ (fullscreen
, Qfullboth
) || EQ (fullscreen
, Qfullscreen
))
4387 : make_number (title
))),
4388 Fcons (Qmenu_bar_external
, FRAME_EXTERNAL_MENU_BAR (f
) ? Qt
: Qnil
),
4389 Fcons (Qmenu_bar_size
,
4390 Fcons (make_number (menu_bar_width
),
4391 make_number (menu_bar_height
))),
4392 Fcons (Qtool_bar_external
, FRAME_EXTERNAL_TOOL_BAR (f
) ? Qt
: Qnil
),
4393 Fcons (Qtool_bar_position
, FRAME_TOOL_BAR_POSITION (f
)),
4394 Fcons (Qtool_bar_size
,
4395 Fcons (make_number (tool_bar_width
),
4396 make_number (tool_bar_height
))),
4397 Fcons (Qframe_inner_size
,
4398 Fcons (make_number (inner_width
),
4399 make_number (inner_height
))));
4402 /************************************************************************
4404 ************************************************************************/
4407 /* Mapping visual names to visuals. */
4409 static struct visual_class
4416 {"StaticGray", StaticGray
},
4417 {"GrayScale", GrayScale
},
4418 {"StaticColor", StaticColor
},
4419 {"PseudoColor", PseudoColor
},
4420 {"TrueColor", TrueColor
},
4421 {"DirectColor", DirectColor
},
4426 #ifndef HAVE_XSCREENNUMBEROFSCREEN
4428 /* Value is the screen number of screen SCR. This is a substitute for
4429 the X function with the same name when that doesn't exist. */
4432 XScreenNumberOfScreen (scr
)
4433 register Screen
*scr
;
4435 Display
*dpy
= scr
->display
;
4438 for (i
= 0; i
< dpy
->nscreens
; ++i
)
4439 if (scr
== dpy
->screens
+ i
)
4445 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
4448 /* Select the visual that should be used on display DPYINFO. Set
4449 members of DPYINFO appropriately. Called from x_term_init. */
4452 select_visual (struct x_display_info
*dpyinfo
)
4454 Display
*dpy
= dpyinfo
->display
;
4455 Screen
*screen
= dpyinfo
->screen
;
4457 /* See if a visual is specified. */
4458 AUTO_STRING (visualClass
, "visualClass");
4459 AUTO_STRING (VisualClass
, "VisualClass");
4460 Lisp_Object value
= display_x_get_resource (dpyinfo
, visualClass
,
4461 VisualClass
, Qnil
, Qnil
);
4463 if (STRINGP (value
))
4465 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
4466 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
4467 depth, a decimal number. NAME is compared with case ignored. */
4468 char *s
= alloca (SBYTES (value
) + 1);
4473 lispstpcpy (s
, value
);
4474 dash
= strchr (s
, '-');
4477 dpyinfo
->n_planes
= atoi (dash
+ 1);
4481 /* We won't find a matching visual with depth 0, so that
4482 an error will be printed below. */
4483 dpyinfo
->n_planes
= 0;
4485 /* Determine the visual class. */
4486 for (i
= 0; visual_classes
[i
].name
; ++i
)
4487 if (xstrcasecmp (s
, visual_classes
[i
].name
) == 0)
4489 class = visual_classes
[i
].class;
4493 /* Look up a matching visual for the specified class. */
4495 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
4496 dpyinfo
->n_planes
, class, &vinfo
))
4497 fatal ("Invalid visual specification `%s'", SDATA (value
));
4499 dpyinfo
->visual
= vinfo
.visual
;
4504 XVisualInfo
*vinfo
, vinfo_template
;
4506 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
4508 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
4509 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
4510 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
4511 &vinfo_template
, &n_visuals
);
4513 fatal ("Can't get proper X visual info");
4515 dpyinfo
->n_planes
= vinfo
->depth
;
4521 /* Return the X display structure for the display named NAME.
4522 Open a new connection if necessary. */
4524 static struct x_display_info
*
4525 x_display_info_for_name (Lisp_Object name
)
4527 struct x_display_info
*dpyinfo
;
4529 CHECK_STRING (name
);
4531 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
4532 if (!NILP (Fstring_equal (XCAR (dpyinfo
->name_list_element
), name
)))
4535 /* Use this general default value to start with. */
4536 Vx_resource_name
= Vinvocation_name
;
4538 validate_x_resource_name ();
4540 dpyinfo
= x_term_init (name
, 0, SSDATA (Vx_resource_name
));
4543 error ("Cannot connect to X server %s", SDATA (name
));
4545 XSETFASTINT (Vwindow_system_version
, 11);
4551 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4553 doc
: /* Open a connection to a display server.
4554 DISPLAY is the name of the display to connect to.
4555 Optional second arg XRM-STRING is a string of resources in xrdb format.
4556 If the optional third arg MUST-SUCCEED is non-nil,
4557 terminate Emacs if we can't open the connection.
4558 \(In the Nextstep version, the last two arguments are currently ignored.) */)
4559 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
4562 struct x_display_info
*dpyinfo
;
4564 CHECK_STRING (display
);
4565 if (! NILP (xrm_string
))
4566 CHECK_STRING (xrm_string
);
4568 xrm_option
= NILP (xrm_string
) ? 0 : SSDATA (xrm_string
);
4570 validate_x_resource_name ();
4572 /* This is what opens the connection and sets x_current_display.
4573 This also initializes many symbols, such as those used for input. */
4574 dpyinfo
= x_term_init (display
, xrm_option
,
4575 SSDATA (Vx_resource_name
));
4579 if (!NILP (must_succeed
))
4580 fatal ("Cannot connect to X server %s.\n\
4581 Check the DISPLAY environment variable or use `-d'.\n\
4582 Also use the `xauth' program to verify that you have the proper\n\
4583 authorization information needed to connect the X server.\n\
4584 An insecure way to solve the problem may be to use `xhost'.\n",
4587 error ("Cannot connect to X server %s", SDATA (display
));
4590 XSETFASTINT (Vwindow_system_version
, 11);
4594 DEFUN ("x-close-connection", Fx_close_connection
,
4595 Sx_close_connection
, 1, 1, 0,
4596 doc
: /* Close the connection to TERMINAL's X server.
4597 For TERMINAL, specify a terminal object, a frame or a display name (a
4598 string). If TERMINAL is nil, that stands for the selected frame's
4600 (Lisp_Object terminal
)
4602 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4604 if (dpyinfo
->reference_count
> 0)
4605 error ("Display still has frames on it");
4607 x_delete_terminal (dpyinfo
->terminal
);
4612 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4613 doc
: /* Return the list of display names that Emacs has connections to. */)
4616 Lisp_Object result
= Qnil
;
4617 struct x_display_info
*xdi
;
4619 for (xdi
= x_display_list
; xdi
; xdi
= xdi
->next
)
4620 result
= Fcons (XCAR (xdi
->name_list_element
), result
);
4625 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4626 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
4627 This function only has an effect on X Windows. With MS Windows, it is
4628 defined but does nothing.
4630 If ON is nil, allow buffering of requests.
4631 Turning on synchronization prohibits the Xlib routines from buffering
4632 requests and seriously degrades performance, but makes debugging much
4634 The optional second argument TERMINAL specifies which display to act on.
4635 TERMINAL should be a terminal object, a frame or a display name (a string).
4636 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
4637 (Lisp_Object on
, Lisp_Object terminal
)
4639 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4641 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
4646 /* Wait for responses to all X commands issued so far for frame F. */
4649 x_sync (struct frame
*f
)
4652 XSync (FRAME_X_DISPLAY (f
), False
);
4657 /***********************************************************************
4659 ***********************************************************************/
4661 DEFUN ("x-change-window-property", Fx_change_window_property
,
4662 Sx_change_window_property
, 2, 6, 0,
4663 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
4664 PROP must be a string. VALUE may be a string or a list of conses,
4665 numbers and/or strings. If an element in the list is a string, it is
4666 converted to an atom and the value of the atom is used. If an element
4667 is a cons, it is converted to a 32 bit number where the car is the 16
4668 top bits and the cdr is the lower 16 bits.
4670 FRAME nil or omitted means use the selected frame.
4671 If TYPE is given and non-nil, it is the name of the type of VALUE.
4672 If TYPE is not given or nil, the type is STRING.
4673 FORMAT gives the size in bits of each element if VALUE is a list.
4674 It must be one of 8, 16 or 32.
4675 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4676 If OUTER-P is non-nil, the property is changed for the outer X window of
4677 FRAME. Default is to change on the edit X window. */)
4678 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
,
4679 Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
4681 struct frame
*f
= decode_window_system_frame (frame
);
4683 Atom target_type
= XA_STRING
;
4684 int element_format
= 8;
4685 unsigned char *data
;
4689 CHECK_STRING (prop
);
4691 if (! NILP (format
))
4693 CHECK_NUMBER (format
);
4695 if (XINT (format
) != 8 && XINT (format
) != 16
4696 && XINT (format
) != 32)
4697 error ("FORMAT must be one of 8, 16 or 32");
4698 element_format
= XINT (format
);
4705 nelements
= x_check_property_data (value
);
4706 if (nelements
== -1)
4707 error ("Bad data in VALUE, must be number, string or cons");
4709 /* The man page for XChangeProperty:
4710 "If the specified format is 32, the property data must be a
4712 This applies even if long is more than 32 bits. The X library
4713 converts to 32 bits before sending to the X server. */
4714 elsize
= element_format
== 32 ? sizeof (long) : element_format
>> 3;
4715 data
= xnmalloc (nelements
, elsize
);
4717 x_fill_property_data (FRAME_X_DISPLAY (f
), value
, data
, element_format
);
4721 CHECK_STRING (value
);
4722 data
= SDATA (value
);
4723 if (INT_MAX
< SBYTES (value
))
4724 error ("VALUE too long");
4725 nelements
= SBYTES (value
);
4729 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4732 CHECK_STRING (type
);
4733 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
4736 if (! NILP (outer_p
)) w
= FRAME_OUTER_WINDOW (f
);
4737 else w
= FRAME_X_WINDOW (f
);
4739 XChangeProperty (FRAME_X_DISPLAY (f
), w
,
4740 prop_atom
, target_type
, element_format
, PropModeReplace
,
4743 if (CONSP (value
)) xfree (data
);
4745 /* Make sure the property is set when we return. */
4746 XFlush (FRAME_X_DISPLAY (f
));
4753 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
4754 Sx_delete_window_property
, 1, 2, 0,
4755 doc
: /* Remove window property PROP from X window of FRAME.
4756 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4757 (Lisp_Object prop
, Lisp_Object frame
)
4759 struct frame
*f
= decode_window_system_frame (frame
);
4762 CHECK_STRING (prop
);
4764 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4765 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
4767 /* Make sure the property is removed when we return. */
4768 XFlush (FRAME_X_DISPLAY (f
));
4776 x_window_property_intern (struct frame
*f
,
4777 Window target_window
,
4780 Lisp_Object delete_p
,
4781 Lisp_Object vector_ret_p
,
4784 unsigned char *tmp_data
= NULL
;
4785 Lisp_Object prop_value
= Qnil
;
4788 unsigned long actual_size
, bytes_remaining
;
4790 struct gcpro gcpro1
;
4792 GCPRO1 (prop_value
);
4794 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4795 prop_atom
, 0, 0, False
, target_type
,
4796 &actual_type
, &actual_format
, &actual_size
,
4797 &bytes_remaining
, &tmp_data
);
4799 *found
= actual_format
!= 0;
4801 if (rc
== Success
&& *found
)
4806 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4807 prop_atom
, 0, bytes_remaining
,
4808 ! NILP (delete_p
), target_type
,
4809 &actual_type
, &actual_format
,
4810 &actual_size
, &bytes_remaining
,
4812 if (rc
== Success
&& tmp_data
)
4814 /* The man page for XGetWindowProperty says:
4815 "If the returned format is 32, the returned data is represented
4816 as a long array and should be cast to that type to obtain the
4818 This applies even if long is more than 32 bits, the X library
4819 converts from 32 bit elements received from the X server to long
4820 and passes the long array to us. Thus, for that case memcpy can not
4821 be used. We convert to a 32 bit type here, because so much code
4824 The bytes and offsets passed to XGetWindowProperty refers to the
4825 property and those are indeed in 32 bit quantities if format is
4828 if (BITS_PER_LONG
> 32 && actual_format
== 32)
4831 int *idata
= (int *) tmp_data
;
4832 long *ldata
= (long *) tmp_data
;
4834 for (i
= 0; i
< actual_size
; ++i
)
4835 idata
[i
] = (int) ldata
[i
];
4838 if (NILP (vector_ret_p
))
4839 prop_value
= make_string ((char *) tmp_data
, actual_size
);
4841 prop_value
= x_property_data_to_lisp (f
,
4848 if (tmp_data
) XFree (tmp_data
);
4855 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
4857 doc
: /* Value is the value of window property PROP on FRAME.
4858 If FRAME is nil or omitted, use the selected frame.
4860 On X Windows, the following optional arguments are also accepted:
4861 If TYPE is nil or omitted, get the property as a string.
4862 Otherwise TYPE is the name of the atom that denotes the type expected.
4863 If SOURCE is non-nil, get the property on that window instead of from
4864 FRAME. The number 0 denotes the root window.
4865 If DELETE-P is non-nil, delete the property after retrieving it.
4866 If VECTOR-RET-P is non-nil, don't return a string but a vector of values.
4868 On MS Windows, this function accepts but ignores those optional arguments.
4870 Value is nil if FRAME hasn't a property with name PROP or if PROP has
4871 no value of TYPE (always string in the MS Windows case). */)
4872 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
,
4873 Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
4875 struct frame
*f
= decode_window_system_frame (frame
);
4877 Lisp_Object prop_value
= Qnil
;
4878 Atom target_type
= XA_STRING
;
4879 Window target_window
= FRAME_X_WINDOW (f
);
4880 struct gcpro gcpro1
;
4883 GCPRO1 (prop_value
);
4884 CHECK_STRING (prop
);
4886 if (! NILP (source
))
4888 CONS_TO_INTEGER (source
, Window
, target_window
);
4889 if (! target_window
)
4890 target_window
= FRAME_DISPLAY_INFO (f
)->root_window
;
4896 if (strcmp ("AnyPropertyType", SSDATA (type
)) == 0)
4897 target_type
= AnyPropertyType
;
4899 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
4902 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4903 prop_value
= x_window_property_intern (f
,
4910 if (NILP (prop_value
)
4913 && target_window
!= FRAME_OUTER_WINDOW (f
))
4915 prop_value
= x_window_property_intern (f
,
4916 FRAME_OUTER_WINDOW (f
),
4930 /***********************************************************************
4932 ***********************************************************************/
4934 static Lisp_Object
x_create_tip_frame (struct x_display_info
*,
4935 Lisp_Object
, Lisp_Object
);
4936 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
4937 Lisp_Object
, int, int, int *, int *);
4939 /* The frame of a currently visible tooltip. */
4941 Lisp_Object tip_frame
;
4943 /* If non-nil, a timer started that hides the last tooltip when it
4946 static Lisp_Object tip_timer
;
4949 /* If non-nil, a vector of 3 elements containing the last args
4950 with which x-show-tip was called. See there. */
4952 static Lisp_Object last_show_tip_args
;
4956 unwind_create_tip_frame (Lisp_Object frame
)
4958 Lisp_Object deleted
;
4960 deleted
= unwind_create_frame (frame
);
4961 if (EQ (deleted
, Qt
))
4969 /* Create a frame for a tooltip on the display described by DPYINFO.
4970 PARMS is a list of frame parameters. TEXT is the string to
4971 display in the tip frame. Value is the frame.
4973 Note that functions called here, esp. x_default_parameter can
4974 signal errors, for instance when a specified color name is
4975 undefined. We have to make sure that we're in a consistent state
4976 when this happens. */
4979 x_create_tip_frame (struct x_display_info
*dpyinfo
,
4987 ptrdiff_t count
= SPECPDL_INDEX ();
4988 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4989 bool face_change_before
= face_change
;
4991 struct buffer
*old_buffer
;
4993 if (!dpyinfo
->terminal
->name
)
4994 error ("Terminal is not live, can't create new frames on it");
4996 parms
= Fcopy_alist (parms
);
4998 /* Get the name of the frame to use for resource lookup. */
4999 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5001 && !EQ (name
, Qunbound
)
5003 error ("Invalid frame name--not a string or nil");
5006 GCPRO3 (parms
, name
, frame
);
5007 f
= make_frame (true);
5008 XSETFRAME (frame
, f
);
5010 AUTO_STRING (tip
, " *tip*");
5011 buffer
= Fget_buffer_create (tip
);
5012 /* Use set_window_buffer instead of Fset_window_buffer (see
5013 discussion of bug#11984, bug#12025, bug#12026). */
5014 set_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, false, false);
5015 old_buffer
= current_buffer
;
5016 set_buffer_internal_1 (XBUFFER (buffer
));
5017 bset_truncate_lines (current_buffer
, Qnil
);
5018 specbind (Qinhibit_read_only
, Qt
);
5019 specbind (Qinhibit_modification_hooks
, Qt
);
5022 set_buffer_internal_1 (old_buffer
);
5024 record_unwind_protect (unwind_create_tip_frame
, frame
);
5026 f
->terminal
= dpyinfo
->terminal
;
5028 /* By setting the output method, we're essentially saying that
5029 the frame is live, as per FRAME_LIVE_P. If we get a signal
5030 from this point on, x_destroy_window might screw up reference
5032 f
->output_method
= output_x_window
;
5033 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
5034 f
->output_data
.x
->icon_bitmap
= -1;
5035 FRAME_FONTSET (f
) = -1;
5036 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
5037 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
5038 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
5039 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
5040 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
5041 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
5042 f
->output_data
.x
->white_relief
.pixel
= -1;
5043 f
->output_data
.x
->black_relief
.pixel
= -1;
5045 fset_icon_name (f
, Qnil
);
5046 FRAME_DISPLAY_INFO (f
) = dpyinfo
;
5047 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5048 f
->output_data
.x
->explicit_parent
= false;
5050 /* These colors will be set anyway later, but it's important
5051 to get the color reference counts right, so initialize them! */
5054 struct gcpro gcpro1
;
5056 /* Function x_decode_color can signal an error. Make
5057 sure to initialize color slots so that we won't try
5058 to free colors we haven't allocated. */
5059 FRAME_FOREGROUND_PIXEL (f
) = -1;
5060 FRAME_BACKGROUND_PIXEL (f
) = -1;
5061 f
->output_data
.x
->cursor_pixel
= -1;
5062 f
->output_data
.x
->cursor_foreground_pixel
= -1;
5063 f
->output_data
.x
->border_pixel
= -1;
5064 f
->output_data
.x
->mouse_pixel
= -1;
5066 black
= build_string ("black");
5068 FRAME_FOREGROUND_PIXEL (f
)
5069 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5070 FRAME_BACKGROUND_PIXEL (f
)
5071 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5072 f
->output_data
.x
->cursor_pixel
5073 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5074 f
->output_data
.x
->cursor_foreground_pixel
5075 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5076 f
->output_data
.x
->border_pixel
5077 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5078 f
->output_data
.x
->mouse_pixel
5079 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5083 /* Set the name; the functions to which we pass f expect the name to
5085 if (EQ (name
, Qunbound
) || NILP (name
))
5087 fset_name (f
, build_string (dpyinfo
->x_id_name
));
5088 f
->explicit_name
= false;
5092 fset_name (f
, name
);
5093 f
->explicit_name
= true;
5094 /* use the frame's title when getting resources for this frame. */
5095 specbind (Qx_resource_name
, name
);
5098 register_font_driver (&xfont_driver
, f
);
5099 #ifdef HAVE_FREETYPE
5101 register_font_driver (&xftfont_driver
, f
);
5102 #else /* not HAVE_XFT */
5103 register_font_driver (&ftxfont_driver
, f
);
5104 #endif /* not HAVE_XFT */
5105 #endif /* HAVE_FREETYPE */
5107 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5108 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5110 /* Extract the window parameters from the supplied values that are
5111 needed to determine window geometry. */
5112 x_default_font_parameter (f
, parms
);
5114 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
5115 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5117 /* This defaults to 2 in order to match xterm. We recognize either
5118 internalBorderWidth or internalBorder (which is what xterm calls
5120 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5124 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5125 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5126 if (! EQ (value
, Qunbound
))
5127 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5131 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5132 "internalBorderWidth", "internalBorderWidth",
5134 x_default_parameter (f
, parms
, Qright_divider_width
, make_number (0),
5135 NULL
, NULL
, RES_TYPE_NUMBER
);
5136 x_default_parameter (f
, parms
, Qbottom_divider_width
, make_number (0),
5137 NULL
, NULL
, RES_TYPE_NUMBER
);
5139 /* Also do the stuff which must be set before the window exists. */
5140 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5141 "foreground", "Foreground", RES_TYPE_STRING
);
5142 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5143 "background", "Background", RES_TYPE_STRING
);
5144 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5145 "pointerColor", "Foreground", RES_TYPE_STRING
);
5146 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5147 "cursorColor", "Foreground", RES_TYPE_STRING
);
5148 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5149 "borderColor", "BorderColor", RES_TYPE_STRING
);
5152 image_cache_refcount
=
5153 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
5154 dpyinfo_refcount
= dpyinfo
->reference_count
;
5155 #endif /* GLYPH_DEBUG */
5157 /* Init faces before x_default_parameter is called for the
5158 scroll-bar-width parameter because otherwise we end up in
5159 init_iterator with a null face cache, which should not happen. */
5160 init_frame_faces (f
);
5162 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5164 x_figure_window_size (f
, parms
, false);
5167 XSetWindowAttributes attrs
;
5169 Atom type
= FRAME_DISPLAY_INFO (f
)->Xatom_net_window_type_tooltip
;
5172 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
;
5173 if (DoesSaveUnders (dpyinfo
->screen
))
5174 mask
|= CWSaveUnder
;
5176 /* Window managers look at the override-redirect flag to determine
5177 whether or net to give windows a decoration (Xlib spec, chapter
5179 attrs
.override_redirect
= True
;
5180 attrs
.save_under
= True
;
5181 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
5182 /* Arrange for getting MapNotify and UnmapNotify events. */
5183 attrs
.event_mask
= StructureNotifyMask
;
5185 = FRAME_X_WINDOW (f
)
5186 = XCreateWindow (FRAME_X_DISPLAY (f
),
5187 FRAME_DISPLAY_INFO (f
)->root_window
,
5188 /* x, y, width, height */
5192 CopyFromParent
, InputOutput
, CopyFromParent
,
5194 XChangeProperty (FRAME_X_DISPLAY (f
), tip_window
,
5195 FRAME_DISPLAY_INFO (f
)->Xatom_net_window_type
,
5196 XA_ATOM
, 32, PropModeReplace
,
5197 (unsigned char *)&type
, 1);
5203 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5204 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5205 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5206 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5207 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5208 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5210 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
5211 Change will not be effected unless different from the current
5213 width
= FRAME_COLS (f
);
5214 height
= FRAME_LINES (f
);
5215 SET_FRAME_COLS (f
, 0);
5216 SET_FRAME_LINES (f
, 0);
5217 change_frame_size (f
, width
, height
, true, false, false, false);
5219 /* Add `tooltip' frame parameter's default value. */
5220 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5222 AUTO_FRAME_ARG (arg
, Qtooltip
, Qt
);
5223 Fmodify_frame_parameters (frame
, arg
);
5226 /* FIXME - can this be done in a similar way to normal frames?
5227 http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00641.html */
5229 /* Set the `display-type' frame parameter before setting up faces. */
5231 Lisp_Object disptype
;
5233 if (FRAME_DISPLAY_INFO (f
)->n_planes
== 1)
5235 else if (FRAME_DISPLAY_INFO (f
)->visual
->class == GrayScale
5236 || FRAME_DISPLAY_INFO (f
)->visual
->class == StaticGray
)
5237 disptype
= intern ("grayscale");
5239 disptype
= intern ("color");
5241 if (NILP (Fframe_parameter (frame
, Qdisplay_type
)))
5243 AUTO_FRAME_ARG (arg
, Qdisplay_type
, disptype
);
5244 Fmodify_frame_parameters (frame
, arg
);
5248 /* Set up faces after all frame parameters are known. This call
5249 also merges in face attributes specified for new frames.
5251 Frame parameters may be changed if .Xdefaults contains
5252 specifications for the default font. For example, if there is an
5253 `Emacs.default.attributeBackground: pink', the `background-color'
5254 attribute of the frame get's set, which let's the internal border
5255 of the tooltip frame appear in pink. Prevent this. */
5257 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5259 /* Set tip_frame here, so that */
5261 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5263 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5265 AUTO_FRAME_ARG (arg
, Qbackground_color
, bg
);
5266 Fmodify_frame_parameters (frame
, arg
);
5274 /* Now that the frame will be official, it counts as a reference to
5275 its display and terminal. */
5276 FRAME_DISPLAY_INFO (f
)->reference_count
++;
5277 f
->terminal
->reference_count
++;
5279 /* It is now ok to make the frame official even if we get an error
5280 below. And the frame needs to be on Vframe_list or making it
5281 visible won't work. */
5282 Vframe_list
= Fcons (frame
, Vframe_list
);
5283 f
->can_x_set_window_size
= true;
5285 /* Setting attributes of faces of the tooltip frame from resources
5286 and similar will set face_change, which leads to the clearing of
5287 all current matrices. Since this isn't necessary here, avoid it
5288 by resetting face_change to the value it had before we created
5290 face_change
= face_change_before
;
5292 /* Discard the unwind_protect. */
5293 return unbind_to (count
, frame
);
5297 /* Compute where to display tip frame F. PARMS is the list of frame
5298 parameters for F. DX and DY are specified offsets from the current
5299 location of the mouse. WIDTH and HEIGHT are the width and height
5300 of the tooltip. Return coordinates relative to the root window of
5301 the display in *ROOT_X, and *ROOT_Y. */
5304 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
)
5306 Lisp_Object left
, top
;
5311 /* User-specified position? */
5312 left
= Fcdr (Fassq (Qleft
, parms
));
5313 top
= Fcdr (Fassq (Qtop
, parms
));
5315 /* Move the tooltip window where the mouse pointer is. Resize and
5317 if (!INTEGERP (left
) || !INTEGERP (top
))
5320 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_DISPLAY_INFO (f
)->root_window
,
5321 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
5326 *root_y
= XINT (top
);
5327 else if (*root_y
+ XINT (dy
) <= 0)
5328 *root_y
= 0; /* Can happen for negative dy */
5329 else if (*root_y
+ XINT (dy
) + height
5330 <= x_display_pixel_height (FRAME_DISPLAY_INFO (f
)))
5331 /* It fits below the pointer */
5332 *root_y
+= XINT (dy
);
5333 else if (height
+ XINT (dy
) <= *root_y
)
5334 /* It fits above the pointer. */
5335 *root_y
-= height
+ XINT (dy
);
5337 /* Put it on the top. */
5340 if (INTEGERP (left
))
5341 *root_x
= XINT (left
);
5342 else if (*root_x
+ XINT (dx
) <= 0)
5343 *root_x
= 0; /* Can happen for negative dx */
5344 else if (*root_x
+ XINT (dx
) + width
5345 <= x_display_pixel_width (FRAME_DISPLAY_INFO (f
)))
5346 /* It fits to the right of the pointer. */
5347 *root_x
+= XINT (dx
);
5348 else if (width
+ XINT (dx
) <= *root_x
)
5349 /* It fits to the left of the pointer. */
5350 *root_x
-= width
+ XINT (dx
);
5352 /* Put it left-justified on the screen--it ought to fit that way. */
5357 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5358 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
5359 A tooltip window is a small X window displaying a string.
5361 This is an internal function; Lisp code should call `tooltip-show'.
5363 FRAME nil or omitted means use the selected frame.
5365 PARMS is an optional list of frame parameters which can be used to
5366 change the tooltip's appearance.
5368 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5369 means use the default timeout of 5 seconds.
5371 If the list of frame parameters PARMS contains a `left' parameters,
5372 the tooltip is displayed at that x-position. Otherwise it is
5373 displayed at the mouse position, with offset DX added (default is 5 if
5374 DX isn't specified). Likewise for the y-position; if a `top' frame
5375 parameter is specified, it determines the y-position of the tooltip
5376 window, otherwise it is displayed at the mouse position, with offset
5377 DY added (default is -10).
5379 A tooltip's maximum size is specified by `x-max-tooltip-size'.
5380 Text larger than the specified size is clipped. */)
5381 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
5386 struct buffer
*old_buffer
;
5387 struct text_pos pos
;
5388 int i
, width
, height
;
5389 bool seen_reversed_p
;
5390 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5391 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5392 ptrdiff_t count
= SPECPDL_INDEX ();
5394 specbind (Qinhibit_redisplay
, Qt
);
5396 GCPRO4 (string
, parms
, frame
, timeout
);
5398 CHECK_STRING (string
);
5399 if (SCHARS (string
) == 0)
5400 string
= make_unibyte_string (" ", 1);
5402 f
= decode_window_system_frame (frame
);
5404 timeout
= make_number (5);
5406 CHECK_NATNUM (timeout
);
5409 dx
= make_number (5);
5414 dy
= make_number (-10);
5419 if (x_gtk_use_system_tooltips
)
5423 /* Hide a previous tip, if any. */
5427 ok
= xg_prepare_tooltip (f
, string
, &width
, &height
);
5430 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5431 xg_show_tooltip (f
, root_x
, root_y
);
5432 /* This is used in Fx_hide_tip. */
5433 XSETFRAME (tip_frame
, f
);
5436 if (ok
) goto start_timer
;
5438 #endif /* USE_GTK */
5440 if (NILP (last_show_tip_args
))
5441 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5443 if (!NILP (tip_frame
))
5445 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5446 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5447 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5449 if (EQ (frame
, last_frame
)
5450 && !NILP (Fequal (last_string
, string
))
5451 && !NILP (Fequal (last_parms
, parms
)))
5453 struct frame
*tip_f
= XFRAME (tip_frame
);
5455 /* Only DX and DY have changed. */
5456 if (!NILP (tip_timer
))
5458 Lisp_Object timer
= tip_timer
;
5460 call1 (Qcancel_timer
, timer
);
5464 compute_tip_xy (tip_f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (tip_f
),
5465 FRAME_PIXEL_HEIGHT (tip_f
), &root_x
, &root_y
);
5466 XMoveWindow (FRAME_X_DISPLAY (tip_f
), FRAME_X_WINDOW (tip_f
),
5473 /* Hide a previous tip, if any. */
5476 ASET (last_show_tip_args
, 0, string
);
5477 ASET (last_show_tip_args
, 1, frame
);
5478 ASET (last_show_tip_args
, 2, parms
);
5480 /* Add default values to frame parameters. */
5481 if (NILP (Fassq (Qname
, parms
)))
5482 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5483 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5484 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5485 if (NILP (Fassq (Qborder_width
, parms
)))
5486 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5487 if (NILP (Fassq (Qbottom_divider_width
, parms
)))
5488 parms
= Fcons (Fcons (Qbottom_divider_width
, make_number (0)), parms
);
5489 if (NILP (Fassq (Qright_divider_width
, parms
)))
5490 parms
= Fcons (Fcons (Qright_divider_width
, make_number (0)), parms
);
5491 if (NILP (Fassq (Qborder_color
, parms
)))
5492 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5493 if (NILP (Fassq (Qbackground_color
, parms
)))
5494 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5497 /* Create a frame for the tooltip, and record it in the global
5498 variable tip_frame. */
5499 frame
= x_create_tip_frame (FRAME_DISPLAY_INFO (f
), parms
, string
);
5502 /* Set up the frame's root window. */
5503 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5509 if (CONSP (Vx_max_tooltip_size
)
5510 && RANGED_INTEGERP (1, XCAR (Vx_max_tooltip_size
), INT_MAX
)
5511 && RANGED_INTEGERP (1, XCDR (Vx_max_tooltip_size
), INT_MAX
))
5513 w
->total_cols
= XFASTINT (XCAR (Vx_max_tooltip_size
));
5514 w
->total_lines
= XFASTINT (XCDR (Vx_max_tooltip_size
));
5519 w
->total_lines
= 40;
5522 w
->pixel_width
= w
->total_cols
* FRAME_COLUMN_WIDTH (f
);
5523 w
->pixel_height
= w
->total_lines
* FRAME_LINE_HEIGHT (f
);
5525 FRAME_TOTAL_COLS (f
) = w
->total_cols
;
5526 adjust_frame_glyphs (f
);
5527 w
->pseudo_window_p
= true;
5529 /* Display the tooltip text in a temporary buffer. */
5530 old_buffer
= current_buffer
;
5531 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->contents
));
5532 bset_truncate_lines (current_buffer
, Qnil
);
5533 clear_glyph_matrix (w
->desired_matrix
);
5534 clear_glyph_matrix (w
->current_matrix
);
5535 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5536 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5538 /* Compute width and height of the tooltip. */
5540 seen_reversed_p
= false;
5541 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5543 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5547 /* Stop at the first empty row at the end. */
5548 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5551 /* Let the row go over the full width of the frame. */
5552 row
->full_width_p
= true;
5554 row_width
= row
->pixel_width
;
5555 if (row
->used
[TEXT_AREA
])
5557 /* There's a glyph at the end of rows that is used to place
5558 the cursor there. Don't include the width of this glyph. */
5559 if (!row
->reversed_p
)
5561 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5562 if (NILP (last
->object
))
5563 row_width
-= last
->pixel_width
;
5567 /* There could be a stretch glyph at the beginning of R2L
5568 rows that is produced by extend_face_to_end_of_line.
5569 Don't count that glyph. */
5570 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
5572 if (g
->type
== STRETCH_GLYPH
&& NILP (g
->object
))
5574 row_width
-= g
->pixel_width
;
5575 seen_reversed_p
= true;
5580 height
+= row
->height
;
5581 width
= max (width
, row_width
);
5584 /* If we've seen partial-length R2L rows, we need to re-adjust the
5585 tool-tip frame width and redisplay it again, to avoid over-wide
5586 tips due to the stretch glyph that extends R2L lines to full
5587 width of the frame. */
5588 if (seen_reversed_p
)
5590 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns,
5592 w
->pixel_width
= width
;
5593 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
5594 w
->total_cols
= width
;
5595 FRAME_TOTAL_COLS (f
) = width
;
5596 SET_FRAME_WIDTH (f
, width
);
5597 adjust_frame_glyphs (f
);
5598 clear_glyph_matrix (w
->desired_matrix
);
5599 clear_glyph_matrix (w
->current_matrix
);
5600 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
5602 /* Recompute width and height of the tooltip. */
5603 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5605 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5609 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5611 row
->full_width_p
= true;
5612 row_width
= row
->pixel_width
;
5613 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
5615 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5616 if (NILP (last
->object
))
5617 row_width
-= last
->pixel_width
;
5620 height
+= row
->height
;
5621 width
= max (width
, row_width
);
5625 /* Add the frame's internal border to the width and height the X
5626 window should have. */
5627 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5628 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5630 /* Move the tooltip window where the mouse pointer is. Resize and
5632 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5635 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5636 root_x
, root_y
, width
, height
);
5637 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5640 /* Draw into the window. */
5641 w
->must_be_updated_p
= true;
5642 update_single_window (w
);
5644 /* Restore original current buffer. */
5645 set_buffer_internal_1 (old_buffer
);
5646 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5649 /* Let the tip disappear after timeout seconds. */
5650 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5651 intern ("x-hide-tip"));
5654 return unbind_to (count
, Qnil
);
5658 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5659 doc
: /* Hide the current tooltip window, if there is any.
5660 Value is t if tooltip was open, nil otherwise. */)
5664 Lisp_Object deleted
, frame
, timer
;
5665 struct gcpro gcpro1
, gcpro2
;
5667 /* Return quickly if nothing to do. */
5668 if (NILP (tip_timer
) && NILP (tip_frame
))
5673 GCPRO2 (frame
, timer
);
5674 tip_frame
= tip_timer
= deleted
= Qnil
;
5676 count
= SPECPDL_INDEX ();
5677 specbind (Qinhibit_redisplay
, Qt
);
5678 specbind (Qinhibit_quit
, Qt
);
5681 call1 (Qcancel_timer
, timer
);
5685 /* When using system tooltip, tip_frame is the Emacs frame on which
5686 the tip is shown. */
5687 struct frame
*f
= XFRAME (frame
);
5688 if (FRAME_LIVE_P (f
) && xg_hide_tooltip (f
))
5695 delete_frame (frame
, Qnil
);
5699 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5700 redisplay procedure is not called when a tip frame over menu
5701 items is unmapped. Redisplay the menu manually... */
5704 struct frame
*f
= SELECTED_FRAME ();
5705 w
= f
->output_data
.x
->menubar_widget
;
5707 if (!DoesSaveUnders (FRAME_DISPLAY_INFO (f
)->screen
)
5711 xlwmenu_redisplay (w
);
5715 #endif /* USE_LUCID */
5719 return unbind_to (count
, deleted
);
5724 /***********************************************************************
5725 File selection dialog
5726 ***********************************************************************/
5728 DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog
,
5729 Sx_uses_old_gtk_dialog
,
5731 doc
: /* Return t if the old Gtk+ file selection dialog is used. */)
5737 && window_system_available (SELECTED_FRAME ())
5738 && xg_uses_old_file_dialog ())
5746 /* Callback for "OK" and "Cancel" on file selection dialog. */
5749 file_dialog_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5751 int *result
= client_data
;
5752 XmAnyCallbackStruct
*cb
= call_data
;
5753 *result
= cb
->reason
;
5757 /* Callback for unmapping a file selection dialog. This is used to
5758 capture the case where a dialog is closed via a window manager's
5759 closer button, for example. Using a XmNdestroyCallback didn't work
5763 file_dialog_unmap_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5765 int *result
= client_data
;
5766 *result
= XmCR_CANCEL
;
5770 clean_up_file_dialog (void *arg
)
5772 Widget dialog
= arg
;
5776 XtUnmanageChild (dialog
);
5777 XtDestroyWidget (dialog
);
5778 x_menu_set_in_use (false);
5783 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5784 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5785 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5786 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5787 or directory must exist.
5789 This function is only defined on NS, MS Windows, and X Windows with the
5790 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5791 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.
5792 On Windows 7 and later, the file selection dialog "remembers" the last
5793 directory where the user selected a file, and will open that directory
5794 instead of DIR on subsequent invocations of this function with the same
5795 value of DIR as in previous invocations; this is standard Windows behavior. */)
5796 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
,
5797 Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5800 struct frame
*f
= SELECTED_FRAME ();
5801 Lisp_Object file
= Qnil
;
5802 Lisp_Object decoded_file
;
5803 Widget dialog
, text
, help
;
5806 XmString dir_xmstring
, pattern_xmstring
;
5807 ptrdiff_t count
= SPECPDL_INDEX ();
5808 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5810 check_window_system (f
);
5812 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5814 if (popup_activated ())
5815 error ("Trying to use a menu from within a menu-entry");
5817 CHECK_STRING (prompt
);
5820 /* Prevent redisplay. */
5821 specbind (Qinhibit_redisplay
, Qt
);
5825 /* Create the dialog with PROMPT as title, using DIR as initial
5826 directory and using "*" as pattern. */
5827 dir
= Fexpand_file_name (dir
, Qnil
);
5828 dir_xmstring
= XmStringCreateLocalized (SSDATA (dir
));
5829 pattern_xmstring
= XmStringCreateLocalized ("*");
5831 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
5832 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
5833 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
5834 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
5835 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
5836 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
5838 XmStringFree (dir_xmstring
);
5839 XmStringFree (pattern_xmstring
);
5841 /* Add callbacks for OK and Cancel. */
5842 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
5843 (XtPointer
) &result
);
5844 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
5845 (XtPointer
) &result
);
5846 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
5847 (XtPointer
) &result
);
5849 /* Remove the help button since we can't display help. */
5850 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
5851 XtUnmanageChild (help
);
5853 /* Mark OK button as default. */
5854 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
5855 XmNshowAsDefault
, True
, NULL
);
5857 /* If MUSTMATCH is non-nil, disable the file entry field of the
5858 dialog, so that the user must select a file from the files list
5859 box. We can't remove it because we wouldn't have a way to get at
5860 the result file name, then. */
5861 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5862 if (!NILP (mustmatch
))
5865 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
5866 XtSetSensitive (text
, False
);
5867 XtSetSensitive (label
, False
);
5870 /* Manage the dialog, so that list boxes get filled. */
5871 XtManageChild (dialog
);
5873 if (STRINGP (default_filename
))
5875 XmString default_xmstring
;
5876 Widget wtext
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5877 Widget list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
5879 XmTextPosition last_pos
= XmTextFieldGetLastPosition (wtext
);
5880 XmTextFieldReplace (wtext
, 0, last_pos
,
5881 (SSDATA (Ffile_name_nondirectory (default_filename
))));
5883 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5884 must include the path for this to work. */
5886 default_xmstring
= XmStringCreateLocalized (SSDATA (default_filename
));
5888 if (XmListItemExists (list
, default_xmstring
))
5890 int item_pos
= XmListItemPos (list
, default_xmstring
);
5891 /* Select the item and scroll it into view. */
5892 XmListSelectPos (list
, item_pos
, True
);
5893 XmListSetPos (list
, item_pos
);
5896 XmStringFree (default_xmstring
);
5899 record_unwind_protect_ptr (clean_up_file_dialog
, dialog
);
5901 /* Process events until the user presses Cancel or OK. */
5902 x_menu_set_in_use (true);
5907 x_menu_wait_for_event (0);
5908 XtAppNextEvent (Xt_app_con
, &event
);
5909 if (event
.type
== KeyPress
5910 && FRAME_X_DISPLAY (f
) == event
.xkey
.display
)
5912 KeySym keysym
= XLookupKeysym (&event
.xkey
, 0);
5914 /* Pop down on C-g. */
5915 if (keysym
== XK_g
&& (event
.xkey
.state
& ControlMask
) != 0)
5916 XtUnmanageChild (dialog
);
5919 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
));
5922 /* Get the result. */
5923 if (result
== XmCR_OK
)
5925 XmString text_string
;
5928 XtVaGetValues (dialog
, XmNtextString
, &text_string
, NULL
);
5929 XmStringGetLtoR (text_string
, XmFONTLIST_DEFAULT_TAG
, &data
);
5930 XmStringFree (text_string
);
5931 file
= build_string (data
);
5940 /* Make "Cancel" equivalent to C-g. */
5942 Fsignal (Qquit
, Qnil
);
5944 decoded_file
= DECODE_FILE (file
);
5946 return unbind_to (count
, decoded_file
);
5949 #endif /* USE_MOTIF */
5954 clean_up_dialog (void)
5956 x_menu_set_in_use (false);
5959 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5960 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5961 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5962 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5963 or directory must exist.
5965 This function is only defined on NS, MS Windows, and X Windows with the
5966 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5967 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.
5968 On Windows 7 and later, the file selection dialog "remembers" the last
5969 directory where the user selected a file, and will open that directory
5970 instead of DIR on subsequent invocations of this function with the same
5971 value of DIR as in previous invocations; this is standard Windows behavior. */)
5972 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5974 struct frame
*f
= SELECTED_FRAME ();
5976 Lisp_Object file
= Qnil
;
5977 Lisp_Object decoded_file
;
5978 ptrdiff_t count
= SPECPDL_INDEX ();
5979 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5982 check_window_system (f
);
5984 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5986 if (popup_activated ())
5987 error ("Trying to use a menu from within a menu-entry");
5989 CHECK_STRING (prompt
);
5992 /* Prevent redisplay. */
5993 specbind (Qinhibit_redisplay
, Qt
);
5994 record_unwind_protect_void (clean_up_dialog
);
5998 if (STRINGP (default_filename
))
5999 cdef_file
= SSDATA (default_filename
);
6001 cdef_file
= SSDATA (dir
);
6003 fn
= xg_get_file_name (f
, SSDATA (prompt
), cdef_file
,
6005 ! NILP (only_dir_p
));
6009 file
= build_string (fn
);
6016 /* Make "Cancel" equivalent to C-g. */
6018 Fsignal (Qquit
, Qnil
);
6020 decoded_file
= DECODE_FILE (file
);
6022 return unbind_to (count
, decoded_file
);
6026 #ifdef HAVE_FREETYPE
6028 DEFUN ("x-select-font", Fx_select_font
, Sx_select_font
, 0, 2, 0,
6029 doc
: /* Read a font using a GTK dialog.
6030 Return either a font spec (for GTK versions >= 3.2) or a string
6031 containing a GTK-style font name.
6033 FRAME is the frame on which to pop up the font chooser. If omitted or
6034 nil, it defaults to the selected frame. */)
6035 (Lisp_Object frame
, Lisp_Object ignored
)
6037 struct frame
*f
= decode_window_system_frame (frame
);
6039 Lisp_Object font_param
;
6040 char *default_name
= NULL
;
6041 struct gcpro gcpro1
, gcpro2
;
6042 ptrdiff_t count
= SPECPDL_INDEX ();
6044 if (popup_activated ())
6045 error ("Trying to use a menu from within a menu-entry");
6047 /* Prevent redisplay. */
6048 specbind (Qinhibit_redisplay
, Qt
);
6049 record_unwind_protect_void (clean_up_dialog
);
6053 GCPRO2 (font_param
, font
);
6055 XSETFONT (font
, FRAME_FONT (f
));
6056 font_param
= Ffont_get (font
, QCname
);
6057 if (STRINGP (font_param
))
6058 default_name
= xlispstrdup (font_param
);
6061 font_param
= Fframe_parameter (frame
, Qfont_param
);
6062 if (STRINGP (font_param
))
6063 default_name
= xlispstrdup (font_param
);
6066 font
= xg_get_font (f
, default_name
);
6067 xfree (default_name
);
6072 Fsignal (Qquit
, Qnil
);
6074 return unbind_to (count
, font
);
6076 #endif /* HAVE_FREETYPE */
6078 #endif /* USE_GTK */
6081 /***********************************************************************
6083 ***********************************************************************/
6086 #include <X11/XKBlib.h>
6087 #include <X11/keysym.h>
6090 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
6091 Sx_backspace_delete_keys_p
, 0, 1, 0,
6092 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
6093 FRAME nil means use the selected frame.
6094 Value is t if we know that both keys are present, and are mapped to the
6095 usual X keysyms. Value is `lambda' if we cannot determine if both keys are
6096 present and mapped to the usual X keysyms. */)
6103 struct frame
*f
= decode_window_system_frame (frame
);
6104 Display
*dpy
= FRAME_X_DISPLAY (f
);
6105 Lisp_Object have_keys
;
6106 int major
, minor
, op
, event
, error_code
;
6110 /* Check library version in case we're dynamically linked. */
6111 major
= XkbMajorVersion
;
6112 minor
= XkbMinorVersion
;
6113 if (!XkbLibraryVersion (&major
, &minor
))
6119 /* Check that the server supports XKB. */
6120 major
= XkbMajorVersion
;
6121 minor
= XkbMinorVersion
;
6122 if (!XkbQueryExtension (dpy
, &op
, &event
, &error_code
, &major
, &minor
))
6128 /* In this code we check that the keyboard has physical keys with names
6129 that start with BKSP (Backspace) and DELE (Delete), and that they
6130 generate keysym XK_BackSpace and XK_Delete respectively.
6131 This function is used to test if normal-erase-is-backspace should be
6133 An alternative approach would be to just check if XK_BackSpace and
6134 XK_Delete are mapped to any key. But if any of those are mapped to
6135 some non-intuitive key combination (Meta-Shift-Ctrl-whatever) and the
6136 user doesn't know about it, it is better to return false here.
6137 It is more obvious to the user what to do if she/he has two keys
6138 clearly marked with names/symbols and one key does something not
6139 expected (i.e. she/he then tries the other).
6140 The cases where Backspace/Delete is mapped to some other key combination
6141 are rare, and in those cases, normal-erase-is-backspace can be turned on
6145 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
6148 int delete_keycode
= 0, backspace_keycode
= 0, i
;
6150 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
6152 for (i
= kb
->min_key_code
;
6153 (i
< kb
->max_key_code
6154 && (delete_keycode
== 0 || backspace_keycode
== 0));
6157 /* The XKB symbolic key names can be seen most easily in
6158 the PS file generated by `xkbprint -label name
6160 if (memcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
6162 else if (memcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
6163 backspace_keycode
= i
;
6166 XkbFreeNames (kb
, 0, True
);
6169 /* As of libX11-1.6.2, XkbGetMap manual says that you should use
6170 XkbFreeClientMap to free the data returned by XkbGetMap. But
6171 this function just frees the data referenced from KB and not
6172 KB itself. To free KB as well, call XkbFreeKeyboard. */
6173 XkbFreeKeyboard (kb
, XkbAllMapComponentsMask
, True
);
6176 && backspace_keycode
6177 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
6178 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
6188 /***********************************************************************
6190 ***********************************************************************/
6192 /* Keep this list in the same order as frame_parms in frame.c.
6193 Use 0 for unsupported frame parameters. */
6195 frame_parm_handler x_frame_parm_handlers
[] =
6199 x_set_background_color
,
6205 x_set_foreground_color
,
6208 x_set_internal_border_width
,
6209 x_set_right_divider_width
,
6210 x_set_bottom_divider_width
,
6211 x_set_menu_bar_lines
,
6213 x_explicitly_set_name
,
6214 x_set_scroll_bar_width
,
6215 x_set_scroll_bar_height
,
6218 x_set_vertical_scroll_bars
,
6219 x_set_horizontal_scroll_bars
,
6221 x_set_tool_bar_lines
,
6222 x_set_scroll_bar_foreground
,
6223 x_set_scroll_bar_background
,
6233 x_set_tool_bar_position
,
6239 DEFSYM (Qundefined_color
, "undefined-color");
6240 DEFSYM (Qcompound_text
, "compound-text");
6241 DEFSYM (Qcancel_timer
, "cancel-timer");
6242 DEFSYM (Qfont_param
, "font-parameter");
6243 DEFSYM (Qmono
, "mono");
6245 Fput (Qundefined_color
, Qerror_conditions
,
6246 listn (CONSTYPE_PURE
, 2, Qundefined_color
, Qerror
));
6247 Fput (Qundefined_color
, Qerror_message
,
6248 build_pure_c_string ("Undefined color"));
6250 DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape
,
6251 doc
: /* The shape of the pointer when over text.
6252 Changing the value does not affect existing frames
6253 unless you set the mouse color. */);
6254 Vx_pointer_shape
= Qnil
;
6256 #if false /* This doesn't really do anything. */
6257 DEFVAR_LISP ("x-nontext-pointer-shape", Vx_nontext_pointer_shape
,
6258 doc
: /* The shape of the pointer when not over text.
6259 This variable takes effect when you create a new frame
6260 or when you set the mouse color. */);
6262 Vx_nontext_pointer_shape
= Qnil
;
6264 DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape
,
6265 doc
: /* The shape of the pointer when Emacs is busy.
6266 This variable takes effect when you create a new frame
6267 or when you set the mouse color. */);
6268 Vx_hourglass_pointer_shape
= Qnil
;
6270 #if false /* This doesn't really do anything. */
6271 DEFVAR_LISP ("x-mode-pointer-shape", Vx_mode_pointer_shape
,
6272 doc
: /* The shape of the pointer when over the mode line.
6273 This variable takes effect when you create a new frame
6274 or when you set the mouse color. */);
6276 Vx_mode_pointer_shape
= Qnil
;
6278 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
6279 Vx_sensitive_text_pointer_shape
,
6280 doc
: /* The shape of the pointer when over mouse-sensitive text.
6281 This variable takes effect when you create a new frame
6282 or when you set the mouse color. */);
6283 Vx_sensitive_text_pointer_shape
= Qnil
;
6285 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
6286 Vx_window_horizontal_drag_shape
,
6287 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
6288 This variable takes effect when you create a new frame
6289 or when you set the mouse color. */);
6290 Vx_window_horizontal_drag_shape
= Qnil
;
6292 DEFVAR_LISP ("x-window-vertical-drag-cursor",
6293 Vx_window_vertical_drag_shape
,
6294 doc
: /* Pointer shape to use for indicating a window can be dragged vertically.
6295 This variable takes effect when you create a new frame
6296 or when you set the mouse color. */);
6297 Vx_window_vertical_drag_shape
= Qnil
;
6299 DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel
,
6300 doc
: /* A string indicating the foreground color of the cursor box. */);
6301 Vx_cursor_fore_pixel
= Qnil
;
6303 DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size
,
6304 doc
: /* Maximum size for tooltips.
6305 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
6306 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
6308 DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager
,
6309 doc
: /* Non-nil if no X window manager is in use.
6310 Emacs doesn't try to figure this out; this is always nil
6311 unless you set it to something else. */);
6312 /* We don't have any way to find this out, so set it to nil
6313 and maybe the user would like to set it to t. */
6314 Vx_no_window_manager
= Qnil
;
6316 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
6317 Vx_pixel_size_width_font_regexp
,
6318 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
6320 Since Emacs gets width of a font matching with this regexp from
6321 PIXEL_SIZE field of the name, font finding mechanism gets faster for
6322 such a font. This is especially effective for such large fonts as
6323 Chinese, Japanese, and Korean. */);
6324 Vx_pixel_size_width_font_regexp
= Qnil
;
6326 /* This is not ifdef:ed, so other builds than GTK can customize it. */
6327 DEFVAR_BOOL ("x-gtk-use-old-file-dialog", x_gtk_use_old_file_dialog
,
6328 doc
: /* Non-nil means prompt with the old GTK file selection dialog.
6329 If nil or if the file selection dialog is not available, the new GTK file
6330 chooser is used instead. To turn off all file dialogs set the
6331 variable `use-file-dialog'. */);
6332 x_gtk_use_old_file_dialog
= false;
6334 DEFVAR_BOOL ("x-gtk-show-hidden-files", x_gtk_show_hidden_files
,
6335 doc
: /* If non-nil, the GTK file chooser will by default show hidden files.
6336 Note that this is just the default, there is a toggle button on the file
6337 chooser to show or not show hidden files on a case by case basis. */);
6338 x_gtk_show_hidden_files
= false;
6340 DEFVAR_BOOL ("x-gtk-file-dialog-help-text", x_gtk_file_dialog_help_text
,
6341 doc
: /* If non-nil, the GTK file chooser will show additional help text.
6342 If more space for files in the file chooser dialog is wanted, set this to nil
6343 to turn the additional text off. */);
6344 x_gtk_file_dialog_help_text
= true;
6346 DEFVAR_BOOL ("x-gtk-use-system-tooltips", x_gtk_use_system_tooltips
,
6347 doc
: /* If non-nil with a Gtk+ built Emacs, the Gtk+ tooltip is used.
6348 Otherwise use Emacs own tooltip implementation.
6349 When using Gtk+ tooltips, the tooltip face is not used. */);
6350 x_gtk_use_system_tooltips
= true;
6352 /* Tell Emacs about this window system. */
6353 Fprovide (Qx
, Qnil
);
6355 #ifdef USE_X_TOOLKIT
6356 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
6358 Fprovide (intern_c_string ("motif"), Qnil
);
6360 DEFVAR_LISP ("motif-version-string", Vmotif_version_string
,
6361 doc
: /* Version info for LessTif/Motif. */);
6362 Vmotif_version_string
= build_string (XmVERSION_STRING
);
6363 #endif /* USE_MOTIF */
6364 #endif /* USE_X_TOOLKIT */
6367 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
6368 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
6369 But for a user it is a toolkit for X, and indeed, configure
6370 accepts --with-x-toolkit=gtk. */
6371 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
6372 Fprovide (intern_c_string ("gtk"), Qnil
);
6373 Fprovide (intern_c_string ("move-toolbar"), Qnil
);
6375 DEFVAR_LISP ("gtk-version-string", Vgtk_version_string
,
6376 doc
: /* Version info for GTK+. */);
6378 char gtk_version
[sizeof ".." + 3 * INT_STRLEN_BOUND (int)];
6379 int len
= sprintf (gtk_version
, "%d.%d.%d",
6380 GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
);
6381 Vgtk_version_string
= make_pure_string (gtk_version
, len
, len
, false);
6383 #endif /* USE_GTK */
6385 /* X window properties. */
6386 defsubr (&Sx_change_window_property
);
6387 defsubr (&Sx_delete_window_property
);
6388 defsubr (&Sx_window_property
);
6390 defsubr (&Sxw_display_color_p
);
6391 defsubr (&Sx_display_grayscale_p
);
6392 defsubr (&Sxw_color_defined_p
);
6393 defsubr (&Sxw_color_values
);
6394 defsubr (&Sx_server_max_request_size
);
6395 defsubr (&Sx_server_vendor
);
6396 defsubr (&Sx_server_version
);
6397 defsubr (&Sx_display_pixel_width
);
6398 defsubr (&Sx_display_pixel_height
);
6399 defsubr (&Sx_display_mm_width
);
6400 defsubr (&Sx_display_mm_height
);
6401 defsubr (&Sx_display_screens
);
6402 defsubr (&Sx_display_planes
);
6403 defsubr (&Sx_display_color_cells
);
6404 defsubr (&Sx_display_visual_class
);
6405 defsubr (&Sx_display_backing_store
);
6406 defsubr (&Sx_display_save_under
);
6407 defsubr (&Sx_display_monitor_attributes_list
);
6408 defsubr (&Sx_frame_geometry
);
6409 defsubr (&Sx_wm_set_size_hint
);
6410 defsubr (&Sx_create_frame
);
6411 defsubr (&Sx_open_connection
);
6412 defsubr (&Sx_close_connection
);
6413 defsubr (&Sx_display_list
);
6414 defsubr (&Sx_synchronize
);
6415 defsubr (&Sx_backspace_delete_keys_p
);
6417 defsubr (&Sx_show_tip
);
6418 defsubr (&Sx_hide_tip
);
6420 staticpro (&tip_timer
);
6422 staticpro (&tip_frame
);
6424 last_show_tip_args
= Qnil
;
6425 staticpro (&last_show_tip_args
);
6427 defsubr (&Sx_uses_old_gtk_dialog
);
6428 #if defined (USE_MOTIF) || defined (USE_GTK)
6429 defsubr (&Sx_file_dialog
);
6432 #if defined (USE_GTK) && defined (HAVE_FREETYPE)
6433 defsubr (&Sx_select_font
);