1 /* Functions for the X window system.
3 Copyright (C) 1989, 1992-2014 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
30 #include "character.h"
32 #include "intervals.h"
33 #include "dispextern.h"
35 #include "blockinput.h"
41 #include "termhooks.h"
46 #include <sys/types.h>
49 #if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */
50 #include "bitmaps/gray.xbm"
52 #include <X11/bitmaps/gray>
55 #include "xsettings.h"
58 #include <X11/extensions/Xrandr.h>
61 #include <X11/extensions/Xinerama.h>
69 #include <X11/Shell.h>
73 #include <X11/Xaw3d/Paned.h>
74 #include <X11/Xaw3d/Label.h>
75 #else /* !HAVE_XAW3D */
76 #include <X11/Xaw/Paned.h>
77 #include <X11/Xaw/Label.h>
78 #endif /* HAVE_XAW3D */
79 #endif /* USE_MOTIF */
82 #undef USG /* ####KLUDGE for Solaris 2.2 and up */
85 #ifdef USG /* Pacify gcc -Wunused-macros. */
93 #include "../lwlib/lwlib.h"
97 #include <Xm/DialogS.h>
98 #include <Xm/FileSB.h>
100 #include <Xm/TextF.h>
104 #include "../lwlib/xlwmenu.h"
107 #if !defined (NO_EDITRES)
109 extern void _XEditResCheckMessages (Widget
, XtPointer
, XEvent
*, Boolean
*);
110 #endif /* not defined NO_EDITRES */
112 /* Unique id counter for widgets created by the Lucid Widget Library. */
114 extern LWLIB_ID widget_id_tick
;
118 #endif /* USE_MOTIF */
120 #endif /* USE_X_TOOLKIT */
126 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
128 static Lisp_Object Qsuppress_icon
;
129 static Lisp_Object Qundefined_color
;
130 static Lisp_Object Qcompound_text
, Qcancel_timer
;
131 Lisp_Object Qfont_param
;
134 static ptrdiff_t image_cache_refcount
;
135 static int dpyinfo_refcount
;
138 static struct x_display_info
*x_display_info_for_name (Lisp_Object
);
140 /* Let the user specify an X display with a Lisp object.
141 OBJECT may be nil, a frame or a terminal object.
142 nil stands for the selected frame--or, if that is not an X frame,
143 the first X display on the list. */
145 struct x_display_info
*
146 check_x_display_info (Lisp_Object object
)
148 struct x_display_info
*dpyinfo
= NULL
;
152 struct frame
*sf
= XFRAME (selected_frame
);
154 if (FRAME_X_P (sf
) && FRAME_LIVE_P (sf
))
155 dpyinfo
= FRAME_DISPLAY_INFO (sf
);
156 else if (x_display_list
!= 0)
157 dpyinfo
= x_display_list
;
159 error ("X windows are not in use or not initialized");
161 else if (TERMINALP (object
))
163 struct terminal
*t
= get_terminal (object
, 1);
165 if (t
->type
!= output_x_window
)
166 error ("Terminal %d is not an X display", t
->id
);
168 dpyinfo
= t
->display_info
.x
;
170 else if (STRINGP (object
))
171 dpyinfo
= x_display_info_for_name (object
);
174 struct frame
*f
= decode_window_system_frame (object
);
175 dpyinfo
= FRAME_DISPLAY_INFO (f
);
181 /* Store the screen positions of frame F into XPTR and YPTR.
182 These are the positions of the containing window manager window,
183 not Emacs's own window. */
186 x_real_positions (struct frame
*f
, int *xptr
, int *yptr
)
188 int win_x
, win_y
, outer_x
IF_LINT (= 0), outer_y
IF_LINT (= 0);
189 int real_x
= 0, real_y
= 0;
191 Window win
= f
->output_data
.x
->parent_desc
;
193 unsigned long actual_size
, bytes_remaining
;
194 int rc
, actual_format
;
195 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
197 Display
*dpy
= FRAME_X_DISPLAY (f
);
198 unsigned char *tmp_data
= NULL
;
199 Atom target_type
= XA_CARDINAL
;
203 x_catch_errors (dpy
);
205 if (win
== dpyinfo
->root_window
)
206 win
= FRAME_OUTER_WINDOW (f
);
208 /* This loop traverses up the containment tree until we hit the root
209 window. Window managers may intersect many windows between our window
210 and the root window. The window we find just before the root window
211 should be the outer WM window. */
214 Window wm_window
, rootw
;
215 Window
*tmp_children
;
216 unsigned int tmp_nchildren
;
219 success
= XQueryTree (FRAME_X_DISPLAY (f
), win
, &rootw
,
220 &wm_window
, &tmp_children
, &tmp_nchildren
);
222 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
224 /* Don't free tmp_children if XQueryTree failed. */
228 XFree (tmp_children
);
230 if (wm_window
== rootw
|| had_errors
)
241 /* Get the real coordinates for the WM window upper left corner */
242 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
243 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
245 /* Translate real coordinates to coordinates relative to our
246 window. For our window, the upper left corner is 0, 0.
247 Since the upper left corner of the WM window is outside
248 our window, win_x and win_y will be negative:
250 ------------------ ---> x
252 | ----------------- v y
255 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
257 /* From-window, to-window. */
258 FRAME_DISPLAY_INFO (f
)->root_window
,
261 /* From-position, to-position. */
262 real_x
, real_y
, &win_x
, &win_y
,
267 if (FRAME_X_WINDOW (f
) == FRAME_OUTER_WINDOW (f
))
274 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
276 /* From-window, to-window. */
277 FRAME_DISPLAY_INFO (f
)->root_window
,
278 FRAME_OUTER_WINDOW (f
),
280 /* From-position, to-position. */
281 real_x
, real_y
, &outer_x
, &outer_y
,
287 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
291 if (dpyinfo
->root_window
== f
->output_data
.x
->parent_desc
)
293 /* Try _NET_FRAME_EXTENTS if our parent is the root window. */
294 rc
= XGetWindowProperty (dpy
, win
, dpyinfo
->Xatom_net_frame_extents
,
295 0, max_len
, False
, target_type
,
296 &actual_type
, &actual_format
, &actual_size
,
297 &bytes_remaining
, &tmp_data
);
299 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
300 && actual_size
== 4 && actual_format
== 32)
304 long *fe
= (long *)tmp_data
;
306 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
307 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
315 if (tmp_data
) XFree (tmp_data
);
321 if (had_errors
) return;
323 f
->x_pixels_diff
= -win_x
;
324 f
->y_pixels_diff
= -win_y
;
326 FRAME_X_OUTPUT (f
)->x_pixels_outer_diff
= -outer_x
;
327 FRAME_X_OUTPUT (f
)->y_pixels_outer_diff
= -outer_y
;
336 /* Gamma-correct COLOR on frame F. */
339 gamma_correct (struct frame
*f
, XColor
*color
)
343 color
->red
= pow (color
->red
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
344 color
->green
= pow (color
->green
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
345 color
->blue
= pow (color
->blue
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
350 /* Decide if color named COLOR_NAME is valid for use on frame F. If
351 so, return the RGB values in COLOR. If ALLOC_P,
352 allocate the color. Value is false if COLOR_NAME is invalid, or
353 no color could be allocated. */
356 x_defined_color (struct frame
*f
, const char *color_name
,
357 XColor
*color
, bool alloc_p
)
360 Display
*dpy
= FRAME_X_DISPLAY (f
);
361 Colormap cmap
= FRAME_X_COLORMAP (f
);
365 success_p
= xg_check_special_colors (f
, color_name
, color
);
368 success_p
= XParseColor (dpy
, cmap
, color_name
, color
) != 0;
369 if (success_p
&& alloc_p
)
370 success_p
= x_alloc_nearest_color (f
, cmap
, color
);
377 /* Return the pixel color value for color COLOR_NAME on frame F. If F
378 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
379 Signal an error if color can't be allocated. */
382 x_decode_color (struct frame
*f
, Lisp_Object color_name
, int mono_color
)
386 CHECK_STRING (color_name
);
388 #if 0 /* Don't do this. It's wrong when we're not using the default
389 colormap, it makes freeing difficult, and it's probably not
390 an important optimization. */
391 if (strcmp (SDATA (color_name
), "black") == 0)
392 return BLACK_PIX_DEFAULT (f
);
393 else if (strcmp (SDATA (color_name
), "white") == 0)
394 return WHITE_PIX_DEFAULT (f
);
397 /* Return MONO_COLOR for monochrome frames. */
398 if (FRAME_DISPLAY_INFO (f
)->n_planes
== 1)
401 /* x_defined_color is responsible for coping with failures
402 by looking for a near-miss. */
403 if (x_defined_color (f
, SSDATA (color_name
), &cdef
, 1))
406 signal_error ("Undefined color", color_name
);
411 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
412 the previous value of that parameter, NEW_VALUE is the new value.
413 See also the comment of wait_for_wm in struct x_output. */
416 x_set_wait_for_wm (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
418 f
->output_data
.x
->wait_for_wm
= !NILP (new_value
);
422 x_set_tool_bar_position (struct frame
*f
,
423 Lisp_Object new_value
,
424 Lisp_Object old_value
)
426 if (! EQ (new_value
, Qleft
) && ! EQ (new_value
, Qright
)
427 && ! EQ (new_value
, Qbottom
) && ! EQ (new_value
, Qtop
))
429 if (EQ (new_value
, old_value
)) return;
432 xg_change_toolbar_position (f
, new_value
);
433 fset_tool_bar_position (f
, new_value
);
439 /* Set icon from FILE for frame F. By using GTK functions the icon
440 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
443 xg_set_icon (struct frame
*f
, Lisp_Object file
)
448 found
= x_find_image_file (file
);
454 char *filename
= SSDATA (found
);
457 pixbuf
= gdk_pixbuf_new_from_file (filename
, &err
);
461 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
463 g_object_unref (pixbuf
);
477 xg_set_icon_from_xpm_data (struct frame
*f
, const char **data
)
479 GdkPixbuf
*pixbuf
= gdk_pixbuf_new_from_xpm_data (data
);
484 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)), pixbuf
);
485 g_object_unref (pixbuf
);
491 /* Functions called only from `x_set_frame_param'
492 to set individual parameters.
494 If FRAME_X_WINDOW (f) is 0,
495 the frame is being created and its X-window does not exist yet.
496 In that case, just record the parameter's new value
497 in the standard place; do not attempt to change the window. */
500 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
502 struct x_output
*x
= f
->output_data
.x
;
503 unsigned long fg
, old_fg
;
505 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
506 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
507 FRAME_FOREGROUND_PIXEL (f
) = fg
;
509 if (FRAME_X_WINDOW (f
) != 0)
511 Display
*dpy
= FRAME_X_DISPLAY (f
);
514 XSetForeground (dpy
, x
->normal_gc
, fg
);
515 XSetBackground (dpy
, x
->reverse_gc
, fg
);
517 if (x
->cursor_pixel
== old_fg
)
519 unload_color (f
, x
->cursor_pixel
);
520 x
->cursor_pixel
= x_copy_color (f
, fg
);
521 XSetBackground (dpy
, x
->cursor_gc
, x
->cursor_pixel
);
526 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
528 if (FRAME_VISIBLE_P (f
))
532 unload_color (f
, old_fg
);
536 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
538 struct x_output
*x
= f
->output_data
.x
;
541 bg
= x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
542 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
543 FRAME_BACKGROUND_PIXEL (f
) = bg
;
545 if (FRAME_X_WINDOW (f
) != 0)
547 Display
*dpy
= FRAME_X_DISPLAY (f
);
550 XSetBackground (dpy
, x
->normal_gc
, bg
);
551 XSetForeground (dpy
, x
->reverse_gc
, bg
);
552 XSetWindowBackground (dpy
, FRAME_X_WINDOW (f
), bg
);
553 XSetForeground (dpy
, x
->cursor_gc
, bg
);
556 xg_set_background_color (f
, bg
);
559 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
560 toolkit scroll bars. */
563 for (bar
= FRAME_SCROLL_BARS (f
);
565 bar
= XSCROLL_BAR (bar
)->next
)
567 Window window
= XSCROLL_BAR (bar
)->x_window
;
568 XSetWindowBackground (dpy
, window
, bg
);
571 #endif /* USE_TOOLKIT_SCROLL_BARS */
574 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
576 if (FRAME_VISIBLE_P (f
))
582 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
584 struct x_output
*x
= f
->output_data
.x
;
585 Display
*dpy
= FRAME_X_DISPLAY (f
);
586 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
587 Cursor hourglass_cursor
, horizontal_drag_cursor
, vertical_drag_cursor
;
588 unsigned long pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
589 unsigned long mask_color
= FRAME_BACKGROUND_PIXEL (f
);
591 /* Don't let pointers be invisible. */
592 if (mask_color
== pixel
)
594 x_free_colors (f
, &pixel
, 1);
595 pixel
= x_copy_color (f
, FRAME_FOREGROUND_PIXEL (f
));
598 unload_color (f
, x
->mouse_pixel
);
599 x
->mouse_pixel
= pixel
;
603 /* It's not okay to crash if the user selects a screwy cursor. */
604 x_catch_errors (dpy
);
606 if (!NILP (Vx_pointer_shape
))
608 CHECK_NUMBER (Vx_pointer_shape
);
609 cursor
= XCreateFontCursor (dpy
, XINT (Vx_pointer_shape
));
612 cursor
= XCreateFontCursor (dpy
, XC_xterm
);
613 x_check_errors (dpy
, "bad text pointer cursor: %s");
615 if (!NILP (Vx_nontext_pointer_shape
))
617 CHECK_NUMBER (Vx_nontext_pointer_shape
);
619 = XCreateFontCursor (dpy
, XINT (Vx_nontext_pointer_shape
));
622 nontext_cursor
= XCreateFontCursor (dpy
, XC_left_ptr
);
623 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
625 if (!NILP (Vx_hourglass_pointer_shape
))
627 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
629 = XCreateFontCursor (dpy
, XINT (Vx_hourglass_pointer_shape
));
632 hourglass_cursor
= XCreateFontCursor (dpy
, XC_watch
);
633 x_check_errors (dpy
, "bad hourglass pointer cursor: %s");
635 if (!NILP (Vx_mode_pointer_shape
))
637 CHECK_NUMBER (Vx_mode_pointer_shape
);
638 mode_cursor
= XCreateFontCursor (dpy
, XINT (Vx_mode_pointer_shape
));
641 mode_cursor
= XCreateFontCursor (dpy
, XC_xterm
);
642 x_check_errors (dpy
, "bad modeline pointer cursor: %s");
644 if (!NILP (Vx_sensitive_text_pointer_shape
))
646 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
648 = XCreateFontCursor (dpy
, XINT (Vx_sensitive_text_pointer_shape
));
651 hand_cursor
= XCreateFontCursor (dpy
, XC_hand2
);
653 if (!NILP (Vx_window_horizontal_drag_shape
))
655 CHECK_TYPE_RANGED_INTEGER (unsigned, Vx_window_horizontal_drag_shape
);
656 horizontal_drag_cursor
657 = XCreateFontCursor (dpy
, XINT (Vx_window_horizontal_drag_shape
));
660 horizontal_drag_cursor
661 = XCreateFontCursor (dpy
, XC_sb_h_double_arrow
);
663 if (!NILP (Vx_window_vertical_drag_shape
))
665 CHECK_NUMBER (Vx_window_vertical_drag_shape
);
667 = XCreateFontCursor (dpy
, XINT (Vx_window_vertical_drag_shape
));
671 = XCreateFontCursor (dpy
, XC_sb_v_double_arrow
);
673 /* Check and report errors with the above calls. */
674 x_check_errors (dpy
, "can't set cursor shape: %s");
678 XColor fore_color
, back_color
;
680 fore_color
.pixel
= x
->mouse_pixel
;
681 x_query_color (f
, &fore_color
);
682 back_color
.pixel
= mask_color
;
683 x_query_color (f
, &back_color
);
685 XRecolorCursor (dpy
, cursor
, &fore_color
, &back_color
);
686 XRecolorCursor (dpy
, nontext_cursor
, &fore_color
, &back_color
);
687 XRecolorCursor (dpy
, mode_cursor
, &fore_color
, &back_color
);
688 XRecolorCursor (dpy
, hand_cursor
, &fore_color
, &back_color
);
689 XRecolorCursor (dpy
, hourglass_cursor
, &fore_color
, &back_color
);
690 XRecolorCursor (dpy
, horizontal_drag_cursor
, &fore_color
, &back_color
);
691 XRecolorCursor (dpy
, vertical_drag_cursor
, &fore_color
, &back_color
);
694 if (FRAME_X_WINDOW (f
) != 0)
695 XDefineCursor (dpy
, FRAME_X_WINDOW (f
),
696 f
->output_data
.x
->current_cursor
= cursor
);
698 if (cursor
!= x
->text_cursor
699 && x
->text_cursor
!= 0)
700 XFreeCursor (dpy
, x
->text_cursor
);
701 x
->text_cursor
= cursor
;
703 if (nontext_cursor
!= x
->nontext_cursor
704 && x
->nontext_cursor
!= 0)
705 XFreeCursor (dpy
, x
->nontext_cursor
);
706 x
->nontext_cursor
= nontext_cursor
;
708 if (hourglass_cursor
!= x
->hourglass_cursor
709 && x
->hourglass_cursor
!= 0)
710 XFreeCursor (dpy
, x
->hourglass_cursor
);
711 x
->hourglass_cursor
= hourglass_cursor
;
713 if (mode_cursor
!= x
->modeline_cursor
714 && x
->modeline_cursor
!= 0)
715 XFreeCursor (dpy
, f
->output_data
.x
->modeline_cursor
);
716 x
->modeline_cursor
= mode_cursor
;
718 if (hand_cursor
!= x
->hand_cursor
719 && x
->hand_cursor
!= 0)
720 XFreeCursor (dpy
, x
->hand_cursor
);
721 x
->hand_cursor
= hand_cursor
;
723 if (horizontal_drag_cursor
!= x
->horizontal_drag_cursor
724 && x
->horizontal_drag_cursor
!= 0)
725 XFreeCursor (dpy
, x
->horizontal_drag_cursor
);
726 x
->horizontal_drag_cursor
= horizontal_drag_cursor
;
728 if (vertical_drag_cursor
!= x
->vertical_drag_cursor
729 && x
->vertical_drag_cursor
!= 0)
730 XFreeCursor (dpy
, x
->vertical_drag_cursor
);
731 x
->vertical_drag_cursor
= vertical_drag_cursor
;
736 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
740 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
742 unsigned long fore_pixel
, pixel
;
743 bool fore_pixel_allocated_p
= 0, pixel_allocated_p
= 0;
744 struct x_output
*x
= f
->output_data
.x
;
746 if (!NILP (Vx_cursor_fore_pixel
))
748 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
749 WHITE_PIX_DEFAULT (f
));
750 fore_pixel_allocated_p
= 1;
753 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
755 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
756 pixel_allocated_p
= 1;
758 /* Make sure that the cursor color differs from the background color. */
759 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
761 if (pixel_allocated_p
)
763 x_free_colors (f
, &pixel
, 1);
764 pixel_allocated_p
= 0;
767 pixel
= x
->mouse_pixel
;
768 if (pixel
== fore_pixel
)
770 if (fore_pixel_allocated_p
)
772 x_free_colors (f
, &fore_pixel
, 1);
773 fore_pixel_allocated_p
= 0;
775 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
779 unload_color (f
, x
->cursor_foreground_pixel
);
780 if (!fore_pixel_allocated_p
)
781 fore_pixel
= x_copy_color (f
, fore_pixel
);
782 x
->cursor_foreground_pixel
= fore_pixel
;
784 unload_color (f
, x
->cursor_pixel
);
785 if (!pixel_allocated_p
)
786 pixel
= x_copy_color (f
, pixel
);
787 x
->cursor_pixel
= pixel
;
789 if (FRAME_X_WINDOW (f
) != 0)
792 XSetBackground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, x
->cursor_pixel
);
793 XSetForeground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, fore_pixel
);
796 if (FRAME_VISIBLE_P (f
))
798 x_update_cursor (f
, 0);
799 x_update_cursor (f
, 1);
803 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
806 /* Set the border-color of frame F to pixel value PIX.
807 Note that this does not fully take effect if done before
808 F has an x-window. */
811 x_set_border_pixel (struct frame
*f
, int pix
)
813 unload_color (f
, f
->output_data
.x
->border_pixel
);
814 f
->output_data
.x
->border_pixel
= pix
;
816 if (FRAME_X_WINDOW (f
) != 0 && f
->border_width
> 0)
819 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), pix
);
822 if (FRAME_VISIBLE_P (f
))
827 /* Set the border-color of frame F to value described by ARG.
828 ARG can be a string naming a color.
829 The border-color is used for the border that is drawn by the X server.
830 Note that this does not fully take effect if done before
831 F has an x-window; it must be redone when the window is created.
833 Note: this is done in two routines because of the way X10 works.
835 Note: under X11, this is normally the province of the window manager,
836 and so emacs's border colors may be overridden. */
839 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
844 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
845 x_set_border_pixel (f
, pix
);
846 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
851 x_set_cursor_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
853 set_frame_cursor_types (f
, arg
);
857 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
863 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
866 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
871 result
= x_text_icon (f
,
872 SSDATA ((!NILP (f
->icon_name
)
876 result
= x_bitmap_icon (f
, arg
);
881 error ("No icon window available");
884 XFlush (FRAME_X_DISPLAY (f
));
889 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
895 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
898 else if (!NILP (arg
) || NILP (oldval
))
901 fset_icon_name (f
, arg
);
903 if (f
->output_data
.x
->icon_bitmap
!= 0)
908 result
= x_text_icon (f
,
909 SSDATA ((!NILP (f
->icon_name
)
918 error ("No icon window available");
921 XFlush (FRAME_X_DISPLAY (f
));
927 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
930 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
931 int olines
= FRAME_MENU_BAR_LINES (f
);
934 /* Right now, menu bars don't work properly in minibuf-only frames;
935 most of the commands try to apply themselves to the minibuffer
936 frame itself, and get an error because you can't switch buffers
937 in or split the minibuffer window. */
938 if (FRAME_MINIBUF_ONLY_P (f
))
941 if (TYPE_RANGED_INTEGERP (int, value
))
942 nlines
= XINT (value
);
946 /* Make sure we redisplay all windows in this frame. */
947 windows_or_buffers_changed
= 59;
949 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
950 FRAME_MENU_BAR_LINES (f
) = 0;
951 FRAME_MENU_BAR_HEIGHT (f
) = 0;
954 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
955 if (FRAME_X_P (f
) && f
->output_data
.x
->menubar_widget
== 0)
956 /* Make sure next redisplay shows the menu bar. */
957 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= 1;
961 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
962 free_frame_menubar (f
);
963 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
965 f
->output_data
.x
->menubar_widget
= 0;
967 #else /* not USE_X_TOOLKIT && not USE_GTK */
968 FRAME_MENU_BAR_LINES (f
) = nlines
;
969 FRAME_MENU_BAR_HEIGHT (f
) = nlines
* FRAME_LINE_HEIGHT (f
);
970 resize_frame_windows (f
, FRAME_TEXT_HEIGHT (f
), 0, 1);
971 if (FRAME_X_WINDOW (f
))
972 x_clear_under_internal_border (f
);
974 /* If the menu bar height gets changed, the internal border below
975 the top margin has to be cleared. Also, if the menu bar gets
976 larger, the area for the added lines has to be cleared except for
977 the first menu bar line that is to be drawn later. */
978 if (nlines
!= olines
)
980 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
981 int width
= FRAME_PIXEL_WIDTH (f
);
984 /* height can be zero here. */
985 if (FRAME_X_WINDOW (f
) && height
> 0 && width
> 0)
987 y
= FRAME_TOP_MARGIN_HEIGHT (f
);
990 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
991 0, y
, width
, height
);
995 if (nlines
> 1 && nlines
> olines
)
997 y
= (olines
== 0 ? 1 : olines
) * FRAME_LINE_HEIGHT (f
);
998 height
= nlines
* FRAME_LINE_HEIGHT (f
) - y
;
1001 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1002 0, y
, width
, height
);
1006 if (nlines
== 0 && WINDOWP (f
->menu_bar_window
))
1007 clear_glyph_matrix (XWINDOW (f
->menu_bar_window
)->current_matrix
);
1009 #endif /* not USE_X_TOOLKIT && not USE_GTK */
1010 adjust_frame_glyphs (f
);
1011 run_window_configuration_change_hook (f
);
1015 /* Set the number of lines used for the tool bar of frame F to VALUE.
1016 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1017 is the old number of tool bar lines. This function changes the
1018 height of all windows on frame F to match the new tool bar height.
1019 The frame's height doesn't change. */
1022 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1025 #if ! defined (USE_GTK)
1026 int delta
, root_height
;
1027 int unit
= FRAME_LINE_HEIGHT (f
);
1030 /* Treat tool bars like menu bars. */
1031 if (FRAME_MINIBUF_ONLY_P (f
))
1034 /* Use VALUE only if an int >= 0. */
1035 if (RANGED_INTEGERP (0, value
, INT_MAX
))
1036 nlines
= XFASTINT (value
);
1042 FRAME_TOOL_BAR_LINES (f
) = 0;
1043 FRAME_TOOL_BAR_HEIGHT (f
) = 0;
1046 FRAME_EXTERNAL_TOOL_BAR (f
) = 1;
1047 if (FRAME_X_P (f
) && f
->output_data
.x
->toolbar_widget
== 0)
1048 /* Make sure next redisplay shows the tool bar. */
1049 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= 1;
1050 update_frame_tool_bar (f
);
1054 if (FRAME_EXTERNAL_TOOL_BAR (f
))
1055 free_frame_tool_bar (f
);
1056 FRAME_EXTERNAL_TOOL_BAR (f
) = 0;
1059 #else /* !USE_GTK */
1061 /* Make sure we redisplay all windows in this frame. */
1062 windows_or_buffers_changed
= 60;
1064 /* DELTA is in pixels now. */
1065 delta
= (nlines
- FRAME_TOOL_BAR_LINES (f
)) * unit
;
1067 /* Don't resize the tool-bar to more than we have room for. Note: The
1068 calculations below and the subsequent call to resize_frame_windows
1069 are inherently flawed because they can make the toolbar higher than
1070 the containing frame. */
1073 root_height
= WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_ROOT_WINDOW (f
)));
1074 if (root_height
- delta
< unit
)
1076 delta
= root_height
- unit
;
1077 /* When creating a new frame and toolbar mode is enabled, we
1078 need at least one toolbar line. */
1079 nlines
= max (FRAME_TOOL_BAR_LINES (f
) + delta
/ unit
, 1);
1083 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1084 FRAME_TOOL_BAR_HEIGHT (f
) = nlines
* FRAME_LINE_HEIGHT (f
);
1085 resize_frame_windows (f
, FRAME_TEXT_HEIGHT (f
), 0, 1);
1086 #if !defined USE_X_TOOLKIT && !defined USE_GTK
1087 if (FRAME_X_WINDOW (f
))
1088 x_clear_under_internal_border (f
);
1090 adjust_frame_glyphs (f
);
1092 /* We also have to make sure that the internal border at the top of
1093 the frame, below the menu bar or tool bar, is redrawn when the
1094 tool bar disappears. This is so because the internal border is
1095 below the tool bar if one is displayed, but is below the menu bar
1096 if there isn't a tool bar. The tool bar draws into the area
1097 below the menu bar. */
1098 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_HEIGHT (f
) == 0)
1101 clear_current_matrices (f
);
1104 /* If the tool bar gets smaller, the internal border below it
1105 has to be cleared. It was formerly part of the display
1106 of the larger tool bar, and updating windows won't clear it. */
1109 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1110 int width
= FRAME_PIXEL_WIDTH (f
);
1111 int y
= nlines
* unit
;
1113 /* height can be zero here. */
1114 if (height
> 0 && width
> 0)
1117 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1118 0, y
, width
, height
);
1122 if (WINDOWP (f
->tool_bar_window
))
1123 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1126 run_window_configuration_change_hook (f
);
1127 #endif /* USE_GTK */
1131 /* Set the foreground color for scroll bars on frame F to VALUE.
1132 VALUE should be a string, a color name. If it isn't a string or
1133 isn't a valid color name, do nothing. OLDVAL is the old value of
1134 the frame parameter. */
1137 x_set_scroll_bar_foreground (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1139 unsigned long pixel
;
1141 if (STRINGP (value
))
1142 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
1146 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
1147 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
1149 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
1150 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1152 /* Remove all scroll bars because they have wrong colors. */
1153 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1154 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1155 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1156 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1158 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
1164 /* Set the background color for scroll bars on frame F to VALUE VALUE
1165 should be a string, a color name. If it isn't a string or isn't a
1166 valid color name, do nothing. OLDVAL is the old value of the frame
1170 x_set_scroll_bar_background (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1172 unsigned long pixel
;
1174 if (STRINGP (value
))
1175 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
1179 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
1180 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
1182 #ifdef USE_TOOLKIT_SCROLL_BARS
1183 /* Scrollbar shadow colors. */
1184 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
1186 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
1187 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
1189 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
1191 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
1192 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
1194 #endif /* USE_TOOLKIT_SCROLL_BARS */
1196 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
1197 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1199 /* Remove all scroll bars because they have wrong colors. */
1200 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1201 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1202 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1203 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1205 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
1211 /* Encode Lisp string STRING as a text in a format appropriate for
1212 XICCC (X Inter Client Communication Conventions).
1214 This can call Lisp code, so callers must GCPRO.
1216 If STRING contains only ASCII characters, do no conversion and
1217 return the string data of STRING. Otherwise, encode the text by
1218 CODING_SYSTEM, and return a newly allocated memory area which
1219 should be freed by `xfree' by a caller.
1221 SELECTIONP non-zero means the string is being encoded for an X
1222 selection, so it is safe to run pre-write conversions (which
1225 Store the byte length of resulting text in *TEXT_BYTES.
1227 If the text contains only ASCII and Latin-1, store 1 in *STRING_P,
1228 which means that the `encoding' of the result can be `STRING'.
1229 Otherwise store 0 in *STRINGP, which means that the `encoding' of
1230 the result should be `COMPOUND_TEXT'. */
1232 static unsigned char *
1233 x_encode_text (Lisp_Object string
, Lisp_Object coding_system
, int selectionp
,
1234 ptrdiff_t *text_bytes
, int *stringp
, int *freep
)
1236 int result
= string_xstring_p (string
);
1237 struct coding_system coding
;
1241 /* No multibyte character in OBJ. We need not encode it. */
1242 *text_bytes
= SBYTES (string
);
1245 return SDATA (string
);
1248 setup_coding_system (coding_system
, &coding
);
1249 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
1250 /* We suppress producing escape sequences for composition. */
1251 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
1252 coding
.destination
= xnmalloc (SCHARS (string
), 2);
1253 coding
.dst_bytes
= SCHARS (string
) * 2;
1254 encode_coding_object (&coding
, string
, 0, 0,
1255 SCHARS (string
), SBYTES (string
), Qnil
);
1256 *text_bytes
= coding
.produced
;
1257 *stringp
= (result
== 1 || !EQ (coding_system
, Qcompound_text
));
1259 return coding
.destination
;
1263 /* Set the WM name to NAME for frame F. Also set the icon name.
1264 If the frame already has an icon name, use that, otherwise set the
1265 icon name to NAME. */
1268 x_set_name_internal (struct frame
*f
, Lisp_Object name
)
1270 if (FRAME_X_WINDOW (f
))
1274 XTextProperty text
, icon
;
1277 int do_free_icon_value
= 0, do_free_text_value
= 0;
1278 Lisp_Object coding_system
;
1279 Lisp_Object encoded_name
;
1280 Lisp_Object encoded_icon_name
;
1281 struct gcpro gcpro1
;
1283 /* As ENCODE_UTF_8 may cause GC and relocation of string data,
1284 we use it before x_encode_text that may return string data. */
1286 encoded_name
= ENCODE_UTF_8 (name
);
1289 coding_system
= Qcompound_text
;
1290 /* Note: Encoding strategy
1292 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1293 text.encoding. But, there are non-internationalized window
1294 managers which don't support that encoding. So, if NAME
1295 contains only ASCII and 8859-1 characters, encode it by
1296 iso-latin-1, and use "STRING" in text.encoding hoping that
1297 such window managers at least analyze this format correctly,
1298 i.e. treat 8-bit bytes as 8859-1 characters.
1300 We may also be able to use "UTF8_STRING" in text.encoding
1301 in the future which can encode all Unicode characters.
1302 But, for the moment, there's no way to know that the
1303 current window manager supports it or not.
1305 Either way, we also set the _NET_WM_NAME and _NET_WM_ICON_NAME
1306 properties. Per the EWMH specification, those two properties
1307 are always UTF8_STRING. This matches what gtk_window_set_title()
1308 does in the USE_GTK case. */
1309 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
,
1310 &do_free_text_value
);
1311 text
.encoding
= (stringp
? XA_STRING
1312 : FRAME_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1314 text
.nitems
= bytes
;
1315 if (text
.nitems
!= bytes
)
1316 error ("Window name too large");
1318 if (!STRINGP (f
->icon_name
))
1321 encoded_icon_name
= encoded_name
;
1325 /* See the above comment "Note: Encoding strategy". */
1326 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
1327 &bytes
, &stringp
, &do_free_icon_value
);
1328 icon
.encoding
= (stringp
? XA_STRING
1329 : FRAME_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1331 icon
.nitems
= bytes
;
1332 if (icon
.nitems
!= bytes
)
1333 error ("Icon name too large");
1335 encoded_icon_name
= ENCODE_UTF_8 (f
->icon_name
);
1339 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1340 SSDATA (encoded_name
));
1341 #else /* not USE_GTK */
1342 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1343 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1344 FRAME_DISPLAY_INFO (f
)->Xatom_net_wm_name
,
1345 FRAME_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1347 SDATA (encoded_name
),
1348 SBYTES (encoded_name
));
1349 #endif /* not USE_GTK */
1351 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &icon
);
1352 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1353 FRAME_DISPLAY_INFO (f
)->Xatom_net_wm_icon_name
,
1354 FRAME_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1356 SDATA (encoded_icon_name
),
1357 SBYTES (encoded_icon_name
));
1359 if (do_free_icon_value
)
1361 if (do_free_text_value
)
1368 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1371 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1372 name; if NAME is a string, set F's name to NAME and set
1373 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1375 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1376 suggesting a new name, which lisp code should override; if
1377 F->explicit_name is set, ignore the new name; otherwise, set it. */
1380 x_set_name (struct frame
*f
, Lisp_Object name
, int explicit)
1382 /* Make sure that requests from lisp code override requests from
1383 Emacs redisplay code. */
1386 /* If we're switching from explicit to implicit, we had better
1387 update the mode lines and thereby update the title. */
1388 if (f
->explicit_name
&& NILP (name
))
1389 update_mode_lines
= 37;
1391 f
->explicit_name
= ! NILP (name
);
1393 else if (f
->explicit_name
)
1396 /* If NAME is nil, set the name to the x_id_name. */
1399 /* Check for no change needed in this very common case
1400 before we do any consing. */
1401 if (!strcmp (FRAME_DISPLAY_INFO (f
)->x_id_name
,
1404 name
= build_string (FRAME_DISPLAY_INFO (f
)->x_id_name
);
1407 CHECK_STRING (name
);
1409 /* Don't change the name if it's already NAME. */
1410 if (! NILP (Fstring_equal (name
, f
->name
)))
1413 fset_name (f
, name
);
1415 /* For setting the frame title, the title parameter should override
1416 the name parameter. */
1417 if (! NILP (f
->title
))
1420 x_set_name_internal (f
, name
);
1423 /* This function should be called when the user's lisp code has
1424 specified a name for the frame; the name will override any set by the
1427 x_explicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1429 x_set_name (f
, arg
, 1);
1432 /* This function should be called by Emacs redisplay code to set the
1433 name; names set this way will never override names set by the user's
1436 x_implicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1438 x_set_name (f
, arg
, 0);
1441 /* Change the title of frame F to NAME.
1442 If NAME is nil, use the frame name as the title. */
1445 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1447 /* Don't change the title if it's already NAME. */
1448 if (EQ (name
, f
->title
))
1451 update_mode_lines
= 38;
1453 fset_title (f
, name
);
1458 CHECK_STRING (name
);
1460 x_set_name_internal (f
, name
);
1464 x_set_scroll_bar_default_width (struct frame
*f
)
1466 int unit
= FRAME_COLUMN_WIDTH (f
);
1467 #ifdef USE_TOOLKIT_SCROLL_BARS
1469 int minw
= xg_get_default_scrollbar_width ();
1473 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1474 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (minw
+ unit
- 1) / unit
;
1475 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = minw
;
1477 /* The width of a non-toolkit scrollbar is at least 14 pixels and a
1478 multiple of the frame's character width. */
1479 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + unit
- 1) / unit
;
1480 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
)
1481 = FRAME_CONFIG_SCROLL_BAR_COLS (f
) * unit
;
1486 /* Record in frame F the specified or default value according to ALIST
1487 of the parameter named PROP (a Lisp symbol). If no value is
1488 specified for PROP, look for an X default for XPROP on the frame
1489 named NAME. If that is not found either, use the value DEFLT. */
1492 x_default_scroll_bar_color_parameter (struct frame
*f
,
1493 Lisp_Object alist
, Lisp_Object prop
,
1494 const char *xprop
, const char *xclass
,
1497 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1500 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
1501 if (EQ (tem
, Qunbound
))
1503 #ifdef USE_TOOLKIT_SCROLL_BARS
1505 /* See if an X resource for the scroll bar color has been
1507 tem
= display_x_get_resource (dpyinfo
,
1508 build_string (foreground_p
1511 empty_unibyte_string
,
1512 build_string ("verticalScrollBar"),
1513 empty_unibyte_string
);
1516 /* If nothing has been specified, scroll bars will use a
1517 toolkit-dependent default. Because these defaults are
1518 difficult to get at without actually creating a scroll
1519 bar, use nil to indicate that no color has been
1524 #else /* not USE_TOOLKIT_SCROLL_BARS */
1528 #endif /* not USE_TOOLKIT_SCROLL_BARS */
1531 x_set_frame_parameters (f
, list1 (Fcons (prop
, tem
)));
1538 #ifdef USE_X_TOOLKIT
1540 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
1541 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
1542 already be present because of the toolkit (Motif adds some of them,
1543 for example, but Xt doesn't). */
1546 hack_wm_protocols (struct frame
*f
, Widget widget
)
1548 Display
*dpy
= XtDisplay (widget
);
1549 Window w
= XtWindow (widget
);
1550 int need_delete
= 1;
1557 unsigned char *catoms
;
1559 unsigned long nitems
= 0;
1560 unsigned long bytes_after
;
1562 if ((XGetWindowProperty (dpy
, w
,
1563 FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1564 (long)0, (long)100, False
, XA_ATOM
,
1565 &type
, &format
, &nitems
, &bytes_after
,
1568 && format
== 32 && type
== XA_ATOM
)
1570 Atom
*atoms
= (Atom
*) catoms
;
1575 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
1577 else if (atoms
[nitems
]
1578 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
1580 else if (atoms
[nitems
]
1581 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
1592 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
1594 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
1596 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
1598 XChangeProperty (dpy
, w
, FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1599 XA_ATOM
, 32, PropModeAppend
,
1600 (unsigned char *) props
, count
);
1608 /* Support routines for XIC (X Input Context). */
1612 static XFontSet
xic_create_xfontset (struct frame
*);
1613 static XIMStyle
best_xim_style (XIMStyles
*);
1616 /* Supported XIM styles, ordered by preference. */
1618 static const XIMStyle supported_xim_styles
[] =
1620 XIMPreeditPosition
| XIMStatusArea
,
1621 XIMPreeditPosition
| XIMStatusNothing
,
1622 XIMPreeditPosition
| XIMStatusNone
,
1623 XIMPreeditNothing
| XIMStatusArea
,
1624 XIMPreeditNothing
| XIMStatusNothing
,
1625 XIMPreeditNothing
| XIMStatusNone
,
1626 XIMPreeditNone
| XIMStatusArea
,
1627 XIMPreeditNone
| XIMStatusNothing
,
1628 XIMPreeditNone
| XIMStatusNone
,
1633 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1634 /* Create an X fontset on frame F with base font name BASE_FONTNAME. */
1636 static const char xic_default_fontset
[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
1638 /* Create an Xt fontset spec from the name of a base font.
1639 If `motif' is True use the Motif syntax. */
1641 xic_create_fontsetname (const char *base_fontname
, int motif
)
1643 const char *sep
= motif
? ";" : ",";
1646 /* Make a fontset name from the base font name. */
1647 if (xic_default_fontset
== base_fontname
)
1649 /* There is no base font name, use the default. */
1650 fontsetname
= xmalloc (strlen (base_fontname
) + 2);
1651 strcpy (fontsetname
, base_fontname
);
1655 /* Make a fontset name from the base font name.
1656 The font set will be made of the following elements:
1658 - the base font where the charset spec is replaced by -*-*.
1659 - the same but with the family also replaced with -*-*-. */
1660 const char *p
= base_fontname
;
1663 for (i
= 0; *p
; p
++)
1667 /* As the font name doesn't conform to XLFD, we can't
1668 modify it to generalize it to allcs and allfamilies.
1669 Use the specified font plus the default. */
1670 fontsetname
= xmalloc (strlen (base_fontname
)
1671 + strlen (xic_default_fontset
) + 3);
1672 strcpy (fontsetname
, base_fontname
);
1673 strcat (fontsetname
, sep
);
1674 strcat (fontsetname
, xic_default_fontset
);
1679 const char *p1
= NULL
, *p2
= NULL
, *p3
= NULL
;
1680 char *font_allcs
= NULL
;
1681 char *font_allfamilies
= NULL
;
1682 char *font_all
= NULL
;
1683 const char *allcs
= "*-*-*-*-*-*-*";
1684 const char *allfamilies
= "-*-*-";
1685 const char *all
= "*-*-*-*-";
1688 for (i
= 0, p
= base_fontname
; i
< 8; p
++)
1701 /* If base_fontname specifies ADSTYLE, make it a
1705 ptrdiff_t diff
= (p2
- p3
) - 2;
1707 base
= alloca (strlen (base_fontname
) + 1);
1708 memcpy (base
, base_fontname
, p3
- base_fontname
);
1709 base
[p3
- base_fontname
] = '*';
1710 base
[(p3
- base_fontname
) + 1] = '-';
1711 strcpy (base
+ (p3
- base_fontname
) + 2, p2
);
1712 p
= base
+ (p
- base_fontname
) - diff
;
1713 p1
= base
+ (p1
- base_fontname
);
1714 p2
= base
+ (p2
- base_fontname
) - diff
;
1715 base_fontname
= base
;
1718 /* Build the font spec that matches all charsets. */
1719 len
= p
- base_fontname
+ strlen (allcs
) + 1;
1720 font_allcs
= alloca (len
);
1721 memcpy (font_allcs
, base_fontname
, p
- base_fontname
);
1722 strcat (font_allcs
, allcs
);
1724 /* Build the font spec that matches all families and
1726 len
= p
- p1
+ strlen (allcs
) + strlen (allfamilies
) + 1;
1727 font_allfamilies
= alloca (len
);
1728 strcpy (font_allfamilies
, allfamilies
);
1729 memcpy (font_allfamilies
+ strlen (allfamilies
), p1
, p
- p1
);
1730 strcat (font_allfamilies
, allcs
);
1732 /* Build the font spec that matches all. */
1733 len
= p
- p2
+ strlen (allcs
) + strlen (all
) + strlen (allfamilies
) + 1;
1734 font_all
= alloca (len
);
1735 strcpy (font_all
, allfamilies
);
1736 strcat (font_all
, all
);
1737 memcpy (font_all
+ strlen (all
) + strlen (allfamilies
), p2
, p
- p2
);
1738 strcat (font_all
, allcs
);
1740 /* Build the actual font set name. */
1741 len
= strlen (base_fontname
) + strlen (font_allcs
)
1742 + strlen (font_allfamilies
) + strlen (font_all
) + 5;
1743 fontsetname
= xmalloc (len
);
1744 strcpy (fontsetname
, base_fontname
);
1745 strcat (fontsetname
, sep
);
1746 strcat (fontsetname
, font_allcs
);
1747 strcat (fontsetname
, sep
);
1748 strcat (fontsetname
, font_allfamilies
);
1749 strcat (fontsetname
, sep
);
1750 strcat (fontsetname
, font_all
);
1754 return strcat (fontsetname
, ":");
1757 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
1759 #ifdef DEBUG_XIC_FONTSET
1761 print_fontset_result (XFontSet xfs
, char *name
, char **missing_list
,
1765 fprintf (stderr
, "XIC Fontset created: %s\n", name
);
1768 fprintf (stderr
, "XIC Fontset failed: %s\n", name
);
1769 while (missing_count
-- > 0)
1771 fprintf (stderr
, " missing: %s\n", *missing_list
);
1780 xic_create_xfontset (struct frame
*f
)
1782 XFontSet xfs
= NULL
;
1783 struct font
*font
= FRAME_FONT (f
);
1784 int pixel_size
= font
->pixel_size
;
1785 Lisp_Object rest
, frame
;
1787 /* See if there is another frame already using same fontset. */
1788 FOR_EACH_FRAME (rest
, frame
)
1790 struct frame
*cf
= XFRAME (frame
);
1792 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
1793 && FRAME_DISPLAY_INFO (cf
) == FRAME_DISPLAY_INFO (f
)
1795 && FRAME_FONT (f
)->pixel_size
== pixel_size
)
1797 xfs
= FRAME_XIC_FONTSET (cf
);
1805 char **missing_list
;
1808 const char *xlfd_format
= "-*-*-medium-r-normal--%d-*-*-*-*-*";
1810 sprintf (buf
, xlfd_format
, pixel_size
);
1811 missing_list
= NULL
;
1812 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
1813 &missing_list
, &missing_count
, &def_string
);
1814 #ifdef DEBUG_XIC_FONTSET
1815 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
1818 XFreeStringList (missing_list
);
1821 /* List of pixel sizes most likely available. Find one that
1822 is closest to pixel_size. */
1823 int sizes
[] = {0, 8, 10, 11, 12, 14, 17, 18, 20, 24, 26, 34, 0};
1824 int *smaller
, *larger
;
1826 for (smaller
= sizes
; smaller
[1]; smaller
++)
1827 if (smaller
[1] >= pixel_size
)
1829 larger
= smaller
+ 1;
1830 if (*larger
== pixel_size
)
1832 while (*smaller
|| *larger
)
1837 this_size
= *smaller
--;
1838 else if (! *smaller
)
1839 this_size
= *larger
++;
1840 else if (pixel_size
- *smaller
< *larger
- pixel_size
)
1841 this_size
= *smaller
--;
1843 this_size
= *larger
++;
1844 sprintf (buf
, xlfd_format
, this_size
);
1845 missing_list
= NULL
;
1846 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
1847 &missing_list
, &missing_count
, &def_string
);
1848 #ifdef DEBUG_XIC_FONTSET
1849 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
1852 XFreeStringList (missing_list
);
1859 const char *last_resort
= "-*-*-*-r-normal--*-*-*-*-*-*";
1861 missing_list
= NULL
;
1862 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), last_resort
,
1863 &missing_list
, &missing_count
, &def_string
);
1864 #ifdef DEBUG_XIC_FONTSET
1865 print_fontset_result (xfs
, last_resort
, missing_list
, missing_count
);
1868 XFreeStringList (missing_list
);
1876 /* Free the X fontset of frame F if it is the last frame using it. */
1879 xic_free_xfontset (struct frame
*f
)
1881 Lisp_Object rest
, frame
;
1884 if (!FRAME_XIC_FONTSET (f
))
1887 /* See if there is another frame sharing the same fontset. */
1888 FOR_EACH_FRAME (rest
, frame
)
1890 struct frame
*cf
= XFRAME (frame
);
1891 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
1892 && FRAME_DISPLAY_INFO (cf
) == FRAME_DISPLAY_INFO (f
)
1893 && FRAME_XIC_FONTSET (cf
) == FRAME_XIC_FONTSET (f
))
1901 /* The fontset is not used anymore. It is safe to free it. */
1902 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
1904 FRAME_XIC_FONTSET (f
) = NULL
;
1908 /* Value is the best input style, given user preferences USER (already
1909 checked to be supported by Emacs), and styles supported by the
1910 input method XIM. */
1913 best_xim_style (XIMStyles
*xim
)
1916 int nr_supported
= ARRAYELTS (supported_xim_styles
);
1918 for (i
= 0; i
< nr_supported
; ++i
)
1919 for (j
= 0; j
< xim
->count_styles
; ++j
)
1920 if (supported_xim_styles
[i
] == xim
->supported_styles
[j
])
1921 return supported_xim_styles
[i
];
1923 /* Return the default style. */
1924 return XIMPreeditNothing
| XIMStatusNothing
;
1927 /* Create XIC for frame F. */
1930 create_frame_xic (struct frame
*f
)
1934 XFontSet xfs
= NULL
;
1935 XVaNestedList status_attr
= NULL
;
1936 XVaNestedList preedit_attr
= NULL
;
1944 xim
= FRAME_X_XIM (f
);
1948 /* Determine XIC style. */
1949 xic_style
= best_xim_style (FRAME_X_XIM_STYLES (f
));
1951 /* Create X fontset. */
1952 if (xic_style
& (XIMPreeditPosition
| XIMStatusArea
))
1954 xfs
= xic_create_xfontset (f
);
1958 FRAME_XIC_FONTSET (f
) = xfs
;
1961 if (xic_style
& XIMPreeditPosition
)
1963 spot
.x
= 0; spot
.y
= 1;
1964 preedit_attr
= XVaCreateNestedList (0,
1967 FRAME_FOREGROUND_PIXEL (f
),
1969 FRAME_BACKGROUND_PIXEL (f
),
1970 (xic_style
& XIMPreeditPosition
1980 if (xic_style
& XIMStatusArea
)
1982 s_area
.x
= 0; s_area
.y
= 0; s_area
.width
= 1; s_area
.height
= 1;
1983 status_attr
= XVaCreateNestedList (0,
1989 FRAME_FOREGROUND_PIXEL (f
),
1991 FRAME_BACKGROUND_PIXEL (f
),
1998 if (preedit_attr
&& status_attr
)
1999 xic
= XCreateIC (xim
,
2000 XNInputStyle
, xic_style
,
2001 XNClientWindow
, FRAME_X_WINDOW (f
),
2002 XNFocusWindow
, FRAME_X_WINDOW (f
),
2003 XNStatusAttributes
, status_attr
,
2004 XNPreeditAttributes
, preedit_attr
,
2006 else if (preedit_attr
)
2007 xic
= XCreateIC (xim
,
2008 XNInputStyle
, xic_style
,
2009 XNClientWindow
, FRAME_X_WINDOW (f
),
2010 XNFocusWindow
, FRAME_X_WINDOW (f
),
2011 XNPreeditAttributes
, preedit_attr
,
2013 else if (status_attr
)
2014 xic
= XCreateIC (xim
,
2015 XNInputStyle
, xic_style
,
2016 XNClientWindow
, FRAME_X_WINDOW (f
),
2017 XNFocusWindow
, FRAME_X_WINDOW (f
),
2018 XNStatusAttributes
, status_attr
,
2021 xic
= XCreateIC (xim
,
2022 XNInputStyle
, xic_style
,
2023 XNClientWindow
, FRAME_X_WINDOW (f
),
2024 XNFocusWindow
, FRAME_X_WINDOW (f
),
2030 FRAME_XIC (f
) = xic
;
2031 FRAME_XIC_STYLE (f
) = xic_style
;
2032 xfs
= NULL
; /* Don't free below. */
2040 XFree (preedit_attr
);
2043 XFree (status_attr
);
2047 /* Destroy XIC and free XIC fontset of frame F, if any. */
2050 free_frame_xic (struct frame
*f
)
2052 if (FRAME_XIC (f
) == NULL
)
2055 XDestroyIC (FRAME_XIC (f
));
2056 xic_free_xfontset (f
);
2058 FRAME_XIC (f
) = NULL
;
2062 /* Place preedit area for XIC of window W's frame to specified
2063 pixel position X/Y. X and Y are relative to window W. */
2066 xic_set_preeditarea (struct window
*w
, int x
, int y
)
2068 struct frame
*f
= XFRAME (w
->frame
);
2072 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
) + WINDOW_LEFT_FRINGE_WIDTH (w
);
2073 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
2074 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
2075 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2080 /* Place status area for XIC in bottom right corner of frame F.. */
2083 xic_set_statusarea (struct frame
*f
)
2085 XIC xic
= FRAME_XIC (f
);
2090 /* Negotiate geometry of status area. If input method has existing
2091 status area, use its current size. */
2092 area
.x
= area
.y
= area
.width
= area
.height
= 0;
2093 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
2094 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2097 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
2098 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2101 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
2103 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
2104 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2108 area
.width
= needed
->width
;
2109 area
.height
= needed
->height
;
2110 area
.x
= FRAME_PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
2111 area
.y
= (FRAME_PIXEL_HEIGHT (f
) - area
.height
2112 - FRAME_MENUBAR_HEIGHT (f
)
2113 - FRAME_TOOLBAR_TOP_HEIGHT (f
)
2114 - FRAME_INTERNAL_BORDER_WIDTH (f
));
2117 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
2118 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2123 /* Set X fontset for XIC of frame F, using base font name
2124 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2127 xic_set_xfontset (struct frame
*f
, const char *base_fontname
)
2132 xic_free_xfontset (f
);
2134 xfs
= xic_create_xfontset (f
);
2136 attr
= XVaCreateNestedList (0, XNFontSet
, xfs
, NULL
);
2137 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
2138 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2139 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
2140 XSetICValues (FRAME_XIC (f
), XNStatusAttributes
, attr
, NULL
);
2143 FRAME_XIC_FONTSET (f
) = xfs
;
2146 #endif /* HAVE_X_I18N */
2150 #ifdef USE_X_TOOLKIT
2152 /* Create and set up the X widget for frame F. */
2155 x_window (struct frame
*f
, long window_prompting
, int minibuffer_only
)
2157 XClassHint class_hints
;
2158 XSetWindowAttributes attributes
;
2159 unsigned long attribute_mask
;
2160 Widget shell_widget
;
2162 Widget frame_widget
;
2168 /* Use the resource name as the top-level widget name
2169 for looking up resources. Make a non-Lisp copy
2170 for the window manager, so GC relocation won't bother it.
2172 Elsewhere we specify the window name for the window manager. */
2173 f
->namebuf
= xstrdup (SSDATA (Vx_resource_name
));
2176 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2177 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2178 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2179 XtSetArg (al
[ac
], XtNborderWidth
, f
->border_width
); ac
++;
2180 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2181 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2182 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2183 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2184 applicationShellWidgetClass
,
2185 FRAME_X_DISPLAY (f
), al
, ac
);
2187 f
->output_data
.x
->widget
= shell_widget
;
2188 /* maybe_set_screen_title_format (shell_widget); */
2190 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2191 NULL
, shell_widget
, False
,
2192 NULL
, NULL
, NULL
, NULL
);
2195 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2196 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2197 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2198 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2199 XtSetValues (pane_widget
, al
, ac
);
2200 f
->output_data
.x
->column_widget
= pane_widget
;
2202 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2203 the emacs screen when changing menubar. This reduces flickering. */
2206 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2207 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2208 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2209 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2210 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2211 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2212 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2213 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2214 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2215 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
2218 f
->output_data
.x
->edit_widget
= frame_widget
;
2220 XtManageChild (frame_widget
);
2222 /* Do some needed geometry management. */
2224 char *tem
, shell_position
[sizeof "=x++" + 4 * INT_STRLEN_BOUND (int)];
2227 int extra_borders
= 0;
2229 = (f
->output_data
.x
->menubar_widget
2230 ? (f
->output_data
.x
->menubar_widget
->core
.height
2231 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
2234 #if 0 /* Experimentally, we now get the right results
2235 for -geometry -0-0 without this. 24 Aug 96, rms. */
2236 if (FRAME_EXTERNAL_MENU_BAR (f
))
2239 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2240 menubar_size
+= ibw
;
2244 f
->output_data
.x
->menubar_height
= menubar_size
;
2247 /* Motif seems to need this amount added to the sizes
2248 specified for the shell widget. The Athena/Lucid widgets don't.
2249 Both conclusions reached experimentally. -- rms. */
2250 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
2251 &extra_borders
, NULL
);
2255 /* Convert our geometry parameters into a geometry string
2257 Note that we do not specify here whether the position
2258 is a user-specified or program-specified one.
2259 We pass that information later, in x_wm_set_size_hints. */
2261 int left
= f
->left_pos
;
2262 int xneg
= window_prompting
& XNegative
;
2263 int top
= f
->top_pos
;
2264 int yneg
= window_prompting
& YNegative
;
2270 if (window_prompting
& USPosition
)
2271 sprintf (shell_position
, "=%dx%d%c%d%c%d",
2272 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2273 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
2274 (xneg
? '-' : '+'), left
,
2275 (yneg
? '-' : '+'), top
);
2278 sprintf (shell_position
, "=%dx%d",
2279 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2280 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
2282 /* Setting x and y when the position is not specified in
2283 the geometry string will set program position in the WM hints.
2284 If Emacs had just one program position, we could set it in
2285 fallback resources, but since each make-frame call can specify
2286 different program positions, this is easier. */
2287 XtSetArg (gal
[gac
], XtNx
, left
); gac
++;
2288 XtSetArg (gal
[gac
], XtNy
, top
); gac
++;
2292 /* We don't free this because we don't know whether
2293 it is safe to free it while the frame exists.
2294 It isn't worth the trouble of arranging to free it
2295 when the frame is deleted. */
2296 tem
= xstrdup (shell_position
);
2297 XtSetArg (gal
[gac
], XtNgeometry
, tem
); gac
++;
2298 XtSetValues (shell_widget
, gal
, gac
);
2301 XtManageChild (pane_widget
);
2302 XtRealizeWidget (shell_widget
);
2304 if (FRAME_X_EMBEDDED_P (f
))
2305 XReparentWindow (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
),
2306 f
->output_data
.x
->parent_desc
, 0, 0);
2308 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2310 validate_x_resource_name ();
2312 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2313 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2314 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2317 FRAME_XIC (f
) = NULL
;
2319 create_frame_xic (f
);
2322 f
->output_data
.x
->wm_hints
.input
= True
;
2323 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2324 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2325 &f
->output_data
.x
->wm_hints
);
2327 hack_wm_protocols (f
, shell_widget
);
2330 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2333 /* Do a stupid property change to force the server to generate a
2334 PropertyNotify event so that the event_stream server timestamp will
2335 be initialized to something relevant to the time we created the window.
2337 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2338 FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2339 XA_ATOM
, 32, PropModeAppend
, NULL
, 0);
2341 /* Make all the standard events reach the Emacs frame. */
2342 attributes
.event_mask
= STANDARD_EVENT_SET
;
2347 /* XIM server might require some X events. */
2348 unsigned long fevent
= NoEventMask
;
2349 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2350 attributes
.event_mask
|= fevent
;
2352 #endif /* HAVE_X_I18N */
2354 attribute_mask
= CWEventMask
;
2355 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2356 attribute_mask
, &attributes
);
2358 XtMapWidget (frame_widget
);
2360 /* x_set_name normally ignores requests to set the name if the
2361 requested name is the same as the current name. This is the one
2362 place where that assumption isn't correct; f->name is set, but
2363 the X server hasn't been told. */
2366 int explicit = f
->explicit_name
;
2368 f
->explicit_name
= 0;
2370 fset_name (f
, Qnil
);
2371 x_set_name (f
, name
, explicit);
2374 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2375 f
->output_data
.x
->current_cursor
2376 = f
->output_data
.x
->text_cursor
);
2380 /* This is a no-op, except under Motif. Make sure main areas are
2381 set to something reasonable, in case we get an error later. */
2382 lw_set_main_areas (pane_widget
, 0, frame_widget
);
2385 #else /* not USE_X_TOOLKIT */
2388 x_window (struct frame
*f
)
2390 if (! xg_create_frame_widgets (f
))
2391 error ("Unable to create window");
2394 FRAME_XIC (f
) = NULL
;
2398 create_frame_xic (f
);
2401 /* XIM server might require some X events. */
2402 unsigned long fevent
= NoEventMask
;
2403 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2405 if (fevent
!= NoEventMask
)
2407 XSetWindowAttributes attributes
;
2408 XWindowAttributes wattr
;
2409 unsigned long attribute_mask
;
2411 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2413 attributes
.event_mask
= wattr
.your_event_mask
| fevent
;
2414 attribute_mask
= CWEventMask
;
2415 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2416 attribute_mask
, &attributes
);
2424 #else /*! USE_GTK */
2425 /* Create and set up the X window for frame F. */
2428 x_window (struct frame
*f
)
2430 XClassHint class_hints
;
2431 XSetWindowAttributes attributes
;
2432 unsigned long attribute_mask
;
2434 attributes
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2435 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
2436 attributes
.bit_gravity
= StaticGravity
;
2437 attributes
.backing_store
= NotUseful
;
2438 attributes
.save_under
= True
;
2439 attributes
.event_mask
= STANDARD_EVENT_SET
;
2440 attributes
.colormap
= FRAME_X_COLORMAP (f
);
2441 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
2446 = XCreateWindow (FRAME_X_DISPLAY (f
),
2447 f
->output_data
.x
->parent_desc
,
2450 FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
),
2452 CopyFromParent
, /* depth */
2453 InputOutput
, /* class */
2455 attribute_mask
, &attributes
);
2460 create_frame_xic (f
);
2463 /* XIM server might require some X events. */
2464 unsigned long fevent
= NoEventMask
;
2465 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2466 attributes
.event_mask
|= fevent
;
2467 attribute_mask
= CWEventMask
;
2468 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2469 attribute_mask
, &attributes
);
2472 #endif /* HAVE_X_I18N */
2474 validate_x_resource_name ();
2476 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2477 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2478 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2480 /* The menubar is part of the ordinary display;
2481 it does not count in addition to the height of the window. */
2482 f
->output_data
.x
->menubar_height
= 0;
2484 /* This indicates that we use the "Passive Input" input model.
2485 Unless we do this, we don't get the Focus{In,Out} events that we
2486 need to draw the cursor correctly. Accursed bureaucrats.
2487 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2489 f
->output_data
.x
->wm_hints
.input
= True
;
2490 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2491 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2492 &f
->output_data
.x
->wm_hints
);
2493 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
2495 /* Request "save yourself" and "delete window" commands from wm. */
2498 protocols
[0] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2499 protocols
[1] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2500 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2503 /* x_set_name normally ignores requests to set the name if the
2504 requested name is the same as the current name. This is the one
2505 place where that assumption isn't correct; f->name is set, but
2506 the X server hasn't been told. */
2509 int explicit = f
->explicit_name
;
2511 f
->explicit_name
= 0;
2513 fset_name (f
, Qnil
);
2514 x_set_name (f
, name
, explicit);
2517 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2518 f
->output_data
.x
->current_cursor
2519 = f
->output_data
.x
->text_cursor
);
2523 if (FRAME_X_WINDOW (f
) == 0)
2524 error ("Unable to create window");
2527 #endif /* not USE_GTK */
2528 #endif /* not USE_X_TOOLKIT */
2530 /* Verify that the icon position args for this window are valid. */
2533 x_icon_verify (struct frame
*f
, Lisp_Object parms
)
2535 Lisp_Object icon_x
, icon_y
;
2537 /* Set the position of the icon. Note that twm groups all
2538 icons in an icon window. */
2539 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2540 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2541 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2543 CHECK_NUMBER (icon_x
);
2544 CHECK_NUMBER (icon_y
);
2546 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2547 error ("Both left and top icon corners of icon must be specified");
2550 /* Handle the icon stuff for this window. Perhaps later we might
2551 want an x_set_icon_position which can be called interactively as
2555 x_icon (struct frame
*f
, Lisp_Object parms
)
2557 Lisp_Object icon_x
, icon_y
;
2559 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2562 /* Set the position of the icon. Note that twm groups all
2563 icons in an icon window. */
2564 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2565 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2566 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2568 CHECK_TYPE_RANGED_INTEGER (int, icon_x
);
2569 CHECK_TYPE_RANGED_INTEGER (int, icon_y
);
2571 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2572 error ("Both left and top icon corners of icon must be specified");
2576 if (! EQ (icon_x
, Qunbound
))
2577 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2579 #if 0 /* x_get_arg removes the visibility parameter as a side effect,
2580 but x_create_frame still needs it. */
2581 /* Start up iconic or window? */
2582 x_wm_set_window_state
2583 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
2589 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
2596 /* Make the GCs needed for this window, setting the
2597 background, border and mouse colors; also create the
2598 mouse cursor and the gray border tile. */
2601 x_make_gc (struct frame
*f
)
2603 XGCValues gc_values
;
2607 /* Create the GCs of this frame.
2608 Note that many default values are used. */
2610 gc_values
.foreground
= FRAME_FOREGROUND_PIXEL (f
);
2611 gc_values
.background
= FRAME_BACKGROUND_PIXEL (f
);
2612 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2613 f
->output_data
.x
->normal_gc
2614 = XCreateGC (FRAME_X_DISPLAY (f
),
2616 GCLineWidth
| GCForeground
| GCBackground
,
2619 /* Reverse video style. */
2620 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2621 gc_values
.background
= FRAME_FOREGROUND_PIXEL (f
);
2622 f
->output_data
.x
->reverse_gc
2623 = XCreateGC (FRAME_X_DISPLAY (f
),
2625 GCForeground
| GCBackground
| GCLineWidth
,
2628 /* Cursor has cursor-color background, background-color foreground. */
2629 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2630 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
2631 gc_values
.fill_style
= FillOpaqueStippled
;
2632 f
->output_data
.x
->cursor_gc
2633 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2634 (GCForeground
| GCBackground
2635 | GCFillStyle
| GCLineWidth
),
2638 /* Create the gray border tile used when the pointer is not in
2639 the frame. Since this depends on the frame's pixel values,
2640 this must be done on a per-frame basis. */
2641 f
->output_data
.x
->border_tile
2642 = (XCreatePixmapFromBitmapData
2643 (FRAME_X_DISPLAY (f
), FRAME_DISPLAY_INFO (f
)->root_window
,
2644 gray_bits
, gray_width
, gray_height
,
2645 FRAME_FOREGROUND_PIXEL (f
),
2646 FRAME_BACKGROUND_PIXEL (f
),
2647 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
2653 /* Free what was allocated in x_make_gc. */
2656 x_free_gcs (struct frame
*f
)
2658 Display
*dpy
= FRAME_X_DISPLAY (f
);
2662 if (f
->output_data
.x
->normal_gc
)
2664 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
2665 f
->output_data
.x
->normal_gc
= 0;
2668 if (f
->output_data
.x
->reverse_gc
)
2670 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
2671 f
->output_data
.x
->reverse_gc
= 0;
2674 if (f
->output_data
.x
->cursor_gc
)
2676 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
2677 f
->output_data
.x
->cursor_gc
= 0;
2680 if (f
->output_data
.x
->border_tile
)
2682 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
2683 f
->output_data
.x
->border_tile
= 0;
2690 /* Handler for signals raised during x_create_frame and
2691 x_create_tip_frame. FRAME is the frame which is partially
2695 unwind_create_frame (Lisp_Object frame
)
2697 struct frame
*f
= XFRAME (frame
);
2699 /* If frame is already dead, nothing to do. This can happen if the
2700 display is disconnected after the frame has become official, but
2701 before x_create_frame removes the unwind protect. */
2702 if (!FRAME_LIVE_P (f
))
2705 /* If frame is ``official'', nothing to do. */
2706 if (NILP (Fmemq (frame
, Vframe_list
)))
2708 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2709 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2712 x_free_frame_resources (f
);
2715 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2716 /* Check that reference counts are indeed correct. */
2717 eassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
2718 eassert (dpyinfo
->terminal
->image_cache
->refcount
== image_cache_refcount
);
2727 do_unwind_create_frame (Lisp_Object frame
)
2729 unwind_create_frame (frame
);
2733 unwind_create_frame_1 (Lisp_Object val
)
2735 inhibit_lisp_code
= val
;
2739 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
2741 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2742 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
2744 Lisp_Object font
= Qnil
;
2745 if (EQ (font_param
, Qunbound
))
2748 if (NILP (font_param
))
2750 /* System font should take precedence over X resources. We suggest this
2751 regardless of font-use-system-font because .emacs may not have been
2753 const char *system_font
= xsettings_get_system_font ();
2755 font
= font_open_by_name (f
, build_unibyte_string (system_font
));
2759 font
= !NILP (font_param
) ? font_param
2760 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
2762 if (! FONTP (font
) && ! STRINGP (font
))
2767 /* This will find the normal Xft font. */
2770 "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1",
2771 "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2772 "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2773 /* This was formerly the first thing tried, but it finds
2774 too many fonts and takes too long. */
2775 "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1",
2776 /* If those didn't work, look for something which will
2778 "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1",
2783 for (i
= 0; names
[i
]; i
++)
2785 font
= font_open_by_name (f
, build_unibyte_string (names
[i
]));
2790 error ("No suitable font was found");
2792 else if (!NILP (font_param
))
2794 /* Remember the explicit font parameter, so we can re-apply it after
2795 we've applied the `default' face settings. */
2796 x_set_frame_parameters (f
, list1 (Fcons (Qfont_param
, font_param
)));
2799 /* This call will make X resources override any system font setting. */
2800 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
2804 DEFUN ("x-wm-set-size-hint", Fx_wm_set_size_hint
, Sx_wm_set_size_hint
,
2806 doc
: /* Send the size hints for frame FRAME to the window manager.
2807 If FRAME is omitted or nil, use the selected frame.
2808 Signal error if FRAME is not an X frame. */)
2811 struct frame
*f
= decode_window_system_frame (frame
);
2814 x_wm_set_size_hint (f
, 0, 0);
2820 set_machine_and_pid_properties (struct frame
*f
)
2822 long pid
= (long) getpid ();
2824 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME. */
2825 XSetWMProperties (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), NULL
, NULL
,
2826 NULL
, 0, NULL
, NULL
, NULL
);
2827 XChangeProperty (FRAME_X_DISPLAY (f
),
2828 FRAME_OUTER_WINDOW (f
),
2829 XInternAtom (FRAME_X_DISPLAY (f
),
2832 XA_CARDINAL
, 32, PropModeReplace
,
2833 (unsigned char *) &pid
, 1);
2836 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
2838 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
2839 Return an Emacs frame object.
2840 PARMS is an alist of frame parameters.
2841 If the parameters specify that the frame should not have a minibuffer,
2842 and do not specify a specific minibuffer window to use,
2843 then `default-minibuffer-frame' must be a frame whose minibuffer can
2844 be shared by the new frame.
2846 This function is an internal primitive--use `make-frame' instead. */)
2850 Lisp_Object frame
, tem
;
2852 int minibuffer_only
= 0;
2853 long window_prompting
= 0;
2855 ptrdiff_t count
= SPECPDL_INDEX ();
2856 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
2857 Lisp_Object display
;
2858 struct x_display_info
*dpyinfo
= NULL
;
2862 parms
= Fcopy_alist (parms
);
2864 /* Use this general default value to start with
2865 until we know if this frame has a specified name. */
2866 Vx_resource_name
= Vinvocation_name
;
2868 display
= x_get_arg (dpyinfo
, parms
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
2869 if (EQ (display
, Qunbound
))
2870 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
2871 if (EQ (display
, Qunbound
))
2873 dpyinfo
= check_x_display_info (display
);
2874 kb
= dpyinfo
->terminal
->kboard
;
2876 if (!dpyinfo
->terminal
->name
)
2877 error ("Terminal is not live, can't create new frames on it");
2879 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
2881 && ! EQ (name
, Qunbound
)
2883 error ("Invalid frame name--not a string or nil");
2886 Vx_resource_name
= name
;
2888 /* See if parent window is specified. */
2889 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
2890 if (EQ (parent
, Qunbound
))
2892 if (! NILP (parent
))
2893 CHECK_NUMBER (parent
);
2895 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
2896 /* No need to protect DISPLAY because that's not used after passing
2897 it to make_frame_without_minibuffer. */
2899 GCPRO4 (parms
, parent
, name
, frame
);
2900 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
2902 if (EQ (tem
, Qnone
) || NILP (tem
))
2903 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
2904 else if (EQ (tem
, Qonly
))
2906 f
= make_minibuffer_frame ();
2907 minibuffer_only
= 1;
2909 else if (WINDOWP (tem
))
2910 f
= make_frame_without_minibuffer (tem
, kb
, display
);
2914 XSETFRAME (frame
, f
);
2916 f
->terminal
= dpyinfo
->terminal
;
2918 f
->output_method
= output_x_window
;
2919 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
2920 f
->output_data
.x
->icon_bitmap
= -1;
2921 FRAME_FONTSET (f
) = -1;
2922 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
2923 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
2924 #ifdef USE_TOOLKIT_SCROLL_BARS
2925 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
2926 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
2927 #endif /* USE_TOOLKIT_SCROLL_BARS */
2928 f
->output_data
.x
->white_relief
.pixel
= -1;
2929 f
->output_data
.x
->black_relief
.pixel
= -1;
2932 x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
2934 if (! STRINGP (f
->icon_name
))
2935 fset_icon_name (f
, Qnil
);
2937 FRAME_DISPLAY_INFO (f
) = dpyinfo
;
2939 /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe. */
2940 record_unwind_protect (do_unwind_create_frame
, frame
);
2942 /* These colors will be set anyway later, but it's important
2943 to get the color reference counts right, so initialize them! */
2946 struct gcpro gcpro1
;
2948 /* Function x_decode_color can signal an error. Make
2949 sure to initialize color slots so that we won't try
2950 to free colors we haven't allocated. */
2951 FRAME_FOREGROUND_PIXEL (f
) = -1;
2952 FRAME_BACKGROUND_PIXEL (f
) = -1;
2953 f
->output_data
.x
->cursor_pixel
= -1;
2954 f
->output_data
.x
->cursor_foreground_pixel
= -1;
2955 f
->output_data
.x
->border_pixel
= -1;
2956 f
->output_data
.x
->mouse_pixel
= -1;
2958 black
= build_string ("black");
2960 FRAME_FOREGROUND_PIXEL (f
)
2961 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2962 FRAME_BACKGROUND_PIXEL (f
)
2963 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2964 f
->output_data
.x
->cursor_pixel
2965 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2966 f
->output_data
.x
->cursor_foreground_pixel
2967 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2968 f
->output_data
.x
->border_pixel
2969 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2970 f
->output_data
.x
->mouse_pixel
2971 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
2975 /* Specify the parent under which to make this X window. */
2979 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
2980 f
->output_data
.x
->explicit_parent
= 1;
2984 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
2985 f
->output_data
.x
->explicit_parent
= 0;
2988 /* Set the name; the functions to which we pass f expect the name to
2990 if (EQ (name
, Qunbound
) || NILP (name
))
2992 fset_name (f
, build_string (dpyinfo
->x_id_name
));
2993 f
->explicit_name
= 0;
2997 fset_name (f
, name
);
2998 f
->explicit_name
= 1;
2999 /* use the frame's title when getting resources for this frame. */
3000 specbind (Qx_resource_name
, name
);
3003 #ifdef HAVE_FREETYPE
3005 register_font_driver (&xftfont_driver
, f
);
3006 #else /* not HAVE_XFT */
3007 register_font_driver (&ftxfont_driver
, f
);
3008 #endif /* not HAVE_XFT */
3009 #endif /* HAVE_FREETYPE */
3010 register_font_driver (&xfont_driver
, f
);
3012 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
3013 "fontBackend", "FontBackend", RES_TYPE_STRING
);
3015 /* Extract the window parameters from the supplied values
3016 that are needed to determine window geometry. */
3017 x_default_font_parameter (f
, parms
);
3018 if (!FRAME_FONT (f
))
3020 delete_frame (frame
, Qnoelisp
);
3021 error ("Invalid frame font");
3024 /* Frame contents get displaced if an embedded X window has a border. */
3025 if (! FRAME_X_EMBEDDED_P (f
))
3026 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
3027 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
3029 /* This defaults to 1 in order to match xterm. We recognize either
3030 internalBorderWidth or internalBorder (which is what xterm calls
3032 if (NILP (Fassq (Qinternal_border_width
, parms
)))
3036 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
3037 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
3038 if (! EQ (value
, Qunbound
))
3039 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
3042 x_default_parameter (f
, parms
, Qinternal_border_width
,
3043 #ifdef USE_GTK /* We used to impose 0 in xg_create_frame_widgets. */
3048 "internalBorderWidth", "internalBorderWidth",
3050 x_default_parameter (f
, parms
, Qright_divider_width
, make_number (0),
3051 NULL
, NULL
, RES_TYPE_NUMBER
);
3052 x_default_parameter (f
, parms
, Qbottom_divider_width
, make_number (0),
3053 NULL
, NULL
, RES_TYPE_NUMBER
);
3054 x_default_parameter (f
, parms
, Qvertical_scroll_bars
,
3055 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
3060 "verticalScrollBars", "ScrollBars",
3063 /* Also do the stuff which must be set before the window exists. */
3064 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3065 "foreground", "Foreground", RES_TYPE_STRING
);
3066 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3067 "background", "Background", RES_TYPE_STRING
);
3068 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3069 "pointerColor", "Foreground", RES_TYPE_STRING
);
3070 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3071 "borderColor", "BorderColor", RES_TYPE_STRING
);
3072 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3073 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3074 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3075 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3076 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3077 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3078 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3079 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3081 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3082 "scrollBarForeground",
3083 "ScrollBarForeground", 1);
3084 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3085 "scrollBarBackground",
3086 "ScrollBarBackground", 0);
3089 image_cache_refcount
=
3090 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
3091 dpyinfo_refcount
= dpyinfo
->reference_count
;
3092 #endif /* GLYPH_DEBUG */
3094 /* Init faces before x_default_parameter is called for scroll-bar
3095 parameters because that function calls x_set_scroll_bar_width,
3096 which calls change_frame_size, which calls Fset_window_buffer,
3097 which runs hooks, which call Fvertical_motion. At the end, we
3098 end up in init_iterator with a null face cache, which should not
3100 init_frame_faces (f
);
3102 /* PXW: This is a duplicate from below. We have to do it here since
3103 otherwise x_set_tool_bar_lines will work with the character sizes
3104 installed by init_frame_faces while the frame's pixel size is still
3105 calculated from a character size of 1 and we subsequently hit the
3106 eassert (height >= 0) assertion in window_box_height. The
3107 non-pixelwise code apparently worked around this because it had one
3108 frame line vs one toolbar line which left us with a zero root
3109 window height which was obviously wrong as well ... */
3110 change_frame_size (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
),
3111 FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
), 1, 0, 0, 1);
3113 /* Set the menu-bar-lines and tool-bar-lines parameters. We don't
3114 look up the X resources controlling the menu-bar and tool-bar
3115 here; they are processed specially at startup, and reflected in
3116 the values of the mode variables.
3118 Avoid calling window-configuration-change-hook; otherwise we
3119 could get an infloop in next_frame since the frame is not yet in
3122 ptrdiff_t count2
= SPECPDL_INDEX ();
3123 record_unwind_protect (unwind_create_frame_1
, inhibit_lisp_code
);
3124 inhibit_lisp_code
= Qt
;
3126 x_default_parameter (f
, parms
, Qmenu_bar_lines
,
3127 NILP (Vmenu_bar_mode
)
3128 ? make_number (0) : make_number (1),
3129 NULL
, NULL
, RES_TYPE_NUMBER
);
3130 x_default_parameter (f
, parms
, Qtool_bar_lines
,
3131 NILP (Vtool_bar_mode
)
3132 ? make_number (0) : make_number (1),
3133 NULL
, NULL
, RES_TYPE_NUMBER
);
3135 unbind_to (count2
, Qnil
);
3138 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3139 "bufferPredicate", "BufferPredicate",
3141 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3142 "title", "Title", RES_TYPE_STRING
);
3143 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3144 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3145 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3146 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3147 x_default_parameter (f
, parms
, Qtool_bar_position
,
3148 f
->tool_bar_position
, 0, 0, RES_TYPE_SYMBOL
);
3150 /* Compute the size of the X window. */
3151 window_prompting
= x_figure_window_size (f
, parms
, 1);
3153 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3154 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3156 x_icon_verify (f
, parms
);
3158 /* Create the X widget or window. */
3159 #ifdef USE_X_TOOLKIT
3160 x_window (f
, window_prompting
, minibuffer_only
);
3168 /* Now consider the frame official. */
3169 f
->terminal
->reference_count
++;
3170 FRAME_DISPLAY_INFO (f
)->reference_count
++;
3171 Vframe_list
= Fcons (frame
, Vframe_list
);
3173 /* We need to do this after creating the X window, so that the
3174 icon-creation functions can say whose icon they're describing. */
3175 x_default_parameter (f
, parms
, Qicon_type
, Qt
,
3176 "bitmapIcon", "BitmapIcon", RES_TYPE_BOOLEAN
);
3178 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3179 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3180 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3181 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3182 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3183 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3184 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3185 "scrollBarWidth", "ScrollBarWidth",
3187 x_default_parameter (f
, parms
, Qalpha
, Qnil
,
3188 "alpha", "Alpha", RES_TYPE_NUMBER
);
3190 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
3191 Change will not be effected unless different from the current
3193 width
= FRAME_TEXT_WIDTH (f
);
3194 height
= FRAME_TEXT_HEIGHT (f
);
3195 FRAME_TEXT_HEIGHT (f
) = 0;
3196 SET_FRAME_WIDTH (f
, 0);
3197 change_frame_size (f
, width
, height
, 1, 0, 0, 1);
3199 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3200 /* Create the menu bar. */
3201 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3203 /* If this signals an error, we haven't set size hints for the
3204 frame and we didn't make it visible. */
3205 initialize_frame_menubar (f
);
3208 /* This is a no-op, except under Motif where it arranges the
3209 main window for the widgets on it. */
3210 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3211 f
->output_data
.x
->menubar_widget
,
3212 f
->output_data
.x
->edit_widget
);
3213 #endif /* not USE_GTK */
3215 #endif /* USE_X_TOOLKIT || USE_GTK */
3217 /* Tell the server what size and position, etc, we want, and how
3218 badly we want them. This should be done after we have the menu
3219 bar so that its size can be taken into account. */
3221 x_wm_set_size_hint (f
, window_prompting
, 0);
3224 /* Make the window appear on the frame and enable display, unless
3225 the caller says not to. However, with explicit parent, Emacs
3226 cannot control visibility, so don't try. */
3227 if (! f
->output_data
.x
->explicit_parent
)
3229 Lisp_Object visibility
;
3231 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3233 if (EQ (visibility
, Qunbound
))
3236 if (EQ (visibility
, Qicon
))
3237 x_iconify_frame (f
);
3238 else if (! NILP (visibility
))
3239 x_make_frame_visible (f
);
3242 /* Must have been Qnil. */
3248 /* Set machine name and pid for the purpose of window managers. */
3249 set_machine_and_pid_properties (f
);
3251 /* Set the WM leader property. GTK does this itself, so this is not
3252 needed when using GTK. */
3253 if (dpyinfo
->client_leader_window
!= 0)
3255 XChangeProperty (FRAME_X_DISPLAY (f
),
3256 FRAME_OUTER_WINDOW (f
),
3257 dpyinfo
->Xatom_wm_client_leader
,
3258 XA_WINDOW
, 32, PropModeReplace
,
3259 (unsigned char *) &dpyinfo
->client_leader_window
, 1);
3264 /* Initialize `default-minibuffer-frame' in case this is the first
3265 frame on this terminal. */
3266 if (FRAME_HAS_MINIBUF_P (f
)
3267 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
3268 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
3269 kset_default_minibuffer_frame (kb
, frame
);
3271 /* All remaining specified parameters, which have not been "used"
3272 by x_get_arg and friends, now go in the misc. alist of the frame. */
3273 for (tem
= parms
; CONSP (tem
); tem
= XCDR (tem
))
3274 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
3275 fset_param_alist (f
, Fcons (XCAR (tem
), f
->param_alist
));
3279 /* Make sure windows on this frame appear in calls to next-window
3280 and similar functions. */
3281 Vwindow_list
= Qnil
;
3283 return unbind_to (count
, frame
);
3287 /* FRAME is used only to get a handle on the X display. We don't pass the
3288 display info directly because we're called from frame.c, which doesn't
3289 know about that structure. */
3292 x_get_focus_frame (struct frame
*frame
)
3294 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (frame
);
3296 if (! dpyinfo
->x_focus_frame
)
3299 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3304 /* In certain situations, when the window manager follows a
3305 click-to-focus policy, there seems to be no way around calling
3306 XSetInputFocus to give another frame the input focus .
3308 In an ideal world, XSetInputFocus should generally be avoided so
3309 that applications don't interfere with the window manager's focus
3310 policy. But I think it's okay to use when it's clearly done
3311 following a user-command. */
3314 x_focus_frame (struct frame
*f
)
3316 Display
*dpy
= FRAME_X_DISPLAY (f
);
3319 x_catch_errors (dpy
);
3321 if (FRAME_X_EMBEDDED_P (f
))
3323 /* For Xembedded frames, normally the embedder forwards key
3324 events. See XEmbed Protocol Specification at
3325 http://freedesktop.org/wiki/Specifications/xembed-spec */
3326 xembed_request_focus (f
);
3330 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3331 RevertToParent
, CurrentTime
);
3332 x_ewmh_activate_frame (f
);
3335 x_uncatch_errors ();
3340 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
3341 doc
: /* Internal function called by `color-defined-p', which see
3342 .\(Note that the Nextstep version of this function ignores FRAME.) */)
3343 (Lisp_Object color
, Lisp_Object frame
)
3346 struct frame
*f
= decode_window_system_frame (frame
);
3348 CHECK_STRING (color
);
3350 if (x_defined_color (f
, SSDATA (color
), &foo
, 0))
3356 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
3357 doc
: /* Internal function called by `color-values', which see. */)
3358 (Lisp_Object color
, Lisp_Object frame
)
3361 struct frame
*f
= decode_window_system_frame (frame
);
3363 CHECK_STRING (color
);
3365 if (x_defined_color (f
, SSDATA (color
), &foo
, 0))
3366 return list3i (foo
.red
, foo
.green
, foo
.blue
);
3371 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
3372 doc
: /* Internal function called by `display-color-p', which see. */)
3373 (Lisp_Object terminal
)
3375 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3377 if (dpyinfo
->n_planes
<= 2)
3380 switch (dpyinfo
->visual
->class)
3393 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3395 doc
: /* Return t if the X display supports shades of gray.
3396 Note that color displays do support shades of gray.
3397 The optional argument TERMINAL specifies which display to ask about.
3398 TERMINAL should be a terminal object, a frame or a display name (a string).
3399 If omitted or nil, that stands for the selected frame's display. */)
3400 (Lisp_Object terminal
)
3402 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3404 if (dpyinfo
->n_planes
<= 1)
3407 switch (dpyinfo
->visual
->class)
3422 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3424 doc
: /* Return the width in pixels of the X display TERMINAL.
3425 The optional argument TERMINAL specifies which display to ask about.
3426 TERMINAL should be a terminal object, a frame or a display name (a string).
3427 If omitted or nil, that stands for the selected frame's display.
3429 On \"multi-monitor\" setups this refers to the pixel width for all
3430 physical monitors associated with TERMINAL. To get information for
3431 each physical monitor, use `display-monitor-attributes-list'. */)
3432 (Lisp_Object terminal
)
3434 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3436 return make_number (x_display_pixel_width (dpyinfo
));
3439 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3440 Sx_display_pixel_height
, 0, 1, 0,
3441 doc
: /* Return the height in pixels of the X display TERMINAL.
3442 The optional argument TERMINAL specifies which display to ask about.
3443 TERMINAL should be a terminal object, a frame or a display name (a string).
3444 If omitted or nil, that stands for the selected frame's display.
3446 On \"multi-monitor\" setups this refers to the pixel height for all
3447 physical monitors associated with TERMINAL. To get information for
3448 each physical monitor, use `display-monitor-attributes-list'. */)
3449 (Lisp_Object terminal
)
3451 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3453 return make_number (x_display_pixel_height (dpyinfo
));
3456 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3458 doc
: /* Return the number of bitplanes of the X display TERMINAL.
3459 The optional argument TERMINAL specifies which display to ask about.
3460 TERMINAL should be a terminal object, a frame or a display name (a string).
3461 If omitted or nil, that stands for the selected frame's display. */)
3462 (Lisp_Object terminal
)
3464 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3466 return make_number (dpyinfo
->n_planes
);
3469 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3471 doc
: /* Return the number of color cells of the X display TERMINAL.
3472 The optional argument TERMINAL specifies which display to ask about.
3473 TERMINAL should be a terminal object, a frame or a display name (a string).
3474 If omitted or nil, that stands for the selected frame's display. */)
3475 (Lisp_Object terminal
)
3477 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3479 int nr_planes
= DisplayPlanes (dpyinfo
->display
,
3480 XScreenNumberOfScreen (dpyinfo
->screen
));
3482 /* Truncate nr_planes to 24 to avoid integer overflow.
3483 Some displays says 32, but only 24 bits are actually significant.
3484 There are only very few and rare video cards that have more than
3485 24 significant bits. Also 24 bits is more than 16 million colors,
3486 it "should be enough for everyone". */
3487 if (nr_planes
> 24) nr_planes
= 24;
3489 return make_number (1 << nr_planes
);
3492 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3493 Sx_server_max_request_size
,
3495 doc
: /* Return the maximum request size of the X server of display TERMINAL.
3496 The optional argument TERMINAL specifies which display to ask about.
3497 TERMINAL should be a terminal object, a frame or a display name (a string).
3498 If omitted or nil, that stands for the selected frame's display. */)
3499 (Lisp_Object terminal
)
3501 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3503 return make_number (MAXREQUEST (dpyinfo
->display
));
3506 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3507 doc
: /* Return the "vendor ID" string of the X server of display TERMINAL.
3508 \(Labeling every distributor as a "vendor" embodies the false assumption
3509 that operating systems cannot be developed and distributed noncommercially.)
3510 The optional argument TERMINAL specifies which display to ask about.
3511 TERMINAL should be a terminal object, a frame or a display name (a string).
3512 If omitted or nil, that stands for the selected frame's display. */)
3513 (Lisp_Object terminal
)
3515 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3516 const char *vendor
= ServerVendor (dpyinfo
->display
);
3518 if (! vendor
) vendor
= "";
3519 return build_string (vendor
);
3522 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3523 doc
: /* Return the version numbers of the X server of display TERMINAL.
3524 The value is a list of three integers: the major and minor
3525 version numbers of the X Protocol in use, and the distributor-specific release
3526 number. See also the function `x-server-vendor'.
3528 The optional argument TERMINAL specifies which display to ask about.
3529 TERMINAL should be a terminal object, a frame or a display name (a string).
3530 If omitted or nil, that stands for the selected frame's display. */)
3531 (Lisp_Object terminal
)
3533 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3534 Display
*dpy
= dpyinfo
->display
;
3536 return list3i (ProtocolVersion (dpy
), ProtocolRevision (dpy
),
3537 VendorRelease (dpy
));
3540 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3541 doc
: /* Return the number of screens on the X server of display TERMINAL.
3542 The optional argument TERMINAL specifies which display to ask about.
3543 TERMINAL should be a terminal object, a frame or a display name (a string).
3544 If omitted or nil, that stands for the selected frame's display. */)
3545 (Lisp_Object terminal
)
3547 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3549 return make_number (ScreenCount (dpyinfo
->display
));
3552 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3553 doc
: /* Return the height in millimeters of the X display TERMINAL.
3554 The optional argument TERMINAL specifies which display to ask about.
3555 TERMINAL should be a terminal object, a frame or a display name (a string).
3556 If omitted or nil, that stands for the selected frame's display.
3558 On \"multi-monitor\" setups this refers to the height in millimeters for
3559 all physical monitors associated with TERMINAL. To get information
3560 for each physical monitor, use `display-monitor-attributes-list'. */)
3561 (Lisp_Object terminal
)
3563 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3565 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3568 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3569 doc
: /* Return the width in millimeters of the X display TERMINAL.
3570 The optional argument TERMINAL specifies which display to ask about.
3571 TERMINAL should be a terminal object, a frame or a display name (a string).
3572 If omitted or nil, that stands for the selected frame's display.
3574 On \"multi-monitor\" setups this refers to the width in millimeters for
3575 all physical monitors associated with TERMINAL. To get information
3576 for each physical monitor, use `display-monitor-attributes-list'. */)
3577 (Lisp_Object terminal
)
3579 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3581 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3584 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3585 Sx_display_backing_store
, 0, 1, 0,
3586 doc
: /* Return an indication of whether X display TERMINAL does backing store.
3587 The value may be `always', `when-mapped', or `not-useful'.
3588 The optional argument TERMINAL specifies which display to ask about.
3589 TERMINAL should be a terminal object, a frame or a display name (a string).
3590 If omitted or nil, that stands for the selected frame's display. */)
3591 (Lisp_Object terminal
)
3593 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3596 switch (DoesBackingStore (dpyinfo
->screen
))
3599 result
= intern ("always");
3603 result
= intern ("when-mapped");
3607 result
= intern ("not-useful");
3611 error ("Strange value for BackingStore parameter of screen");
3617 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3618 Sx_display_visual_class
, 0, 1, 0,
3619 doc
: /* Return the visual class of the X display TERMINAL.
3620 The value is one of the symbols `static-gray', `gray-scale',
3621 `static-color', `pseudo-color', `true-color', or `direct-color'.
3623 The optional argument TERMINAL specifies which display to ask about.
3624 TERMINAL should a terminal object, a frame or a display name (a string).
3625 If omitted or nil, that stands for the selected frame's display. */)
3626 (Lisp_Object terminal
)
3628 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3631 switch (dpyinfo
->visual
->class)
3634 result
= intern ("static-gray");
3637 result
= intern ("gray-scale");
3640 result
= intern ("static-color");
3643 result
= intern ("pseudo-color");
3646 result
= intern ("true-color");
3649 result
= intern ("direct-color");
3652 error ("Display has an unknown visual class");
3658 DEFUN ("x-display-save-under", Fx_display_save_under
,
3659 Sx_display_save_under
, 0, 1, 0,
3660 doc
: /* Return t if the X display TERMINAL supports the save-under feature.
3661 The optional argument TERMINAL specifies which display to ask about.
3662 TERMINAL should be a terminal object, a frame or a display name (a string).
3663 If omitted or nil, that stands for the selected frame's display. */)
3664 (Lisp_Object terminal
)
3666 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3668 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3674 /* Store the geometry of the workarea on display DPYINFO into *RECT.
3675 Return false if and only if the workarea information cannot be
3676 obtained via the _NET_WORKAREA root window property. */
3678 #if ! GTK_CHECK_VERSION (3, 4, 0)
3680 x_get_net_workarea (struct x_display_info
*dpyinfo
, XRectangle
*rect
)
3682 Display
*dpy
= dpyinfo
->display
;
3683 long offset
, max_len
;
3684 Atom target_type
, actual_type
;
3685 unsigned long actual_size
, bytes_remaining
;
3686 int rc
, actual_format
;
3687 unsigned char *tmp_data
= NULL
;
3688 bool result
= false;
3690 x_catch_errors (dpy
);
3693 target_type
= XA_CARDINAL
;
3694 rc
= XGetWindowProperty (dpy
, dpyinfo
->root_window
,
3695 dpyinfo
->Xatom_net_current_desktop
,
3696 offset
, max_len
, False
, target_type
,
3697 &actual_type
, &actual_format
, &actual_size
,
3698 &bytes_remaining
, &tmp_data
);
3699 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
3700 && actual_format
== 32 && actual_size
== max_len
)
3702 long current_desktop
= ((long *) tmp_data
)[0];
3707 offset
= 4 * current_desktop
;
3709 rc
= XGetWindowProperty (dpy
, dpyinfo
->root_window
,
3710 dpyinfo
->Xatom_net_workarea
,
3711 offset
, max_len
, False
, target_type
,
3712 &actual_type
, &actual_format
, &actual_size
,
3713 &bytes_remaining
, &tmp_data
);
3714 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
3715 && actual_format
== 32 && actual_size
== max_len
)
3717 long *values
= (long *) tmp_data
;
3719 rect
->x
= values
[0];
3720 rect
->y
= values
[1];
3721 rect
->width
= values
[2];
3722 rect
->height
= values
[3];
3732 x_uncatch_errors ();
3740 /* Return monitor number where F is "most" or closest to. */
3742 x_get_monitor_for_frame (struct frame
*f
,
3743 struct MonitorInfo
*monitors
,
3747 int area
= 0, dist
= -1;
3748 int best_area
= -1, best_dist
= -1;
3751 if (n_monitors
== 1) return 0;
3752 frect
.x
= f
->left_pos
;
3753 frect
.y
= f
->top_pos
;
3754 frect
.width
= FRAME_PIXEL_WIDTH (f
);
3755 frect
.height
= FRAME_PIXEL_HEIGHT (f
);
3757 for (i
= 0; i
< n_monitors
; ++i
)
3759 struct MonitorInfo
*mi
= &monitors
[i
];
3763 if (mi
->geom
.width
== 0) continue;
3765 if (x_intersect_rectangles (&mi
->geom
, &frect
, &res
))
3767 a
= res
.width
* res
.height
;
3775 if (a
== 0 && area
== 0)
3778 if (frect
.x
+ frect
.width
< mi
->geom
.x
)
3779 dx
= mi
->geom
.x
- frect
.x
+ frect
.width
;
3780 else if (frect
.x
> mi
->geom
.x
+ mi
->geom
.width
)
3781 dx
= frect
.x
- mi
->geom
.x
+ mi
->geom
.width
;
3784 if (frect
.y
+ frect
.height
< mi
->geom
.y
)
3785 dy
= mi
->geom
.y
- frect
.y
+ frect
.height
;
3786 else if (frect
.y
> mi
->geom
.y
+ mi
->geom
.height
)
3787 dy
= frect
.y
- mi
->geom
.y
+ mi
->geom
.height
;
3792 if (dist
== -1 || dist
> d
)
3800 return best_area
!= -1 ? best_area
: (best_dist
!= -1 ? best_dist
: 0);
3804 x_make_monitor_attribute_list (struct MonitorInfo
*monitors
,
3806 int primary_monitor
,
3807 struct x_display_info
*dpyinfo
,
3810 Lisp_Object monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
3811 Lisp_Object frame
, rest
;
3813 FOR_EACH_FRAME (rest
, frame
)
3815 struct frame
*f
= XFRAME (frame
);
3817 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
3818 && !EQ (frame
, tip_frame
))
3820 int i
= x_get_monitor_for_frame (f
, monitors
, n_monitors
);
3821 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
3825 return make_monitor_attribute_list (monitors
, n_monitors
, primary_monitor
,
3826 monitor_frames
, source
);
3830 x_get_monitor_attributes_fallback (struct x_display_info
*dpyinfo
)
3832 struct MonitorInfo monitor
;
3833 XRectangle workarea_r
;
3835 /* Fallback: treat (possibly) multiple physical monitors as if they
3836 formed a single monitor as a whole. This should provide a
3837 consistent result at least on single monitor environments. */
3838 monitor
.geom
.x
= monitor
.geom
.y
= 0;
3839 monitor
.geom
.width
= x_display_pixel_width (dpyinfo
);
3840 monitor
.geom
.height
= x_display_pixel_height (dpyinfo
);
3841 monitor
.mm_width
= WidthMMOfScreen (dpyinfo
->screen
);
3842 monitor
.mm_height
= HeightMMOfScreen (dpyinfo
->screen
);
3843 monitor
.name
= xstrdup ("combined screen");
3845 if (x_get_net_workarea (dpyinfo
, &workarea_r
))
3846 monitor
.work
= workarea_r
;
3848 monitor
.work
= monitor
.geom
;
3849 return x_make_monitor_attribute_list (&monitor
, 1, 0, dpyinfo
, "fallback");
3853 #ifdef HAVE_XINERAMA
3855 x_get_monitor_attributes_xinerama (struct x_display_info
*dpyinfo
)
3858 Lisp_Object attributes_list
= Qnil
;
3859 Display
*dpy
= dpyinfo
->display
;
3860 XineramaScreenInfo
*info
= XineramaQueryScreens (dpy
, &n_monitors
);
3861 struct MonitorInfo
*monitors
;
3862 double mm_width_per_pixel
, mm_height_per_pixel
;
3864 if (! info
|| n_monitors
== 0)
3868 return attributes_list
;
3871 mm_width_per_pixel
= ((double) WidthMMOfScreen (dpyinfo
->screen
)
3872 / x_display_pixel_width (dpyinfo
));
3873 mm_height_per_pixel
= ((double) HeightMMOfScreen (dpyinfo
->screen
)
3874 / x_display_pixel_height (dpyinfo
));
3875 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
3876 for (i
= 0; i
< n_monitors
; ++i
)
3878 struct MonitorInfo
*mi
= &monitors
[i
];
3879 XRectangle workarea_r
;
3881 mi
->geom
.x
= info
[i
].x_org
;
3882 mi
->geom
.y
= info
[i
].y_org
;
3883 mi
->geom
.width
= info
[i
].width
;
3884 mi
->geom
.height
= info
[i
].height
;
3885 mi
->mm_width
= mi
->geom
.width
* mm_width_per_pixel
+ 0.5;
3886 mi
->mm_height
= mi
->geom
.height
* mm_height_per_pixel
+ 0.5;
3889 /* Xinerama usually have primary monitor first, just use that. */
3890 if (i
== 0 && x_get_net_workarea (dpyinfo
, &workarea_r
))
3892 mi
->work
= workarea_r
;
3893 if (! x_intersect_rectangles (&mi
->geom
, &mi
->work
, &mi
->work
))
3894 mi
->work
= mi
->geom
;
3897 mi
->work
= mi
->geom
;
3901 attributes_list
= x_make_monitor_attribute_list (monitors
,
3906 free_monitors (monitors
, n_monitors
);
3907 return attributes_list
;
3909 #endif /* HAVE_XINERAMA */
3914 x_get_monitor_attributes_xrandr (struct x_display_info
*dpyinfo
)
3916 Lisp_Object attributes_list
= Qnil
;
3917 XRRScreenResources
*resources
;
3918 Display
*dpy
= dpyinfo
->display
;
3919 int i
, n_monitors
, primary
= -1;
3920 RROutput pxid
= None
;
3921 struct MonitorInfo
*monitors
;
3923 #ifdef HAVE_XRRGETSCREENRESOURCESCURRENT
3924 resources
= XRRGetScreenResourcesCurrent (dpy
, dpyinfo
->root_window
);
3926 resources
= XRRGetScreenResources (dpy
, dpyinfo
->root_window
);
3928 if (! resources
|| resources
->noutput
== 0)
3931 XRRFreeScreenResources (resources
);
3934 n_monitors
= resources
->noutput
;
3935 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
3937 #ifdef HAVE_XRRGETOUTPUTPRIMARY
3938 pxid
= XRRGetOutputPrimary (dpy
, dpyinfo
->root_window
);
3941 for (i
= 0; i
< n_monitors
; ++i
)
3943 XRROutputInfo
*info
= XRRGetOutputInfo (dpy
, resources
,
3944 resources
->outputs
[i
]);
3945 Connection conn
= info
? info
->connection
: RR_Disconnected
;
3946 RRCrtc id
= info
? info
->crtc
: None
;
3948 if (strcmp (info
->name
, "default") == 0)
3950 /* Non XRandr 1.2 driver, does not give useful data. */
3951 XRRFreeOutputInfo (info
);
3952 XRRFreeScreenResources (resources
);
3953 free_monitors (monitors
, n_monitors
);
3957 if (conn
!= RR_Disconnected
&& id
!= None
)
3959 XRRCrtcInfo
*crtc
= XRRGetCrtcInfo (dpy
, resources
, id
);
3960 struct MonitorInfo
*mi
= &monitors
[i
];
3961 XRectangle workarea_r
;
3965 XRRFreeOutputInfo (info
);
3969 mi
->geom
.x
= crtc
->x
;
3970 mi
->geom
.y
= crtc
->y
;
3971 mi
->geom
.width
= crtc
->width
;
3972 mi
->geom
.height
= crtc
->height
;
3973 mi
->mm_width
= info
->mm_width
;
3974 mi
->mm_height
= info
->mm_height
;
3975 mi
->name
= xstrdup (info
->name
);
3977 if (pxid
!= None
&& pxid
== resources
->outputs
[i
])
3979 else if (primary
== -1 && strcmp (info
->name
, "LVDS") == 0)
3982 if (i
== primary
&& x_get_net_workarea (dpyinfo
, &workarea_r
))
3984 mi
->work
= workarea_r
;
3985 if (! x_intersect_rectangles (&mi
->geom
, &mi
->work
, &mi
->work
))
3986 mi
->work
= mi
->geom
;
3989 mi
->work
= mi
->geom
;
3991 XRRFreeCrtcInfo (crtc
);
3993 XRRFreeOutputInfo (info
);
3995 XRRFreeScreenResources (resources
);
3997 attributes_list
= x_make_monitor_attribute_list (monitors
,
4002 free_monitors (monitors
, n_monitors
);
4003 return attributes_list
;
4005 #endif /* HAVE_XRANDR */
4008 x_get_monitor_attributes (struct x_display_info
*dpyinfo
)
4010 Lisp_Object attributes_list
= Qnil
;
4011 Display
*dpy
= dpyinfo
->display
;
4013 (void) dpy
; /* Suppress unused variable warning. */
4016 int xrr_event_base
, xrr_error_base
;
4017 bool xrr_ok
= false;
4018 xrr_ok
= XRRQueryExtension (dpy
, &xrr_event_base
, &xrr_error_base
);
4021 int xrr_major
, xrr_minor
;
4022 XRRQueryVersion (dpy
, &xrr_major
, &xrr_minor
);
4023 xrr_ok
= (xrr_major
== 1 && xrr_minor
>= 2) || xrr_major
> 1;
4027 attributes_list
= x_get_monitor_attributes_xrandr (dpyinfo
);
4028 #endif /* HAVE_XRANDR */
4030 #ifdef HAVE_XINERAMA
4031 if (NILP (attributes_list
))
4033 int xin_event_base
, xin_error_base
;
4034 bool xin_ok
= false;
4035 xin_ok
= XineramaQueryExtension (dpy
, &xin_event_base
, &xin_error_base
);
4036 if (xin_ok
&& XineramaIsActive (dpy
))
4037 attributes_list
= x_get_monitor_attributes_xinerama (dpyinfo
);
4039 #endif /* HAVE_XINERAMA */
4041 if (NILP (attributes_list
))
4042 attributes_list
= x_get_monitor_attributes_fallback (dpyinfo
);
4044 return attributes_list
;
4047 #endif /* !USE_GTK */
4049 DEFUN ("x-display-monitor-attributes-list", Fx_display_monitor_attributes_list
,
4050 Sx_display_monitor_attributes_list
,
4052 doc
: /* Return a list of physical monitor attributes on the X display TERMINAL.
4054 The optional argument TERMINAL specifies which display to ask about.
4055 TERMINAL should be a terminal object, a frame or a display name (a string).
4056 If omitted or nil, that stands for the selected frame's display.
4058 In addition to the standard attribute keys listed in
4059 `display-monitor-attributes-list', the following keys are contained in
4062 source -- String describing the source from which multi-monitor
4063 information is obtained, one of \"Gdk\", \"XRandr\",
4064 \"Xinerama\", or \"fallback\"
4066 Internal use only, use `display-monitor-attributes-list' instead. */)
4067 (Lisp_Object terminal
)
4069 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4070 Lisp_Object attributes_list
= Qnil
;
4073 double mm_width_per_pixel
, mm_height_per_pixel
;
4076 gint primary_monitor
= 0, n_monitors
, i
;
4077 Lisp_Object monitor_frames
, rest
, frame
;
4078 static const char *source
= "Gdk";
4079 struct MonitorInfo
*monitors
;
4082 mm_width_per_pixel
= ((double) WidthMMOfScreen (dpyinfo
->screen
)
4083 / x_display_pixel_width (dpyinfo
));
4084 mm_height_per_pixel
= ((double) HeightMMOfScreen (dpyinfo
->screen
)
4085 / x_display_pixel_height (dpyinfo
));
4086 gdpy
= gdk_x11_lookup_xdisplay (dpyinfo
->display
);
4087 gscreen
= gdk_display_get_default_screen (gdpy
);
4088 #if GTK_CHECK_VERSION (2, 20, 0)
4089 primary_monitor
= gdk_screen_get_primary_monitor (gscreen
);
4091 n_monitors
= gdk_screen_get_n_monitors (gscreen
);
4092 monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
4093 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
4095 FOR_EACH_FRAME (rest
, frame
)
4097 struct frame
*f
= XFRAME (frame
);
4099 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
4100 && !EQ (frame
, tip_frame
))
4102 GdkWindow
*gwin
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
4104 i
= gdk_screen_get_monitor_at_window (gscreen
, gwin
);
4105 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
4109 for (i
= 0; i
< n_monitors
; ++i
)
4111 gint width_mm
= -1, height_mm
= -1;
4112 GdkRectangle rec
, work
;
4113 struct MonitorInfo
*mi
= &monitors
[i
];
4115 gdk_screen_get_monitor_geometry (gscreen
, i
, &rec
);
4117 #if GTK_CHECK_VERSION (2, 14, 0)
4118 width_mm
= gdk_screen_get_monitor_width_mm (gscreen
, i
);
4119 height_mm
= gdk_screen_get_monitor_height_mm (gscreen
, i
);
4122 width_mm
= rec
.width
* mm_width_per_pixel
+ 0.5;
4124 height_mm
= rec
.height
* mm_height_per_pixel
+ 0.5;
4126 #if GTK_CHECK_VERSION (3, 4, 0)
4127 gdk_screen_get_monitor_workarea (gscreen
, i
, &work
);
4129 /* Emulate the behavior of GTK+ 3.4. */
4131 XRectangle workarea_r
;
4133 if (i
== primary_monitor
&& x_get_net_workarea (dpyinfo
, &workarea_r
))
4135 work
.x
= workarea_r
.x
;
4136 work
.y
= workarea_r
.y
;
4137 work
.width
= workarea_r
.width
;
4138 work
.height
= workarea_r
.height
;
4139 if (! gdk_rectangle_intersect (&rec
, &work
, &work
))
4150 mi
->geom
.width
= rec
.width
;
4151 mi
->geom
.height
= rec
.height
;
4152 mi
->work
.x
= work
.x
;
4153 mi
->work
.y
= work
.y
;
4154 mi
->work
.width
= work
.width
;
4155 mi
->work
.height
= work
.height
;
4156 mi
->mm_width
= width_mm
;
4157 mi
->mm_height
= height_mm
;
4159 #if GTK_CHECK_VERSION (2, 14, 0)
4160 mi
->name
= gdk_screen_get_monitor_plug_name (gscreen
, i
);
4164 attributes_list
= make_monitor_attribute_list (monitors
,
4170 #else /* not USE_GTK */
4173 attributes_list
= x_get_monitor_attributes (dpyinfo
);
4176 #endif /* not USE_GTK */
4178 return attributes_list
;
4181 /************************************************************************
4183 ************************************************************************/
4186 /* Mapping visual names to visuals. */
4188 static struct visual_class
4195 {"StaticGray", StaticGray
},
4196 {"GrayScale", GrayScale
},
4197 {"StaticColor", StaticColor
},
4198 {"PseudoColor", PseudoColor
},
4199 {"TrueColor", TrueColor
},
4200 {"DirectColor", DirectColor
},
4205 #ifndef HAVE_XSCREENNUMBEROFSCREEN
4207 /* Value is the screen number of screen SCR. This is a substitute for
4208 the X function with the same name when that doesn't exist. */
4211 XScreenNumberOfScreen (scr
)
4212 register Screen
*scr
;
4214 Display
*dpy
= scr
->display
;
4217 for (i
= 0; i
< dpy
->nscreens
; ++i
)
4218 if (scr
== dpy
->screens
+ i
)
4224 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
4227 /* Select the visual that should be used on display DPYINFO. Set
4228 members of DPYINFO appropriately. Called from x_term_init. */
4231 select_visual (struct x_display_info
*dpyinfo
)
4233 Display
*dpy
= dpyinfo
->display
;
4234 Screen
*screen
= dpyinfo
->screen
;
4237 /* See if a visual is specified. */
4238 value
= display_x_get_resource (dpyinfo
,
4239 build_string ("visualClass"),
4240 build_string ("VisualClass"),
4242 if (STRINGP (value
))
4244 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
4245 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
4246 depth, a decimal number. NAME is compared with case ignored. */
4247 char *s
= alloca (SBYTES (value
) + 1);
4252 strcpy (s
, SSDATA (value
));
4253 dash
= strchr (s
, '-');
4256 dpyinfo
->n_planes
= atoi (dash
+ 1);
4260 /* We won't find a matching visual with depth 0, so that
4261 an error will be printed below. */
4262 dpyinfo
->n_planes
= 0;
4264 /* Determine the visual class. */
4265 for (i
= 0; visual_classes
[i
].name
; ++i
)
4266 if (xstrcasecmp (s
, visual_classes
[i
].name
) == 0)
4268 class = visual_classes
[i
].class;
4272 /* Look up a matching visual for the specified class. */
4274 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
4275 dpyinfo
->n_planes
, class, &vinfo
))
4276 fatal ("Invalid visual specification `%s'", SDATA (value
));
4278 dpyinfo
->visual
= vinfo
.visual
;
4283 XVisualInfo
*vinfo
, vinfo_template
;
4285 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
4287 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
4288 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
4289 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
4290 &vinfo_template
, &n_visuals
);
4292 fatal ("Can't get proper X visual info");
4294 dpyinfo
->n_planes
= vinfo
->depth
;
4300 /* Return the X display structure for the display named NAME.
4301 Open a new connection if necessary. */
4303 static struct x_display_info
*
4304 x_display_info_for_name (Lisp_Object name
)
4306 struct x_display_info
*dpyinfo
;
4308 CHECK_STRING (name
);
4310 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
4311 if (!NILP (Fstring_equal (XCAR (dpyinfo
->name_list_element
), name
)))
4314 /* Use this general default value to start with. */
4315 Vx_resource_name
= Vinvocation_name
;
4317 validate_x_resource_name ();
4319 dpyinfo
= x_term_init (name
, 0, SSDATA (Vx_resource_name
));
4322 error ("Cannot connect to X server %s", SDATA (name
));
4324 XSETFASTINT (Vwindow_system_version
, 11);
4330 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4332 doc
: /* Open a connection to a display server.
4333 DISPLAY is the name of the display to connect to.
4334 Optional second arg XRM-STRING is a string of resources in xrdb format.
4335 If the optional third arg MUST-SUCCEED is non-nil,
4336 terminate Emacs if we can't open the connection.
4337 \(In the Nextstep version, the last two arguments are currently ignored.) */)
4338 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
4341 struct x_display_info
*dpyinfo
;
4343 CHECK_STRING (display
);
4344 if (! NILP (xrm_string
))
4345 CHECK_STRING (xrm_string
);
4347 xrm_option
= NILP (xrm_string
) ? 0 : SSDATA (xrm_string
);
4349 validate_x_resource_name ();
4351 /* This is what opens the connection and sets x_current_display.
4352 This also initializes many symbols, such as those used for input. */
4353 dpyinfo
= x_term_init (display
, xrm_option
,
4354 SSDATA (Vx_resource_name
));
4358 if (!NILP (must_succeed
))
4359 fatal ("Cannot connect to X server %s.\n\
4360 Check the DISPLAY environment variable or use `-d'.\n\
4361 Also use the `xauth' program to verify that you have the proper\n\
4362 authorization information needed to connect the X server.\n\
4363 An insecure way to solve the problem may be to use `xhost'.\n",
4366 error ("Cannot connect to X server %s", SDATA (display
));
4369 XSETFASTINT (Vwindow_system_version
, 11);
4373 DEFUN ("x-close-connection", Fx_close_connection
,
4374 Sx_close_connection
, 1, 1, 0,
4375 doc
: /* Close the connection to TERMINAL's X server.
4376 For TERMINAL, specify a terminal object, a frame or a display name (a
4377 string). If TERMINAL is nil, that stands for the selected frame's
4379 (Lisp_Object terminal
)
4381 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4383 if (dpyinfo
->reference_count
> 0)
4384 error ("Display still has frames on it");
4386 x_delete_terminal (dpyinfo
->terminal
);
4391 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4392 doc
: /* Return the list of display names that Emacs has connections to. */)
4395 Lisp_Object result
= Qnil
;
4396 struct x_display_info
*xdi
;
4398 for (xdi
= x_display_list
; xdi
; xdi
= xdi
->next
)
4399 result
= Fcons (XCAR (xdi
->name_list_element
), result
);
4404 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4405 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
4406 This function only has an effect on X Windows. With MS Windows, it is
4407 defined but does nothing.
4409 If ON is nil, allow buffering of requests.
4410 Turning on synchronization prohibits the Xlib routines from buffering
4411 requests and seriously degrades performance, but makes debugging much
4413 The optional second argument TERMINAL specifies which display to act on.
4414 TERMINAL should be a terminal object, a frame or a display name (a string).
4415 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
4416 (Lisp_Object on
, Lisp_Object terminal
)
4418 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4420 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
4425 /* Wait for responses to all X commands issued so far for frame F. */
4428 x_sync (struct frame
*f
)
4431 XSync (FRAME_X_DISPLAY (f
), False
);
4436 /***********************************************************************
4438 ***********************************************************************/
4440 DEFUN ("x-change-window-property", Fx_change_window_property
,
4441 Sx_change_window_property
, 2, 6, 0,
4442 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
4443 PROP must be a string. VALUE may be a string or a list of conses,
4444 numbers and/or strings. If an element in the list is a string, it is
4445 converted to an atom and the value of the atom is used. If an element
4446 is a cons, it is converted to a 32 bit number where the car is the 16
4447 top bits and the cdr is the lower 16 bits.
4449 FRAME nil or omitted means use the selected frame.
4450 If TYPE is given and non-nil, it is the name of the type of VALUE.
4451 If TYPE is not given or nil, the type is STRING.
4452 FORMAT gives the size in bits of each element if VALUE is a list.
4453 It must be one of 8, 16 or 32.
4454 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4455 If OUTER-P is non-nil, the property is changed for the outer X window of
4456 FRAME. Default is to change on the edit X window. */)
4457 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
,
4458 Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
4460 struct frame
*f
= decode_window_system_frame (frame
);
4462 Atom target_type
= XA_STRING
;
4463 int element_format
= 8;
4464 unsigned char *data
;
4468 CHECK_STRING (prop
);
4470 if (! NILP (format
))
4472 CHECK_NUMBER (format
);
4474 if (XINT (format
) != 8 && XINT (format
) != 16
4475 && XINT (format
) != 32)
4476 error ("FORMAT must be one of 8, 16 or 32");
4477 element_format
= XINT (format
);
4484 nelements
= x_check_property_data (value
);
4485 if (nelements
== -1)
4486 error ("Bad data in VALUE, must be number, string or cons");
4488 /* The man page for XChangeProperty:
4489 "If the specified format is 32, the property data must be a
4491 This applies even if long is more than 32 bits. The X library
4492 converts to 32 bits before sending to the X server. */
4493 elsize
= element_format
== 32 ? sizeof (long) : element_format
>> 3;
4494 data
= xnmalloc (nelements
, elsize
);
4496 x_fill_property_data (FRAME_X_DISPLAY (f
), value
, data
, element_format
);
4500 CHECK_STRING (value
);
4501 data
= SDATA (value
);
4502 if (INT_MAX
< SBYTES (value
))
4503 error ("VALUE too long");
4504 nelements
= SBYTES (value
);
4508 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4511 CHECK_STRING (type
);
4512 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
4515 if (! NILP (outer_p
)) w
= FRAME_OUTER_WINDOW (f
);
4516 else w
= FRAME_X_WINDOW (f
);
4518 XChangeProperty (FRAME_X_DISPLAY (f
), w
,
4519 prop_atom
, target_type
, element_format
, PropModeReplace
,
4522 if (CONSP (value
)) xfree (data
);
4524 /* Make sure the property is set when we return. */
4525 XFlush (FRAME_X_DISPLAY (f
));
4532 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
4533 Sx_delete_window_property
, 1, 2, 0,
4534 doc
: /* Remove window property PROP from X window of FRAME.
4535 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4536 (Lisp_Object prop
, Lisp_Object frame
)
4538 struct frame
*f
= decode_window_system_frame (frame
);
4541 CHECK_STRING (prop
);
4543 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4544 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
4546 /* Make sure the property is removed when we return. */
4547 XFlush (FRAME_X_DISPLAY (f
));
4555 x_window_property_intern (struct frame
*f
,
4556 Window target_window
,
4559 Lisp_Object delete_p
,
4560 Lisp_Object vector_ret_p
,
4563 unsigned char *tmp_data
= NULL
;
4564 Lisp_Object prop_value
= Qnil
;
4567 unsigned long actual_size
, bytes_remaining
;
4569 struct gcpro gcpro1
;
4571 GCPRO1 (prop_value
);
4573 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4574 prop_atom
, 0, 0, False
, target_type
,
4575 &actual_type
, &actual_format
, &actual_size
,
4576 &bytes_remaining
, &tmp_data
);
4578 *found
= actual_format
!= 0;
4580 if (rc
== Success
&& *found
)
4585 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4586 prop_atom
, 0, bytes_remaining
,
4587 ! NILP (delete_p
), target_type
,
4588 &actual_type
, &actual_format
,
4589 &actual_size
, &bytes_remaining
,
4591 if (rc
== Success
&& tmp_data
)
4593 /* The man page for XGetWindowProperty says:
4594 "If the returned format is 32, the returned data is represented
4595 as a long array and should be cast to that type to obtain the
4597 This applies even if long is more than 32 bits, the X library
4598 converts from 32 bit elements received from the X server to long
4599 and passes the long array to us. Thus, for that case memcpy can not
4600 be used. We convert to a 32 bit type here, because so much code
4603 The bytes and offsets passed to XGetWindowProperty refers to the
4604 property and those are indeed in 32 bit quantities if format is
4607 if (BITS_PER_LONG
> 32 && actual_format
== 32)
4610 int *idata
= (int *) tmp_data
;
4611 long *ldata
= (long *) tmp_data
;
4613 for (i
= 0; i
< actual_size
; ++i
)
4614 idata
[i
] = (int) ldata
[i
];
4617 if (NILP (vector_ret_p
))
4618 prop_value
= make_string ((char *) tmp_data
, actual_size
);
4620 prop_value
= x_property_data_to_lisp (f
,
4627 if (tmp_data
) XFree (tmp_data
);
4634 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
4636 doc
: /* Value is the value of window property PROP on FRAME.
4637 If FRAME is nil or omitted, use the selected frame.
4639 On X Windows, the following optional arguments are also accepted:
4640 If TYPE is nil or omitted, get the property as a string.
4641 Otherwise TYPE is the name of the atom that denotes the type expected.
4642 If SOURCE is non-nil, get the property on that window instead of from
4643 FRAME. The number 0 denotes the root window.
4644 If DELETE-P is non-nil, delete the property after retrieving it.
4645 If VECTOR-RET-P is non-nil, don't return a string but a vector of values.
4647 On MS Windows, this function accepts but ignores those optional arguments.
4649 Value is nil if FRAME hasn't a property with name PROP or if PROP has
4650 no value of TYPE (always string in the MS Windows case). */)
4651 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
,
4652 Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
4654 struct frame
*f
= decode_window_system_frame (frame
);
4656 Lisp_Object prop_value
= Qnil
;
4657 Atom target_type
= XA_STRING
;
4658 Window target_window
= FRAME_X_WINDOW (f
);
4659 struct gcpro gcpro1
;
4662 GCPRO1 (prop_value
);
4663 CHECK_STRING (prop
);
4665 if (! NILP (source
))
4667 CONS_TO_INTEGER (source
, Window
, target_window
);
4668 if (! target_window
)
4669 target_window
= FRAME_DISPLAY_INFO (f
)->root_window
;
4675 if (strcmp ("AnyPropertyType", SSDATA (type
)) == 0)
4676 target_type
= AnyPropertyType
;
4678 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
4681 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4682 prop_value
= x_window_property_intern (f
,
4689 if (NILP (prop_value
)
4692 && target_window
!= FRAME_OUTER_WINDOW (f
))
4694 prop_value
= x_window_property_intern (f
,
4695 FRAME_OUTER_WINDOW (f
),
4711 /***********************************************************************
4713 ***********************************************************************/
4715 /* Timer function of hourglass_atimer. TIMER is equal to
4718 Display an hourglass pointer on all frames by mapping the frames'
4719 hourglass_window. Set the hourglass_p flag in the frames'
4720 output_data.x structure to indicate that an hourglass cursor is
4721 shown on the frames. */
4724 show_hourglass (struct atimer
*timer
)
4726 /* The timer implementation will cancel this timer automatically
4727 after this function has run. Set hourglass_atimer to null
4728 so that we know the timer doesn't have to be canceled. */
4729 hourglass_atimer
= NULL
;
4731 if (!hourglass_shown_p
)
4733 Lisp_Object rest
, frame
;
4737 FOR_EACH_FRAME (rest
, frame
)
4739 struct frame
*f
= XFRAME (frame
);
4741 if (FRAME_LIVE_P (f
) && FRAME_X_P (f
) && FRAME_X_DISPLAY (f
))
4743 Display
*dpy
= FRAME_X_DISPLAY (f
);
4745 #ifdef USE_X_TOOLKIT
4746 if (f
->output_data
.x
->widget
)
4748 if (FRAME_OUTER_WINDOW (f
))
4751 f
->output_data
.x
->hourglass_p
= 1;
4753 if (!f
->output_data
.x
->hourglass_window
)
4755 unsigned long mask
= CWCursor
;
4756 XSetWindowAttributes attrs
;
4758 Window parent
= FRAME_X_WINDOW (f
);
4760 Window parent
= FRAME_OUTER_WINDOW (f
);
4762 attrs
.cursor
= f
->output_data
.x
->hourglass_cursor
;
4764 f
->output_data
.x
->hourglass_window
4765 = XCreateWindow (dpy
, parent
,
4766 0, 0, 32000, 32000, 0, 0,
4772 XMapRaised (dpy
, f
->output_data
.x
->hourglass_window
);
4778 hourglass_shown_p
= 1;
4784 /* Hide the hourglass pointer on all frames, if it is currently
4788 hide_hourglass (void)
4790 if (hourglass_shown_p
)
4792 Lisp_Object rest
, frame
;
4795 FOR_EACH_FRAME (rest
, frame
)
4797 struct frame
*f
= XFRAME (frame
);
4800 /* Watch out for newly created frames. */
4801 && f
->output_data
.x
->hourglass_window
)
4803 XUnmapWindow (FRAME_X_DISPLAY (f
),
4804 f
->output_data
.x
->hourglass_window
);
4805 /* Sync here because XTread_socket looks at the
4806 hourglass_p flag that is reset to zero below. */
4807 XSync (FRAME_X_DISPLAY (f
), False
);
4808 f
->output_data
.x
->hourglass_p
= 0;
4812 hourglass_shown_p
= 0;
4819 /***********************************************************************
4821 ***********************************************************************/
4823 static Lisp_Object
x_create_tip_frame (struct x_display_info
*,
4824 Lisp_Object
, Lisp_Object
);
4825 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
4826 Lisp_Object
, int, int, int *, int *);
4828 /* The frame of a currently visible tooltip. */
4830 Lisp_Object tip_frame
;
4832 /* If non-nil, a timer started that hides the last tooltip when it
4835 static Lisp_Object tip_timer
;
4838 /* If non-nil, a vector of 3 elements containing the last args
4839 with which x-show-tip was called. See there. */
4841 static Lisp_Object last_show_tip_args
;
4845 unwind_create_tip_frame (Lisp_Object frame
)
4847 Lisp_Object deleted
;
4849 deleted
= unwind_create_frame (frame
);
4850 if (EQ (deleted
, Qt
))
4858 /* Create a frame for a tooltip on the display described by DPYINFO.
4859 PARMS is a list of frame parameters. TEXT is the string to
4860 display in the tip frame. Value is the frame.
4862 Note that functions called here, esp. x_default_parameter can
4863 signal errors, for instance when a specified color name is
4864 undefined. We have to make sure that we're in a consistent state
4865 when this happens. */
4868 x_create_tip_frame (struct x_display_info
*dpyinfo
,
4876 ptrdiff_t count
= SPECPDL_INDEX ();
4877 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4878 int face_change_count_before
= face_change_count
;
4880 struct buffer
*old_buffer
;
4882 if (!dpyinfo
->terminal
->name
)
4883 error ("Terminal is not live, can't create new frames on it");
4885 parms
= Fcopy_alist (parms
);
4887 /* Get the name of the frame to use for resource lookup. */
4888 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
4890 && !EQ (name
, Qunbound
)
4892 error ("Invalid frame name--not a string or nil");
4895 GCPRO3 (parms
, name
, frame
);
4897 XSETFRAME (frame
, f
);
4899 buffer
= Fget_buffer_create (build_string (" *tip*"));
4900 /* Use set_window_buffer instead of Fset_window_buffer (see
4901 discussion of bug#11984, bug#12025, bug#12026). */
4902 set_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, 0, 0);
4903 old_buffer
= current_buffer
;
4904 set_buffer_internal_1 (XBUFFER (buffer
));
4905 bset_truncate_lines (current_buffer
, Qnil
);
4906 specbind (Qinhibit_read_only
, Qt
);
4907 specbind (Qinhibit_modification_hooks
, Qt
);
4910 set_buffer_internal_1 (old_buffer
);
4912 record_unwind_protect (unwind_create_tip_frame
, frame
);
4914 f
->terminal
= dpyinfo
->terminal
;
4916 /* By setting the output method, we're essentially saying that
4917 the frame is live, as per FRAME_LIVE_P. If we get a signal
4918 from this point on, x_destroy_window might screw up reference
4920 f
->output_method
= output_x_window
;
4921 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
4922 f
->output_data
.x
->icon_bitmap
= -1;
4923 FRAME_FONTSET (f
) = -1;
4924 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
4925 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
4926 #ifdef USE_TOOLKIT_SCROLL_BARS
4927 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
4928 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
4929 #endif /* USE_TOOLKIT_SCROLL_BARS */
4930 f
->output_data
.x
->white_relief
.pixel
= -1;
4931 f
->output_data
.x
->black_relief
.pixel
= -1;
4933 fset_icon_name (f
, Qnil
);
4934 FRAME_DISPLAY_INFO (f
) = dpyinfo
;
4935 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
4936 f
->output_data
.x
->explicit_parent
= 0;
4938 /* These colors will be set anyway later, but it's important
4939 to get the color reference counts right, so initialize them! */
4942 struct gcpro gcpro1
;
4944 /* Function x_decode_color can signal an error. Make
4945 sure to initialize color slots so that we won't try
4946 to free colors we haven't allocated. */
4947 FRAME_FOREGROUND_PIXEL (f
) = -1;
4948 FRAME_BACKGROUND_PIXEL (f
) = -1;
4949 f
->output_data
.x
->cursor_pixel
= -1;
4950 f
->output_data
.x
->cursor_foreground_pixel
= -1;
4951 f
->output_data
.x
->border_pixel
= -1;
4952 f
->output_data
.x
->mouse_pixel
= -1;
4954 black
= build_string ("black");
4956 FRAME_FOREGROUND_PIXEL (f
)
4957 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4958 FRAME_BACKGROUND_PIXEL (f
)
4959 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4960 f
->output_data
.x
->cursor_pixel
4961 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4962 f
->output_data
.x
->cursor_foreground_pixel
4963 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4964 f
->output_data
.x
->border_pixel
4965 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4966 f
->output_data
.x
->mouse_pixel
4967 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
4971 /* Set the name; the functions to which we pass f expect the name to
4973 if (EQ (name
, Qunbound
) || NILP (name
))
4975 fset_name (f
, build_string (dpyinfo
->x_id_name
));
4976 f
->explicit_name
= 0;
4980 fset_name (f
, name
);
4981 f
->explicit_name
= 1;
4982 /* use the frame's title when getting resources for this frame. */
4983 specbind (Qx_resource_name
, name
);
4986 register_font_driver (&xfont_driver
, f
);
4987 #ifdef HAVE_FREETYPE
4989 register_font_driver (&xftfont_driver
, f
);
4990 #else /* not HAVE_XFT */
4991 register_font_driver (&ftxfont_driver
, f
);
4992 #endif /* not HAVE_XFT */
4993 #endif /* HAVE_FREETYPE */
4995 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
4996 "fontBackend", "FontBackend", RES_TYPE_STRING
);
4998 /* Extract the window parameters from the supplied values that are
4999 needed to determine window geometry. */
5000 x_default_font_parameter (f
, parms
);
5002 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
5003 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5005 /* This defaults to 2 in order to match xterm. We recognize either
5006 internalBorderWidth or internalBorder (which is what xterm calls
5008 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5012 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5013 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5014 if (! EQ (value
, Qunbound
))
5015 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5019 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5020 "internalBorderWidth", "internalBorderWidth",
5022 x_default_parameter (f
, parms
, Qright_divider_width
, make_number (0),
5023 NULL
, NULL
, RES_TYPE_NUMBER
);
5024 x_default_parameter (f
, parms
, Qbottom_divider_width
, make_number (0),
5025 NULL
, NULL
, RES_TYPE_NUMBER
);
5027 /* Also do the stuff which must be set before the window exists. */
5028 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5029 "foreground", "Foreground", RES_TYPE_STRING
);
5030 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5031 "background", "Background", RES_TYPE_STRING
);
5032 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5033 "pointerColor", "Foreground", RES_TYPE_STRING
);
5034 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5035 "cursorColor", "Foreground", RES_TYPE_STRING
);
5036 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5037 "borderColor", "BorderColor", RES_TYPE_STRING
);
5040 image_cache_refcount
=
5041 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
5042 dpyinfo_refcount
= dpyinfo
->reference_count
;
5043 #endif /* GLYPH_DEBUG */
5045 /* Init faces before x_default_parameter is called for scroll-bar
5046 parameters because that function calls x_set_scroll_bar_width,
5047 which calls change_frame_size, which calls Fset_window_buffer,
5048 which runs hooks, which call Fvertical_motion. At the end, we
5049 end up in init_iterator with a null face cache, which should not
5051 init_frame_faces (f
);
5053 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5055 x_figure_window_size (f
, parms
, 0);
5058 XSetWindowAttributes attrs
;
5060 Atom type
= FRAME_DISPLAY_INFO (f
)->Xatom_net_window_type_tooltip
;
5063 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
;
5064 if (DoesSaveUnders (dpyinfo
->screen
))
5065 mask
|= CWSaveUnder
;
5067 /* Window managers look at the override-redirect flag to determine
5068 whether or net to give windows a decoration (Xlib spec, chapter
5070 attrs
.override_redirect
= True
;
5071 attrs
.save_under
= True
;
5072 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
5073 /* Arrange for getting MapNotify and UnmapNotify events. */
5074 attrs
.event_mask
= StructureNotifyMask
;
5076 = FRAME_X_WINDOW (f
)
5077 = XCreateWindow (FRAME_X_DISPLAY (f
),
5078 FRAME_DISPLAY_INFO (f
)->root_window
,
5079 /* x, y, width, height */
5083 CopyFromParent
, InputOutput
, CopyFromParent
,
5085 XChangeProperty (FRAME_X_DISPLAY (f
), tip_window
,
5086 FRAME_DISPLAY_INFO (f
)->Xatom_net_window_type
,
5087 XA_ATOM
, 32, PropModeReplace
,
5088 (unsigned char *)&type
, 1);
5094 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5095 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5096 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5097 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5098 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5099 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5101 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
5102 Change will not be effected unless different from the current
5104 width
= FRAME_COLS (f
);
5105 height
= FRAME_LINES (f
);
5106 SET_FRAME_COLS (f
, 0);
5107 FRAME_LINES (f
) = 0;
5108 change_frame_size (f
, width
, height
, 1, 0, 0, 0);
5110 /* Add `tooltip' frame parameter's default value. */
5111 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5112 Fmodify_frame_parameters (frame
, list1 (Fcons (Qtooltip
, Qt
)));
5114 /* FIXME - can this be done in a similar way to normal frames?
5115 http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00641.html */
5117 /* Set the `display-type' frame parameter before setting up faces. */
5119 Lisp_Object disptype
;
5121 if (FRAME_DISPLAY_INFO (f
)->n_planes
== 1)
5122 disptype
= intern ("mono");
5123 else if (FRAME_DISPLAY_INFO (f
)->visual
->class == GrayScale
5124 || FRAME_DISPLAY_INFO (f
)->visual
->class == StaticGray
)
5125 disptype
= intern ("grayscale");
5127 disptype
= intern ("color");
5129 if (NILP (Fframe_parameter (frame
, Qdisplay_type
)))
5130 Fmodify_frame_parameters (frame
, list1 (Fcons (Qdisplay_type
, disptype
)));
5133 /* Set up faces after all frame parameters are known. This call
5134 also merges in face attributes specified for new frames.
5136 Frame parameters may be changed if .Xdefaults contains
5137 specifications for the default font. For example, if there is an
5138 `Emacs.default.attributeBackground: pink', the `background-color'
5139 attribute of the frame get's set, which let's the internal border
5140 of the tooltip frame appear in pink. Prevent this. */
5142 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5144 /* Set tip_frame here, so that */
5146 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5148 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5149 Fmodify_frame_parameters (frame
, list1 (Fcons (Qbackground_color
, bg
)));
5156 /* Now that the frame will be official, it counts as a reference to
5157 its display and terminal. */
5158 FRAME_DISPLAY_INFO (f
)->reference_count
++;
5159 f
->terminal
->reference_count
++;
5161 /* It is now ok to make the frame official even if we get an error
5162 below. And the frame needs to be on Vframe_list or making it
5163 visible won't work. */
5164 Vframe_list
= Fcons (frame
, Vframe_list
);
5167 /* Setting attributes of faces of the tooltip frame from resources
5168 and similar will increment face_change_count, which leads to the
5169 clearing of all current matrices. Since this isn't necessary
5170 here, avoid it by resetting face_change_count to the value it
5171 had before we created the tip frame. */
5172 face_change_count
= face_change_count_before
;
5174 /* Discard the unwind_protect. */
5175 return unbind_to (count
, frame
);
5179 /* Compute where to display tip frame F. PARMS is the list of frame
5180 parameters for F. DX and DY are specified offsets from the current
5181 location of the mouse. WIDTH and HEIGHT are the width and height
5182 of the tooltip. Return coordinates relative to the root window of
5183 the display in *ROOT_X, and *ROOT_Y. */
5186 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
)
5188 Lisp_Object left
, top
;
5193 /* User-specified position? */
5194 left
= Fcdr (Fassq (Qleft
, parms
));
5195 top
= Fcdr (Fassq (Qtop
, parms
));
5197 /* Move the tooltip window where the mouse pointer is. Resize and
5199 if (!INTEGERP (left
) || !INTEGERP (top
))
5202 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_DISPLAY_INFO (f
)->root_window
,
5203 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
5208 *root_y
= XINT (top
);
5209 else if (*root_y
+ XINT (dy
) <= 0)
5210 *root_y
= 0; /* Can happen for negative dy */
5211 else if (*root_y
+ XINT (dy
) + height
5212 <= x_display_pixel_height (FRAME_DISPLAY_INFO (f
)))
5213 /* It fits below the pointer */
5214 *root_y
+= XINT (dy
);
5215 else if (height
+ XINT (dy
) <= *root_y
)
5216 /* It fits above the pointer. */
5217 *root_y
-= height
+ XINT (dy
);
5219 /* Put it on the top. */
5222 if (INTEGERP (left
))
5223 *root_x
= XINT (left
);
5224 else if (*root_x
+ XINT (dx
) <= 0)
5225 *root_x
= 0; /* Can happen for negative dx */
5226 else if (*root_x
+ XINT (dx
) + width
5227 <= x_display_pixel_width (FRAME_DISPLAY_INFO (f
)))
5228 /* It fits to the right of the pointer. */
5229 *root_x
+= XINT (dx
);
5230 else if (width
+ XINT (dx
) <= *root_x
)
5231 /* It fits to the left of the pointer. */
5232 *root_x
-= width
+ XINT (dx
);
5234 /* Put it left-justified on the screen--it ought to fit that way. */
5239 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5240 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
5241 A tooltip window is a small X window displaying a string.
5243 This is an internal function; Lisp code should call `tooltip-show'.
5245 FRAME nil or omitted means use the selected frame.
5247 PARMS is an optional list of frame parameters which can be used to
5248 change the tooltip's appearance.
5250 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5251 means use the default timeout of 5 seconds.
5253 If the list of frame parameters PARMS contains a `left' parameters,
5254 the tooltip is displayed at that x-position. Otherwise it is
5255 displayed at the mouse position, with offset DX added (default is 5 if
5256 DX isn't specified). Likewise for the y-position; if a `top' frame
5257 parameter is specified, it determines the y-position of the tooltip
5258 window, otherwise it is displayed at the mouse position, with offset
5259 DY added (default is -10).
5261 A tooltip's maximum size is specified by `x-max-tooltip-size'.
5262 Text larger than the specified size is clipped. */)
5263 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
5268 struct buffer
*old_buffer
;
5269 struct text_pos pos
;
5270 int i
, width
, height
, seen_reversed_p
;
5271 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5272 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5273 ptrdiff_t count
= SPECPDL_INDEX ();
5275 specbind (Qinhibit_redisplay
, Qt
);
5277 GCPRO4 (string
, parms
, frame
, timeout
);
5279 CHECK_STRING (string
);
5280 if (SCHARS (string
) == 0)
5281 string
= make_unibyte_string (" ", 1);
5283 f
= decode_window_system_frame (frame
);
5285 timeout
= make_number (5);
5287 CHECK_NATNUM (timeout
);
5290 dx
= make_number (5);
5295 dy
= make_number (-10);
5300 if (x_gtk_use_system_tooltips
)
5304 /* Hide a previous tip, if any. */
5308 ok
= xg_prepare_tooltip (f
, string
, &width
, &height
);
5311 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5312 xg_show_tooltip (f
, root_x
, root_y
);
5313 /* This is used in Fx_hide_tip. */
5314 XSETFRAME (tip_frame
, f
);
5317 if (ok
) goto start_timer
;
5319 #endif /* USE_GTK */
5321 if (NILP (last_show_tip_args
))
5322 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5324 if (!NILP (tip_frame
))
5326 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5327 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5328 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5330 if (EQ (frame
, last_frame
)
5331 && !NILP (Fequal (last_string
, string
))
5332 && !NILP (Fequal (last_parms
, parms
)))
5334 struct frame
*tip_f
= XFRAME (tip_frame
);
5336 /* Only DX and DY have changed. */
5337 if (!NILP (tip_timer
))
5339 Lisp_Object timer
= tip_timer
;
5341 call1 (Qcancel_timer
, timer
);
5345 compute_tip_xy (tip_f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (tip_f
),
5346 FRAME_PIXEL_HEIGHT (tip_f
), &root_x
, &root_y
);
5347 XMoveWindow (FRAME_X_DISPLAY (tip_f
), FRAME_X_WINDOW (tip_f
),
5354 /* Hide a previous tip, if any. */
5357 ASET (last_show_tip_args
, 0, string
);
5358 ASET (last_show_tip_args
, 1, frame
);
5359 ASET (last_show_tip_args
, 2, parms
);
5361 /* Add default values to frame parameters. */
5362 if (NILP (Fassq (Qname
, parms
)))
5363 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5364 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5365 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5366 if (NILP (Fassq (Qborder_width
, parms
)))
5367 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5368 if (NILP (Fassq (Qbottom_divider_width
, parms
)))
5369 parms
= Fcons (Fcons (Qbottom_divider_width
, make_number (0)), parms
);
5370 if (NILP (Fassq (Qright_divider_width
, parms
)))
5371 parms
= Fcons (Fcons (Qright_divider_width
, make_number (0)), parms
);
5372 if (NILP (Fassq (Qborder_color
, parms
)))
5373 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5374 if (NILP (Fassq (Qbackground_color
, parms
)))
5375 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5378 /* Create a frame for the tooltip, and record it in the global
5379 variable tip_frame. */
5380 frame
= x_create_tip_frame (FRAME_DISPLAY_INFO (f
), parms
, string
);
5383 /* Set up the frame's root window. */
5384 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5390 if (CONSP (Vx_max_tooltip_size
)
5391 && RANGED_INTEGERP (1, XCAR (Vx_max_tooltip_size
), INT_MAX
)
5392 && RANGED_INTEGERP (1, XCDR (Vx_max_tooltip_size
), INT_MAX
))
5394 w
->total_cols
= XFASTINT (XCAR (Vx_max_tooltip_size
));
5395 w
->total_lines
= XFASTINT (XCDR (Vx_max_tooltip_size
));
5400 w
->total_lines
= 40;
5403 w
->pixel_width
= w
->total_cols
* FRAME_COLUMN_WIDTH (f
);
5404 w
->pixel_height
= w
->total_lines
* FRAME_LINE_HEIGHT (f
);
5406 FRAME_TOTAL_COLS (f
) = w
->total_cols
;
5407 adjust_frame_glyphs (f
);
5408 w
->pseudo_window_p
= 1;
5410 /* Display the tooltip text in a temporary buffer. */
5411 old_buffer
= current_buffer
;
5412 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->contents
));
5413 bset_truncate_lines (current_buffer
, Qnil
);
5414 clear_glyph_matrix (w
->desired_matrix
);
5415 clear_glyph_matrix (w
->current_matrix
);
5416 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5417 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5419 /* Compute width and height of the tooltip. */
5420 width
= height
= seen_reversed_p
= 0;
5421 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5423 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5427 /* Stop at the first empty row at the end. */
5428 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5431 /* Let the row go over the full width of the frame. */
5432 row
->full_width_p
= 1;
5434 row_width
= row
->pixel_width
;
5435 if (row
->used
[TEXT_AREA
])
5437 /* There's a glyph at the end of rows that is used to place
5438 the cursor there. Don't include the width of this glyph. */
5439 if (!row
->reversed_p
)
5441 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5442 if (INTEGERP (last
->object
))
5443 row_width
-= last
->pixel_width
;
5447 /* There could be a stretch glyph at the beginning of R2L
5448 rows that is produced by extend_face_to_end_of_line.
5449 Don't count that glyph. */
5450 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
5452 if (g
->type
== STRETCH_GLYPH
&& INTEGERP (g
->object
))
5454 row_width
-= g
->pixel_width
;
5455 seen_reversed_p
= 1;
5460 height
+= row
->height
;
5461 width
= max (width
, row_width
);
5464 /* If we've seen partial-length R2L rows, we need to re-adjust the
5465 tool-tip frame width and redisplay it again, to avoid over-wide
5466 tips due to the stretch glyph that extends R2L lines to full
5467 width of the frame. */
5468 if (seen_reversed_p
)
5470 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns,
5472 w
->pixel_width
= width
;
5473 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
5474 w
->total_cols
= width
;
5475 FRAME_TOTAL_COLS (f
) = width
;
5476 SET_FRAME_WIDTH (f
, width
);
5477 adjust_frame_glyphs (f
);
5478 clear_glyph_matrix (w
->desired_matrix
);
5479 clear_glyph_matrix (w
->current_matrix
);
5480 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
5482 /* Recompute width and height of the tooltip. */
5483 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5485 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5489 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5491 row
->full_width_p
= 1;
5492 row_width
= row
->pixel_width
;
5493 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
5495 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5496 if (INTEGERP (last
->object
))
5497 row_width
-= last
->pixel_width
;
5500 height
+= row
->height
;
5501 width
= max (width
, row_width
);
5505 /* Add the frame's internal border to the width and height the X
5506 window should have. */
5507 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5508 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5510 /* Move the tooltip window where the mouse pointer is. Resize and
5512 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5515 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5516 root_x
, root_y
, width
, height
);
5517 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5520 /* Draw into the window. */
5521 w
->must_be_updated_p
= 1;
5522 update_single_window (w
, 1);
5524 /* Restore original current buffer. */
5525 set_buffer_internal_1 (old_buffer
);
5526 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5529 /* Let the tip disappear after timeout seconds. */
5530 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5531 intern ("x-hide-tip"));
5534 return unbind_to (count
, Qnil
);
5538 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5539 doc
: /* Hide the current tooltip window, if there is any.
5540 Value is t if tooltip was open, nil otherwise. */)
5544 Lisp_Object deleted
, frame
, timer
;
5545 struct gcpro gcpro1
, gcpro2
;
5547 /* Return quickly if nothing to do. */
5548 if (NILP (tip_timer
) && NILP (tip_frame
))
5553 GCPRO2 (frame
, timer
);
5554 tip_frame
= tip_timer
= deleted
= Qnil
;
5556 count
= SPECPDL_INDEX ();
5557 specbind (Qinhibit_redisplay
, Qt
);
5558 specbind (Qinhibit_quit
, Qt
);
5561 call1 (Qcancel_timer
, timer
);
5565 /* When using system tooltip, tip_frame is the Emacs frame on which
5566 the tip is shown. */
5567 struct frame
*f
= XFRAME (frame
);
5568 if (FRAME_LIVE_P (f
) && xg_hide_tooltip (f
))
5575 delete_frame (frame
, Qnil
);
5579 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5580 redisplay procedure is not called when a tip frame over menu
5581 items is unmapped. Redisplay the menu manually... */
5584 struct frame
*f
= SELECTED_FRAME ();
5585 w
= f
->output_data
.x
->menubar_widget
;
5587 if (!DoesSaveUnders (FRAME_DISPLAY_INFO (f
)->screen
)
5591 xlwmenu_redisplay (w
);
5595 #endif /* USE_LUCID */
5599 return unbind_to (count
, deleted
);
5604 /***********************************************************************
5605 File selection dialog
5606 ***********************************************************************/
5608 DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog
,
5609 Sx_uses_old_gtk_dialog
,
5611 doc
: /* Return t if the old Gtk+ file selection dialog is used. */)
5617 && window_system_available (SELECTED_FRAME ())
5618 && xg_uses_old_file_dialog ())
5626 /* Callback for "OK" and "Cancel" on file selection dialog. */
5629 file_dialog_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5631 int *result
= client_data
;
5632 XmAnyCallbackStruct
*cb
= call_data
;
5633 *result
= cb
->reason
;
5637 /* Callback for unmapping a file selection dialog. This is used to
5638 capture the case where a dialog is closed via a window manager's
5639 closer button, for example. Using a XmNdestroyCallback didn't work
5643 file_dialog_unmap_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5645 int *result
= client_data
;
5646 *result
= XmCR_CANCEL
;
5650 clean_up_file_dialog (void *arg
)
5652 Widget dialog
= arg
;
5656 XtUnmanageChild (dialog
);
5657 XtDestroyWidget (dialog
);
5658 x_menu_set_in_use (0);
5663 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5664 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5665 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5666 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5667 or directory must exist.
5669 This function is only defined on NS, MS Windows, and X Windows with the
5670 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5671 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5672 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
,
5673 Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5676 struct frame
*f
= SELECTED_FRAME ();
5677 Lisp_Object file
= Qnil
;
5678 Lisp_Object decoded_file
;
5679 Widget dialog
, text
, help
;
5682 XmString dir_xmstring
, pattern_xmstring
;
5683 ptrdiff_t count
= SPECPDL_INDEX ();
5684 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5686 check_window_system (f
);
5688 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5690 if (popup_activated ())
5691 error ("Trying to use a menu from within a menu-entry");
5693 CHECK_STRING (prompt
);
5696 /* Prevent redisplay. */
5697 specbind (Qinhibit_redisplay
, Qt
);
5701 /* Create the dialog with PROMPT as title, using DIR as initial
5702 directory and using "*" as pattern. */
5703 dir
= Fexpand_file_name (dir
, Qnil
);
5704 dir_xmstring
= XmStringCreateLocalized (SSDATA (dir
));
5705 pattern_xmstring
= XmStringCreateLocalized ("*");
5707 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
5708 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
5709 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
5710 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
5711 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
5712 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
5714 XmStringFree (dir_xmstring
);
5715 XmStringFree (pattern_xmstring
);
5717 /* Add callbacks for OK and Cancel. */
5718 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
5719 (XtPointer
) &result
);
5720 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
5721 (XtPointer
) &result
);
5722 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
5723 (XtPointer
) &result
);
5725 /* Remove the help button since we can't display help. */
5726 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
5727 XtUnmanageChild (help
);
5729 /* Mark OK button as default. */
5730 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
5731 XmNshowAsDefault
, True
, NULL
);
5733 /* If MUSTMATCH is non-nil, disable the file entry field of the
5734 dialog, so that the user must select a file from the files list
5735 box. We can't remove it because we wouldn't have a way to get at
5736 the result file name, then. */
5737 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5738 if (!NILP (mustmatch
))
5741 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
5742 XtSetSensitive (text
, False
);
5743 XtSetSensitive (label
, False
);
5746 /* Manage the dialog, so that list boxes get filled. */
5747 XtManageChild (dialog
);
5749 if (STRINGP (default_filename
))
5751 XmString default_xmstring
;
5752 Widget wtext
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5753 Widget list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
5755 XmTextPosition last_pos
= XmTextFieldGetLastPosition (wtext
);
5756 XmTextFieldReplace (wtext
, 0, last_pos
,
5757 (SSDATA (Ffile_name_nondirectory (default_filename
))));
5759 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5760 must include the path for this to work. */
5762 default_xmstring
= XmStringCreateLocalized (SSDATA (default_filename
));
5764 if (XmListItemExists (list
, default_xmstring
))
5766 int item_pos
= XmListItemPos (list
, default_xmstring
);
5767 /* Select the item and scroll it into view. */
5768 XmListSelectPos (list
, item_pos
, True
);
5769 XmListSetPos (list
, item_pos
);
5772 XmStringFree (default_xmstring
);
5775 record_unwind_protect_ptr (clean_up_file_dialog
, dialog
);
5777 /* Process events until the user presses Cancel or OK. */
5778 x_menu_set_in_use (1);
5783 x_menu_wait_for_event (0);
5784 XtAppNextEvent (Xt_app_con
, &event
);
5785 if (event
.type
== KeyPress
5786 && FRAME_X_DISPLAY (f
) == event
.xkey
.display
)
5788 KeySym keysym
= XLookupKeysym (&event
.xkey
, 0);
5790 /* Pop down on C-g. */
5791 if (keysym
== XK_g
&& (event
.xkey
.state
& ControlMask
) != 0)
5792 XtUnmanageChild (dialog
);
5795 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
));
5798 /* Get the result. */
5799 if (result
== XmCR_OK
)
5801 XmString text_string
;
5804 XtVaGetValues (dialog
, XmNtextString
, &text_string
, NULL
);
5805 XmStringGetLtoR (text_string
, XmFONTLIST_DEFAULT_TAG
, &data
);
5806 XmStringFree (text_string
);
5807 file
= build_string (data
);
5816 /* Make "Cancel" equivalent to C-g. */
5818 Fsignal (Qquit
, Qnil
);
5820 decoded_file
= DECODE_FILE (file
);
5822 return unbind_to (count
, decoded_file
);
5825 #endif /* USE_MOTIF */
5830 clean_up_dialog (void)
5832 x_menu_set_in_use (0);
5835 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5836 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5837 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5838 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5839 or directory must exist.
5841 This function is only defined on NS, MS Windows, and X Windows with the
5842 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5843 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5844 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5846 struct frame
*f
= SELECTED_FRAME ();
5848 Lisp_Object file
= Qnil
;
5849 Lisp_Object decoded_file
;
5850 ptrdiff_t count
= SPECPDL_INDEX ();
5851 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5854 check_window_system (f
);
5856 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5858 if (popup_activated ())
5859 error ("Trying to use a menu from within a menu-entry");
5861 CHECK_STRING (prompt
);
5864 /* Prevent redisplay. */
5865 specbind (Qinhibit_redisplay
, Qt
);
5866 record_unwind_protect_void (clean_up_dialog
);
5870 if (STRINGP (default_filename
))
5871 cdef_file
= SSDATA (default_filename
);
5873 cdef_file
= SSDATA (dir
);
5875 fn
= xg_get_file_name (f
, SSDATA (prompt
), cdef_file
,
5877 ! NILP (only_dir_p
));
5881 file
= build_string (fn
);
5888 /* Make "Cancel" equivalent to C-g. */
5890 Fsignal (Qquit
, Qnil
);
5892 decoded_file
= DECODE_FILE (file
);
5894 return unbind_to (count
, decoded_file
);
5898 #ifdef HAVE_FREETYPE
5900 DEFUN ("x-select-font", Fx_select_font
, Sx_select_font
, 0, 2, 0,
5901 doc
: /* Read a font using a GTK dialog.
5902 Return either a font spec (for GTK versions >= 3.2) or a string
5903 containing a GTK-style font name.
5905 FRAME is the frame on which to pop up the font chooser. If omitted or
5906 nil, it defaults to the selected frame. */)
5907 (Lisp_Object frame
, Lisp_Object ignored
)
5909 struct frame
*f
= decode_window_system_frame (frame
);
5911 Lisp_Object font_param
;
5912 char *default_name
= NULL
;
5913 struct gcpro gcpro1
, gcpro2
;
5914 ptrdiff_t count
= SPECPDL_INDEX ();
5916 if (popup_activated ())
5917 error ("Trying to use a menu from within a menu-entry");
5919 /* Prevent redisplay. */
5920 specbind (Qinhibit_redisplay
, Qt
);
5921 record_unwind_protect_void (clean_up_dialog
);
5925 GCPRO2 (font_param
, font
);
5927 XSETFONT (font
, FRAME_FONT (f
));
5928 font_param
= Ffont_get (font
, intern (":name"));
5929 if (STRINGP (font_param
))
5930 default_name
= xstrdup (SSDATA (font_param
));
5933 font_param
= Fframe_parameter (frame
, Qfont_param
);
5934 if (STRINGP (font_param
))
5935 default_name
= xstrdup (SSDATA (font_param
));
5938 font
= xg_get_font (f
, default_name
);
5939 xfree (default_name
);
5944 Fsignal (Qquit
, Qnil
);
5946 return unbind_to (count
, font
);
5948 #endif /* HAVE_FREETYPE */
5950 #endif /* USE_GTK */
5953 /***********************************************************************
5955 ***********************************************************************/
5958 #include <X11/XKBlib.h>
5959 #include <X11/keysym.h>
5962 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
5963 Sx_backspace_delete_keys_p
, 0, 1, 0,
5964 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
5965 FRAME nil means use the selected frame.
5966 Value is t if we know that both keys are present, and are mapped to the
5967 usual X keysyms. Value is `lambda' if we cannot determine if both keys are
5968 present and mapped to the usual X keysyms. */)
5975 struct frame
*f
= decode_window_system_frame (frame
);
5976 Display
*dpy
= FRAME_X_DISPLAY (f
);
5977 Lisp_Object have_keys
;
5978 int major
, minor
, op
, event
, error_code
;
5982 /* Check library version in case we're dynamically linked. */
5983 major
= XkbMajorVersion
;
5984 minor
= XkbMinorVersion
;
5985 if (!XkbLibraryVersion (&major
, &minor
))
5991 /* Check that the server supports XKB. */
5992 major
= XkbMajorVersion
;
5993 minor
= XkbMinorVersion
;
5994 if (!XkbQueryExtension (dpy
, &op
, &event
, &error_code
, &major
, &minor
))
6000 /* In this code we check that the keyboard has physical keys with names
6001 that start with BKSP (Backspace) and DELE (Delete), and that they
6002 generate keysym XK_BackSpace and XK_Delete respectively.
6003 This function is used to test if normal-erase-is-backspace should be
6005 An alternative approach would be to just check if XK_BackSpace and
6006 XK_Delete are mapped to any key. But if any of those are mapped to
6007 some non-intuitive key combination (Meta-Shift-Ctrl-whatever) and the
6008 user doesn't know about it, it is better to return false here.
6009 It is more obvious to the user what to do if she/he has two keys
6010 clearly marked with names/symbols and one key does something not
6011 expected (i.e. she/he then tries the other).
6012 The cases where Backspace/Delete is mapped to some other key combination
6013 are rare, and in those cases, normal-erase-is-backspace can be turned on
6017 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
6020 int delete_keycode
= 0, backspace_keycode
= 0, i
;
6022 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
6024 for (i
= kb
->min_key_code
;
6025 (i
< kb
->max_key_code
6026 && (delete_keycode
== 0 || backspace_keycode
== 0));
6029 /* The XKB symbolic key names can be seen most easily in
6030 the PS file generated by `xkbprint -label name
6032 if (memcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
6034 else if (memcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
6035 backspace_keycode
= i
;
6038 XkbFreeNames (kb
, 0, True
);
6041 XkbFreeClientMap (kb
, 0, True
);
6044 && backspace_keycode
6045 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
6046 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
6056 /***********************************************************************
6058 ***********************************************************************/
6060 /* Keep this list in the same order as frame_parms in frame.c.
6061 Use 0 for unsupported frame parameters. */
6063 frame_parm_handler x_frame_parm_handlers
[] =
6067 x_set_background_color
,
6073 x_set_foreground_color
,
6076 x_set_internal_border_width
,
6077 x_set_right_divider_width
,
6078 x_set_bottom_divider_width
,
6079 x_set_menu_bar_lines
,
6081 x_explicitly_set_name
,
6082 x_set_scroll_bar_width
,
6085 x_set_vertical_scroll_bars
,
6087 x_set_tool_bar_lines
,
6088 x_set_scroll_bar_foreground
,
6089 x_set_scroll_bar_background
,
6099 x_set_tool_bar_position
,
6105 /* The section below is built by the lisp expression at the top of the file,
6106 just above where these variables are declared. */
6107 /*&&& init symbols here &&&*/
6108 DEFSYM (Qsuppress_icon
, "suppress-icon");
6109 DEFSYM (Qundefined_color
, "undefined-color");
6110 DEFSYM (Qcompound_text
, "compound-text");
6111 DEFSYM (Qcancel_timer
, "cancel-timer");
6112 DEFSYM (Qfont_param
, "font-parameter");
6113 /* This is the end of symbol initialization. */
6115 Fput (Qundefined_color
, Qerror_conditions
,
6116 listn (CONSTYPE_PURE
, 2, Qundefined_color
, Qerror
));
6117 Fput (Qundefined_color
, Qerror_message
,
6118 build_pure_c_string ("Undefined color"));
6120 DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape
,
6121 doc
: /* The shape of the pointer when over text.
6122 Changing the value does not affect existing frames
6123 unless you set the mouse color. */);
6124 Vx_pointer_shape
= Qnil
;
6126 #if 0 /* This doesn't really do anything. */
6127 DEFVAR_LISP ("x-nontext-pointer-shape", Vx_nontext_pointer_shape
,
6128 doc
: /* The shape of the pointer when not over text.
6129 This variable takes effect when you create a new frame
6130 or when you set the mouse color. */);
6132 Vx_nontext_pointer_shape
= Qnil
;
6134 DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape
,
6135 doc
: /* The shape of the pointer when Emacs is busy.
6136 This variable takes effect when you create a new frame
6137 or when you set the mouse color. */);
6138 Vx_hourglass_pointer_shape
= Qnil
;
6140 #if 0 /* This doesn't really do anything. */
6141 DEFVAR_LISP ("x-mode-pointer-shape", Vx_mode_pointer_shape
,
6142 doc
: /* The shape of the pointer when over the mode line.
6143 This variable takes effect when you create a new frame
6144 or when you set the mouse color. */);
6146 Vx_mode_pointer_shape
= Qnil
;
6148 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
6149 Vx_sensitive_text_pointer_shape
,
6150 doc
: /* The shape of the pointer when over mouse-sensitive text.
6151 This variable takes effect when you create a new frame
6152 or when you set the mouse color. */);
6153 Vx_sensitive_text_pointer_shape
= Qnil
;
6155 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
6156 Vx_window_horizontal_drag_shape
,
6157 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
6158 This variable takes effect when you create a new frame
6159 or when you set the mouse color. */);
6160 Vx_window_horizontal_drag_shape
= Qnil
;
6162 DEFVAR_LISP ("x-window-vertical-drag-cursor",
6163 Vx_window_vertical_drag_shape
,
6164 doc
: /* Pointer shape to use for indicating a window can be dragged vertically.
6165 This variable takes effect when you create a new frame
6166 or when you set the mouse color. */);
6167 Vx_window_vertical_drag_shape
= Qnil
;
6169 DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel
,
6170 doc
: /* A string indicating the foreground color of the cursor box. */);
6171 Vx_cursor_fore_pixel
= Qnil
;
6173 DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size
,
6174 doc
: /* Maximum size for tooltips.
6175 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
6176 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
6178 DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager
,
6179 doc
: /* Non-nil if no X window manager is in use.
6180 Emacs doesn't try to figure this out; this is always nil
6181 unless you set it to something else. */);
6182 /* We don't have any way to find this out, so set it to nil
6183 and maybe the user would like to set it to t. */
6184 Vx_no_window_manager
= Qnil
;
6186 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
6187 Vx_pixel_size_width_font_regexp
,
6188 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
6190 Since Emacs gets width of a font matching with this regexp from
6191 PIXEL_SIZE field of the name, font finding mechanism gets faster for
6192 such a font. This is especially effective for such large fonts as
6193 Chinese, Japanese, and Korean. */);
6194 Vx_pixel_size_width_font_regexp
= Qnil
;
6196 /* This is not ifdef:ed, so other builds than GTK can customize it. */
6197 DEFVAR_BOOL ("x-gtk-use-old-file-dialog", x_gtk_use_old_file_dialog
,
6198 doc
: /* Non-nil means prompt with the old GTK file selection dialog.
6199 If nil or if the file selection dialog is not available, the new GTK file
6200 chooser is used instead. To turn off all file dialogs set the
6201 variable `use-file-dialog'. */);
6202 x_gtk_use_old_file_dialog
= 0;
6204 DEFVAR_BOOL ("x-gtk-show-hidden-files", x_gtk_show_hidden_files
,
6205 doc
: /* If non-nil, the GTK file chooser will by default show hidden files.
6206 Note that this is just the default, there is a toggle button on the file
6207 chooser to show or not show hidden files on a case by case basis. */);
6208 x_gtk_show_hidden_files
= 0;
6210 DEFVAR_BOOL ("x-gtk-file-dialog-help-text", x_gtk_file_dialog_help_text
,
6211 doc
: /* If non-nil, the GTK file chooser will show additional help text.
6212 If more space for files in the file chooser dialog is wanted, set this to nil
6213 to turn the additional text off. */);
6214 x_gtk_file_dialog_help_text
= 1;
6216 DEFVAR_BOOL ("x-gtk-whole-detached-tool-bar", x_gtk_whole_detached_tool_bar
,
6217 doc
: /* If non-nil, a detached tool bar is shown in full.
6218 The default is to just show an arrow and pressing on that arrow shows
6219 the tool bar buttons. */);
6220 x_gtk_whole_detached_tool_bar
= 0;
6222 DEFVAR_BOOL ("x-gtk-use-system-tooltips", x_gtk_use_system_tooltips
,
6223 doc
: /* If non-nil with a Gtk+ built Emacs, the Gtk+ tooltip is used.
6224 Otherwise use Emacs own tooltip implementation.
6225 When using Gtk+ tooltips, the tooltip face is not used. */);
6226 x_gtk_use_system_tooltips
= 1;
6228 /* Tell Emacs about this window system. */
6229 Fprovide (Qx
, Qnil
);
6231 #ifdef USE_X_TOOLKIT
6232 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
6234 Fprovide (intern_c_string ("motif"), Qnil
);
6236 DEFVAR_LISP ("motif-version-string", Vmotif_version_string
,
6237 doc
: /* Version info for LessTif/Motif. */);
6238 Vmotif_version_string
= build_string (XmVERSION_STRING
);
6239 #endif /* USE_MOTIF */
6240 #endif /* USE_X_TOOLKIT */
6243 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
6244 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
6245 But for a user it is a toolkit for X, and indeed, configure
6246 accepts --with-x-toolkit=gtk. */
6247 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
6248 Fprovide (intern_c_string ("gtk"), Qnil
);
6249 Fprovide (intern_c_string ("move-toolbar"), Qnil
);
6251 DEFVAR_LISP ("gtk-version-string", Vgtk_version_string
,
6252 doc
: /* Version info for GTK+. */);
6254 char gtk_version
[sizeof ".." + 3 * INT_STRLEN_BOUND (int)];
6255 int len
= sprintf (gtk_version
, "%d.%d.%d",
6256 GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
);
6257 Vgtk_version_string
= make_pure_string (gtk_version
, len
, len
, 0);
6259 #endif /* USE_GTK */
6261 /* X window properties. */
6262 defsubr (&Sx_change_window_property
);
6263 defsubr (&Sx_delete_window_property
);
6264 defsubr (&Sx_window_property
);
6266 defsubr (&Sxw_display_color_p
);
6267 defsubr (&Sx_display_grayscale_p
);
6268 defsubr (&Sxw_color_defined_p
);
6269 defsubr (&Sxw_color_values
);
6270 defsubr (&Sx_server_max_request_size
);
6271 defsubr (&Sx_server_vendor
);
6272 defsubr (&Sx_server_version
);
6273 defsubr (&Sx_display_pixel_width
);
6274 defsubr (&Sx_display_pixel_height
);
6275 defsubr (&Sx_display_mm_width
);
6276 defsubr (&Sx_display_mm_height
);
6277 defsubr (&Sx_display_screens
);
6278 defsubr (&Sx_display_planes
);
6279 defsubr (&Sx_display_color_cells
);
6280 defsubr (&Sx_display_visual_class
);
6281 defsubr (&Sx_display_backing_store
);
6282 defsubr (&Sx_display_save_under
);
6283 defsubr (&Sx_display_monitor_attributes_list
);
6284 defsubr (&Sx_wm_set_size_hint
);
6285 defsubr (&Sx_create_frame
);
6286 defsubr (&Sx_open_connection
);
6287 defsubr (&Sx_close_connection
);
6288 defsubr (&Sx_display_list
);
6289 defsubr (&Sx_synchronize
);
6290 defsubr (&Sx_backspace_delete_keys_p
);
6292 defsubr (&Sx_show_tip
);
6293 defsubr (&Sx_hide_tip
);
6295 staticpro (&tip_timer
);
6297 staticpro (&tip_frame
);
6299 last_show_tip_args
= Qnil
;
6300 staticpro (&last_show_tip_args
);
6302 defsubr (&Sx_uses_old_gtk_dialog
);
6303 #if defined (USE_MOTIF) || defined (USE_GTK)
6304 defsubr (&Sx_file_dialog
);
6307 #if defined (USE_GTK) && defined (HAVE_FREETYPE)
6308 defsubr (&Sx_select_font
);