1 /* Functions for the X window system.
3 Copyright (C) 1989, 1992-2013 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
29 #include "character.h"
31 #include "intervals.h"
32 #include "dispextern.h"
34 #include "blockinput.h"
40 #include "termhooks.h"
47 #include <sys/types.h>
50 #if 1 /* Used to be #ifdef EMACS_BITMAP_FILES, but this should always work. */
51 #include "bitmaps/gray.xbm"
53 #include <X11/bitmaps/gray>
56 #include "xsettings.h"
59 #include <X11/extensions/Xrandr.h>
62 #include <X11/extensions/Xinerama.h>
70 #include <X11/Shell.h>
74 #include <X11/Xaw3d/Paned.h>
75 #include <X11/Xaw3d/Label.h>
76 #else /* !HAVE_XAW3D */
77 #include <X11/Xaw/Paned.h>
78 #include <X11/Xaw/Label.h>
79 #endif /* HAVE_XAW3D */
80 #endif /* USE_MOTIF */
83 #undef USG /* ####KLUDGE for Solaris 2.2 and up */
86 #ifdef USG /* Pacify gcc -Wunused-macros. */
94 #include "../lwlib/lwlib.h"
98 #include <Xm/DialogS.h>
99 #include <Xm/FileSB.h>
101 #include <Xm/TextF.h>
105 #include "../lwlib/xlwmenu.h"
108 #if !defined (NO_EDITRES)
110 extern void _XEditResCheckMessages (Widget
, XtPointer
, XEvent
*, Boolean
*);
111 #endif /* not defined NO_EDITRES */
113 /* Unique id counter for widgets created by the Lucid Widget Library. */
115 extern LWLIB_ID widget_id_tick
;
119 #endif /* USE_MOTIF */
121 #endif /* USE_X_TOOLKIT */
127 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
129 static Lisp_Object Qsuppress_icon
;
130 static Lisp_Object Qundefined_color
;
131 static Lisp_Object Qcompound_text
, Qcancel_timer
;
132 Lisp_Object Qfont_param
;
135 static ptrdiff_t image_cache_refcount
;
136 static int dpyinfo_refcount
;
139 static struct x_display_info
*x_display_info_for_name (Lisp_Object
);
141 /* Let the user specify an X display with a Lisp object.
142 OBJECT may be nil, a frame or a terminal object.
143 nil stands for the selected frame--or, if that is not an X frame,
144 the first X display on the list. */
146 struct x_display_info
*
147 check_x_display_info (Lisp_Object object
)
149 struct x_display_info
*dpyinfo
= NULL
;
153 struct frame
*sf
= XFRAME (selected_frame
);
155 if (FRAME_X_P (sf
) && FRAME_LIVE_P (sf
))
156 dpyinfo
= FRAME_X_DISPLAY_INFO (sf
);
157 else if (x_display_list
!= 0)
158 dpyinfo
= x_display_list
;
160 error ("X windows are not in use or not initialized");
162 else if (TERMINALP (object
))
164 struct terminal
*t
= get_terminal (object
, 1);
166 if (t
->type
!= output_x_window
)
167 error ("Terminal %d is not an X display", t
->id
);
169 dpyinfo
= t
->display_info
.x
;
171 else if (STRINGP (object
))
172 dpyinfo
= x_display_info_for_name (object
);
175 struct frame
*f
= decode_window_system_frame (object
);
176 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
183 /* Return the Emacs frame-object corresponding to an X window.
184 It could be the frame's main window or an icon window. */
186 /* This function can be called during GC, so use GC_xxx type test macros. */
189 x_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
191 Lisp_Object tail
, frame
;
197 FOR_EACH_FRAME (tail
, frame
)
200 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
202 if (f
->output_data
.x
->hourglass_window
== wdesc
)
205 if ((f
->output_data
.x
->edit_widget
206 && XtWindow (f
->output_data
.x
->edit_widget
) == wdesc
)
207 /* A tooltip frame? */
208 || (!f
->output_data
.x
->edit_widget
209 && FRAME_X_WINDOW (f
) == wdesc
)
210 || f
->output_data
.x
->icon_desc
== wdesc
)
212 #else /* not USE_X_TOOLKIT */
214 if (f
->output_data
.x
->edit_widget
)
216 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
217 struct x_output
*x
= f
->output_data
.x
;
218 if (gwdesc
!= 0 && gwdesc
== x
->edit_widget
)
222 if (FRAME_X_WINDOW (f
) == wdesc
223 || f
->output_data
.x
->icon_desc
== wdesc
)
225 #endif /* not USE_X_TOOLKIT */
230 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
231 /* Like x_window_to_frame but also compares the window with the widget's
235 x_any_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
237 Lisp_Object tail
, frame
;
238 struct frame
*f
, *found
= NULL
;
244 FOR_EACH_FRAME (tail
, frame
)
249 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
251 /* This frame matches if the window is any of its widgets. */
252 x
= f
->output_data
.x
;
253 if (x
->hourglass_window
== wdesc
)
258 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
260 && gtk_widget_get_toplevel (gwdesc
) == x
->widget
)
263 if (wdesc
== XtWindow (x
->widget
)
264 || wdesc
== XtWindow (x
->column_widget
)
265 || wdesc
== XtWindow (x
->edit_widget
))
267 /* Match if the window is this frame's menubar. */
268 else if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
272 else if (FRAME_X_WINDOW (f
) == wdesc
)
273 /* A tooltip frame. */
281 /* Likewise, but consider only the menu bar widget. */
284 x_menubar_window_to_frame (struct x_display_info
*dpyinfo
, XEvent
*event
)
286 Window wdesc
= event
->xany
.window
;
287 Lisp_Object tail
, frame
;
294 FOR_EACH_FRAME (tail
, frame
)
297 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
299 x
= f
->output_data
.x
;
301 if (x
->menubar_widget
&& xg_event_is_for_menubar (f
, event
))
304 /* Match if the window is this frame's menubar. */
305 if (x
->menubar_widget
306 && lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
313 /* Return the frame whose principal (outermost) window is WDESC.
314 If WDESC is some other (smaller) window, we return 0. */
317 x_top_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
319 Lisp_Object tail
, frame
;
326 FOR_EACH_FRAME (tail
, frame
)
329 if (!FRAME_X_P (f
) || FRAME_X_DISPLAY_INFO (f
) != dpyinfo
)
331 x
= f
->output_data
.x
;
335 /* This frame matches if the window is its topmost widget. */
337 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
338 if (gwdesc
== x
->widget
)
341 if (wdesc
== XtWindow (x
->widget
))
343 #if 0 /* I don't know why it did this,
344 but it seems logically wrong,
345 and it causes trouble for MapNotify events. */
346 /* Match if the window is this frame's menubar. */
347 if (x
->menubar_widget
348 && wdesc
== XtWindow (x
->menubar_widget
))
353 else if (FRAME_X_WINDOW (f
) == wdesc
)
359 #endif /* USE_X_TOOLKIT || USE_GTK */
363 /* Store the screen positions of frame F into XPTR and YPTR.
364 These are the positions of the containing window manager window,
365 not Emacs's own window. */
368 x_real_positions (struct frame
*f
, int *xptr
, int *yptr
)
370 int win_x
, win_y
, outer_x
IF_LINT (= 0), outer_y
IF_LINT (= 0);
371 int real_x
= 0, real_y
= 0;
373 Window win
= f
->output_data
.x
->parent_desc
;
375 unsigned long actual_size
, bytes_remaining
;
376 int rc
, actual_format
;
377 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
379 Display
*dpy
= FRAME_X_DISPLAY (f
);
380 unsigned char *tmp_data
= NULL
;
381 Atom target_type
= XA_CARDINAL
;
385 x_catch_errors (dpy
);
387 if (win
== dpyinfo
->root_window
)
388 win
= FRAME_OUTER_WINDOW (f
);
390 /* This loop traverses up the containment tree until we hit the root
391 window. Window managers may intersect many windows between our window
392 and the root window. The window we find just before the root window
393 should be the outer WM window. */
396 Window wm_window
, rootw
;
397 Window
*tmp_children
;
398 unsigned int tmp_nchildren
;
401 success
= XQueryTree (FRAME_X_DISPLAY (f
), win
, &rootw
,
402 &wm_window
, &tmp_children
, &tmp_nchildren
);
404 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
406 /* Don't free tmp_children if XQueryTree failed. */
410 XFree (tmp_children
);
412 if (wm_window
== rootw
|| had_errors
)
423 /* Get the real coordinates for the WM window upper left corner */
424 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
425 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
427 /* Translate real coordinates to coordinates relative to our
428 window. For our window, the upper left corner is 0, 0.
429 Since the upper left corner of the WM window is outside
430 our window, win_x and win_y will be negative:
432 ------------------ ---> x
434 | ----------------- v y
437 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
439 /* From-window, to-window. */
440 FRAME_X_DISPLAY_INFO (f
)->root_window
,
443 /* From-position, to-position. */
444 real_x
, real_y
, &win_x
, &win_y
,
449 if (FRAME_X_WINDOW (f
) == FRAME_OUTER_WINDOW (f
))
456 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
458 /* From-window, to-window. */
459 FRAME_X_DISPLAY_INFO (f
)->root_window
,
460 FRAME_OUTER_WINDOW (f
),
462 /* From-position, to-position. */
463 real_x
, real_y
, &outer_x
, &outer_y
,
469 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
473 if (dpyinfo
->root_window
== f
->output_data
.x
->parent_desc
)
475 /* Try _NET_FRAME_EXTENTS if our parent is the root window. */
476 rc
= XGetWindowProperty (dpy
, win
, dpyinfo
->Xatom_net_frame_extents
,
477 0, max_len
, False
, target_type
,
478 &actual_type
, &actual_format
, &actual_size
,
479 &bytes_remaining
, &tmp_data
);
481 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
482 && actual_size
== 4 && actual_format
== 32)
486 long *fe
= (long *)tmp_data
;
488 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
489 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
497 if (tmp_data
) XFree (tmp_data
);
503 if (had_errors
) return;
505 f
->x_pixels_diff
= -win_x
;
506 f
->y_pixels_diff
= -win_y
;
508 FRAME_X_OUTPUT (f
)->x_pixels_outer_diff
= -outer_x
;
509 FRAME_X_OUTPUT (f
)->y_pixels_outer_diff
= -outer_y
;
518 /* Gamma-correct COLOR on frame F. */
521 gamma_correct (struct frame
*f
, XColor
*color
)
525 color
->red
= pow (color
->red
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
526 color
->green
= pow (color
->green
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
527 color
->blue
= pow (color
->blue
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
532 /* Decide if color named COLOR_NAME is valid for use on frame F. If
533 so, return the RGB values in COLOR. If ALLOC_P,
534 allocate the color. Value is false if COLOR_NAME is invalid, or
535 no color could be allocated. */
538 x_defined_color (struct frame
*f
, const char *color_name
,
539 XColor
*color
, bool alloc_p
)
542 Display
*dpy
= FRAME_X_DISPLAY (f
);
543 Colormap cmap
= FRAME_X_COLORMAP (f
);
547 success_p
= xg_check_special_colors (f
, color_name
, color
);
550 success_p
= XParseColor (dpy
, cmap
, color_name
, color
) != 0;
551 if (success_p
&& alloc_p
)
552 success_p
= x_alloc_nearest_color (f
, cmap
, color
);
559 /* Return the pixel color value for color COLOR_NAME on frame F. If F
560 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
561 Signal an error if color can't be allocated. */
564 x_decode_color (struct frame
*f
, Lisp_Object color_name
, int mono_color
)
568 CHECK_STRING (color_name
);
570 #if 0 /* Don't do this. It's wrong when we're not using the default
571 colormap, it makes freeing difficult, and it's probably not
572 an important optimization. */
573 if (strcmp (SDATA (color_name
), "black") == 0)
574 return BLACK_PIX_DEFAULT (f
);
575 else if (strcmp (SDATA (color_name
), "white") == 0)
576 return WHITE_PIX_DEFAULT (f
);
579 /* Return MONO_COLOR for monochrome frames. */
580 if (FRAME_X_DISPLAY_INFO (f
)->n_planes
== 1)
583 /* x_defined_color is responsible for coping with failures
584 by looking for a near-miss. */
585 if (x_defined_color (f
, SSDATA (color_name
), &cdef
, 1))
588 signal_error ("Undefined color", color_name
);
593 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
594 the previous value of that parameter, NEW_VALUE is the new value.
595 See also the comment of wait_for_wm in struct x_output. */
598 x_set_wait_for_wm (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
600 f
->output_data
.x
->wait_for_wm
= !NILP (new_value
);
604 x_set_tool_bar_position (struct frame
*f
,
605 Lisp_Object new_value
,
606 Lisp_Object old_value
)
608 if (! EQ (new_value
, Qleft
) && ! EQ (new_value
, Qright
)
609 && ! EQ (new_value
, Qbottom
) && ! EQ (new_value
, Qtop
))
611 if (EQ (new_value
, old_value
)) return;
614 xg_change_toolbar_position (f
, new_value
);
615 fset_tool_bar_position (f
, new_value
);
621 /* Set icon from FILE for frame F. By using GTK functions the icon
622 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
625 xg_set_icon (struct frame
*f
, Lisp_Object file
)
630 found
= x_find_image_file (file
);
636 char *filename
= SSDATA (found
);
639 pixbuf
= gdk_pixbuf_new_from_file (filename
, &err
);
643 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
645 g_object_unref (pixbuf
);
659 xg_set_icon_from_xpm_data (struct frame
*f
, const char **data
)
661 GdkPixbuf
*pixbuf
= gdk_pixbuf_new_from_xpm_data (data
);
666 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)), pixbuf
);
667 g_object_unref (pixbuf
);
673 /* Functions called only from `x_set_frame_param'
674 to set individual parameters.
676 If FRAME_X_WINDOW (f) is 0,
677 the frame is being created and its X-window does not exist yet.
678 In that case, just record the parameter's new value
679 in the standard place; do not attempt to change the window. */
682 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
684 struct x_output
*x
= f
->output_data
.x
;
685 unsigned long fg
, old_fg
;
687 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
688 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
689 FRAME_FOREGROUND_PIXEL (f
) = fg
;
691 if (FRAME_X_WINDOW (f
) != 0)
693 Display
*dpy
= FRAME_X_DISPLAY (f
);
696 XSetForeground (dpy
, x
->normal_gc
, fg
);
697 XSetBackground (dpy
, x
->reverse_gc
, fg
);
699 if (x
->cursor_pixel
== old_fg
)
701 unload_color (f
, x
->cursor_pixel
);
702 x
->cursor_pixel
= x_copy_color (f
, fg
);
703 XSetBackground (dpy
, x
->cursor_gc
, x
->cursor_pixel
);
708 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
710 if (FRAME_VISIBLE_P (f
))
714 unload_color (f
, old_fg
);
718 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
720 struct x_output
*x
= f
->output_data
.x
;
723 bg
= x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
724 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
725 FRAME_BACKGROUND_PIXEL (f
) = bg
;
727 if (FRAME_X_WINDOW (f
) != 0)
729 Display
*dpy
= FRAME_X_DISPLAY (f
);
732 XSetBackground (dpy
, x
->normal_gc
, bg
);
733 XSetForeground (dpy
, x
->reverse_gc
, bg
);
734 XSetWindowBackground (dpy
, FRAME_X_WINDOW (f
), bg
);
735 XSetForeground (dpy
, x
->cursor_gc
, bg
);
738 xg_set_background_color (f
, bg
);
741 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
742 toolkit scroll bars. */
745 for (bar
= FRAME_SCROLL_BARS (f
);
747 bar
= XSCROLL_BAR (bar
)->next
)
749 Window window
= XSCROLL_BAR (bar
)->x_window
;
750 XSetWindowBackground (dpy
, window
, bg
);
753 #endif /* USE_TOOLKIT_SCROLL_BARS */
756 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
758 if (FRAME_VISIBLE_P (f
))
764 make_invisible_cursor (struct frame
*f
)
766 Display
*dpy
= FRAME_X_DISPLAY (f
);
767 static char const no_data
[] = { 0 };
772 x_catch_errors (dpy
);
773 pix
= XCreateBitmapFromData (dpy
, FRAME_X_DISPLAY_INFO (f
)->root_window
,
775 if (! x_had_errors_p (dpy
) && pix
!= None
)
779 col
.red
= col
.green
= col
.blue
= 0;
780 col
.flags
= DoRed
| DoGreen
| DoBlue
;
781 pixc
= XCreatePixmapCursor (dpy
, pix
, pix
, &col
, &col
, 0, 0);
782 if (! x_had_errors_p (dpy
) && pixc
!= None
)
784 XFreePixmap (dpy
, pix
);
793 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
795 struct x_output
*x
= f
->output_data
.x
;
796 Display
*dpy
= FRAME_X_DISPLAY (f
);
797 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
798 Cursor hourglass_cursor
, horizontal_drag_cursor
;
799 unsigned long pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
800 unsigned long mask_color
= FRAME_BACKGROUND_PIXEL (f
);
802 /* Don't let pointers be invisible. */
803 if (mask_color
== pixel
)
805 x_free_colors (f
, &pixel
, 1);
806 pixel
= x_copy_color (f
, FRAME_FOREGROUND_PIXEL (f
));
809 unload_color (f
, x
->mouse_pixel
);
810 x
->mouse_pixel
= pixel
;
814 /* It's not okay to crash if the user selects a screwy cursor. */
815 x_catch_errors (dpy
);
817 if (!NILP (Vx_pointer_shape
))
819 CHECK_NUMBER (Vx_pointer_shape
);
820 cursor
= XCreateFontCursor (dpy
, XINT (Vx_pointer_shape
));
823 cursor
= XCreateFontCursor (dpy
, XC_xterm
);
824 x_check_errors (dpy
, "bad text pointer cursor: %s");
826 if (!NILP (Vx_nontext_pointer_shape
))
828 CHECK_NUMBER (Vx_nontext_pointer_shape
);
830 = XCreateFontCursor (dpy
, XINT (Vx_nontext_pointer_shape
));
833 nontext_cursor
= XCreateFontCursor (dpy
, XC_left_ptr
);
834 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
836 if (!NILP (Vx_hourglass_pointer_shape
))
838 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
840 = XCreateFontCursor (dpy
, XINT (Vx_hourglass_pointer_shape
));
843 hourglass_cursor
= XCreateFontCursor (dpy
, XC_watch
);
844 x_check_errors (dpy
, "bad hourglass pointer cursor: %s");
846 if (!NILP (Vx_mode_pointer_shape
))
848 CHECK_NUMBER (Vx_mode_pointer_shape
);
849 mode_cursor
= XCreateFontCursor (dpy
, XINT (Vx_mode_pointer_shape
));
852 mode_cursor
= XCreateFontCursor (dpy
, XC_xterm
);
853 x_check_errors (dpy
, "bad modeline pointer cursor: %s");
855 if (!NILP (Vx_sensitive_text_pointer_shape
))
857 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
859 = XCreateFontCursor (dpy
, XINT (Vx_sensitive_text_pointer_shape
));
862 hand_cursor
= XCreateFontCursor (dpy
, XC_hand2
);
864 if (!NILP (Vx_window_horizontal_drag_shape
))
866 CHECK_NUMBER (Vx_window_horizontal_drag_shape
);
867 horizontal_drag_cursor
868 = XCreateFontCursor (dpy
, XINT (Vx_window_horizontal_drag_shape
));
871 horizontal_drag_cursor
872 = XCreateFontCursor (dpy
, XC_sb_h_double_arrow
);
874 /* Check and report errors with the above calls. */
875 x_check_errors (dpy
, "can't set cursor shape: %s");
879 XColor fore_color
, back_color
;
881 fore_color
.pixel
= x
->mouse_pixel
;
882 x_query_color (f
, &fore_color
);
883 back_color
.pixel
= mask_color
;
884 x_query_color (f
, &back_color
);
886 XRecolorCursor (dpy
, cursor
, &fore_color
, &back_color
);
887 XRecolorCursor (dpy
, nontext_cursor
, &fore_color
, &back_color
);
888 XRecolorCursor (dpy
, mode_cursor
, &fore_color
, &back_color
);
889 XRecolorCursor (dpy
, hand_cursor
, &fore_color
, &back_color
);
890 XRecolorCursor (dpy
, hourglass_cursor
, &fore_color
, &back_color
);
891 XRecolorCursor (dpy
, horizontal_drag_cursor
, &fore_color
, &back_color
);
894 if (FRAME_X_WINDOW (f
) != 0)
895 XDefineCursor (dpy
, FRAME_X_WINDOW (f
),
896 f
->output_data
.x
->current_cursor
= cursor
);
898 if (FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
== 0)
899 FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
= make_invisible_cursor (f
);
901 if (cursor
!= x
->text_cursor
902 && x
->text_cursor
!= 0)
903 XFreeCursor (dpy
, x
->text_cursor
);
904 x
->text_cursor
= cursor
;
906 if (nontext_cursor
!= x
->nontext_cursor
907 && x
->nontext_cursor
!= 0)
908 XFreeCursor (dpy
, x
->nontext_cursor
);
909 x
->nontext_cursor
= nontext_cursor
;
911 if (hourglass_cursor
!= x
->hourglass_cursor
912 && x
->hourglass_cursor
!= 0)
913 XFreeCursor (dpy
, x
->hourglass_cursor
);
914 x
->hourglass_cursor
= hourglass_cursor
;
916 if (mode_cursor
!= x
->modeline_cursor
917 && x
->modeline_cursor
!= 0)
918 XFreeCursor (dpy
, f
->output_data
.x
->modeline_cursor
);
919 x
->modeline_cursor
= mode_cursor
;
921 if (hand_cursor
!= x
->hand_cursor
922 && x
->hand_cursor
!= 0)
923 XFreeCursor (dpy
, x
->hand_cursor
);
924 x
->hand_cursor
= hand_cursor
;
926 if (horizontal_drag_cursor
!= x
->horizontal_drag_cursor
927 && x
->horizontal_drag_cursor
!= 0)
928 XFreeCursor (dpy
, x
->horizontal_drag_cursor
);
929 x
->horizontal_drag_cursor
= horizontal_drag_cursor
;
934 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
938 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
940 unsigned long fore_pixel
, pixel
;
941 bool fore_pixel_allocated_p
= 0, pixel_allocated_p
= 0;
942 struct x_output
*x
= f
->output_data
.x
;
944 if (!NILP (Vx_cursor_fore_pixel
))
946 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
947 WHITE_PIX_DEFAULT (f
));
948 fore_pixel_allocated_p
= 1;
951 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
953 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
954 pixel_allocated_p
= 1;
956 /* Make sure that the cursor color differs from the background color. */
957 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
959 if (pixel_allocated_p
)
961 x_free_colors (f
, &pixel
, 1);
962 pixel_allocated_p
= 0;
965 pixel
= x
->mouse_pixel
;
966 if (pixel
== fore_pixel
)
968 if (fore_pixel_allocated_p
)
970 x_free_colors (f
, &fore_pixel
, 1);
971 fore_pixel_allocated_p
= 0;
973 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
977 unload_color (f
, x
->cursor_foreground_pixel
);
978 if (!fore_pixel_allocated_p
)
979 fore_pixel
= x_copy_color (f
, fore_pixel
);
980 x
->cursor_foreground_pixel
= fore_pixel
;
982 unload_color (f
, x
->cursor_pixel
);
983 if (!pixel_allocated_p
)
984 pixel
= x_copy_color (f
, pixel
);
985 x
->cursor_pixel
= pixel
;
987 if (FRAME_X_WINDOW (f
) != 0)
990 XSetBackground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, x
->cursor_pixel
);
991 XSetForeground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, fore_pixel
);
994 if (FRAME_VISIBLE_P (f
))
996 x_update_cursor (f
, 0);
997 x_update_cursor (f
, 1);
1001 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
1004 /* Set the border-color of frame F to pixel value PIX.
1005 Note that this does not fully take effect if done before
1006 F has an x-window. */
1009 x_set_border_pixel (struct frame
*f
, int pix
)
1011 unload_color (f
, f
->output_data
.x
->border_pixel
);
1012 f
->output_data
.x
->border_pixel
= pix
;
1014 if (FRAME_X_WINDOW (f
) != 0 && f
->border_width
> 0)
1017 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), pix
);
1020 if (FRAME_VISIBLE_P (f
))
1025 /* Set the border-color of frame F to value described by ARG.
1026 ARG can be a string naming a color.
1027 The border-color is used for the border that is drawn by the X server.
1028 Note that this does not fully take effect if done before
1029 F has an x-window; it must be redone when the window is created.
1031 Note: this is done in two routines because of the way X10 works.
1033 Note: under X11, this is normally the province of the window manager,
1034 and so emacs's border colors may be overridden. */
1037 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1042 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
1043 x_set_border_pixel (f
, pix
);
1044 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
1049 x_set_cursor_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1051 set_frame_cursor_types (f
, arg
);
1055 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1061 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1064 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
1069 result
= x_text_icon (f
,
1070 SSDATA ((!NILP (f
->icon_name
)
1074 result
= x_bitmap_icon (f
, arg
);
1079 error ("No icon window available");
1082 XFlush (FRAME_X_DISPLAY (f
));
1087 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1093 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
1096 else if (!NILP (arg
) || NILP (oldval
))
1099 fset_icon_name (f
, arg
);
1101 if (f
->output_data
.x
->icon_bitmap
!= 0)
1106 result
= x_text_icon (f
,
1107 SSDATA ((!NILP (f
->icon_name
)
1116 error ("No icon window available");
1119 XFlush (FRAME_X_DISPLAY (f
));
1125 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1128 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
1129 int olines
= FRAME_MENU_BAR_LINES (f
);
1132 /* Right now, menu bars don't work properly in minibuf-only frames;
1133 most of the commands try to apply themselves to the minibuffer
1134 frame itself, and get an error because you can't switch buffers
1135 in or split the minibuffer window. */
1136 if (FRAME_MINIBUF_ONLY_P (f
))
1139 if (TYPE_RANGED_INTEGERP (int, value
))
1140 nlines
= XINT (value
);
1144 /* Make sure we redisplay all windows in this frame. */
1145 windows_or_buffers_changed
++;
1147 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
1148 FRAME_MENU_BAR_LINES (f
) = 0;
1151 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1152 if (FRAME_X_P (f
) && f
->output_data
.x
->menubar_widget
== 0)
1153 /* Make sure next redisplay shows the menu bar. */
1154 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= 1;
1158 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1159 free_frame_menubar (f
);
1160 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1162 f
->output_data
.x
->menubar_widget
= 0;
1164 #else /* not USE_X_TOOLKIT && not USE_GTK */
1165 FRAME_MENU_BAR_LINES (f
) = nlines
;
1166 resize_frame_windows (f
, FRAME_LINES (f
), 0);
1168 /* If the menu bar height gets changed, the internal border below
1169 the top margin has to be cleared. Also, if the menu bar gets
1170 larger, the area for the added lines has to be cleared except for
1171 the first menu bar line that is to be drawn later. */
1172 if (nlines
!= olines
)
1174 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1175 int width
= FRAME_PIXEL_WIDTH (f
);
1178 /* height can be zero here. */
1179 if (height
> 0 && width
> 0)
1181 y
= FRAME_TOP_MARGIN_HEIGHT (f
);
1184 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1185 0, y
, width
, height
);
1189 if (nlines
> 1 && nlines
> olines
)
1191 y
= (olines
== 0 ? 1 : olines
) * FRAME_LINE_HEIGHT (f
);
1192 height
= nlines
* FRAME_LINE_HEIGHT (f
) - y
;
1195 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1196 0, y
, width
, height
);
1200 if (nlines
== 0 && WINDOWP (f
->menu_bar_window
))
1201 clear_glyph_matrix (XWINDOW (f
->menu_bar_window
)->current_matrix
);
1203 #endif /* not USE_X_TOOLKIT && not USE_GTK */
1204 adjust_frame_glyphs (f
);
1205 run_window_configuration_change_hook (f
);
1209 /* Set the number of lines used for the tool bar of frame F to VALUE.
1210 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1211 is the old number of tool bar lines. This function changes the
1212 height of all windows on frame F to match the new tool bar height.
1213 The frame's height doesn't change. */
1216 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1219 #if ! defined (USE_GTK)
1220 int delta
, root_height
;
1221 Lisp_Object root_window
;
1224 /* Treat tool bars like menu bars. */
1225 if (FRAME_MINIBUF_ONLY_P (f
))
1228 /* Use VALUE only if an int >= 0. */
1229 if (RANGED_INTEGERP (0, value
, INT_MAX
))
1230 nlines
= XFASTINT (value
);
1236 FRAME_TOOL_BAR_LINES (f
) = 0;
1239 FRAME_EXTERNAL_TOOL_BAR (f
) = 1;
1240 if (FRAME_X_P (f
) && f
->output_data
.x
->toolbar_widget
== 0)
1241 /* Make sure next redisplay shows the tool bar. */
1242 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= 1;
1243 update_frame_tool_bar (f
);
1247 if (FRAME_EXTERNAL_TOOL_BAR (f
))
1248 free_frame_tool_bar (f
);
1249 FRAME_EXTERNAL_TOOL_BAR (f
) = 0;
1252 #else /* !USE_GTK */
1254 /* Make sure we redisplay all windows in this frame. */
1255 ++windows_or_buffers_changed
;
1257 delta
= nlines
- FRAME_TOOL_BAR_LINES (f
);
1259 /* Don't resize the tool-bar to more than we have room for. */
1260 root_window
= FRAME_ROOT_WINDOW (f
);
1261 root_height
= WINDOW_TOTAL_LINES (XWINDOW (root_window
));
1262 if (root_height
- delta
< 1)
1264 delta
= root_height
- 1;
1265 nlines
= FRAME_TOOL_BAR_LINES (f
) + delta
;
1268 FRAME_TOOL_BAR_LINES (f
) = nlines
;
1269 resize_frame_windows (f
, FRAME_LINES (f
), 0);
1270 adjust_frame_glyphs (f
);
1272 /* We also have to make sure that the internal border at the top of
1273 the frame, below the menu bar or tool bar, is redrawn when the
1274 tool bar disappears. This is so because the internal border is
1275 below the tool bar if one is displayed, but is below the menu bar
1276 if there isn't a tool bar. The tool bar draws into the area
1277 below the menu bar. */
1278 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_LINES (f
) == 0)
1281 clear_current_matrices (f
);
1284 /* If the tool bar gets smaller, the internal border below it
1285 has to be cleared. It was formerly part of the display
1286 of the larger tool bar, and updating windows won't clear it. */
1289 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1290 int width
= FRAME_PIXEL_WIDTH (f
);
1291 int y
= (FRAME_MENU_BAR_LINES (f
) + nlines
) * FRAME_LINE_HEIGHT (f
);
1293 /* height can be zero here. */
1294 if (height
> 0 && width
> 0)
1297 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1298 0, y
, width
, height
);
1302 if (WINDOWP (f
->tool_bar_window
))
1303 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1306 run_window_configuration_change_hook (f
);
1307 #endif /* USE_GTK */
1311 /* Set the foreground color for scroll bars on frame F to VALUE.
1312 VALUE should be a string, a color name. If it isn't a string or
1313 isn't a valid color name, do nothing. OLDVAL is the old value of
1314 the frame parameter. */
1317 x_set_scroll_bar_foreground (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1319 unsigned long pixel
;
1321 if (STRINGP (value
))
1322 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
1326 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
1327 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
1329 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
1330 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1332 /* Remove all scroll bars because they have wrong colors. */
1333 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1334 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1335 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1336 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1338 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
1344 /* Set the background color for scroll bars on frame F to VALUE VALUE
1345 should be a string, a color name. If it isn't a string or isn't a
1346 valid color name, do nothing. OLDVAL is the old value of the frame
1350 x_set_scroll_bar_background (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1352 unsigned long pixel
;
1354 if (STRINGP (value
))
1355 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
1359 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
1360 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
1362 #ifdef USE_TOOLKIT_SCROLL_BARS
1363 /* Scrollbar shadow colors. */
1364 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
1366 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
1367 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
1369 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
1371 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
1372 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
1374 #endif /* USE_TOOLKIT_SCROLL_BARS */
1376 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
1377 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1379 /* Remove all scroll bars because they have wrong colors. */
1380 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1381 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1382 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1383 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1385 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
1391 /* Encode Lisp string STRING as a text in a format appropriate for
1392 XICCC (X Inter Client Communication Conventions).
1394 This can call Lisp code, so callers must GCPRO.
1396 If STRING contains only ASCII characters, do no conversion and
1397 return the string data of STRING. Otherwise, encode the text by
1398 CODING_SYSTEM, and return a newly allocated memory area which
1399 should be freed by `xfree' by a caller.
1401 SELECTIONP non-zero means the string is being encoded for an X
1402 selection, so it is safe to run pre-write conversions (which
1405 Store the byte length of resulting text in *TEXT_BYTES.
1407 If the text contains only ASCII and Latin-1, store 1 in *STRING_P,
1408 which means that the `encoding' of the result can be `STRING'.
1409 Otherwise store 0 in *STRINGP, which means that the `encoding' of
1410 the result should be `COMPOUND_TEXT'. */
1412 static unsigned char *
1413 x_encode_text (Lisp_Object string
, Lisp_Object coding_system
, int selectionp
,
1414 ptrdiff_t *text_bytes
, int *stringp
, int *freep
)
1416 int result
= string_xstring_p (string
);
1417 struct coding_system coding
;
1421 /* No multibyte character in OBJ. We need not encode it. */
1422 *text_bytes
= SBYTES (string
);
1425 return SDATA (string
);
1428 setup_coding_system (coding_system
, &coding
);
1429 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
1430 /* We suppress producing escape sequences for composition. */
1431 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
1432 coding
.destination
= xnmalloc (SCHARS (string
), 2);
1433 coding
.dst_bytes
= SCHARS (string
) * 2;
1434 encode_coding_object (&coding
, string
, 0, 0,
1435 SCHARS (string
), SBYTES (string
), Qnil
);
1436 *text_bytes
= coding
.produced
;
1437 *stringp
= (result
== 1 || !EQ (coding_system
, Qcompound_text
));
1439 return coding
.destination
;
1443 /* Set the WM name to NAME for frame F. Also set the icon name.
1444 If the frame already has an icon name, use that, otherwise set the
1445 icon name to NAME. */
1448 x_set_name_internal (struct frame
*f
, Lisp_Object name
)
1450 if (FRAME_X_WINDOW (f
))
1454 XTextProperty text
, icon
;
1457 int do_free_icon_value
= 0, do_free_text_value
= 0;
1458 Lisp_Object coding_system
;
1459 Lisp_Object encoded_name
;
1460 Lisp_Object encoded_icon_name
;
1461 struct gcpro gcpro1
;
1463 /* As ENCODE_UTF_8 may cause GC and relocation of string data,
1464 we use it before x_encode_text that may return string data. */
1466 encoded_name
= ENCODE_UTF_8 (name
);
1469 coding_system
= Qcompound_text
;
1470 /* Note: Encoding strategy
1472 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1473 text.encoding. But, there are non-internationalized window
1474 managers which don't support that encoding. So, if NAME
1475 contains only ASCII and 8859-1 characters, encode it by
1476 iso-latin-1, and use "STRING" in text.encoding hoping that
1477 such window managers at least analyze this format correctly,
1478 i.e. treat 8-bit bytes as 8859-1 characters.
1480 We may also be able to use "UTF8_STRING" in text.encoding
1481 in the future which can encode all Unicode characters.
1482 But, for the moment, there's no way to know that the
1483 current window manager supports it or not.
1485 Either way, we also set the _NET_WM_NAME and _NET_WM_ICON_NAME
1486 properties. Per the EWMH specification, those two properties
1487 are always UTF8_STRING. This matches what gtk_window_set_title()
1488 does in the USE_GTK case. */
1489 text
.value
= x_encode_text (name
, coding_system
, 0, &bytes
, &stringp
,
1490 &do_free_text_value
);
1491 text
.encoding
= (stringp
? XA_STRING
1492 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1494 text
.nitems
= bytes
;
1495 if (text
.nitems
!= bytes
)
1496 error ("Window name too large");
1498 if (!STRINGP (f
->icon_name
))
1501 encoded_icon_name
= encoded_name
;
1505 /* See the above comment "Note: Encoding strategy". */
1506 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, 0,
1507 &bytes
, &stringp
, &do_free_icon_value
);
1508 icon
.encoding
= (stringp
? XA_STRING
1509 : FRAME_X_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1511 icon
.nitems
= bytes
;
1512 if (icon
.nitems
!= bytes
)
1513 error ("Icon name too large");
1515 encoded_icon_name
= ENCODE_UTF_8 (f
->icon_name
);
1519 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1520 SSDATA (encoded_name
));
1521 #else /* not USE_GTK */
1522 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1523 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1524 FRAME_X_DISPLAY_INFO (f
)->Xatom_net_wm_name
,
1525 FRAME_X_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1527 SDATA (encoded_name
),
1528 SBYTES (encoded_name
));
1529 #endif /* not USE_GTK */
1531 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &icon
);
1532 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1533 FRAME_X_DISPLAY_INFO (f
)->Xatom_net_wm_icon_name
,
1534 FRAME_X_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1536 SDATA (encoded_icon_name
),
1537 SBYTES (encoded_icon_name
));
1539 if (do_free_icon_value
)
1541 if (do_free_text_value
)
1548 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1551 If EXPLICIT is non-zero, that indicates that lisp code is setting the
1552 name; if NAME is a string, set F's name to NAME and set
1553 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1555 If EXPLICIT is zero, that indicates that Emacs redisplay code is
1556 suggesting a new name, which lisp code should override; if
1557 F->explicit_name is set, ignore the new name; otherwise, set it. */
1560 x_set_name (struct frame
*f
, Lisp_Object name
, int explicit)
1562 /* Make sure that requests from lisp code override requests from
1563 Emacs redisplay code. */
1566 /* If we're switching from explicit to implicit, we had better
1567 update the mode lines and thereby update the title. */
1568 if (f
->explicit_name
&& NILP (name
))
1569 update_mode_lines
= 1;
1571 f
->explicit_name
= ! NILP (name
);
1573 else if (f
->explicit_name
)
1576 /* If NAME is nil, set the name to the x_id_name. */
1579 /* Check for no change needed in this very common case
1580 before we do any consing. */
1581 if (!strcmp (FRAME_X_DISPLAY_INFO (f
)->x_id_name
,
1584 name
= build_string (FRAME_X_DISPLAY_INFO (f
)->x_id_name
);
1587 CHECK_STRING (name
);
1589 /* Don't change the name if it's already NAME. */
1590 if (! NILP (Fstring_equal (name
, f
->name
)))
1593 fset_name (f
, name
);
1595 /* For setting the frame title, the title parameter should override
1596 the name parameter. */
1597 if (! NILP (f
->title
))
1600 x_set_name_internal (f
, name
);
1603 /* This function should be called when the user's lisp code has
1604 specified a name for the frame; the name will override any set by the
1607 x_explicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1609 x_set_name (f
, arg
, 1);
1612 /* This function should be called by Emacs redisplay code to set the
1613 name; names set this way will never override names set by the user's
1616 x_implicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1618 x_set_name (f
, arg
, 0);
1621 /* Change the title of frame F to NAME.
1622 If NAME is nil, use the frame name as the title. */
1625 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1627 /* Don't change the title if it's already NAME. */
1628 if (EQ (name
, f
->title
))
1631 update_mode_lines
= 1;
1633 fset_title (f
, name
);
1638 CHECK_STRING (name
);
1640 x_set_name_internal (f
, name
);
1644 x_set_scroll_bar_default_width (struct frame
*f
)
1646 int wid
= FRAME_COLUMN_WIDTH (f
);
1647 #ifdef USE_TOOLKIT_SCROLL_BARS
1649 int minw
= xg_get_default_scrollbar_width ();
1653 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1654 int width
= minw
+ 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
1655 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (width
+ wid
- 1) / wid
;
1656 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = width
;
1658 /* Make the actual width at least 14 pixels and a multiple of a
1660 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
1662 /* Use all of that space (aside from required margins) for the
1664 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = 0;
1669 /* Record in frame F the specified or default value according to ALIST
1670 of the parameter named PROP (a Lisp symbol). If no value is
1671 specified for PROP, look for an X default for XPROP on the frame
1672 named NAME. If that is not found either, use the value DEFLT. */
1675 x_default_scroll_bar_color_parameter (struct frame
*f
,
1676 Lisp_Object alist
, Lisp_Object prop
,
1677 const char *xprop
, const char *xclass
,
1680 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1683 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
1684 if (EQ (tem
, Qunbound
))
1686 #ifdef USE_TOOLKIT_SCROLL_BARS
1688 /* See if an X resource for the scroll bar color has been
1690 tem
= display_x_get_resource (dpyinfo
,
1691 build_string (foreground_p
1694 empty_unibyte_string
,
1695 build_string ("verticalScrollBar"),
1696 empty_unibyte_string
);
1699 /* If nothing has been specified, scroll bars will use a
1700 toolkit-dependent default. Because these defaults are
1701 difficult to get at without actually creating a scroll
1702 bar, use nil to indicate that no color has been
1707 #else /* not USE_TOOLKIT_SCROLL_BARS */
1711 #endif /* not USE_TOOLKIT_SCROLL_BARS */
1714 x_set_frame_parameters (f
, list1 (Fcons (prop
, tem
)));
1721 #ifdef USE_X_TOOLKIT
1723 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
1724 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
1725 already be present because of the toolkit (Motif adds some of them,
1726 for example, but Xt doesn't). */
1729 hack_wm_protocols (struct frame
*f
, Widget widget
)
1731 Display
*dpy
= XtDisplay (widget
);
1732 Window w
= XtWindow (widget
);
1733 int need_delete
= 1;
1740 unsigned char *catoms
;
1742 unsigned long nitems
= 0;
1743 unsigned long bytes_after
;
1745 if ((XGetWindowProperty (dpy
, w
,
1746 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1747 (long)0, (long)100, False
, XA_ATOM
,
1748 &type
, &format
, &nitems
, &bytes_after
,
1751 && format
== 32 && type
== XA_ATOM
)
1753 Atom
*atoms
= (Atom
*) catoms
;
1758 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
1760 else if (atoms
[nitems
]
1761 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
1763 else if (atoms
[nitems
]
1764 == FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
1775 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
1777 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
1779 props
[count
++] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
1781 XChangeProperty (dpy
, w
, FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1782 XA_ATOM
, 32, PropModeAppend
,
1783 (unsigned char *) props
, count
);
1791 /* Support routines for XIC (X Input Context). */
1795 static XFontSet
xic_create_xfontset (struct frame
*);
1796 static XIMStyle
best_xim_style (XIMStyles
*, XIMStyles
*);
1799 /* Supported XIM styles, ordered by preference. */
1801 static XIMStyle supported_xim_styles
[] =
1803 XIMPreeditPosition
| XIMStatusArea
,
1804 XIMPreeditPosition
| XIMStatusNothing
,
1805 XIMPreeditPosition
| XIMStatusNone
,
1806 XIMPreeditNothing
| XIMStatusArea
,
1807 XIMPreeditNothing
| XIMStatusNothing
,
1808 XIMPreeditNothing
| XIMStatusNone
,
1809 XIMPreeditNone
| XIMStatusArea
,
1810 XIMPreeditNone
| XIMStatusNothing
,
1811 XIMPreeditNone
| XIMStatusNone
,
1816 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1817 /* Create an X fontset on frame F with base font name BASE_FONTNAME. */
1819 static const char xic_default_fontset
[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
1821 /* Create an Xt fontset spec from the name of a base font.
1822 If `motif' is True use the Motif syntax. */
1824 xic_create_fontsetname (const char *base_fontname
, int motif
)
1826 const char *sep
= motif
? ";" : ",";
1829 /* Make a fontset name from the base font name. */
1830 if (xic_default_fontset
== base_fontname
)
1832 /* There is no base font name, use the default. */
1833 fontsetname
= xmalloc (strlen (base_fontname
) + 2);
1834 strcpy (fontsetname
, base_fontname
);
1838 /* Make a fontset name from the base font name.
1839 The font set will be made of the following elements:
1841 - the base font where the charset spec is replaced by -*-*.
1842 - the same but with the family also replaced with -*-*-. */
1843 const char *p
= base_fontname
;
1846 for (i
= 0; *p
; p
++)
1850 /* As the font name doesn't conform to XLFD, we can't
1851 modify it to generalize it to allcs and allfamilies.
1852 Use the specified font plus the default. */
1853 fontsetname
= xmalloc (strlen (base_fontname
)
1854 + strlen (xic_default_fontset
) + 3);
1855 strcpy (fontsetname
, base_fontname
);
1856 strcat (fontsetname
, sep
);
1857 strcat (fontsetname
, xic_default_fontset
);
1862 const char *p1
= NULL
, *p2
= NULL
, *p3
= NULL
;
1863 char *font_allcs
= NULL
;
1864 char *font_allfamilies
= NULL
;
1865 char *font_all
= NULL
;
1866 const char *allcs
= "*-*-*-*-*-*-*";
1867 const char *allfamilies
= "-*-*-";
1868 const char *all
= "*-*-*-*-";
1871 for (i
= 0, p
= base_fontname
; i
< 8; p
++)
1884 /* If base_fontname specifies ADSTYLE, make it a
1888 ptrdiff_t diff
= (p2
- p3
) - 2;
1890 base
= alloca (strlen (base_fontname
) + 1);
1891 memcpy (base
, base_fontname
, p3
- base_fontname
);
1892 base
[p3
- base_fontname
] = '*';
1893 base
[(p3
- base_fontname
) + 1] = '-';
1894 strcpy (base
+ (p3
- base_fontname
) + 2, p2
);
1895 p
= base
+ (p
- base_fontname
) - diff
;
1896 p1
= base
+ (p1
- base_fontname
);
1897 p2
= base
+ (p2
- base_fontname
) - diff
;
1898 base_fontname
= base
;
1901 /* Build the font spec that matches all charsets. */
1902 len
= p
- base_fontname
+ strlen (allcs
) + 1;
1903 font_allcs
= alloca (len
);
1904 memcpy (font_allcs
, base_fontname
, p
- base_fontname
);
1905 strcat (font_allcs
, allcs
);
1907 /* Build the font spec that matches all families and
1909 len
= p
- p1
+ strlen (allcs
) + strlen (allfamilies
) + 1;
1910 font_allfamilies
= alloca (len
);
1911 strcpy (font_allfamilies
, allfamilies
);
1912 memcpy (font_allfamilies
+ strlen (allfamilies
), p1
, p
- p1
);
1913 strcat (font_allfamilies
, allcs
);
1915 /* Build the font spec that matches all. */
1916 len
= p
- p2
+ strlen (allcs
) + strlen (all
) + strlen (allfamilies
) + 1;
1917 font_all
= alloca (len
);
1918 strcpy (font_all
, allfamilies
);
1919 strcat (font_all
, all
);
1920 memcpy (font_all
+ strlen (all
) + strlen (allfamilies
), p2
, p
- p2
);
1921 strcat (font_all
, allcs
);
1923 /* Build the actual font set name. */
1924 len
= strlen (base_fontname
) + strlen (font_allcs
)
1925 + strlen (font_allfamilies
) + strlen (font_all
) + 5;
1926 fontsetname
= xmalloc (len
);
1927 strcpy (fontsetname
, base_fontname
);
1928 strcat (fontsetname
, sep
);
1929 strcat (fontsetname
, font_allcs
);
1930 strcat (fontsetname
, sep
);
1931 strcat (fontsetname
, font_allfamilies
);
1932 strcat (fontsetname
, sep
);
1933 strcat (fontsetname
, font_all
);
1937 strcat (fontsetname
, ":");
1940 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
1942 #ifdef DEBUG_XIC_FONTSET
1944 print_fontset_result (XFontSet xfs
, char *name
, char **missing_list
,
1948 fprintf (stderr
, "XIC Fontset created: %s\n", name
);
1951 fprintf (stderr
, "XIC Fontset failed: %s\n", name
);
1952 while (missing_count
-- > 0)
1954 fprintf (stderr
, " missing: %s\n", *missing_list
);
1963 xic_create_xfontset (struct frame
*f
)
1965 XFontSet xfs
= NULL
;
1966 struct font
*font
= FRAME_FONT (f
);
1967 int pixel_size
= font
->pixel_size
;
1968 Lisp_Object rest
, frame
;
1970 /* See if there is another frame already using same fontset. */
1971 FOR_EACH_FRAME (rest
, frame
)
1973 struct frame
*cf
= XFRAME (frame
);
1975 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
1976 && FRAME_X_DISPLAY_INFO (cf
) == FRAME_X_DISPLAY_INFO (f
)
1978 && FRAME_FONT (f
)->pixel_size
== pixel_size
)
1980 xfs
= FRAME_XIC_FONTSET (cf
);
1988 char **missing_list
;
1991 const char *xlfd_format
= "-*-*-medium-r-normal--%d-*-*-*-*-*";
1993 sprintf (buf
, xlfd_format
, pixel_size
);
1994 missing_list
= NULL
;
1995 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
1996 &missing_list
, &missing_count
, &def_string
);
1997 #ifdef DEBUG_XIC_FONTSET
1998 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
2001 XFreeStringList (missing_list
);
2004 /* List of pixel sizes most likely available. Find one that
2005 is closest to pixel_size. */
2006 int sizes
[] = {0, 8, 10, 11, 12, 14, 17, 18, 20, 24, 26, 34, 0};
2007 int *smaller
, *larger
;
2009 for (smaller
= sizes
; smaller
[1]; smaller
++)
2010 if (smaller
[1] >= pixel_size
)
2012 larger
= smaller
+ 1;
2013 if (*larger
== pixel_size
)
2015 while (*smaller
|| *larger
)
2020 this_size
= *smaller
--;
2021 else if (! *smaller
)
2022 this_size
= *larger
++;
2023 else if (pixel_size
- *smaller
< *larger
- pixel_size
)
2024 this_size
= *smaller
--;
2026 this_size
= *larger
++;
2027 sprintf (buf
, xlfd_format
, this_size
);
2028 missing_list
= NULL
;
2029 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
2030 &missing_list
, &missing_count
, &def_string
);
2031 #ifdef DEBUG_XIC_FONTSET
2032 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
2035 XFreeStringList (missing_list
);
2042 const char *last_resort
= "-*-*-*-r-normal--*-*-*-*-*-*";
2044 missing_list
= NULL
;
2045 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), last_resort
,
2046 &missing_list
, &missing_count
, &def_string
);
2047 #ifdef DEBUG_XIC_FONTSET
2048 print_fontset_result (xfs
, last_resort
, missing_list
, missing_count
);
2051 XFreeStringList (missing_list
);
2059 /* Free the X fontset of frame F if it is the last frame using it. */
2062 xic_free_xfontset (struct frame
*f
)
2064 Lisp_Object rest
, frame
;
2067 if (!FRAME_XIC_FONTSET (f
))
2070 /* See if there is another frame sharing the same fontset. */
2071 FOR_EACH_FRAME (rest
, frame
)
2073 struct frame
*cf
= XFRAME (frame
);
2074 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
2075 && FRAME_X_DISPLAY_INFO (cf
) == FRAME_X_DISPLAY_INFO (f
)
2076 && FRAME_XIC_FONTSET (cf
) == FRAME_XIC_FONTSET (f
))
2084 /* The fontset is not used anymore. It is safe to free it. */
2085 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
2087 FRAME_XIC_FONTSET (f
) = NULL
;
2091 /* Value is the best input style, given user preferences USER (already
2092 checked to be supported by Emacs), and styles supported by the
2093 input method XIM. */
2096 best_xim_style (XIMStyles
*user
, XIMStyles
*xim
)
2100 for (i
= 0; i
< user
->count_styles
; ++i
)
2101 for (j
= 0; j
< xim
->count_styles
; ++j
)
2102 if (user
->supported_styles
[i
] == xim
->supported_styles
[j
])
2103 return user
->supported_styles
[i
];
2105 /* Return the default style. */
2106 return XIMPreeditNothing
| XIMStatusNothing
;
2109 /* Create XIC for frame F. */
2111 static XIMStyle xic_style
;
2114 create_frame_xic (struct frame
*f
)
2118 XFontSet xfs
= NULL
;
2123 /* Create X fontset. */
2124 xfs
= xic_create_xfontset (f
);
2125 xim
= FRAME_X_XIM (f
);
2130 XVaNestedList preedit_attr
;
2131 XVaNestedList status_attr
;
2133 s_area
.x
= 0; s_area
.y
= 0; s_area
.width
= 1; s_area
.height
= 1;
2134 spot
.x
= 0; spot
.y
= 1;
2136 /* Determine XIC style. */
2139 XIMStyles supported_list
;
2140 supported_list
.count_styles
= (sizeof supported_xim_styles
2141 / sizeof supported_xim_styles
[0]);
2142 supported_list
.supported_styles
= supported_xim_styles
;
2143 xic_style
= best_xim_style (&supported_list
,
2144 FRAME_X_XIM_STYLES (f
));
2147 preedit_attr
= XVaCreateNestedList (0,
2150 FRAME_FOREGROUND_PIXEL (f
),
2152 FRAME_BACKGROUND_PIXEL (f
),
2153 (xic_style
& XIMPreeditPosition
2158 status_attr
= XVaCreateNestedList (0,
2164 FRAME_FOREGROUND_PIXEL (f
),
2166 FRAME_BACKGROUND_PIXEL (f
),
2169 xic
= XCreateIC (xim
,
2170 XNInputStyle
, xic_style
,
2171 XNClientWindow
, FRAME_X_WINDOW (f
),
2172 XNFocusWindow
, FRAME_X_WINDOW (f
),
2173 XNStatusAttributes
, status_attr
,
2174 XNPreeditAttributes
, preedit_attr
,
2176 XFree (preedit_attr
);
2177 XFree (status_attr
);
2180 FRAME_XIC (f
) = xic
;
2181 FRAME_XIC_STYLE (f
) = xic_style
;
2182 FRAME_XIC_FONTSET (f
) = xfs
;
2186 /* Destroy XIC and free XIC fontset of frame F, if any. */
2189 free_frame_xic (struct frame
*f
)
2191 if (FRAME_XIC (f
) == NULL
)
2194 XDestroyIC (FRAME_XIC (f
));
2195 xic_free_xfontset (f
);
2197 FRAME_XIC (f
) = NULL
;
2201 /* Place preedit area for XIC of window W's frame to specified
2202 pixel position X/Y. X and Y are relative to window W. */
2205 xic_set_preeditarea (struct window
*w
, int x
, int y
)
2207 struct frame
*f
= XFRAME (w
->frame
);
2211 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
) + WINDOW_LEFT_FRINGE_WIDTH (w
);
2212 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
2213 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
2214 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2219 /* Place status area for XIC in bottom right corner of frame F.. */
2222 xic_set_statusarea (struct frame
*f
)
2224 XIC xic
= FRAME_XIC (f
);
2229 /* Negotiate geometry of status area. If input method has existing
2230 status area, use its current size. */
2231 area
.x
= area
.y
= area
.width
= area
.height
= 0;
2232 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
2233 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2236 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
2237 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2240 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
2242 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
2243 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2247 area
.width
= needed
->width
;
2248 area
.height
= needed
->height
;
2249 area
.x
= FRAME_PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
2250 area
.y
= (FRAME_PIXEL_HEIGHT (f
) - area
.height
2251 - FRAME_MENUBAR_HEIGHT (f
)
2252 - FRAME_TOOLBAR_TOP_HEIGHT (f
)
2253 - FRAME_INTERNAL_BORDER_WIDTH (f
));
2256 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
2257 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2262 /* Set X fontset for XIC of frame F, using base font name
2263 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2266 xic_set_xfontset (struct frame
*f
, const char *base_fontname
)
2271 xic_free_xfontset (f
);
2273 xfs
= xic_create_xfontset (f
);
2275 attr
= XVaCreateNestedList (0, XNFontSet
, xfs
, NULL
);
2276 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
2277 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2278 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
2279 XSetICValues (FRAME_XIC (f
), XNStatusAttributes
, attr
, NULL
);
2282 FRAME_XIC_FONTSET (f
) = xfs
;
2285 #endif /* HAVE_X_I18N */
2289 #ifdef USE_X_TOOLKIT
2291 /* Create and set up the X widget for frame F. */
2294 x_window (struct frame
*f
, long window_prompting
, int minibuffer_only
)
2296 XClassHint class_hints
;
2297 XSetWindowAttributes attributes
;
2298 unsigned long attribute_mask
;
2299 Widget shell_widget
;
2301 Widget frame_widget
;
2307 /* Use the resource name as the top-level widget name
2308 for looking up resources. Make a non-Lisp copy
2309 for the window manager, so GC relocation won't bother it.
2311 Elsewhere we specify the window name for the window manager. */
2312 f
->namebuf
= xstrdup (SSDATA (Vx_resource_name
));
2315 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2316 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2317 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2318 XtSetArg (al
[ac
], XtNborderWidth
, f
->border_width
); ac
++;
2319 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2320 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2321 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2322 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2323 applicationShellWidgetClass
,
2324 FRAME_X_DISPLAY (f
), al
, ac
);
2326 f
->output_data
.x
->widget
= shell_widget
;
2327 /* maybe_set_screen_title_format (shell_widget); */
2329 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2330 NULL
, shell_widget
, False
,
2331 NULL
, NULL
, NULL
, NULL
);
2334 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2335 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2336 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2337 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2338 XtSetValues (pane_widget
, al
, ac
);
2339 f
->output_data
.x
->column_widget
= pane_widget
;
2341 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2342 the emacs screen when changing menubar. This reduces flickering. */
2345 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2346 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2347 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2348 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2349 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2350 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2351 XtSetArg (al
[ac
], XtNdepth
, FRAME_X_DISPLAY_INFO (f
)->n_planes
); ac
++;
2352 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2353 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2354 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
2357 f
->output_data
.x
->edit_widget
= frame_widget
;
2359 XtManageChild (frame_widget
);
2361 /* Do some needed geometry management. */
2363 char *tem
, shell_position
[sizeof "=x++" + 4 * INT_STRLEN_BOUND (int)];
2366 int extra_borders
= 0;
2368 = (f
->output_data
.x
->menubar_widget
2369 ? (f
->output_data
.x
->menubar_widget
->core
.height
2370 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
2373 #if 0 /* Experimentally, we now get the right results
2374 for -geometry -0-0 without this. 24 Aug 96, rms. */
2375 if (FRAME_EXTERNAL_MENU_BAR (f
))
2378 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2379 menubar_size
+= ibw
;
2383 f
->output_data
.x
->menubar_height
= menubar_size
;
2386 /* Motif seems to need this amount added to the sizes
2387 specified for the shell widget. The Athena/Lucid widgets don't.
2388 Both conclusions reached experimentally. -- rms. */
2389 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
2390 &extra_borders
, NULL
);
2394 /* Convert our geometry parameters into a geometry string
2396 Note that we do not specify here whether the position
2397 is a user-specified or program-specified one.
2398 We pass that information later, in x_wm_set_size_hints. */
2400 int left
= f
->left_pos
;
2401 int xneg
= window_prompting
& XNegative
;
2402 int top
= f
->top_pos
;
2403 int yneg
= window_prompting
& YNegative
;
2409 if (window_prompting
& USPosition
)
2410 sprintf (shell_position
, "=%dx%d%c%d%c%d",
2411 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2412 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
2413 (xneg
? '-' : '+'), left
,
2414 (yneg
? '-' : '+'), top
);
2417 sprintf (shell_position
, "=%dx%d",
2418 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2419 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
2421 /* Setting x and y when the position is not specified in
2422 the geometry string will set program position in the WM hints.
2423 If Emacs had just one program position, we could set it in
2424 fallback resources, but since each make-frame call can specify
2425 different program positions, this is easier. */
2426 XtSetArg (gal
[gac
], XtNx
, left
); gac
++;
2427 XtSetArg (gal
[gac
], XtNy
, top
); gac
++;
2431 /* We don't free this because we don't know whether
2432 it is safe to free it while the frame exists.
2433 It isn't worth the trouble of arranging to free it
2434 when the frame is deleted. */
2435 tem
= xstrdup (shell_position
);
2436 XtSetArg (gal
[gac
], XtNgeometry
, tem
); gac
++;
2437 XtSetValues (shell_widget
, gal
, gac
);
2440 XtManageChild (pane_widget
);
2441 XtRealizeWidget (shell_widget
);
2443 if (FRAME_X_EMBEDDED_P (f
))
2444 XReparentWindow (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
),
2445 f
->output_data
.x
->parent_desc
, 0, 0);
2447 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2449 validate_x_resource_name ();
2451 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2452 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2453 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2456 FRAME_XIC (f
) = NULL
;
2458 create_frame_xic (f
);
2461 f
->output_data
.x
->wm_hints
.input
= True
;
2462 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2463 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2464 &f
->output_data
.x
->wm_hints
);
2466 hack_wm_protocols (f
, shell_widget
);
2469 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2472 /* Do a stupid property change to force the server to generate a
2473 PropertyNotify event so that the event_stream server timestamp will
2474 be initialized to something relevant to the time we created the window.
2476 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2477 FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2478 XA_ATOM
, 32, PropModeAppend
, NULL
, 0);
2480 /* Make all the standard events reach the Emacs frame. */
2481 attributes
.event_mask
= STANDARD_EVENT_SET
;
2486 /* XIM server might require some X events. */
2487 unsigned long fevent
= NoEventMask
;
2488 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2489 attributes
.event_mask
|= fevent
;
2491 #endif /* HAVE_X_I18N */
2493 attribute_mask
= CWEventMask
;
2494 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2495 attribute_mask
, &attributes
);
2497 XtMapWidget (frame_widget
);
2499 /* x_set_name normally ignores requests to set the name if the
2500 requested name is the same as the current name. This is the one
2501 place where that assumption isn't correct; f->name is set, but
2502 the X server hasn't been told. */
2505 int explicit = f
->explicit_name
;
2507 f
->explicit_name
= 0;
2509 fset_name (f
, Qnil
);
2510 x_set_name (f
, name
, explicit);
2513 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2514 f
->output_data
.x
->current_cursor
2515 = f
->output_data
.x
->text_cursor
);
2519 /* This is a no-op, except under Motif. Make sure main areas are
2520 set to something reasonable, in case we get an error later. */
2521 lw_set_main_areas (pane_widget
, 0, frame_widget
);
2524 #else /* not USE_X_TOOLKIT */
2527 x_window (struct frame
*f
)
2529 if (! xg_create_frame_widgets (f
))
2530 error ("Unable to create window");
2533 FRAME_XIC (f
) = NULL
;
2537 create_frame_xic (f
);
2540 /* XIM server might require some X events. */
2541 unsigned long fevent
= NoEventMask
;
2542 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2544 if (fevent
!= NoEventMask
)
2546 XSetWindowAttributes attributes
;
2547 XWindowAttributes wattr
;
2548 unsigned long attribute_mask
;
2550 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2552 attributes
.event_mask
= wattr
.your_event_mask
| fevent
;
2553 attribute_mask
= CWEventMask
;
2554 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2555 attribute_mask
, &attributes
);
2563 #else /*! USE_GTK */
2564 /* Create and set up the X window for frame F. */
2567 x_window (struct frame
*f
)
2569 XClassHint class_hints
;
2570 XSetWindowAttributes attributes
;
2571 unsigned long attribute_mask
;
2573 attributes
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2574 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
2575 attributes
.bit_gravity
= StaticGravity
;
2576 attributes
.backing_store
= NotUseful
;
2577 attributes
.save_under
= True
;
2578 attributes
.event_mask
= STANDARD_EVENT_SET
;
2579 attributes
.colormap
= FRAME_X_COLORMAP (f
);
2580 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
2585 = XCreateWindow (FRAME_X_DISPLAY (f
),
2586 f
->output_data
.x
->parent_desc
,
2589 FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
),
2591 CopyFromParent
, /* depth */
2592 InputOutput
, /* class */
2594 attribute_mask
, &attributes
);
2599 create_frame_xic (f
);
2602 /* XIM server might require some X events. */
2603 unsigned long fevent
= NoEventMask
;
2604 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2605 attributes
.event_mask
|= fevent
;
2606 attribute_mask
= CWEventMask
;
2607 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2608 attribute_mask
, &attributes
);
2611 #endif /* HAVE_X_I18N */
2613 validate_x_resource_name ();
2615 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2616 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2617 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2619 /* The menubar is part of the ordinary display;
2620 it does not count in addition to the height of the window. */
2621 f
->output_data
.x
->menubar_height
= 0;
2623 /* This indicates that we use the "Passive Input" input model.
2624 Unless we do this, we don't get the Focus{In,Out} events that we
2625 need to draw the cursor correctly. Accursed bureaucrats.
2626 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2628 f
->output_data
.x
->wm_hints
.input
= True
;
2629 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2630 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2631 &f
->output_data
.x
->wm_hints
);
2632 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
2634 /* Request "save yourself" and "delete window" commands from wm. */
2637 protocols
[0] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2638 protocols
[1] = FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2639 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2642 /* x_set_name normally ignores requests to set the name if the
2643 requested name is the same as the current name. This is the one
2644 place where that assumption isn't correct; f->name is set, but
2645 the X server hasn't been told. */
2648 int explicit = f
->explicit_name
;
2650 f
->explicit_name
= 0;
2652 fset_name (f
, Qnil
);
2653 x_set_name (f
, name
, explicit);
2656 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2657 f
->output_data
.x
->current_cursor
2658 = f
->output_data
.x
->text_cursor
);
2662 if (FRAME_X_WINDOW (f
) == 0)
2663 error ("Unable to create window");
2666 #endif /* not USE_GTK */
2667 #endif /* not USE_X_TOOLKIT */
2669 /* Verify that the icon position args for this window are valid. */
2672 x_icon_verify (struct frame
*f
, Lisp_Object parms
)
2674 Lisp_Object icon_x
, icon_y
;
2676 /* Set the position of the icon. Note that twm groups all
2677 icons in an icon window. */
2678 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2679 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2680 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2682 CHECK_NUMBER (icon_x
);
2683 CHECK_NUMBER (icon_y
);
2685 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2686 error ("Both left and top icon corners of icon must be specified");
2689 /* Handle the icon stuff for this window. Perhaps later we might
2690 want an x_set_icon_position which can be called interactively as
2694 x_icon (struct frame
*f
, Lisp_Object parms
)
2696 Lisp_Object icon_x
, icon_y
;
2698 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2701 /* Set the position of the icon. Note that twm groups all
2702 icons in an icon window. */
2703 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2704 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2705 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2707 CHECK_TYPE_RANGED_INTEGER (int, icon_x
);
2708 CHECK_TYPE_RANGED_INTEGER (int, icon_y
);
2710 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2711 error ("Both left and top icon corners of icon must be specified");
2715 if (! EQ (icon_x
, Qunbound
))
2716 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2718 #if 0 /* x_get_arg removes the visibility parameter as a side effect,
2719 but x_create_frame still needs it. */
2720 /* Start up iconic or window? */
2721 x_wm_set_window_state
2722 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
2728 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
2735 /* Make the GCs needed for this window, setting the
2736 background, border and mouse colors; also create the
2737 mouse cursor and the gray border tile. */
2740 x_make_gc (struct frame
*f
)
2742 XGCValues gc_values
;
2746 /* Create the GCs of this frame.
2747 Note that many default values are used. */
2749 gc_values
.foreground
= FRAME_FOREGROUND_PIXEL (f
);
2750 gc_values
.background
= FRAME_BACKGROUND_PIXEL (f
);
2751 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2752 f
->output_data
.x
->normal_gc
2753 = XCreateGC (FRAME_X_DISPLAY (f
),
2755 GCLineWidth
| GCForeground
| GCBackground
,
2758 /* Reverse video style. */
2759 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2760 gc_values
.background
= FRAME_FOREGROUND_PIXEL (f
);
2761 f
->output_data
.x
->reverse_gc
2762 = XCreateGC (FRAME_X_DISPLAY (f
),
2764 GCForeground
| GCBackground
| GCLineWidth
,
2767 /* Cursor has cursor-color background, background-color foreground. */
2768 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2769 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
2770 gc_values
.fill_style
= FillOpaqueStippled
;
2771 f
->output_data
.x
->cursor_gc
2772 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2773 (GCForeground
| GCBackground
2774 | GCFillStyle
| GCLineWidth
),
2777 /* Create the gray border tile used when the pointer is not in
2778 the frame. Since this depends on the frame's pixel values,
2779 this must be done on a per-frame basis. */
2780 f
->output_data
.x
->border_tile
2781 = (XCreatePixmapFromBitmapData
2782 (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
2783 gray_bits
, gray_width
, gray_height
,
2784 FRAME_FOREGROUND_PIXEL (f
),
2785 FRAME_BACKGROUND_PIXEL (f
),
2786 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
2792 /* Free what was allocated in x_make_gc. */
2795 x_free_gcs (struct frame
*f
)
2797 Display
*dpy
= FRAME_X_DISPLAY (f
);
2801 if (f
->output_data
.x
->normal_gc
)
2803 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
2804 f
->output_data
.x
->normal_gc
= 0;
2807 if (f
->output_data
.x
->reverse_gc
)
2809 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
2810 f
->output_data
.x
->reverse_gc
= 0;
2813 if (f
->output_data
.x
->cursor_gc
)
2815 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
2816 f
->output_data
.x
->cursor_gc
= 0;
2819 if (f
->output_data
.x
->border_tile
)
2821 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
2822 f
->output_data
.x
->border_tile
= 0;
2829 /* Handler for signals raised during x_create_frame and
2830 x_create_tip_frame. FRAME is the frame which is partially
2834 unwind_create_frame (Lisp_Object frame
)
2836 struct frame
*f
= XFRAME (frame
);
2838 /* If frame is already dead, nothing to do. This can happen if the
2839 display is disconnected after the frame has become official, but
2840 before x_create_frame removes the unwind protect. */
2841 if (!FRAME_LIVE_P (f
))
2844 /* If frame is ``official'', nothing to do. */
2845 if (NILP (Fmemq (frame
, Vframe_list
)))
2847 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2848 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2851 x_free_frame_resources (f
);
2854 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2855 /* Check that reference counts are indeed correct. */
2856 eassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
2857 eassert (dpyinfo
->terminal
->image_cache
->refcount
== image_cache_refcount
);
2866 do_unwind_create_frame (Lisp_Object frame
)
2868 unwind_create_frame (frame
);
2872 unwind_create_frame_1 (Lisp_Object val
)
2874 inhibit_lisp_code
= val
;
2878 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
2880 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
2881 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
2883 Lisp_Object font
= Qnil
;
2884 if (EQ (font_param
, Qunbound
))
2887 if (NILP (font_param
))
2889 /* System font should take precedence over X resources. We suggest this
2890 regardless of font-use-system-font because .emacs may not have been
2892 const char *system_font
= xsettings_get_system_font ();
2894 font
= font_open_by_name (f
, build_unibyte_string (system_font
));
2898 font
= !NILP (font_param
) ? font_param
2899 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
2901 if (! FONTP (font
) && ! STRINGP (font
))
2906 /* This will find the normal Xft font. */
2909 "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1",
2910 "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2911 "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2912 /* This was formerly the first thing tried, but it finds
2913 too many fonts and takes too long. */
2914 "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1",
2915 /* If those didn't work, look for something which will
2917 "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1",
2922 for (i
= 0; names
[i
]; i
++)
2924 font
= font_open_by_name (f
, build_unibyte_string (names
[i
]));
2929 error ("No suitable font was found");
2931 else if (!NILP (font_param
))
2933 /* Remember the explicit font parameter, so we can re-apply it after
2934 we've applied the `default' face settings. */
2935 x_set_frame_parameters (f
, list1 (Fcons (Qfont_param
, font_param
)));
2938 /* This call will make X resources override any system font setting. */
2939 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
2943 DEFUN ("x-wm-set-size-hint", Fx_wm_set_size_hint
, Sx_wm_set_size_hint
,
2945 doc
: /* Send the size hints for frame FRAME to the window manager.
2946 If FRAME is omitted or nil, use the selected frame.
2947 Signal error if FRAME is not an X frame. */)
2950 struct frame
*f
= decode_window_system_frame (frame
);
2953 x_wm_set_size_hint (f
, 0, 0);
2959 set_machine_and_pid_properties (struct frame
*f
)
2961 long pid
= (long) getpid ();
2963 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME. */
2964 XSetWMProperties (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), NULL
, NULL
,
2965 NULL
, 0, NULL
, NULL
, NULL
);
2966 XChangeProperty (FRAME_X_DISPLAY (f
),
2967 FRAME_OUTER_WINDOW (f
),
2968 XInternAtom (FRAME_X_DISPLAY (f
),
2971 XA_CARDINAL
, 32, PropModeReplace
,
2972 (unsigned char *) &pid
, 1);
2975 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
2977 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
2978 Return an Emacs frame object.
2979 PARMS is an alist of frame parameters.
2980 If the parameters specify that the frame should not have a minibuffer,
2981 and do not specify a specific minibuffer window to use,
2982 then `default-minibuffer-frame' must be a frame whose minibuffer can
2983 be shared by the new frame.
2985 This function is an internal primitive--use `make-frame' instead. */)
2989 Lisp_Object frame
, tem
;
2991 int minibuffer_only
= 0;
2992 long window_prompting
= 0;
2994 ptrdiff_t count
= SPECPDL_INDEX ();
2995 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
2996 Lisp_Object display
;
2997 struct x_display_info
*dpyinfo
= NULL
;
3001 parms
= Fcopy_alist (parms
);
3003 /* Use this general default value to start with
3004 until we know if this frame has a specified name. */
3005 Vx_resource_name
= Vinvocation_name
;
3007 display
= x_get_arg (dpyinfo
, parms
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
3008 if (EQ (display
, Qunbound
))
3009 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
3010 if (EQ (display
, Qunbound
))
3012 dpyinfo
= check_x_display_info (display
);
3013 kb
= dpyinfo
->terminal
->kboard
;
3015 if (!dpyinfo
->terminal
->name
)
3016 error ("Terminal is not live, can't create new frames on it");
3018 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
3020 && ! EQ (name
, Qunbound
)
3022 error ("Invalid frame name--not a string or nil");
3025 Vx_resource_name
= name
;
3027 /* See if parent window is specified. */
3028 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
3029 if (EQ (parent
, Qunbound
))
3031 if (! NILP (parent
))
3032 CHECK_NUMBER (parent
);
3034 /* make_frame_without_minibuffer can run Lisp code and garbage collect. */
3035 /* No need to protect DISPLAY because that's not used after passing
3036 it to make_frame_without_minibuffer. */
3038 GCPRO4 (parms
, parent
, name
, frame
);
3039 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
3041 if (EQ (tem
, Qnone
) || NILP (tem
))
3042 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
3043 else if (EQ (tem
, Qonly
))
3045 f
= make_minibuffer_frame ();
3046 minibuffer_only
= 1;
3048 else if (WINDOWP (tem
))
3049 f
= make_frame_without_minibuffer (tem
, kb
, display
);
3053 XSETFRAME (frame
, f
);
3055 f
->terminal
= dpyinfo
->terminal
;
3057 f
->output_method
= output_x_window
;
3058 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
3059 f
->output_data
.x
->icon_bitmap
= -1;
3060 FRAME_FONTSET (f
) = -1;
3061 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
3062 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
3063 #ifdef USE_TOOLKIT_SCROLL_BARS
3064 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
3065 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
3066 #endif /* USE_TOOLKIT_SCROLL_BARS */
3069 x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
3071 if (! STRINGP (f
->icon_name
))
3072 fset_icon_name (f
, Qnil
);
3074 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
3076 /* With FRAME_X_DISPLAY_INFO set up, this unwind-protect is safe. */
3077 record_unwind_protect (do_unwind_create_frame
, frame
);
3079 /* These colors will be set anyway later, but it's important
3080 to get the color reference counts right, so initialize them! */
3083 struct gcpro gcpro1
;
3085 /* Function x_decode_color can signal an error. Make
3086 sure to initialize color slots so that we won't try
3087 to free colors we haven't allocated. */
3088 FRAME_FOREGROUND_PIXEL (f
) = -1;
3089 FRAME_BACKGROUND_PIXEL (f
) = -1;
3090 f
->output_data
.x
->cursor_pixel
= -1;
3091 f
->output_data
.x
->cursor_foreground_pixel
= -1;
3092 f
->output_data
.x
->border_pixel
= -1;
3093 f
->output_data
.x
->mouse_pixel
= -1;
3095 black
= build_string ("black");
3097 FRAME_FOREGROUND_PIXEL (f
)
3098 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3099 FRAME_BACKGROUND_PIXEL (f
)
3100 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3101 f
->output_data
.x
->cursor_pixel
3102 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3103 f
->output_data
.x
->cursor_foreground_pixel
3104 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3105 f
->output_data
.x
->border_pixel
3106 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3107 f
->output_data
.x
->mouse_pixel
3108 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3112 /* Specify the parent under which to make this X window. */
3116 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
3117 f
->output_data
.x
->explicit_parent
= 1;
3121 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
3122 f
->output_data
.x
->explicit_parent
= 0;
3125 /* Set the name; the functions to which we pass f expect the name to
3127 if (EQ (name
, Qunbound
) || NILP (name
))
3129 fset_name (f
, build_string (dpyinfo
->x_id_name
));
3130 f
->explicit_name
= 0;
3134 fset_name (f
, name
);
3135 f
->explicit_name
= 1;
3136 /* use the frame's title when getting resources for this frame. */
3137 specbind (Qx_resource_name
, name
);
3140 #ifdef HAVE_FREETYPE
3142 register_font_driver (&xftfont_driver
, f
);
3143 #else /* not HAVE_XFT */
3144 register_font_driver (&ftxfont_driver
, f
);
3145 #endif /* not HAVE_XFT */
3146 #endif /* HAVE_FREETYPE */
3147 register_font_driver (&xfont_driver
, f
);
3149 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
3150 "fontBackend", "FontBackend", RES_TYPE_STRING
);
3152 /* Extract the window parameters from the supplied values
3153 that are needed to determine window geometry. */
3154 x_default_font_parameter (f
, parms
);
3155 if (!FRAME_FONT (f
))
3157 delete_frame (frame
, Qnoelisp
);
3158 error ("Invalid frame font");
3161 /* Frame contents get displaced if an embedded X window has a border. */
3162 if (! FRAME_X_EMBEDDED_P (f
))
3163 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
3164 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
3166 /* This defaults to 1 in order to match xterm. We recognize either
3167 internalBorderWidth or internalBorder (which is what xterm calls
3169 if (NILP (Fassq (Qinternal_border_width
, parms
)))
3173 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
3174 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
3175 if (! EQ (value
, Qunbound
))
3176 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
3179 x_default_parameter (f
, parms
, Qinternal_border_width
,
3180 #ifdef USE_GTK /* We used to impose 0 in xg_create_frame_widgets. */
3185 "internalBorderWidth", "internalBorderWidth",
3187 x_default_parameter (f
, parms
, Qvertical_scroll_bars
,
3188 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
3193 "verticalScrollBars", "ScrollBars",
3196 /* Also do the stuff which must be set before the window exists. */
3197 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3198 "foreground", "Foreground", RES_TYPE_STRING
);
3199 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3200 "background", "Background", RES_TYPE_STRING
);
3201 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3202 "pointerColor", "Foreground", RES_TYPE_STRING
);
3203 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3204 "borderColor", "BorderColor", RES_TYPE_STRING
);
3205 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3206 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3207 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3208 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3209 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3210 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3211 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3212 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3214 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3215 "scrollBarForeground",
3216 "ScrollBarForeground", 1);
3217 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3218 "scrollBarBackground",
3219 "ScrollBarBackground", 0);
3222 image_cache_refcount
=
3223 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
3224 dpyinfo_refcount
= dpyinfo
->reference_count
;
3225 #endif /* GLYPH_DEBUG */
3227 /* Init faces before x_default_parameter is called for scroll-bar
3228 parameters because that function calls x_set_scroll_bar_width,
3229 which calls change_frame_size, which calls Fset_window_buffer,
3230 which runs hooks, which call Fvertical_motion. At the end, we
3231 end up in init_iterator with a null face cache, which should not
3233 init_frame_faces (f
);
3235 /* Set the menu-bar-lines and tool-bar-lines parameters. We don't
3236 look up the X resources controlling the menu-bar and tool-bar
3237 here; they are processed specially at startup, and reflected in
3238 the values of the mode variables.
3240 Avoid calling window-configuration-change-hook; otherwise we
3241 could get an infloop in next_frame since the frame is not yet in
3244 ptrdiff_t count2
= SPECPDL_INDEX ();
3245 record_unwind_protect (unwind_create_frame_1
, inhibit_lisp_code
);
3246 inhibit_lisp_code
= Qt
;
3248 x_default_parameter (f
, parms
, Qmenu_bar_lines
,
3249 NILP (Vmenu_bar_mode
)
3250 ? make_number (0) : make_number (1),
3251 NULL
, NULL
, RES_TYPE_NUMBER
);
3252 x_default_parameter (f
, parms
, Qtool_bar_lines
,
3253 NILP (Vtool_bar_mode
)
3254 ? make_number (0) : make_number (1),
3255 NULL
, NULL
, RES_TYPE_NUMBER
);
3257 unbind_to (count2
, Qnil
);
3260 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3261 "bufferPredicate", "BufferPredicate",
3263 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3264 "title", "Title", RES_TYPE_STRING
);
3265 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3266 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3267 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3268 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3269 x_default_parameter (f
, parms
, Qtool_bar_position
,
3270 f
->tool_bar_position
, 0, 0, RES_TYPE_SYMBOL
);
3272 /* Compute the size of the X window. */
3273 window_prompting
= x_figure_window_size (f
, parms
, 1);
3275 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3276 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3278 x_icon_verify (f
, parms
);
3280 /* Create the X widget or window. */
3281 #ifdef USE_X_TOOLKIT
3282 x_window (f
, window_prompting
, minibuffer_only
);
3290 /* Now consider the frame official. */
3291 f
->terminal
->reference_count
++;
3292 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
3293 Vframe_list
= Fcons (frame
, Vframe_list
);
3295 /* We need to do this after creating the X window, so that the
3296 icon-creation functions can say whose icon they're describing. */
3297 x_default_parameter (f
, parms
, Qicon_type
, Qt
,
3298 "bitmapIcon", "BitmapIcon", RES_TYPE_BOOLEAN
);
3300 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3301 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3302 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3303 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3304 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3305 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3306 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3307 "scrollBarWidth", "ScrollBarWidth",
3309 x_default_parameter (f
, parms
, Qalpha
, Qnil
,
3310 "alpha", "Alpha", RES_TYPE_NUMBER
);
3312 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
3313 Change will not be effected unless different from the current
3315 width
= FRAME_COLS (f
);
3316 height
= FRAME_LINES (f
);
3318 SET_FRAME_COLS (f
, 0);
3319 FRAME_LINES (f
) = 0;
3320 change_frame_size (f
, height
, width
, 1, 0, 0);
3322 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3323 /* Create the menu bar. */
3324 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3326 /* If this signals an error, we haven't set size hints for the
3327 frame and we didn't make it visible. */
3328 initialize_frame_menubar (f
);
3331 /* This is a no-op, except under Motif where it arranges the
3332 main window for the widgets on it. */
3333 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3334 f
->output_data
.x
->menubar_widget
,
3335 f
->output_data
.x
->edit_widget
);
3336 #endif /* not USE_GTK */
3338 #endif /* USE_X_TOOLKIT || USE_GTK */
3340 /* Tell the server what size and position, etc, we want, and how
3341 badly we want them. This should be done after we have the menu
3342 bar so that its size can be taken into account. */
3344 x_wm_set_size_hint (f
, window_prompting
, 0);
3347 /* Make the window appear on the frame and enable display, unless
3348 the caller says not to. However, with explicit parent, Emacs
3349 cannot control visibility, so don't try. */
3350 if (! f
->output_data
.x
->explicit_parent
)
3352 Lisp_Object visibility
;
3354 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3356 if (EQ (visibility
, Qunbound
))
3359 if (EQ (visibility
, Qicon
))
3360 x_iconify_frame (f
);
3361 else if (! NILP (visibility
))
3362 x_make_frame_visible (f
);
3365 /* Must have been Qnil. */
3371 /* Set machine name and pid for the purpose of window managers. */
3372 set_machine_and_pid_properties (f
);
3374 /* Set the WM leader property. GTK does this itself, so this is not
3375 needed when using GTK. */
3376 if (dpyinfo
->client_leader_window
!= 0)
3378 XChangeProperty (FRAME_X_DISPLAY (f
),
3379 FRAME_OUTER_WINDOW (f
),
3380 dpyinfo
->Xatom_wm_client_leader
,
3381 XA_WINDOW
, 32, PropModeReplace
,
3382 (unsigned char *) &dpyinfo
->client_leader_window
, 1);
3387 /* Initialize `default-minibuffer-frame' in case this is the first
3388 frame on this terminal. */
3389 if (FRAME_HAS_MINIBUF_P (f
)
3390 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
3391 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
3392 kset_default_minibuffer_frame (kb
, frame
);
3394 /* All remaining specified parameters, which have not been "used"
3395 by x_get_arg and friends, now go in the misc. alist of the frame. */
3396 for (tem
= parms
; CONSP (tem
); tem
= XCDR (tem
))
3397 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
3398 fset_param_alist (f
, Fcons (XCAR (tem
), f
->param_alist
));
3402 /* Make sure windows on this frame appear in calls to next-window
3403 and similar functions. */
3404 Vwindow_list
= Qnil
;
3406 return unbind_to (count
, frame
);
3410 /* FRAME is used only to get a handle on the X display. We don't pass the
3411 display info directly because we're called from frame.c, which doesn't
3412 know about that structure. */
3415 x_get_focus_frame (struct frame
*frame
)
3417 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (frame
);
3419 if (! dpyinfo
->x_focus_frame
)
3422 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3427 /* In certain situations, when the window manager follows a
3428 click-to-focus policy, there seems to be no way around calling
3429 XSetInputFocus to give another frame the input focus .
3431 In an ideal world, XSetInputFocus should generally be avoided so
3432 that applications don't interfere with the window manager's focus
3433 policy. But I think it's okay to use when it's clearly done
3434 following a user-command. */
3436 DEFUN ("x-focus-frame", Fx_focus_frame
, Sx_focus_frame
, 1, 1, 0,
3437 doc
: /* Set the input focus to FRAME.
3438 FRAME nil means use the selected frame. */)
3441 struct frame
*f
= decode_window_system_frame (frame
);
3442 Display
*dpy
= FRAME_X_DISPLAY (f
);
3445 x_catch_errors (dpy
);
3447 if (FRAME_X_EMBEDDED_P (f
))
3449 /* For Xembedded frames, normally the embedder forwards key
3450 events. See XEmbed Protocol Specification at
3451 http://freedesktop.org/wiki/Specifications/xembed-spec */
3452 xembed_request_focus (f
);
3456 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3457 RevertToParent
, CurrentTime
);
3458 x_ewmh_activate_frame (f
);
3461 x_uncatch_errors ();
3468 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
3469 doc
: /* Internal function called by `color-defined-p', which see
3470 .\(Note that the Nextstep version of this function ignores FRAME.) */)
3471 (Lisp_Object color
, Lisp_Object frame
)
3474 struct frame
*f
= decode_window_system_frame (frame
);
3476 CHECK_STRING (color
);
3478 if (x_defined_color (f
, SSDATA (color
), &foo
, 0))
3484 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
3485 doc
: /* Internal function called by `color-values', which see. */)
3486 (Lisp_Object color
, Lisp_Object frame
)
3489 struct frame
*f
= decode_window_system_frame (frame
);
3491 CHECK_STRING (color
);
3493 if (x_defined_color (f
, SSDATA (color
), &foo
, 0))
3494 return list3i (foo
.red
, foo
.green
, foo
.blue
);
3499 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
3500 doc
: /* Internal function called by `display-color-p', which see. */)
3501 (Lisp_Object terminal
)
3503 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3505 if (dpyinfo
->n_planes
<= 2)
3508 switch (dpyinfo
->visual
->class)
3521 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3523 doc
: /* Return t if the X display supports shades of gray.
3524 Note that color displays do support shades of gray.
3525 The optional argument TERMINAL specifies which display to ask about.
3526 TERMINAL should be a terminal object, a frame or a display name (a string).
3527 If omitted or nil, that stands for the selected frame's display. */)
3528 (Lisp_Object terminal
)
3530 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3532 if (dpyinfo
->n_planes
<= 1)
3535 switch (dpyinfo
->visual
->class)
3550 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3552 doc
: /* Return the width in pixels of the X display TERMINAL.
3553 The optional argument TERMINAL specifies which display to ask about.
3554 TERMINAL should be a terminal object, a frame or a display name (a string).
3555 If omitted or nil, that stands for the selected frame's display.
3557 On \"multi-monitor\" setups this refers to the pixel width for all
3558 physical monitors associated with TERMINAL. To get information for
3559 each physical monitor, use `display-monitor-attributes-list'. */)
3560 (Lisp_Object terminal
)
3562 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3564 return make_number (x_display_pixel_width (dpyinfo
));
3567 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3568 Sx_display_pixel_height
, 0, 1, 0,
3569 doc
: /* Return the height in pixels 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 pixel height for all
3575 physical monitors associated with TERMINAL. To get information for
3576 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 (x_display_pixel_height (dpyinfo
));
3584 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3586 doc
: /* Return the number of bitplanes of the X display TERMINAL.
3587 The optional argument TERMINAL specifies which display to ask about.
3588 TERMINAL should be a terminal object, a frame or a display name (a string).
3589 If omitted or nil, that stands for the selected frame's display. */)
3590 (Lisp_Object terminal
)
3592 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3594 return make_number (dpyinfo
->n_planes
);
3597 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3599 doc
: /* Return the number of color cells of the X display TERMINAL.
3600 The optional argument TERMINAL specifies which display to ask about.
3601 TERMINAL should be a terminal object, a frame or a display name (a string).
3602 If omitted or nil, that stands for the selected frame's display. */)
3603 (Lisp_Object terminal
)
3605 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3607 int nr_planes
= DisplayPlanes (dpyinfo
->display
,
3608 XScreenNumberOfScreen (dpyinfo
->screen
));
3610 /* Truncate nr_planes to 24 to avoid integer overflow.
3611 Some displays says 32, but only 24 bits are actually significant.
3612 There are only very few and rare video cards that have more than
3613 24 significant bits. Also 24 bits is more than 16 million colors,
3614 it "should be enough for everyone". */
3615 if (nr_planes
> 24) nr_planes
= 24;
3617 return make_number (1 << nr_planes
);
3620 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3621 Sx_server_max_request_size
,
3623 doc
: /* Return the maximum request size of the X server of display TERMINAL.
3624 The optional argument TERMINAL specifies which display to ask about.
3625 TERMINAL should be a terminal object, a frame or a display name (a string).
3626 If omitted or nil, that stands for the selected frame's display. */)
3627 (Lisp_Object terminal
)
3629 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3631 return make_number (MAXREQUEST (dpyinfo
->display
));
3634 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3635 doc
: /* Return the "vendor ID" string of the X server of display TERMINAL.
3636 \(Labeling every distributor as a "vendor" embodies the false assumption
3637 that operating systems cannot be developed and distributed noncommercially.)
3638 The optional argument TERMINAL specifies which display to ask about.
3639 TERMINAL should be a terminal object, a frame or a display name (a string).
3640 If omitted or nil, that stands for the selected frame's display. */)
3641 (Lisp_Object terminal
)
3643 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3644 const char *vendor
= ServerVendor (dpyinfo
->display
);
3646 if (! vendor
) vendor
= "";
3647 return build_string (vendor
);
3650 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3651 doc
: /* Return the version numbers of the X server of display TERMINAL.
3652 The value is a list of three integers: the major and minor
3653 version numbers of the X Protocol in use, and the distributor-specific release
3654 number. See also the function `x-server-vendor'.
3656 The optional argument TERMINAL specifies which display to ask about.
3657 TERMINAL should be a terminal object, a frame or a display name (a string).
3658 If omitted or nil, that stands for the selected frame's display. */)
3659 (Lisp_Object terminal
)
3661 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3662 Display
*dpy
= dpyinfo
->display
;
3664 return list3i (ProtocolVersion (dpy
), ProtocolRevision (dpy
),
3665 VendorRelease (dpy
));
3668 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3669 doc
: /* Return the number of screens on the X server of display TERMINAL.
3670 The optional argument TERMINAL specifies which display to ask about.
3671 TERMINAL should be a terminal object, a frame or a display name (a string).
3672 If omitted or nil, that stands for the selected frame's display. */)
3673 (Lisp_Object terminal
)
3675 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3677 return make_number (ScreenCount (dpyinfo
->display
));
3680 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3681 doc
: /* Return the height in millimeters of the X display TERMINAL.
3682 The optional argument TERMINAL specifies which display to ask about.
3683 TERMINAL should be a terminal object, a frame or a display name (a string).
3684 If omitted or nil, that stands for the selected frame's display.
3686 On \"multi-monitor\" setups this refers to the height in millimeters for
3687 all physical monitors associated with TERMINAL. To get information
3688 for each physical monitor, use `display-monitor-attributes-list'. */)
3689 (Lisp_Object terminal
)
3691 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3693 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3696 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3697 doc
: /* Return the width in millimeters of the X display TERMINAL.
3698 The optional argument TERMINAL specifies which display to ask about.
3699 TERMINAL should be a terminal object, a frame or a display name (a string).
3700 If omitted or nil, that stands for the selected frame's display.
3702 On \"multi-monitor\" setups this refers to the width in millimeters for
3703 all physical monitors associated with TERMINAL. To get information
3704 for each physical monitor, use `display-monitor-attributes-list'. */)
3705 (Lisp_Object terminal
)
3707 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3709 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3712 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3713 Sx_display_backing_store
, 0, 1, 0,
3714 doc
: /* Return an indication of whether X display TERMINAL does backing store.
3715 The value may be `always', `when-mapped', or `not-useful'.
3716 The optional argument TERMINAL specifies which display to ask about.
3717 TERMINAL should be a terminal object, a frame or a display name (a string).
3718 If omitted or nil, that stands for the selected frame's display. */)
3719 (Lisp_Object terminal
)
3721 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3724 switch (DoesBackingStore (dpyinfo
->screen
))
3727 result
= intern ("always");
3731 result
= intern ("when-mapped");
3735 result
= intern ("not-useful");
3739 error ("Strange value for BackingStore parameter of screen");
3745 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3746 Sx_display_visual_class
, 0, 1, 0,
3747 doc
: /* Return the visual class of the X display TERMINAL.
3748 The value is one of the symbols `static-gray', `gray-scale',
3749 `static-color', `pseudo-color', `true-color', or `direct-color'.
3751 The optional argument TERMINAL specifies which display to ask about.
3752 TERMINAL should a terminal object, a frame or a display name (a string).
3753 If omitted or nil, that stands for the selected frame's display. */)
3754 (Lisp_Object terminal
)
3756 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3759 switch (dpyinfo
->visual
->class)
3762 result
= intern ("static-gray");
3765 result
= intern ("gray-scale");
3768 result
= intern ("static-color");
3771 result
= intern ("pseudo-color");
3774 result
= intern ("true-color");
3777 result
= intern ("direct-color");
3780 error ("Display has an unknown visual class");
3786 DEFUN ("x-display-save-under", Fx_display_save_under
,
3787 Sx_display_save_under
, 0, 1, 0,
3788 doc
: /* Return t if the X display TERMINAL supports the save-under feature.
3789 The optional argument TERMINAL specifies which display to ask about.
3790 TERMINAL should be a terminal object, a frame or a display name (a string).
3791 If omitted or nil, that stands for the selected frame's display. */)
3792 (Lisp_Object terminal
)
3794 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3796 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3802 /* Store the geometry of the workarea on display DPYINFO into *RECT.
3803 Return false if and only if the workarea information cannot be
3804 obtained via the _NET_WORKAREA root window property. */
3806 #if ! GTK_CHECK_VERSION (3, 4, 0)
3808 x_get_net_workarea (struct x_display_info
*dpyinfo
, XRectangle
*rect
)
3810 Display
*dpy
= dpyinfo
->display
;
3811 long offset
, max_len
;
3812 Atom target_type
, actual_type
;
3813 unsigned long actual_size
, bytes_remaining
;
3814 int rc
, actual_format
;
3815 unsigned char *tmp_data
= NULL
;
3816 bool result
= false;
3818 x_catch_errors (dpy
);
3821 target_type
= XA_CARDINAL
;
3822 rc
= XGetWindowProperty (dpy
, dpyinfo
->root_window
,
3823 dpyinfo
->Xatom_net_current_desktop
,
3824 offset
, max_len
, False
, target_type
,
3825 &actual_type
, &actual_format
, &actual_size
,
3826 &bytes_remaining
, &tmp_data
);
3827 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
3828 && actual_format
== 32 && actual_size
== max_len
)
3830 long current_desktop
= ((long *) tmp_data
)[0];
3835 offset
= 4 * current_desktop
;
3837 rc
= XGetWindowProperty (dpy
, dpyinfo
->root_window
,
3838 dpyinfo
->Xatom_net_workarea
,
3839 offset
, max_len
, False
, target_type
,
3840 &actual_type
, &actual_format
, &actual_size
,
3841 &bytes_remaining
, &tmp_data
);
3842 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
3843 && actual_format
== 32 && actual_size
== max_len
)
3845 long *values
= (long *) tmp_data
;
3847 rect
->x
= values
[0];
3848 rect
->y
= values
[1];
3849 rect
->width
= values
[2];
3850 rect
->height
= values
[3];
3860 x_uncatch_errors ();
3868 /* Return monitor number where F is "most" or closest to. */
3870 x_get_monitor_for_frame (struct frame
*f
,
3871 struct MonitorInfo
*monitors
,
3875 int area
= 0, dist
= -1;
3876 int best_area
= -1, best_dist
= -1;
3879 if (n_monitors
== 1) return 0;
3880 frect
.x
= f
->left_pos
;
3881 frect
.y
= f
->top_pos
;
3882 frect
.width
= FRAME_PIXEL_WIDTH (f
);
3883 frect
.height
= FRAME_PIXEL_HEIGHT (f
);
3885 for (i
= 0; i
< n_monitors
; ++i
)
3887 struct MonitorInfo
*mi
= &monitors
[i
];
3891 if (mi
->geom
.width
== 0) continue;
3893 if (x_intersect_rectangles (&mi
->geom
, &frect
, &res
))
3895 a
= res
.width
* res
.height
;
3903 if (a
== 0 && area
== 0)
3906 if (frect
.x
+ frect
.width
< mi
->geom
.x
)
3907 dx
= mi
->geom
.x
- frect
.x
+ frect
.width
;
3908 else if (frect
.x
> mi
->geom
.x
+ mi
->geom
.width
)
3909 dx
= frect
.x
- mi
->geom
.x
+ mi
->geom
.width
;
3912 if (frect
.y
+ frect
.height
< mi
->geom
.y
)
3913 dy
= mi
->geom
.y
- frect
.y
+ frect
.height
;
3914 else if (frect
.y
> mi
->geom
.y
+ mi
->geom
.height
)
3915 dy
= frect
.y
- mi
->geom
.y
+ mi
->geom
.height
;
3920 if (dist
== -1 || dist
> d
)
3928 return best_area
!= -1 ? best_area
: (best_dist
!= -1 ? best_dist
: 0);
3932 x_make_monitor_attribute_list (struct MonitorInfo
*monitors
,
3934 int primary_monitor
,
3935 struct x_display_info
*dpyinfo
,
3938 Lisp_Object monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
3939 Lisp_Object frame
, rest
;
3941 FOR_EACH_FRAME (rest
, frame
)
3943 struct frame
*f
= XFRAME (frame
);
3945 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
3946 && !EQ (frame
, tip_frame
))
3948 int i
= x_get_monitor_for_frame (f
, monitors
, n_monitors
);
3949 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
3953 return make_monitor_attribute_list (monitors
, n_monitors
, primary_monitor
,
3954 monitor_frames
, source
);
3958 x_get_monitor_attributes_fallback (struct x_display_info
*dpyinfo
)
3960 struct MonitorInfo monitor
;
3961 XRectangle workarea_r
;
3963 /* Fallback: treat (possibly) multiple physical monitors as if they
3964 formed a single monitor as a whole. This should provide a
3965 consistent result at least on single monitor environments. */
3966 monitor
.geom
.x
= monitor
.geom
.y
= 0;
3967 monitor
.geom
.width
= x_display_pixel_width (dpyinfo
);
3968 monitor
.geom
.height
= x_display_pixel_height (dpyinfo
);
3969 monitor
.mm_width
= WidthMMOfScreen (dpyinfo
->screen
);
3970 monitor
.mm_height
= HeightMMOfScreen (dpyinfo
->screen
);
3971 monitor
.name
= xstrdup ("combined screen");
3973 if (x_get_net_workarea (dpyinfo
, &workarea_r
))
3974 monitor
.work
= workarea_r
;
3976 monitor
.work
= monitor
.geom
;
3977 return x_make_monitor_attribute_list (&monitor
, 1, 0, dpyinfo
, "fallback");
3981 #ifdef HAVE_XINERAMA
3983 x_get_monitor_attributes_xinerama (struct x_display_info
*dpyinfo
)
3986 Lisp_Object attributes_list
= Qnil
;
3987 Display
*dpy
= dpyinfo
->display
;
3988 XineramaScreenInfo
*info
= XineramaQueryScreens (dpy
, &n_monitors
);
3989 struct MonitorInfo
*monitors
;
3990 double mm_width_per_pixel
, mm_height_per_pixel
;
3992 if (! info
|| n_monitors
== 0)
3996 return attributes_list
;
3999 mm_width_per_pixel
= ((double) WidthMMOfScreen (dpyinfo
->screen
)
4000 / x_display_pixel_width (dpyinfo
));
4001 mm_height_per_pixel
= ((double) HeightMMOfScreen (dpyinfo
->screen
)
4002 / x_display_pixel_height (dpyinfo
));
4003 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
4004 for (i
= 0; i
< n_monitors
; ++i
)
4006 struct MonitorInfo
*mi
= &monitors
[i
];
4007 XRectangle workarea_r
;
4009 mi
->geom
.x
= info
[i
].x_org
;
4010 mi
->geom
.y
= info
[i
].y_org
;
4011 mi
->geom
.width
= info
[i
].width
;
4012 mi
->geom
.height
= info
[i
].height
;
4013 mi
->mm_width
= mi
->geom
.width
* mm_width_per_pixel
+ 0.5;
4014 mi
->mm_height
= mi
->geom
.height
* mm_height_per_pixel
+ 0.5;
4017 /* Xinerama usually have primary monitor first, just use that. */
4018 if (i
== 0 && x_get_net_workarea (dpyinfo
, &workarea_r
))
4020 mi
->work
= workarea_r
;
4021 if (! x_intersect_rectangles (&mi
->geom
, &mi
->work
, &mi
->work
))
4022 mi
->work
= mi
->geom
;
4025 mi
->work
= mi
->geom
;
4029 attributes_list
= x_make_monitor_attribute_list (monitors
,
4034 free_monitors (monitors
, n_monitors
);
4035 return attributes_list
;
4037 #endif /* HAVE_XINERAMA */
4042 x_get_monitor_attributes_xrandr (struct x_display_info
*dpyinfo
)
4044 Lisp_Object attributes_list
= Qnil
;
4045 XRRScreenResources
*resources
;
4046 Display
*dpy
= dpyinfo
->display
;
4047 int i
, n_monitors
, primary
= -1;
4048 RROutput pxid
= None
;
4049 struct MonitorInfo
*monitors
;
4051 #ifdef HAVE_XRRGETSCREENRESOURCESCURRENT
4052 resources
= XRRGetScreenResourcesCurrent (dpy
, dpyinfo
->root_window
);
4054 resources
= XRRGetScreenResources (dpy
, dpyinfo
->root_window
);
4056 if (! resources
|| resources
->noutput
== 0)
4059 XRRFreeScreenResources (resources
);
4062 n_monitors
= resources
->noutput
;
4063 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
4065 #ifdef HAVE_XRRGETOUTPUTPRIMARY
4066 pxid
= XRRGetOutputPrimary (dpy
, dpyinfo
->root_window
);
4069 for (i
= 0; i
< n_monitors
; ++i
)
4071 XRROutputInfo
*info
= XRRGetOutputInfo (dpy
, resources
,
4072 resources
->outputs
[i
]);
4073 Connection conn
= info
? info
->connection
: RR_Disconnected
;
4074 RRCrtc id
= info
? info
->crtc
: None
;
4076 if (strcmp (info
->name
, "default") == 0)
4078 /* Non XRandr 1.2 driver, does not give useful data. */
4079 XRRFreeOutputInfo (info
);
4080 XRRFreeScreenResources (resources
);
4081 free_monitors (monitors
, n_monitors
);
4085 if (conn
!= RR_Disconnected
&& id
!= None
)
4087 XRRCrtcInfo
*crtc
= XRRGetCrtcInfo (dpy
, resources
, id
);
4088 struct MonitorInfo
*mi
= &monitors
[i
];
4089 XRectangle workarea_r
;
4093 XRRFreeOutputInfo (info
);
4097 mi
->geom
.x
= crtc
->x
;
4098 mi
->geom
.y
= crtc
->y
;
4099 mi
->geom
.width
= crtc
->width
;
4100 mi
->geom
.height
= crtc
->height
;
4101 mi
->mm_width
= info
->mm_width
;
4102 mi
->mm_height
= info
->mm_height
;
4103 mi
->name
= xstrdup (info
->name
);
4105 if (pxid
!= None
&& pxid
== resources
->outputs
[i
])
4107 else if (primary
== -1 && strcmp (info
->name
, "LVDS") == 0)
4110 if (i
== primary
&& x_get_net_workarea (dpyinfo
, &workarea_r
))
4112 mi
->work
= workarea_r
;
4113 if (! x_intersect_rectangles (&mi
->geom
, &mi
->work
, &mi
->work
))
4114 mi
->work
= mi
->geom
;
4117 mi
->work
= mi
->geom
;
4119 XRRFreeCrtcInfo (crtc
);
4121 XRRFreeOutputInfo (info
);
4123 XRRFreeScreenResources (resources
);
4125 attributes_list
= x_make_monitor_attribute_list (monitors
,
4130 free_monitors (monitors
, n_monitors
);
4131 return attributes_list
;
4133 #endif /* HAVE_XRANDR */
4136 x_get_monitor_attributes (struct x_display_info
*dpyinfo
)
4138 Lisp_Object attributes_list
= Qnil
;
4139 Display
*dpy
= dpyinfo
->display
;
4142 int xrr_event_base
, xrr_error_base
;
4143 bool xrr_ok
= false;
4144 xrr_ok
= XRRQueryExtension (dpy
, &xrr_event_base
, &xrr_error_base
);
4147 int xrr_major
, xrr_minor
;
4148 XRRQueryVersion (dpy
, &xrr_major
, &xrr_minor
);
4149 xrr_ok
= (xrr_major
== 1 && xrr_minor
>= 2) || xrr_major
> 1;
4153 attributes_list
= x_get_monitor_attributes_xrandr (dpyinfo
);
4154 #endif /* HAVE_XRANDR */
4156 #ifdef HAVE_XINERAMA
4157 if (NILP (attributes_list
))
4159 int xin_event_base
, xin_error_base
;
4160 bool xin_ok
= false;
4161 xin_ok
= XineramaQueryExtension (dpy
, &xin_event_base
, &xin_error_base
);
4162 if (xin_ok
&& XineramaIsActive (dpy
))
4163 attributes_list
= x_get_monitor_attributes_xinerama (dpyinfo
);
4165 #endif /* HAVE_XINERAMA */
4167 if (NILP (attributes_list
))
4168 attributes_list
= x_get_monitor_attributes_fallback (dpyinfo
);
4170 return attributes_list
;
4173 #endif /* !USE_GTK */
4175 DEFUN ("x-display-monitor-attributes-list", Fx_display_monitor_attributes_list
,
4176 Sx_display_monitor_attributes_list
,
4178 doc
: /* Return a list of physical monitor attributes on the X display TERMINAL.
4180 The optional argument TERMINAL specifies which display to ask about.
4181 TERMINAL should be a terminal object, a frame or a display name (a string).
4182 If omitted or nil, that stands for the selected frame's display.
4184 In addition to the standard attribute keys listed in
4185 `display-monitor-attributes-list', the following keys are contained in
4188 source -- String describing the source from which multi-monitor
4189 information is obtained, one of \"Gdk\", \"XRandr\",
4190 \"Xinerama\", or \"fallback\"
4192 Internal use only, use `display-monitor-attributes-list' instead. */)
4193 (Lisp_Object terminal
)
4195 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4196 Lisp_Object attributes_list
= Qnil
;
4199 double mm_width_per_pixel
, mm_height_per_pixel
;
4202 gint primary_monitor
= 0, n_monitors
, i
;
4203 Lisp_Object monitor_frames
, rest
, frame
;
4204 static const char *source
= "Gdk";
4205 struct MonitorInfo
*monitors
;
4208 mm_width_per_pixel
= ((double) WidthMMOfScreen (dpyinfo
->screen
)
4209 / x_display_pixel_width (dpyinfo
));
4210 mm_height_per_pixel
= ((double) HeightMMOfScreen (dpyinfo
->screen
)
4211 / x_display_pixel_height (dpyinfo
));
4212 gdpy
= gdk_x11_lookup_xdisplay (dpyinfo
->display
);
4213 gscreen
= gdk_display_get_default_screen (gdpy
);
4214 #if GTK_CHECK_VERSION (2, 20, 0)
4215 primary_monitor
= gdk_screen_get_primary_monitor (gscreen
);
4217 n_monitors
= gdk_screen_get_n_monitors (gscreen
);
4218 monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
4219 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
4221 FOR_EACH_FRAME (rest
, frame
)
4223 struct frame
*f
= XFRAME (frame
);
4225 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
4226 && !EQ (frame
, tip_frame
))
4228 GdkWindow
*gwin
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
4230 i
= gdk_screen_get_monitor_at_window (gscreen
, gwin
);
4231 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
4235 for (i
= 0; i
< n_monitors
; ++i
)
4237 gint width_mm
= -1, height_mm
= -1;
4238 GdkRectangle rec
, work
;
4239 struct MonitorInfo
*mi
= &monitors
[i
];
4241 gdk_screen_get_monitor_geometry (gscreen
, i
, &rec
);
4243 #if GTK_CHECK_VERSION (2, 14, 0)
4244 width_mm
= gdk_screen_get_monitor_width_mm (gscreen
, i
);
4245 height_mm
= gdk_screen_get_monitor_height_mm (gscreen
, i
);
4248 width_mm
= rec
.width
* mm_width_per_pixel
+ 0.5;
4250 height_mm
= rec
.height
* mm_height_per_pixel
+ 0.5;
4252 #if GTK_CHECK_VERSION (3, 4, 0)
4253 gdk_screen_get_monitor_workarea (gscreen
, i
, &work
);
4255 /* Emulate the behavior of GTK+ 3.4. */
4257 XRectangle workarea_r
;
4259 if (i
== primary_monitor
&& x_get_net_workarea (dpyinfo
, &workarea_r
))
4261 work
.x
= workarea_r
.x
;
4262 work
.y
= workarea_r
.y
;
4263 work
.width
= workarea_r
.width
;
4264 work
.height
= workarea_r
.height
;
4265 if (! gdk_rectangle_intersect (&rec
, &work
, &work
))
4276 mi
->geom
.width
= rec
.width
;
4277 mi
->geom
.height
= rec
.height
;
4278 mi
->work
.x
= work
.x
;
4279 mi
->work
.y
= work
.y
;
4280 mi
->work
.width
= work
.width
;
4281 mi
->work
.height
= work
.height
;
4282 mi
->mm_width
= width_mm
;
4283 mi
->mm_height
= height_mm
;
4285 #if GTK_CHECK_VERSION (2, 14, 0)
4286 mi
->name
= gdk_screen_get_monitor_plug_name (gscreen
, i
);
4290 attributes_list
= make_monitor_attribute_list (monitors
,
4296 #else /* not USE_GTK */
4299 attributes_list
= x_get_monitor_attributes (dpyinfo
);
4302 #endif /* not USE_GTK */
4304 return attributes_list
;
4307 /************************************************************************
4309 ************************************************************************/
4312 /* Mapping visual names to visuals. */
4314 static struct visual_class
4321 {"StaticGray", StaticGray
},
4322 {"GrayScale", GrayScale
},
4323 {"StaticColor", StaticColor
},
4324 {"PseudoColor", PseudoColor
},
4325 {"TrueColor", TrueColor
},
4326 {"DirectColor", DirectColor
},
4331 #ifndef HAVE_XSCREENNUMBEROFSCREEN
4333 /* Value is the screen number of screen SCR. This is a substitute for
4334 the X function with the same name when that doesn't exist. */
4337 XScreenNumberOfScreen (scr
)
4338 register Screen
*scr
;
4340 Display
*dpy
= scr
->display
;
4343 for (i
= 0; i
< dpy
->nscreens
; ++i
)
4344 if (scr
== dpy
->screens
+ i
)
4350 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
4353 /* Select the visual that should be used on display DPYINFO. Set
4354 members of DPYINFO appropriately. Called from x_term_init. */
4357 select_visual (struct x_display_info
*dpyinfo
)
4359 Display
*dpy
= dpyinfo
->display
;
4360 Screen
*screen
= dpyinfo
->screen
;
4363 /* See if a visual is specified. */
4364 value
= display_x_get_resource (dpyinfo
,
4365 build_string ("visualClass"),
4366 build_string ("VisualClass"),
4368 if (STRINGP (value
))
4370 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
4371 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
4372 depth, a decimal number. NAME is compared with case ignored. */
4373 char *s
= alloca (SBYTES (value
) + 1);
4378 strcpy (s
, SSDATA (value
));
4379 dash
= strchr (s
, '-');
4382 dpyinfo
->n_planes
= atoi (dash
+ 1);
4386 /* We won't find a matching visual with depth 0, so that
4387 an error will be printed below. */
4388 dpyinfo
->n_planes
= 0;
4390 /* Determine the visual class. */
4391 for (i
= 0; visual_classes
[i
].name
; ++i
)
4392 if (xstrcasecmp (s
, visual_classes
[i
].name
) == 0)
4394 class = visual_classes
[i
].class;
4398 /* Look up a matching visual for the specified class. */
4400 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
4401 dpyinfo
->n_planes
, class, &vinfo
))
4402 fatal ("Invalid visual specification `%s'", SDATA (value
));
4404 dpyinfo
->visual
= vinfo
.visual
;
4409 XVisualInfo
*vinfo
, vinfo_template
;
4411 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
4413 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
4414 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
4415 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
4416 &vinfo_template
, &n_visuals
);
4418 fatal ("Can't get proper X visual info");
4420 dpyinfo
->n_planes
= vinfo
->depth
;
4426 /* Return the X display structure for the display named NAME.
4427 Open a new connection if necessary. */
4429 static struct x_display_info
*
4430 x_display_info_for_name (Lisp_Object name
)
4433 struct x_display_info
*dpyinfo
;
4435 CHECK_STRING (name
);
4437 for (dpyinfo
= x_display_list
, names
= x_display_name_list
;
4439 dpyinfo
= dpyinfo
->next
, names
= XCDR (names
))
4442 tem
= Fstring_equal (XCAR (XCAR (names
)), name
);
4447 /* Use this general default value to start with. */
4448 Vx_resource_name
= Vinvocation_name
;
4450 validate_x_resource_name ();
4452 dpyinfo
= x_term_init (name
, 0, SSDATA (Vx_resource_name
));
4455 error ("Cannot connect to X server %s", SDATA (name
));
4457 XSETFASTINT (Vwindow_system_version
, 11);
4463 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4465 doc
: /* Open a connection to a display server.
4466 DISPLAY is the name of the display to connect to.
4467 Optional second arg XRM-STRING is a string of resources in xrdb format.
4468 If the optional third arg MUST-SUCCEED is non-nil,
4469 terminate Emacs if we can't open the connection.
4470 \(In the Nextstep version, the last two arguments are currently ignored.) */)
4471 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
4474 struct x_display_info
*dpyinfo
;
4476 CHECK_STRING (display
);
4477 if (! NILP (xrm_string
))
4478 CHECK_STRING (xrm_string
);
4480 xrm_option
= NILP (xrm_string
) ? 0 : SSDATA (xrm_string
);
4482 validate_x_resource_name ();
4484 /* This is what opens the connection and sets x_current_display.
4485 This also initializes many symbols, such as those used for input. */
4486 dpyinfo
= x_term_init (display
, xrm_option
,
4487 SSDATA (Vx_resource_name
));
4491 if (!NILP (must_succeed
))
4492 fatal ("Cannot connect to X server %s.\n\
4493 Check the DISPLAY environment variable or use `-d'.\n\
4494 Also use the `xauth' program to verify that you have the proper\n\
4495 authorization information needed to connect the X server.\n\
4496 An insecure way to solve the problem may be to use `xhost'.\n",
4499 error ("Cannot connect to X server %s", SDATA (display
));
4502 XSETFASTINT (Vwindow_system_version
, 11);
4506 DEFUN ("x-close-connection", Fx_close_connection
,
4507 Sx_close_connection
, 1, 1, 0,
4508 doc
: /* Close the connection to TERMINAL's X server.
4509 For TERMINAL, specify a terminal object, a frame or a display name (a
4510 string). If TERMINAL is nil, that stands for the selected frame's
4512 (Lisp_Object terminal
)
4514 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4516 if (dpyinfo
->reference_count
> 0)
4517 error ("Display still has frames on it");
4519 x_delete_terminal (dpyinfo
->terminal
);
4524 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4525 doc
: /* Return the list of display names that Emacs has connections to. */)
4528 Lisp_Object tail
, result
;
4531 for (tail
= x_display_name_list
; CONSP (tail
); tail
= XCDR (tail
))
4532 result
= Fcons (XCAR (XCAR (tail
)), result
);
4537 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4538 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
4539 This function only has an effect on X Windows. With MS Windows, it is
4540 defined but does nothing.
4542 If ON is nil, allow buffering of requests.
4543 Turning on synchronization prohibits the Xlib routines from buffering
4544 requests and seriously degrades performance, but makes debugging much
4546 The optional second argument TERMINAL specifies which display to act on.
4547 TERMINAL should be a terminal object, a frame or a display name (a string).
4548 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
4549 (Lisp_Object on
, Lisp_Object terminal
)
4551 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4553 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
4558 /* Wait for responses to all X commands issued so far for frame F. */
4561 x_sync (struct frame
*f
)
4564 XSync (FRAME_X_DISPLAY (f
), False
);
4569 /***********************************************************************
4571 ***********************************************************************/
4573 DEFUN ("x-change-window-property", Fx_change_window_property
,
4574 Sx_change_window_property
, 2, 6, 0,
4575 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
4576 PROP must be a string. VALUE may be a string or a list of conses,
4577 numbers and/or strings. If an element in the list is a string, it is
4578 converted to an atom and the value of the atom is used. If an element
4579 is a cons, it is converted to a 32 bit number where the car is the 16
4580 top bits and the cdr is the lower 16 bits.
4582 FRAME nil or omitted means use the selected frame.
4583 If TYPE is given and non-nil, it is the name of the type of VALUE.
4584 If TYPE is not given or nil, the type is STRING.
4585 FORMAT gives the size in bits of each element if VALUE is a list.
4586 It must be one of 8, 16 or 32.
4587 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4588 If OUTER-P is non-nil, the property is changed for the outer X window of
4589 FRAME. Default is to change on the edit X window. */)
4590 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
,
4591 Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
4593 struct frame
*f
= decode_window_system_frame (frame
);
4595 Atom target_type
= XA_STRING
;
4596 int element_format
= 8;
4597 unsigned char *data
;
4601 CHECK_STRING (prop
);
4603 if (! NILP (format
))
4605 CHECK_NUMBER (format
);
4607 if (XINT (format
) != 8 && XINT (format
) != 16
4608 && XINT (format
) != 32)
4609 error ("FORMAT must be one of 8, 16 or 32");
4610 element_format
= XINT (format
);
4617 nelements
= x_check_property_data (value
);
4618 if (nelements
== -1)
4619 error ("Bad data in VALUE, must be number, string or cons");
4621 /* The man page for XChangeProperty:
4622 "If the specified format is 32, the property data must be a
4624 This applies even if long is more than 32 bits. The X library
4625 converts to 32 bits before sending to the X server. */
4626 elsize
= element_format
== 32 ? sizeof (long) : element_format
>> 3;
4627 data
= xnmalloc (nelements
, elsize
);
4629 x_fill_property_data (FRAME_X_DISPLAY (f
), value
, data
, element_format
);
4633 CHECK_STRING (value
);
4634 data
= SDATA (value
);
4635 if (INT_MAX
< SBYTES (value
))
4636 error ("VALUE too long");
4637 nelements
= SBYTES (value
);
4641 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4644 CHECK_STRING (type
);
4645 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
4648 if (! NILP (outer_p
)) w
= FRAME_OUTER_WINDOW (f
);
4649 else w
= FRAME_X_WINDOW (f
);
4651 XChangeProperty (FRAME_X_DISPLAY (f
), w
,
4652 prop_atom
, target_type
, element_format
, PropModeReplace
,
4655 if (CONSP (value
)) xfree (data
);
4657 /* Make sure the property is set when we return. */
4658 XFlush (FRAME_X_DISPLAY (f
));
4665 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
4666 Sx_delete_window_property
, 1, 2, 0,
4667 doc
: /* Remove window property PROP from X window of FRAME.
4668 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4669 (Lisp_Object prop
, Lisp_Object frame
)
4671 struct frame
*f
= decode_window_system_frame (frame
);
4674 CHECK_STRING (prop
);
4676 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4677 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
4679 /* Make sure the property is removed when we return. */
4680 XFlush (FRAME_X_DISPLAY (f
));
4687 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
4689 doc
: /* Value is the value of window property PROP on FRAME.
4690 If FRAME is nil or omitted, use the selected frame.
4692 On X Windows, the following optional arguments are also accepted:
4693 If TYPE is nil or omitted, get the property as a string.
4694 Otherwise TYPE is the name of the atom that denotes the type expected.
4695 If SOURCE is non-nil, get the property on that window instead of from
4696 FRAME. The number 0 denotes the root window.
4697 If DELETE-P is non-nil, delete the property after retrieving it.
4698 If VECTOR-RET-P is non-nil, don't return a string but a vector of values.
4700 On MS Windows, this function accepts but ignores those optional arguments.
4702 Value is nil if FRAME hasn't a property with name PROP or if PROP has
4703 no value of TYPE (always string in the MS Windows case). */)
4704 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
,
4705 Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
4707 struct frame
*f
= decode_window_system_frame (frame
);
4710 Lisp_Object prop_value
= Qnil
;
4711 unsigned char *tmp_data
= NULL
;
4713 Atom target_type
= XA_STRING
;
4715 unsigned long actual_size
, bytes_remaining
;
4716 Window target_window
= FRAME_X_WINDOW (f
);
4717 struct gcpro gcpro1
;
4719 GCPRO1 (prop_value
);
4720 CHECK_STRING (prop
);
4722 if (! NILP (source
))
4724 CONS_TO_INTEGER (source
, Window
, target_window
);
4725 if (! target_window
)
4726 target_window
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
4732 if (strcmp ("AnyPropertyType", SSDATA (type
)) == 0)
4733 target_type
= AnyPropertyType
;
4735 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
4738 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4739 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4740 prop_atom
, 0, 0, False
, target_type
,
4741 &actual_type
, &actual_format
, &actual_size
,
4742 &bytes_remaining
, &tmp_data
);
4745 int size
= bytes_remaining
;
4750 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4751 prop_atom
, 0, bytes_remaining
,
4752 ! NILP (delete_p
), target_type
,
4753 &actual_type
, &actual_format
,
4754 &actual_size
, &bytes_remaining
,
4756 if (rc
== Success
&& tmp_data
)
4758 /* The man page for XGetWindowProperty says:
4759 "If the returned format is 32, the returned data is represented
4760 as a long array and should be cast to that type to obtain the
4762 This applies even if long is more than 32 bits, the X library
4763 converts from 32 bit elements received from the X server to long
4764 and passes the long array to us. Thus, for that case memcpy can not
4765 be used. We convert to a 32 bit type here, because so much code
4768 The bytes and offsets passed to XGetWindowProperty refers to the
4769 property and those are indeed in 32 bit quantities if format is
4772 if (BITS_PER_LONG
> 32 && actual_format
== 32)
4775 int *idata
= (int *) tmp_data
;
4776 long *ldata
= (long *) tmp_data
;
4778 for (i
= 0; i
< actual_size
; ++i
)
4779 idata
[i
] = (int) ldata
[i
];
4782 if (NILP (vector_ret_p
))
4783 prop_value
= make_string ((char *) tmp_data
, size
);
4785 prop_value
= x_property_data_to_lisp (f
,
4792 if (tmp_data
) XFree (tmp_data
);
4802 /***********************************************************************
4804 ***********************************************************************/
4806 /* Timer function of hourglass_atimer. TIMER is equal to
4809 Display an hourglass pointer on all frames by mapping the frames'
4810 hourglass_window. Set the hourglass_p flag in the frames'
4811 output_data.x structure to indicate that an hourglass cursor is
4812 shown on the frames. */
4815 show_hourglass (struct atimer
*timer
)
4817 /* The timer implementation will cancel this timer automatically
4818 after this function has run. Set hourglass_atimer to null
4819 so that we know the timer doesn't have to be canceled. */
4820 hourglass_atimer
= NULL
;
4822 if (!hourglass_shown_p
)
4824 Lisp_Object rest
, frame
;
4828 FOR_EACH_FRAME (rest
, frame
)
4830 struct frame
*f
= XFRAME (frame
);
4832 if (FRAME_LIVE_P (f
) && FRAME_X_P (f
) && FRAME_X_DISPLAY (f
))
4834 Display
*dpy
= FRAME_X_DISPLAY (f
);
4836 #ifdef USE_X_TOOLKIT
4837 if (f
->output_data
.x
->widget
)
4839 if (FRAME_OUTER_WINDOW (f
))
4842 f
->output_data
.x
->hourglass_p
= 1;
4844 if (!f
->output_data
.x
->hourglass_window
)
4846 unsigned long mask
= CWCursor
;
4847 XSetWindowAttributes attrs
;
4849 Window parent
= FRAME_X_WINDOW (f
);
4851 Window parent
= FRAME_OUTER_WINDOW (f
);
4853 attrs
.cursor
= f
->output_data
.x
->hourglass_cursor
;
4855 f
->output_data
.x
->hourglass_window
4856 = XCreateWindow (dpy
, parent
,
4857 0, 0, 32000, 32000, 0, 0,
4863 XMapRaised (dpy
, f
->output_data
.x
->hourglass_window
);
4869 hourglass_shown_p
= 1;
4875 /* Hide the hourglass pointer on all frames, if it is currently
4879 hide_hourglass (void)
4881 if (hourglass_shown_p
)
4883 Lisp_Object rest
, frame
;
4886 FOR_EACH_FRAME (rest
, frame
)
4888 struct frame
*f
= XFRAME (frame
);
4891 /* Watch out for newly created frames. */
4892 && f
->output_data
.x
->hourglass_window
)
4894 XUnmapWindow (FRAME_X_DISPLAY (f
),
4895 f
->output_data
.x
->hourglass_window
);
4896 /* Sync here because XTread_socket looks at the
4897 hourglass_p flag that is reset to zero below. */
4898 XSync (FRAME_X_DISPLAY (f
), False
);
4899 f
->output_data
.x
->hourglass_p
= 0;
4903 hourglass_shown_p
= 0;
4910 /***********************************************************************
4912 ***********************************************************************/
4914 static Lisp_Object
x_create_tip_frame (struct x_display_info
*,
4915 Lisp_Object
, Lisp_Object
);
4916 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
4917 Lisp_Object
, int, int, int *, int *);
4919 /* The frame of a currently visible tooltip. */
4921 Lisp_Object tip_frame
;
4923 /* If non-nil, a timer started that hides the last tooltip when it
4926 static Lisp_Object tip_timer
;
4929 /* If non-nil, a vector of 3 elements containing the last args
4930 with which x-show-tip was called. See there. */
4932 static Lisp_Object last_show_tip_args
;
4936 unwind_create_tip_frame (Lisp_Object frame
)
4938 Lisp_Object deleted
;
4940 deleted
= unwind_create_frame (frame
);
4941 if (EQ (deleted
, Qt
))
4949 /* Create a frame for a tooltip on the display described by DPYINFO.
4950 PARMS is a list of frame parameters. TEXT is the string to
4951 display in the tip frame. Value is the frame.
4953 Note that functions called here, esp. x_default_parameter can
4954 signal errors, for instance when a specified color name is
4955 undefined. We have to make sure that we're in a consistent state
4956 when this happens. */
4959 x_create_tip_frame (struct x_display_info
*dpyinfo
,
4967 ptrdiff_t count
= SPECPDL_INDEX ();
4968 struct gcpro gcpro1
, gcpro2
, gcpro3
;
4969 int face_change_count_before
= face_change_count
;
4971 struct buffer
*old_buffer
;
4973 if (!dpyinfo
->terminal
->name
)
4974 error ("Terminal is not live, can't create new frames on it");
4976 parms
= Fcopy_alist (parms
);
4978 /* Get the name of the frame to use for resource lookup. */
4979 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
4981 && !EQ (name
, Qunbound
)
4983 error ("Invalid frame name--not a string or nil");
4986 GCPRO3 (parms
, name
, frame
);
4988 XSETFRAME (frame
, f
);
4990 buffer
= Fget_buffer_create (build_string (" *tip*"));
4991 /* Use set_window_buffer instead of Fset_window_buffer (see
4992 discussion of bug#11984, bug#12025, bug#12026). */
4993 set_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, 0, 0);
4994 old_buffer
= current_buffer
;
4995 set_buffer_internal_1 (XBUFFER (buffer
));
4996 bset_truncate_lines (current_buffer
, Qnil
);
4997 specbind (Qinhibit_read_only
, Qt
);
4998 specbind (Qinhibit_modification_hooks
, Qt
);
5001 set_buffer_internal_1 (old_buffer
);
5003 record_unwind_protect (unwind_create_tip_frame
, frame
);
5005 f
->terminal
= dpyinfo
->terminal
;
5007 /* By setting the output method, we're essentially saying that
5008 the frame is live, as per FRAME_LIVE_P. If we get a signal
5009 from this point on, x_destroy_window might screw up reference
5011 f
->output_method
= output_x_window
;
5012 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
5013 f
->output_data
.x
->icon_bitmap
= -1;
5014 FRAME_FONTSET (f
) = -1;
5015 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
5016 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
5017 #ifdef USE_TOOLKIT_SCROLL_BARS
5018 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
5019 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
5020 #endif /* USE_TOOLKIT_SCROLL_BARS */
5021 fset_icon_name (f
, Qnil
);
5022 FRAME_X_DISPLAY_INFO (f
) = dpyinfo
;
5023 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
5024 f
->output_data
.x
->explicit_parent
= 0;
5026 /* These colors will be set anyway later, but it's important
5027 to get the color reference counts right, so initialize them! */
5030 struct gcpro gcpro1
;
5032 /* Function x_decode_color can signal an error. Make
5033 sure to initialize color slots so that we won't try
5034 to free colors we haven't allocated. */
5035 FRAME_FOREGROUND_PIXEL (f
) = -1;
5036 FRAME_BACKGROUND_PIXEL (f
) = -1;
5037 f
->output_data
.x
->cursor_pixel
= -1;
5038 f
->output_data
.x
->cursor_foreground_pixel
= -1;
5039 f
->output_data
.x
->border_pixel
= -1;
5040 f
->output_data
.x
->mouse_pixel
= -1;
5042 black
= build_string ("black");
5044 FRAME_FOREGROUND_PIXEL (f
)
5045 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5046 FRAME_BACKGROUND_PIXEL (f
)
5047 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5048 f
->output_data
.x
->cursor_pixel
5049 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5050 f
->output_data
.x
->cursor_foreground_pixel
5051 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5052 f
->output_data
.x
->border_pixel
5053 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5054 f
->output_data
.x
->mouse_pixel
5055 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5059 /* Set the name; the functions to which we pass f expect the name to
5061 if (EQ (name
, Qunbound
) || NILP (name
))
5063 fset_name (f
, build_string (dpyinfo
->x_id_name
));
5064 f
->explicit_name
= 0;
5068 fset_name (f
, name
);
5069 f
->explicit_name
= 1;
5070 /* use the frame's title when getting resources for this frame. */
5071 specbind (Qx_resource_name
, name
);
5074 register_font_driver (&xfont_driver
, f
);
5075 #ifdef HAVE_FREETYPE
5077 register_font_driver (&xftfont_driver
, f
);
5078 #else /* not HAVE_XFT */
5079 register_font_driver (&ftxfont_driver
, f
);
5080 #endif /* not HAVE_XFT */
5081 #endif /* HAVE_FREETYPE */
5083 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5084 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5086 /* Extract the window parameters from the supplied values that are
5087 needed to determine window geometry. */
5088 x_default_font_parameter (f
, parms
);
5090 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
5091 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5093 /* This defaults to 2 in order to match xterm. We recognize either
5094 internalBorderWidth or internalBorder (which is what xterm calls
5096 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5100 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5101 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5102 if (! EQ (value
, Qunbound
))
5103 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5107 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5108 "internalBorderWidth", "internalBorderWidth",
5111 /* Also do the stuff which must be set before the window exists. */
5112 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5113 "foreground", "Foreground", RES_TYPE_STRING
);
5114 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5115 "background", "Background", RES_TYPE_STRING
);
5116 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5117 "pointerColor", "Foreground", RES_TYPE_STRING
);
5118 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5119 "cursorColor", "Foreground", RES_TYPE_STRING
);
5120 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5121 "borderColor", "BorderColor", RES_TYPE_STRING
);
5124 image_cache_refcount
=
5125 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
5126 dpyinfo_refcount
= dpyinfo
->reference_count
;
5127 #endif /* GLYPH_DEBUG */
5129 /* Init faces before x_default_parameter is called for scroll-bar
5130 parameters because that function calls x_set_scroll_bar_width,
5131 which calls change_frame_size, which calls Fset_window_buffer,
5132 which runs hooks, which call Fvertical_motion. At the end, we
5133 end up in init_iterator with a null face cache, which should not
5135 init_frame_faces (f
);
5137 f
->output_data
.x
->parent_desc
= FRAME_X_DISPLAY_INFO (f
)->root_window
;
5139 x_figure_window_size (f
, parms
, 0);
5142 XSetWindowAttributes attrs
;
5144 Atom type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_net_window_type_tooltip
;
5147 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
;
5148 if (DoesSaveUnders (dpyinfo
->screen
))
5149 mask
|= CWSaveUnder
;
5151 /* Window managers look at the override-redirect flag to determine
5152 whether or net to give windows a decoration (Xlib spec, chapter
5154 attrs
.override_redirect
= True
;
5155 attrs
.save_under
= True
;
5156 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
5157 /* Arrange for getting MapNotify and UnmapNotify events. */
5158 attrs
.event_mask
= StructureNotifyMask
;
5160 = FRAME_X_WINDOW (f
)
5161 = XCreateWindow (FRAME_X_DISPLAY (f
),
5162 FRAME_X_DISPLAY_INFO (f
)->root_window
,
5163 /* x, y, width, height */
5167 CopyFromParent
, InputOutput
, CopyFromParent
,
5169 XChangeProperty (FRAME_X_DISPLAY (f
), tip_window
,
5170 FRAME_X_DISPLAY_INFO (f
)->Xatom_net_window_type
,
5171 XA_ATOM
, 32, PropModeReplace
,
5172 (unsigned char *)&type
, 1);
5178 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5179 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5180 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5181 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5182 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5183 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5185 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
5186 Change will not be effected unless different from the current
5188 width
= FRAME_COLS (f
);
5189 height
= FRAME_LINES (f
);
5190 SET_FRAME_COLS (f
, 0);
5191 FRAME_LINES (f
) = 0;
5192 change_frame_size (f
, height
, width
, 1, 0, 0);
5194 /* Add `tooltip' frame parameter's default value. */
5195 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5196 Fmodify_frame_parameters (frame
, list1 (Fcons (Qtooltip
, Qt
)));
5198 /* FIXME - can this be done in a similar way to normal frames?
5199 http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00641.html */
5201 /* Set the `display-type' frame parameter before setting up faces. */
5203 Lisp_Object disptype
;
5205 if (FRAME_X_DISPLAY_INFO (f
)->n_planes
== 1)
5206 disptype
= intern ("mono");
5207 else if (FRAME_X_DISPLAY_INFO (f
)->visual
->class == GrayScale
5208 || FRAME_X_DISPLAY_INFO (f
)->visual
->class == StaticGray
)
5209 disptype
= intern ("grayscale");
5211 disptype
= intern ("color");
5213 if (NILP (Fframe_parameter (frame
, Qdisplay_type
)))
5214 Fmodify_frame_parameters (frame
, list1 (Fcons (Qdisplay_type
, disptype
)));
5217 /* Set up faces after all frame parameters are known. This call
5218 also merges in face attributes specified for new frames.
5220 Frame parameters may be changed if .Xdefaults contains
5221 specifications for the default font. For example, if there is an
5222 `Emacs.default.attributeBackground: pink', the `background-color'
5223 attribute of the frame get's set, which let's the internal border
5224 of the tooltip frame appear in pink. Prevent this. */
5226 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5228 /* Set tip_frame here, so that */
5230 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5232 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5233 Fmodify_frame_parameters (frame
, list1 (Fcons (Qbackground_color
, bg
)));
5240 /* Now that the frame will be official, it counts as a reference to
5241 its display and terminal. */
5242 FRAME_X_DISPLAY_INFO (f
)->reference_count
++;
5243 f
->terminal
->reference_count
++;
5245 /* It is now ok to make the frame official even if we get an error
5246 below. And the frame needs to be on Vframe_list or making it
5247 visible won't work. */
5248 Vframe_list
= Fcons (frame
, Vframe_list
);
5251 /* Setting attributes of faces of the tooltip frame from resources
5252 and similar will increment face_change_count, which leads to the
5253 clearing of all current matrices. Since this isn't necessary
5254 here, avoid it by resetting face_change_count to the value it
5255 had before we created the tip frame. */
5256 face_change_count
= face_change_count_before
;
5258 /* Discard the unwind_protect. */
5259 return unbind_to (count
, frame
);
5263 /* Compute where to display tip frame F. PARMS is the list of frame
5264 parameters for F. DX and DY are specified offsets from the current
5265 location of the mouse. WIDTH and HEIGHT are the width and height
5266 of the tooltip. Return coordinates relative to the root window of
5267 the display in *ROOT_X, and *ROOT_Y. */
5270 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
)
5272 Lisp_Object left
, top
;
5277 /* User-specified position? */
5278 left
= Fcdr (Fassq (Qleft
, parms
));
5279 top
= Fcdr (Fassq (Qtop
, parms
));
5281 /* Move the tooltip window where the mouse pointer is. Resize and
5283 if (!INTEGERP (left
) || !INTEGERP (top
))
5286 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_X_DISPLAY_INFO (f
)->root_window
,
5287 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
5292 *root_y
= XINT (top
);
5293 else if (*root_y
+ XINT (dy
) <= 0)
5294 *root_y
= 0; /* Can happen for negative dy */
5295 else if (*root_y
+ XINT (dy
) + height
5296 <= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
)))
5297 /* It fits below the pointer */
5298 *root_y
+= XINT (dy
);
5299 else if (height
+ XINT (dy
) <= *root_y
)
5300 /* It fits above the pointer. */
5301 *root_y
-= height
+ XINT (dy
);
5303 /* Put it on the top. */
5306 if (INTEGERP (left
))
5307 *root_x
= XINT (left
);
5308 else if (*root_x
+ XINT (dx
) <= 0)
5309 *root_x
= 0; /* Can happen for negative dx */
5310 else if (*root_x
+ XINT (dx
) + width
5311 <= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
)))
5312 /* It fits to the right of the pointer. */
5313 *root_x
+= XINT (dx
);
5314 else if (width
+ XINT (dx
) <= *root_x
)
5315 /* It fits to the left of the pointer. */
5316 *root_x
-= width
+ XINT (dx
);
5318 /* Put it left-justified on the screen--it ought to fit that way. */
5323 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5324 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
5325 A tooltip window is a small X window displaying a string.
5327 This is an internal function; Lisp code should call `tooltip-show'.
5329 FRAME nil or omitted means use the selected frame.
5331 PARMS is an optional list of frame parameters which can be used to
5332 change the tooltip's appearance.
5334 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5335 means use the default timeout of 5 seconds.
5337 If the list of frame parameters PARMS contains a `left' parameters,
5338 the tooltip is displayed at that x-position. Otherwise it is
5339 displayed at the mouse position, with offset DX added (default is 5 if
5340 DX isn't specified). Likewise for the y-position; if a `top' frame
5341 parameter is specified, it determines the y-position of the tooltip
5342 window, otherwise it is displayed at the mouse position, with offset
5343 DY added (default is -10).
5345 A tooltip's maximum size is specified by `x-max-tooltip-size'.
5346 Text larger than the specified size is clipped. */)
5347 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
5352 struct buffer
*old_buffer
;
5353 struct text_pos pos
;
5354 int i
, width
, height
, seen_reversed_p
;
5355 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
5356 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5357 ptrdiff_t count
= SPECPDL_INDEX ();
5359 specbind (Qinhibit_redisplay
, Qt
);
5361 GCPRO4 (string
, parms
, frame
, timeout
);
5363 CHECK_STRING (string
);
5364 if (SCHARS (string
) == 0)
5365 string
= make_unibyte_string (" ", 1);
5367 f
= decode_window_system_frame (frame
);
5369 timeout
= make_number (5);
5371 CHECK_NATNUM (timeout
);
5374 dx
= make_number (5);
5379 dy
= make_number (-10);
5384 if (x_gtk_use_system_tooltips
)
5388 /* Hide a previous tip, if any. */
5392 ok
= xg_prepare_tooltip (f
, string
, &width
, &height
);
5395 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5396 xg_show_tooltip (f
, root_x
, root_y
);
5397 /* This is used in Fx_hide_tip. */
5398 XSETFRAME (tip_frame
, f
);
5401 if (ok
) goto start_timer
;
5403 #endif /* USE_GTK */
5405 if (NILP (last_show_tip_args
))
5406 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5408 if (!NILP (tip_frame
))
5410 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5411 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5412 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5414 if (EQ (frame
, last_frame
)
5415 && !NILP (Fequal (last_string
, string
))
5416 && !NILP (Fequal (last_parms
, parms
)))
5418 struct frame
*tip_f
= XFRAME (tip_frame
);
5420 /* Only DX and DY have changed. */
5421 if (!NILP (tip_timer
))
5423 Lisp_Object timer
= tip_timer
;
5425 call1 (Qcancel_timer
, timer
);
5429 compute_tip_xy (tip_f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (tip_f
),
5430 FRAME_PIXEL_HEIGHT (tip_f
), &root_x
, &root_y
);
5431 XMoveWindow (FRAME_X_DISPLAY (tip_f
), FRAME_X_WINDOW (tip_f
),
5438 /* Hide a previous tip, if any. */
5441 ASET (last_show_tip_args
, 0, string
);
5442 ASET (last_show_tip_args
, 1, frame
);
5443 ASET (last_show_tip_args
, 2, parms
);
5445 /* Add default values to frame parameters. */
5446 if (NILP (Fassq (Qname
, parms
)))
5447 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5448 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5449 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5450 if (NILP (Fassq (Qborder_width
, parms
)))
5451 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5452 if (NILP (Fassq (Qborder_color
, parms
)))
5453 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5454 if (NILP (Fassq (Qbackground_color
, parms
)))
5455 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5458 /* Create a frame for the tooltip, and record it in the global
5459 variable tip_frame. */
5460 frame
= x_create_tip_frame (FRAME_X_DISPLAY_INFO (f
), parms
, string
);
5463 /* Set up the frame's root window. */
5464 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5468 if (CONSP (Vx_max_tooltip_size
)
5469 && RANGED_INTEGERP (1, XCAR (Vx_max_tooltip_size
), INT_MAX
)
5470 && RANGED_INTEGERP (1, XCDR (Vx_max_tooltip_size
), INT_MAX
))
5472 w
->total_cols
= XFASTINT (XCAR (Vx_max_tooltip_size
));
5473 w
->total_lines
= XFASTINT (XCDR (Vx_max_tooltip_size
));
5478 w
->total_lines
= 40;
5481 FRAME_TOTAL_COLS (f
) = w
->total_cols
;
5482 adjust_frame_glyphs (f
);
5483 w
->pseudo_window_p
= 1;
5485 /* Display the tooltip text in a temporary buffer. */
5486 old_buffer
= current_buffer
;
5487 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->contents
));
5488 bset_truncate_lines (current_buffer
, Qnil
);
5489 clear_glyph_matrix (w
->desired_matrix
);
5490 clear_glyph_matrix (w
->current_matrix
);
5491 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5492 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5494 /* Compute width and height of the tooltip. */
5495 width
= height
= seen_reversed_p
= 0;
5496 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5498 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5502 /* Stop at the first empty row at the end. */
5503 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5506 /* Let the row go over the full width of the frame. */
5507 row
->full_width_p
= 1;
5509 row_width
= row
->pixel_width
;
5510 if (row
->used
[TEXT_AREA
])
5512 /* There's a glyph at the end of rows that is used to place
5513 the cursor there. Don't include the width of this glyph. */
5514 if (!row
->reversed_p
)
5516 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5517 if (INTEGERP (last
->object
))
5518 row_width
-= last
->pixel_width
;
5522 /* There could be a stretch glyph at the beginning of R2L
5523 rows that is produced by extend_face_to_end_of_line.
5524 Don't count that glyph. */
5525 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
5527 if (g
->type
== STRETCH_GLYPH
&& INTEGERP (g
->object
))
5529 row_width
-= g
->pixel_width
;
5530 seen_reversed_p
= 1;
5535 height
+= row
->height
;
5536 width
= max (width
, row_width
);
5539 /* If we've seen partial-length R2L rows, we need to re-adjust the
5540 tool-tip frame width and redisplay it again, to avoid over-wide
5541 tips due to the stretch glyph that extends R2L lines to full
5542 width of the frame. */
5543 if (seen_reversed_p
)
5545 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns,
5547 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
5548 w
->total_cols
= width
;
5549 FRAME_TOTAL_COLS (f
) = width
;
5550 adjust_frame_glyphs (f
);
5551 clear_glyph_matrix (w
->desired_matrix
);
5552 clear_glyph_matrix (w
->current_matrix
);
5553 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
5555 /* Recompute width and height of the tooltip. */
5556 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5558 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5562 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5564 row
->full_width_p
= 1;
5565 row_width
= row
->pixel_width
;
5566 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
5568 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5569 if (INTEGERP (last
->object
))
5570 row_width
-= last
->pixel_width
;
5573 height
+= row
->height
;
5574 width
= max (width
, row_width
);
5578 /* Add the frame's internal border to the width and height the X
5579 window should have. */
5580 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5581 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5583 /* Move the tooltip window where the mouse pointer is. Resize and
5585 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5588 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5589 root_x
, root_y
, width
, height
);
5590 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5593 /* Draw into the window. */
5594 w
->must_be_updated_p
= 1;
5595 update_single_window (w
, 1);
5597 /* Restore original current buffer. */
5598 set_buffer_internal_1 (old_buffer
);
5599 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5602 /* Let the tip disappear after timeout seconds. */
5603 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5604 intern ("x-hide-tip"));
5607 return unbind_to (count
, Qnil
);
5611 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5612 doc
: /* Hide the current tooltip window, if there is any.
5613 Value is t if tooltip was open, nil otherwise. */)
5617 Lisp_Object deleted
, frame
, timer
;
5618 struct gcpro gcpro1
, gcpro2
;
5620 /* Return quickly if nothing to do. */
5621 if (NILP (tip_timer
) && NILP (tip_frame
))
5626 GCPRO2 (frame
, timer
);
5627 tip_frame
= tip_timer
= deleted
= Qnil
;
5629 count
= SPECPDL_INDEX ();
5630 specbind (Qinhibit_redisplay
, Qt
);
5631 specbind (Qinhibit_quit
, Qt
);
5634 call1 (Qcancel_timer
, timer
);
5638 /* When using system tooltip, tip_frame is the Emacs frame on which
5639 the tip is shown. */
5640 struct frame
*f
= XFRAME (frame
);
5641 if (FRAME_LIVE_P (f
) && xg_hide_tooltip (f
))
5648 delete_frame (frame
, Qnil
);
5652 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5653 redisplay procedure is not called when a tip frame over menu
5654 items is unmapped. Redisplay the menu manually... */
5657 struct frame
*f
= SELECTED_FRAME ();
5658 w
= f
->output_data
.x
->menubar_widget
;
5660 if (!DoesSaveUnders (FRAME_X_DISPLAY_INFO (f
)->screen
)
5664 xlwmenu_redisplay (w
);
5668 #endif /* USE_LUCID */
5672 return unbind_to (count
, deleted
);
5677 /***********************************************************************
5678 File selection dialog
5679 ***********************************************************************/
5681 DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog
,
5682 Sx_uses_old_gtk_dialog
,
5684 doc
: /* Return t if the old Gtk+ file selection dialog is used. */)
5690 && window_system_available (SELECTED_FRAME ())
5691 && xg_uses_old_file_dialog ())
5699 /* Callback for "OK" and "Cancel" on file selection dialog. */
5702 file_dialog_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5704 int *result
= client_data
;
5705 XmAnyCallbackStruct
*cb
= call_data
;
5706 *result
= cb
->reason
;
5710 /* Callback for unmapping a file selection dialog. This is used to
5711 capture the case where a dialog is closed via a window manager's
5712 closer button, for example. Using a XmNdestroyCallback didn't work
5716 file_dialog_unmap_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5718 int *result
= client_data
;
5719 *result
= XmCR_CANCEL
;
5723 clean_up_file_dialog (void *arg
)
5725 Widget dialog
= arg
;
5729 XtUnmanageChild (dialog
);
5730 XtDestroyWidget (dialog
);
5731 x_menu_set_in_use (0);
5736 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5737 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5738 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5739 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5740 or directory must exist.
5742 This function is only defined on NS, MS Windows, and X Windows with the
5743 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5744 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5745 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
,
5746 Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5749 struct frame
*f
= SELECTED_FRAME ();
5750 Lisp_Object file
= Qnil
;
5751 Lisp_Object decoded_file
;
5752 Widget dialog
, text
, help
;
5755 XmString dir_xmstring
, pattern_xmstring
;
5756 ptrdiff_t count
= SPECPDL_INDEX ();
5757 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5759 check_window_system (f
);
5761 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5763 if (popup_activated ())
5764 error ("Trying to use a menu from within a menu-entry");
5766 CHECK_STRING (prompt
);
5769 /* Prevent redisplay. */
5770 specbind (Qinhibit_redisplay
, Qt
);
5774 /* Create the dialog with PROMPT as title, using DIR as initial
5775 directory and using "*" as pattern. */
5776 dir
= Fexpand_file_name (dir
, Qnil
);
5777 dir_xmstring
= XmStringCreateLocalized (SSDATA (dir
));
5778 pattern_xmstring
= XmStringCreateLocalized ("*");
5780 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
5781 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
5782 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
5783 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
5784 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
5785 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
5787 XmStringFree (dir_xmstring
);
5788 XmStringFree (pattern_xmstring
);
5790 /* Add callbacks for OK and Cancel. */
5791 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
5792 (XtPointer
) &result
);
5793 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
5794 (XtPointer
) &result
);
5795 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
5796 (XtPointer
) &result
);
5798 /* Remove the help button since we can't display help. */
5799 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
5800 XtUnmanageChild (help
);
5802 /* Mark OK button as default. */
5803 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
5804 XmNshowAsDefault
, True
, NULL
);
5806 /* If MUSTMATCH is non-nil, disable the file entry field of the
5807 dialog, so that the user must select a file from the files list
5808 box. We can't remove it because we wouldn't have a way to get at
5809 the result file name, then. */
5810 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5811 if (!NILP (mustmatch
))
5814 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
5815 XtSetSensitive (text
, False
);
5816 XtSetSensitive (label
, False
);
5819 /* Manage the dialog, so that list boxes get filled. */
5820 XtManageChild (dialog
);
5822 if (STRINGP (default_filename
))
5824 XmString default_xmstring
;
5825 Widget wtext
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
5826 Widget list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
5828 XmTextPosition last_pos
= XmTextFieldGetLastPosition (wtext
);
5829 XmTextFieldReplace (wtext
, 0, last_pos
,
5830 (SSDATA (Ffile_name_nondirectory (default_filename
))));
5832 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
5833 must include the path for this to work. */
5835 default_xmstring
= XmStringCreateLocalized (SSDATA (default_filename
));
5837 if (XmListItemExists (list
, default_xmstring
))
5839 int item_pos
= XmListItemPos (list
, default_xmstring
);
5840 /* Select the item and scroll it into view. */
5841 XmListSelectPos (list
, item_pos
, True
);
5842 XmListSetPos (list
, item_pos
);
5845 XmStringFree (default_xmstring
);
5848 record_unwind_protect_ptr (clean_up_file_dialog
, dialog
);
5850 /* Process events until the user presses Cancel or OK. */
5851 x_menu_set_in_use (1);
5856 x_menu_wait_for_event (0);
5857 XtAppNextEvent (Xt_app_con
, &event
);
5858 if (event
.type
== KeyPress
5859 && FRAME_X_DISPLAY (f
) == event
.xkey
.display
)
5861 KeySym keysym
= XLookupKeysym (&event
.xkey
, 0);
5863 /* Pop down on C-g. */
5864 if (keysym
== XK_g
&& (event
.xkey
.state
& ControlMask
) != 0)
5865 XtUnmanageChild (dialog
);
5868 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
));
5871 /* Get the result. */
5872 if (result
== XmCR_OK
)
5874 XmString text_string
;
5877 XtVaGetValues (dialog
, XmNtextString
, &text_string
, NULL
);
5878 XmStringGetLtoR (text_string
, XmFONTLIST_DEFAULT_TAG
, &data
);
5879 XmStringFree (text_string
);
5880 file
= build_string (data
);
5889 /* Make "Cancel" equivalent to C-g. */
5891 Fsignal (Qquit
, Qnil
);
5893 decoded_file
= DECODE_FILE (file
);
5895 return unbind_to (count
, decoded_file
);
5898 #endif /* USE_MOTIF */
5903 clean_up_dialog (void)
5905 x_menu_set_in_use (0);
5908 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5909 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5910 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5911 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5912 or directory must exist.
5914 This function is only defined on NS, MS Windows, and X Windows with the
5915 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5916 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5917 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5919 struct frame
*f
= SELECTED_FRAME ();
5921 Lisp_Object file
= Qnil
;
5922 Lisp_Object decoded_file
;
5923 ptrdiff_t count
= SPECPDL_INDEX ();
5924 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
, gcpro6
;
5927 check_window_system (f
);
5929 GCPRO6 (prompt
, dir
, default_filename
, mustmatch
, only_dir_p
, file
);
5931 if (popup_activated ())
5932 error ("Trying to use a menu from within a menu-entry");
5934 CHECK_STRING (prompt
);
5937 /* Prevent redisplay. */
5938 specbind (Qinhibit_redisplay
, Qt
);
5939 record_unwind_protect_void (clean_up_dialog
);
5943 if (STRINGP (default_filename
))
5944 cdef_file
= SSDATA (default_filename
);
5946 cdef_file
= SSDATA (dir
);
5948 fn
= xg_get_file_name (f
, SSDATA (prompt
), cdef_file
,
5950 ! NILP (only_dir_p
));
5954 file
= build_string (fn
);
5961 /* Make "Cancel" equivalent to C-g. */
5963 Fsignal (Qquit
, Qnil
);
5965 decoded_file
= DECODE_FILE (file
);
5967 return unbind_to (count
, decoded_file
);
5971 #ifdef HAVE_FREETYPE
5973 DEFUN ("x-select-font", Fx_select_font
, Sx_select_font
, 0, 2, 0,
5974 doc
: /* Read a font using a GTK dialog.
5975 Return either a font spec (for GTK versions >= 3.2) or a string
5976 containing a GTK-style font name.
5978 FRAME is the frame on which to pop up the font chooser. If omitted or
5979 nil, it defaults to the selected frame. */)
5980 (Lisp_Object frame
, Lisp_Object ignored
)
5982 struct frame
*f
= decode_window_system_frame (frame
);
5984 Lisp_Object font_param
;
5985 char *default_name
= NULL
;
5986 struct gcpro gcpro1
, gcpro2
;
5987 ptrdiff_t count
= SPECPDL_INDEX ();
5989 if (popup_activated ())
5990 error ("Trying to use a menu from within a menu-entry");
5992 /* Prevent redisplay. */
5993 specbind (Qinhibit_redisplay
, Qt
);
5994 record_unwind_protect_void (clean_up_dialog
);
5998 GCPRO2 (font_param
, font
);
6000 XSETFONT (font
, FRAME_FONT (f
));
6001 font_param
= Ffont_get (font
, intern (":name"));
6002 if (STRINGP (font_param
))
6003 default_name
= xstrdup (SSDATA (font_param
));
6006 font_param
= Fframe_parameter (frame
, Qfont_param
);
6007 if (STRINGP (font_param
))
6008 default_name
= xstrdup (SSDATA (font_param
));
6011 font
= xg_get_font (f
, default_name
);
6012 xfree (default_name
);
6017 Fsignal (Qquit
, Qnil
);
6019 return unbind_to (count
, font
);
6021 #endif /* HAVE_FREETYPE */
6023 #endif /* USE_GTK */
6026 /***********************************************************************
6028 ***********************************************************************/
6031 #include <X11/XKBlib.h>
6032 #include <X11/keysym.h>
6035 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
6036 Sx_backspace_delete_keys_p
, 0, 1, 0,
6037 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
6038 FRAME nil means use the selected frame.
6039 Value is t if we know that both keys are present, and are mapped to the
6040 usual X keysyms. Value is `lambda' if we cannot determine if both keys are
6041 present and mapped to the usual X keysyms. */)
6048 struct frame
*f
= decode_window_system_frame (frame
);
6049 Display
*dpy
= FRAME_X_DISPLAY (f
);
6050 Lisp_Object have_keys
;
6051 int major
, minor
, op
, event
, error_code
;
6055 /* Check library version in case we're dynamically linked. */
6056 major
= XkbMajorVersion
;
6057 minor
= XkbMinorVersion
;
6058 if (!XkbLibraryVersion (&major
, &minor
))
6064 /* Check that the server supports XKB. */
6065 major
= XkbMajorVersion
;
6066 minor
= XkbMinorVersion
;
6067 if (!XkbQueryExtension (dpy
, &op
, &event
, &error_code
, &major
, &minor
))
6073 /* In this code we check that the keyboard has physical keys with names
6074 that start with BKSP (Backspace) and DELE (Delete), and that they
6075 generate keysym XK_BackSpace and XK_Delete respectively.
6076 This function is used to test if normal-erase-is-backspace should be
6078 An alternative approach would be to just check if XK_BackSpace and
6079 XK_Delete are mapped to any key. But if any of those are mapped to
6080 some non-intuitive key combination (Meta-Shift-Ctrl-whatever) and the
6081 user doesn't know about it, it is better to return false here.
6082 It is more obvious to the user what to do if she/he has two keys
6083 clearly marked with names/symbols and one key does something not
6084 expected (i.e. she/he then tries the other).
6085 The cases where Backspace/Delete is mapped to some other key combination
6086 are rare, and in those cases, normal-erase-is-backspace can be turned on
6090 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
6093 int delete_keycode
= 0, backspace_keycode
= 0, i
;
6095 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
6097 for (i
= kb
->min_key_code
;
6098 (i
< kb
->max_key_code
6099 && (delete_keycode
== 0 || backspace_keycode
== 0));
6102 /* The XKB symbolic key names can be seen most easily in
6103 the PS file generated by `xkbprint -label name
6105 if (memcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
6107 else if (memcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
6108 backspace_keycode
= i
;
6111 XkbFreeNames (kb
, 0, True
);
6114 XkbFreeClientMap (kb
, 0, True
);
6117 && backspace_keycode
6118 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
6119 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
6129 /***********************************************************************
6131 ***********************************************************************/
6133 /* Keep this list in the same order as frame_parms in frame.c.
6134 Use 0 for unsupported frame parameters. */
6136 frame_parm_handler x_frame_parm_handlers
[] =
6140 x_set_background_color
,
6146 x_set_foreground_color
,
6149 x_set_internal_border_width
,
6150 x_set_menu_bar_lines
,
6152 x_explicitly_set_name
,
6153 x_set_scroll_bar_width
,
6156 x_set_vertical_scroll_bars
,
6158 x_set_tool_bar_lines
,
6159 x_set_scroll_bar_foreground
,
6160 x_set_scroll_bar_background
,
6170 x_set_tool_bar_position
,
6176 /* The section below is built by the lisp expression at the top of the file,
6177 just above where these variables are declared. */
6178 /*&&& init symbols here &&&*/
6179 DEFSYM (Qsuppress_icon
, "suppress-icon");
6180 DEFSYM (Qundefined_color
, "undefined-color");
6181 DEFSYM (Qcompound_text
, "compound-text");
6182 DEFSYM (Qcancel_timer
, "cancel-timer");
6183 DEFSYM (Qfont_param
, "font-parameter");
6184 /* This is the end of symbol initialization. */
6186 Fput (Qundefined_color
, Qerror_conditions
,
6187 listn (CONSTYPE_PURE
, 2, Qundefined_color
, Qerror
));
6188 Fput (Qundefined_color
, Qerror_message
,
6189 build_pure_c_string ("Undefined color"));
6191 DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape
,
6192 doc
: /* The shape of the pointer when over text.
6193 Changing the value does not affect existing frames
6194 unless you set the mouse color. */);
6195 Vx_pointer_shape
= Qnil
;
6197 #if 0 /* This doesn't really do anything. */
6198 DEFVAR_LISP ("x-nontext-pointer-shape", Vx_nontext_pointer_shape
,
6199 doc
: /* The shape of the pointer when not over text.
6200 This variable takes effect when you create a new frame
6201 or when you set the mouse color. */);
6203 Vx_nontext_pointer_shape
= Qnil
;
6205 DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape
,
6206 doc
: /* The shape of the pointer when Emacs is busy.
6207 This variable takes effect when you create a new frame
6208 or when you set the mouse color. */);
6209 Vx_hourglass_pointer_shape
= Qnil
;
6211 #if 0 /* This doesn't really do anything. */
6212 DEFVAR_LISP ("x-mode-pointer-shape", Vx_mode_pointer_shape
,
6213 doc
: /* The shape of the pointer when over the mode line.
6214 This variable takes effect when you create a new frame
6215 or when you set the mouse color. */);
6217 Vx_mode_pointer_shape
= Qnil
;
6219 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
6220 Vx_sensitive_text_pointer_shape
,
6221 doc
: /* The shape of the pointer when over mouse-sensitive text.
6222 This variable takes effect when you create a new frame
6223 or when you set the mouse color. */);
6224 Vx_sensitive_text_pointer_shape
= Qnil
;
6226 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
6227 Vx_window_horizontal_drag_shape
,
6228 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
6229 This variable takes effect when you create a new frame
6230 or when you set the mouse color. */);
6231 Vx_window_horizontal_drag_shape
= Qnil
;
6233 DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel
,
6234 doc
: /* A string indicating the foreground color of the cursor box. */);
6235 Vx_cursor_fore_pixel
= Qnil
;
6237 DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size
,
6238 doc
: /* Maximum size for tooltips.
6239 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
6240 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
6242 DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager
,
6243 doc
: /* Non-nil if no X window manager is in use.
6244 Emacs doesn't try to figure this out; this is always nil
6245 unless you set it to something else. */);
6246 /* We don't have any way to find this out, so set it to nil
6247 and maybe the user would like to set it to t. */
6248 Vx_no_window_manager
= Qnil
;
6250 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
6251 Vx_pixel_size_width_font_regexp
,
6252 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
6254 Since Emacs gets width of a font matching with this regexp from
6255 PIXEL_SIZE field of the name, font finding mechanism gets faster for
6256 such a font. This is especially effective for such large fonts as
6257 Chinese, Japanese, and Korean. */);
6258 Vx_pixel_size_width_font_regexp
= Qnil
;
6260 /* This is not ifdef:ed, so other builds than GTK can customize it. */
6261 DEFVAR_BOOL ("x-gtk-use-old-file-dialog", x_gtk_use_old_file_dialog
,
6262 doc
: /* Non-nil means prompt with the old GTK file selection dialog.
6263 If nil or if the file selection dialog is not available, the new GTK file
6264 chooser is used instead. To turn off all file dialogs set the
6265 variable `use-file-dialog'. */);
6266 x_gtk_use_old_file_dialog
= 0;
6268 DEFVAR_BOOL ("x-gtk-show-hidden-files", x_gtk_show_hidden_files
,
6269 doc
: /* If non-nil, the GTK file chooser will by default show hidden files.
6270 Note that this is just the default, there is a toggle button on the file
6271 chooser to show or not show hidden files on a case by case basis. */);
6272 x_gtk_show_hidden_files
= 0;
6274 DEFVAR_BOOL ("x-gtk-file-dialog-help-text", x_gtk_file_dialog_help_text
,
6275 doc
: /* If non-nil, the GTK file chooser will show additional help text.
6276 If more space for files in the file chooser dialog is wanted, set this to nil
6277 to turn the additional text off. */);
6278 x_gtk_file_dialog_help_text
= 1;
6280 DEFVAR_BOOL ("x-gtk-whole-detached-tool-bar", x_gtk_whole_detached_tool_bar
,
6281 doc
: /* If non-nil, a detached tool bar is shown in full.
6282 The default is to just show an arrow and pressing on that arrow shows
6283 the tool bar buttons. */);
6284 x_gtk_whole_detached_tool_bar
= 0;
6286 DEFVAR_BOOL ("x-gtk-use-system-tooltips", x_gtk_use_system_tooltips
,
6287 doc
: /* If non-nil with a Gtk+ built Emacs, the Gtk+ tooltip is used.
6288 Otherwise use Emacs own tooltip implementation.
6289 When using Gtk+ tooltips, the tooltip face is not used. */);
6290 x_gtk_use_system_tooltips
= 1;
6292 /* Tell Emacs about this window system. */
6293 Fprovide (Qx
, Qnil
);
6295 #ifdef USE_X_TOOLKIT
6296 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
6298 Fprovide (intern_c_string ("motif"), Qnil
);
6300 DEFVAR_LISP ("motif-version-string", Vmotif_version_string
,
6301 doc
: /* Version info for LessTif/Motif. */);
6302 Vmotif_version_string
= build_string (XmVERSION_STRING
);
6303 #endif /* USE_MOTIF */
6304 #endif /* USE_X_TOOLKIT */
6307 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
6308 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
6309 But for a user it is a toolkit for X, and indeed, configure
6310 accepts --with-x-toolkit=gtk. */
6311 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
6312 Fprovide (intern_c_string ("gtk"), Qnil
);
6313 Fprovide (intern_c_string ("move-toolbar"), Qnil
);
6315 DEFVAR_LISP ("gtk-version-string", Vgtk_version_string
,
6316 doc
: /* Version info for GTK+. */);
6318 char gtk_version
[sizeof ".." + 3 * INT_STRLEN_BOUND (int)];
6319 int len
= sprintf (gtk_version
, "%d.%d.%d",
6320 GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
);
6321 Vgtk_version_string
= make_pure_string (gtk_version
, len
, len
, 0);
6323 #endif /* USE_GTK */
6325 /* X window properties. */
6326 defsubr (&Sx_change_window_property
);
6327 defsubr (&Sx_delete_window_property
);
6328 defsubr (&Sx_window_property
);
6330 defsubr (&Sxw_display_color_p
);
6331 defsubr (&Sx_display_grayscale_p
);
6332 defsubr (&Sxw_color_defined_p
);
6333 defsubr (&Sxw_color_values
);
6334 defsubr (&Sx_server_max_request_size
);
6335 defsubr (&Sx_server_vendor
);
6336 defsubr (&Sx_server_version
);
6337 defsubr (&Sx_display_pixel_width
);
6338 defsubr (&Sx_display_pixel_height
);
6339 defsubr (&Sx_display_mm_width
);
6340 defsubr (&Sx_display_mm_height
);
6341 defsubr (&Sx_display_screens
);
6342 defsubr (&Sx_display_planes
);
6343 defsubr (&Sx_display_color_cells
);
6344 defsubr (&Sx_display_visual_class
);
6345 defsubr (&Sx_display_backing_store
);
6346 defsubr (&Sx_display_save_under
);
6347 defsubr (&Sx_display_monitor_attributes_list
);
6348 defsubr (&Sx_wm_set_size_hint
);
6349 defsubr (&Sx_create_frame
);
6350 defsubr (&Sx_open_connection
);
6351 defsubr (&Sx_close_connection
);
6352 defsubr (&Sx_display_list
);
6353 defsubr (&Sx_synchronize
);
6354 defsubr (&Sx_focus_frame
);
6355 defsubr (&Sx_backspace_delete_keys_p
);
6357 defsubr (&Sx_show_tip
);
6358 defsubr (&Sx_hide_tip
);
6360 staticpro (&tip_timer
);
6362 staticpro (&tip_frame
);
6364 last_show_tip_args
= Qnil
;
6365 staticpro (&last_show_tip_args
);
6367 defsubr (&Sx_uses_old_gtk_dialog
);
6368 #if defined (USE_MOTIF) || defined (USE_GTK)
6369 defsubr (&Sx_file_dialog
);
6372 #if defined (USE_GTK) && defined (HAVE_FREETYPE)
6373 defsubr (&Sx_select_font
);
6377 #endif /* HAVE_X_WINDOWS */