1 /* Functions for the X window system.
3 Copyright (C) 1989, 1992-2013 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/>. */
29 #include "character.h"
31 #include "intervals.h"
32 #include "dispextern.h"
34 #include "blockinput.h"
40 #include "termhooks.h"
47 #include <sys/types.h>
50 #if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */
51 #include "bitmaps/gray.xbm"
53 #include <X11/bitmaps/gray>
56 #include "xsettings.h"
59 #include <X11/extensions/Xrandr.h>
62 #include <X11/extensions/Xinerama.h>
70 #include <X11/Shell.h>
74 #include <X11/Xaw3d/Paned.h>
75 #include <X11/Xaw3d/Label.h>
76 #else /* !HAVE_XAW3D */
77 #include <X11/Xaw/Paned.h>
78 #include <X11/Xaw/Label.h>
79 #endif /* HAVE_XAW3D */
80 #endif /* USE_MOTIF */
83 #undef USG /* ####KLUDGE for Solaris 2.2 and up */
86 #ifdef USG /* Pacify gcc -Wunused-macros. */
94 #include "../lwlib/lwlib.h"
98 #include <Xm/DialogS.h>
99 #include <Xm/FileSB.h>
101 #include <Xm/TextF.h>
105 #include "../lwlib/xlwmenu.h"
108 #if !defined (NO_EDITRES)
110 extern void _XEditResCheckMessages (Widget
, XtPointer
, XEvent
*, Boolean
*);
111 #endif /* not defined NO_EDITRES */
113 /* Unique id counter for widgets created by the Lucid Widget Library. */
115 extern LWLIB_ID widget_id_tick
;
119 #endif /* USE_MOTIF */
121 #endif /* USE_X_TOOLKIT */
127 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
129 static Lisp_Object Qsuppress_icon
;
130 static Lisp_Object Qundefined_color
;
131 static Lisp_Object Qcompound_text
, Qcancel_timer
;
132 Lisp_Object Qfont_param
;
135 static ptrdiff_t image_cache_refcount
;
136 static int dpyinfo_refcount
;
139 static struct x_display_info
*x_display_info_for_name (Lisp_Object
);
141 /* Let the user specify an X display with a Lisp object.
142 OBJECT may be nil, a frame or a terminal object.
143 nil stands for the selected frame--or, if that is not an X frame,
144 the first X display on the list. */
146 struct x_display_info
*
147 check_x_display_info (Lisp_Object object
)
149 struct x_display_info
*dpyinfo
= NULL
;
153 struct frame
*sf
= XFRAME (selected_frame
);
155 if (FRAME_X_P (sf
) && FRAME_LIVE_P (sf
))
156 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
157 else if (x_display_list
!= 0)
158 dpyinfo
= x_display_list
;
160 error ("X windows are not in use or not initialized");
162 else if (TERMINALP (object
))
164 struct terminal
*t
= get_terminal (object
, 1);
166 if (t
->type
!= output_x_window
)
167 error ("Terminal %d is not an X display", t
->id
);
169 dpyinfo
= t
->display_info
.x
;
171 else if (STRINGP (object
))
172 dpyinfo
= x_display_info_for_name (object
);
175 struct frame
*f
= decode_window_system_frame (object
);
176 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
182 /* Store the screen positions of frame F into XPTR and YPTR.
183 These are the positions of the containing window manager window,
184 not Emacs's own window. */
187 x_real_positions (struct frame
*f
, int *xptr
, int *yptr
)
189 int win_x
, win_y
, outer_x
IF_LINT (= 0), outer_y
IF_LINT (= 0);
190 int real_x
= 0, real_y
= 0;
192 Window win
= f
->output_data
.x
->parent_desc
;
194 unsigned long actual_size
, bytes_remaining
;
195 int rc
, actual_format
;
196 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
198 Display
*dpy
= FRAME_X_DISPLAY (f
);
199 unsigned char *tmp_data
= NULL
;
200 Atom target_type
= XA_CARDINAL
;
204 x_catch_errors (dpy
);
206 if (win
== dpyinfo
->root_window
)
207 win
= FRAME_OUTER_WINDOW (f
);
209 /* This loop traverses up the containment tree until we hit the root
210 window. Window managers may intersect many windows between our window
211 and the root window. The window we find just before the root window
212 should be the outer WM window. */
215 Window wm_window
, rootw
;
216 Window
*tmp_children
;
217 unsigned int tmp_nchildren
;
220 success
= XQueryTree (FRAME_X_DISPLAY (f
), win
, &rootw
,
221 &wm_window
, &tmp_children
, &tmp_nchildren
);
223 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
225 /* Don't free tmp_children if XQueryTree failed. */
229 XFree (tmp_children
);
231 if (wm_window
== rootw
|| had_errors
)
242 /* Get the real coordinates for the WM window upper left corner */
243 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
244 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
246 /* Translate real coordinates to coordinates relative to our
247 window. For our window, the upper left corner is 0, 0.
248 Since the upper left corner of the WM window is outside
249 our window, win_x and win_y will be negative:
251 ------------------ ---> x
253 | ----------------- v y
256 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
258 /* From-window, to-window. */
259 FRAME_X_DISPLAY_INFO (f
)->root_window
,
262 /* From-position, to-position. */
263 real_x
, real_y
, &win_x
, &win_y
,
268 if (FRAME_X_WINDOW (f
) == FRAME_OUTER_WINDOW (f
))
275 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
277 /* From-window, to-window. */
278 FRAME_X_DISPLAY_INFO (f
)->root_window
,
279 FRAME_OUTER_WINDOW (f
),
281 /* From-position, to-position. */
282 real_x
, real_y
, &outer_x
, &outer_y
,
288 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
292 if (dpyinfo
->root_window
== f
->output_data
.x
->parent_desc
)
294 /* Try _NET_FRAME_EXTENTS if our parent is the root window. */
295 rc
= XGetWindowProperty (dpy
, win
, dpyinfo
->Xatom_net_frame_extents
,
296 0, max_len
, False
, target_type
,
297 &actual_type
, &actual_format
, &actual_size
,
298 &bytes_remaining
, &tmp_data
);
300 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
301 && actual_size
== 4 && actual_format
== 32)
305 long *fe
= (long *)tmp_data
;
307 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
308 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
316 if (tmp_data
) XFree (tmp_data
);
322 if (had_errors
) return;
324 f
->x_pixels_diff
= -win_x
;
325 f
->y_pixels_diff
= -win_y
;
327 FRAME_X_OUTPUT (f
)->x_pixels_outer_diff
= -outer_x
;
328 FRAME_X_OUTPUT (f
)->y_pixels_outer_diff
= -outer_y
;
337 /* Gamma-correct COLOR on frame F. */
340 gamma_correct (struct frame
*f
, XColor
*color
)
344 color
->red
= pow (color
->red
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
345 color
->green
= pow (color
->green
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
346 color
->blue
= pow (color
->blue
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
351 /* Decide if color named COLOR_NAME is valid for use on frame F. If
352 so, return the RGB values in COLOR. If ALLOC_P,
353 allocate the color. Value is false if COLOR_NAME is invalid, or
354 no color could be allocated. */
357 x_defined_color (struct frame
*f
, const char *color_name
,
358 XColor
*color
, bool alloc_p
)
361 Display
*dpy
= FRAME_X_DISPLAY (f
);
362 Colormap cmap
= FRAME_X_COLORMAP (f
);
366 success_p
= xg_check_special_colors (f
, color_name
, color
);
369 success_p
= XParseColor (dpy
, cmap
, color_name
, color
) != 0;
370 if (success_p
&& alloc_p
)
371 success_p
= x_alloc_nearest_color (f
, cmap
, color
);
378 /* Return the pixel color value for color COLOR_NAME on frame F. If F
379 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
380 Signal an error if color can't be allocated. */
383 x_decode_color (struct frame
*f
, Lisp_Object color_name
, int mono_color
)
387 CHECK_STRING (color_name
);
389 #if 0 /* Don't do this. It's wrong when we're not using the default
390 colormap, it makes freeing difficult, and it's probably not
391 an important optimization. */
392 if (strcmp (SDATA (color_name
), "black") == 0)
393 return BLACK_PIX_DEFAULT (f
);
394 else if (strcmp (SDATA (color_name
), "white") == 0)
395 return WHITE_PIX_DEFAULT (f
);
398 /* Return MONO_COLOR for monochrome frames. */
399 if (FRAME_X_DISPLAY_INFO (f
)->n_planes
== 1)
402 /* x_defined_color is responsible for coping with failures
403 by looking for a near-miss. */
404 if (x_defined_color (f
, SSDATA (color_name
), &cdef
, 1))
407 signal_error ("Undefined color", color_name
);
412 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
413 the previous value of that parameter, NEW_VALUE is the new value.
414 See also the comment of wait_for_wm in struct x_output. */
417 x_set_wait_for_wm (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
419 f
->output_data
.x
->wait_for_wm
= !NILP (new_value
);
423 x_set_tool_bar_position (struct frame
*f
,
424 Lisp_Object new_value
,
425 Lisp_Object old_value
)
427 if (! EQ (new_value
, Qleft
) && ! EQ (new_value
, Qright
)
428 && ! EQ (new_value
, Qbottom
) && ! EQ (new_value
, Qtop
))
430 if (EQ (new_value
, old_value
)) return;
433 xg_change_toolbar_position (f
, new_value
);
434 fset_tool_bar_position (f
, new_value
);
440 /* Set icon from FILE for frame F. By using GTK functions the icon
441 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
444 xg_set_icon (struct frame
*f
, Lisp_Object file
)
449 found
= x_find_image_file (file
);
455 char *filename
= SSDATA (found
);
458 pixbuf
= gdk_pixbuf_new_from_file (filename
, &err
);
462 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
464 g_object_unref (pixbuf
);
478 xg_set_icon_from_xpm_data (struct frame
*f
, const char **data
)
480 GdkPixbuf
*pixbuf
= gdk_pixbuf_new_from_xpm_data (data
);
485 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)), pixbuf
);
486 g_object_unref (pixbuf
);
492 /* Functions called only from `x_set_frame_param'
493 to set individual parameters.
495 If FRAME_X_WINDOW (f) is 0,
496 the frame is being created and its X-window does not exist yet.
497 In that case, just record the parameter's new value
498 in the standard place; do not attempt to change the window. */
501 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
503 struct x_output
*x
= f
->output_data
.x
;
504 unsigned long fg
, old_fg
;
506 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
507 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
508 FRAME_FOREGROUND_PIXEL (f
) = fg
;
510 if (FRAME_X_WINDOW (f
) != 0)
512 Display
*dpy
= FRAME_X_DISPLAY (f
);
515 XSetForeground (dpy
, x
->normal_gc
, fg
);
516 XSetBackground (dpy
, x
->reverse_gc
, fg
);
518 if (x
->cursor_pixel
== old_fg
)
520 unload_color (f
, x
->cursor_pixel
);
521 x
->cursor_pixel
= x_copy_color (f
, fg
);
522 XSetBackground (dpy
, x
->cursor_gc
, x
->cursor_pixel
);
527 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
529 if (FRAME_VISIBLE_P (f
))
533 unload_color (f
, old_fg
);
537 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
539 struct x_output
*x
= f
->output_data
.x
;
542 bg
= x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
543 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
544 FRAME_BACKGROUND_PIXEL (f
) = bg
;
546 if (FRAME_X_WINDOW (f
) != 0)
548 Display
*dpy
= FRAME_X_DISPLAY (f
);
551 XSetBackground (dpy
, x
->normal_gc
, bg
);
552 XSetForeground (dpy
, x
->reverse_gc
, bg
);
553 XSetWindowBackground (dpy
, FRAME_X_WINDOW (f
), bg
);
554 XSetForeground (dpy
, x
->cursor_gc
, bg
);
557 xg_set_background_color (f
, bg
);
560 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
561 toolkit scroll bars. */
564 for (bar
= FRAME_SCROLL_BARS (f
);
566 bar
= XSCROLL_BAR (bar
)->next
)
568 Window window
= XSCROLL_BAR (bar
)->x_window
;
569 XSetWindowBackground (dpy
, window
, bg
);
572 #endif /* USE_TOOLKIT_SCROLL_BARS */
575 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
577 if (FRAME_VISIBLE_P (f
))
583 make_invisible_cursor (struct frame
*f
)
585 Display
*dpy
= FRAME_X_DISPLAY (f
);
586 static char const no_data
[] = { 0 };
591 x_catch_errors (dpy
);
592 pix
= XCreateBitmapFromData (dpy
, FRAME_X_DISPLAY_INFO (f
)->root_window
,
594 if (! x_had_errors_p (dpy
) && pix
!= None
)
598 col
.red
= col
.green
= col
.blue
= 0;
599 col
.flags
= DoRed
| DoGreen
| DoBlue
;
600 pixc
= XCreatePixmapCursor (dpy
, pix
, pix
, &col
, &col
, 0, 0);
601 if (! x_had_errors_p (dpy
) && pixc
!= None
)
603 XFreePixmap (dpy
, pix
);
612 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
614 struct x_output
*x
= f
->output_data
.x
;
615 Display
*dpy
= FRAME_X_DISPLAY (f
);
616 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
617 Cursor hourglass_cursor
, horizontal_drag_cursor
;
618 unsigned long pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
619 unsigned long mask_color
= FRAME_BACKGROUND_PIXEL (f
);
621 /* Don't let pointers be invisible. */
622 if (mask_color
== pixel
)
624 x_free_colors (f
, &pixel
, 1);
625 pixel
= x_copy_color (f
, FRAME_FOREGROUND_PIXEL (f
));
628 unload_color (f
, x
->mouse_pixel
);
629 x
->mouse_pixel
= pixel
;
633 /* It's not okay to crash if the user selects a screwy cursor. */
634 x_catch_errors (dpy
);
636 if (!NILP (Vx_pointer_shape
))
638 CHECK_NUMBER (Vx_pointer_shape
);
639 cursor
= XCreateFontCursor (dpy
, XINT (Vx_pointer_shape
));
642 cursor
= XCreateFontCursor (dpy
, XC_xterm
);
643 x_check_errors (dpy
, "bad text pointer cursor: %s");
645 if (!NILP (Vx_nontext_pointer_shape
))
647 CHECK_NUMBER (Vx_nontext_pointer_shape
);
649 = XCreateFontCursor (dpy
, XINT (Vx_nontext_pointer_shape
));
652 nontext_cursor
= XCreateFontCursor (dpy
, XC_left_ptr
);
653 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
655 if (!NILP (Vx_hourglass_pointer_shape
))
657 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
659 = XCreateFontCursor (dpy
, XINT (Vx_hourglass_pointer_shape
));
662 hourglass_cursor
= XCreateFontCursor (dpy
, XC_watch
);
663 x_check_errors (dpy
, "bad hourglass pointer cursor: %s");
665 if (!NILP (Vx_mode_pointer_shape
))
667 CHECK_NUMBER (Vx_mode_pointer_shape
);
668 mode_cursor
= XCreateFontCursor (dpy
, XINT (Vx_mode_pointer_shape
));
671 mode_cursor
= XCreateFontCursor (dpy
, XC_xterm
);
672 x_check_errors (dpy
, "bad modeline pointer cursor: %s");
674 if (!NILP (Vx_sensitive_text_pointer_shape
))
676 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
678 = XCreateFontCursor (dpy
, XINT (Vx_sensitive_text_pointer_shape
));
681 hand_cursor
= XCreateFontCursor (dpy
, XC_hand2
);
683 if (!NILP (Vx_window_horizontal_drag_shape
))
685 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
686 horizontal_drag_cursor
687 = XCreateFontCursor (dpy
, XINT (Vx_window_horizontal_drag_shape
));
690 horizontal_drag_cursor
691 = XCreateFontCursor (dpy
, XC_sb_h_double_arrow
);
693 /* Check and report errors with the above calls. */
694 x_check_errors (dpy
, "can't set cursor shape: %s");
698 XColor fore_color
, back_color
;
700 fore_color
.pixel
= x
->mouse_pixel
;
701 x_query_color (f
, &fore_color
);
702 back_color
.pixel
= mask_color
;
703 x_query_color (f
, &back_color
);
705 XRecolorCursor (dpy
, cursor
, &fore_color
, &back_color
);
706 XRecolorCursor (dpy
, nontext_cursor
, &fore_color
, &back_color
);
707 XRecolorCursor (dpy
, mode_cursor
, &fore_color
, &back_color
);
708 XRecolorCursor (dpy
, hand_cursor
, &fore_color
, &back_color
);
709 XRecolorCursor (dpy
, hourglass_cursor
, &fore_color
, &back_color
);
710 XRecolorCursor (dpy
, horizontal_drag_cursor
, &fore_color
, &back_color
);
713 if (FRAME_X_WINDOW (f
) != 0)
714 XDefineCursor (dpy
, FRAME_X_WINDOW (f
),
715 f
->output_data
.x
->current_cursor
= cursor
);
717 if (FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
== 0)
718 FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
= make_invisible_cursor (f
);
720 if (cursor
!= x
->text_cursor
721 && x
->text_cursor
!= 0)
722 XFreeCursor (dpy
, x
->text_cursor
);
723 x
->text_cursor
= cursor
;
725 if (nontext_cursor
!= x
->nontext_cursor
726 && x
->nontext_cursor
!= 0)
727 XFreeCursor (dpy
, x
->nontext_cursor
);
728 x
->nontext_cursor
= nontext_cursor
;
730 if (hourglass_cursor
!= x
->hourglass_cursor
731 && x
->hourglass_cursor
!= 0)
732 XFreeCursor (dpy
, x
->hourglass_cursor
);
733 x
->hourglass_cursor
= hourglass_cursor
;
735 if (mode_cursor
!= x
->modeline_cursor
736 && x
->modeline_cursor
!= 0)
737 XFreeCursor (dpy
, f
->output_data
.x
->modeline_cursor
);
738 x
->modeline_cursor
= mode_cursor
;
740 if (hand_cursor
!= x
->hand_cursor
741 && x
->hand_cursor
!= 0)
742 XFreeCursor (dpy
, x
->hand_cursor
);
743 x
->hand_cursor
= hand_cursor
;
745 if (horizontal_drag_cursor
!= x
->horizontal_drag_cursor
746 && x
->horizontal_drag_cursor
!= 0)
747 XFreeCursor (dpy
, x
->horizontal_drag_cursor
);
748 x
->horizontal_drag_cursor
= horizontal_drag_cursor
;
753 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
757 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
759 unsigned long fore_pixel
, pixel
;
760 bool fore_pixel_allocated_p
= 0, pixel_allocated_p
= 0;
761 struct x_output
*x
= f
->output_data
.x
;
763 if (!NILP (Vx_cursor_fore_pixel
))
765 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
766 WHITE_PIX_DEFAULT (f
));
767 fore_pixel_allocated_p
= 1;
770 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
772 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
773 pixel_allocated_p
= 1;
775 /* Make sure that the cursor color differs from the background color. */
776 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
778 if (pixel_allocated_p
)
780 x_free_colors (f
, &pixel
, 1);
781 pixel_allocated_p
= 0;
784 pixel
= x
->mouse_pixel
;
785 if (pixel
== fore_pixel
)
787 if (fore_pixel_allocated_p
)
789 x_free_colors (f
, &fore_pixel
, 1);
790 fore_pixel_allocated_p
= 0;
792 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
796 unload_color (f
, x
->cursor_foreground_pixel
);
797 if (!fore_pixel_allocated_p
)
798 fore_pixel
= x_copy_color (f
, fore_pixel
);
799 x
->cursor_foreground_pixel
= fore_pixel
;
801 unload_color (f
, x
->cursor_pixel
);
802 if (!pixel_allocated_p
)
803 pixel
= x_copy_color (f
, pixel
);
804 x
->cursor_pixel
= pixel
;
806 if (FRAME_X_WINDOW (f
) != 0)
809 XSetBackground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, x
->cursor_pixel
);
810 XSetForeground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, fore_pixel
);
813 if (FRAME_VISIBLE_P (f
))
815 x_update_cursor (f
, 0);
816 x_update_cursor (f
, 1);
820 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
823 /* Set the border-color of frame F to pixel value PIX.
824 Note that this does not fully take effect if done before
825 F has an x-window. */
828 x_set_border_pixel (struct frame
*f
, int pix
)
830 unload_color (f
, f
->output_data
.x
->border_pixel
);
831 f
->output_data
.x
->border_pixel
= pix
;
833 if (FRAME_X_WINDOW (f
) != 0 && f
->border_width
> 0)
836 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), pix
);
839 if (FRAME_VISIBLE_P (f
))
844 /* Set the border-color of frame F to value described by ARG.
845 ARG can be a string naming a color.
846 The border-color is used for the border that is drawn by the X server.
847 Note that this does not fully take effect if done before
848 F has an x-window; it must be redone when the window is created.
850 Note: this is done in two routines because of the way X10 works.
852 Note: under X11, this is normally the province of the window manager,
853 and so emacs's border colors may be overridden. */
856 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
861 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
862 x_set_border_pixel (f
, pix
);
863 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
868 x_set_cursor_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
870 set_frame_cursor_types (f
, arg
);
874 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
880 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
883 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
888 result
= x_text_icon (f
,
889 SSDATA ((!NILP (f
->icon_name
)
893 result
= x_bitmap_icon (f
, arg
);
898 error ("No icon window available");
901 XFlush (FRAME_X_DISPLAY (f
));
906 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
912 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
915 else if (!NILP (arg
) || NILP (oldval
))
918 fset_icon_name (f
, arg
);
920 if (f
->output_data
.x
->icon_bitmap
!= 0)
925 result
= x_text_icon (f
,
926 SSDATA ((!NILP (f
->icon_name
)
935 error ("No icon window available");
938 XFlush (FRAME_X_DISPLAY (f
));
944 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
947 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
948 int olines
= FRAME_MENU_BAR_LINES (f
);
951 /* Right now, menu bars don't work properly in minibuf-only frames;
952 most of the commands try to apply themselves to the minibuffer
953 frame itself, and get an error because you can't switch buffers
954 in or split the minibuffer window. */
955 if (FRAME_MINIBUF_ONLY_P (f
))
958 if (TYPE_RANGED_INTEGERP (int, value
))
959 nlines
= XINT (value
);
963 /* Make sure we redisplay all windows in this frame. */
964 windows_or_buffers_changed
++;
966 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
967 FRAME_MENU_BAR_LINES (f
) = 0;
970 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
971 if (FRAME_X_P (f
) && f
->output_data
.x
->menubar_widget
== 0)
972 /* Make sure next redisplay shows the menu bar. */
973 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= 1;
977 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
978 free_frame_menubar (f
);
979 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
981 f
->output_data
.x
->menubar_widget
= 0;
983 #else /* not USE_X_TOOLKIT && not USE_GTK */
984 FRAME_MENU_BAR_LINES (f
) = nlines
;
985 resize_frame_windows (f
, FRAME_LINES (f
), 0);
987 /* If the menu bar height gets changed, the internal border below
988 the top margin has to be cleared. Also, if the menu bar gets
989 larger, the area for the added lines has to be cleared except for
990 the first menu bar line that is to be drawn later. */
991 if (nlines
!= olines
)
993 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
994 int width
= FRAME_PIXEL_WIDTH (f
);
997 /* height can be zero here. */
998 if (height
> 0 && width
> 0)
1000 y
= FRAME_TOP_MARGIN_HEIGHT (f
);
1003 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1004 0, y
, width
, height
);
1008 if (nlines
> 1 && nlines
> olines
)
1010 y
= (olines
== 0 ? 1 : olines
) * FRAME_LINE_HEIGHT (f
);
1011 height
= nlines
* FRAME_LINE_HEIGHT (f
) - y
;
1014 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1015 0, y
, width
, height
);
1019 if (nlines
== 0 && WINDOWP (f
->menu_bar_window
))
1020 clear_glyph_matrix (XWINDOW (f
->menu_bar_window
)->current_matrix
);
1022 #endif /* not USE_X_TOOLKIT && not USE_GTK */
1023 adjust_frame_glyphs (f
);
1024 run_window_configuration_change_hook (f
);
1028 /* Set the number of lines used for the tool bar of frame F to VALUE.
1029 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1030 is the old number of tool bar lines. This function changes the
1031 height of all windows on frame F to match the new tool bar height.
1032 The frame's height doesn't change. */
1035 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1038 #if ! defined (USE_GTK)
1039 int delta
, root_height
;
1040 Lisp_Object root_window
;
1043 /* Treat tool bars like menu bars. */
1044 if (FRAME_MINIBUF_ONLY_P (f
))
1047 /* Use VALUE only if an int >= 0. */
1048 if (RANGED_INTEGERP (0, value
, INT_MAX
))
1049 nlines
= XFASTINT (value
);
1055 FRAME_TOOL_BAR_LINES (f
) = 0;
1058 FRAME_EXTERNAL_TOOL_BAR (f
) = 1;
1059 if (FRAME_X_P (f
) && f
->output_data
.x
->toolbar_widget
== 0)
1060 /* Make sure next redisplay shows the tool bar. */
1061 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= 1;
1062 update_frame_tool_bar (f
);
1066 if (FRAME_EXTERNAL_TOOL_BAR (f
))
1067 free_frame_tool_bar (f
);
1068 FRAME_EXTERNAL_TOOL_BAR (f
) = 0;
1071 #else /* !USE_GTK */
1073 /* Make sure we redisplay all windows in this frame. */
1074 ++windows_or_buffers_changed
;
1076 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1078 /* Don't resize the tool-bar to more than we have room for. */
1079 root_window
= FRAME_ROOT_WINDOW (f
);
1080 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1081 if (root_height
- delta
< 1)
1083 delta
= root_height
- 1;
1084 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1087 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1088 resize_frame_windows (f
, FRAME_LINES (f
), 0);
1089 adjust_frame_glyphs (f
);
1091 /* We also have to make sure that the internal border at the top of
1092 the frame, below the menu bar or tool bar, is redrawn when the
1093 tool bar disappears. This is so because the internal border is
1094 below the tool bar if one is displayed, but is below the menu bar
1095 if there isn't a tool bar. The tool bar draws into the area
1096 below the menu bar. */
1097 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1100 clear_current_matrices (f
);
1103 /* If the tool bar gets smaller, the internal border below it
1104 has to be cleared. It was formerly part of the display
1105 of the larger tool bar, and updating windows won't clear it. */
1108 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1109 int width
= FRAME_PIXEL_WIDTH (f
);
1110 int y
= (FRAME_MENU_BAR_LINES (f
) + nlines
) * FRAME_LINE_HEIGHT (f
);
1112 /* height can be zero here. */
1113 if (height
> 0 && width
> 0)
1116 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1117 0, y
, width
, height
);
1121 if (WINDOWP (f
->tool_bar_window
))
1122 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1125 run_window_configuration_change_hook (f
);
1126 #endif /* USE_GTK */
1130 /* Set the foreground color for scroll bars on frame F to VALUE.
1131 VALUE should be a string, a color name. If it isn't a string or
1132 isn't a valid color name, do nothing. OLDVAL is the old value of
1133 the frame parameter. */
1136 x_set_scroll_bar_foreground (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1138 unsigned long pixel
;
1140 if (STRINGP (value
))
1141 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
1145 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
1146 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
1148 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
1149 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1151 /* Remove all scroll bars because they have wrong colors. */
1152 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1153 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1154 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1155 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1157 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
1163 /* Set the background color for scroll bars on frame F to VALUE VALUE
1164 should be a string, a color name. If it isn't a string or isn't a
1165 valid color name, do nothing. OLDVAL is the old value of the frame
1169 x_set_scroll_bar_background (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1171 unsigned long pixel
;
1173 if (STRINGP (value
))
1174 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
1178 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
1179 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
1181 #ifdef USE_TOOLKIT_SCROLL_BARS
1182 /* Scrollbar shadow colors. */
1183 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
1185 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
1186 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
1188 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
1190 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
1191 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
1193 #endif /* USE_TOOLKIT_SCROLL_BARS */
1195 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
1196 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1198 /* Remove all scroll bars because they have wrong colors. */
1199 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1200 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1201 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1202 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1204 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
1210 /* Encode Lisp string STRING as a text in a format appropriate for
1211 XICCC (X Inter Client Communication Conventions).
1213 This can call Lisp code, so callers must GCPRO.
1215 If STRING contains only ASCII characters, do no conversion and
1216 return the string data of STRING. Otherwise, encode the text by
1217 CODING_SYSTEM, and return a newly allocated memory area which
1218 should be freed by `xfree' by a caller.
1220 SELECTIONP non-zero means the string is being encoded for an X
1221 selection, so it is safe to run pre-write conversions (which
1224 Store the byte length of resulting text in *TEXT_BYTES.
1226 If the text contains only ASCII and Latin-1, store 1 in *STRING_P,
1227 which means that the `encoding' of the result can be `STRING'.
1228 Otherwise store 0 in *STRINGP, which means that the `encoding' of
1229 the result should be `COMPOUND_TEXT'. */
1231 static unsigned char *
1232 x_encode_text (Lisp_Object string
, Lisp_Object coding_system
, int selectionp
,
1233 ptrdiff_t *text_bytes
, int *stringp
, int *freep
)
1235 int result
= string_xstring_p (string
);
1236 struct coding_system coding
;
1240 /* No multibyte character in OBJ. We need not encode it. */
1241 *text_bytes
= SBYTES (string
);
1244 return SDATA (string
);
1247 setup_coding_system (coding_system
, &coding
);
1248 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
1249 /* We suppress producing escape sequences for composition. */
1250 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
1251 coding
.destination
= xnmalloc (SCHARS (string
), 2);
1252 coding
.dst_bytes
= SCHARS (string
) * 2;
1253 encode_coding_object (&coding
, string
, 0, 0,
1254 SCHARS (string
), SBYTES (string
), Qnil
);
1255 *text_bytes
= coding
.produced
;
1256 *stringp
= (result
== 1 || !EQ (coding_system
, Qcompound_text
));
1258 return coding
.destination
;
1262 /* Set the WM name to NAME for frame F. Also set the icon name.
1263 If the frame already has an icon name, use that, otherwise set the
1264 icon name to NAME. */
1267 x_set_name_internal (struct frame
*f
, Lisp_Object name
)
1269 if (FRAME_X_WINDOW (f
))
1273 XTextProperty text
, icon
;
1276 int do_free_icon_value
= 0, do_free_text_value
= 0;
1277 Lisp_Object coding_system
;
1278 Lisp_Object encoded_name
;
1279 Lisp_Object encoded_icon_name
;
1280 struct gcpro gcpro1
;
1282 /* As ENCODE_UTF_8 may cause GC and relocation of string data,
1283 we use it before x_encode_text that may return string data. */
1285 encoded_name
= ENCODE_UTF_8 (name
);
1288 coding_system
= Qcompound_text
;
1289 /* Note: Encoding strategy
1291 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1292 text.encoding. But, there are non-internationalized window
1293 managers which don't support that encoding. So, if NAME
1294 contains only ASCII and 8859-1 characters, encode it by
1295 iso-latin-1, and use "STRING" in text.encoding hoping that
1296 such window managers at least analyze this format correctly,
1297 i.e. treat 8-bit bytes as 8859-1 characters.
1299 We may also be able to use "UTF8_STRING" in text.encoding
1300 in the future which can encode all Unicode characters.
1301 But, for the moment, there's no way to know that the
1302 current window manager supports it or not.
1304 Either way, we also set the _NET_WM_NAME and _NET_WM_ICON_NAME
1305 properties. Per the EWMH specification, those two properties
1306 are always UTF8_STRING. This matches what gtk_window_set_title()
1307 does in the USE_GTK case. */
1308 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
,
1309 &do_free_text_value
);
1310 text
.encoding
= (stringp
? XA_STRING
1311 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1313 text
.nitems
= bytes
;
1314 if (text
.nitems
!= bytes
)
1315 error ("Window name too large");
1317 if (!STRINGP (f
->icon_name
))
1320 encoded_icon_name
= encoded_name
;
1324 /* See the above comment "Note: Encoding strategy". */
1325 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
1326 &bytes
, &stringp
, &do_free_icon_value
);
1327 icon
.encoding
= (stringp
? XA_STRING
1328 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1330 icon
.nitems
= bytes
;
1331 if (icon
.nitems
!= bytes
)
1332 error ("Icon name too large");
1334 encoded_icon_name
= ENCODE_UTF_8 (f
->icon_name
);
1338 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1339 SSDATA (encoded_name
));
1340 #else /* not USE_GTK */
1341 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1342 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1343 FRAME_X_DISPLAY_INFO (f
)->Xatom_net_wm_name
,
1344 FRAME_X_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1346 SDATA (encoded_name
),
1347 SBYTES (encoded_name
));
1348 #endif /* not USE_GTK */
1350 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &icon
);
1351 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1352 FRAME_X_DISPLAY_INFO (f
)->Xatom_net_wm_icon_name
,
1353 FRAME_X_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1355 SDATA (encoded_icon_name
),
1356 SBYTES (encoded_icon_name
));
1358 if (do_free_icon_value
)
1360 if (do_free_text_value
)
1367 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1370 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1371 name; if NAME is a string, set F's name to NAME and set
1372 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1374 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1375 suggesting a new name, which lisp code should override; if
1376 F->explicit_name is set, ignore the new name; otherwise, set it. */
1379 x_set_name (struct frame
*f
, Lisp_Object name
, int explicit)
1381 /* Make sure that requests from lisp code override requests from
1382 Emacs redisplay code. */
1385 /* If we're switching from explicit to implicit, we had better
1386 update the mode lines and thereby update the title. */
1387 if (f
->explicit_name
&& NILP (name
))
1388 update_mode_lines
= 1;
1390 f
->explicit_name
= ! NILP (name
);
1392 else if (f
->explicit_name
)
1395 /* If NAME is nil, set the name to the x_id_name. */
1398 /* Check for no change needed in this very common case
1399 before we do any consing. */
1400 if (!strcmp (FRAME_X_DISPLAY_INFO (f
)->x_id_name
,
1403 name
= build_string (FRAME_X_DISPLAY_INFO (f
)->x_id_name
);
1406 CHECK_STRING (name
);
1408 /* Don't change the name if it's already NAME. */
1409 if (! NILP (Fstring_equal (name
, f
->name
)))
1412 fset_name (f
, name
);
1414 /* For setting the frame title, the title parameter should override
1415 the name parameter. */
1416 if (! NILP (f
->title
))
1419 x_set_name_internal (f
, name
);
1422 /* This function should be called when the user's lisp code has
1423 specified a name for the frame; the name will override any set by the
1426 x_explicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1428 x_set_name (f
, arg
, 1);
1431 /* This function should be called by Emacs redisplay code to set the
1432 name; names set this way will never override names set by the user's
1435 x_implicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1437 x_set_name (f
, arg
, 0);
1440 /* Change the title of frame F to NAME.
1441 If NAME is nil, use the frame name as the title. */
1444 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1446 /* Don't change the title if it's already NAME. */
1447 if (EQ (name
, f
->title
))
1450 update_mode_lines
= 1;
1452 fset_title (f
, name
);
1457 CHECK_STRING (name
);
1459 x_set_name_internal (f
, name
);
1463 x_set_scroll_bar_default_width (struct frame
*f
)
1465 int wid
= FRAME_COLUMN_WIDTH (f
);
1466 #ifdef USE_TOOLKIT_SCROLL_BARS
1468 int minw
= xg_get_default_scrollbar_width ();
1472 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1473 int width
= minw
+ 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1474 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (width
+ wid
- 1) / wid
;
1475 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = width
;
1477 /* Make the actual width at least 14 pixels and a multiple of a
1479 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
1481 /* Use all of that space (aside from required margins) for the
1483 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = 0;
1488 /* Record in frame F the specified or default value according to ALIST
1489 of the parameter named PROP (a Lisp symbol). If no value is
1490 specified for PROP, look for an X default for XPROP on the frame
1491 named NAME. If that is not found either, use the value DEFLT. */
1494 x_default_scroll_bar_color_parameter (struct frame
*f
,
1495 Lisp_Object alist
, Lisp_Object prop
,
1496 const char *xprop
, const char *xclass
,
1499 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1502 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
1503 if (EQ (tem
, Qunbound
))
1505 #ifdef USE_TOOLKIT_SCROLL_BARS
1507 /* See if an X resource for the scroll bar color has been
1509 tem
= display_x_get_resource (dpyinfo
,
1510 build_string (foreground_p
1513 empty_unibyte_string
,
1514 build_string ("verticalScrollBar"),
1515 empty_unibyte_string
);
1518 /* If nothing has been specified, scroll bars will use a
1519 toolkit-dependent default. Because these defaults are
1520 difficult to get at without actually creating a scroll
1521 bar, use nil to indicate that no color has been
1526 #else /* not USE_TOOLKIT_SCROLL_BARS */
1530 #endif /* not USE_TOOLKIT_SCROLL_BARS */
1533 x_set_frame_parameters (f
, list1 (Fcons (prop
, tem
)));
1540 #ifdef USE_X_TOOLKIT
1542 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
1543 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
1544 already be present because of the toolkit (Motif adds some of them,
1545 for example, but Xt doesn't). */
1548 hack_wm_protocols (struct frame
*f
, Widget widget
)
1550 Display
*dpy
= XtDisplay (widget
);
1551 Window w
= XtWindow (widget
);
1552 int need_delete
= 1;
1559 unsigned char *catoms
;
1561 unsigned long nitems
= 0;
1562 unsigned long bytes_after
;
1564 if ((XGetWindowProperty (dpy
, w
,
1565 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1566 (long)0, (long)100, False
, XA_ATOM
,
1567 &type
, &format
, &nitems
, &bytes_after
,
1570 && format
== 32 && type
== XA_ATOM
)
1572 Atom
*atoms
= (Atom
*) catoms
;
1577 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
1579 else if (atoms
[nitems
]
1580 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
1582 else if (atoms
[nitems
]
1583 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
1594 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
1596 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
1598 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
1600 XChangeProperty (dpy
, w
, FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1601 XA_ATOM
, 32, PropModeAppend
,
1602 (unsigned char *) props
, count
);
1610 /* Support routines for XIC (X Input Context). */
1614 static XFontSet
xic_create_xfontset (struct frame
*);
1615 static XIMStyle
best_xim_style (XIMStyles
*, XIMStyles
*);
1618 /* Supported XIM styles, ordered by preference. */
1620 static XIMStyle supported_xim_styles
[] =
1622 XIMPreeditPosition
| XIMStatusArea
,
1623 XIMPreeditPosition
| XIMStatusNothing
,
1624 XIMPreeditPosition
| XIMStatusNone
,
1625 XIMPreeditNothing
| XIMStatusArea
,
1626 XIMPreeditNothing
| XIMStatusNothing
,
1627 XIMPreeditNothing
| XIMStatusNone
,
1628 XIMPreeditNone
| XIMStatusArea
,
1629 XIMPreeditNone
| XIMStatusNothing
,
1630 XIMPreeditNone
| XIMStatusNone
,
1635 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1636 /* Create an X fontset on frame F with base font name BASE_FONTNAME. */
1638 static const char xic_default_fontset
[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
1640 /* Create an Xt fontset spec from the name of a base font.
1641 If `motif' is True use the Motif syntax. */
1643 xic_create_fontsetname (const char *base_fontname
, int motif
)
1645 const char *sep
= motif
? ";" : ",";
1648 /* Make a fontset name from the base font name. */
1649 if (xic_default_fontset
== base_fontname
)
1651 /* There is no base font name, use the default. */
1652 fontsetname
= xmalloc (strlen (base_fontname
) + 2);
1653 strcpy (fontsetname
, base_fontname
);
1657 /* Make a fontset name from the base font name.
1658 The font set will be made of the following elements:
1660 - the base font where the charset spec is replaced by -*-*.
1661 - the same but with the family also replaced with -*-*-. */
1662 const char *p
= base_fontname
;
1665 for (i
= 0; *p
; p
++)
1669 /* As the font name doesn't conform to XLFD, we can't
1670 modify it to generalize it to allcs and allfamilies.
1671 Use the specified font plus the default. */
1672 fontsetname
= xmalloc (strlen (base_fontname
)
1673 + strlen (xic_default_fontset
) + 3);
1674 strcpy (fontsetname
, base_fontname
);
1675 strcat (fontsetname
, sep
);
1676 strcat (fontsetname
, xic_default_fontset
);
1681 const char *p1
= NULL
, *p2
= NULL
, *p3
= NULL
;
1682 char *font_allcs
= NULL
;
1683 char *font_allfamilies
= NULL
;
1684 char *font_all
= NULL
;
1685 const char *allcs
= "*-*-*-*-*-*-*";
1686 const char *allfamilies
= "-*-*-";
1687 const char *all
= "*-*-*-*-";
1690 for (i
= 0, p
= base_fontname
; i
< 8; p
++)
1703 /* If base_fontname specifies ADSTYLE, make it a
1707 ptrdiff_t diff
= (p2
- p3
) - 2;
1709 base
= alloca (strlen (base_fontname
) + 1);
1710 memcpy (base
, base_fontname
, p3
- base_fontname
);
1711 base
[p3
- base_fontname
] = '*';
1712 base
[(p3
- base_fontname
) + 1] = '-';
1713 strcpy (base
+ (p3
- base_fontname
) + 2, p2
);
1714 p
= base
+ (p
- base_fontname
) - diff
;
1715 p1
= base
+ (p1
- base_fontname
);
1716 p2
= base
+ (p2
- base_fontname
) - diff
;
1717 base_fontname
= base
;
1720 /* Build the font spec that matches all charsets. */
1721 len
= p
- base_fontname
+ strlen (allcs
) + 1;
1722 font_allcs
= alloca (len
);
1723 memcpy (font_allcs
, base_fontname
, p
- base_fontname
);
1724 strcat (font_allcs
, allcs
);
1726 /* Build the font spec that matches all families and
1728 len
= p
- p1
+ strlen (allcs
) + strlen (allfamilies
) + 1;
1729 font_allfamilies
= alloca (len
);
1730 strcpy (font_allfamilies
, allfamilies
);
1731 memcpy (font_allfamilies
+ strlen (allfamilies
), p1
, p
- p1
);
1732 strcat (font_allfamilies
, allcs
);
1734 /* Build the font spec that matches all. */
1735 len
= p
- p2
+ strlen (allcs
) + strlen (all
) + strlen (allfamilies
) + 1;
1736 font_all
= alloca (len
);
1737 strcpy (font_all
, allfamilies
);
1738 strcat (font_all
, all
);
1739 memcpy (font_all
+ strlen (all
) + strlen (allfamilies
), p2
, p
- p2
);
1740 strcat (font_all
, allcs
);
1742 /* Build the actual font set name. */
1743 len
= strlen (base_fontname
) + strlen (font_allcs
)
1744 + strlen (font_allfamilies
) + strlen (font_all
) + 5;
1745 fontsetname
= xmalloc (len
);
1746 strcpy (fontsetname
, base_fontname
);
1747 strcat (fontsetname
, sep
);
1748 strcat (fontsetname
, font_allcs
);
1749 strcat (fontsetname
, sep
);
1750 strcat (fontsetname
, font_allfamilies
);
1751 strcat (fontsetname
, sep
);
1752 strcat (fontsetname
, font_all
);
1756 strcat (fontsetname
, ":");
1759 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
1761 #ifdef DEBUG_XIC_FONTSET
1763 print_fontset_result (XFontSet xfs
, char *name
, char **missing_list
,
1767 fprintf (stderr
, "XIC Fontset created: %s\n", name
);
1770 fprintf (stderr
, "XIC Fontset failed: %s\n", name
);
1771 while (missing_count
-- > 0)
1773 fprintf (stderr
, " missing: %s\n", *missing_list
);
1782 xic_create_xfontset (struct frame
*f
)
1784 XFontSet xfs
= NULL
;
1785 struct font
*font
= FRAME_FONT (f
);
1786 int pixel_size
= font
->pixel_size
;
1787 Lisp_Object rest
, frame
;
1789 /* See if there is another frame already using same fontset. */
1790 FOR_EACH_FRAME (rest
, frame
)
1792 struct frame
*cf
= XFRAME (frame
);
1794 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
1795 && FRAME_X_DISPLAY_INFO (cf
) == FRAME_X_DISPLAY_INFO (f
)
1797 && FRAME_FONT (f
)->pixel_size
== pixel_size
)
1799 xfs
= FRAME_XIC_FONTSET (cf
);
1807 char **missing_list
;
1810 const char *xlfd_format
= "-*-*-medium-r-normal--%d-*-*-*-*-*";
1812 sprintf (buf
, xlfd_format
, pixel_size
);
1813 missing_list
= NULL
;
1814 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
1815 &missing_list
, &missing_count
, &def_string
);
1816 #ifdef DEBUG_XIC_FONTSET
1817 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
1820 XFreeStringList (missing_list
);
1823 /* List of pixel sizes most likely available. Find one that
1824 is closest to pixel_size. */
1825 int sizes
[] = {0, 8, 10, 11, 12, 14, 17, 18, 20, 24, 26, 34, 0};
1826 int *smaller
, *larger
;
1828 for (smaller
= sizes
; smaller
[1]; smaller
++)
1829 if (smaller
[1] >= pixel_size
)
1831 larger
= smaller
+ 1;
1832 if (*larger
== pixel_size
)
1834 while (*smaller
|| *larger
)
1839 this_size
= *smaller
--;
1840 else if (! *smaller
)
1841 this_size
= *larger
++;
1842 else if (pixel_size
- *smaller
< *larger
- pixel_size
)
1843 this_size
= *smaller
--;
1845 this_size
= *larger
++;
1846 sprintf (buf
, xlfd_format
, this_size
);
1847 missing_list
= NULL
;
1848 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
1849 &missing_list
, &missing_count
, &def_string
);
1850 #ifdef DEBUG_XIC_FONTSET
1851 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
1854 XFreeStringList (missing_list
);
1861 const char *last_resort
= "-*-*-*-r-normal--*-*-*-*-*-*";
1863 missing_list
= NULL
;
1864 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), last_resort
,
1865 &missing_list
, &missing_count
, &def_string
);
1866 #ifdef DEBUG_XIC_FONTSET
1867 print_fontset_result (xfs
, last_resort
, missing_list
, missing_count
);
1870 XFreeStringList (missing_list
);
1878 /* Free the X fontset of frame F if it is the last frame using it. */
1881 xic_free_xfontset (struct frame
*f
)
1883 Lisp_Object rest
, frame
;
1886 if (!FRAME_XIC_FONTSET (f
))
1889 /* See if there is another frame sharing the same fontset. */
1890 FOR_EACH_FRAME (rest
, frame
)
1892 struct frame
*cf
= XFRAME (frame
);
1893 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
1894 && FRAME_X_DISPLAY_INFO (cf
) == FRAME_X_DISPLAY_INFO (f
)
1895 && FRAME_XIC_FONTSET (cf
) == FRAME_XIC_FONTSET (f
))
1903 /* The fontset is not used anymore. It is safe to free it. */
1904 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
1906 FRAME_XIC_FONTSET (f
) = NULL
;
1910 /* Value is the best input style, given user preferences USER (already
1911 checked to be supported by Emacs), and styles supported by the
1912 input method XIM. */
1915 best_xim_style (XIMStyles
*user
, XIMStyles
*xim
)
1919 for (i
= 0; i
< user
->count_styles
; ++i
)
1920 for (j
= 0; j
< xim
->count_styles
; ++j
)
1921 if (user
->supported_styles
[i
] == xim
->supported_styles
[j
])
1922 return user
->supported_styles
[i
];
1924 /* Return the default style. */
1925 return XIMPreeditNothing
| XIMStatusNothing
;
1928 /* Create XIC for frame F. */
1930 static XIMStyle xic_style
;
1933 create_frame_xic (struct frame
*f
)
1937 XFontSet xfs
= NULL
;
1942 /* Create X fontset. */
1943 xfs
= xic_create_xfontset (f
);
1944 xim
= FRAME_X_XIM (f
);
1949 XVaNestedList preedit_attr
;
1950 XVaNestedList status_attr
;
1952 s_area
.x
= 0; s_area
.y
= 0; s_area
.width
= 1; s_area
.height
= 1;
1953 spot
.x
= 0; spot
.y
= 1;
1955 /* Determine XIC style. */
1958 XIMStyles supported_list
;
1959 supported_list
.count_styles
= (sizeof supported_xim_styles
1960 / sizeof supported_xim_styles
[0]);
1961 supported_list
.supported_styles
= supported_xim_styles
;
1962 xic_style
= best_xim_style (&supported_list
,
1963 FRAME_X_XIM_STYLES (f
));
1966 preedit_attr
= XVaCreateNestedList (0,
1969 FRAME_FOREGROUND_PIXEL (f
),
1971 FRAME_BACKGROUND_PIXEL (f
),
1972 (xic_style
& XIMPreeditPosition
1977 status_attr
= XVaCreateNestedList (0,
1983 FRAME_FOREGROUND_PIXEL (f
),
1985 FRAME_BACKGROUND_PIXEL (f
),
1988 xic
= XCreateIC (xim
,
1989 XNInputStyle
, xic_style
,
1990 XNClientWindow
, FRAME_X_WINDOW (f
),
1991 XNFocusWindow
, FRAME_X_WINDOW (f
),
1992 XNStatusAttributes
, status_attr
,
1993 XNPreeditAttributes
, preedit_attr
,
1995 XFree (preedit_attr
);
1996 XFree (status_attr
);
1999 FRAME_XIC (f
) = xic
;
2000 FRAME_XIC_STYLE (f
) = xic_style
;
2001 FRAME_XIC_FONTSET (f
) = xfs
;
2005 /* Destroy XIC and free XIC fontset of frame F, if any. */
2008 free_frame_xic (struct frame
*f
)
2010 if (FRAME_XIC (f
) == NULL
)
2013 XDestroyIC (FRAME_XIC (f
));
2014 xic_free_xfontset (f
);
2016 FRAME_XIC (f
) = NULL
;
2020 /* Place preedit area for XIC of window W's frame to specified
2021 pixel position X/Y. X and Y are relative to window W. */
2024 xic_set_preeditarea (struct window
*w
, int x
, int y
)
2026 struct frame
*f
= XFRAME (w
->frame
);
2030 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
) + WINDOW_LEFT_FRINGE_WIDTH (w
);
2031 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
2032 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
2033 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2038 /* Place status area for XIC in bottom right corner of frame F.. */
2041 xic_set_statusarea (struct frame
*f
)
2043 XIC xic
= FRAME_XIC (f
);
2048 /* Negotiate geometry of status area. If input method has existing
2049 status area, use its current size. */
2050 area
.x
= area
.y
= area
.width
= area
.height
= 0;
2051 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
2052 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2055 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
2056 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2059 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
2061 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
2062 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2066 area
.width
= needed
->width
;
2067 area
.height
= needed
->height
;
2068 area
.x
= FRAME_PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
2069 area
.y
= (FRAME_PIXEL_HEIGHT (f
) - area
.height
2070 - FRAME_MENUBAR_HEIGHT (f
)
2071 - FRAME_TOOLBAR_TOP_HEIGHT (f
)
2072 - FRAME_INTERNAL_BORDER_WIDTH (f
));
2075 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
2076 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2081 /* Set X fontset for XIC of frame F, using base font name
2082 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2085 xic_set_xfontset (struct frame
*f
, const char *base_fontname
)
2090 xic_free_xfontset (f
);
2092 xfs
= xic_create_xfontset (f
);
2094 attr
= XVaCreateNestedList (0, XNFontSet
, xfs
, NULL
);
2095 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
2096 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2097 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
2098 XSetICValues (FRAME_XIC (f
), XNStatusAttributes
, attr
, NULL
);
2101 FRAME_XIC_FONTSET (f
) = xfs
;
2104 #endif /* HAVE_X_I18N */
2108 #ifdef USE_X_TOOLKIT
2110 /* Create and set up the X widget for frame F. */
2113 x_window (struct frame
*f
, long window_prompting
, int minibuffer_only
)
2115 XClassHint class_hints
;
2116 XSetWindowAttributes attributes
;
2117 unsigned long attribute_mask
;
2118 Widget shell_widget
;
2120 Widget frame_widget
;
2126 /* Use the resource name as the top-level widget name
2127 for looking up resources. Make a non-Lisp copy
2128 for the window manager, so GC relocation won't bother it.
2130 Elsewhere we specify the window name for the window manager. */
2131 f
->namebuf
= xstrdup (SSDATA (Vx_resource_name
));
2134 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2135 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2136 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2137 XtSetArg (al
[ac
], XtNborderWidth
, f
->border_width
); ac
++;
2138 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2139 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2140 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2141 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2142 applicationShellWidgetClass
,
2143 FRAME_X_DISPLAY (f
), al
, ac
);
2145 f
->output_data
.x
->widget
= shell_widget
;
2146 /* maybe_set_screen_title_format (shell_widget); */
2148 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2149 NULL
, shell_widget
, False
,
2150 NULL
, NULL
, NULL
, NULL
);
2153 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2154 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2155 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2156 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2157 XtSetValues (pane_widget
, al
, ac
);
2158 f
->output_data
.x
->column_widget
= pane_widget
;
2160 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2161 the emacs screen when changing menubar. This reduces flickering. */
2164 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2165 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2166 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2167 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2168 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2169 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2170 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2171 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2172 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2173 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
2176 f
->output_data
.x
->edit_widget
= frame_widget
;
2178 XtManageChild (frame_widget
);
2180 /* Do some needed geometry management. */
2182 char *tem
, shell_position
[sizeof "=x++" + 4 * INT_STRLEN_BOUND (int)];
2185 int extra_borders
= 0;
2187 = (f
->output_data
.x
->menubar_widget
2188 ? (f
->output_data
.x
->menubar_widget
->core
.height
2189 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
2192 #if 0 /* Experimentally, we now get the right results
2193 for -geometry -0-0 without this. 24 Aug 96, rms. */
2194 if (FRAME_EXTERNAL_MENU_BAR (f
))
2197 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2198 menubar_size
+= ibw
;
2202 f
->output_data
.x
->menubar_height
= menubar_size
;
2205 /* Motif seems to need this amount added to the sizes
2206 specified for the shell widget. The Athena/Lucid widgets don't.
2207 Both conclusions reached experimentally. -- rms. */
2208 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
2209 &extra_borders
, NULL
);
2213 /* Convert our geometry parameters into a geometry string
2215 Note that we do not specify here whether the position
2216 is a user-specified or program-specified one.
2217 We pass that information later, in x_wm_set_size_hints. */
2219 int left
= f
->left_pos
;
2220 int xneg
= window_prompting
& XNegative
;
2221 int top
= f
->top_pos
;
2222 int yneg
= window_prompting
& YNegative
;
2228 if (window_prompting
& USPosition
)
2229 sprintf (shell_position
, "=%dx%d%c%d%c%d",
2230 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2231 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
2232 (xneg
? '-' : '+'), left
,
2233 (yneg
? '-' : '+'), top
);
2236 sprintf (shell_position
, "=%dx%d",
2237 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2238 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
2240 /* Setting x and y when the position is not specified in
2241 the geometry string will set program position in the WM hints.
2242 If Emacs had just one program position, we could set it in
2243 fallback resources, but since each make-frame call can specify
2244 different program positions, this is easier. */
2245 XtSetArg (gal
[gac
], XtNx
, left
); gac
++;
2246 XtSetArg (gal
[gac
], XtNy
, top
); gac
++;
2250 /* We don't free this because we don't know whether
2251 it is safe to free it while the frame exists.
2252 It isn't worth the trouble of arranging to free it
2253 when the frame is deleted. */
2254 tem
= xstrdup (shell_position
);
2255 XtSetArg (gal
[gac
], XtNgeometry
, tem
); gac
++;
2256 XtSetValues (shell_widget
, gal
, gac
);
2259 XtManageChild (pane_widget
);
2260 XtRealizeWidget (shell_widget
);
2262 if (FRAME_X_EMBEDDED_P (f
))
2263 XReparentWindow (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
),
2264 f
->output_data
.x
->parent_desc
, 0, 0);
2266 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2268 validate_x_resource_name ();
2270 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2271 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2272 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2275 FRAME_XIC (f
) = NULL
;
2277 create_frame_xic (f
);
2280 f
->output_data
.x
->wm_hints
.input
= True
;
2281 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2282 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2283 &f
->output_data
.x
->wm_hints
);
2285 hack_wm_protocols (f
, shell_widget
);
2288 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2291 /* Do a stupid property change to force the server to generate a
2292 PropertyNotify event so that the event_stream server timestamp will
2293 be initialized to something relevant to the time we created the window.
2295 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2296 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2297 XA_ATOM
, 32, PropModeAppend
, NULL
, 0);
2299 /* Make all the standard events reach the Emacs frame. */
2300 attributes
.event_mask
= STANDARD_EVENT_SET
;
2305 /* XIM server might require some X events. */
2306 unsigned long fevent
= NoEventMask
;
2307 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2308 attributes
.event_mask
|= fevent
;
2310 #endif /* HAVE_X_I18N */
2312 attribute_mask
= CWEventMask
;
2313 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2314 attribute_mask
, &attributes
);
2316 XtMapWidget (frame_widget
);
2318 /* x_set_name normally ignores requests to set the name if the
2319 requested name is the same as the current name. This is the one
2320 place where that assumption isn't correct; f->name is set, but
2321 the X server hasn't been told. */
2324 int explicit = f
->explicit_name
;
2326 f
->explicit_name
= 0;
2328 fset_name (f
, Qnil
);
2329 x_set_name (f
, name
, explicit);
2332 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2333 f
->output_data
.x
->current_cursor
2334 = f
->output_data
.x
->text_cursor
);
2338 /* This is a no-op, except under Motif. Make sure main areas are
2339 set to something reasonable, in case we get an error later. */
2340 lw_set_main_areas (pane_widget
, 0, frame_widget
);
2343 #else /* not USE_X_TOOLKIT */
2346 x_window (struct frame
*f
)
2348 if (! xg_create_frame_widgets (f
))
2349 error ("Unable to create window");
2352 FRAME_XIC (f
) = NULL
;
2356 create_frame_xic (f
);
2359 /* XIM server might require some X events. */
2360 unsigned long fevent
= NoEventMask
;
2361 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2363 if (fevent
!= NoEventMask
)
2365 XSetWindowAttributes attributes
;
2366 XWindowAttributes wattr
;
2367 unsigned long attribute_mask
;
2369 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2371 attributes
.event_mask
= wattr
.your_event_mask
| fevent
;
2372 attribute_mask
= CWEventMask
;
2373 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2374 attribute_mask
, &attributes
);
2382 #else /*! USE_GTK */
2383 /* Create and set up the X window for frame F. */
2386 x_window (struct frame
*f
)
2388 XClassHint class_hints
;
2389 XSetWindowAttributes attributes
;
2390 unsigned long attribute_mask
;
2392 attributes
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2393 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
2394 attributes
.bit_gravity
= StaticGravity
;
2395 attributes
.backing_store
= NotUseful
;
2396 attributes
.save_under
= True
;
2397 attributes
.event_mask
= STANDARD_EVENT_SET
;
2398 attributes
.colormap
= FRAME_X_COLORMAP (f
);
2399 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
2404 = XCreateWindow (FRAME_X_DISPLAY (f
),
2405 f
->output_data
.x
->parent_desc
,
2408 FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
),
2410 CopyFromParent
, /* depth */
2411 InputOutput
, /* class */
2413 attribute_mask
, &attributes
);
2418 create_frame_xic (f
);
2421 /* XIM server might require some X events. */
2422 unsigned long fevent
= NoEventMask
;
2423 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2424 attributes
.event_mask
|= fevent
;
2425 attribute_mask
= CWEventMask
;
2426 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2427 attribute_mask
, &attributes
);
2430 #endif /* HAVE_X_I18N */
2432 validate_x_resource_name ();
2434 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2435 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2436 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2438 /* The menubar is part of the ordinary display;
2439 it does not count in addition to the height of the window. */
2440 f
->output_data
.x
->menubar_height
= 0;
2442 /* This indicates that we use the "Passive Input" input model.
2443 Unless we do this, we don't get the Focus{In,Out} events that we
2444 need to draw the cursor correctly. Accursed bureaucrats.
2445 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2447 f
->output_data
.x
->wm_hints
.input
= True
;
2448 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2449 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2450 &f
->output_data
.x
->wm_hints
);
2451 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
2453 /* Request "save yourself" and "delete window" commands from wm. */
2456 protocols
[0] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2457 protocols
[1] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2458 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2461 /* x_set_name normally ignores requests to set the name if the
2462 requested name is the same as the current name. This is the one
2463 place where that assumption isn't correct; f->name is set, but
2464 the X server hasn't been told. */
2467 int explicit = f
->explicit_name
;
2469 f
->explicit_name
= 0;
2471 fset_name (f
, Qnil
);
2472 x_set_name (f
, name
, explicit);
2475 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2476 f
->output_data
.x
->current_cursor
2477 = f
->output_data
.x
->text_cursor
);
2481 if (FRAME_X_WINDOW (f
) == 0)
2482 error ("Unable to create window");
2485 #endif /* not USE_GTK */
2486 #endif /* not USE_X_TOOLKIT */
2488 /* Verify that the icon position args for this window are valid. */
2491 x_icon_verify (struct frame
*f
, Lisp_Object parms
)
2493 Lisp_Object icon_x
, icon_y
;
2495 /* Set the position of the icon. Note that twm groups all
2496 icons in an icon window. */
2497 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2498 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2499 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2501 CHECK_NUMBER (icon_x
);
2502 CHECK_NUMBER (icon_y
);
2504 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2505 error ("Both left and top icon corners of icon must be specified");
2508 /* Handle the icon stuff for this window. Perhaps later we might
2509 want an x_set_icon_position which can be called interactively as
2513 x_icon (struct frame
*f
, Lisp_Object parms
)
2515 Lisp_Object icon_x
, icon_y
;
2517 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2520 /* Set the position of the icon. Note that twm groups all
2521 icons in an icon window. */
2522 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2523 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2524 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2526 CHECK_TYPE_RANGED_INTEGER (int, icon_x
);
2527 CHECK_TYPE_RANGED_INTEGER (int, icon_y
);
2529 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2530 error ("Both left and top icon corners of icon must be specified");
2534 if (! EQ (icon_x
, Qunbound
))
2535 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2537 #if 0 /* x_get_arg removes the visibility parameter as a side effect,
2538 but x_create_frame still needs it. */
2539 /* Start up iconic or window? */
2540 x_wm_set_window_state
2541 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
2547 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
2554 /* Make the GCs needed for this window, setting the
2555 background, border and mouse colors; also create the
2556 mouse cursor and the gray border tile. */
2559 x_make_gc (struct frame
*f
)
2561 XGCValues gc_values
;
2565 /* Create the GCs of this frame.
2566 Note that many default values are used. */
2568 gc_values
.foreground
= FRAME_FOREGROUND_PIXEL (f
);
2569 gc_values
.background
= FRAME_BACKGROUND_PIXEL (f
);
2570 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2571 f
->output_data
.x
->normal_gc
2572 = XCreateGC (FRAME_X_DISPLAY (f
),
2574 GCLineWidth
| GCForeground
| GCBackground
,
2577 /* Reverse video style. */
2578 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2579 gc_values
.background
= FRAME_FOREGROUND_PIXEL (f
);
2580 f
->output_data
.x
->reverse_gc
2581 = XCreateGC (FRAME_X_DISPLAY (f
),
2583 GCForeground
| GCBackground
| GCLineWidth
,
2586 /* Cursor has cursor-color background, background-color foreground. */
2587 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2588 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
2589 gc_values
.fill_style
= FillOpaqueStippled
;
2590 f
->output_data
.x
->cursor_gc
2591 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2592 (GCForeground
| GCBackground
2593 | GCFillStyle
| GCLineWidth
),
2596 /* Create the gray border tile used when the pointer is not in
2597 the frame. Since this depends on the frame's pixel values,
2598 this must be done on a per-frame basis. */
2599 f
->output_data
.x
->border_tile
2600 = (XCreatePixmapFromBitmapData
2601 (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
2602 gray_bits
, gray_width
, gray_height
,
2603 FRAME_FOREGROUND_PIXEL (f
),
2604 FRAME_BACKGROUND_PIXEL (f
),
2605 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
2611 /* Free what was allocated in x_make_gc. */
2614 x_free_gcs (struct frame
*f
)
2616 Display
*dpy
= FRAME_X_DISPLAY (f
);
2620 if (f
->output_data
.x
->normal_gc
)
2622 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
2623 f
->output_data
.x
->normal_gc
= 0;
2626 if (f
->output_data
.x
->reverse_gc
)
2628 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
2629 f
->output_data
.x
->reverse_gc
= 0;
2632 if (f
->output_data
.x
->cursor_gc
)
2634 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
2635 f
->output_data
.x
->cursor_gc
= 0;
2638 if (f
->output_data
.x
->border_tile
)
2640 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
2641 f
->output_data
.x
->border_tile
= 0;
2648 /* Handler for signals raised during x_create_frame and
2649 x_create_tip_frame. FRAME is the frame which is partially
2653 unwind_create_frame (Lisp_Object frame
)
2655 struct frame
*f
= XFRAME (frame
);
2657 /* If frame is already dead, nothing to do. This can happen if the
2658 display is disconnected after the frame has become official, but
2659 before x_create_frame removes the unwind protect. */
2660 if (!FRAME_LIVE_P (f
))
2663 /* If frame is ``official'', nothing to do. */
2664 if (NILP (Fmemq (frame
, Vframe_list
)))
2666 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2667 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2670 x_free_frame_resources (f
);
2673 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2674 /* Check that reference counts are indeed correct. */
2675 eassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
2676 eassert (dpyinfo
->terminal
->image_cache
->refcount
== image_cache_refcount
);
2685 do_unwind_create_frame (Lisp_Object frame
)
2687 unwind_create_frame (frame
);
2691 unwind_create_frame_1 (Lisp_Object val
)
2693 inhibit_lisp_code
= val
;
2697 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
2699 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2700 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
2702 Lisp_Object font
= Qnil
;
2703 if (EQ (font_param
, Qunbound
))
2706 if (NILP (font_param
))
2708 /* System font should take precedence over X resources. We suggest this
2709 regardless of font-use-system-font because .emacs may not have been
2711 const char *system_font
= xsettings_get_system_font ();
2713 font
= font_open_by_name (f
, build_unibyte_string (system_font
));
2717 font
= !NILP (font_param
) ? font_param
2718 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
2720 if (! FONTP (font
) && ! STRINGP (font
))
2725 /* This will find the normal Xft font. */
2728 "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1",
2729 "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2730 "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2731 /* This was formerly the first thing tried, but it finds
2732 too many fonts and takes too long. */
2733 "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1",
2734 /* If those didn't work, look for something which will
2736 "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1",
2741 for (i
= 0; names
[i
]; i
++)
2743 font
= font_open_by_name (f
, build_unibyte_string (names
[i
]));
2748 error ("No suitable font was found");
2750 else if (!NILP (font_param
))
2752 /* Remember the explicit font parameter, so we can re-apply it after
2753 we've applied the `default' face settings. */
2754 x_set_frame_parameters (f
, list1 (Fcons (Qfont_param
, font_param
)));
2757 /* This call will make X resources override any system font setting. */
2758 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
2762 DEFUN ("x-wm-set-size-hint", Fx_wm_set_size_hint
, Sx_wm_set_size_hint
,
2764 doc
: /* Send the size hints for frame FRAME to the window manager.
2765 If FRAME is omitted or nil, use the selected frame.
2766 Signal error if FRAME is not an X frame. */)
2769 struct frame
*f
= decode_window_system_frame (frame
);
2772 x_wm_set_size_hint (f
, 0, 0);
2778 set_machine_and_pid_properties (struct frame
*f
)
2780 long pid
= (long) getpid ();
2782 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME. */
2783 XSetWMProperties (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), NULL
, NULL
,
2784 NULL
, 0, NULL
, NULL
, NULL
);
2785 XChangeProperty (FRAME_X_DISPLAY (f
),
2786 FRAME_OUTER_WINDOW (f
),
2787 XInternAtom (FRAME_X_DISPLAY (f
),
2790 XA_CARDINAL
, 32, PropModeReplace
,
2791 (unsigned char *) &pid
, 1);
2794 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
2796 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
2797 Return an Emacs frame object.
2798 PARMS is an alist of frame parameters.
2799 If the parameters specify that the frame should not have a minibuffer,
2800 and do not specify a specific minibuffer window to use,
2801 then `default-minibuffer-frame' must be a frame whose minibuffer can
2802 be shared by the new frame.
2804 This function is an internal primitive--use `make-frame' instead. */)
2808 Lisp_Object frame
, tem
;
2810 int minibuffer_only
= 0;
2811 long window_prompting
= 0;
2813 ptrdiff_t count
= SPECPDL_INDEX ();
2814 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
2815 Lisp_Object display
;
2816 struct x_display_info
*dpyinfo
= NULL
;
2820 parms
= Fcopy_alist (parms
);
2822 /* Use this general default value to start with
2823 until we know if this frame has a specified name. */
2824 Vx_resource_name
= Vinvocation_name
;
2826 display
= x_get_arg (dpyinfo
, parms
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
2827 if (EQ (display
, Qunbound
))
2828 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
2829 if (EQ (display
, Qunbound
))
2831 dpyinfo
= check_x_display_info (display
);
2832 kb
= dpyinfo
->terminal
->kboard
;
2834 if (!dpyinfo
->terminal
->name
)
2835 error ("Terminal is not live, can't create new frames on it");
2837 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
2839 && ! EQ (name
, Qunbound
)
2841 error ("Invalid frame name--not a string or nil");
2844 Vx_resource_name
= name
;
2846 /* See if parent window is specified. */
2847 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
2848 if (EQ (parent
, Qunbound
))
2850 if (! NILP (parent
))
2851 CHECK_NUMBER (parent
);
2853 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
2854 /* No need to protect DISPLAY because that's not used after passing
2855 it to make_frame_without_minibuffer. */
2857 GCPRO4 (parms
, parent
, name
, frame
);
2858 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
2860 if (EQ (tem
, Qnone
) || NILP (tem
))
2861 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
2862 else if (EQ (tem
, Qonly
))
2864 f
= make_minibuffer_frame ();
2865 minibuffer_only
= 1;
2867 else if (WINDOWP (tem
))
2868 f
= make_frame_without_minibuffer (tem
, kb
, display
);
2872 XSETFRAME (frame
, f
);
2874 f
->terminal
= dpyinfo
->terminal
;
2876 f
->output_method
= output_x_window
;
2877 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
2878 f
->output_data
.x
->icon_bitmap
= -1;
2879 FRAME_FONTSET (f
) = -1;
2880 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
2881 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
2882 #ifdef USE_TOOLKIT_SCROLL_BARS
2883 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
2884 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
2885 #endif /* USE_TOOLKIT_SCROLL_BARS */
2888 x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
2890 if (! STRINGP (f
->icon_name
))
2891 fset_icon_name (f
, Qnil
);
2893 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
2895 /* With FRAME_X_DISPLAY_INFO set up, this unwind-protect is safe. */
2896 record_unwind_protect (do_unwind_create_frame
, frame
);
2898 /* These colors will be set anyway later, but it's important
2899 to get the color reference counts right, so initialize them! */
2902 struct gcpro gcpro1
;
2904 /* Function x_decode_color can signal an error. Make
2905 sure to initialize color slots so that we won't try
2906 to free colors we haven't allocated. */
2907 FRAME_FOREGROUND_PIXEL (f
) = -1;
2908 FRAME_BACKGROUND_PIXEL (f
) = -1;
2909 f
->output_data
.x
->cursor_pixel
= -1;
2910 f
->output_data
.x
->cursor_foreground_pixel
= -1;
2911 f
->output_data
.x
->border_pixel
= -1;
2912 f
->output_data
.x
->mouse_pixel
= -1;
2914 black
= build_string ("black");
2916 FRAME_FOREGROUND_PIXEL (f
)
2917 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2918 FRAME_BACKGROUND_PIXEL (f
)
2919 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2920 f
->output_data
.x
->cursor_pixel
2921 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2922 f
->output_data
.x
->cursor_foreground_pixel
2923 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2924 f
->output_data
.x
->border_pixel
2925 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2926 f
->output_data
.x
->mouse_pixel
2927 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2931 /* Specify the parent under which to make this X window. */
2935 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
2936 f
->output_data
.x
->explicit_parent
= 1;
2940 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
2941 f
->output_data
.x
->explicit_parent
= 0;
2944 /* Set the name; the functions to which we pass f expect the name to
2946 if (EQ (name
, Qunbound
) || NILP (name
))
2948 fset_name (f
, build_string (dpyinfo
->x_id_name
));
2949 f
->explicit_name
= 0;
2953 fset_name (f
, name
);
2954 f
->explicit_name
= 1;
2955 /* use the frame's title when getting resources for this frame. */
2956 specbind (Qx_resource_name
, name
);
2959 #ifdef HAVE_FREETYPE
2961 register_font_driver (&xftfont_driver
, f
);
2962 #else /* not HAVE_XFT */
2963 register_font_driver (&ftxfont_driver
, f
);
2964 #endif /* not HAVE_XFT */
2965 #endif /* HAVE_FREETYPE */
2966 register_font_driver (&xfont_driver
, f
);
2968 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
2969 "fontBackend", "FontBackend", RES_TYPE_STRING
);
2971 /* Extract the window parameters from the supplied values
2972 that are needed to determine window geometry. */
2973 x_default_font_parameter (f
, parms
);
2974 if (!FRAME_FONT (f
))
2976 delete_frame (frame
, Qnoelisp
);
2977 error ("Invalid frame font");
2980 /* Frame contents get displaced if an embedded X window has a border. */
2981 if (! FRAME_X_EMBEDDED_P (f
))
2982 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
2983 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
2985 /* This defaults to 1 in order to match xterm. We recognize either
2986 internalBorderWidth or internalBorder (which is what xterm calls
2988 if (NILP (Fassq (Qinternal_border_width
, parms
)))
2992 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
2993 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
2994 if (! EQ (value
, Qunbound
))
2995 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
2998 x_default_parameter (f
, parms
, Qinternal_border_width
,
2999 #ifdef USE_GTK /* We used to impose 0 in xg_create_frame_widgets. */
3004 "internalBorderWidth", "internalBorderWidth",
3006 x_default_parameter (f
, parms
, Qvertical_scroll_bars
,
3007 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
3012 "verticalScrollBars", "ScrollBars",
3015 /* Also do the stuff which must be set before the window exists. */
3016 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3017 "foreground", "Foreground", RES_TYPE_STRING
);
3018 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3019 "background", "Background", RES_TYPE_STRING
);
3020 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3021 "pointerColor", "Foreground", RES_TYPE_STRING
);
3022 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3023 "borderColor", "BorderColor", RES_TYPE_STRING
);
3024 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3025 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3026 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3027 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3028 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3029 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3030 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3031 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3033 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3034 "scrollBarForeground",
3035 "ScrollBarForeground", 1);
3036 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3037 "scrollBarBackground",
3038 "ScrollBarBackground", 0);
3041 image_cache_refcount
=
3042 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
3043 dpyinfo_refcount
= dpyinfo
->reference_count
;
3044 #endif /* GLYPH_DEBUG */
3046 /* Init faces before x_default_parameter is called for scroll-bar
3047 parameters because that function calls x_set_scroll_bar_width,
3048 which calls change_frame_size, which calls Fset_window_buffer,
3049 which runs hooks, which call Fvertical_motion. At the end, we
3050 end up in init_iterator with a null face cache, which should not
3052 init_frame_faces (f
);
3054 /* Set the menu-bar-lines and tool-bar-lines parameters. We don't
3055 look up the X resources controlling the menu-bar and tool-bar
3056 here; they are processed specially at startup, and reflected in
3057 the values of the mode variables.
3059 Avoid calling window-configuration-change-hook; otherwise we
3060 could get an infloop in next_frame since the frame is not yet in
3063 ptrdiff_t count2
= SPECPDL_INDEX ();
3064 record_unwind_protect (unwind_create_frame_1
, inhibit_lisp_code
);
3065 inhibit_lisp_code
= Qt
;
3067 x_default_parameter (f
, parms
, Qmenu_bar_lines
,
3068 NILP (Vmenu_bar_mode
)
3069 ? make_number (0) : make_number (1),
3070 NULL
, NULL
, RES_TYPE_NUMBER
);
3071 x_default_parameter (f
, parms
, Qtool_bar_lines
,
3072 NILP (Vtool_bar_mode
)
3073 ? make_number (0) : make_number (1),
3074 NULL
, NULL
, RES_TYPE_NUMBER
);
3076 unbind_to (count2
, Qnil
);
3079 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3080 "bufferPredicate", "BufferPredicate",
3082 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3083 "title", "Title", RES_TYPE_STRING
);
3084 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3085 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3086 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3087 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3088 x_default_parameter (f
, parms
, Qtool_bar_position
,
3089 f
->tool_bar_position
, 0, 0, RES_TYPE_SYMBOL
);
3091 /* Compute the size of the X window. */
3092 window_prompting
= x_figure_window_size (f
, parms
, 1);
3094 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3095 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3097 x_icon_verify (f
, parms
);
3099 /* Create the X widget or window. */
3100 #ifdef USE_X_TOOLKIT
3101 x_window (f
, window_prompting
, minibuffer_only
);
3109 /* Now consider the frame official. */
3110 f
->terminal
->reference_count
++;
3111 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
3112 Vframe_list
= Fcons (frame
, Vframe_list
);
3114 /* We need to do this after creating the X window, so that the
3115 icon-creation functions can say whose icon they're describing. */
3116 x_default_parameter (f
, parms
, Qicon_type
, Qt
,
3117 "bitmapIcon", "BitmapIcon", RES_TYPE_BOOLEAN
);
3119 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3120 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3121 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3122 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3123 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3124 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3125 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3126 "scrollBarWidth", "ScrollBarWidth",
3128 x_default_parameter (f
, parms
, Qalpha
, Qnil
,
3129 "alpha", "Alpha", RES_TYPE_NUMBER
);
3131 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
3132 Change will not be effected unless different from the current
3134 width
= FRAME_COLS (f
);
3135 height
= FRAME_LINES (f
);
3137 SET_FRAME_COLS (f
, 0);
3138 FRAME_LINES (f
) = 0;
3139 change_frame_size (f
, height
, width
, 1, 0, 0);
3141 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3142 /* Create the menu bar. */
3143 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3145 /* If this signals an error, we haven't set size hints for the
3146 frame and we didn't make it visible. */
3147 initialize_frame_menubar (f
);
3150 /* This is a no-op, except under Motif where it arranges the
3151 main window for the widgets on it. */
3152 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3153 f
->output_data
.x
->menubar_widget
,
3154 f
->output_data
.x
->edit_widget
);
3155 #endif /* not USE_GTK */
3157 #endif /* USE_X_TOOLKIT || USE_GTK */
3159 /* Tell the server what size and position, etc, we want, and how
3160 badly we want them. This should be done after we have the menu
3161 bar so that its size can be taken into account. */
3163 x_wm_set_size_hint (f
, window_prompting
, 0);
3166 /* Make the window appear on the frame and enable display, unless
3167 the caller says not to. However, with explicit parent, Emacs
3168 cannot control visibility, so don't try. */
3169 if (! f
->output_data
.x
->explicit_parent
)
3171 Lisp_Object visibility
;
3173 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3175 if (EQ (visibility
, Qunbound
))
3178 if (EQ (visibility
, Qicon
))
3179 x_iconify_frame (f
);
3180 else if (! NILP (visibility
))
3181 x_make_frame_visible (f
);
3184 /* Must have been Qnil. */
3190 /* Set machine name and pid for the purpose of window managers. */
3191 set_machine_and_pid_properties (f
);
3193 /* Set the WM leader property. GTK does this itself, so this is not
3194 needed when using GTK. */
3195 if (dpyinfo
->client_leader_window
!= 0)
3197 XChangeProperty (FRAME_X_DISPLAY (f
),
3198 FRAME_OUTER_WINDOW (f
),
3199 dpyinfo
->Xatom_wm_client_leader
,
3200 XA_WINDOW
, 32, PropModeReplace
,
3201 (unsigned char *) &dpyinfo
->client_leader_window
, 1);
3206 /* Initialize `default-minibuffer-frame' in case this is the first
3207 frame on this terminal. */
3208 if (FRAME_HAS_MINIBUF_P (f
)
3209 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
3210 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
3211 kset_default_minibuffer_frame (kb
, frame
);
3213 /* All remaining specified parameters, which have not been "used"
3214 by x_get_arg and friends, now go in the misc. alist of the frame. */
3215 for (tem
= parms
; CONSP (tem
); tem
= XCDR (tem
))
3216 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
3217 fset_param_alist (f
, Fcons (XCAR (tem
), f
->param_alist
));
3221 /* Make sure windows on this frame appear in calls to next-window
3222 and similar functions. */
3223 Vwindow_list
= Qnil
;
3225 return unbind_to (count
, frame
);
3229 /* FRAME is used only to get a handle on the X display. We don't pass the
3230 display info directly because we're called from frame.c, which doesn't
3231 know about that structure. */
3234 x_get_focus_frame (struct frame
*frame
)
3236 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (frame
);
3238 if (! dpyinfo
->x_focus_frame
)
3241 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3246 /* In certain situations, when the window manager follows a
3247 click-to-focus policy, there seems to be no way around calling
3248 XSetInputFocus to give another frame the input focus .
3250 In an ideal world, XSetInputFocus should generally be avoided so
3251 that applications don't interfere with the window manager's focus
3252 policy. But I think it's okay to use when it's clearly done
3253 following a user-command. */
3255 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
3256 doc
: /* Set the input focus to FRAME.
3257 FRAME nil means use the selected frame. */)
3260 struct frame
*f
= decode_window_system_frame (frame
);
3261 Display
*dpy
= FRAME_X_DISPLAY (f
);
3264 x_catch_errors (dpy
);
3266 if (FRAME_X_EMBEDDED_P (f
))
3268 /* For Xembedded frames, normally the embedder forwards key
3269 events. See XEmbed Protocol Specification at
3270 http://freedesktop.org/wiki/Specifications/xembed-spec */
3271 xembed_request_focus (f
);
3275 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3276 RevertToParent
, CurrentTime
);
3277 x_ewmh_activate_frame (f
);
3280 x_uncatch_errors ();
3287 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
3288 doc
: /* Internal function called by `color-defined-p', which see
3289 .\(Note that the Nextstep version of this function ignores FRAME.) */)
3290 (Lisp_Object color
, Lisp_Object frame
)
3293 struct frame
*f
= decode_window_system_frame (frame
);
3295 CHECK_STRING (color
);
3297 if (x_defined_color (f
, SSDATA (color
), &foo
, 0))
3303 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
3304 doc
: /* Internal function called by `color-values', which see. */)
3305 (Lisp_Object color
, Lisp_Object frame
)
3308 struct frame
*f
= decode_window_system_frame (frame
);
3310 CHECK_STRING (color
);
3312 if (x_defined_color (f
, SSDATA (color
), &foo
, 0))
3313 return list3i (foo
.red
, foo
.green
, foo
.blue
);
3318 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
3319 doc
: /* Internal function called by `display-color-p', which see. */)
3320 (Lisp_Object terminal
)
3322 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3324 if (dpyinfo
->n_planes
<= 2)
3327 switch (dpyinfo
->visual
->class)
3340 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3342 doc
: /* Return t if the X display supports shades of gray.
3343 Note that color displays do support shades of gray.
3344 The optional argument TERMINAL specifies which display to ask about.
3345 TERMINAL should be a terminal object, a frame or a display name (a string).
3346 If omitted or nil, that stands for the selected frame's display. */)
3347 (Lisp_Object terminal
)
3349 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3351 if (dpyinfo
->n_planes
<= 1)
3354 switch (dpyinfo
->visual
->class)
3369 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3371 doc
: /* Return the width in pixels of the X display TERMINAL.
3372 The optional argument TERMINAL specifies which display to ask about.
3373 TERMINAL should be a terminal object, a frame or a display name (a string).
3374 If omitted or nil, that stands for the selected frame's display.
3376 On \"multi-monitor\" setups this refers to the pixel width for all
3377 physical monitors associated with TERMINAL. To get information for
3378 each physical monitor, use `display-monitor-attributes-list'. */)
3379 (Lisp_Object terminal
)
3381 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3383 return make_number (x_display_pixel_width (dpyinfo
));
3386 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3387 Sx_display_pixel_height
, 0, 1, 0,
3388 doc
: /* Return the height in pixels of the X display TERMINAL.
3389 The optional argument TERMINAL specifies which display to ask about.
3390 TERMINAL should be a terminal object, a frame or a display name (a string).
3391 If omitted or nil, that stands for the selected frame's display.
3393 On \"multi-monitor\" setups this refers to the pixel height for all
3394 physical monitors associated with TERMINAL. To get information for
3395 each physical monitor, use `display-monitor-attributes-list'. */)
3396 (Lisp_Object terminal
)
3398 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3400 return make_number (x_display_pixel_height (dpyinfo
));
3403 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3405 doc
: /* Return the number of bitplanes of the X display TERMINAL.
3406 The optional argument TERMINAL specifies which display to ask about.
3407 TERMINAL should be a terminal object, a frame or a display name (a string).
3408 If omitted or nil, that stands for the selected frame's display. */)
3409 (Lisp_Object terminal
)
3411 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3413 return make_number (dpyinfo
->n_planes
);
3416 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3418 doc
: /* Return the number of color cells of the X display TERMINAL.
3419 The optional argument TERMINAL specifies which display to ask about.
3420 TERMINAL should be a terminal object, a frame or a display name (a string).
3421 If omitted or nil, that stands for the selected frame's display. */)
3422 (Lisp_Object terminal
)
3424 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3426 int nr_planes
= DisplayPlanes (dpyinfo
->display
,
3427 XScreenNumberOfScreen (dpyinfo
->screen
));
3429 /* Truncate nr_planes to 24 to avoid integer overflow.
3430 Some displays says 32, but only 24 bits are actually significant.
3431 There are only very few and rare video cards that have more than
3432 24 significant bits. Also 24 bits is more than 16 million colors,
3433 it "should be enough for everyone". */
3434 if (nr_planes
> 24) nr_planes
= 24;
3436 return make_number (1 << nr_planes
);
3439 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3440 Sx_server_max_request_size
,
3442 doc
: /* Return the maximum request size of the X server of display TERMINAL.
3443 The optional argument TERMINAL specifies which display to ask about.
3444 TERMINAL should be a terminal object, a frame or a display name (a string).
3445 If omitted or nil, that stands for the selected frame's display. */)
3446 (Lisp_Object terminal
)
3448 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3450 return make_number (MAXREQUEST (dpyinfo
->display
));
3453 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3454 doc
: /* Return the "vendor ID" string of the X server of display TERMINAL.
3455 \(Labeling every distributor as a "vendor" embodies the false assumption
3456 that operating systems cannot be developed and distributed noncommercially.)
3457 The optional argument TERMINAL specifies which display to ask about.
3458 TERMINAL should be a terminal object, a frame or a display name (a string).
3459 If omitted or nil, that stands for the selected frame's display. */)
3460 (Lisp_Object terminal
)
3462 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3463 const char *vendor
= ServerVendor (dpyinfo
->display
);
3465 if (! vendor
) vendor
= "";
3466 return build_string (vendor
);
3469 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3470 doc
: /* Return the version numbers of the X server of display TERMINAL.
3471 The value is a list of three integers: the major and minor
3472 version numbers of the X Protocol in use, and the distributor-specific release
3473 number. See also the function `x-server-vendor'.
3475 The optional argument TERMINAL specifies which display to ask about.
3476 TERMINAL should be a terminal object, a frame or a display name (a string).
3477 If omitted or nil, that stands for the selected frame's display. */)
3478 (Lisp_Object terminal
)
3480 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3481 Display
*dpy
= dpyinfo
->display
;
3483 return list3i (ProtocolVersion (dpy
), ProtocolRevision (dpy
),
3484 VendorRelease (dpy
));
3487 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3488 doc
: /* Return the number of screens on the X server of display TERMINAL.
3489 The optional argument TERMINAL specifies which display to ask about.
3490 TERMINAL should be a terminal object, a frame or a display name (a string).
3491 If omitted or nil, that stands for the selected frame's display. */)
3492 (Lisp_Object terminal
)
3494 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3496 return make_number (ScreenCount (dpyinfo
->display
));
3499 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3500 doc
: /* Return the height in millimeters of the X display TERMINAL.
3501 The optional argument TERMINAL specifies which display to ask about.
3502 TERMINAL should be a terminal object, a frame or a display name (a string).
3503 If omitted or nil, that stands for the selected frame's display.
3505 On \"multi-monitor\" setups this refers to the height in millimeters for
3506 all physical monitors associated with TERMINAL. To get information
3507 for each physical monitor, use `display-monitor-attributes-list'. */)
3508 (Lisp_Object terminal
)
3510 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3512 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3515 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3516 doc
: /* Return the width in millimeters of the X display TERMINAL.
3517 The optional argument TERMINAL specifies which display to ask about.
3518 TERMINAL should be a terminal object, a frame or a display name (a string).
3519 If omitted or nil, that stands for the selected frame's display.
3521 On \"multi-monitor\" setups this refers to the width in millimeters for
3522 all physical monitors associated with TERMINAL. To get information
3523 for each physical monitor, use `display-monitor-attributes-list'. */)
3524 (Lisp_Object terminal
)
3526 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3528 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3531 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3532 Sx_display_backing_store
, 0, 1, 0,
3533 doc
: /* Return an indication of whether X display TERMINAL does backing store.
3534 The value may be `always', `when-mapped', or `not-useful'.
3535 The optional argument TERMINAL specifies which display to ask about.
3536 TERMINAL should be a terminal object, a frame or a display name (a string).
3537 If omitted or nil, that stands for the selected frame's display. */)
3538 (Lisp_Object terminal
)
3540 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3543 switch (DoesBackingStore (dpyinfo
->screen
))
3546 result
= intern ("always");
3550 result
= intern ("when-mapped");
3554 result
= intern ("not-useful");
3558 error ("Strange value for BackingStore parameter of screen");
3564 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3565 Sx_display_visual_class
, 0, 1, 0,
3566 doc
: /* Return the visual class of the X display TERMINAL.
3567 The value is one of the symbols `static-gray', `gray-scale',
3568 `static-color', `pseudo-color', `true-color', or `direct-color'.
3570 The optional argument TERMINAL specifies which display to ask about.
3571 TERMINAL should a terminal object, a frame or a display name (a string).
3572 If omitted or nil, that stands for the selected frame's display. */)
3573 (Lisp_Object terminal
)
3575 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3578 switch (dpyinfo
->visual
->class)
3581 result
= intern ("static-gray");
3584 result
= intern ("gray-scale");
3587 result
= intern ("static-color");
3590 result
= intern ("pseudo-color");
3593 result
= intern ("true-color");
3596 result
= intern ("direct-color");
3599 error ("Display has an unknown visual class");
3605 DEFUN ("x-display-save-under", Fx_display_save_under
,
3606 Sx_display_save_under
, 0, 1, 0,
3607 doc
: /* Return t if the X display TERMINAL supports the save-under feature.
3608 The optional argument TERMINAL specifies which display to ask about.
3609 TERMINAL should be a terminal object, a frame or a display name (a string).
3610 If omitted or nil, that stands for the selected frame's display. */)
3611 (Lisp_Object terminal
)
3613 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3615 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3621 /* Store the geometry of the workarea on display DPYINFO into *RECT.
3622 Return false if and only if the workarea information cannot be
3623 obtained via the _NET_WORKAREA root window property. */
3625 #if ! GTK_CHECK_VERSION (3, 4, 0)
3627 x_get_net_workarea (struct x_display_info
*dpyinfo
, XRectangle
*rect
)
3629 Display
*dpy
= dpyinfo
->display
;
3630 long offset
, max_len
;
3631 Atom target_type
, actual_type
;
3632 unsigned long actual_size
, bytes_remaining
;
3633 int rc
, actual_format
;
3634 unsigned char *tmp_data
= NULL
;
3635 bool result
= false;
3637 x_catch_errors (dpy
);
3640 target_type
= XA_CARDINAL
;
3641 rc
= XGetWindowProperty (dpy
, dpyinfo
->root_window
,
3642 dpyinfo
->Xatom_net_current_desktop
,
3643 offset
, max_len
, False
, target_type
,
3644 &actual_type
, &actual_format
, &actual_size
,
3645 &bytes_remaining
, &tmp_data
);
3646 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
3647 && actual_format
== 32 && actual_size
== max_len
)
3649 long current_desktop
= ((long *) tmp_data
)[0];
3654 offset
= 4 * current_desktop
;
3656 rc
= XGetWindowProperty (dpy
, dpyinfo
->root_window
,
3657 dpyinfo
->Xatom_net_workarea
,
3658 offset
, max_len
, False
, target_type
,
3659 &actual_type
, &actual_format
, &actual_size
,
3660 &bytes_remaining
, &tmp_data
);
3661 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
3662 && actual_format
== 32 && actual_size
== max_len
)
3664 long *values
= (long *) tmp_data
;
3666 rect
->x
= values
[0];
3667 rect
->y
= values
[1];
3668 rect
->width
= values
[2];
3669 rect
->height
= values
[3];
3679 x_uncatch_errors ();
3687 /* Return monitor number where F is "most" or closest to. */
3689 x_get_monitor_for_frame (struct frame
*f
,
3690 struct MonitorInfo
*monitors
,
3694 int area
= 0, dist
= -1;
3695 int best_area
= -1, best_dist
= -1;
3698 if (n_monitors
== 1) return 0;
3699 frect
.x
= f
->left_pos
;
3700 frect
.y
= f
->top_pos
;
3701 frect
.width
= FRAME_PIXEL_WIDTH (f
);
3702 frect
.height
= FRAME_PIXEL_HEIGHT (f
);
3704 for (i
= 0; i
< n_monitors
; ++i
)
3706 struct MonitorInfo
*mi
= &monitors
[i
];
3710 if (mi
->geom
.width
== 0) continue;
3712 if (x_intersect_rectangles (&mi
->geom
, &frect
, &res
))
3714 a
= res
.width
* res
.height
;
3722 if (a
== 0 && area
== 0)
3725 if (frect
.x
+ frect
.width
< mi
->geom
.x
)
3726 dx
= mi
->geom
.x
- frect
.x
+ frect
.width
;
3727 else if (frect
.x
> mi
->geom
.x
+ mi
->geom
.width
)
3728 dx
= frect
.x
- mi
->geom
.x
+ mi
->geom
.width
;
3731 if (frect
.y
+ frect
.height
< mi
->geom
.y
)
3732 dy
= mi
->geom
.y
- frect
.y
+ frect
.height
;
3733 else if (frect
.y
> mi
->geom
.y
+ mi
->geom
.height
)
3734 dy
= frect
.y
- mi
->geom
.y
+ mi
->geom
.height
;
3739 if (dist
== -1 || dist
> d
)
3747 return best_area
!= -1 ? best_area
: (best_dist
!= -1 ? best_dist
: 0);
3751 x_make_monitor_attribute_list (struct MonitorInfo
*monitors
,
3753 int primary_monitor
,
3754 struct x_display_info
*dpyinfo
,
3757 Lisp_Object monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
3758 Lisp_Object frame
, rest
;
3760 FOR_EACH_FRAME (rest
, frame
)
3762 struct frame
*f
= XFRAME (frame
);
3764 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
3765 && !EQ (frame
, tip_frame
))
3767 int i
= x_get_monitor_for_frame (f
, monitors
, n_monitors
);
3768 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
3772 return make_monitor_attribute_list (monitors
, n_monitors
, primary_monitor
,
3773 monitor_frames
, source
);
3777 x_get_monitor_attributes_fallback (struct x_display_info
*dpyinfo
)
3779 struct MonitorInfo monitor
;
3780 XRectangle workarea_r
;
3782 /* Fallback: treat (possibly) multiple physical monitors as if they
3783 formed a single monitor as a whole. This should provide a
3784 consistent result at least on single monitor environments. */
3785 monitor
.geom
.x
= monitor
.geom
.y
= 0;
3786 monitor
.geom
.width
= x_display_pixel_width (dpyinfo
);
3787 monitor
.geom
.height
= x_display_pixel_height (dpyinfo
);
3788 monitor
.mm_width
= WidthMMOfScreen (dpyinfo
->screen
);
3789 monitor
.mm_height
= HeightMMOfScreen (dpyinfo
->screen
);
3790 monitor
.name
= xstrdup ("combined screen");
3792 if (x_get_net_workarea (dpyinfo
, &workarea_r
))
3793 monitor
.work
= workarea_r
;
3795 monitor
.work
= monitor
.geom
;
3796 return x_make_monitor_attribute_list (&monitor
, 1, 0, dpyinfo
, "fallback");
3800 #ifdef HAVE_XINERAMA
3802 x_get_monitor_attributes_xinerama (struct x_display_info
*dpyinfo
)
3805 Lisp_Object attributes_list
= Qnil
;
3806 Display
*dpy
= dpyinfo
->display
;
3807 XineramaScreenInfo
*info
= XineramaQueryScreens (dpy
, &n_monitors
);
3808 struct MonitorInfo
*monitors
;
3809 double mm_width_per_pixel
, mm_height_per_pixel
;
3811 if (! info
|| n_monitors
== 0)
3815 return attributes_list
;
3818 mm_width_per_pixel
= ((double) WidthMMOfScreen (dpyinfo
->screen
)
3819 / x_display_pixel_width (dpyinfo
));
3820 mm_height_per_pixel
= ((double) HeightMMOfScreen (dpyinfo
->screen
)
3821 / x_display_pixel_height (dpyinfo
));
3822 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
3823 for (i
= 0; i
< n_monitors
; ++i
)
3825 struct MonitorInfo
*mi
= &monitors
[i
];
3826 XRectangle workarea_r
;
3828 mi
->geom
.x
= info
[i
].x_org
;
3829 mi
->geom
.y
= info
[i
].y_org
;
3830 mi
->geom
.width
= info
[i
].width
;
3831 mi
->geom
.height
= info
[i
].height
;
3832 mi
->mm_width
= mi
->geom
.width
* mm_width_per_pixel
+ 0.5;
3833 mi
->mm_height
= mi
->geom
.height
* mm_height_per_pixel
+ 0.5;
3836 /* Xinerama usually have primary monitor first, just use that. */
3837 if (i
== 0 && x_get_net_workarea (dpyinfo
, &workarea_r
))
3839 mi
->work
= workarea_r
;
3840 if (! x_intersect_rectangles (&mi
->geom
, &mi
->work
, &mi
->work
))
3841 mi
->work
= mi
->geom
;
3844 mi
->work
= mi
->geom
;
3848 attributes_list
= x_make_monitor_attribute_list (monitors
,
3853 free_monitors (monitors
, n_monitors
);
3854 return attributes_list
;
3856 #endif /* HAVE_XINERAMA */
3861 x_get_monitor_attributes_xrandr (struct x_display_info
*dpyinfo
)
3863 Lisp_Object attributes_list
= Qnil
;
3864 XRRScreenResources
*resources
;
3865 Display
*dpy
= dpyinfo
->display
;
3866 int i
, n_monitors
, primary
= -1;
3867 RROutput pxid
= None
;
3868 struct MonitorInfo
*monitors
;
3870 #ifdef HAVE_XRRGETSCREENRESOURCESCURRENT
3871 resources
= XRRGetScreenResourcesCurrent (dpy
, dpyinfo
->root_window
);
3873 resources
= XRRGetScreenResources (dpy
, dpyinfo
->root_window
);
3875 if (! resources
|| resources
->noutput
== 0)
3878 XRRFreeScreenResources (resources
);
3881 n_monitors
= resources
->noutput
;
3882 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
3884 #ifdef HAVE_XRRGETOUTPUTPRIMARY
3885 pxid
= XRRGetOutputPrimary (dpy
, dpyinfo
->root_window
);
3888 for (i
= 0; i
< n_monitors
; ++i
)
3890 XRROutputInfo
*info
= XRRGetOutputInfo (dpy
, resources
,
3891 resources
->outputs
[i
]);
3892 Connection conn
= info
? info
->connection
: RR_Disconnected
;
3893 RRCrtc id
= info
? info
->crtc
: None
;
3895 if (strcmp (info
->name
, "default") == 0)
3897 /* Non XRandr 1.2 driver, does not give useful data. */
3898 XRRFreeOutputInfo (info
);
3899 XRRFreeScreenResources (resources
);
3900 free_monitors (monitors
, n_monitors
);
3904 if (conn
!= RR_Disconnected
&& id
!= None
)
3906 XRRCrtcInfo
*crtc
= XRRGetCrtcInfo (dpy
, resources
, id
);
3907 struct MonitorInfo
*mi
= &monitors
[i
];
3908 XRectangle workarea_r
;
3912 XRRFreeOutputInfo (info
);
3916 mi
->geom
.x
= crtc
->x
;
3917 mi
->geom
.y
= crtc
->y
;
3918 mi
->geom
.width
= crtc
->width
;
3919 mi
->geom
.height
= crtc
->height
;
3920 mi
->mm_width
= info
->mm_width
;
3921 mi
->mm_height
= info
->mm_height
;
3922 mi
->name
= xstrdup (info
->name
);
3924 if (pxid
!= None
&& pxid
== resources
->outputs
[i
])
3926 else if (primary
== -1 && strcmp (info
->name
, "LVDS") == 0)
3929 if (i
== primary
&& x_get_net_workarea (dpyinfo
, &workarea_r
))
3931 mi
->work
= workarea_r
;
3932 if (! x_intersect_rectangles (&mi
->geom
, &mi
->work
, &mi
->work
))
3933 mi
->work
= mi
->geom
;
3936 mi
->work
= mi
->geom
;
3938 XRRFreeCrtcInfo (crtc
);
3940 XRRFreeOutputInfo (info
);
3942 XRRFreeScreenResources (resources
);
3944 attributes_list
= x_make_monitor_attribute_list (monitors
,
3949 free_monitors (monitors
, n_monitors
);
3950 return attributes_list
;
3952 #endif /* HAVE_XRANDR */
3955 x_get_monitor_attributes (struct x_display_info
*dpyinfo
)
3957 Lisp_Object attributes_list
= Qnil
;
3958 Display
*dpy
= dpyinfo
->display
;
3961 int xrr_event_base
, xrr_error_base
;
3962 bool xrr_ok
= false;
3963 xrr_ok
= XRRQueryExtension (dpy
, &xrr_event_base
, &xrr_error_base
);
3966 int xrr_major
, xrr_minor
;
3967 XRRQueryVersion (dpy
, &xrr_major
, &xrr_minor
);
3968 xrr_ok
= (xrr_major
== 1 && xrr_minor
>= 2) || xrr_major
> 1;
3972 attributes_list
= x_get_monitor_attributes_xrandr (dpyinfo
);
3973 #endif /* HAVE_XRANDR */
3975 #ifdef HAVE_XINERAMA
3976 if (NILP (attributes_list
))
3978 int xin_event_base
, xin_error_base
;
3979 bool xin_ok
= false;
3980 xin_ok
= XineramaQueryExtension (dpy
, &xin_event_base
, &xin_error_base
);
3981 if (xin_ok
&& XineramaIsActive (dpy
))
3982 attributes_list
= x_get_monitor_attributes_xinerama (dpyinfo
);
3984 #endif /* HAVE_XINERAMA */
3986 if (NILP (attributes_list
))
3987 attributes_list
= x_get_monitor_attributes_fallback (dpyinfo
);
3989 return attributes_list
;
3992 #endif /* !USE_GTK */
3994 DEFUN ("x-display-monitor-attributes-list", Fx_display_monitor_attributes_list
,
3995 Sx_display_monitor_attributes_list
,
3997 doc
: /* Return a list of physical monitor attributes on the X display TERMINAL.
3999 The optional argument TERMINAL specifies which display to ask about.
4000 TERMINAL should be a terminal object, a frame or a display name (a string).
4001 If omitted or nil, that stands for the selected frame's display.
4003 In addition to the standard attribute keys listed in
4004 `display-monitor-attributes-list', the following keys are contained in
4007 source -- String describing the source from which multi-monitor
4008 information is obtained, one of \"Gdk\", \"XRandr\",
4009 \"Xinerama\", or \"fallback\"
4011 Internal use only, use `display-monitor-attributes-list' instead. */)
4012 (Lisp_Object terminal
)
4014 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4015 Lisp_Object attributes_list
= Qnil
;
4018 double mm_width_per_pixel
, mm_height_per_pixel
;
4021 gint primary_monitor
= 0, n_monitors
, i
;
4022 Lisp_Object monitor_frames
, rest
, frame
;
4023 static const char *source
= "Gdk";
4024 struct MonitorInfo
*monitors
;
4027 mm_width_per_pixel
= ((double) WidthMMOfScreen (dpyinfo
->screen
)
4028 / x_display_pixel_width (dpyinfo
));
4029 mm_height_per_pixel
= ((double) HeightMMOfScreen (dpyinfo
->screen
)
4030 / x_display_pixel_height (dpyinfo
));
4031 gdpy
= gdk_x11_lookup_xdisplay (dpyinfo
->display
);
4032 gscreen
= gdk_display_get_default_screen (gdpy
);
4033 #if GTK_CHECK_VERSION (2, 20, 0)
4034 primary_monitor
= gdk_screen_get_primary_monitor (gscreen
);
4036 n_monitors
= gdk_screen_get_n_monitors (gscreen
);
4037 monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
4038 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
4040 FOR_EACH_FRAME (rest
, frame
)
4042 struct frame
*f
= XFRAME (frame
);
4044 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
4045 && !EQ (frame
, tip_frame
))
4047 GdkWindow
*gwin
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
4049 i
= gdk_screen_get_monitor_at_window (gscreen
, gwin
);
4050 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
4054 for (i
= 0; i
< n_monitors
; ++i
)
4056 gint width_mm
= -1, height_mm
= -1;
4057 GdkRectangle rec
, work
;
4058 struct MonitorInfo
*mi
= &monitors
[i
];
4060 gdk_screen_get_monitor_geometry (gscreen
, i
, &rec
);
4062 #if GTK_CHECK_VERSION (2, 14, 0)
4063 width_mm
= gdk_screen_get_monitor_width_mm (gscreen
, i
);
4064 height_mm
= gdk_screen_get_monitor_height_mm (gscreen
, i
);
4067 width_mm
= rec
.width
* mm_width_per_pixel
+ 0.5;
4069 height_mm
= rec
.height
* mm_height_per_pixel
+ 0.5;
4071 #if GTK_CHECK_VERSION (3, 4, 0)
4072 gdk_screen_get_monitor_workarea (gscreen
, i
, &work
);
4074 /* Emulate the behavior of GTK+ 3.4. */
4076 XRectangle workarea_r
;
4078 if (i
== primary_monitor
&& x_get_net_workarea (dpyinfo
, &workarea_r
))
4080 work
.x
= workarea_r
.x
;
4081 work
.y
= workarea_r
.y
;
4082 work
.width
= workarea_r
.width
;
4083 work
.height
= workarea_r
.height
;
4084 if (! gdk_rectangle_intersect (&rec
, &work
, &work
))
4095 mi
->geom
.width
= rec
.width
;
4096 mi
->geom
.height
= rec
.height
;
4097 mi
->work
.x
= work
.x
;
4098 mi
->work
.y
= work
.y
;
4099 mi
->work
.width
= work
.width
;
4100 mi
->work
.height
= work
.height
;
4101 mi
->mm_width
= width_mm
;
4102 mi
->mm_height
= height_mm
;
4104 #if GTK_CHECK_VERSION (2, 14, 0)
4105 mi
->name
= gdk_screen_get_monitor_plug_name (gscreen
, i
);
4109 attributes_list
= make_monitor_attribute_list (monitors
,
4115 #else /* not USE_GTK */
4118 attributes_list
= x_get_monitor_attributes (dpyinfo
);
4121 #endif /* not USE_GTK */
4123 return attributes_list
;
4126 /************************************************************************
4128 ************************************************************************/
4131 /* Mapping visual names to visuals. */
4133 static struct visual_class
4140 {"StaticGray", StaticGray
},
4141 {"GrayScale", GrayScale
},
4142 {"StaticColor", StaticColor
},
4143 {"PseudoColor", PseudoColor
},
4144 {"TrueColor", TrueColor
},
4145 {"DirectColor", DirectColor
},
4150 #ifndef HAVE_XSCREENNUMBEROFSCREEN
4152 /* Value is the screen number of screen SCR. This is a substitute for
4153 the X function with the same name when that doesn't exist. */
4156 XScreenNumberOfScreen (scr
)
4157 register Screen
*scr
;
4159 Display
*dpy
= scr
->display
;
4162 for (i
= 0; i
< dpy
->nscreens
; ++i
)
4163 if (scr
== dpy
->screens
+ i
)
4169 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
4172 /* Select the visual that should be used on display DPYINFO. Set
4173 members of DPYINFO appropriately. Called from x_term_init. */
4176 select_visual (struct x_display_info
*dpyinfo
)
4178 Display
*dpy
= dpyinfo
->display
;
4179 Screen
*screen
= dpyinfo
->screen
;
4182 /* See if a visual is specified. */
4183 value
= display_x_get_resource (dpyinfo
,
4184 build_string ("visualClass"),
4185 build_string ("VisualClass"),
4187 if (STRINGP (value
))
4189 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
4190 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
4191 depth, a decimal number. NAME is compared with case ignored. */
4192 char *s
= alloca (SBYTES (value
) + 1);
4197 strcpy (s
, SSDATA (value
));
4198 dash
= strchr (s
, '-');
4201 dpyinfo
->n_planes
= atoi (dash
+ 1);
4205 /* We won't find a matching visual with depth 0, so that
4206 an error will be printed below. */
4207 dpyinfo
->n_planes
= 0;
4209 /* Determine the visual class. */
4210 for (i
= 0; visual_classes
[i
].name
; ++i
)
4211 if (xstrcasecmp (s
, visual_classes
[i
].name
) == 0)
4213 class = visual_classes
[i
].class;
4217 /* Look up a matching visual for the specified class. */
4219 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
4220 dpyinfo
->n_planes
, class, &vinfo
))
4221 fatal ("Invalid visual specification `%s'", SDATA (value
));
4223 dpyinfo
->visual
= vinfo
.visual
;
4228 XVisualInfo
*vinfo
, vinfo_template
;
4230 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
4232 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
4233 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
4234 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
4235 &vinfo_template
, &n_visuals
);
4237 fatal ("Can't get proper X visual info");
4239 dpyinfo
->n_planes
= vinfo
->depth
;
4245 /* Return the X display structure for the display named NAME.
4246 Open a new connection if necessary. */
4248 static struct x_display_info
*
4249 x_display_info_for_name (Lisp_Object name
)
4252 struct x_display_info
*dpyinfo
;
4254 CHECK_STRING (name
);
4256 for (dpyinfo
= x_display_list
, names
= x_display_name_list
;
4258 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
4261 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
4266 /* Use this general default value to start with. */
4267 Vx_resource_name
= Vinvocation_name
;
4269 validate_x_resource_name ();
4271 dpyinfo
= x_term_init (name
, 0, SSDATA (Vx_resource_name
));
4274 error ("Cannot connect to X server %s", SDATA (name
));
4276 XSETFASTINT (Vwindow_system_version
, 11);
4282 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4284 doc
: /* Open a connection to a display server.
4285 DISPLAY is the name of the display to connect to.
4286 Optional second arg XRM-STRING is a string of resources in xrdb format.
4287 If the optional third arg MUST-SUCCEED is non-nil,
4288 terminate Emacs if we can't open the connection.
4289 \(In the Nextstep version, the last two arguments are currently ignored.) */)
4290 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
4293 struct x_display_info
*dpyinfo
;
4295 CHECK_STRING (display
);
4296 if (! NILP (xrm_string
))
4297 CHECK_STRING (xrm_string
);
4299 xrm_option
= NILP (xrm_string
) ? 0 : SSDATA (xrm_string
);
4301 validate_x_resource_name ();
4303 /* This is what opens the connection and sets x_current_display.
4304 This also initializes many symbols, such as those used for input. */
4305 dpyinfo
= x_term_init (display
, xrm_option
,
4306 SSDATA (Vx_resource_name
));
4310 if (!NILP (must_succeed
))
4311 fatal ("Cannot connect to X server %s.\n\
4312 Check the DISPLAY environment variable or use `-d'.\n\
4313 Also use the `xauth' program to verify that you have the proper\n\
4314 authorization information needed to connect the X server.\n\
4315 An insecure way to solve the problem may be to use `xhost'.\n",
4318 error ("Cannot connect to X server %s", SDATA (display
));
4321 XSETFASTINT (Vwindow_system_version
, 11);
4325 DEFUN ("x-close-connection", Fx_close_connection
,
4326 Sx_close_connection
, 1, 1, 0,
4327 doc
: /* Close the connection to TERMINAL's X server.
4328 For TERMINAL, specify a terminal object, a frame or a display name (a
4329 string). If TERMINAL is nil, that stands for the selected frame's
4331 (Lisp_Object terminal
)
4333 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4335 if (dpyinfo
->reference_count
> 0)
4336 error ("Display still has frames on it");
4338 x_delete_terminal (dpyinfo
->terminal
);
4343 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4344 doc
: /* Return the list of display names that Emacs has connections to. */)
4347 Lisp_Object tail
, result
;
4350 for (tail
= x_display_name_list
; CONSP (tail
); tail
= XCDR (tail
))
4351 result
= Fcons (XCAR (XCAR (tail
)), result
);
4356 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4357 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
4358 This function only has an effect on X Windows. With MS Windows, it is
4359 defined but does nothing.
4361 If ON is nil, allow buffering of requests.
4362 Turning on synchronization prohibits the Xlib routines from buffering
4363 requests and seriously degrades performance, but makes debugging much
4365 The optional second argument TERMINAL specifies which display to act on.
4366 TERMINAL should be a terminal object, a frame or a display name (a string).
4367 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
4368 (Lisp_Object on
, Lisp_Object terminal
)
4370 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4372 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
4377 /* Wait for responses to all X commands issued so far for frame F. */
4380 x_sync (struct frame
*f
)
4383 XSync (FRAME_X_DISPLAY (f
), False
);
4388 /***********************************************************************
4390 ***********************************************************************/
4392 DEFUN ("x-change-window-property", Fx_change_window_property
,
4393 Sx_change_window_property
, 2, 6, 0,
4394 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
4395 PROP must be a string. VALUE may be a string or a list of conses,
4396 numbers and/or strings. If an element in the list is a string, it is
4397 converted to an atom and the value of the atom is used. If an element
4398 is a cons, it is converted to a 32 bit number where the car is the 16
4399 top bits and the cdr is the lower 16 bits.
4401 FRAME nil or omitted means use the selected frame.
4402 If TYPE is given and non-nil, it is the name of the type of VALUE.
4403 If TYPE is not given or nil, the type is STRING.
4404 FORMAT gives the size in bits of each element if VALUE is a list.
4405 It must be one of 8, 16 or 32.
4406 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4407 If OUTER-P is non-nil, the property is changed for the outer X window of
4408 FRAME. Default is to change on the edit X window. */)
4409 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
,
4410 Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
4412 struct frame
*f
= decode_window_system_frame (frame
);
4414 Atom target_type
= XA_STRING
;
4415 int element_format
= 8;
4416 unsigned char *data
;
4420 CHECK_STRING (prop
);
4422 if (! NILP (format
))
4424 CHECK_NUMBER (format
);
4426 if (XINT (format
) != 8 && XINT (format
) != 16
4427 && XINT (format
) != 32)
4428 error ("FORMAT must be one of 8, 16 or 32");
4429 element_format
= XINT (format
);
4436 nelements
= x_check_property_data (value
);
4437 if (nelements
== -1)
4438 error ("Bad data in VALUE, must be number, string or cons");
4440 /* The man page for XChangeProperty:
4441 "If the specified format is 32, the property data must be a
4443 This applies even if long is more than 32 bits. The X library
4444 converts to 32 bits before sending to the X server. */
4445 elsize
= element_format
== 32 ? sizeof (long) : element_format
>> 3;
4446 data
= xnmalloc (nelements
, elsize
);
4448 x_fill_property_data (FRAME_X_DISPLAY (f
), value
, data
, element_format
);
4452 CHECK_STRING (value
);
4453 data
= SDATA (value
);
4454 if (INT_MAX
< SBYTES (value
))
4455 error ("VALUE too long");
4456 nelements
= SBYTES (value
);
4460 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4463 CHECK_STRING (type
);
4464 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
4467 if (! NILP (outer_p
)) w
= FRAME_OUTER_WINDOW (f
);
4468 else w
= FRAME_X_WINDOW (f
);
4470 XChangeProperty (FRAME_X_DISPLAY (f
), w
,
4471 prop_atom
, target_type
, element_format
, PropModeReplace
,
4474 if (CONSP (value
)) xfree (data
);
4476 /* Make sure the property is set when we return. */
4477 XFlush (FRAME_X_DISPLAY (f
));
4484 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
4485 Sx_delete_window_property
, 1, 2, 0,
4486 doc
: /* Remove window property PROP from X window of FRAME.
4487 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4488 (Lisp_Object prop
, Lisp_Object frame
)
4490 struct frame
*f
= decode_window_system_frame (frame
);
4493 CHECK_STRING (prop
);
4495 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4496 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
4498 /* Make sure the property is removed when we return. */
4499 XFlush (FRAME_X_DISPLAY (f
));
4506 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
4508 doc
: /* Value is the value of window property PROP on FRAME.
4509 If FRAME is nil or omitted, use the selected frame.
4511 On X Windows, the following optional arguments are also accepted:
4512 If TYPE is nil or omitted, get the property as a string.
4513 Otherwise TYPE is the name of the atom that denotes the type expected.
4514 If SOURCE is non-nil, get the property on that window instead of from
4515 FRAME. The number 0 denotes the root window.
4516 If DELETE-P is non-nil, delete the property after retrieving it.
4517 If VECTOR-RET-P is non-nil, don't return a string but a vector of values.
4519 On MS Windows, this function accepts but ignores those optional arguments.
4521 Value is nil if FRAME hasn't a property with name PROP or if PROP has
4522 no value of TYPE (always string in the MS Windows case). */)
4523 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
,
4524 Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
4526 struct frame
*f
= decode_window_system_frame (frame
);
4529 Lisp_Object prop_value
= Qnil
;
4530 unsigned char *tmp_data
= NULL
;
4532 Atom target_type
= XA_STRING
;
4534 unsigned long actual_size
, bytes_remaining
;
4535 Window target_window
= FRAME_X_WINDOW (f
);
4536 struct gcpro gcpro1
;
4538 GCPRO1 (prop_value
);
4539 CHECK_STRING (prop
);
4541 if (! NILP (source
))
4543 CONS_TO_INTEGER (source
, Window
, target_window
);
4544 if (! target_window
)
4545 target_window
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4551 if (strcmp ("AnyPropertyType", SSDATA (type
)) == 0)
4552 target_type
= AnyPropertyType
;
4554 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
4557 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4558 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4559 prop_atom
, 0, 0, False
, target_type
,
4560 &actual_type
, &actual_format
, &actual_size
,
4561 &bytes_remaining
, &tmp_data
);
4564 int size
= bytes_remaining
;
4569 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4570 prop_atom
, 0, bytes_remaining
,
4571 ! NILP (delete_p
), target_type
,
4572 &actual_type
, &actual_format
,
4573 &actual_size
, &bytes_remaining
,
4575 if (rc
== Success
&& tmp_data
)
4577 /* The man page for XGetWindowProperty says:
4578 "If the returned format is 32, the returned data is represented
4579 as a long array and should be cast to that type to obtain the
4581 This applies even if long is more than 32 bits, the X library
4582 converts from 32 bit elements received from the X server to long
4583 and passes the long array to us. Thus, for that case memcpy can not
4584 be used. We convert to a 32 bit type here, because so much code
4587 The bytes and offsets passed to XGetWindowProperty refers to the
4588 property and those are indeed in 32 bit quantities if format is
4591 if (BITS_PER_LONG
> 32 && actual_format
== 32)
4594 int *idata
= (int *) tmp_data
;
4595 long *ldata
= (long *) tmp_data
;
4597 for (i
= 0; i
< actual_size
; ++i
)
4598 idata
[i
] = (int) ldata
[i
];
4601 if (NILP (vector_ret_p
))
4602 prop_value
= make_string ((char *) tmp_data
, size
);
4604 prop_value
= x_property_data_to_lisp (f
,
4611 if (tmp_data
) XFree (tmp_data
);
4621 /***********************************************************************
4623 ***********************************************************************/
4625 /* Timer function of hourglass_atimer. TIMER is equal to
4628 Display an hourglass pointer on all frames by mapping the frames'
4629 hourglass_window. Set the hourglass_p flag in the frames'
4630 output_data.x structure to indicate that an hourglass cursor is
4631 shown on the frames. */
4634 show_hourglass (struct atimer
*timer
)
4636 /* The timer implementation will cancel this timer automatically
4637 after this function has run. Set hourglass_atimer to null
4638 so that we know the timer doesn't have to be canceled. */
4639 hourglass_atimer
= NULL
;
4641 if (!hourglass_shown_p
)
4643 Lisp_Object rest
, frame
;
4647 FOR_EACH_FRAME (rest
, frame
)
4649 struct frame
*f
= XFRAME (frame
);
4651 if (FRAME_LIVE_P (f
) && FRAME_X_P (f
) && FRAME_X_DISPLAY (f
))
4653 Display
*dpy
= FRAME_X_DISPLAY (f
);
4655 #ifdef USE_X_TOOLKIT
4656 if (f
->output_data
.x
->widget
)
4658 if (FRAME_OUTER_WINDOW (f
))
4661 f
->output_data
.x
->hourglass_p
= 1;
4663 if (!f
->output_data
.x
->hourglass_window
)
4665 unsigned long mask
= CWCursor
;
4666 XSetWindowAttributes attrs
;
4668 Window parent
= FRAME_X_WINDOW (f
);
4670 Window parent
= FRAME_OUTER_WINDOW (f
);
4672 attrs
.cursor
= f
->output_data
.x
->hourglass_cursor
;
4674 f
->output_data
.x
->hourglass_window
4675 = XCreateWindow (dpy
, parent
,
4676 0, 0, 32000, 32000, 0, 0,
4682 XMapRaised (dpy
, f
->output_data
.x
->hourglass_window
);
4688 hourglass_shown_p
= 1;
4694 /* Hide the hourglass pointer on all frames, if it is currently
4698 hide_hourglass (void)
4700 if (hourglass_shown_p
)
4702 Lisp_Object rest
, frame
;
4705 FOR_EACH_FRAME (rest
, frame
)
4707 struct frame
*f
= XFRAME (frame
);
4710 /* Watch out for newly created frames. */
4711 && f
->output_data
.x
->hourglass_window
)
4713 XUnmapWindow (FRAME_X_DISPLAY (f
),
4714 f
->output_data
.x
->hourglass_window
);
4715 /* Sync here because XTread_socket looks at the
4716 hourglass_p flag that is reset to zero below. */
4717 XSync (FRAME_X_DISPLAY (f
), False
);
4718 f
->output_data
.x
->hourglass_p
= 0;
4722 hourglass_shown_p
= 0;
4729 /***********************************************************************
4731 ***********************************************************************/
4733 static Lisp_Object
x_create_tip_frame (struct x_display_info
*,
4734 Lisp_Object
, Lisp_Object
);
4735 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
4736 Lisp_Object
, int, int, int *, int *);
4738 /* The frame of a currently visible tooltip. */
4740 Lisp_Object tip_frame
;
4742 /* If non-nil, a timer started that hides the last tooltip when it
4745 static Lisp_Object tip_timer
;
4748 /* If non-nil, a vector of 3 elements containing the last args
4749 with which x-show-tip was called. See there. */
4751 static Lisp_Object last_show_tip_args
;
4755 unwind_create_tip_frame (Lisp_Object frame
)
4757 Lisp_Object deleted
;
4759 deleted
= unwind_create_frame (frame
);
4760 if (EQ (deleted
, Qt
))
4768 /* Create a frame for a tooltip on the display described by DPYINFO.
4769 PARMS is a list of frame parameters. TEXT is the string to
4770 display in the tip frame. Value is the frame.
4772 Note that functions called here, esp. x_default_parameter can
4773 signal errors, for instance when a specified color name is
4774 undefined. We have to make sure that we're in a consistent state
4775 when this happens. */
4778 x_create_tip_frame (struct x_display_info
*dpyinfo
,
4786 ptrdiff_t count
= SPECPDL_INDEX ();
4787 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4788 int face_change_count_before
= face_change_count
;
4790 struct buffer
*old_buffer
;
4792 if (!dpyinfo
->terminal
->name
)
4793 error ("Terminal is not live, can't create new frames on it");
4795 parms
= Fcopy_alist (parms
);
4797 /* Get the name of the frame to use for resource lookup. */
4798 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
4800 && !EQ (name
, Qunbound
)
4802 error ("Invalid frame name--not a string or nil");
4805 GCPRO3 (parms
, name
, frame
);
4807 XSETFRAME (frame
, f
);
4809 buffer
= Fget_buffer_create (build_string (" *tip*"));
4810 /* Use set_window_buffer instead of Fset_window_buffer (see
4811 discussion of bug#11984, bug#12025, bug#12026). */
4812 set_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, 0, 0);
4813 old_buffer
= current_buffer
;
4814 set_buffer_internal_1 (XBUFFER (buffer
));
4815 bset_truncate_lines (current_buffer
, Qnil
);
4816 specbind (Qinhibit_read_only
, Qt
);
4817 specbind (Qinhibit_modification_hooks
, Qt
);
4820 set_buffer_internal_1 (old_buffer
);
4822 record_unwind_protect (unwind_create_tip_frame
, frame
);
4824 f
->terminal
= dpyinfo
->terminal
;
4826 /* By setting the output method, we're essentially saying that
4827 the frame is live, as per FRAME_LIVE_P. If we get a signal
4828 from this point on, x_destroy_window might screw up reference
4830 f
->output_method
= output_x_window
;
4831 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
4832 f
->output_data
.x
->icon_bitmap
= -1;
4833 FRAME_FONTSET (f
) = -1;
4834 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
4835 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
4836 #ifdef USE_TOOLKIT_SCROLL_BARS
4837 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
4838 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
4839 #endif /* USE_TOOLKIT_SCROLL_BARS */
4840 fset_icon_name (f
, Qnil
);
4841 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
4842 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4843 f
->output_data
.x
->explicit_parent
= 0;
4845 /* These colors will be set anyway later, but it's important
4846 to get the color reference counts right, so initialize them! */
4849 struct gcpro gcpro1
;
4851 /* Function x_decode_color can signal an error. Make
4852 sure to initialize color slots so that we won't try
4853 to free colors we haven't allocated. */
4854 FRAME_FOREGROUND_PIXEL (f
) = -1;
4855 FRAME_BACKGROUND_PIXEL (f
) = -1;
4856 f
->output_data
.x
->cursor_pixel
= -1;
4857 f
->output_data
.x
->cursor_foreground_pixel
= -1;
4858 f
->output_data
.x
->border_pixel
= -1;
4859 f
->output_data
.x
->mouse_pixel
= -1;
4861 black
= build_string ("black");
4863 FRAME_FOREGROUND_PIXEL (f
)
4864 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4865 FRAME_BACKGROUND_PIXEL (f
)
4866 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4867 f
->output_data
.x
->cursor_pixel
4868 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4869 f
->output_data
.x
->cursor_foreground_pixel
4870 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4871 f
->output_data
.x
->border_pixel
4872 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4873 f
->output_data
.x
->mouse_pixel
4874 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4878 /* Set the name; the functions to which we pass f expect the name to
4880 if (EQ (name
, Qunbound
) || NILP (name
))
4882 fset_name (f
, build_string (dpyinfo
->x_id_name
));
4883 f
->explicit_name
= 0;
4887 fset_name (f
, name
);
4888 f
->explicit_name
= 1;
4889 /* use the frame's title when getting resources for this frame. */
4890 specbind (Qx_resource_name
, name
);
4893 register_font_driver (&xfont_driver
, f
);
4894 #ifdef HAVE_FREETYPE
4896 register_font_driver (&xftfont_driver
, f
);
4897 #else /* not HAVE_XFT */
4898 register_font_driver (&ftxfont_driver
, f
);
4899 #endif /* not HAVE_XFT */
4900 #endif /* HAVE_FREETYPE */
4902 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
4903 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4905 /* Extract the window parameters from the supplied values that are
4906 needed to determine window geometry. */
4907 x_default_font_parameter (f
, parms
);
4909 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
4910 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
4912 /* This defaults to 2 in order to match xterm. We recognize either
4913 internalBorderWidth or internalBorder (which is what xterm calls
4915 if (NILP (Fassq (Qinternal_border_width
, parms
)))
4919 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
4920 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
4921 if (! EQ (value
, Qunbound
))
4922 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
4926 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
4927 "internalBorderWidth", "internalBorderWidth",
4930 /* Also do the stuff which must be set before the window exists. */
4931 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
4932 "foreground", "Foreground", RES_TYPE_STRING
);
4933 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
4934 "background", "Background", RES_TYPE_STRING
);
4935 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
4936 "pointerColor", "Foreground", RES_TYPE_STRING
);
4937 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
4938 "cursorColor", "Foreground", RES_TYPE_STRING
);
4939 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
4940 "borderColor", "BorderColor", RES_TYPE_STRING
);
4943 image_cache_refcount
=
4944 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
4945 dpyinfo_refcount
= dpyinfo
->reference_count
;
4946 #endif /* GLYPH_DEBUG */
4948 /* Init faces before x_default_parameter is called for scroll-bar
4949 parameters because that function calls x_set_scroll_bar_width,
4950 which calls change_frame_size, which calls Fset_window_buffer,
4951 which runs hooks, which call Fvertical_motion. At the end, we
4952 end up in init_iterator with a null face cache, which should not
4954 init_frame_faces (f
);
4956 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4958 x_figure_window_size (f
, parms
, 0);
4961 XSetWindowAttributes attrs
;
4963 Atom type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_net_window_type_tooltip
;
4966 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
;
4967 if (DoesSaveUnders (dpyinfo
->screen
))
4968 mask
|= CWSaveUnder
;
4970 /* Window managers look at the override-redirect flag to determine
4971 whether or net to give windows a decoration (Xlib spec, chapter
4973 attrs
.override_redirect
= True
;
4974 attrs
.save_under
= True
;
4975 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
4976 /* Arrange for getting MapNotify and UnmapNotify events. */
4977 attrs
.event_mask
= StructureNotifyMask
;
4979 = FRAME_X_WINDOW (f
)
4980 = XCreateWindow (FRAME_X_DISPLAY (f
),
4981 FRAME_X_DISPLAY_INFO (f
)->root_window
,
4982 /* x, y, width, height */
4986 CopyFromParent
, InputOutput
, CopyFromParent
,
4988 XChangeProperty (FRAME_X_DISPLAY (f
), tip_window
,
4989 FRAME_X_DISPLAY_INFO (f
)->Xatom_net_window_type
,
4990 XA_ATOM
, 32, PropModeReplace
,
4991 (unsigned char *)&type
, 1);
4997 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
4998 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
4999 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5000 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5001 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5002 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5004 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
5005 Change will not be effected unless different from the current
5007 width
= FRAME_COLS (f
);
5008 height
= FRAME_LINES (f
);
5009 SET_FRAME_COLS (f
, 0);
5010 FRAME_LINES (f
) = 0;
5011 change_frame_size (f
, height
, width
, 1, 0, 0);
5013 /* Add `tooltip' frame parameter's default value. */
5014 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5015 Fmodify_frame_parameters (frame
, list1 (Fcons (Qtooltip
, Qt
)));
5017 /* FIXME - can this be done in a similar way to normal frames?
5018 http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00641.html */
5020 /* Set the `display-type' frame parameter before setting up faces. */
5022 Lisp_Object disptype
;
5024 if (FRAME_X_DISPLAY_INFO (f
)->n_planes
== 1)
5025 disptype
= intern ("mono");
5026 else if (FRAME_X_DISPLAY_INFO (f
)->visual
->class == GrayScale
5027 || FRAME_X_DISPLAY_INFO (f
)->visual
->class == StaticGray
)
5028 disptype
= intern ("grayscale");
5030 disptype
= intern ("color");
5032 if (NILP (Fframe_parameter (frame
, Qdisplay_type
)))
5033 Fmodify_frame_parameters (frame
, list1 (Fcons (Qdisplay_type
, disptype
)));
5036 /* Set up faces after all frame parameters are known. This call
5037 also merges in face attributes specified for new frames.
5039 Frame parameters may be changed if .Xdefaults contains
5040 specifications for the default font. For example, if there is an
5041 `Emacs.default.attributeBackground: pink', the `background-color'
5042 attribute of the frame get's set, which let's the internal border
5043 of the tooltip frame appear in pink. Prevent this. */
5045 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5047 /* Set tip_frame here, so that */
5049 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5051 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5052 Fmodify_frame_parameters (frame
, list1 (Fcons (Qbackground_color
, bg
)));
5059 /* Now that the frame will be official, it counts as a reference to
5060 its display and terminal. */
5061 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
5062 f
->terminal
->reference_count
++;
5064 /* It is now ok to make the frame official even if we get an error
5065 below. And the frame needs to be on Vframe_list or making it
5066 visible won't work. */
5067 Vframe_list
= Fcons (frame
, Vframe_list
);
5070 /* Setting attributes of faces of the tooltip frame from resources
5071 and similar will increment face_change_count, which leads to the
5072 clearing of all current matrices. Since this isn't necessary
5073 here, avoid it by resetting face_change_count to the value it
5074 had before we created the tip frame. */
5075 face_change_count
= face_change_count_before
;
5077 /* Discard the unwind_protect. */
5078 return unbind_to (count
, frame
);
5082 /* Compute where to display tip frame F. PARMS is the list of frame
5083 parameters for F. DX and DY are specified offsets from the current
5084 location of the mouse. WIDTH and HEIGHT are the width and height
5085 of the tooltip. Return coordinates relative to the root window of
5086 the display in *ROOT_X, and *ROOT_Y. */
5089 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
)
5091 Lisp_Object left
, top
;
5096 /* User-specified position? */
5097 left
= Fcdr (Fassq (Qleft
, parms
));
5098 top
= Fcdr (Fassq (Qtop
, parms
));
5100 /* Move the tooltip window where the mouse pointer is. Resize and
5102 if (!INTEGERP (left
) || !INTEGERP (top
))
5105 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
5106 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
5111 *root_y
= XINT (top
);
5112 else if (*root_y
+ XINT (dy
) <= 0)
5113 *root_y
= 0; /* Can happen for negative dy */
5114 else if (*root_y
+ XINT (dy
) + height
5115 <= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
)))
5116 /* It fits below the pointer */
5117 *root_y
+= XINT (dy
);
5118 else if (height
+ XINT (dy
) <= *root_y
)
5119 /* It fits above the pointer. */
5120 *root_y
-= height
+ XINT (dy
);
5122 /* Put it on the top. */
5125 if (INTEGERP (left
))
5126 *root_x
= XINT (left
);
5127 else if (*root_x
+ XINT (dx
) <= 0)
5128 *root_x
= 0; /* Can happen for negative dx */
5129 else if (*root_x
+ XINT (dx
) + width
5130 <= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
)))
5131 /* It fits to the right of the pointer. */
5132 *root_x
+= XINT (dx
);
5133 else if (width
+ XINT (dx
) <= *root_x
)
5134 /* It fits to the left of the pointer. */
5135 *root_x
-= width
+ XINT (dx
);
5137 /* Put it left-justified on the screen--it ought to fit that way. */
5142 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5143 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
5144 A tooltip window is a small X window displaying a string.
5146 This is an internal function; Lisp code should call `tooltip-show'.
5148 FRAME nil or omitted means use the selected frame.
5150 PARMS is an optional list of frame parameters which can be used to
5151 change the tooltip's appearance.
5153 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5154 means use the default timeout of 5 seconds.
5156 If the list of frame parameters PARMS contains a `left' parameters,
5157 the tooltip is displayed at that x-position. Otherwise it is
5158 displayed at the mouse position, with offset DX added (default is 5 if
5159 DX isn't specified). Likewise for the y-position; if a `top' frame
5160 parameter is specified, it determines the y-position of the tooltip
5161 window, otherwise it is displayed at the mouse position, with offset
5162 DY added (default is -10).
5164 A tooltip's maximum size is specified by `x-max-tooltip-size'.
5165 Text larger than the specified size is clipped. */)
5166 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
5171 struct buffer
*old_buffer
;
5172 struct text_pos pos
;
5173 int i
, width
, height
, seen_reversed_p
;
5174 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5175 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5176 ptrdiff_t count
= SPECPDL_INDEX ();
5178 specbind (Qinhibit_redisplay
, Qt
);
5180 GCPRO4 (string
, parms
, frame
, timeout
);
5182 CHECK_STRING (string
);
5183 if (SCHARS (string
) == 0)
5184 string
= make_unibyte_string (" ", 1);
5186 f
= decode_window_system_frame (frame
);
5188 timeout
= make_number (5);
5190 CHECK_NATNUM (timeout
);
5193 dx
= make_number (5);
5198 dy
= make_number (-10);
5203 if (x_gtk_use_system_tooltips
)
5207 /* Hide a previous tip, if any. */
5211 ok
= xg_prepare_tooltip (f
, string
, &width
, &height
);
5214 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5215 xg_show_tooltip (f
, root_x
, root_y
);
5216 /* This is used in Fx_hide_tip. */
5217 XSETFRAME (tip_frame
, f
);
5220 if (ok
) goto start_timer
;
5222 #endif /* USE_GTK */
5224 if (NILP (last_show_tip_args
))
5225 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5227 if (!NILP (tip_frame
))
5229 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5230 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5231 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5233 if (EQ (frame
, last_frame
)
5234 && !NILP (Fequal (last_string
, string
))
5235 && !NILP (Fequal (last_parms
, parms
)))
5237 struct frame
*tip_f
= XFRAME (tip_frame
);
5239 /* Only DX and DY have changed. */
5240 if (!NILP (tip_timer
))
5242 Lisp_Object timer
= tip_timer
;
5244 call1 (Qcancel_timer
, timer
);
5248 compute_tip_xy (tip_f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (tip_f
),
5249 FRAME_PIXEL_HEIGHT (tip_f
), &root_x
, &root_y
);
5250 XMoveWindow (FRAME_X_DISPLAY (tip_f
), FRAME_X_WINDOW (tip_f
),
5257 /* Hide a previous tip, if any. */
5260 ASET (last_show_tip_args
, 0, string
);
5261 ASET (last_show_tip_args
, 1, frame
);
5262 ASET (last_show_tip_args
, 2, parms
);
5264 /* Add default values to frame parameters. */
5265 if (NILP (Fassq (Qname
, parms
)))
5266 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5267 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5268 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5269 if (NILP (Fassq (Qborder_width
, parms
)))
5270 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5271 if (NILP (Fassq (Qborder_color
, parms
)))
5272 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5273 if (NILP (Fassq (Qbackground_color
, parms
)))
5274 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5277 /* Create a frame for the tooltip, and record it in the global
5278 variable tip_frame. */
5279 frame
= x_create_tip_frame (FRAME_X_DISPLAY_INFO (f
), parms
, string
);
5282 /* Set up the frame's root window. */
5283 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5287 if (CONSP (Vx_max_tooltip_size
)
5288 && RANGED_INTEGERP (1, XCAR (Vx_max_tooltip_size
), INT_MAX
)
5289 && RANGED_INTEGERP (1, XCDR (Vx_max_tooltip_size
), INT_MAX
))
5291 w
->total_cols
= XFASTINT (XCAR (Vx_max_tooltip_size
));
5292 w
->total_lines
= XFASTINT (XCDR (Vx_max_tooltip_size
));
5297 w
->total_lines
= 40;
5300 FRAME_TOTAL_COLS (f
) = w
->total_cols
;
5301 adjust_frame_glyphs (f
);
5302 w
->pseudo_window_p
= 1;
5304 /* Display the tooltip text in a temporary buffer. */
5305 old_buffer
= current_buffer
;
5306 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->contents
));
5307 bset_truncate_lines (current_buffer
, Qnil
);
5308 clear_glyph_matrix (w
->desired_matrix
);
5309 clear_glyph_matrix (w
->current_matrix
);
5310 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5311 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5313 /* Compute width and height of the tooltip. */
5314 width
= height
= seen_reversed_p
= 0;
5315 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5317 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5321 /* Stop at the first empty row at the end. */
5322 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5325 /* Let the row go over the full width of the frame. */
5326 row
->full_width_p
= 1;
5328 row_width
= row
->pixel_width
;
5329 if (row
->used
[TEXT_AREA
])
5331 /* There's a glyph at the end of rows that is used to place
5332 the cursor there. Don't include the width of this glyph. */
5333 if (!row
->reversed_p
)
5335 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5336 if (INTEGERP (last
->object
))
5337 row_width
-= last
->pixel_width
;
5341 /* There could be a stretch glyph at the beginning of R2L
5342 rows that is produced by extend_face_to_end_of_line.
5343 Don't count that glyph. */
5344 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
5346 if (g
->type
== STRETCH_GLYPH
&& INTEGERP (g
->object
))
5348 row_width
-= g
->pixel_width
;
5349 seen_reversed_p
= 1;
5354 height
+= row
->height
;
5355 width
= max (width
, row_width
);
5358 /* If we've seen partial-length R2L rows, we need to re-adjust the
5359 tool-tip frame width and redisplay it again, to avoid over-wide
5360 tips due to the stretch glyph that extends R2L lines to full
5361 width of the frame. */
5362 if (seen_reversed_p
)
5364 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns,
5366 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
5367 w
->total_cols
= width
;
5368 FRAME_TOTAL_COLS (f
) = width
;
5369 adjust_frame_glyphs (f
);
5370 clear_glyph_matrix (w
->desired_matrix
);
5371 clear_glyph_matrix (w
->current_matrix
);
5372 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
5374 /* Recompute width and height of the tooltip. */
5375 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5377 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5381 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5383 row
->full_width_p
= 1;
5384 row_width
= row
->pixel_width
;
5385 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
5387 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5388 if (INTEGERP (last
->object
))
5389 row_width
-= last
->pixel_width
;
5392 height
+= row
->height
;
5393 width
= max (width
, row_width
);
5397 /* Add the frame's internal border to the width and height the X
5398 window should have. */
5399 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5400 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5402 /* Move the tooltip window where the mouse pointer is. Resize and
5404 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5407 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5408 root_x
, root_y
, width
, height
);
5409 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5412 /* Draw into the window. */
5413 w
->must_be_updated_p
= 1;
5414 update_single_window (w
, 1);
5416 /* Restore original current buffer. */
5417 set_buffer_internal_1 (old_buffer
);
5418 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5421 /* Let the tip disappear after timeout seconds. */
5422 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5423 intern ("x-hide-tip"));
5426 return unbind_to (count
, Qnil
);
5430 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5431 doc
: /* Hide the current tooltip window, if there is any.
5432 Value is t if tooltip was open, nil otherwise. */)
5436 Lisp_Object deleted
, frame
, timer
;
5437 struct gcpro gcpro1
, gcpro2
;
5439 /* Return quickly if nothing to do. */
5440 if (NILP (tip_timer
) && NILP (tip_frame
))
5445 GCPRO2 (frame
, timer
);
5446 tip_frame
= tip_timer
= deleted
= Qnil
;
5448 count
= SPECPDL_INDEX ();
5449 specbind (Qinhibit_redisplay
, Qt
);
5450 specbind (Qinhibit_quit
, Qt
);
5453 call1 (Qcancel_timer
, timer
);
5457 /* When using system tooltip, tip_frame is the Emacs frame on which
5458 the tip is shown. */
5459 struct frame
*f
= XFRAME (frame
);
5460 if (FRAME_LIVE_P (f
) && xg_hide_tooltip (f
))
5467 delete_frame (frame
, Qnil
);
5471 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5472 redisplay procedure is not called when a tip frame over menu
5473 items is unmapped. Redisplay the menu manually... */
5476 struct frame
*f
= SELECTED_FRAME ();
5477 w
= f
->output_data
.x
->menubar_widget
;
5479 if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f
)->screen
)
5483 xlwmenu_redisplay (w
);
5487 #endif /* USE_LUCID */
5491 return unbind_to (count
, deleted
);
5496 /***********************************************************************
5497 File selection dialog
5498 ***********************************************************************/
5500 DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog
,
5501 Sx_uses_old_gtk_dialog
,
5503 doc
: /* Return t if the old Gtk+ file selection dialog is used. */)
5509 && window_system_available (SELECTED_FRAME ())
5510 && xg_uses_old_file_dialog ())
5518 /* Callback for "OK" and "Cancel" on file selection dialog. */
5521 file_dialog_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5523 int *result
= client_data
;
5524 XmAnyCallbackStruct
*cb
= call_data
;
5525 *result
= cb
->reason
;
5529 /* Callback for unmapping a file selection dialog. This is used to
5530 capture the case where a dialog is closed via a window manager's
5531 closer button, for example. Using a XmNdestroyCallback didn't work
5535 file_dialog_unmap_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5537 int *result
= client_data
;
5538 *result
= XmCR_CANCEL
;
5542 clean_up_file_dialog (void *arg
)
5544 Widget dialog
= arg
;
5548 XtUnmanageChild (dialog
);
5549 XtDestroyWidget (dialog
);
5550 x_menu_set_in_use (0);
5555 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5556 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5557 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5558 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5559 or directory must exist.
5561 This function is only defined on NS, MS Windows, and X Windows with the
5562 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5563 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5564 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
,
5565 Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5568 struct frame
*f
= SELECTED_FRAME ();
5569 Lisp_Object file
= Qnil
;
5570 Lisp_Object decoded_file
;
5571 Widget dialog
, text
, help
;
5574 XmString dir_xmstring
, pattern_xmstring
;
5575 ptrdiff_t count
= SPECPDL_INDEX ();
5576 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5578 check_window_system (f
);
5580 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5582 if (popup_activated ())
5583 error ("Trying to use a menu from within a menu-entry");
5585 CHECK_STRING (prompt
);
5588 /* Prevent redisplay. */
5589 specbind (Qinhibit_redisplay
, Qt
);
5593 /* Create the dialog with PROMPT as title, using DIR as initial
5594 directory and using "*" as pattern. */
5595 dir
= Fexpand_file_name (dir
, Qnil
);
5596 dir_xmstring
= XmStringCreateLocalized (SSDATA (dir
));
5597 pattern_xmstring
= XmStringCreateLocalized ("*");
5599 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
5600 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
5601 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
5602 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
5603 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
5604 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
5606 XmStringFree (dir_xmstring
);
5607 XmStringFree (pattern_xmstring
);
5609 /* Add callbacks for OK and Cancel. */
5610 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
5611 (XtPointer
) &result
);
5612 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
5613 (XtPointer
) &result
);
5614 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
5615 (XtPointer
) &result
);
5617 /* Remove the help button since we can't display help. */
5618 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
5619 XtUnmanageChild (help
);
5621 /* Mark OK button as default. */
5622 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
5623 XmNshowAsDefault
, True
, NULL
);
5625 /* If MUSTMATCH is non-nil, disable the file entry field of the
5626 dialog, so that the user must select a file from the files list
5627 box. We can't remove it because we wouldn't have a way to get at
5628 the result file name, then. */
5629 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5630 if (!NILP (mustmatch
))
5633 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
5634 XtSetSensitive (text
, False
);
5635 XtSetSensitive (label
, False
);
5638 /* Manage the dialog, so that list boxes get filled. */
5639 XtManageChild (dialog
);
5641 if (STRINGP (default_filename
))
5643 XmString default_xmstring
;
5644 Widget wtext
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5645 Widget list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
5647 XmTextPosition last_pos
= XmTextFieldGetLastPosition (wtext
);
5648 XmTextFieldReplace (wtext
, 0, last_pos
,
5649 (SSDATA (Ffile_name_nondirectory (default_filename
))));
5651 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5652 must include the path for this to work. */
5654 default_xmstring
= XmStringCreateLocalized (SSDATA (default_filename
));
5656 if (XmListItemExists (list
, default_xmstring
))
5658 int item_pos
= XmListItemPos (list
, default_xmstring
);
5659 /* Select the item and scroll it into view. */
5660 XmListSelectPos (list
, item_pos
, True
);
5661 XmListSetPos (list
, item_pos
);
5664 XmStringFree (default_xmstring
);
5667 record_unwind_protect_ptr (clean_up_file_dialog
, dialog
);
5669 /* Process events until the user presses Cancel or OK. */
5670 x_menu_set_in_use (1);
5675 x_menu_wait_for_event (0);
5676 XtAppNextEvent (Xt_app_con
, &event
);
5677 if (event
.type
== KeyPress
5678 && FRAME_X_DISPLAY (f
) == event
.xkey
.display
)
5680 KeySym keysym
= XLookupKeysym (&event
.xkey
, 0);
5682 /* Pop down on C-g. */
5683 if (keysym
== XK_g
&& (event
.xkey
.state
& ControlMask
) != 0)
5684 XtUnmanageChild (dialog
);
5687 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
));
5690 /* Get the result. */
5691 if (result
== XmCR_OK
)
5693 XmString text_string
;
5696 XtVaGetValues (dialog
, XmNtextString
, &text_string
, NULL
);
5697 XmStringGetLtoR (text_string
, XmFONTLIST_DEFAULT_TAG
, &data
);
5698 XmStringFree (text_string
);
5699 file
= build_string (data
);
5708 /* Make "Cancel" equivalent to C-g. */
5710 Fsignal (Qquit
, Qnil
);
5712 decoded_file
= DECODE_FILE (file
);
5714 return unbind_to (count
, decoded_file
);
5717 #endif /* USE_MOTIF */
5722 clean_up_dialog (void)
5724 x_menu_set_in_use (0);
5727 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5728 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5729 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5730 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5731 or directory must exist.
5733 This function is only defined on NS, MS Windows, and X Windows with the
5734 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5735 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5736 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5738 struct frame
*f
= SELECTED_FRAME ();
5740 Lisp_Object file
= Qnil
;
5741 Lisp_Object decoded_file
;
5742 ptrdiff_t count
= SPECPDL_INDEX ();
5743 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5746 check_window_system (f
);
5748 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5750 if (popup_activated ())
5751 error ("Trying to use a menu from within a menu-entry");
5753 CHECK_STRING (prompt
);
5756 /* Prevent redisplay. */
5757 specbind (Qinhibit_redisplay
, Qt
);
5758 record_unwind_protect_void (clean_up_dialog
);
5762 if (STRINGP (default_filename
))
5763 cdef_file
= SSDATA (default_filename
);
5765 cdef_file
= SSDATA (dir
);
5767 fn
= xg_get_file_name (f
, SSDATA (prompt
), cdef_file
,
5769 ! NILP (only_dir_p
));
5773 file
= build_string (fn
);
5780 /* Make "Cancel" equivalent to C-g. */
5782 Fsignal (Qquit
, Qnil
);
5784 decoded_file
= DECODE_FILE (file
);
5786 return unbind_to (count
, decoded_file
);
5790 #ifdef HAVE_FREETYPE
5792 DEFUN ("x-select-font", Fx_select_font
, Sx_select_font
, 0, 2, 0,
5793 doc
: /* Read a font using a GTK dialog.
5794 Return either a font spec (for GTK versions >= 3.2) or a string
5795 containing a GTK-style font name.
5797 FRAME is the frame on which to pop up the font chooser. If omitted or
5798 nil, it defaults to the selected frame. */)
5799 (Lisp_Object frame
, Lisp_Object ignored
)
5801 struct frame
*f
= decode_window_system_frame (frame
);
5803 Lisp_Object font_param
;
5804 char *default_name
= NULL
;
5805 struct gcpro gcpro1
, gcpro2
;
5806 ptrdiff_t count
= SPECPDL_INDEX ();
5808 if (popup_activated ())
5809 error ("Trying to use a menu from within a menu-entry");
5811 /* Prevent redisplay. */
5812 specbind (Qinhibit_redisplay
, Qt
);
5813 record_unwind_protect_void (clean_up_dialog
);
5817 GCPRO2 (font_param
, font
);
5819 XSETFONT (font
, FRAME_FONT (f
));
5820 font_param
= Ffont_get (font
, intern (":name"));
5821 if (STRINGP (font_param
))
5822 default_name
= xstrdup (SSDATA (font_param
));
5825 font_param
= Fframe_parameter (frame
, Qfont_param
);
5826 if (STRINGP (font_param
))
5827 default_name
= xstrdup (SSDATA (font_param
));
5830 font
= xg_get_font (f
, default_name
);
5831 xfree (default_name
);
5836 Fsignal (Qquit
, Qnil
);
5838 return unbind_to (count
, font
);
5840 #endif /* HAVE_FREETYPE */
5842 #endif /* USE_GTK */
5845 /***********************************************************************
5847 ***********************************************************************/
5850 #include <X11/XKBlib.h>
5851 #include <X11/keysym.h>
5854 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
5855 Sx_backspace_delete_keys_p
, 0, 1, 0,
5856 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
5857 FRAME nil means use the selected frame.
5858 Value is t if we know that both keys are present, and are mapped to the
5859 usual X keysyms. Value is `lambda' if we cannot determine if both keys are
5860 present and mapped to the usual X keysyms. */)
5867 struct frame
*f
= decode_window_system_frame (frame
);
5868 Display
*dpy
= FRAME_X_DISPLAY (f
);
5869 Lisp_Object have_keys
;
5870 int major
, minor
, op
, event
, error_code
;
5874 /* Check library version in case we're dynamically linked. */
5875 major
= XkbMajorVersion
;
5876 minor
= XkbMinorVersion
;
5877 if (!XkbLibraryVersion (&major
, &minor
))
5883 /* Check that the server supports XKB. */
5884 major
= XkbMajorVersion
;
5885 minor
= XkbMinorVersion
;
5886 if (!XkbQueryExtension (dpy
, &op
, &event
, &error_code
, &major
, &minor
))
5892 /* In this code we check that the keyboard has physical keys with names
5893 that start with BKSP (Backspace) and DELE (Delete), and that they
5894 generate keysym XK_BackSpace and XK_Delete respectively.
5895 This function is used to test if normal-erase-is-backspace should be
5897 An alternative approach would be to just check if XK_BackSpace and
5898 XK_Delete are mapped to any key. But if any of those are mapped to
5899 some non-intuitive key combination (Meta-Shift-Ctrl-whatever) and the
5900 user doesn't know about it, it is better to return false here.
5901 It is more obvious to the user what to do if she/he has two keys
5902 clearly marked with names/symbols and one key does something not
5903 expected (i.e. she/he then tries the other).
5904 The cases where Backspace/Delete is mapped to some other key combination
5905 are rare, and in those cases, normal-erase-is-backspace can be turned on
5909 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
5912 int delete_keycode
= 0, backspace_keycode
= 0, i
;
5914 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
5916 for (i
= kb
->min_key_code
;
5917 (i
< kb
->max_key_code
5918 && (delete_keycode
== 0 || backspace_keycode
== 0));
5921 /* The XKB symbolic key names can be seen most easily in
5922 the PS file generated by `xkbprint -label name
5924 if (memcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
5926 else if (memcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
5927 backspace_keycode
= i
;
5930 XkbFreeNames (kb
, 0, True
);
5933 XkbFreeClientMap (kb
, 0, True
);
5936 && backspace_keycode
5937 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
5938 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
5948 /***********************************************************************
5950 ***********************************************************************/
5952 /* Keep this list in the same order as frame_parms in frame.c.
5953 Use 0 for unsupported frame parameters. */
5955 frame_parm_handler x_frame_parm_handlers
[] =
5959 x_set_background_color
,
5965 x_set_foreground_color
,
5968 x_set_internal_border_width
,
5969 x_set_menu_bar_lines
,
5971 x_explicitly_set_name
,
5972 x_set_scroll_bar_width
,
5975 x_set_vertical_scroll_bars
,
5977 x_set_tool_bar_lines
,
5978 x_set_scroll_bar_foreground
,
5979 x_set_scroll_bar_background
,
5989 x_set_tool_bar_position
,
5995 /* The section below is built by the lisp expression at the top of the file,
5996 just above where these variables are declared. */
5997 /*&&& init symbols here &&&*/
5998 DEFSYM (Qsuppress_icon
, "suppress-icon");
5999 DEFSYM (Qundefined_color
, "undefined-color");
6000 DEFSYM (Qcompound_text
, "compound-text");
6001 DEFSYM (Qcancel_timer
, "cancel-timer");
6002 DEFSYM (Qfont_param
, "font-parameter");
6003 /* This is the end of symbol initialization. */
6005 Fput (Qundefined_color
, Qerror_conditions
,
6006 listn (CONSTYPE_PURE
, 2, Qundefined_color
, Qerror
));
6007 Fput (Qundefined_color
, Qerror_message
,
6008 build_pure_c_string ("Undefined color"));
6010 DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape
,
6011 doc
: /* The shape of the pointer when over text.
6012 Changing the value does not affect existing frames
6013 unless you set the mouse color. */);
6014 Vx_pointer_shape
= Qnil
;
6016 #if 0 /* This doesn't really do anything. */
6017 DEFVAR_LISP ("x-nontext-pointer-shape", Vx_nontext_pointer_shape
,
6018 doc
: /* The shape of the pointer when not over text.
6019 This variable takes effect when you create a new frame
6020 or when you set the mouse color. */);
6022 Vx_nontext_pointer_shape
= Qnil
;
6024 DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape
,
6025 doc
: /* The shape of the pointer when Emacs is busy.
6026 This variable takes effect when you create a new frame
6027 or when you set the mouse color. */);
6028 Vx_hourglass_pointer_shape
= Qnil
;
6030 #if 0 /* This doesn't really do anything. */
6031 DEFVAR_LISP ("x-mode-pointer-shape", Vx_mode_pointer_shape
,
6032 doc
: /* The shape of the pointer when over the mode line.
6033 This variable takes effect when you create a new frame
6034 or when you set the mouse color. */);
6036 Vx_mode_pointer_shape
= Qnil
;
6038 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
6039 Vx_sensitive_text_pointer_shape
,
6040 doc
: /* The shape of the pointer when over mouse-sensitive text.
6041 This variable takes effect when you create a new frame
6042 or when you set the mouse color. */);
6043 Vx_sensitive_text_pointer_shape
= Qnil
;
6045 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
6046 Vx_window_horizontal_drag_shape
,
6047 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
6048 This variable takes effect when you create a new frame
6049 or when you set the mouse color. */);
6050 Vx_window_horizontal_drag_shape
= Qnil
;
6052 DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel
,
6053 doc
: /* A string indicating the foreground color of the cursor box. */);
6054 Vx_cursor_fore_pixel
= Qnil
;
6056 DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size
,
6057 doc
: /* Maximum size for tooltips.
6058 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
6059 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
6061 DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager
,
6062 doc
: /* Non-nil if no X window manager is in use.
6063 Emacs doesn't try to figure this out; this is always nil
6064 unless you set it to something else. */);
6065 /* We don't have any way to find this out, so set it to nil
6066 and maybe the user would like to set it to t. */
6067 Vx_no_window_manager
= Qnil
;
6069 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
6070 Vx_pixel_size_width_font_regexp
,
6071 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
6073 Since Emacs gets width of a font matching with this regexp from
6074 PIXEL_SIZE field of the name, font finding mechanism gets faster for
6075 such a font. This is especially effective for such large fonts as
6076 Chinese, Japanese, and Korean. */);
6077 Vx_pixel_size_width_font_regexp
= Qnil
;
6079 /* This is not ifdef:ed, so other builds than GTK can customize it. */
6080 DEFVAR_BOOL ("x-gtk-use-old-file-dialog", x_gtk_use_old_file_dialog
,
6081 doc
: /* Non-nil means prompt with the old GTK file selection dialog.
6082 If nil or if the file selection dialog is not available, the new GTK file
6083 chooser is used instead. To turn off all file dialogs set the
6084 variable `use-file-dialog'. */);
6085 x_gtk_use_old_file_dialog
= 0;
6087 DEFVAR_BOOL ("x-gtk-show-hidden-files", x_gtk_show_hidden_files
,
6088 doc
: /* If non-nil, the GTK file chooser will by default show hidden files.
6089 Note that this is just the default, there is a toggle button on the file
6090 chooser to show or not show hidden files on a case by case basis. */);
6091 x_gtk_show_hidden_files
= 0;
6093 DEFVAR_BOOL ("x-gtk-file-dialog-help-text", x_gtk_file_dialog_help_text
,
6094 doc
: /* If non-nil, the GTK file chooser will show additional help text.
6095 If more space for files in the file chooser dialog is wanted, set this to nil
6096 to turn the additional text off. */);
6097 x_gtk_file_dialog_help_text
= 1;
6099 DEFVAR_BOOL ("x-gtk-whole-detached-tool-bar", x_gtk_whole_detached_tool_bar
,
6100 doc
: /* If non-nil, a detached tool bar is shown in full.
6101 The default is to just show an arrow and pressing on that arrow shows
6102 the tool bar buttons. */);
6103 x_gtk_whole_detached_tool_bar
= 0;
6105 DEFVAR_BOOL ("x-gtk-use-system-tooltips", x_gtk_use_system_tooltips
,
6106 doc
: /* If non-nil with a Gtk+ built Emacs, the Gtk+ tooltip is used.
6107 Otherwise use Emacs own tooltip implementation.
6108 When using Gtk+ tooltips, the tooltip face is not used. */);
6109 x_gtk_use_system_tooltips
= 1;
6111 /* Tell Emacs about this window system. */
6112 Fprovide (Qx
, Qnil
);
6114 #ifdef USE_X_TOOLKIT
6115 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
6117 Fprovide (intern_c_string ("motif"), Qnil
);
6119 DEFVAR_LISP ("motif-version-string", Vmotif_version_string
,
6120 doc
: /* Version info for LessTif/Motif. */);
6121 Vmotif_version_string
= build_string (XmVERSION_STRING
);
6122 #endif /* USE_MOTIF */
6123 #endif /* USE_X_TOOLKIT */
6126 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
6127 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
6128 But for a user it is a toolkit for X, and indeed, configure
6129 accepts --with-x-toolkit=gtk. */
6130 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
6131 Fprovide (intern_c_string ("gtk"), Qnil
);
6132 Fprovide (intern_c_string ("move-toolbar"), Qnil
);
6134 DEFVAR_LISP ("gtk-version-string", Vgtk_version_string
,
6135 doc
: /* Version info for GTK+. */);
6137 char gtk_version
[sizeof ".." + 3 * INT_STRLEN_BOUND (int)];
6138 int len
= sprintf (gtk_version
, "%d.%d.%d",
6139 GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
);
6140 Vgtk_version_string
= make_pure_string (gtk_version
, len
, len
, 0);
6142 #endif /* USE_GTK */
6144 /* X window properties. */
6145 defsubr (&Sx_change_window_property
);
6146 defsubr (&Sx_delete_window_property
);
6147 defsubr (&Sx_window_property
);
6149 defsubr (&Sxw_display_color_p
);
6150 defsubr (&Sx_display_grayscale_p
);
6151 defsubr (&Sxw_color_defined_p
);
6152 defsubr (&Sxw_color_values
);
6153 defsubr (&Sx_server_max_request_size
);
6154 defsubr (&Sx_server_vendor
);
6155 defsubr (&Sx_server_version
);
6156 defsubr (&Sx_display_pixel_width
);
6157 defsubr (&Sx_display_pixel_height
);
6158 defsubr (&Sx_display_mm_width
);
6159 defsubr (&Sx_display_mm_height
);
6160 defsubr (&Sx_display_screens
);
6161 defsubr (&Sx_display_planes
);
6162 defsubr (&Sx_display_color_cells
);
6163 defsubr (&Sx_display_visual_class
);
6164 defsubr (&Sx_display_backing_store
);
6165 defsubr (&Sx_display_save_under
);
6166 defsubr (&Sx_display_monitor_attributes_list
);
6167 defsubr (&Sx_wm_set_size_hint
);
6168 defsubr (&Sx_create_frame
);
6169 defsubr (&Sx_open_connection
);
6170 defsubr (&Sx_close_connection
);
6171 defsubr (&Sx_display_list
);
6172 defsubr (&Sx_synchronize
);
6173 defsubr (&Sx_focus_frame
);
6174 defsubr (&Sx_backspace_delete_keys_p
);
6176 defsubr (&Sx_show_tip
);
6177 defsubr (&Sx_hide_tip
);
6179 staticpro (&tip_timer
);
6181 staticpro (&tip_frame
);
6183 last_show_tip_args
= Qnil
;
6184 staticpro (&last_show_tip_args
);
6186 defsubr (&Sx_uses_old_gtk_dialog
);
6187 #if defined (USE_MOTIF) || defined (USE_GTK)
6188 defsubr (&Sx_file_dialog
);
6191 #if defined (USE_GTK) && defined (HAVE_FREETYPE)
6192 defsubr (&Sx_select_font
);
6196 #endif /* HAVE_X_WINDOWS */