1 /* Functions for the X window system.
3 Copyright (C) 1989, 1992-2015 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
30 #include "character.h"
32 #include "intervals.h"
33 #include "dispextern.h"
35 #include "blockinput.h"
41 #include "termhooks.h"
46 #include <sys/types.h>
49 #include "bitmaps/gray.xbm"
50 #include "xsettings.h"
53 #include <X11/extensions/Xrandr.h>
56 #include <X11/extensions/Xinerama.h>
64 #include <X11/Shell.h>
68 #include <X11/Xaw3d/Paned.h>
69 #include <X11/Xaw3d/Label.h>
70 #else /* !HAVE_XAW3D */
71 #include <X11/Xaw/Paned.h>
72 #include <X11/Xaw/Label.h>
73 #endif /* HAVE_XAW3D */
74 #endif /* USE_MOTIF */
77 #undef USG /* ####KLUDGE for Solaris 2.2 and up */
80 #ifdef USG /* Pacify gcc -Wunused-macros. */
88 #include "../lwlib/lwlib.h"
92 #include <Xm/DialogS.h>
93 #include <Xm/FileSB.h>
99 #include "../lwlib/xlwmenu.h"
102 #if !defined (NO_EDITRES)
104 extern void _XEditResCheckMessages (Widget
, XtPointer
, XEvent
*, Boolean
*);
105 #endif /* not defined NO_EDITRES */
107 /* Unique id counter for widgets created by the Lucid Widget Library. */
109 extern LWLIB_ID widget_id_tick
;
113 #endif /* USE_MOTIF */
115 #endif /* USE_X_TOOLKIT */
121 #define MAXREQUEST(dpy) (XMaxRequestSize (dpy))
123 static ptrdiff_t image_cache_refcount
;
125 static int dpyinfo_refcount
;
128 static struct x_display_info
*x_display_info_for_name (Lisp_Object
);
130 /* Let the user specify an X display with a Lisp object.
131 OBJECT may be nil, a frame or a terminal object.
132 nil stands for the selected frame--or, if that is not an X frame,
133 the first X display on the list. */
135 struct x_display_info
*
136 check_x_display_info (Lisp_Object object
)
138 struct x_display_info
*dpyinfo
= NULL
;
142 struct frame
*sf
= XFRAME (selected_frame
);
144 if (FRAME_X_P (sf
) && FRAME_LIVE_P (sf
))
145 dpyinfo
= FRAME_DISPLAY_INFO (sf
);
146 else if (x_display_list
!= 0)
147 dpyinfo
= x_display_list
;
149 error ("X windows are not in use or not initialized");
151 else if (TERMINALP (object
))
153 struct terminal
*t
= decode_live_terminal (object
);
155 if (t
->type
!= output_x_window
)
156 error ("Terminal %d is not an X display", t
->id
);
158 dpyinfo
= t
->display_info
.x
;
160 else if (STRINGP (object
))
161 dpyinfo
= x_display_info_for_name (object
);
164 struct frame
*f
= decode_window_system_frame (object
);
165 dpyinfo
= FRAME_DISPLAY_INFO (f
);
171 /* Return the screen positions and offsets of frame F.
172 Store the offsets between FRAME_OUTER_WINDOW and the containing
173 window manager window into LEFT_OFFSET_X, RIGHT_OFFSET_X,
174 TOP_OFFSET_Y and BOTTOM_OFFSET_Y.
175 Store the offsets between FRAME_X_WINDOW and the containing
176 window manager window into X_PIXELS_DIFF and Y_PIXELS_DIFF.
177 Store the screen positions of frame F into XPTR and YPTR.
178 These are the positions of the containing window manager window,
179 not Emacs's own window. */
181 x_real_pos_and_offsets (struct frame
*f
,
185 int *bottom_offset_y
,
192 int win_x
, win_y
, outer_x
IF_LINT (= 0), outer_y
IF_LINT (= 0);
193 int real_x
= 0, real_y
= 0;
194 bool had_errors
= false;
195 Window win
= f
->output_data
.x
->parent_desc
;
197 unsigned long actual_size
, bytes_remaining
;
198 int rc
, actual_format
;
199 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
201 Display
*dpy
= FRAME_X_DISPLAY (f
);
202 unsigned char *tmp_data
= NULL
;
203 Atom target_type
= XA_CARDINAL
;
204 unsigned int ow
IF_LINT (= 0), oh
IF_LINT (= 0);
208 x_catch_errors (dpy
);
210 if (x_pixels_diff
) *x_pixels_diff
= 0;
211 if (y_pixels_diff
) *y_pixels_diff
= 0;
212 if (left_offset_x
) *left_offset_x
= 0;
213 if (top_offset_y
) *top_offset_y
= 0;
214 if (right_offset_x
) *right_offset_x
= 0;
215 if (bottom_offset_y
) *bottom_offset_y
= 0;
218 if (outer_border
) *outer_border
= 0;
220 if (win
== dpyinfo
->root_window
)
221 win
= FRAME_OUTER_WINDOW (f
);
223 /* This loop traverses up the containment tree until we hit the root
224 window. Window managers may intersect many windows between our window
225 and the root window. The window we find just before the root window
226 should be the outer WM window. */
229 Window wm_window
, rootw
;
230 Window
*tmp_children
;
231 unsigned int tmp_nchildren
;
234 success
= XQueryTree (FRAME_X_DISPLAY (f
), win
, &rootw
,
235 &wm_window
, &tmp_children
, &tmp_nchildren
);
237 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
239 /* Don't free tmp_children if XQueryTree failed. */
243 XFree (tmp_children
);
245 if (wm_window
== rootw
|| had_errors
)
256 /* Get the real coordinates for the WM window upper left corner */
257 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
258 &rootw
, &real_x
, &real_y
, &ow
, &oh
, &ign
, &ign
);
262 XWindowAttributes atts
;
263 XGetWindowAttributes (FRAME_X_DISPLAY (f
), win
, &atts
);
264 *outer_border
= atts
.border_width
;
267 /* Translate real coordinates to coordinates relative to our
268 window. For our window, the upper left corner is 0, 0.
269 Since the upper left corner of the WM window is outside
270 our window, win_x and win_y will be negative:
272 ------------------ ---> x
274 | ----------------- v y
277 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
279 /* From-window, to-window. */
280 FRAME_DISPLAY_INFO (f
)->root_window
,
283 /* From-position, to-position. */
284 real_x
, real_y
, &win_x
, &win_y
,
289 if (FRAME_X_WINDOW (f
) == FRAME_OUTER_WINDOW (f
))
296 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
298 /* From-window, to-window. */
299 FRAME_DISPLAY_INFO (f
)->root_window
,
300 FRAME_OUTER_WINDOW (f
),
302 /* From-position, to-position. */
303 real_x
, real_y
, &outer_x
, &outer_y
,
309 had_errors
= x_had_errors_p (FRAME_X_DISPLAY (f
));
313 if (dpyinfo
->root_window
== f
->output_data
.x
->parent_desc
)
315 /* Try _NET_FRAME_EXTENTS if our parent is the root window. */
316 rc
= XGetWindowProperty (dpy
, win
, dpyinfo
->Xatom_net_frame_extents
,
317 0, max_len
, False
, target_type
,
318 &actual_type
, &actual_format
, &actual_size
,
319 &bytes_remaining
, &tmp_data
);
321 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
322 && actual_size
== 4 && actual_format
== 32)
326 long *fe
= (long *)tmp_data
;
328 XGetGeometry (FRAME_X_DISPLAY (f
), win
,
329 &rootw
, &real_x
, &real_y
, &ign
, &ign
, &ign
, &ign
);
337 if (tmp_data
) XFree (tmp_data
);
343 if (had_errors
) return;
345 if (x_pixels_diff
) *x_pixels_diff
= -win_x
;
346 if (y_pixels_diff
) *y_pixels_diff
= -win_y
;
348 if (left_offset_x
) *left_offset_x
= -outer_x
;
349 if (top_offset_y
) *top_offset_y
= -outer_y
;
351 if (xptr
) *xptr
= real_x
;
352 if (yptr
) *yptr
= real_y
;
354 if (right_offset_x
|| bottom_offset_y
)
357 unsigned int ign
, fw
, fh
;
360 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
361 &rootw
, &xy_ign
, &xy_ign
, &fw
, &fh
, &ign
, &ign
);
362 if (right_offset_x
) *right_offset_x
= ow
- fw
+ outer_x
;
363 if (bottom_offset_y
) *bottom_offset_y
= oh
- fh
+ outer_y
;
367 /* Store the screen positions of frame F into XPTR and YPTR.
368 These are the positions of the containing window manager window,
369 not Emacs's own window. */
372 x_real_positions (struct frame
*f
, int *xptr
, int *yptr
)
374 x_real_pos_and_offsets (f
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, xptr
, yptr
,
379 /* Get the mouse position in frame relative coordinates. */
382 x_relative_mouse_position (struct frame
*f
, int *x
, int *y
)
384 Window root
, dummy_window
;
387 eassert (FRAME_X_P (f
));
391 XQueryPointer (FRAME_X_DISPLAY (f
),
392 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
394 /* The root window which contains the pointer. */
397 /* Window pointer is on, not used */
400 /* The position on that root window. */
403 /* x/y in dummy_window coordinates, not used. */
406 /* Modifier keys and pointer buttons, about which
408 (unsigned int *) &dummy
);
410 XTranslateCoordinates (FRAME_X_DISPLAY (f
),
412 /* From-window, to-window. */
413 FRAME_DISPLAY_INFO (f
)->root_window
,
416 /* From-position, to-position. */
425 /* Gamma-correct COLOR on frame F. */
428 gamma_correct (struct frame
*f
, XColor
*color
)
432 color
->red
= pow (color
->red
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
433 color
->green
= pow (color
->green
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
434 color
->blue
= pow (color
->blue
/ 65535.0, f
->gamma
) * 65535.0 + 0.5;
439 /* Decide if color named COLOR_NAME is valid for use on frame F. If
440 so, return the RGB values in COLOR. If ALLOC_P,
441 allocate the color. Value is false if COLOR_NAME is invalid, or
442 no color could be allocated. */
445 x_defined_color (struct frame
*f
, const char *color_name
,
446 XColor
*color
, bool alloc_p
)
448 bool success_p
= false;
449 Display
*dpy
= FRAME_X_DISPLAY (f
);
450 Colormap cmap
= FRAME_X_COLORMAP (f
);
454 success_p
= xg_check_special_colors (f
, color_name
, color
);
457 success_p
= XParseColor (dpy
, cmap
, color_name
, color
) != 0;
458 if (success_p
&& alloc_p
)
459 success_p
= x_alloc_nearest_color (f
, cmap
, color
);
466 /* Return the pixel color value for color COLOR_NAME on frame F. If F
467 is a monochrome frame, return MONO_COLOR regardless of what ARG says.
468 Signal an error if color can't be allocated. */
471 x_decode_color (struct frame
*f
, Lisp_Object color_name
, int mono_color
)
475 CHECK_STRING (color_name
);
477 #if false /* Don't do this. It's wrong when we're not using the default
478 colormap, it makes freeing difficult, and it's probably not
479 an important optimization. */
480 if (strcmp (SDATA (color_name
), "black") == 0)
481 return BLACK_PIX_DEFAULT (f
);
482 else if (strcmp (SDATA (color_name
), "white") == 0)
483 return WHITE_PIX_DEFAULT (f
);
486 /* Return MONO_COLOR for monochrome frames. */
487 if (FRAME_DISPLAY_INFO (f
)->n_planes
== 1)
490 /* x_defined_color is responsible for coping with failures
491 by looking for a near-miss. */
492 if (x_defined_color (f
, SSDATA (color_name
), &cdef
, true))
495 signal_error ("Undefined color", color_name
);
500 /* Change the `wait-for-wm' frame parameter of frame F. OLD_VALUE is
501 the previous value of that parameter, NEW_VALUE is the new value.
502 See also the comment of wait_for_wm in struct x_output. */
505 x_set_wait_for_wm (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
507 f
->output_data
.x
->wait_for_wm
= !NILP (new_value
);
511 x_set_tool_bar_position (struct frame
*f
,
512 Lisp_Object new_value
,
513 Lisp_Object old_value
)
515 Lisp_Object choice
= list4 (Qleft
, Qright
, Qtop
, Qbottom
);
517 if (!NILP (Fmemq (new_value
, choice
)))
520 if (!EQ (new_value
, old_value
))
522 xg_change_toolbar_position (f
, new_value
);
523 fset_tool_bar_position (f
, new_value
);
526 if (!EQ (new_value
, Qtop
))
527 error ("The only supported tool bar position is top");
531 wrong_choice (choice
, new_value
);
536 /* Set icon from FILE for frame F. By using GTK functions the icon
537 may be any format that GdkPixbuf knows about, i.e. not just bitmaps. */
540 xg_set_icon (struct frame
*f
, Lisp_Object file
)
545 found
= x_find_image_file (file
);
551 char *filename
= SSDATA (ENCODE_FILE (found
));
554 pixbuf
= gdk_pixbuf_new_from_file (filename
, &err
);
558 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
560 g_object_unref (pixbuf
);
574 xg_set_icon_from_xpm_data (struct frame
*f
, const char **data
)
576 GdkPixbuf
*pixbuf
= gdk_pixbuf_new_from_xpm_data (data
);
581 gtk_window_set_icon (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)), pixbuf
);
582 g_object_unref (pixbuf
);
588 /* Functions called only from `x_set_frame_param'
589 to set individual parameters.
591 If FRAME_X_WINDOW (f) is 0,
592 the frame is being created and its X-window does not exist yet.
593 In that case, just record the parameter's new value
594 in the standard place; do not attempt to change the window. */
597 x_set_foreground_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
599 struct x_output
*x
= f
->output_data
.x
;
600 unsigned long fg
, old_fg
;
602 fg
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
603 old_fg
= FRAME_FOREGROUND_PIXEL (f
);
604 FRAME_FOREGROUND_PIXEL (f
) = fg
;
606 if (FRAME_X_WINDOW (f
) != 0)
608 Display
*dpy
= FRAME_X_DISPLAY (f
);
611 XSetForeground (dpy
, x
->normal_gc
, fg
);
612 XSetBackground (dpy
, x
->reverse_gc
, fg
);
614 if (x
->cursor_pixel
== old_fg
)
616 unload_color (f
, x
->cursor_pixel
);
617 x
->cursor_pixel
= x_copy_color (f
, fg
);
618 XSetBackground (dpy
, x
->cursor_gc
, x
->cursor_pixel
);
623 update_face_from_frame_parameter (f
, Qforeground_color
, arg
);
625 if (FRAME_VISIBLE_P (f
))
629 unload_color (f
, old_fg
);
633 x_set_background_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
635 struct x_output
*x
= f
->output_data
.x
;
638 bg
= x_decode_color (f
, arg
, WHITE_PIX_DEFAULT (f
));
639 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
640 FRAME_BACKGROUND_PIXEL (f
) = bg
;
642 if (FRAME_X_WINDOW (f
) != 0)
644 Display
*dpy
= FRAME_X_DISPLAY (f
);
647 XSetBackground (dpy
, x
->normal_gc
, bg
);
648 XSetForeground (dpy
, x
->reverse_gc
, bg
);
649 XSetWindowBackground (dpy
, FRAME_X_WINDOW (f
), bg
);
650 XSetForeground (dpy
, x
->cursor_gc
, bg
);
653 xg_set_background_color (f
, bg
);
656 #ifndef USE_TOOLKIT_SCROLL_BARS /* Turns out to be annoying with
657 toolkit scroll bars. */
660 for (bar
= FRAME_SCROLL_BARS (f
);
662 bar
= XSCROLL_BAR (bar
)->next
)
664 Window window
= XSCROLL_BAR (bar
)->x_window
;
665 XSetWindowBackground (dpy
, window
, bg
);
668 #endif /* USE_TOOLKIT_SCROLL_BARS */
671 update_face_from_frame_parameter (f
, Qbackground_color
, arg
);
673 if (FRAME_VISIBLE_P (f
))
679 x_set_mouse_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
681 struct x_output
*x
= f
->output_data
.x
;
682 Display
*dpy
= FRAME_X_DISPLAY (f
);
683 Cursor cursor
, nontext_cursor
, mode_cursor
, hand_cursor
;
684 Cursor hourglass_cursor
, horizontal_drag_cursor
, vertical_drag_cursor
;
685 unsigned long pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
686 unsigned long mask_color
= FRAME_BACKGROUND_PIXEL (f
);
688 /* Don't let pointers be invisible. */
689 if (mask_color
== pixel
)
691 x_free_colors (f
, &pixel
, 1);
692 pixel
= x_copy_color (f
, FRAME_FOREGROUND_PIXEL (f
));
695 unload_color (f
, x
->mouse_pixel
);
696 x
->mouse_pixel
= pixel
;
700 /* It's not okay to crash if the user selects a screwy cursor. */
701 x_catch_errors (dpy
);
703 if (!NILP (Vx_pointer_shape
))
705 CHECK_NUMBER (Vx_pointer_shape
);
706 cursor
= XCreateFontCursor (dpy
, XINT (Vx_pointer_shape
));
709 cursor
= XCreateFontCursor (dpy
, XC_xterm
);
710 x_check_errors (dpy
, "bad text pointer cursor: %s");
712 if (!NILP (Vx_nontext_pointer_shape
))
714 CHECK_NUMBER (Vx_nontext_pointer_shape
);
716 = XCreateFontCursor (dpy
, XINT (Vx_nontext_pointer_shape
));
719 nontext_cursor
= XCreateFontCursor (dpy
, XC_left_ptr
);
720 x_check_errors (dpy
, "bad nontext pointer cursor: %s");
722 if (!NILP (Vx_hourglass_pointer_shape
))
724 CHECK_NUMBER (Vx_hourglass_pointer_shape
);
726 = XCreateFontCursor (dpy
, XINT (Vx_hourglass_pointer_shape
));
729 hourglass_cursor
= XCreateFontCursor (dpy
, XC_watch
);
730 x_check_errors (dpy
, "bad hourglass pointer cursor: %s");
732 if (!NILP (Vx_mode_pointer_shape
))
734 CHECK_NUMBER (Vx_mode_pointer_shape
);
735 mode_cursor
= XCreateFontCursor (dpy
, XINT (Vx_mode_pointer_shape
));
738 mode_cursor
= XCreateFontCursor (dpy
, XC_xterm
);
739 x_check_errors (dpy
, "bad modeline pointer cursor: %s");
741 if (!NILP (Vx_sensitive_text_pointer_shape
))
743 CHECK_NUMBER (Vx_sensitive_text_pointer_shape
);
745 = XCreateFontCursor (dpy
, XINT (Vx_sensitive_text_pointer_shape
));
748 hand_cursor
= XCreateFontCursor (dpy
, XC_hand2
);
750 if (!NILP (Vx_window_horizontal_drag_shape
))
752 CHECK_TYPE_RANGED_INTEGER (unsigned, Vx_window_horizontal_drag_shape
);
753 horizontal_drag_cursor
754 = XCreateFontCursor (dpy
, XINT (Vx_window_horizontal_drag_shape
));
757 horizontal_drag_cursor
758 = XCreateFontCursor (dpy
, XC_sb_h_double_arrow
);
760 if (!NILP (Vx_window_vertical_drag_shape
))
762 CHECK_NUMBER (Vx_window_vertical_drag_shape
);
764 = XCreateFontCursor (dpy
, XINT (Vx_window_vertical_drag_shape
));
768 = XCreateFontCursor (dpy
, XC_sb_v_double_arrow
);
770 /* Check and report errors with the above calls. */
771 x_check_errors (dpy
, "can't set cursor shape: %s");
775 XColor fore_color
, back_color
;
777 fore_color
.pixel
= x
->mouse_pixel
;
778 x_query_color (f
, &fore_color
);
779 back_color
.pixel
= mask_color
;
780 x_query_color (f
, &back_color
);
782 XRecolorCursor (dpy
, cursor
, &fore_color
, &back_color
);
783 XRecolorCursor (dpy
, nontext_cursor
, &fore_color
, &back_color
);
784 XRecolorCursor (dpy
, mode_cursor
, &fore_color
, &back_color
);
785 XRecolorCursor (dpy
, hand_cursor
, &fore_color
, &back_color
);
786 XRecolorCursor (dpy
, hourglass_cursor
, &fore_color
, &back_color
);
787 XRecolorCursor (dpy
, horizontal_drag_cursor
, &fore_color
, &back_color
);
788 XRecolorCursor (dpy
, vertical_drag_cursor
, &fore_color
, &back_color
);
791 if (FRAME_X_WINDOW (f
) != 0)
792 XDefineCursor (dpy
, FRAME_X_WINDOW (f
),
793 f
->output_data
.x
->current_cursor
= cursor
);
795 if (cursor
!= x
->text_cursor
796 && x
->text_cursor
!= 0)
797 XFreeCursor (dpy
, x
->text_cursor
);
798 x
->text_cursor
= cursor
;
800 if (nontext_cursor
!= x
->nontext_cursor
801 && x
->nontext_cursor
!= 0)
802 XFreeCursor (dpy
, x
->nontext_cursor
);
803 x
->nontext_cursor
= nontext_cursor
;
805 if (hourglass_cursor
!= x
->hourglass_cursor
806 && x
->hourglass_cursor
!= 0)
807 XFreeCursor (dpy
, x
->hourglass_cursor
);
808 x
->hourglass_cursor
= hourglass_cursor
;
810 if (mode_cursor
!= x
->modeline_cursor
811 && x
->modeline_cursor
!= 0)
812 XFreeCursor (dpy
, f
->output_data
.x
->modeline_cursor
);
813 x
->modeline_cursor
= mode_cursor
;
815 if (hand_cursor
!= x
->hand_cursor
816 && x
->hand_cursor
!= 0)
817 XFreeCursor (dpy
, x
->hand_cursor
);
818 x
->hand_cursor
= hand_cursor
;
820 if (horizontal_drag_cursor
!= x
->horizontal_drag_cursor
821 && x
->horizontal_drag_cursor
!= 0)
822 XFreeCursor (dpy
, x
->horizontal_drag_cursor
);
823 x
->horizontal_drag_cursor
= horizontal_drag_cursor
;
825 if (vertical_drag_cursor
!= x
->vertical_drag_cursor
826 && x
->vertical_drag_cursor
!= 0)
827 XFreeCursor (dpy
, x
->vertical_drag_cursor
);
828 x
->vertical_drag_cursor
= vertical_drag_cursor
;
833 update_face_from_frame_parameter (f
, Qmouse_color
, arg
);
837 x_set_cursor_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
839 unsigned long fore_pixel
, pixel
;
840 bool fore_pixel_allocated_p
= false, pixel_allocated_p
= false;
841 struct x_output
*x
= f
->output_data
.x
;
843 if (!NILP (Vx_cursor_fore_pixel
))
845 fore_pixel
= x_decode_color (f
, Vx_cursor_fore_pixel
,
846 WHITE_PIX_DEFAULT (f
));
847 fore_pixel_allocated_p
= true;
850 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
852 pixel
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
853 pixel_allocated_p
= true;
855 /* Make sure that the cursor color differs from the background color. */
856 if (pixel
== FRAME_BACKGROUND_PIXEL (f
))
858 if (pixel_allocated_p
)
860 x_free_colors (f
, &pixel
, 1);
861 pixel_allocated_p
= false;
864 pixel
= x
->mouse_pixel
;
865 if (pixel
== fore_pixel
)
867 if (fore_pixel_allocated_p
)
869 x_free_colors (f
, &fore_pixel
, 1);
870 fore_pixel_allocated_p
= false;
872 fore_pixel
= FRAME_BACKGROUND_PIXEL (f
);
876 unload_color (f
, x
->cursor_foreground_pixel
);
877 if (!fore_pixel_allocated_p
)
878 fore_pixel
= x_copy_color (f
, fore_pixel
);
879 x
->cursor_foreground_pixel
= fore_pixel
;
881 unload_color (f
, x
->cursor_pixel
);
882 if (!pixel_allocated_p
)
883 pixel
= x_copy_color (f
, pixel
);
884 x
->cursor_pixel
= pixel
;
886 if (FRAME_X_WINDOW (f
) != 0)
889 XSetBackground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, x
->cursor_pixel
);
890 XSetForeground (FRAME_X_DISPLAY (f
), x
->cursor_gc
, fore_pixel
);
893 if (FRAME_VISIBLE_P (f
))
895 x_update_cursor (f
, false);
896 x_update_cursor (f
, true);
900 update_face_from_frame_parameter (f
, Qcursor_color
, arg
);
903 /* Set the border-color of frame F to pixel value PIX.
904 Note that this does not fully take effect if done before
905 F has an x-window. */
908 x_set_border_pixel (struct frame
*f
, int pix
)
910 unload_color (f
, f
->output_data
.x
->border_pixel
);
911 f
->output_data
.x
->border_pixel
= pix
;
913 if (FRAME_X_WINDOW (f
) != 0 && f
->border_width
> 0)
916 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), pix
);
919 if (FRAME_VISIBLE_P (f
))
924 /* Set the border-color of frame F to value described by ARG.
925 ARG can be a string naming a color.
926 The border-color is used for the border that is drawn by the X server.
927 Note that this does not fully take effect if done before
928 F has an x-window; it must be redone when the window is created.
930 Note: this is done in two routines because of the way X10 works.
932 Note: under X11, this is normally the province of the window manager,
933 and so emacs's border colors may be overridden. */
936 x_set_border_color (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
941 pix
= x_decode_color (f
, arg
, BLACK_PIX_DEFAULT (f
));
942 x_set_border_pixel (f
, pix
);
943 update_face_from_frame_parameter (f
, Qborder_color
, arg
);
948 x_set_cursor_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
950 set_frame_cursor_types (f
, arg
);
954 x_set_icon_type (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
960 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
963 else if (!STRINGP (oldval
) && EQ (oldval
, Qnil
) == EQ (arg
, Qnil
))
968 result
= x_text_icon (f
,
969 SSDATA ((!NILP (f
->icon_name
)
973 result
= x_bitmap_icon (f
, arg
);
978 error ("No icon window available");
981 XFlush (FRAME_X_DISPLAY (f
));
986 x_set_icon_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
992 if (STRINGP (oldval
) && EQ (Fstring_equal (oldval
, arg
), Qt
))
995 else if (!NILP (arg
) || NILP (oldval
))
998 fset_icon_name (f
, arg
);
1000 if (f
->output_data
.x
->icon_bitmap
!= 0)
1005 result
= x_text_icon (f
,
1006 SSDATA ((!NILP (f
->icon_name
)
1015 error ("No icon window available");
1018 XFlush (FRAME_X_DISPLAY (f
));
1024 x_set_menu_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1027 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
1028 int olines
= FRAME_MENU_BAR_LINES (f
);
1031 /* Right now, menu bars don't work properly in minibuf-only frames;
1032 most of the commands try to apply themselves to the minibuffer
1033 frame itself, and get an error because you can't switch buffers
1034 in or split the minibuffer window. */
1035 if (FRAME_MINIBUF_ONLY_P (f
))
1038 if (TYPE_RANGED_INTEGERP (int, value
))
1039 nlines
= XINT (value
);
1043 /* Make sure we redisplay all windows in this frame. */
1044 windows_or_buffers_changed
= 59;
1046 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
1047 FRAME_MENU_BAR_LINES (f
) = 0;
1048 FRAME_MENU_BAR_HEIGHT (f
) = 0;
1051 FRAME_EXTERNAL_MENU_BAR (f
) = 1;
1052 if (FRAME_X_P (f
) && f
->output_data
.x
->menubar_widget
== 0)
1053 /* Make sure next redisplay shows the menu bar. */
1054 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= true;
1058 if (FRAME_EXTERNAL_MENU_BAR (f
) == 1)
1059 free_frame_menubar (f
);
1060 FRAME_EXTERNAL_MENU_BAR (f
) = 0;
1062 f
->output_data
.x
->menubar_widget
= 0;
1064 #else /* not USE_X_TOOLKIT && not USE_GTK */
1065 FRAME_MENU_BAR_LINES (f
) = nlines
;
1066 FRAME_MENU_BAR_HEIGHT (f
) = nlines
* FRAME_LINE_HEIGHT (f
);
1067 adjust_frame_size (f
, -1, -1, 2, true, Qmenu_bar_lines
);
1068 if (FRAME_X_WINDOW (f
))
1069 x_clear_under_internal_border (f
);
1071 /* If the menu bar height gets changed, the internal border below
1072 the top margin has to be cleared. Also, if the menu bar gets
1073 larger, the area for the added lines has to be cleared except for
1074 the first menu bar line that is to be drawn later. */
1075 if (nlines
!= olines
)
1077 int height
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1078 int width
= FRAME_PIXEL_WIDTH (f
);
1081 /* height can be zero here. */
1082 if (FRAME_X_WINDOW (f
) && height
> 0 && width
> 0)
1084 y
= FRAME_TOP_MARGIN_HEIGHT (f
);
1087 x_clear_area (f
, 0, y
, width
, height
);
1091 if (nlines
> 1 && nlines
> olines
)
1093 y
= (olines
== 0 ? 1 : olines
) * FRAME_LINE_HEIGHT (f
);
1094 height
= nlines
* FRAME_LINE_HEIGHT (f
) - y
;
1097 x_clear_area (f
, 0, y
, width
, height
);
1101 if (nlines
== 0 && WINDOWP (f
->menu_bar_window
))
1102 clear_glyph_matrix (XWINDOW (f
->menu_bar_window
)->current_matrix
);
1104 #endif /* not USE_X_TOOLKIT && not USE_GTK */
1105 adjust_frame_glyphs (f
);
1106 run_window_configuration_change_hook (f
);
1110 /* Set the number of lines used for the tool bar of frame F to VALUE.
1111 VALUE not an integer, or < 0 means set the lines to zero. OLDVAL
1112 is the old number of tool bar lines. This function changes the
1113 height of all windows on frame F to match the new tool bar height.
1114 The frame's height doesn't change. */
1117 x_set_tool_bar_lines (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1121 /* Treat tool bars like menu bars. */
1122 if (FRAME_MINIBUF_ONLY_P (f
))
1125 /* Use VALUE only if an int >= 0. */
1126 if (RANGED_INTEGERP (0, value
, INT_MAX
))
1127 nlines
= XFASTINT (value
);
1131 x_change_tool_bar_height (f
, nlines
* FRAME_LINE_HEIGHT (f
));
1135 /* Set the pixel height of the tool bar of frame F to HEIGHT. */
1137 x_change_tool_bar_height (struct frame
*f
, int height
)
1140 FRAME_TOOL_BAR_LINES (f
) = 0;
1141 FRAME_TOOL_BAR_HEIGHT (f
) = 0;
1144 FRAME_EXTERNAL_TOOL_BAR (f
) = true;
1145 if (FRAME_X_P (f
) && f
->output_data
.x
->toolbar_widget
== 0)
1146 /* Make sure next redisplay shows the tool bar. */
1147 XWINDOW (FRAME_SELECTED_WINDOW (f
))->update_mode_line
= true;
1148 update_frame_tool_bar (f
);
1152 if (FRAME_EXTERNAL_TOOL_BAR (f
))
1153 free_frame_tool_bar (f
);
1154 FRAME_EXTERNAL_TOOL_BAR (f
) = false;
1156 #else /* !USE_GTK */
1157 int unit
= FRAME_LINE_HEIGHT (f
);
1158 int old_height
= FRAME_TOOL_BAR_HEIGHT (f
);
1159 int lines
= (height
+ unit
- 1) / unit
;
1160 Lisp_Object fullscreen
;
1162 /* Make sure we redisplay all windows in this frame. */
1163 windows_or_buffers_changed
= 60;
1166 /* Recalculate tool bar and frame text sizes. */
1167 FRAME_TOOL_BAR_HEIGHT (f
) = height
;
1168 FRAME_TOOL_BAR_LINES (f
) = lines
;
1169 /* Store the `tool-bar-lines' and `height' frame parameters. */
1170 store_frame_param (f
, Qtool_bar_lines
, make_number (lines
));
1171 store_frame_param (f
, Qheight
, make_number (FRAME_LINES (f
)));
1173 /* We also have to make sure that the internal border at the top of
1174 the frame, below the menu bar or tool bar, is redrawn when the
1175 tool bar disappears. This is so because the internal border is
1176 below the tool bar if one is displayed, but is below the menu bar
1177 if there isn't a tool bar. The tool bar draws into the area
1178 below the menu bar. */
1179 if (FRAME_X_WINDOW (f
) && FRAME_TOOL_BAR_HEIGHT (f
) == 0)
1182 clear_current_matrices (f
);
1185 if ((height
< old_height
) && WINDOWP (f
->tool_bar_window
))
1186 clear_glyph_matrix (XWINDOW (f
->tool_bar_window
)->current_matrix
);
1188 /* Recalculate toolbar height. */
1189 f
->n_tool_bar_rows
= 0;
1191 adjust_frame_size (f
, -1, -1,
1192 ((NILP (fullscreen
= get_frame_param (f
, Qfullscreen
))
1193 || EQ (fullscreen
, Qfullwidth
)) ? 1
1194 : (old_height
== 0 || height
== 0) ? 2
1196 false, Qtool_bar_lines
);
1198 /* adjust_frame_size might not have done anything, garbage frame
1200 adjust_frame_glyphs (f
);
1201 SET_FRAME_GARBAGED (f
);
1202 if (FRAME_X_WINDOW (f
))
1203 x_clear_under_internal_border (f
);
1205 #endif /* USE_GTK */
1210 x_set_internal_border_width (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1214 CHECK_TYPE_RANGED_INTEGER (int, arg
);
1215 border
= max (XINT (arg
), 0);
1217 if (border
!= FRAME_INTERNAL_BORDER_WIDTH (f
))
1219 FRAME_INTERNAL_BORDER_WIDTH (f
) = border
;
1221 #ifdef USE_X_TOOLKIT
1222 if (FRAME_X_OUTPUT (f
)->edit_widget
)
1223 widget_store_internal_border (FRAME_X_OUTPUT (f
)->edit_widget
);
1226 if (FRAME_X_WINDOW (f
) != 0)
1228 adjust_frame_size (f
, -1, -1, 3, false, Qinternal_border_width
);
1231 xg_clear_under_internal_border (f
);
1233 x_clear_under_internal_border (f
);
1241 /* Set the foreground color for scroll bars on frame F to VALUE.
1242 VALUE should be a string, a color name. If it isn't a string or
1243 isn't a valid color name, do nothing. OLDVAL is the old value of
1244 the frame parameter. */
1247 x_set_scroll_bar_foreground (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1249 unsigned long pixel
;
1251 if (STRINGP (value
))
1252 pixel
= x_decode_color (f
, value
, BLACK_PIX_DEFAULT (f
));
1256 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
1257 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
1259 f
->output_data
.x
->scroll_bar_foreground_pixel
= pixel
;
1260 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1262 /* Remove all scroll bars because they have wrong colors. */
1263 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1264 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1265 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1266 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1268 update_face_from_frame_parameter (f
, Qscroll_bar_foreground
, value
);
1274 /* Set the background color for scroll bars on frame F to VALUE VALUE
1275 should be a string, a color name. If it isn't a string or isn't a
1276 valid color name, do nothing. OLDVAL is the old value of the frame
1280 x_set_scroll_bar_background (struct frame
*f
, Lisp_Object value
, Lisp_Object oldval
)
1282 unsigned long pixel
;
1284 if (STRINGP (value
))
1285 pixel
= x_decode_color (f
, value
, WHITE_PIX_DEFAULT (f
));
1289 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
1290 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
1292 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
1293 /* Scrollbar shadow colors. */
1294 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
1296 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
1297 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
1299 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
1301 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
1302 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
1304 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
1306 f
->output_data
.x
->scroll_bar_background_pixel
= pixel
;
1307 if (FRAME_X_WINDOW (f
) && FRAME_VISIBLE_P (f
))
1309 /* Remove all scroll bars because they have wrong colors. */
1310 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
1311 (*FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
) (f
);
1312 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
1313 (*FRAME_TERMINAL (f
)->judge_scroll_bars_hook
) (f
);
1315 update_face_from_frame_parameter (f
, Qscroll_bar_background
, value
);
1321 /* Encode Lisp string STRING as a text in a format appropriate for
1322 XICCC (X Inter Client Communication Conventions).
1324 If STRING contains only ASCII characters, do no conversion and
1325 return the string data of STRING. Otherwise, encode the text by
1326 CODING_SYSTEM, and return a newly allocated memory area which
1327 should be freed by `xfree' by a caller.
1329 Store the byte length of resulting text in *TEXT_BYTES.
1331 If the text contains only ASCII and Latin-1, store true in *STRING_P,
1332 which means that the `encoding' of the result can be `STRING'.
1333 Otherwise store false in *STRINGP, which means that the `encoding' of
1334 the result should be `COMPOUND_TEXT'. */
1336 static unsigned char *
1337 x_encode_text (Lisp_Object string
, Lisp_Object coding_system
,
1338 ptrdiff_t *text_bytes
, bool *stringp
, bool *freep
)
1340 int result
= string_xstring_p (string
);
1341 struct coding_system coding
;
1345 /* No multibyte character in OBJ. We need not encode it. */
1346 *text_bytes
= SBYTES (string
);
1349 return SDATA (string
);
1352 setup_coding_system (coding_system
, &coding
);
1353 coding
.mode
|= (CODING_MODE_SAFE_ENCODING
| CODING_MODE_LAST_BLOCK
);
1354 /* We suppress producing escape sequences for composition. */
1355 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
1356 coding
.destination
= xnmalloc (SCHARS (string
), 2);
1357 coding
.dst_bytes
= SCHARS (string
) * 2;
1358 encode_coding_object (&coding
, string
, 0, 0,
1359 SCHARS (string
), SBYTES (string
), Qnil
);
1360 *text_bytes
= coding
.produced
;
1361 *stringp
= (result
== 1 || !EQ (coding_system
, Qcompound_text
));
1363 return coding
.destination
;
1367 /* Set the WM name to NAME for frame F. Also set the icon name.
1368 If the frame already has an icon name, use that, otherwise set the
1369 icon name to NAME. */
1372 x_set_name_internal (struct frame
*f
, Lisp_Object name
)
1374 if (FRAME_X_WINDOW (f
))
1378 XTextProperty text
, icon
;
1381 bool do_free_icon_value
= false, do_free_text_value
= false;
1382 Lisp_Object coding_system
;
1383 Lisp_Object encoded_name
;
1384 Lisp_Object encoded_icon_name
;
1386 /* As ENCODE_UTF_8 may cause GC and relocation of string data,
1387 we use it before x_encode_text that may return string data. */
1388 encoded_name
= ENCODE_UTF_8 (name
);
1390 coding_system
= Qcompound_text
;
1391 /* Note: Encoding strategy
1393 We encode NAME by compound-text and use "COMPOUND-TEXT" in
1394 text.encoding. But, there are non-internationalized window
1395 managers which don't support that encoding. So, if NAME
1396 contains only ASCII and 8859-1 characters, encode it by
1397 iso-latin-1, and use "STRING" in text.encoding hoping that
1398 such window managers at least analyze this format correctly,
1399 i.e. treat 8-bit bytes as 8859-1 characters.
1401 We may also be able to use "UTF8_STRING" in text.encoding
1402 in the future which can encode all Unicode characters.
1403 But, for the moment, there's no way to know that the
1404 current window manager supports it or not.
1406 Either way, we also set the _NET_WM_NAME and _NET_WM_ICON_NAME
1407 properties. Per the EWMH specification, those two properties
1408 are always UTF8_STRING. This matches what gtk_window_set_title()
1409 does in the USE_GTK case. */
1410 text
.value
= x_encode_text (name
, coding_system
, &bytes
,
1411 &stringp
, &do_free_text_value
);
1412 text
.encoding
= (stringp
? XA_STRING
1413 : FRAME_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1415 text
.nitems
= bytes
;
1417 if (!STRINGP (f
->icon_name
))
1420 encoded_icon_name
= encoded_name
;
1424 /* See the above comment "Note: Encoding strategy". */
1425 icon
.value
= x_encode_text (f
->icon_name
, coding_system
, &bytes
,
1426 &stringp
, &do_free_icon_value
);
1427 icon
.encoding
= (stringp
? XA_STRING
1428 : FRAME_DISPLAY_INFO (f
)->Xatom_COMPOUND_TEXT
);
1430 icon
.nitems
= bytes
;
1432 encoded_icon_name
= ENCODE_UTF_8 (f
->icon_name
);
1436 gtk_window_set_title (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)),
1437 SSDATA (encoded_name
));
1438 #else /* not USE_GTK */
1439 XSetWMName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
1440 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1441 FRAME_DISPLAY_INFO (f
)->Xatom_net_wm_name
,
1442 FRAME_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1444 SDATA (encoded_name
),
1445 SBYTES (encoded_name
));
1446 #endif /* not USE_GTK */
1448 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &icon
);
1449 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
1450 FRAME_DISPLAY_INFO (f
)->Xatom_net_wm_icon_name
,
1451 FRAME_DISPLAY_INFO (f
)->Xatom_UTF8_STRING
,
1453 SDATA (encoded_icon_name
),
1454 SBYTES (encoded_icon_name
));
1456 if (do_free_icon_value
)
1458 if (do_free_text_value
)
1465 /* Change the name of frame F to NAME. If NAME is nil, set F's name to
1468 If EXPLICIT is true, that indicates that lisp code is setting the
1469 name; if NAME is a string, set F's name to NAME and set
1470 F->explicit_name; if NAME is Qnil, then clear F->explicit_name.
1472 If EXPLICIT is false, that indicates that Emacs redisplay code is
1473 suggesting a new name, which lisp code should override; if
1474 F->explicit_name is set, ignore the new name; otherwise, set it. */
1477 x_set_name (struct frame
*f
, Lisp_Object name
, bool explicit)
1479 /* Make sure that requests from lisp code override requests from
1480 Emacs redisplay code. */
1483 /* If we're switching from explicit to implicit, we had better
1484 update the mode lines and thereby update the title. */
1485 if (f
->explicit_name
&& NILP (name
))
1486 update_mode_lines
= 37;
1488 f
->explicit_name
= ! NILP (name
);
1490 else if (f
->explicit_name
)
1493 /* If NAME is nil, set the name to the x_id_name. */
1496 /* Check for no change needed in this very common case
1497 before we do any consing. */
1498 if (!strcmp (FRAME_DISPLAY_INFO (f
)->x_id_name
,
1501 name
= build_string (FRAME_DISPLAY_INFO (f
)->x_id_name
);
1504 CHECK_STRING (name
);
1506 /* Don't change the name if it's already NAME. */
1507 if (! NILP (Fstring_equal (name
, f
->name
)))
1510 fset_name (f
, name
);
1512 /* For setting the frame title, the title parameter should override
1513 the name parameter. */
1514 if (! NILP (f
->title
))
1517 x_set_name_internal (f
, name
);
1520 /* This function should be called when the user's lisp code has
1521 specified a name for the frame; the name will override any set by the
1524 x_explicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1526 x_set_name (f
, arg
, true);
1529 /* This function should be called by Emacs redisplay code to set the
1530 name; names set this way will never override names set by the user's
1533 x_implicitly_set_name (struct frame
*f
, Lisp_Object arg
, Lisp_Object oldval
)
1535 x_set_name (f
, arg
, false);
1538 /* Change the title of frame F to NAME.
1539 If NAME is nil, use the frame name as the title. */
1542 x_set_title (struct frame
*f
, Lisp_Object name
, Lisp_Object old_name
)
1544 /* Don't change the title if it's already NAME. */
1545 if (EQ (name
, f
->title
))
1548 update_mode_lines
= 38;
1550 fset_title (f
, name
);
1555 CHECK_STRING (name
);
1557 x_set_name_internal (f
, name
);
1561 x_set_scroll_bar_default_width (struct frame
*f
)
1563 int unit
= FRAME_COLUMN_WIDTH (f
);
1564 #ifdef USE_TOOLKIT_SCROLL_BARS
1566 int minw
= xg_get_default_scrollbar_width ();
1570 /* A minimum width of 14 doesn't look good for toolkit scroll bars. */
1571 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (minw
+ unit
- 1) / unit
;
1572 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) = minw
;
1574 /* The width of a non-toolkit scrollbar is 14 pixels. */
1575 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + unit
- 1) / unit
;
1576 FRAME_CONFIG_SCROLL_BAR_WIDTH (f
)
1577 = FRAME_CONFIG_SCROLL_BAR_COLS (f
) * unit
;
1582 x_set_scroll_bar_default_height (struct frame
*f
)
1584 int height
= FRAME_LINE_HEIGHT (f
);
1585 #ifdef USE_TOOLKIT_SCROLL_BARS
1587 int min_height
= xg_get_default_scrollbar_height ();
1589 int min_height
= 16;
1591 /* A minimum height of 14 doesn't look good for toolkit scroll bars. */
1592 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) = min_height
;
1593 FRAME_CONFIG_SCROLL_BAR_LINES (f
) = (min_height
+ height
- 1) / height
;
1595 /* The height of a non-toolkit scrollbar is 14 pixels. */
1596 FRAME_CONFIG_SCROLL_BAR_LINES (f
) = (14 + height
- 1) / height
;
1598 /* Use all of that space (aside from required margins) for the
1600 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f
) = 14;
1605 /* Record in frame F the specified or default value according to ALIST
1606 of the parameter named PROP (a Lisp symbol). If no value is
1607 specified for PROP, look for an X default for XPROP on the frame
1608 named NAME. If that is not found either, use the value DEFLT. */
1611 x_default_scroll_bar_color_parameter (struct frame
*f
,
1612 Lisp_Object alist
, Lisp_Object prop
,
1613 const char *xprop
, const char *xclass
,
1616 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1619 tem
= x_get_arg (dpyinfo
, alist
, prop
, xprop
, xclass
, RES_TYPE_STRING
);
1620 if (EQ (tem
, Qunbound
))
1622 #ifdef USE_TOOLKIT_SCROLL_BARS
1624 /* See if an X resource for the scroll bar color has been
1626 AUTO_STRING (foreground
, "foreground");
1627 AUTO_STRING (background
, "foreground");
1628 AUTO_STRING (verticalScrollBar
, "verticalScrollBar");
1629 tem
= (display_x_get_resource
1630 (dpyinfo
, foreground_p
? foreground
: background
,
1631 empty_unibyte_string
,
1633 empty_unibyte_string
));
1636 /* If nothing has been specified, scroll bars will use a
1637 toolkit-dependent default. Because these defaults are
1638 difficult to get at without actually creating a scroll
1639 bar, use nil to indicate that no color has been
1644 #else /* not USE_TOOLKIT_SCROLL_BARS */
1648 #endif /* not USE_TOOLKIT_SCROLL_BARS */
1651 AUTO_FRAME_ARG (arg
, prop
, tem
);
1652 x_set_frame_parameters (f
, arg
);
1659 #ifdef USE_X_TOOLKIT
1661 /* If the WM_PROTOCOLS property does not already contain WM_TAKE_FOCUS,
1662 WM_DELETE_WINDOW, and WM_SAVE_YOURSELF, then add them. (They may
1663 already be present because of the toolkit (Motif adds some of them,
1664 for example, but Xt doesn't). */
1667 hack_wm_protocols (struct frame
*f
, Widget widget
)
1669 Display
*dpy
= XtDisplay (widget
);
1670 Window w
= XtWindow (widget
);
1671 bool need_delete
= true;
1672 bool need_focus
= true;
1673 bool need_save
= true;
1678 unsigned char *catoms
;
1680 unsigned long nitems
= 0;
1681 unsigned long bytes_after
;
1683 if ((XGetWindowProperty (dpy
, w
,
1684 FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1685 0, 100, False
, XA_ATOM
,
1686 &type
, &format
, &nitems
, &bytes_after
,
1689 && format
== 32 && type
== XA_ATOM
)
1691 Atom
*atoms
= (Atom
*) catoms
;
1696 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
)
1697 need_delete
= false;
1698 else if (atoms
[nitems
]
1699 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_take_focus
)
1701 else if (atoms
[nitems
]
1702 == FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
)
1713 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
1715 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_take_focus
;
1717 props
[count
++] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
1719 XChangeProperty (dpy
, w
, FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
1720 XA_ATOM
, 32, PropModeAppend
,
1721 (unsigned char *) props
, count
);
1729 /* Support routines for XIC (X Input Context). */
1733 static XFontSet
xic_create_xfontset (struct frame
*);
1734 static XIMStyle
best_xim_style (XIMStyles
*);
1737 /* Supported XIM styles, ordered by preference. */
1739 static const XIMStyle supported_xim_styles
[] =
1741 XIMPreeditPosition
| XIMStatusArea
,
1742 XIMPreeditPosition
| XIMStatusNothing
,
1743 XIMPreeditPosition
| XIMStatusNone
,
1744 XIMPreeditNothing
| XIMStatusArea
,
1745 XIMPreeditNothing
| XIMStatusNothing
,
1746 XIMPreeditNothing
| XIMStatusNone
,
1747 XIMPreeditNone
| XIMStatusArea
,
1748 XIMPreeditNone
| XIMStatusNothing
,
1749 XIMPreeditNone
| XIMStatusNone
,
1754 #if defined HAVE_X_WINDOWS && defined USE_X_TOOLKIT
1755 /* Create an X fontset on frame F with base font name BASE_FONTNAME. */
1757 static const char xic_default_fontset
[] = "-*-*-*-r-normal--14-*-*-*-*-*-*-*";
1759 /* Create an Xt fontset spec from the name of a base font.
1760 If `motif' is True use the Motif syntax. */
1762 xic_create_fontsetname (const char *base_fontname
, bool motif
)
1764 const char *sep
= motif
? ";" : ",";
1768 /* Make a fontset name from the base font name. */
1769 if (xic_default_fontset
== base_fontname
)
1771 /* There is no base font name, use the default. */
1772 fontsetname
= xmalloc (strlen (base_fontname
) + 2);
1773 z
= stpcpy (fontsetname
, base_fontname
);
1777 /* Make a fontset name from the base font name.
1778 The font set will be made of the following elements:
1780 - the base font where the charset spec is replaced by -*-*.
1781 - the same but with the family also replaced with -*-*-. */
1782 const char *p
= base_fontname
;
1785 for (i
= 0; *p
; p
++)
1789 /* As the font name doesn't conform to XLFD, we can't
1790 modify it to generalize it to allcs and allfamilies.
1791 Use the specified font plus the default. */
1792 fontsetname
= xmalloc (strlen (base_fontname
)
1793 + strlen (xic_default_fontset
) + 3);
1794 z
= stpcpy (fontsetname
, base_fontname
);
1795 z
= stpcpy (z
, sep
);
1796 z
= stpcpy (z
, xic_default_fontset
);
1801 const char *p1
= NULL
, *p2
= NULL
, *p3
= NULL
;
1802 char *font_allcs
= NULL
;
1803 char *font_allfamilies
= NULL
;
1804 char *font_all
= NULL
;
1805 const char *allcs
= "*-*-*-*-*-*-*";
1806 const char *allfamilies
= "-*-*-";
1807 const char *all
= "*-*-*-*-";
1810 for (i
= 0, p
= base_fontname
; i
< 8; p
++)
1823 /* If base_fontname specifies ADSTYLE, make it a
1827 ptrdiff_t diff
= (p2
- p3
) - 2;
1829 base
= alloca (strlen (base_fontname
) + 1);
1830 memcpy (base
, base_fontname
, p3
- base_fontname
);
1831 base
[p3
- base_fontname
] = '*';
1832 base
[(p3
- base_fontname
) + 1] = '-';
1833 strcpy (base
+ (p3
- base_fontname
) + 2, p2
);
1834 p
= base
+ (p
- base_fontname
) - diff
;
1835 p1
= base
+ (p1
- base_fontname
);
1836 p2
= base
+ (p2
- base_fontname
) - diff
;
1837 base_fontname
= base
;
1840 /* Build the font spec that matches all charsets. */
1841 len
= p
- base_fontname
+ strlen (allcs
) + 1;
1842 font_allcs
= alloca (len
);
1843 memcpy (font_allcs
, base_fontname
, p
- base_fontname
);
1844 strcpy (font_allcs
+ (p
- base_fontname
), allcs
);
1846 /* Build the font spec that matches all families and
1848 len
= p
- p1
+ strlen (allcs
) + strlen (allfamilies
) + 1;
1849 font_allfamilies
= alloca (len
);
1850 strcpy (font_allfamilies
, allfamilies
);
1851 memcpy (font_allfamilies
+ strlen (allfamilies
), p1
, p
- p1
);
1852 strcpy (font_allfamilies
+ strlen (allfamilies
) + (p
- p1
), allcs
);
1854 /* Build the font spec that matches all. */
1855 len
= p
- p2
+ strlen (allcs
) + strlen (all
) + strlen (allfamilies
) + 1;
1856 font_all
= alloca (len
);
1857 z
= stpcpy (font_all
, allfamilies
);
1858 z
= stpcpy (z
, all
);
1859 memcpy (z
, p2
, p
- p2
);
1860 strcpy (z
+ (p
- p2
), allcs
);
1862 /* Build the actual font set name. */
1863 len
= strlen (base_fontname
) + strlen (font_allcs
)
1864 + strlen (font_allfamilies
) + strlen (font_all
) + 5;
1865 fontsetname
= xmalloc (len
);
1866 z
= stpcpy (fontsetname
, base_fontname
);
1867 z
= stpcpy (z
, sep
);
1868 z
= stpcpy (z
, font_allcs
);
1869 z
= stpcpy (z
, sep
);
1870 z
= stpcpy (z
, font_allfamilies
);
1871 z
= stpcpy (z
, sep
);
1872 z
= stpcpy (z
, font_all
);
1879 #endif /* HAVE_X_WINDOWS && USE_X_TOOLKIT */
1881 #ifdef DEBUG_XIC_FONTSET
1883 print_fontset_result (XFontSet xfs
, char *name
, char **missing_list
,
1887 fprintf (stderr
, "XIC Fontset created: %s\n", name
);
1890 fprintf (stderr
, "XIC Fontset failed: %s\n", name
);
1891 while (missing_count
-- > 0)
1893 fprintf (stderr
, " missing: %s\n", *missing_list
);
1902 xic_create_xfontset (struct frame
*f
)
1904 XFontSet xfs
= NULL
;
1905 struct font
*font
= FRAME_FONT (f
);
1906 int pixel_size
= font
->pixel_size
;
1907 Lisp_Object rest
, frame
;
1909 /* See if there is another frame already using same fontset. */
1910 FOR_EACH_FRAME (rest
, frame
)
1912 struct frame
*cf
= XFRAME (frame
);
1914 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
1915 && FRAME_DISPLAY_INFO (cf
) == FRAME_DISPLAY_INFO (f
)
1917 && FRAME_FONT (f
)->pixel_size
== pixel_size
)
1919 xfs
= FRAME_XIC_FONTSET (cf
);
1927 char **missing_list
;
1930 const char *xlfd_format
= "-*-*-medium-r-normal--%d-*-*-*-*-*";
1932 sprintf (buf
, xlfd_format
, pixel_size
);
1933 missing_list
= NULL
;
1934 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
1935 &missing_list
, &missing_count
, &def_string
);
1936 #ifdef DEBUG_XIC_FONTSET
1937 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
1940 XFreeStringList (missing_list
);
1943 /* List of pixel sizes most likely available. Find one that
1944 is closest to pixel_size. */
1945 int sizes
[] = {0, 8, 10, 11, 12, 14, 17, 18, 20, 24, 26, 34, 0};
1946 int *smaller
, *larger
;
1948 for (smaller
= sizes
; smaller
[1]; smaller
++)
1949 if (smaller
[1] >= pixel_size
)
1951 larger
= smaller
+ 1;
1952 if (*larger
== pixel_size
)
1954 while (*smaller
|| *larger
)
1959 this_size
= *smaller
--;
1960 else if (! *smaller
)
1961 this_size
= *larger
++;
1962 else if (pixel_size
- *smaller
< *larger
- pixel_size
)
1963 this_size
= *smaller
--;
1965 this_size
= *larger
++;
1966 sprintf (buf
, xlfd_format
, this_size
);
1967 missing_list
= NULL
;
1968 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), buf
,
1969 &missing_list
, &missing_count
, &def_string
);
1970 #ifdef DEBUG_XIC_FONTSET
1971 print_fontset_result (xfs
, buf
, missing_list
, missing_count
);
1974 XFreeStringList (missing_list
);
1981 const char *last_resort
= "-*-*-*-r-normal--*-*-*-*-*-*";
1983 missing_list
= NULL
;
1984 xfs
= XCreateFontSet (FRAME_X_DISPLAY (f
), last_resort
,
1985 &missing_list
, &missing_count
, &def_string
);
1986 #ifdef DEBUG_XIC_FONTSET
1987 print_fontset_result (xfs
, last_resort
, missing_list
, missing_count
);
1990 XFreeStringList (missing_list
);
1998 /* Free the X fontset of frame F if it is the last frame using it. */
2001 xic_free_xfontset (struct frame
*f
)
2003 Lisp_Object rest
, frame
;
2004 bool shared_p
= false;
2006 if (!FRAME_XIC_FONTSET (f
))
2009 /* See if there is another frame sharing the same fontset. */
2010 FOR_EACH_FRAME (rest
, frame
)
2012 struct frame
*cf
= XFRAME (frame
);
2013 if (cf
!= f
&& FRAME_LIVE_P (f
) && FRAME_X_P (cf
)
2014 && FRAME_DISPLAY_INFO (cf
) == FRAME_DISPLAY_INFO (f
)
2015 && FRAME_XIC_FONTSET (cf
) == FRAME_XIC_FONTSET (f
))
2023 /* The fontset is not used anymore. It is safe to free it. */
2024 XFreeFontSet (FRAME_X_DISPLAY (f
), FRAME_XIC_FONTSET (f
));
2026 FRAME_XIC_FONTSET (f
) = NULL
;
2030 /* Value is the best input style, given user preferences USER (already
2031 checked to be supported by Emacs), and styles supported by the
2032 input method XIM. */
2035 best_xim_style (XIMStyles
*xim
)
2038 int nr_supported
= ARRAYELTS (supported_xim_styles
);
2040 for (i
= 0; i
< nr_supported
; ++i
)
2041 for (j
= 0; j
< xim
->count_styles
; ++j
)
2042 if (supported_xim_styles
[i
] == xim
->supported_styles
[j
])
2043 return supported_xim_styles
[i
];
2045 /* Return the default style. */
2046 return XIMPreeditNothing
| XIMStatusNothing
;
2049 /* Create XIC for frame F. */
2052 create_frame_xic (struct frame
*f
)
2056 XFontSet xfs
= NULL
;
2057 XVaNestedList status_attr
= NULL
;
2058 XVaNestedList preedit_attr
= NULL
;
2066 xim
= FRAME_X_XIM (f
);
2070 /* Determine XIC style. */
2071 xic_style
= best_xim_style (FRAME_X_XIM_STYLES (f
));
2073 /* Create X fontset. */
2074 if (xic_style
& (XIMPreeditPosition
| XIMStatusArea
))
2076 xfs
= xic_create_xfontset (f
);
2080 FRAME_XIC_FONTSET (f
) = xfs
;
2083 if (xic_style
& XIMPreeditPosition
)
2085 spot
.x
= 0; spot
.y
= 1;
2086 preedit_attr
= XVaCreateNestedList (0,
2089 FRAME_FOREGROUND_PIXEL (f
),
2091 FRAME_BACKGROUND_PIXEL (f
),
2092 (xic_style
& XIMPreeditPosition
2102 if (xic_style
& XIMStatusArea
)
2104 s_area
.x
= 0; s_area
.y
= 0; s_area
.width
= 1; s_area
.height
= 1;
2105 status_attr
= XVaCreateNestedList (0,
2111 FRAME_FOREGROUND_PIXEL (f
),
2113 FRAME_BACKGROUND_PIXEL (f
),
2120 if (preedit_attr
&& status_attr
)
2121 xic
= XCreateIC (xim
,
2122 XNInputStyle
, xic_style
,
2123 XNClientWindow
, FRAME_X_WINDOW (f
),
2124 XNFocusWindow
, FRAME_X_WINDOW (f
),
2125 XNStatusAttributes
, status_attr
,
2126 XNPreeditAttributes
, preedit_attr
,
2128 else if (preedit_attr
)
2129 xic
= XCreateIC (xim
,
2130 XNInputStyle
, xic_style
,
2131 XNClientWindow
, FRAME_X_WINDOW (f
),
2132 XNFocusWindow
, FRAME_X_WINDOW (f
),
2133 XNPreeditAttributes
, preedit_attr
,
2135 else if (status_attr
)
2136 xic
= XCreateIC (xim
,
2137 XNInputStyle
, xic_style
,
2138 XNClientWindow
, FRAME_X_WINDOW (f
),
2139 XNFocusWindow
, FRAME_X_WINDOW (f
),
2140 XNStatusAttributes
, status_attr
,
2143 xic
= XCreateIC (xim
,
2144 XNInputStyle
, xic_style
,
2145 XNClientWindow
, FRAME_X_WINDOW (f
),
2146 XNFocusWindow
, FRAME_X_WINDOW (f
),
2152 FRAME_XIC (f
) = xic
;
2153 FRAME_XIC_STYLE (f
) = xic_style
;
2154 xfs
= NULL
; /* Don't free below. */
2162 XFree (preedit_attr
);
2165 XFree (status_attr
);
2169 /* Destroy XIC and free XIC fontset of frame F, if any. */
2172 free_frame_xic (struct frame
*f
)
2174 if (FRAME_XIC (f
) == NULL
)
2177 XDestroyIC (FRAME_XIC (f
));
2178 xic_free_xfontset (f
);
2180 FRAME_XIC (f
) = NULL
;
2184 /* Place preedit area for XIC of window W's frame to specified
2185 pixel position X/Y. X and Y are relative to window W. */
2188 xic_set_preeditarea (struct window
*w
, int x
, int y
)
2190 struct frame
*f
= XFRAME (w
->frame
);
2194 spot
.x
= WINDOW_TO_FRAME_PIXEL_X (w
, x
) + WINDOW_LEFT_FRINGE_WIDTH (w
);
2195 spot
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
) + FONT_BASE (FRAME_FONT (f
));
2196 attr
= XVaCreateNestedList (0, XNSpotLocation
, &spot
, NULL
);
2197 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2202 /* Place status area for XIC in bottom right corner of frame F.. */
2205 xic_set_statusarea (struct frame
*f
)
2207 XIC xic
= FRAME_XIC (f
);
2212 /* Negotiate geometry of status area. If input method has existing
2213 status area, use its current size. */
2214 area
.x
= area
.y
= area
.width
= area
.height
= 0;
2215 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &area
, NULL
);
2216 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2219 attr
= XVaCreateNestedList (0, XNAreaNeeded
, &needed
, NULL
);
2220 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2223 if (needed
->width
== 0) /* Use XNArea instead of XNAreaNeeded */
2225 attr
= XVaCreateNestedList (0, XNArea
, &needed
, NULL
);
2226 XGetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2230 area
.width
= needed
->width
;
2231 area
.height
= needed
->height
;
2232 area
.x
= FRAME_PIXEL_WIDTH (f
) - area
.width
- FRAME_INTERNAL_BORDER_WIDTH (f
);
2233 area
.y
= (FRAME_PIXEL_HEIGHT (f
) - area
.height
2234 - FRAME_MENUBAR_HEIGHT (f
)
2235 - FRAME_TOOLBAR_TOP_HEIGHT (f
)
2236 - FRAME_INTERNAL_BORDER_WIDTH (f
));
2239 attr
= XVaCreateNestedList (0, XNArea
, &area
, NULL
);
2240 XSetICValues (xic
, XNStatusAttributes
, attr
, NULL
);
2245 /* Set X fontset for XIC of frame F, using base font name
2246 BASE_FONTNAME. Called when a new Emacs fontset is chosen. */
2249 xic_set_xfontset (struct frame
*f
, const char *base_fontname
)
2254 xic_free_xfontset (f
);
2256 xfs
= xic_create_xfontset (f
);
2258 attr
= XVaCreateNestedList (0, XNFontSet
, xfs
, NULL
);
2259 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
2260 XSetICValues (FRAME_XIC (f
), XNPreeditAttributes
, attr
, NULL
);
2261 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
2262 XSetICValues (FRAME_XIC (f
), XNStatusAttributes
, attr
, NULL
);
2265 FRAME_XIC_FONTSET (f
) = xfs
;
2268 #endif /* HAVE_X_I18N */
2272 #ifdef USE_X_TOOLKIT
2274 /* Create and set up the X widget for frame F. */
2277 x_window (struct frame
*f
, long window_prompting
)
2279 XClassHint class_hints
;
2280 XSetWindowAttributes attributes
;
2281 unsigned long attribute_mask
;
2282 Widget shell_widget
;
2284 Widget frame_widget
;
2290 /* Use the resource name as the top-level widget name
2291 for looking up resources. Make a non-Lisp copy
2292 for the window manager, so GC relocation won't bother it.
2294 Elsewhere we specify the window name for the window manager. */
2295 f
->namebuf
= xlispstrdup (Vx_resource_name
);
2298 XtSetArg (al
[ac
], XtNallowShellResize
, 1); ac
++;
2299 XtSetArg (al
[ac
], XtNinput
, 1); ac
++;
2300 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2301 XtSetArg (al
[ac
], XtNborderWidth
, f
->border_width
); ac
++;
2302 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2303 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2304 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2305 shell_widget
= XtAppCreateShell (f
->namebuf
, EMACS_CLASS
,
2306 applicationShellWidgetClass
,
2307 FRAME_X_DISPLAY (f
), al
, ac
);
2309 f
->output_data
.x
->widget
= shell_widget
;
2310 /* maybe_set_screen_title_format (shell_widget); */
2312 pane_widget
= lw_create_widget ("main", "pane", widget_id_tick
++,
2313 NULL
, shell_widget
, False
,
2314 NULL
, NULL
, NULL
, NULL
);
2317 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2318 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2319 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2320 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2321 XtSetValues (pane_widget
, al
, ac
);
2322 f
->output_data
.x
->column_widget
= pane_widget
;
2324 /* mappedWhenManaged to false tells to the paned window to not map/unmap
2325 the emacs screen when changing menubar. This reduces flickering. */
2328 XtSetArg (al
[ac
], XtNmappedWhenManaged
, 0); ac
++;
2329 XtSetArg (al
[ac
], XtNshowGrip
, 0); ac
++;
2330 XtSetArg (al
[ac
], XtNallowResize
, 1); ac
++;
2331 XtSetArg (al
[ac
], XtNresizeToPreferred
, 1); ac
++;
2332 XtSetArg (al
[ac
], XtNemacsFrame
, f
); ac
++;
2333 XtSetArg (al
[ac
], XtNvisual
, FRAME_X_VISUAL (f
)); ac
++;
2334 XtSetArg (al
[ac
], XtNdepth
, FRAME_DISPLAY_INFO (f
)->n_planes
); ac
++;
2335 XtSetArg (al
[ac
], XtNcolormap
, FRAME_X_COLORMAP (f
)); ac
++;
2336 XtSetArg (al
[ac
], XtNborderWidth
, 0); ac
++;
2337 frame_widget
= XtCreateWidget (f
->namebuf
, emacsFrameClass
, pane_widget
,
2340 f
->output_data
.x
->edit_widget
= frame_widget
;
2342 XtManageChild (frame_widget
);
2344 /* Do some needed geometry management. */
2348 int extra_borders
= 0;
2350 = (f
->output_data
.x
->menubar_widget
2351 ? (f
->output_data
.x
->menubar_widget
->core
.height
2352 + f
->output_data
.x
->menubar_widget
->core
.border_width
)
2355 #if false /* Experimentally, we now get the right results
2356 for -geometry -0-0 without this. 24 Aug 96, rms. */
2357 if (FRAME_EXTERNAL_MENU_BAR (f
))
2360 XtVaGetValues (pane_widget
, XtNinternalBorderWidth
, &ibw
, NULL
);
2361 menubar_size
+= ibw
;
2365 FRAME_MENUBAR_HEIGHT (f
) = menubar_size
;
2368 /* Motif seems to need this amount added to the sizes
2369 specified for the shell widget. The Athena/Lucid widgets don't.
2370 Both conclusions reached experimentally. -- rms. */
2371 XtVaGetValues (f
->output_data
.x
->edit_widget
, XtNinternalBorderWidth
,
2372 &extra_borders
, NULL
);
2376 f
->shell_position
= xmalloc (sizeof "=x++" + 4 * INT_STRLEN_BOUND (int));
2378 /* Convert our geometry parameters into a geometry string
2380 Note that we do not specify here whether the position
2381 is a user-specified or program-specified one.
2382 We pass that information later, in x_wm_set_size_hints. */
2384 int left
= f
->left_pos
;
2385 bool xneg
= (window_prompting
& XNegative
) != 0;
2386 int top
= f
->top_pos
;
2387 bool yneg
= (window_prompting
& YNegative
) != 0;
2393 if (window_prompting
& USPosition
)
2394 sprintf (f
->shell_position
, "=%dx%d%c%d%c%d",
2395 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2396 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
,
2397 (xneg
? '-' : '+'), left
,
2398 (yneg
? '-' : '+'), top
);
2401 sprintf (f
->shell_position
, "=%dx%d",
2402 FRAME_PIXEL_WIDTH (f
) + extra_borders
,
2403 FRAME_PIXEL_HEIGHT (f
) + menubar_size
+ extra_borders
);
2405 /* Setting x and y when the position is not specified in
2406 the geometry string will set program position in the WM hints.
2407 If Emacs had just one program position, we could set it in
2408 fallback resources, but since each make-frame call can specify
2409 different program positions, this is easier. */
2410 XtSetArg (gal
[gac
], XtNx
, left
); gac
++;
2411 XtSetArg (gal
[gac
], XtNy
, top
); gac
++;
2415 XtSetArg (gal
[gac
], XtNgeometry
, f
->shell_position
); gac
++;
2416 XtSetValues (shell_widget
, gal
, gac
);
2419 XtManageChild (pane_widget
);
2420 XtRealizeWidget (shell_widget
);
2422 if (FRAME_X_EMBEDDED_P (f
))
2423 XReparentWindow (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
),
2424 f
->output_data
.x
->parent_desc
, 0, 0);
2426 FRAME_X_WINDOW (f
) = XtWindow (frame_widget
);
2428 validate_x_resource_name ();
2430 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2431 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2432 XSetClassHint (FRAME_X_DISPLAY (f
), XtWindow (shell_widget
), &class_hints
);
2435 FRAME_XIC (f
) = NULL
;
2437 create_frame_xic (f
);
2440 f
->output_data
.x
->wm_hints
.input
= True
;
2441 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2442 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2443 &f
->output_data
.x
->wm_hints
);
2445 hack_wm_protocols (f
, shell_widget
);
2448 XtAddEventHandler (shell_widget
, 0, True
, _XEditResCheckMessages
, 0);
2451 /* Do a stupid property change to force the server to generate a
2452 PropertyNotify event so that the event_stream server timestamp will
2453 be initialized to something relevant to the time we created the window.
2455 XChangeProperty (XtDisplay (frame_widget
), XtWindow (frame_widget
),
2456 FRAME_DISPLAY_INFO (f
)->Xatom_wm_protocols
,
2457 XA_ATOM
, 32, PropModeAppend
, NULL
, 0);
2459 /* Make all the standard events reach the Emacs frame. */
2460 attributes
.event_mask
= STANDARD_EVENT_SET
;
2465 /* XIM server might require some X events. */
2466 unsigned long fevent
= NoEventMask
;
2467 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2468 attributes
.event_mask
|= fevent
;
2470 #endif /* HAVE_X_I18N */
2472 attribute_mask
= CWEventMask
;
2473 XChangeWindowAttributes (XtDisplay (shell_widget
), XtWindow (shell_widget
),
2474 attribute_mask
, &attributes
);
2476 XtMapWidget (frame_widget
);
2478 /* x_set_name normally ignores requests to set the name if the
2479 requested name is the same as the current name. This is the one
2480 place where that assumption isn't correct; f->name is set, but
2481 the X server hasn't been told. */
2484 bool explicit = f
->explicit_name
;
2486 f
->explicit_name
= false;
2488 fset_name (f
, Qnil
);
2489 x_set_name (f
, name
, explicit);
2492 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2493 f
->output_data
.x
->current_cursor
2494 = f
->output_data
.x
->text_cursor
);
2498 /* This is a no-op, except under Motif. Make sure main areas are
2499 set to something reasonable, in case we get an error later. */
2500 lw_set_main_areas (pane_widget
, 0, frame_widget
);
2503 #else /* not USE_X_TOOLKIT */
2506 x_window (struct frame
*f
)
2508 if (! xg_create_frame_widgets (f
))
2509 error ("Unable to create window");
2512 FRAME_XIC (f
) = NULL
;
2516 create_frame_xic (f
);
2519 /* XIM server might require some X events. */
2520 unsigned long fevent
= NoEventMask
;
2521 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2523 if (fevent
!= NoEventMask
)
2525 XSetWindowAttributes attributes
;
2526 XWindowAttributes wattr
;
2527 unsigned long attribute_mask
;
2529 XGetWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2531 attributes
.event_mask
= wattr
.your_event_mask
| fevent
;
2532 attribute_mask
= CWEventMask
;
2533 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2534 attribute_mask
, &attributes
);
2542 #else /*! USE_GTK */
2543 /* Create and set up the X window for frame F. */
2546 x_window (struct frame
*f
)
2548 XClassHint class_hints
;
2549 XSetWindowAttributes attributes
;
2550 unsigned long attribute_mask
;
2552 attributes
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
2553 attributes
.border_pixel
= f
->output_data
.x
->border_pixel
;
2554 attributes
.bit_gravity
= StaticGravity
;
2555 attributes
.backing_store
= NotUseful
;
2556 attributes
.save_under
= True
;
2557 attributes
.event_mask
= STANDARD_EVENT_SET
;
2558 attributes
.colormap
= FRAME_X_COLORMAP (f
);
2559 attribute_mask
= (CWBackPixel
| CWBorderPixel
| CWBitGravity
| CWEventMask
2564 = XCreateWindow (FRAME_X_DISPLAY (f
),
2565 f
->output_data
.x
->parent_desc
,
2568 FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
),
2570 CopyFromParent
, /* depth */
2571 InputOutput
, /* class */
2573 attribute_mask
, &attributes
);
2578 create_frame_xic (f
);
2581 /* XIM server might require some X events. */
2582 unsigned long fevent
= NoEventMask
;
2583 XGetICValues (FRAME_XIC (f
), XNFilterEvents
, &fevent
, NULL
);
2584 attributes
.event_mask
|= fevent
;
2585 attribute_mask
= CWEventMask
;
2586 XChangeWindowAttributes (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2587 attribute_mask
, &attributes
);
2590 #endif /* HAVE_X_I18N */
2592 validate_x_resource_name ();
2594 class_hints
.res_name
= SSDATA (Vx_resource_name
);
2595 class_hints
.res_class
= SSDATA (Vx_resource_class
);
2596 XSetClassHint (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), &class_hints
);
2598 /* This indicates that we use the "Passive Input" input model.
2599 Unless we do this, we don't get the Focus{In,Out} events that we
2600 need to draw the cursor correctly. Accursed bureaucrats.
2601 XWhipsAndChains (FRAME_X_DISPLAY (f), IronMaiden, &TheRack); */
2603 f
->output_data
.x
->wm_hints
.input
= True
;
2604 f
->output_data
.x
->wm_hints
.flags
|= InputHint
;
2605 XSetWMHints (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2606 &f
->output_data
.x
->wm_hints
);
2607 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
2609 /* Request "save yourself" and "delete window" commands from wm. */
2612 protocols
[0] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_delete_window
;
2613 protocols
[1] = FRAME_DISPLAY_INFO (f
)->Xatom_wm_save_yourself
;
2614 XSetWMProtocols (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), protocols
, 2);
2617 /* x_set_name normally ignores requests to set the name if the
2618 requested name is the same as the current name. This is the one
2619 place where that assumption isn't correct; f->name is set, but
2620 the X server hasn't been told. */
2623 bool explicit = f
->explicit_name
;
2625 f
->explicit_name
= false;
2627 fset_name (f
, Qnil
);
2628 x_set_name (f
, name
, explicit);
2631 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2632 f
->output_data
.x
->current_cursor
2633 = f
->output_data
.x
->text_cursor
);
2637 if (FRAME_X_WINDOW (f
) == 0)
2638 error ("Unable to create window");
2641 #endif /* not USE_GTK */
2642 #endif /* not USE_X_TOOLKIT */
2644 /* Verify that the icon position args for this window are valid. */
2647 x_icon_verify (struct frame
*f
, Lisp_Object parms
)
2649 Lisp_Object icon_x
, icon_y
;
2651 /* Set the position of the icon. Note that twm groups all
2652 icons in an icon window. */
2653 icon_x
= x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2654 icon_y
= x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2655 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2657 CHECK_NUMBER (icon_x
);
2658 CHECK_NUMBER (icon_y
);
2660 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2661 error ("Both left and top icon corners of icon must be specified");
2664 /* Handle the icon stuff for this window. Perhaps later we might
2665 want an x_set_icon_position which can be called interactively as
2669 x_icon (struct frame
*f
, Lisp_Object parms
)
2671 /* Set the position of the icon. Note that twm groups all
2672 icons in an icon window. */
2674 = x_frame_get_and_record_arg (f
, parms
, Qicon_left
, 0, 0, RES_TYPE_NUMBER
);
2676 = x_frame_get_and_record_arg (f
, parms
, Qicon_top
, 0, 0, RES_TYPE_NUMBER
);
2677 if (!EQ (icon_x
, Qunbound
) && !EQ (icon_y
, Qunbound
))
2679 CHECK_TYPE_RANGED_INTEGER (int, icon_x
);
2680 CHECK_TYPE_RANGED_INTEGER (int, icon_y
);
2682 else if (!EQ (icon_x
, Qunbound
) || !EQ (icon_y
, Qunbound
))
2683 error ("Both left and top icon corners of icon must be specified");
2687 if (! EQ (icon_x
, Qunbound
))
2688 x_wm_set_icon_position (f
, XINT (icon_x
), XINT (icon_y
));
2690 #if false /* x_get_arg removes the visibility parameter as a side effect,
2691 but x_create_frame still needs it. */
2692 /* Start up iconic or window? */
2693 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2694 x_wm_set_window_state
2695 (f
, (EQ (x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0, RES_TYPE_SYMBOL
),
2701 x_text_icon (f
, SSDATA ((!NILP (f
->icon_name
)
2708 /* Make the GCs needed for this window, setting the
2709 background, border and mouse colors; also create the
2710 mouse cursor and the gray border tile. */
2713 x_make_gc (struct frame
*f
)
2715 XGCValues gc_values
;
2719 /* Create the GCs of this frame.
2720 Note that many default values are used. */
2722 gc_values
.foreground
= FRAME_FOREGROUND_PIXEL (f
);
2723 gc_values
.background
= FRAME_BACKGROUND_PIXEL (f
);
2724 gc_values
.line_width
= 0; /* Means 1 using fast algorithm. */
2725 f
->output_data
.x
->normal_gc
2726 = XCreateGC (FRAME_X_DISPLAY (f
),
2728 GCLineWidth
| GCForeground
| GCBackground
,
2731 /* Reverse video style. */
2732 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2733 gc_values
.background
= FRAME_FOREGROUND_PIXEL (f
);
2734 f
->output_data
.x
->reverse_gc
2735 = XCreateGC (FRAME_X_DISPLAY (f
),
2737 GCForeground
| GCBackground
| GCLineWidth
,
2740 /* Cursor has cursor-color background, background-color foreground. */
2741 gc_values
.foreground
= FRAME_BACKGROUND_PIXEL (f
);
2742 gc_values
.background
= f
->output_data
.x
->cursor_pixel
;
2743 gc_values
.fill_style
= FillOpaqueStippled
;
2744 f
->output_data
.x
->cursor_gc
2745 = XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2746 (GCForeground
| GCBackground
2747 | GCFillStyle
| GCLineWidth
),
2750 /* Create the gray border tile used when the pointer is not in
2751 the frame. Since this depends on the frame's pixel values,
2752 this must be done on a per-frame basis. */
2753 f
->output_data
.x
->border_tile
2754 = (XCreatePixmapFromBitmapData
2755 (FRAME_X_DISPLAY (f
), FRAME_DISPLAY_INFO (f
)->root_window
,
2756 gray_bits
, gray_width
, gray_height
,
2757 FRAME_FOREGROUND_PIXEL (f
),
2758 FRAME_BACKGROUND_PIXEL (f
),
2759 DefaultDepth (FRAME_X_DISPLAY (f
), FRAME_X_SCREEN_NUMBER (f
))));
2765 /* Free what was allocated in x_make_gc. */
2768 x_free_gcs (struct frame
*f
)
2770 Display
*dpy
= FRAME_X_DISPLAY (f
);
2774 if (f
->output_data
.x
->normal_gc
)
2776 XFreeGC (dpy
, f
->output_data
.x
->normal_gc
);
2777 f
->output_data
.x
->normal_gc
= 0;
2780 if (f
->output_data
.x
->reverse_gc
)
2782 XFreeGC (dpy
, f
->output_data
.x
->reverse_gc
);
2783 f
->output_data
.x
->reverse_gc
= 0;
2786 if (f
->output_data
.x
->cursor_gc
)
2788 XFreeGC (dpy
, f
->output_data
.x
->cursor_gc
);
2789 f
->output_data
.x
->cursor_gc
= 0;
2792 if (f
->output_data
.x
->border_tile
)
2794 XFreePixmap (dpy
, f
->output_data
.x
->border_tile
);
2795 f
->output_data
.x
->border_tile
= 0;
2802 /* Handler for signals raised during x_create_frame and
2803 x_create_tip_frame. FRAME is the frame which is partially
2807 unwind_create_frame (Lisp_Object frame
)
2809 struct frame
*f
= XFRAME (frame
);
2811 /* If frame is already dead, nothing to do. This can happen if the
2812 display is disconnected after the frame has become official, but
2813 before x_create_frame removes the unwind protect. */
2814 if (!FRAME_LIVE_P (f
))
2817 /* If frame is ``official'', nothing to do. */
2818 if (NILP (Fmemq (frame
, Vframe_list
)))
2820 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2821 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2824 /* If the frame's image cache refcount is still the same as our
2825 private shadow variable, it means we are unwinding a frame
2826 for which we didn't yet call init_frame_faces, where the
2827 refcount is incremented. Therefore, we increment it here, so
2828 that free_frame_faces, called in x_free_frame_resources
2829 below, will not mistakenly decrement the counter that was not
2830 incremented yet to account for this new frame. */
2831 if (FRAME_IMAGE_CACHE (f
) != NULL
2832 && FRAME_IMAGE_CACHE (f
)->refcount
== image_cache_refcount
)
2833 FRAME_IMAGE_CACHE (f
)->refcount
++;
2835 x_free_frame_resources (f
);
2838 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2839 /* Check that reference counts are indeed correct. */
2840 eassert (dpyinfo
->reference_count
== dpyinfo_refcount
);
2841 eassert (dpyinfo
->terminal
->image_cache
->refcount
== image_cache_refcount
);
2850 do_unwind_create_frame (Lisp_Object frame
)
2852 unwind_create_frame (frame
);
2856 x_default_font_parameter (struct frame
*f
, Lisp_Object parms
)
2858 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2859 Lisp_Object font_param
= x_get_arg (dpyinfo
, parms
, Qfont
, NULL
, NULL
,
2861 Lisp_Object font
= Qnil
;
2862 if (EQ (font_param
, Qunbound
))
2865 if (NILP (font_param
))
2867 /* System font should take precedence over X resources. We suggest this
2868 regardless of font-use-system-font because .emacs may not have been
2870 const char *system_font
= xsettings_get_system_font ();
2872 font
= font_open_by_name (f
, build_unibyte_string (system_font
));
2876 font
= !NILP (font_param
) ? font_param
2877 : x_get_arg (dpyinfo
, parms
, Qfont
, "font", "Font", RES_TYPE_STRING
);
2879 if (! FONTP (font
) && ! STRINGP (font
))
2884 /* This will find the normal Xft font. */
2887 "-adobe-courier-medium-r-*-*-*-120-*-*-*-*-iso8859-1",
2888 "-misc-fixed-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2889 "-*-*-medium-r-normal-*-*-140-*-*-c-*-iso8859-1",
2890 /* This was formerly the first thing tried, but it finds
2891 too many fonts and takes too long. */
2892 "-*-*-medium-r-*-*-*-*-*-*-c-*-iso8859-1",
2893 /* If those didn't work, look for something which will
2895 "-*-fixed-*-*-*-*-*-140-*-*-c-*-iso8859-1",
2900 for (i
= 0; names
[i
]; i
++)
2902 font
= font_open_by_name (f
, build_unibyte_string (names
[i
]));
2907 error ("No suitable font was found");
2909 else if (!NILP (font_param
))
2911 /* Remember the explicit font parameter, so we can re-apply it after
2912 we've applied the `default' face settings. */
2913 AUTO_FRAME_ARG (arg
, Qfont_param
, font_param
);
2914 x_set_frame_parameters (f
, arg
);
2917 /* This call will make X resources override any system font setting. */
2918 x_default_parameter (f
, parms
, Qfont
, font
, "font", "Font", RES_TYPE_STRING
);
2922 DEFUN ("x-wm-set-size-hint", Fx_wm_set_size_hint
, Sx_wm_set_size_hint
,
2924 doc
: /* Send the size hints for frame FRAME to the window manager.
2925 If FRAME is omitted or nil, use the selected frame.
2926 Signal error if FRAME is not an X frame. */)
2929 struct frame
*f
= decode_window_system_frame (frame
);
2932 x_wm_set_size_hint (f
, 0, false);
2938 set_machine_and_pid_properties (struct frame
*f
)
2940 /* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME. */
2941 XSetWMProperties (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), NULL
, NULL
,
2942 NULL
, 0, NULL
, NULL
, NULL
);
2943 pid_t pid
= getpid ();
2944 if (pid
<= 0xffffffffu
)
2946 unsigned long xpid
= pid
;
2947 XChangeProperty (FRAME_X_DISPLAY (f
),
2948 FRAME_OUTER_WINDOW (f
),
2949 XInternAtom (FRAME_X_DISPLAY (f
),
2952 XA_CARDINAL
, 32, PropModeReplace
,
2953 (unsigned char *) &xpid
, 1);
2957 DEFUN ("x-create-frame", Fx_create_frame
, Sx_create_frame
,
2959 doc
: /* Make a new X window, which is called a "frame" in Emacs terms.
2960 Return an Emacs frame object. PARMS is an alist of frame parameters.
2961 If the parameters specify that the frame should not have a minibuffer,
2962 and do not specify a specific minibuffer window to use, then
2963 `default-minibuffer-frame' must be a frame whose minibuffer can be
2964 shared by the new frame.
2966 This function is an internal primitive--use `make-frame' instead. */)
2970 Lisp_Object frame
, tem
;
2972 bool minibuffer_only
= false;
2973 long window_prompting
= 0;
2974 ptrdiff_t count
= SPECPDL_INDEX ();
2975 Lisp_Object display
;
2976 struct x_display_info
*dpyinfo
= NULL
;
2980 parms
= Fcopy_alist (parms
);
2982 /* Use this general default value to start with
2983 until we know if this frame has a specified name. */
2984 Vx_resource_name
= Vinvocation_name
;
2986 display
= x_get_arg (dpyinfo
, parms
, Qterminal
, 0, 0, RES_TYPE_NUMBER
);
2987 if (EQ (display
, Qunbound
))
2988 display
= x_get_arg (dpyinfo
, parms
, Qdisplay
, 0, 0, RES_TYPE_STRING
);
2989 if (EQ (display
, Qunbound
))
2991 dpyinfo
= check_x_display_info (display
);
2992 kb
= dpyinfo
->terminal
->kboard
;
2994 if (!dpyinfo
->terminal
->name
)
2995 error ("Terminal is not live, can't create new frames on it");
2997 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
2999 && ! EQ (name
, Qunbound
)
3001 error ("Invalid frame name--not a string or nil");
3004 Vx_resource_name
= name
;
3006 /* See if parent window is specified. */
3007 parent
= x_get_arg (dpyinfo
, parms
, Qparent_id
, NULL
, NULL
, RES_TYPE_NUMBER
);
3008 if (EQ (parent
, Qunbound
))
3010 if (! NILP (parent
))
3011 CHECK_NUMBER (parent
);
3014 tem
= x_get_arg (dpyinfo
, parms
, Qminibuffer
, "minibuffer", "Minibuffer",
3016 if (EQ (tem
, Qnone
) || NILP (tem
))
3017 f
= make_frame_without_minibuffer (Qnil
, kb
, display
);
3018 else if (EQ (tem
, Qonly
))
3020 f
= make_minibuffer_frame ();
3021 minibuffer_only
= true;
3023 else if (WINDOWP (tem
))
3024 f
= make_frame_without_minibuffer (tem
, kb
, display
);
3026 f
= make_frame (true);
3028 XSETFRAME (frame
, f
);
3030 f
->terminal
= dpyinfo
->terminal
;
3032 f
->output_method
= output_x_window
;
3033 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
3034 f
->output_data
.x
->icon_bitmap
= -1;
3035 FRAME_FONTSET (f
) = -1;
3036 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
3037 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
3038 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
3039 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
3040 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
3041 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
3042 f
->output_data
.x
->white_relief
.pixel
= -1;
3043 f
->output_data
.x
->black_relief
.pixel
= -1;
3046 x_get_arg (dpyinfo
, parms
, Qicon_name
, "iconName", "Title",
3048 if (! STRINGP (f
->icon_name
))
3049 fset_icon_name (f
, Qnil
);
3051 FRAME_DISPLAY_INFO (f
) = dpyinfo
;
3053 /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe. */
3054 record_unwind_protect (do_unwind_create_frame
, frame
);
3056 /* These colors will be set anyway later, but it's important
3057 to get the color reference counts right, so initialize them! */
3061 /* Function x_decode_color can signal an error. Make
3062 sure to initialize color slots so that we won't try
3063 to free colors we haven't allocated. */
3064 FRAME_FOREGROUND_PIXEL (f
) = -1;
3065 FRAME_BACKGROUND_PIXEL (f
) = -1;
3066 f
->output_data
.x
->cursor_pixel
= -1;
3067 f
->output_data
.x
->cursor_foreground_pixel
= -1;
3068 f
->output_data
.x
->border_pixel
= -1;
3069 f
->output_data
.x
->mouse_pixel
= -1;
3071 black
= build_string ("black");
3072 FRAME_FOREGROUND_PIXEL (f
)
3073 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3074 FRAME_BACKGROUND_PIXEL (f
)
3075 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3076 f
->output_data
.x
->cursor_pixel
3077 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3078 f
->output_data
.x
->cursor_foreground_pixel
3079 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3080 f
->output_data
.x
->border_pixel
3081 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3082 f
->output_data
.x
->mouse_pixel
3083 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
3086 /* Specify the parent under which to make this X window. */
3089 f
->output_data
.x
->parent_desc
= (Window
) XFASTINT (parent
);
3090 f
->output_data
.x
->explicit_parent
= true;
3094 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
3095 f
->output_data
.x
->explicit_parent
= false;
3098 /* Set the name; the functions to which we pass f expect the name to
3100 if (EQ (name
, Qunbound
) || NILP (name
))
3102 fset_name (f
, build_string (dpyinfo
->x_id_name
));
3103 f
->explicit_name
= false;
3107 fset_name (f
, name
);
3108 f
->explicit_name
= true;
3109 /* Use the frame's title when getting resources for this frame. */
3110 specbind (Qx_resource_name
, name
);
3114 register_font_driver (&ftcrfont_driver
, f
);
3116 #ifdef HAVE_FREETYPE
3118 register_font_driver (&xftfont_driver
, f
);
3119 #else /* not HAVE_XFT */
3120 register_font_driver (&ftxfont_driver
, f
);
3121 #endif /* not HAVE_XFT */
3122 #endif /* HAVE_FREETYPE */
3123 register_font_driver (&xfont_driver
, f
);
3124 #endif /* not USE_CAIRO */
3126 image_cache_refcount
=
3127 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
3129 dpyinfo_refcount
= dpyinfo
->reference_count
;
3130 #endif /* GLYPH_DEBUG */
3132 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
3133 "fontBackend", "FontBackend", RES_TYPE_STRING
);
3135 /* Extract the window parameters from the supplied values
3136 that are needed to determine window geometry. */
3137 x_default_font_parameter (f
, parms
);
3138 if (!FRAME_FONT (f
))
3140 delete_frame (frame
, Qnoelisp
);
3141 error ("Invalid frame font");
3144 /* Frame contents get displaced if an embedded X window has a border. */
3145 if (! FRAME_X_EMBEDDED_P (f
))
3146 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
3147 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
3149 /* This defaults to 1 in order to match xterm. We recognize either
3150 internalBorderWidth or internalBorder (which is what xterm calls
3152 if (NILP (Fassq (Qinternal_border_width
, parms
)))
3156 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
3157 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
3158 if (! EQ (value
, Qunbound
))
3159 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
3162 x_default_parameter (f
, parms
, Qinternal_border_width
,
3163 #ifdef USE_GTK /* We used to impose 0 in xg_create_frame_widgets. */
3168 "internalBorderWidth", "internalBorderWidth",
3170 x_default_parameter (f
, parms
, Qright_divider_width
, make_number (0),
3171 NULL
, NULL
, RES_TYPE_NUMBER
);
3172 x_default_parameter (f
, parms
, Qbottom_divider_width
, make_number (0),
3173 NULL
, NULL
, RES_TYPE_NUMBER
);
3174 x_default_parameter (f
, parms
, Qvertical_scroll_bars
,
3175 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
3180 "verticalScrollBars", "ScrollBars",
3182 x_default_parameter (f
, parms
, Qhorizontal_scroll_bars
, Qnil
,
3183 "horizontalScrollBars", "ScrollBars",
3185 /* Also do the stuff which must be set before the window exists. */
3186 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
3187 "foreground", "Foreground", RES_TYPE_STRING
);
3188 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
3189 "background", "Background", RES_TYPE_STRING
);
3190 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
3191 "pointerColor", "Foreground", RES_TYPE_STRING
);
3192 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
3193 "borderColor", "BorderColor", RES_TYPE_STRING
);
3194 x_default_parameter (f
, parms
, Qscreen_gamma
, Qnil
,
3195 "screenGamma", "ScreenGamma", RES_TYPE_FLOAT
);
3196 x_default_parameter (f
, parms
, Qline_spacing
, Qnil
,
3197 "lineSpacing", "LineSpacing", RES_TYPE_NUMBER
);
3198 x_default_parameter (f
, parms
, Qleft_fringe
, Qnil
,
3199 "leftFringe", "LeftFringe", RES_TYPE_NUMBER
);
3200 x_default_parameter (f
, parms
, Qright_fringe
, Qnil
,
3201 "rightFringe", "RightFringe", RES_TYPE_NUMBER
);
3203 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_foreground
,
3204 "scrollBarForeground",
3205 "ScrollBarForeground", true);
3206 x_default_scroll_bar_color_parameter (f
, parms
, Qscroll_bar_background
,
3207 "scrollBarBackground",
3208 "ScrollBarBackground", false);
3210 /* Init faces before x_default_parameter is called for the
3211 scroll-bar-width parameter because otherwise we end up in
3212 init_iterator with a null face cache, which should not happen. */
3213 init_frame_faces (f
);
3215 /* The following call of change_frame_size is needed since otherwise
3216 x_set_tool_bar_lines will already work with the character sizes
3217 installed by init_frame_faces while the frame's pixel size is
3218 still calculated from a character size of 1 and we subsequently
3219 hit the (height >= 0) assertion in window_box_height.
3221 The non-pixelwise code apparently worked around this because it
3222 had one frame line vs one toolbar line which left us with a zero
3223 root window height which was obviously wrong as well ... */
3224 adjust_frame_size (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
),
3225 FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
), 5, true,
3228 /* Set the menu-bar-lines and tool-bar-lines parameters. We don't
3229 look up the X resources controlling the menu-bar and tool-bar
3230 here; they are processed specially at startup, and reflected in
3231 the values of the mode variables. */
3233 x_default_parameter (f
, parms
, Qmenu_bar_lines
,
3234 NILP (Vmenu_bar_mode
)
3235 ? make_number (0) : make_number (1),
3236 NULL
, NULL
, RES_TYPE_NUMBER
);
3237 x_default_parameter (f
, parms
, Qtool_bar_lines
,
3238 NILP (Vtool_bar_mode
)
3239 ? make_number (0) : make_number (1),
3240 NULL
, NULL
, RES_TYPE_NUMBER
);
3242 x_default_parameter (f
, parms
, Qbuffer_predicate
, Qnil
,
3243 "bufferPredicate", "BufferPredicate",
3245 x_default_parameter (f
, parms
, Qtitle
, Qnil
,
3246 "title", "Title", RES_TYPE_STRING
);
3247 x_default_parameter (f
, parms
, Qwait_for_wm
, Qt
,
3248 "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN
);
3249 x_default_parameter (f
, parms
, Qtool_bar_position
,
3250 FRAME_TOOL_BAR_POSITION (f
), 0, 0, RES_TYPE_SYMBOL
);
3252 /* Compute the size of the X window. */
3253 window_prompting
= x_figure_window_size (f
, parms
, true);
3255 tem
= x_get_arg (dpyinfo
, parms
, Qunsplittable
, 0, 0, RES_TYPE_BOOLEAN
);
3256 f
->no_split
= minibuffer_only
|| EQ (tem
, Qt
);
3258 x_icon_verify (f
, parms
);
3260 /* Create the X widget or window. */
3261 #ifdef USE_X_TOOLKIT
3262 x_window (f
, window_prompting
);
3270 /* Now consider the frame official. */
3271 f
->terminal
->reference_count
++;
3272 FRAME_DISPLAY_INFO (f
)->reference_count
++;
3273 Vframe_list
= Fcons (frame
, Vframe_list
);
3275 /* We need to do this after creating the X window, so that the
3276 icon-creation functions can say whose icon they're describing. */
3277 x_default_parameter (f
, parms
, Qicon_type
, Qt
,
3278 "bitmapIcon", "BitmapIcon", RES_TYPE_BOOLEAN
);
3280 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
3281 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3282 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
3283 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
3284 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
3285 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
3286 x_default_parameter (f
, parms
, Qscroll_bar_width
, Qnil
,
3287 "scrollBarWidth", "ScrollBarWidth",
3289 x_default_parameter (f
, parms
, Qscroll_bar_height
, Qnil
,
3290 "scrollBarHeight", "ScrollBarHeight",
3292 x_default_parameter (f
, parms
, Qalpha
, Qnil
,
3293 "alpha", "Alpha", RES_TYPE_NUMBER
);
3295 /* Consider frame official, now. */
3296 f
->can_x_set_window_size
= true;
3298 adjust_frame_size (f
, FRAME_TEXT_WIDTH (f
), FRAME_TEXT_HEIGHT (f
), 0, true,
3301 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3302 /* Create the menu bar. */
3303 if (!minibuffer_only
&& FRAME_EXTERNAL_MENU_BAR (f
))
3305 /* If this signals an error, we haven't set size hints for the
3306 frame and we didn't make it visible. */
3307 initialize_frame_menubar (f
);
3310 /* This is a no-op, except under Motif where it arranges the
3311 main window for the widgets on it. */
3312 lw_set_main_areas (f
->output_data
.x
->column_widget
,
3313 f
->output_data
.x
->menubar_widget
,
3314 f
->output_data
.x
->edit_widget
);
3315 #endif /* not USE_GTK */
3317 #endif /* USE_X_TOOLKIT || USE_GTK */
3319 /* Tell the server what size and position, etc, we want, and how
3320 badly we want them. This should be done after we have the menu
3321 bar so that its size can be taken into account. */
3323 x_wm_set_size_hint (f
, window_prompting
, false);
3326 /* Process fullscreen parameter here in the hope that normalizing a
3327 fullheight/fullwidth frame will produce the size set by the last
3328 adjust_frame_size call. */
3329 x_default_parameter (f
, parms
, Qfullscreen
, Qnil
,
3330 "fullscreen", "Fullscreen", RES_TYPE_SYMBOL
);
3332 /* Make the window appear on the frame and enable display, unless
3333 the caller says not to. However, with explicit parent, Emacs
3334 cannot control visibility, so don't try. */
3335 if (! f
->output_data
.x
->explicit_parent
)
3337 Lisp_Object visibility
;
3339 visibility
= x_get_arg (dpyinfo
, parms
, Qvisibility
, 0, 0,
3341 if (EQ (visibility
, Qunbound
))
3344 if (EQ (visibility
, Qicon
))
3345 x_iconify_frame (f
);
3346 else if (! NILP (visibility
))
3347 x_make_frame_visible (f
);
3350 /* Must have been Qnil. */
3356 /* Set machine name and pid for the purpose of window managers. */
3357 set_machine_and_pid_properties (f
);
3359 /* Set the WM leader property. GTK does this itself, so this is not
3360 needed when using GTK. */
3361 if (dpyinfo
->client_leader_window
!= 0)
3363 XChangeProperty (FRAME_X_DISPLAY (f
),
3364 FRAME_OUTER_WINDOW (f
),
3365 dpyinfo
->Xatom_wm_client_leader
,
3366 XA_WINDOW
, 32, PropModeReplace
,
3367 (unsigned char *) &dpyinfo
->client_leader_window
, 1);
3372 /* Initialize `default-minibuffer-frame' in case this is the first
3373 frame on this terminal. */
3374 if (FRAME_HAS_MINIBUF_P (f
)
3375 && (!FRAMEP (KVAR (kb
, Vdefault_minibuffer_frame
))
3376 || !FRAME_LIVE_P (XFRAME (KVAR (kb
, Vdefault_minibuffer_frame
)))))
3377 kset_default_minibuffer_frame (kb
, frame
);
3379 /* All remaining specified parameters, which have not been "used"
3380 by x_get_arg and friends, now go in the misc. alist of the frame. */
3381 for (tem
= parms
; CONSP (tem
); tem
= XCDR (tem
))
3382 if (CONSP (XCAR (tem
)) && !NILP (XCAR (XCAR (tem
))))
3383 fset_param_alist (f
, Fcons (XCAR (tem
), f
->param_alist
));
3385 /* Make sure windows on this frame appear in calls to next-window
3386 and similar functions. */
3387 Vwindow_list
= Qnil
;
3389 return unbind_to (count
, frame
);
3393 /* FRAME is used only to get a handle on the X display. We don't pass the
3394 display info directly because we're called from frame.c, which doesn't
3395 know about that structure. */
3398 x_get_focus_frame (struct frame
*frame
)
3400 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (frame
);
3402 if (! dpyinfo
->x_focus_frame
)
3405 XSETFRAME (xfocus
, dpyinfo
->x_focus_frame
);
3410 /* In certain situations, when the window manager follows a
3411 click-to-focus policy, there seems to be no way around calling
3412 XSetInputFocus to give another frame the input focus .
3414 In an ideal world, XSetInputFocus should generally be avoided so
3415 that applications don't interfere with the window manager's focus
3416 policy. But I think it's okay to use when it's clearly done
3417 following a user-command. */
3420 x_focus_frame (struct frame
*f
)
3422 Display
*dpy
= FRAME_X_DISPLAY (f
);
3425 x_catch_errors (dpy
);
3427 if (FRAME_X_EMBEDDED_P (f
))
3429 /* For Xembedded frames, normally the embedder forwards key
3430 events. See XEmbed Protocol Specification at
3431 http://freedesktop.org/wiki/Specifications/xembed-spec */
3432 xembed_request_focus (f
);
3436 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3437 RevertToParent
, CurrentTime
);
3438 x_ewmh_activate_frame (f
);
3441 x_uncatch_errors ();
3446 DEFUN ("xw-color-defined-p", Fxw_color_defined_p
, Sxw_color_defined_p
, 1, 2, 0,
3447 doc
: /* Internal function called by `color-defined-p', which see
3448 .\(Note that the Nextstep version of this function ignores FRAME.) */)
3449 (Lisp_Object color
, Lisp_Object frame
)
3452 struct frame
*f
= decode_window_system_frame (frame
);
3454 CHECK_STRING (color
);
3456 if (x_defined_color (f
, SSDATA (color
), &foo
, false))
3462 DEFUN ("xw-color-values", Fxw_color_values
, Sxw_color_values
, 1, 2, 0,
3463 doc
: /* Internal function called by `color-values', which see. */)
3464 (Lisp_Object color
, Lisp_Object frame
)
3467 struct frame
*f
= decode_window_system_frame (frame
);
3469 CHECK_STRING (color
);
3471 if (x_defined_color (f
, SSDATA (color
), &foo
, false))
3472 return list3i (foo
.red
, foo
.green
, foo
.blue
);
3477 DEFUN ("xw-display-color-p", Fxw_display_color_p
, Sxw_display_color_p
, 0, 1, 0,
3478 doc
: /* Internal function called by `display-color-p', which see. */)
3479 (Lisp_Object terminal
)
3481 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3483 if (dpyinfo
->n_planes
<= 2)
3486 switch (dpyinfo
->visual
->class)
3499 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p
, Sx_display_grayscale_p
,
3501 doc
: /* Return t if the X display supports shades of gray.
3502 Note that color displays do support shades of gray.
3503 The optional argument TERMINAL specifies which display to ask about.
3504 TERMINAL should be a terminal object, a frame or a display name (a string).
3505 If omitted or nil, that stands for the selected frame's display. */)
3506 (Lisp_Object terminal
)
3508 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3510 if (dpyinfo
->n_planes
<= 1)
3513 switch (dpyinfo
->visual
->class)
3528 DEFUN ("x-display-pixel-width", Fx_display_pixel_width
, Sx_display_pixel_width
,
3530 doc
: /* Return the width in pixels of the X display TERMINAL.
3531 The optional argument TERMINAL specifies which display to ask about.
3532 TERMINAL should be a terminal object, a frame or a display name (a string).
3533 If omitted or nil, that stands for the selected frame's display.
3535 On \"multi-monitor\" setups this refers to the pixel width for all
3536 physical monitors associated with TERMINAL. To get information for
3537 each physical monitor, use `display-monitor-attributes-list'. */)
3538 (Lisp_Object terminal
)
3540 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3542 return make_number (x_display_pixel_width (dpyinfo
));
3545 DEFUN ("x-display-pixel-height", Fx_display_pixel_height
,
3546 Sx_display_pixel_height
, 0, 1, 0,
3547 doc
: /* Return the height in pixels of the X display TERMINAL.
3548 The optional argument TERMINAL specifies which display to ask about.
3549 TERMINAL should be a terminal object, a frame or a display name (a string).
3550 If omitted or nil, that stands for the selected frame's display.
3552 On \"multi-monitor\" setups this refers to the pixel height for all
3553 physical monitors associated with TERMINAL. To get information for
3554 each physical monitor, use `display-monitor-attributes-list'. */)
3555 (Lisp_Object terminal
)
3557 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3559 return make_number (x_display_pixel_height (dpyinfo
));
3562 DEFUN ("x-display-planes", Fx_display_planes
, Sx_display_planes
,
3564 doc
: /* Return the number of bitplanes of the X display TERMINAL.
3565 The optional argument TERMINAL specifies which display to ask about.
3566 TERMINAL should be a terminal object, a frame or a display name (a string).
3567 If omitted or nil, that stands for the selected frame's display. */)
3568 (Lisp_Object terminal
)
3570 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3572 return make_number (dpyinfo
->n_planes
);
3575 DEFUN ("x-display-color-cells", Fx_display_color_cells
, Sx_display_color_cells
,
3577 doc
: /* Return the number of color cells of the X display TERMINAL.
3578 The optional argument TERMINAL specifies which display to ask about.
3579 TERMINAL should be a terminal object, a frame or a display name (a string).
3580 If omitted or nil, that stands for the selected frame's display. */)
3581 (Lisp_Object terminal
)
3583 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3585 int nr_planes
= DisplayPlanes (dpyinfo
->display
,
3586 XScreenNumberOfScreen (dpyinfo
->screen
));
3588 /* Truncate nr_planes to 24 to avoid integer overflow.
3589 Some displays says 32, but only 24 bits are actually significant.
3590 There are only very few and rare video cards that have more than
3591 24 significant bits. Also 24 bits is more than 16 million colors,
3592 it "should be enough for everyone". */
3593 if (nr_planes
> 24) nr_planes
= 24;
3595 return make_number (1 << nr_planes
);
3598 DEFUN ("x-server-max-request-size", Fx_server_max_request_size
,
3599 Sx_server_max_request_size
,
3601 doc
: /* Return the maximum request size of the X server of display TERMINAL.
3602 The optional argument TERMINAL specifies which display to ask about.
3603 TERMINAL should be a terminal object, a frame or a display name (a string).
3604 If omitted or nil, that stands for the selected frame's display. */)
3605 (Lisp_Object terminal
)
3607 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3609 return make_number (MAXREQUEST (dpyinfo
->display
));
3612 DEFUN ("x-server-vendor", Fx_server_vendor
, Sx_server_vendor
, 0, 1, 0,
3613 doc
: /* Return the "vendor ID" string of the GUI software on TERMINAL.
3615 \(Labeling every distributor as a "vendor" embodies the false assumption
3616 that operating systems cannot be developed and distributed noncommercially.)
3617 The optional argument TERMINAL specifies which display to ask about.
3619 For GNU and Unix systems, this queries the X server software; for
3620 MS-Windows, this queries the OS.
3622 TERMINAL should be a terminal object, a frame or a display name (a string).
3623 If omitted or nil, that stands for the selected frame's display. */)
3624 (Lisp_Object terminal
)
3626 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3627 const char *vendor
= ServerVendor (dpyinfo
->display
);
3629 if (! vendor
) vendor
= "";
3630 return build_string (vendor
);
3633 DEFUN ("x-server-version", Fx_server_version
, Sx_server_version
, 0, 1, 0,
3634 doc
: /* Return the version numbers of the GUI software on TERMINAL.
3635 The value is a list of three integers specifying the version of the GUI
3638 For GNU and Unix system, the first 2 numbers are the version of the X
3639 Protocol used on TERMINAL and the 3rd number is the distributor-specific
3640 release number. For MS-Windows, the 3 numbers report the version and
3641 the build number of the OS.
3643 See also the function `x-server-vendor'.
3645 The optional argument TERMINAL specifies which display to ask about.
3646 TERMINAL should be a terminal object, a frame or a display name (a string).
3647 If omitted or nil, that stands for the selected frame's display. */)
3648 (Lisp_Object terminal
)
3650 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3651 Display
*dpy
= dpyinfo
->display
;
3653 return list3i (ProtocolVersion (dpy
), ProtocolRevision (dpy
),
3654 VendorRelease (dpy
));
3657 DEFUN ("x-display-screens", Fx_display_screens
, Sx_display_screens
, 0, 1, 0,
3658 doc
: /* Return the number of screens on the X server of display TERMINAL.
3659 The optional argument TERMINAL specifies which display to ask about.
3660 TERMINAL should be a terminal object, a frame or a display name (a string).
3661 If omitted or nil, that stands for the selected frame's display. */)
3662 (Lisp_Object terminal
)
3664 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3666 return make_number (ScreenCount (dpyinfo
->display
));
3669 DEFUN ("x-display-mm-height", Fx_display_mm_height
, Sx_display_mm_height
, 0, 1, 0,
3670 doc
: /* Return the height in millimeters of the X display TERMINAL.
3671 The optional argument TERMINAL specifies which display to ask about.
3672 TERMINAL should be a terminal object, a frame or a display name (a string).
3673 If omitted or nil, that stands for the selected frame's display.
3675 On \"multi-monitor\" setups this refers to the height in millimeters for
3676 all physical monitors associated with TERMINAL. To get information
3677 for each physical monitor, use `display-monitor-attributes-list'. */)
3678 (Lisp_Object terminal
)
3680 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3682 return make_number (HeightMMOfScreen (dpyinfo
->screen
));
3685 DEFUN ("x-display-mm-width", Fx_display_mm_width
, Sx_display_mm_width
, 0, 1, 0,
3686 doc
: /* Return the width in millimeters of the X display TERMINAL.
3687 The optional argument TERMINAL specifies which display to ask about.
3688 TERMINAL should be a terminal object, a frame or a display name (a string).
3689 If omitted or nil, that stands for the selected frame's display.
3691 On \"multi-monitor\" setups this refers to the width in millimeters for
3692 all physical monitors associated with TERMINAL. To get information
3693 for each physical monitor, use `display-monitor-attributes-list'. */)
3694 (Lisp_Object terminal
)
3696 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3698 return make_number (WidthMMOfScreen (dpyinfo
->screen
));
3701 DEFUN ("x-display-backing-store", Fx_display_backing_store
,
3702 Sx_display_backing_store
, 0, 1, 0,
3703 doc
: /* Return an indication of whether X display TERMINAL does backing store.
3704 The value may be `always', `when-mapped', or `not-useful'.
3705 The optional argument TERMINAL specifies which display to ask about.
3706 TERMINAL should be a terminal object, a frame or a display name (a string).
3707 If omitted or nil, that stands for the selected frame's display. */)
3708 (Lisp_Object terminal
)
3710 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3713 switch (DoesBackingStore (dpyinfo
->screen
))
3716 result
= intern ("always");
3720 result
= intern ("when-mapped");
3724 result
= intern ("not-useful");
3728 error ("Strange value for BackingStore parameter of screen");
3734 DEFUN ("x-display-visual-class", Fx_display_visual_class
,
3735 Sx_display_visual_class
, 0, 1, 0,
3736 doc
: /* Return the visual class of the X display TERMINAL.
3737 The value is one of the symbols `static-gray', `gray-scale',
3738 `static-color', `pseudo-color', `true-color', or `direct-color'.
3740 The optional argument TERMINAL specifies which display to ask about.
3741 TERMINAL should a terminal object, a frame or a display name (a string).
3742 If omitted or nil, that stands for the selected frame's display. */)
3743 (Lisp_Object terminal
)
3745 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3748 switch (dpyinfo
->visual
->class)
3751 result
= intern ("static-gray");
3754 result
= intern ("gray-scale");
3757 result
= intern ("static-color");
3760 result
= intern ("pseudo-color");
3763 result
= intern ("true-color");
3766 result
= intern ("direct-color");
3769 error ("Display has an unknown visual class");
3775 DEFUN ("x-display-save-under", Fx_display_save_under
,
3776 Sx_display_save_under
, 0, 1, 0,
3777 doc
: /* Return t if the X display TERMINAL supports the save-under feature.
3778 The optional argument TERMINAL specifies which display to ask about.
3779 TERMINAL should be a terminal object, a frame or a display name (a string).
3780 If omitted or nil, that stands for the selected frame's display. */)
3781 (Lisp_Object terminal
)
3783 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
3785 if (DoesSaveUnders (dpyinfo
->screen
) == True
)
3791 /* Store the geometry of the workarea on display DPYINFO into *RECT.
3792 Return false if and only if the workarea information cannot be
3793 obtained via the _NET_WORKAREA root window property. */
3795 #if ! GTK_CHECK_VERSION (3, 4, 0)
3797 x_get_net_workarea (struct x_display_info
*dpyinfo
, XRectangle
*rect
)
3799 Display
*dpy
= dpyinfo
->display
;
3800 long offset
, max_len
;
3801 Atom target_type
, actual_type
;
3802 unsigned long actual_size
, bytes_remaining
;
3803 int rc
, actual_format
;
3804 unsigned char *tmp_data
= NULL
;
3805 bool result
= false;
3807 x_catch_errors (dpy
);
3810 target_type
= XA_CARDINAL
;
3811 rc
= XGetWindowProperty (dpy
, dpyinfo
->root_window
,
3812 dpyinfo
->Xatom_net_current_desktop
,
3813 offset
, max_len
, False
, target_type
,
3814 &actual_type
, &actual_format
, &actual_size
,
3815 &bytes_remaining
, &tmp_data
);
3816 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
3817 && actual_format
== 32 && actual_size
== max_len
)
3819 long current_desktop
= ((long *) tmp_data
)[0];
3824 offset
= 4 * current_desktop
;
3826 rc
= XGetWindowProperty (dpy
, dpyinfo
->root_window
,
3827 dpyinfo
->Xatom_net_workarea
,
3828 offset
, max_len
, False
, target_type
,
3829 &actual_type
, &actual_format
, &actual_size
,
3830 &bytes_remaining
, &tmp_data
);
3831 if (rc
== Success
&& actual_type
== target_type
&& !x_had_errors_p (dpy
)
3832 && actual_format
== 32 && actual_size
== max_len
)
3834 long *values
= (long *) tmp_data
;
3836 rect
->x
= values
[0];
3837 rect
->y
= values
[1];
3838 rect
->width
= values
[2];
3839 rect
->height
= values
[3];
3849 x_uncatch_errors ();
3857 /* Return monitor number where F is "most" or closest to. */
3859 x_get_monitor_for_frame (struct frame
*f
,
3860 struct MonitorInfo
*monitors
,
3864 int area
= 0, dist
= -1;
3865 int best_area
= -1, best_dist
= -1;
3868 if (n_monitors
== 1) return 0;
3869 frect
.x
= f
->left_pos
;
3870 frect
.y
= f
->top_pos
;
3871 frect
.width
= FRAME_PIXEL_WIDTH (f
);
3872 frect
.height
= FRAME_PIXEL_HEIGHT (f
);
3874 for (i
= 0; i
< n_monitors
; ++i
)
3876 struct MonitorInfo
*mi
= &monitors
[i
];
3880 if (mi
->geom
.width
== 0) continue;
3882 if (x_intersect_rectangles (&mi
->geom
, &frect
, &res
))
3884 a
= res
.width
* res
.height
;
3892 if (a
== 0 && area
== 0)
3895 if (frect
.x
+ frect
.width
< mi
->geom
.x
)
3896 dx
= mi
->geom
.x
- frect
.x
+ frect
.width
;
3897 else if (frect
.x
> mi
->geom
.x
+ mi
->geom
.width
)
3898 dx
= frect
.x
- mi
->geom
.x
+ mi
->geom
.width
;
3901 if (frect
.y
+ frect
.height
< mi
->geom
.y
)
3902 dy
= mi
->geom
.y
- frect
.y
+ frect
.height
;
3903 else if (frect
.y
> mi
->geom
.y
+ mi
->geom
.height
)
3904 dy
= frect
.y
- mi
->geom
.y
+ mi
->geom
.height
;
3909 if (dist
== -1 || dist
> d
)
3917 return best_area
!= -1 ? best_area
: (best_dist
!= -1 ? best_dist
: 0);
3921 x_make_monitor_attribute_list (struct MonitorInfo
*monitors
,
3923 int primary_monitor
,
3924 struct x_display_info
*dpyinfo
,
3927 Lisp_Object monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
3928 Lisp_Object frame
, rest
;
3930 FOR_EACH_FRAME (rest
, frame
)
3932 struct frame
*f
= XFRAME (frame
);
3934 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
3935 && !EQ (frame
, tip_frame
))
3937 int i
= x_get_monitor_for_frame (f
, monitors
, n_monitors
);
3938 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
3942 return make_monitor_attribute_list (monitors
, n_monitors
, primary_monitor
,
3943 monitor_frames
, source
);
3947 x_get_monitor_attributes_fallback (struct x_display_info
*dpyinfo
)
3949 struct MonitorInfo monitor
;
3950 XRectangle workarea_r
;
3952 /* Fallback: treat (possibly) multiple physical monitors as if they
3953 formed a single monitor as a whole. This should provide a
3954 consistent result at least on single monitor environments. */
3955 monitor
.geom
.x
= monitor
.geom
.y
= 0;
3956 monitor
.geom
.width
= x_display_pixel_width (dpyinfo
);
3957 monitor
.geom
.height
= x_display_pixel_height (dpyinfo
);
3958 monitor
.mm_width
= WidthMMOfScreen (dpyinfo
->screen
);
3959 monitor
.mm_height
= HeightMMOfScreen (dpyinfo
->screen
);
3960 monitor
.name
= xstrdup ("combined screen");
3962 if (x_get_net_workarea (dpyinfo
, &workarea_r
))
3963 monitor
.work
= workarea_r
;
3965 monitor
.work
= monitor
.geom
;
3966 return x_make_monitor_attribute_list (&monitor
, 1, 0, dpyinfo
, "fallback");
3970 #ifdef HAVE_XINERAMA
3972 x_get_monitor_attributes_xinerama (struct x_display_info
*dpyinfo
)
3975 Lisp_Object attributes_list
= Qnil
;
3976 Display
*dpy
= dpyinfo
->display
;
3977 XineramaScreenInfo
*info
= XineramaQueryScreens (dpy
, &n_monitors
);
3978 struct MonitorInfo
*monitors
;
3979 double mm_width_per_pixel
, mm_height_per_pixel
;
3981 if (! info
|| n_monitors
== 0)
3985 return attributes_list
;
3988 mm_width_per_pixel
= ((double) WidthMMOfScreen (dpyinfo
->screen
)
3989 / x_display_pixel_width (dpyinfo
));
3990 mm_height_per_pixel
= ((double) HeightMMOfScreen (dpyinfo
->screen
)
3991 / x_display_pixel_height (dpyinfo
));
3992 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
3993 for (i
= 0; i
< n_monitors
; ++i
)
3995 struct MonitorInfo
*mi
= &monitors
[i
];
3996 XRectangle workarea_r
;
3998 mi
->geom
.x
= info
[i
].x_org
;
3999 mi
->geom
.y
= info
[i
].y_org
;
4000 mi
->geom
.width
= info
[i
].width
;
4001 mi
->geom
.height
= info
[i
].height
;
4002 mi
->mm_width
= mi
->geom
.width
* mm_width_per_pixel
+ 0.5;
4003 mi
->mm_height
= mi
->geom
.height
* mm_height_per_pixel
+ 0.5;
4006 /* Xinerama usually have primary monitor first, just use that. */
4007 if (i
== 0 && x_get_net_workarea (dpyinfo
, &workarea_r
))
4009 mi
->work
= workarea_r
;
4010 if (! x_intersect_rectangles (&mi
->geom
, &mi
->work
, &mi
->work
))
4011 mi
->work
= mi
->geom
;
4014 mi
->work
= mi
->geom
;
4018 attributes_list
= x_make_monitor_attribute_list (monitors
,
4023 free_monitors (monitors
, n_monitors
);
4024 return attributes_list
;
4026 #endif /* HAVE_XINERAMA */
4031 x_get_monitor_attributes_xrandr (struct x_display_info
*dpyinfo
)
4033 Lisp_Object attributes_list
= Qnil
;
4034 XRRScreenResources
*resources
;
4035 Display
*dpy
= dpyinfo
->display
;
4036 int i
, n_monitors
, primary
= -1;
4037 RROutput pxid
= None
;
4038 struct MonitorInfo
*monitors
;
4040 #ifdef HAVE_XRRGETSCREENRESOURCESCURRENT
4041 resources
= XRRGetScreenResourcesCurrent (dpy
, dpyinfo
->root_window
);
4043 resources
= XRRGetScreenResources (dpy
, dpyinfo
->root_window
);
4045 if (! resources
|| resources
->noutput
== 0)
4048 XRRFreeScreenResources (resources
);
4051 n_monitors
= resources
->noutput
;
4052 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
4054 #ifdef HAVE_XRRGETOUTPUTPRIMARY
4055 pxid
= XRRGetOutputPrimary (dpy
, dpyinfo
->root_window
);
4058 for (i
= 0; i
< n_monitors
; ++i
)
4060 XRROutputInfo
*info
= XRRGetOutputInfo (dpy
, resources
,
4061 resources
->outputs
[i
]);
4062 Connection conn
= info
? info
->connection
: RR_Disconnected
;
4063 RRCrtc id
= info
? info
->crtc
: None
;
4065 if (strcmp (info
->name
, "default") == 0)
4067 /* Non XRandr 1.2 driver, does not give useful data. */
4068 XRRFreeOutputInfo (info
);
4069 XRRFreeScreenResources (resources
);
4070 free_monitors (monitors
, n_monitors
);
4074 if (conn
!= RR_Disconnected
&& id
!= None
)
4076 XRRCrtcInfo
*crtc
= XRRGetCrtcInfo (dpy
, resources
, id
);
4077 struct MonitorInfo
*mi
= &monitors
[i
];
4078 XRectangle workarea_r
;
4082 XRRFreeOutputInfo (info
);
4086 mi
->geom
.x
= crtc
->x
;
4087 mi
->geom
.y
= crtc
->y
;
4088 mi
->geom
.width
= crtc
->width
;
4089 mi
->geom
.height
= crtc
->height
;
4090 mi
->mm_width
= info
->mm_width
;
4091 mi
->mm_height
= info
->mm_height
;
4092 mi
->name
= xstrdup (info
->name
);
4094 if (pxid
!= None
&& pxid
== resources
->outputs
[i
])
4096 else if (primary
== -1 && strcmp (info
->name
, "LVDS") == 0)
4099 if (i
== primary
&& x_get_net_workarea (dpyinfo
, &workarea_r
))
4101 mi
->work
= workarea_r
;
4102 if (! x_intersect_rectangles (&mi
->geom
, &mi
->work
, &mi
->work
))
4103 mi
->work
= mi
->geom
;
4106 mi
->work
= mi
->geom
;
4108 XRRFreeCrtcInfo (crtc
);
4110 XRRFreeOutputInfo (info
);
4112 XRRFreeScreenResources (resources
);
4114 attributes_list
= x_make_monitor_attribute_list (monitors
,
4119 free_monitors (monitors
, n_monitors
);
4120 return attributes_list
;
4122 #endif /* HAVE_XRANDR */
4125 x_get_monitor_attributes (struct x_display_info
*dpyinfo
)
4127 Lisp_Object attributes_list
= Qnil
;
4128 Display
*dpy
= dpyinfo
->display
;
4130 (void) dpy
; /* Suppress unused variable warning. */
4133 int xrr_event_base
, xrr_error_base
;
4134 bool xrr_ok
= false;
4135 xrr_ok
= XRRQueryExtension (dpy
, &xrr_event_base
, &xrr_error_base
);
4138 int xrr_major
, xrr_minor
;
4139 XRRQueryVersion (dpy
, &xrr_major
, &xrr_minor
);
4140 xrr_ok
= (xrr_major
== 1 && xrr_minor
>= 2) || xrr_major
> 1;
4144 attributes_list
= x_get_monitor_attributes_xrandr (dpyinfo
);
4145 #endif /* HAVE_XRANDR */
4147 #ifdef HAVE_XINERAMA
4148 if (NILP (attributes_list
))
4150 int xin_event_base
, xin_error_base
;
4151 bool xin_ok
= false;
4152 xin_ok
= XineramaQueryExtension (dpy
, &xin_event_base
, &xin_error_base
);
4153 if (xin_ok
&& XineramaIsActive (dpy
))
4154 attributes_list
= x_get_monitor_attributes_xinerama (dpyinfo
);
4156 #endif /* HAVE_XINERAMA */
4158 if (NILP (attributes_list
))
4159 attributes_list
= x_get_monitor_attributes_fallback (dpyinfo
);
4161 return attributes_list
;
4164 #endif /* !USE_GTK */
4166 DEFUN ("x-display-monitor-attributes-list", Fx_display_monitor_attributes_list
,
4167 Sx_display_monitor_attributes_list
,
4169 doc
: /* Return a list of physical monitor attributes on the X display TERMINAL.
4171 The optional argument TERMINAL specifies which display to ask about.
4172 TERMINAL should be a terminal object, a frame or a display name (a string).
4173 If omitted or nil, that stands for the selected frame's display.
4175 In addition to the standard attribute keys listed in
4176 `display-monitor-attributes-list', the following keys are contained in
4179 source -- String describing the source from which multi-monitor
4180 information is obtained, one of \"Gdk\", \"XRandr\",
4181 \"Xinerama\", or \"fallback\"
4183 Internal use only, use `display-monitor-attributes-list' instead. */)
4184 (Lisp_Object terminal
)
4186 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4187 Lisp_Object attributes_list
= Qnil
;
4190 double mm_width_per_pixel
, mm_height_per_pixel
;
4193 gint primary_monitor
= 0, n_monitors
, i
;
4194 Lisp_Object monitor_frames
, rest
, frame
;
4195 static const char *source
= "Gdk";
4196 struct MonitorInfo
*monitors
;
4199 mm_width_per_pixel
= ((double) WidthMMOfScreen (dpyinfo
->screen
)
4200 / x_display_pixel_width (dpyinfo
));
4201 mm_height_per_pixel
= ((double) HeightMMOfScreen (dpyinfo
->screen
)
4202 / x_display_pixel_height (dpyinfo
));
4203 gdpy
= gdk_x11_lookup_xdisplay (dpyinfo
->display
);
4204 gscreen
= gdk_display_get_default_screen (gdpy
);
4205 #if GTK_CHECK_VERSION (2, 20, 0)
4206 primary_monitor
= gdk_screen_get_primary_monitor (gscreen
);
4208 n_monitors
= gdk_screen_get_n_monitors (gscreen
);
4209 monitor_frames
= Fmake_vector (make_number (n_monitors
), Qnil
);
4210 monitors
= xzalloc (n_monitors
* sizeof *monitors
);
4212 FOR_EACH_FRAME (rest
, frame
)
4214 struct frame
*f
= XFRAME (frame
);
4216 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
4217 && !EQ (frame
, tip_frame
))
4219 GdkWindow
*gwin
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
4221 i
= gdk_screen_get_monitor_at_window (gscreen
, gwin
);
4222 ASET (monitor_frames
, i
, Fcons (frame
, AREF (monitor_frames
, i
)));
4226 for (i
= 0; i
< n_monitors
; ++i
)
4228 gint width_mm
= -1, height_mm
= -1;
4229 GdkRectangle rec
, work
;
4230 struct MonitorInfo
*mi
= &monitors
[i
];
4232 gdk_screen_get_monitor_geometry (gscreen
, i
, &rec
);
4234 #if GTK_CHECK_VERSION (2, 14, 0)
4235 width_mm
= gdk_screen_get_monitor_width_mm (gscreen
, i
);
4236 height_mm
= gdk_screen_get_monitor_height_mm (gscreen
, i
);
4239 width_mm
= rec
.width
* mm_width_per_pixel
+ 0.5;
4241 height_mm
= rec
.height
* mm_height_per_pixel
+ 0.5;
4243 #if GTK_CHECK_VERSION (3, 4, 0)
4244 gdk_screen_get_monitor_workarea (gscreen
, i
, &work
);
4246 /* Emulate the behavior of GTK+ 3.4. */
4248 XRectangle workarea_r
;
4250 if (i
== primary_monitor
&& x_get_net_workarea (dpyinfo
, &workarea_r
))
4252 work
.x
= workarea_r
.x
;
4253 work
.y
= workarea_r
.y
;
4254 work
.width
= workarea_r
.width
;
4255 work
.height
= workarea_r
.height
;
4256 if (! gdk_rectangle_intersect (&rec
, &work
, &work
))
4267 mi
->geom
.width
= rec
.width
;
4268 mi
->geom
.height
= rec
.height
;
4269 mi
->work
.x
= work
.x
;
4270 mi
->work
.y
= work
.y
;
4271 mi
->work
.width
= work
.width
;
4272 mi
->work
.height
= work
.height
;
4273 mi
->mm_width
= width_mm
;
4274 mi
->mm_height
= height_mm
;
4276 #if GTK_CHECK_VERSION (2, 14, 0)
4277 mi
->name
= gdk_screen_get_monitor_plug_name (gscreen
, i
);
4281 attributes_list
= make_monitor_attribute_list (monitors
,
4287 #else /* not USE_GTK */
4290 attributes_list
= x_get_monitor_attributes (dpyinfo
);
4293 #endif /* not USE_GTK */
4295 return attributes_list
;
4298 /* Return geometric attributes of FRAME. According to the value of
4299 ATTRIBUTES return the outer edges of FRAME (Qouter_edges), the native
4300 edges of FRAME (Qnative_edges), or the inner edges of frame
4301 (Qinner_edges). Any other value means to return the geometry as
4302 returned by Fx_frame_geometry. */
4304 frame_geometry (Lisp_Object frame
, Lisp_Object attribute
)
4306 struct frame
*f
= decode_live_frame (frame
);
4307 /** XWindowAttributes atts; **/
4309 unsigned int ign
, native_width
, native_height
;
4310 int xy_ign
, xptr
, yptr
;
4311 int left_off
, right_off
, top_off
, bottom_off
;
4312 int outer_left
, outer_top
, outer_right
, outer_bottom
;
4313 int native_left
, native_top
, native_right
, native_bottom
;
4314 int inner_left
, inner_top
, inner_right
, inner_bottom
;
4315 int internal_border_width
;
4316 bool menu_bar_external
= false, tool_bar_external
= false;
4317 int menu_bar_height
= 0, menu_bar_width
= 0;
4318 int tool_bar_height
= 0, tool_bar_width
= 0;
4320 if (FRAME_INITIAL_P (f
) || !FRAME_X_P (f
))
4324 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
4325 &rootw
, &xy_ign
, &xy_ign
, &native_width
, &native_height
,
4327 /** XGetWindowAttributes (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f), &atts); **/
4328 x_real_pos_and_offsets (f
, &left_off
, &right_off
, &top_off
, &bottom_off
,
4329 NULL
, NULL
, &xptr
, &yptr
, NULL
);
4332 /** native_width = atts.width; **/
4333 /** native_height = atts.height; **/
4337 outer_right
= outer_left
+ left_off
+ native_width
+ right_off
;
4338 outer_bottom
= outer_top
+ top_off
+ native_height
+ bottom_off
;
4340 native_left
= outer_left
+ left_off
;
4341 native_top
= outer_top
+ top_off
;
4342 native_right
= native_left
+ native_width
;
4343 native_bottom
= native_top
+ native_height
;
4345 internal_border_width
= FRAME_INTERNAL_BORDER_WIDTH (f
);
4346 inner_left
= native_left
+ internal_border_width
;
4347 inner_top
= native_top
+ internal_border_width
;
4348 inner_right
= native_right
- internal_border_width
;
4349 inner_bottom
= native_bottom
- internal_border_width
;
4351 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
4352 menu_bar_external
= true;
4353 menu_bar_height
= FRAME_MENUBAR_HEIGHT (f
);
4354 native_top
+= menu_bar_height
;
4355 inner_top
+= menu_bar_height
;
4357 menu_bar_height
= FRAME_MENU_BAR_HEIGHT (f
);
4358 inner_top
+= menu_bar_height
;
4360 menu_bar_width
= menu_bar_height
? native_width
: 0;
4362 #if defined (USE_GTK)
4363 tool_bar_external
= true;
4364 if (EQ (FRAME_TOOL_BAR_POSITION (f
), Qleft
))
4366 tool_bar_width
= FRAME_TOOLBAR_WIDTH (f
);
4367 native_left
+= tool_bar_width
;
4368 inner_left
+= tool_bar_width
;
4370 = tool_bar_width
? native_height
- menu_bar_height
: 0;
4372 else if (EQ (FRAME_TOOL_BAR_POSITION (f
), Qtop
))
4374 tool_bar_height
= FRAME_TOOLBAR_HEIGHT (f
);
4375 native_top
+= tool_bar_height
;
4376 inner_top
+= tool_bar_height
;
4377 tool_bar_width
= tool_bar_height
? native_width
: 0;
4379 else if (EQ (FRAME_TOOL_BAR_POSITION (f
), Qright
))
4381 tool_bar_width
= FRAME_TOOLBAR_WIDTH (f
);
4382 native_right
-= tool_bar_width
;
4383 inner_right
-= tool_bar_width
;
4385 = tool_bar_width
? native_height
- menu_bar_height
: 0;
4389 tool_bar_height
= FRAME_TOOLBAR_HEIGHT (f
);
4390 native_bottom
-= tool_bar_height
;
4391 inner_bottom
-= tool_bar_height
;
4392 tool_bar_width
= tool_bar_height
? native_width
: 0;
4395 tool_bar_height
= FRAME_TOOL_BAR_HEIGHT (f
);
4396 tool_bar_width
= tool_bar_height
? native_width
: 0;
4397 inner_top
+= tool_bar_height
;
4400 /* Construct list. */
4401 if (EQ (attribute
, Qouter_edges
))
4402 return list4 (make_number (outer_left
), make_number (outer_top
),
4403 make_number (outer_right
), make_number (outer_bottom
));
4404 else if (EQ (attribute
, Qnative_edges
))
4405 return list4 (make_number (native_left
), make_number (native_top
),
4406 make_number (native_right
), make_number (native_bottom
));
4407 else if (EQ (attribute
, Qinner_edges
))
4408 return list4 (make_number (inner_left
), make_number (inner_top
),
4409 make_number (inner_right
), make_number (inner_bottom
));
4412 listn (CONSTYPE_HEAP
, 10,
4413 Fcons (Qouter_position
,
4414 Fcons (make_number (outer_left
),
4415 make_number (outer_top
))),
4417 Fcons (make_number (outer_right
- outer_left
),
4418 make_number (outer_bottom
- outer_top
))),
4420 Fcons (Qexternal_border_size
,
4421 Fcons (make_number (right_off
),
4422 make_number (bottom_off
))),
4424 Fcons (Qtitle_bar_size
,
4425 Fcons (make_number (0),
4426 make_number (top_off
- bottom_off
))),
4427 Fcons (Qmenu_bar_external
, menu_bar_external
? Qt
: Qnil
),
4428 Fcons (Qmenu_bar_size
,
4429 Fcons (make_number (menu_bar_width
),
4430 make_number (menu_bar_height
))),
4431 Fcons (Qtool_bar_external
, tool_bar_external
? Qt
: Qnil
),
4432 Fcons (Qtool_bar_position
, FRAME_TOOL_BAR_POSITION (f
)),
4433 Fcons (Qtool_bar_size
,
4434 Fcons (make_number (tool_bar_width
),
4435 make_number (tool_bar_height
))),
4436 Fcons (Qinternal_border_width
,
4437 make_number (internal_border_width
)));
4440 DEFUN ("x-frame-geometry", Fx_frame_geometry
, Sx_frame_geometry
, 0, 1, 0,
4441 doc
: /* Return geometric attributes of FRAME.
4442 FRAME must be a live frame and defaults to the selected one. The return
4443 value is an association list of the attributes listed below. All height
4444 and width values are in pixels.
4446 `outer-position' is a cons of the outer left and top edges of FRAME
4447 relative to the origin - the position (0, 0) - of FRAME's display.
4449 `outer-size' is a cons of the outer width and height of FRAME. The
4450 outer size includes the title bar and the external borders as well as
4451 any menu and/or tool bar of frame.
4453 `external-border-size' is a cons of the horizontal and vertical width of
4454 FRAME's external borders as supplied by the window manager.
4456 `title-bar-size' is a cons of the width and height of the title bar of
4457 FRAME as supplied by the window manager. If both of them are zero,
4458 FRAME has no title bar. If only the width is zero, Emacs was not
4459 able to retrieve the width information.
4461 `menu-bar-external', if non-nil, means the menu bar is external (never
4462 included in the inner edges of FRAME).
4464 `menu-bar-size' is a cons of the width and height of the menu bar of
4467 `tool-bar-external', if non-nil, means the tool bar is external (never
4468 included in the inner edges of FRAME).
4470 `tool-bar-position' tells on which side the tool bar on FRAME is and can
4471 be one of `left', `top', `right' or `bottom'. If this is nil, FRAME
4474 `tool-bar-size' is a cons of the width and height of the tool bar of
4477 `internal-border-width' is the width of the internal border of
4481 return frame_geometry (frame
, Qnil
);
4484 DEFUN ("x-frame-edges", Fx_frame_edges
, Sx_frame_edges
, 0, 2, 0,
4485 doc
: /* Return edge coordinates of FRAME.
4486 FRAME must be a live frame and defaults to the selected one. The return
4487 value is a list of the form (LEFT, TOP, RIGHT, BOTTOM). All values are
4488 in pixels relative to the origin - the position (0, 0) - of FRAME's
4491 If optional argument TYPE is the symbol `outer-edges', return the outer
4492 edges of FRAME. The outer edges comprise the decorations of the window
4493 manager (like the title bar or external borders) as well as any external
4494 menu or tool bar of FRAME. If optional argument TYPE is the symbol
4495 `native-edges' or nil, return the native edges of FRAME. The native
4496 edges exclude the decorations of the window manager and any external
4497 menu or tool bar of FRAME. If TYPE is the symbol `inner-edges', return
4498 the inner edges of FRAME. These edges exclude title bar, any borders,
4499 menu bar or tool bar of FRAME. */)
4500 (Lisp_Object frame
, Lisp_Object type
)
4502 return frame_geometry (frame
, ((EQ (type
, Qouter_edges
)
4503 || EQ (type
, Qinner_edges
))
4508 DEFUN ("x-mouse-absolute-pixel-position", Fx_mouse_absolute_pixel_position
,
4509 Sx_mouse_absolute_pixel_position
, 0, 0, 0,
4510 doc
: /* Return absolute position of mouse cursor in pixels.
4511 The position is returned as a cons cell (X . Y) of the coordinates of
4512 the mouse cursor position in pixels relative to a position (0, 0) of the
4513 selected frame's display. */)
4516 struct frame
*f
= SELECTED_FRAME ();
4517 Window root
, dummy_window
;
4520 if (FRAME_INITIAL_P (f
) || !FRAME_X_P (f
))
4524 XQueryPointer (FRAME_X_DISPLAY (f
),
4525 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
4526 &root
, &dummy_window
, &x
, &y
, &dummy
, &dummy
,
4527 (unsigned int *) &dummy
);
4530 return Fcons (make_number (x
), make_number (y
));
4533 DEFUN ("x-set-mouse-absolute-pixel-position", Fx_set_mouse_absolute_pixel_position
,
4534 Sx_set_mouse_absolute_pixel_position
, 2, 2, 0,
4535 doc
: /* Move mouse pointer to absolute pixel position (X, Y).
4536 The coordinates X and Y are interpreted in pixels relative to a position
4537 (0, 0) of the selected frame's display. */)
4538 (Lisp_Object x
, Lisp_Object y
)
4540 struct frame
*f
= SELECTED_FRAME ();
4542 if (FRAME_INITIAL_P (f
) || !FRAME_X_P (f
))
4545 CHECK_TYPE_RANGED_INTEGER (int, x
);
4546 CHECK_TYPE_RANGED_INTEGER (int, y
);
4549 XWarpPointer (FRAME_X_DISPLAY (f
), None
, DefaultRootWindow (FRAME_X_DISPLAY (f
)),
4550 0, 0, 0, 0, XINT (x
), XINT (y
));
4556 /************************************************************************
4558 ************************************************************************/
4561 /* Mapping visual names to visuals. */
4563 static struct visual_class
4570 {"StaticGray", StaticGray
},
4571 {"GrayScale", GrayScale
},
4572 {"StaticColor", StaticColor
},
4573 {"PseudoColor", PseudoColor
},
4574 {"TrueColor", TrueColor
},
4575 {"DirectColor", DirectColor
},
4580 #ifndef HAVE_XSCREENNUMBEROFSCREEN
4582 /* Value is the screen number of screen SCR. This is a substitute for
4583 the X function with the same name when that doesn't exist. */
4586 XScreenNumberOfScreen (scr
)
4587 register Screen
*scr
;
4589 Display
*dpy
= scr
->display
;
4592 for (i
= 0; i
< dpy
->nscreens
; ++i
)
4593 if (scr
== dpy
->screens
+ i
)
4599 #endif /* not HAVE_XSCREENNUMBEROFSCREEN */
4602 /* Select the visual that should be used on display DPYINFO. Set
4603 members of DPYINFO appropriately. Called from x_term_init. */
4606 select_visual (struct x_display_info
*dpyinfo
)
4608 Display
*dpy
= dpyinfo
->display
;
4609 Screen
*screen
= dpyinfo
->screen
;
4611 /* See if a visual is specified. */
4612 AUTO_STRING (visualClass
, "visualClass");
4613 AUTO_STRING (VisualClass
, "VisualClass");
4614 Lisp_Object value
= display_x_get_resource (dpyinfo
, visualClass
,
4615 VisualClass
, Qnil
, Qnil
);
4617 if (STRINGP (value
))
4619 /* VALUE should be of the form CLASS-DEPTH, where CLASS is one
4620 of `PseudoColor', `TrueColor' etc. and DEPTH is the color
4621 depth, a decimal number. NAME is compared with case ignored. */
4622 char *s
= alloca (SBYTES (value
) + 1);
4627 lispstpcpy (s
, value
);
4628 dash
= strchr (s
, '-');
4631 dpyinfo
->n_planes
= atoi (dash
+ 1);
4635 /* We won't find a matching visual with depth 0, so that
4636 an error will be printed below. */
4637 dpyinfo
->n_planes
= 0;
4639 /* Determine the visual class. */
4640 for (i
= 0; visual_classes
[i
].name
; ++i
)
4641 if (xstrcasecmp (s
, visual_classes
[i
].name
) == 0)
4643 class = visual_classes
[i
].class;
4647 /* Look up a matching visual for the specified class. */
4649 || !XMatchVisualInfo (dpy
, XScreenNumberOfScreen (screen
),
4650 dpyinfo
->n_planes
, class, &vinfo
))
4651 fatal ("Invalid visual specification '%s'",
4652 SSDATA (ENCODE_SYSTEM (value
)));
4654 dpyinfo
->visual
= vinfo
.visual
;
4659 XVisualInfo
*vinfo
, vinfo_template
;
4661 dpyinfo
->visual
= DefaultVisualOfScreen (screen
);
4663 vinfo_template
.visualid
= XVisualIDFromVisual (dpyinfo
->visual
);
4664 vinfo_template
.screen
= XScreenNumberOfScreen (screen
);
4665 vinfo
= XGetVisualInfo (dpy
, VisualIDMask
| VisualScreenMask
,
4666 &vinfo_template
, &n_visuals
);
4668 fatal ("Can't get proper X visual info");
4670 dpyinfo
->n_planes
= vinfo
->depth
;
4676 /* Return the X display structure for the display named NAME.
4677 Open a new connection if necessary. */
4679 static struct x_display_info
*
4680 x_display_info_for_name (Lisp_Object name
)
4682 struct x_display_info
*dpyinfo
;
4684 CHECK_STRING (name
);
4686 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
4687 if (!NILP (Fstring_equal (XCAR (dpyinfo
->name_list_element
), name
)))
4690 /* Use this general default value to start with. */
4691 Vx_resource_name
= Vinvocation_name
;
4693 validate_x_resource_name ();
4695 dpyinfo
= x_term_init (name
, 0, SSDATA (Vx_resource_name
));
4698 error ("Cannot connect to X server %s", SDATA (name
));
4700 XSETFASTINT (Vwindow_system_version
, 11);
4706 DEFUN ("x-open-connection", Fx_open_connection
, Sx_open_connection
,
4708 doc
: /* Open a connection to a display server.
4709 DISPLAY is the name of the display to connect to.
4710 Optional second arg XRM-STRING is a string of resources in xrdb format.
4711 If the optional third arg MUST-SUCCEED is non-nil,
4712 terminate Emacs if we can't open the connection.
4713 \(In the Nextstep version, the last two arguments are currently ignored.) */)
4714 (Lisp_Object display
, Lisp_Object xrm_string
, Lisp_Object must_succeed
)
4717 struct x_display_info
*dpyinfo
;
4719 CHECK_STRING (display
);
4720 if (! NILP (xrm_string
))
4721 CHECK_STRING (xrm_string
);
4723 xrm_option
= NILP (xrm_string
) ? 0 : SSDATA (xrm_string
);
4725 validate_x_resource_name ();
4727 /* This is what opens the connection and sets x_current_display.
4728 This also initializes many symbols, such as those used for input. */
4729 dpyinfo
= x_term_init (display
, xrm_option
,
4730 SSDATA (Vx_resource_name
));
4734 if (!NILP (must_succeed
))
4735 fatal ("Cannot connect to X server %s.\n\
4736 Check the DISPLAY environment variable or use `-d'.\n\
4737 Also use the `xauth' program to verify that you have the proper\n\
4738 authorization information needed to connect the X server.\n\
4739 An insecure way to solve the problem may be to use `xhost'.\n",
4742 error ("Cannot connect to X server %s", SDATA (display
));
4745 XSETFASTINT (Vwindow_system_version
, 11);
4749 DEFUN ("x-close-connection", Fx_close_connection
,
4750 Sx_close_connection
, 1, 1, 0,
4751 doc
: /* Close the connection to TERMINAL's X server.
4752 For TERMINAL, specify a terminal object, a frame or a display name (a
4753 string). If TERMINAL is nil, that stands for the selected frame's
4755 (Lisp_Object terminal
)
4757 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4759 if (dpyinfo
->reference_count
> 0)
4760 error ("Display still has frames on it");
4762 x_delete_terminal (dpyinfo
->terminal
);
4767 DEFUN ("x-display-list", Fx_display_list
, Sx_display_list
, 0, 0, 0,
4768 doc
: /* Return the list of display names that Emacs has connections to. */)
4771 Lisp_Object result
= Qnil
;
4772 struct x_display_info
*xdi
;
4774 for (xdi
= x_display_list
; xdi
; xdi
= xdi
->next
)
4775 result
= Fcons (XCAR (xdi
->name_list_element
), result
);
4780 DEFUN ("x-synchronize", Fx_synchronize
, Sx_synchronize
, 1, 2, 0,
4781 doc
: /* If ON is non-nil, report X errors as soon as the erring request is made.
4782 This function only has an effect on X Windows. With MS Windows, it is
4783 defined but does nothing.
4785 If ON is nil, allow buffering of requests.
4786 Turning on synchronization prohibits the Xlib routines from buffering
4787 requests and seriously degrades performance, but makes debugging much
4789 The optional second argument TERMINAL specifies which display to act on.
4790 TERMINAL should be a terminal object, a frame or a display name (a string).
4791 If TERMINAL is omitted or nil, that stands for the selected frame's display. */)
4792 (Lisp_Object on
, Lisp_Object terminal
)
4794 struct x_display_info
*dpyinfo
= check_x_display_info (terminal
);
4796 XSynchronize (dpyinfo
->display
, !EQ (on
, Qnil
));
4801 /* Wait for responses to all X commands issued so far for frame F. */
4804 x_sync (struct frame
*f
)
4807 XSync (FRAME_X_DISPLAY (f
), False
);
4812 /***********************************************************************
4814 ***********************************************************************/
4816 DEFUN ("x-change-window-property", Fx_change_window_property
,
4817 Sx_change_window_property
, 2, 6, 0,
4818 doc
: /* Change window property PROP to VALUE on the X window of FRAME.
4819 PROP must be a string. VALUE may be a string or a list of conses,
4820 numbers and/or strings. If an element in the list is a string, it is
4821 converted to an atom and the value of the atom is used. If an element
4822 is a cons, it is converted to a 32 bit number where the car is the 16
4823 top bits and the cdr is the lower 16 bits.
4825 FRAME nil or omitted means use the selected frame.
4826 If TYPE is given and non-nil, it is the name of the type of VALUE.
4827 If TYPE is not given or nil, the type is STRING.
4828 FORMAT gives the size in bits of each element if VALUE is a list.
4829 It must be one of 8, 16 or 32.
4830 If VALUE is a string or FORMAT is nil or not given, FORMAT defaults to 8.
4831 If OUTER-P is non-nil, the property is changed for the outer X window of
4832 FRAME. Default is to change on the edit X window. */)
4833 (Lisp_Object prop
, Lisp_Object value
, Lisp_Object frame
,
4834 Lisp_Object type
, Lisp_Object format
, Lisp_Object outer_p
)
4836 struct frame
*f
= decode_window_system_frame (frame
);
4838 Atom target_type
= XA_STRING
;
4839 int element_format
= 8;
4840 unsigned char *data
;
4844 CHECK_STRING (prop
);
4846 if (! NILP (format
))
4848 CHECK_NUMBER (format
);
4850 if (XINT (format
) != 8 && XINT (format
) != 16
4851 && XINT (format
) != 32)
4852 error ("FORMAT must be one of 8, 16 or 32");
4853 element_format
= XINT (format
);
4860 nelements
= x_check_property_data (value
);
4861 if (nelements
== -1)
4862 error ("Bad data in VALUE, must be number, string or cons");
4864 /* The man page for XChangeProperty:
4865 "If the specified format is 32, the property data must be a
4867 This applies even if long is more than 32 bits. The X library
4868 converts to 32 bits before sending to the X server. */
4869 elsize
= element_format
== 32 ? sizeof (long) : element_format
>> 3;
4870 data
= xnmalloc (nelements
, elsize
);
4872 x_fill_property_data (FRAME_X_DISPLAY (f
), value
, data
, element_format
);
4876 CHECK_STRING (value
);
4877 data
= SDATA (value
);
4878 if (INT_MAX
< SBYTES (value
))
4879 error ("VALUE too long");
4880 nelements
= SBYTES (value
);
4884 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4887 CHECK_STRING (type
);
4888 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
4891 if (! NILP (outer_p
)) w
= FRAME_OUTER_WINDOW (f
);
4892 else w
= FRAME_X_WINDOW (f
);
4894 XChangeProperty (FRAME_X_DISPLAY (f
), w
,
4895 prop_atom
, target_type
, element_format
, PropModeReplace
,
4898 if (CONSP (value
)) xfree (data
);
4900 /* Make sure the property is set when we return. */
4901 XFlush (FRAME_X_DISPLAY (f
));
4908 DEFUN ("x-delete-window-property", Fx_delete_window_property
,
4909 Sx_delete_window_property
, 1, 2, 0,
4910 doc
: /* Remove window property PROP from X window of FRAME.
4911 FRAME nil or omitted means use the selected frame. Value is PROP. */)
4912 (Lisp_Object prop
, Lisp_Object frame
)
4914 struct frame
*f
= decode_window_system_frame (frame
);
4917 CHECK_STRING (prop
);
4919 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
4920 XDeleteProperty (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), prop_atom
);
4922 /* Make sure the property is removed when we return. */
4923 XFlush (FRAME_X_DISPLAY (f
));
4931 x_window_property_intern (struct frame
*f
,
4932 Window target_window
,
4935 Lisp_Object delete_p
,
4936 Lisp_Object vector_ret_p
,
4939 unsigned char *tmp_data
= NULL
;
4940 Lisp_Object prop_value
= Qnil
;
4943 unsigned long actual_size
, bytes_remaining
;
4946 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4947 prop_atom
, 0, 0, False
, target_type
,
4948 &actual_type
, &actual_format
, &actual_size
,
4949 &bytes_remaining
, &tmp_data
);
4951 *found
= actual_format
!= 0;
4953 if (rc
== Success
&& *found
)
4958 rc
= XGetWindowProperty (FRAME_X_DISPLAY (f
), target_window
,
4959 prop_atom
, 0, bytes_remaining
,
4960 ! NILP (delete_p
), target_type
,
4961 &actual_type
, &actual_format
,
4962 &actual_size
, &bytes_remaining
,
4964 if (rc
== Success
&& tmp_data
)
4966 /* The man page for XGetWindowProperty says:
4967 "If the returned format is 32, the returned data is represented
4968 as a long array and should be cast to that type to obtain the
4970 This applies even if long is more than 32 bits, the X library
4971 converts from 32 bit elements received from the X server to long
4972 and passes the long array to us. Thus, for that case memcpy can not
4973 be used. We convert to a 32 bit type here, because so much code
4976 The bytes and offsets passed to XGetWindowProperty refers to the
4977 property and those are indeed in 32 bit quantities if format is
4980 if (BITS_PER_LONG
> 32 && actual_format
== 32)
4983 int *idata
= (int *) tmp_data
;
4984 long *ldata
= (long *) tmp_data
;
4986 for (i
= 0; i
< actual_size
; ++i
)
4987 idata
[i
] = (int) ldata
[i
];
4990 if (NILP (vector_ret_p
))
4991 prop_value
= make_string ((char *) tmp_data
, actual_size
);
4993 prop_value
= x_property_data_to_lisp (f
,
5000 if (tmp_data
) XFree (tmp_data
);
5006 DEFUN ("x-window-property", Fx_window_property
, Sx_window_property
,
5008 doc
: /* Value is the value of window property PROP on FRAME.
5009 If FRAME is nil or omitted, use the selected frame.
5011 On X Windows, the following optional arguments are also accepted:
5012 If TYPE is nil or omitted, get the property as a string.
5013 Otherwise TYPE is the name of the atom that denotes the type expected.
5014 If SOURCE is non-nil, get the property on that window instead of from
5015 FRAME. The number 0 denotes the root window.
5016 If DELETE-P is non-nil, delete the property after retrieving it.
5017 If VECTOR-RET-P is non-nil, don't return a string but a vector of values.
5019 On MS Windows, this function accepts but ignores those optional arguments.
5021 Value is nil if FRAME hasn't a property with name PROP or if PROP has
5022 no value of TYPE (always string in the MS Windows case). */)
5023 (Lisp_Object prop
, Lisp_Object frame
, Lisp_Object type
,
5024 Lisp_Object source
, Lisp_Object delete_p
, Lisp_Object vector_ret_p
)
5026 struct frame
*f
= decode_window_system_frame (frame
);
5028 Lisp_Object prop_value
= Qnil
;
5029 Atom target_type
= XA_STRING
;
5030 Window target_window
= FRAME_X_WINDOW (f
);
5033 CHECK_STRING (prop
);
5035 if (! NILP (source
))
5037 CONS_TO_INTEGER (source
, Window
, target_window
);
5038 if (! target_window
)
5039 target_window
= FRAME_DISPLAY_INFO (f
)->root_window
;
5045 if (strcmp ("AnyPropertyType", SSDATA (type
)) == 0)
5046 target_type
= AnyPropertyType
;
5048 target_type
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (type
), False
);
5051 prop_atom
= XInternAtom (FRAME_X_DISPLAY (f
), SSDATA (prop
), False
);
5052 prop_value
= x_window_property_intern (f
,
5059 if (NILP (prop_value
)
5062 && target_window
!= FRAME_OUTER_WINDOW (f
))
5064 prop_value
= x_window_property_intern (f
,
5065 FRAME_OUTER_WINDOW (f
),
5078 /***********************************************************************
5080 ***********************************************************************/
5082 static Lisp_Object
x_create_tip_frame (struct x_display_info
*,
5083 Lisp_Object
, Lisp_Object
);
5084 static void compute_tip_xy (struct frame
*, Lisp_Object
, Lisp_Object
,
5085 Lisp_Object
, int, int, int *, int *);
5087 /* The frame of a currently visible tooltip. */
5089 Lisp_Object tip_frame
;
5091 /* If non-nil, a timer started that hides the last tooltip when it
5094 static Lisp_Object tip_timer
;
5097 /* If non-nil, a vector of 3 elements containing the last args
5098 with which x-show-tip was called. See there. */
5100 static Lisp_Object last_show_tip_args
;
5104 unwind_create_tip_frame (Lisp_Object frame
)
5106 Lisp_Object deleted
;
5108 deleted
= unwind_create_frame (frame
);
5109 if (EQ (deleted
, Qt
))
5117 /* Create a frame for a tooltip on the display described by DPYINFO.
5118 PARMS is a list of frame parameters. TEXT is the string to
5119 display in the tip frame. Value is the frame.
5121 Note that functions called here, esp. x_default_parameter can
5122 signal errors, for instance when a specified color name is
5123 undefined. We have to make sure that we're in a consistent state
5124 when this happens. */
5127 x_create_tip_frame (struct x_display_info
*dpyinfo
,
5135 ptrdiff_t count
= SPECPDL_INDEX ();
5136 bool face_change_before
= face_change
;
5138 struct buffer
*old_buffer
;
5140 if (!dpyinfo
->terminal
->name
)
5141 error ("Terminal is not live, can't create new frames on it");
5143 parms
= Fcopy_alist (parms
);
5145 /* Get the name of the frame to use for resource lookup. */
5146 name
= x_get_arg (dpyinfo
, parms
, Qname
, "name", "Name", RES_TYPE_STRING
);
5148 && !EQ (name
, Qunbound
)
5150 error ("Invalid frame name--not a string or nil");
5153 f
= make_frame (true);
5154 XSETFRAME (frame
, f
);
5156 AUTO_STRING (tip
, " *tip*");
5157 buffer
= Fget_buffer_create (tip
);
5158 /* Use set_window_buffer instead of Fset_window_buffer (see
5159 discussion of bug#11984, bug#12025, bug#12026). */
5160 set_window_buffer (FRAME_ROOT_WINDOW (f
), buffer
, false, false);
5161 old_buffer
= current_buffer
;
5162 set_buffer_internal_1 (XBUFFER (buffer
));
5163 bset_truncate_lines (current_buffer
, Qnil
);
5164 specbind (Qinhibit_read_only
, Qt
);
5165 specbind (Qinhibit_modification_hooks
, Qt
);
5168 set_buffer_internal_1 (old_buffer
);
5170 record_unwind_protect (unwind_create_tip_frame
, frame
);
5172 f
->terminal
= dpyinfo
->terminal
;
5174 /* By setting the output method, we're essentially saying that
5175 the frame is live, as per FRAME_LIVE_P. If we get a signal
5176 from this point on, x_destroy_window might screw up reference
5178 f
->output_method
= output_x_window
;
5179 f
->output_data
.x
= xzalloc (sizeof *f
->output_data
.x
);
5180 f
->output_data
.x
->icon_bitmap
= -1;
5181 FRAME_FONTSET (f
) = -1;
5182 f
->output_data
.x
->scroll_bar_foreground_pixel
= -1;
5183 f
->output_data
.x
->scroll_bar_background_pixel
= -1;
5184 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
5185 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= -1;
5186 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= -1;
5187 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
5188 f
->output_data
.x
->white_relief
.pixel
= -1;
5189 f
->output_data
.x
->black_relief
.pixel
= -1;
5191 fset_icon_name (f
, Qnil
);
5192 FRAME_DISPLAY_INFO (f
) = dpyinfo
;
5193 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5194 f
->output_data
.x
->explicit_parent
= false;
5196 /* These colors will be set anyway later, but it's important
5197 to get the color reference counts right, so initialize them! */
5201 /* Function x_decode_color can signal an error. Make
5202 sure to initialize color slots so that we won't try
5203 to free colors we haven't allocated. */
5204 FRAME_FOREGROUND_PIXEL (f
) = -1;
5205 FRAME_BACKGROUND_PIXEL (f
) = -1;
5206 f
->output_data
.x
->cursor_pixel
= -1;
5207 f
->output_data
.x
->cursor_foreground_pixel
= -1;
5208 f
->output_data
.x
->border_pixel
= -1;
5209 f
->output_data
.x
->mouse_pixel
= -1;
5211 black
= build_string ("black");
5212 FRAME_FOREGROUND_PIXEL (f
)
5213 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5214 FRAME_BACKGROUND_PIXEL (f
)
5215 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5216 f
->output_data
.x
->cursor_pixel
5217 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5218 f
->output_data
.x
->cursor_foreground_pixel
5219 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5220 f
->output_data
.x
->border_pixel
5221 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5222 f
->output_data
.x
->mouse_pixel
5223 = x_decode_color (f
, black
, BLACK_PIX_DEFAULT (f
));
5226 /* Set the name; the functions to which we pass f expect the name to
5228 if (EQ (name
, Qunbound
) || NILP (name
))
5230 fset_name (f
, build_string (dpyinfo
->x_id_name
));
5231 f
->explicit_name
= false;
5235 fset_name (f
, name
);
5236 f
->explicit_name
= true;
5237 /* use the frame's title when getting resources for this frame. */
5238 specbind (Qx_resource_name
, name
);
5242 register_font_driver (&ftcrfont_driver
, f
);
5244 register_font_driver (&xfont_driver
, f
);
5245 #ifdef HAVE_FREETYPE
5247 register_font_driver (&xftfont_driver
, f
);
5248 #else /* not HAVE_XFT */
5249 register_font_driver (&ftxfont_driver
, f
);
5250 #endif /* not HAVE_XFT */
5251 #endif /* HAVE_FREETYPE */
5252 #endif /* not USE_CAIRO */
5254 image_cache_refcount
=
5255 FRAME_IMAGE_CACHE (f
) ? FRAME_IMAGE_CACHE (f
)->refcount
: 0;
5257 dpyinfo_refcount
= dpyinfo
->reference_count
;
5258 #endif /* GLYPH_DEBUG */
5260 x_default_parameter (f
, parms
, Qfont_backend
, Qnil
,
5261 "fontBackend", "FontBackend", RES_TYPE_STRING
);
5263 /* Extract the window parameters from the supplied values that are
5264 needed to determine window geometry. */
5265 x_default_font_parameter (f
, parms
);
5267 x_default_parameter (f
, parms
, Qborder_width
, make_number (0),
5268 "borderWidth", "BorderWidth", RES_TYPE_NUMBER
);
5270 /* This defaults to 2 in order to match xterm. We recognize either
5271 internalBorderWidth or internalBorder (which is what xterm calls
5273 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5277 value
= x_get_arg (dpyinfo
, parms
, Qinternal_border_width
,
5278 "internalBorder", "internalBorder", RES_TYPE_NUMBER
);
5279 if (! EQ (value
, Qunbound
))
5280 parms
= Fcons (Fcons (Qinternal_border_width
, value
),
5284 x_default_parameter (f
, parms
, Qinternal_border_width
, make_number (1),
5285 "internalBorderWidth", "internalBorderWidth",
5287 x_default_parameter (f
, parms
, Qright_divider_width
, make_number (0),
5288 NULL
, NULL
, RES_TYPE_NUMBER
);
5289 x_default_parameter (f
, parms
, Qbottom_divider_width
, make_number (0),
5290 NULL
, NULL
, RES_TYPE_NUMBER
);
5292 /* Also do the stuff which must be set before the window exists. */
5293 x_default_parameter (f
, parms
, Qforeground_color
, build_string ("black"),
5294 "foreground", "Foreground", RES_TYPE_STRING
);
5295 x_default_parameter (f
, parms
, Qbackground_color
, build_string ("white"),
5296 "background", "Background", RES_TYPE_STRING
);
5297 x_default_parameter (f
, parms
, Qmouse_color
, build_string ("black"),
5298 "pointerColor", "Foreground", RES_TYPE_STRING
);
5299 x_default_parameter (f
, parms
, Qcursor_color
, build_string ("black"),
5300 "cursorColor", "Foreground", RES_TYPE_STRING
);
5301 x_default_parameter (f
, parms
, Qborder_color
, build_string ("black"),
5302 "borderColor", "BorderColor", RES_TYPE_STRING
);
5304 /* Init faces before x_default_parameter is called for the
5305 scroll-bar-width parameter because otherwise we end up in
5306 init_iterator with a null face cache, which should not happen. */
5307 init_frame_faces (f
);
5309 f
->output_data
.x
->parent_desc
= FRAME_DISPLAY_INFO (f
)->root_window
;
5311 x_figure_window_size (f
, parms
, false);
5314 XSetWindowAttributes attrs
;
5316 Atom type
= FRAME_DISPLAY_INFO (f
)->Xatom_net_window_type_tooltip
;
5319 mask
= CWBackPixel
| CWOverrideRedirect
| CWEventMask
;
5320 if (DoesSaveUnders (dpyinfo
->screen
))
5321 mask
|= CWSaveUnder
;
5323 /* Window managers look at the override-redirect flag to determine
5324 whether or net to give windows a decoration (Xlib spec, chapter
5326 attrs
.override_redirect
= True
;
5327 attrs
.save_under
= True
;
5328 attrs
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
5329 /* Arrange for getting MapNotify and UnmapNotify events. */
5330 attrs
.event_mask
= StructureNotifyMask
;
5332 = FRAME_X_WINDOW (f
)
5333 = XCreateWindow (FRAME_X_DISPLAY (f
),
5334 FRAME_DISPLAY_INFO (f
)->root_window
,
5335 /* x, y, width, height */
5339 CopyFromParent
, InputOutput
, CopyFromParent
,
5341 XChangeProperty (FRAME_X_DISPLAY (f
), tip_window
,
5342 FRAME_DISPLAY_INFO (f
)->Xatom_net_window_type
,
5343 XA_ATOM
, 32, PropModeReplace
,
5344 (unsigned char *)&type
, 1);
5350 x_default_parameter (f
, parms
, Qauto_raise
, Qnil
,
5351 "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5352 x_default_parameter (f
, parms
, Qauto_lower
, Qnil
,
5353 "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN
);
5354 x_default_parameter (f
, parms
, Qcursor_type
, Qbox
,
5355 "cursorType", "CursorType", RES_TYPE_SYMBOL
);
5357 /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
5358 Change will not be effected unless different from the current
5360 width
= FRAME_COLS (f
);
5361 height
= FRAME_LINES (f
);
5362 SET_FRAME_COLS (f
, 0);
5363 SET_FRAME_LINES (f
, 0);
5364 change_frame_size (f
, width
, height
, true, false, false, false);
5366 /* Add `tooltip' frame parameter's default value. */
5367 if (NILP (Fframe_parameter (frame
, Qtooltip
)))
5369 AUTO_FRAME_ARG (arg
, Qtooltip
, Qt
);
5370 Fmodify_frame_parameters (frame
, arg
);
5373 /* FIXME - can this be done in a similar way to normal frames?
5374 http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00641.html */
5376 /* Set the `display-type' frame parameter before setting up faces. */
5378 Lisp_Object disptype
;
5380 if (FRAME_DISPLAY_INFO (f
)->n_planes
== 1)
5382 else if (FRAME_DISPLAY_INFO (f
)->visual
->class == GrayScale
5383 || FRAME_DISPLAY_INFO (f
)->visual
->class == StaticGray
)
5384 disptype
= intern ("grayscale");
5386 disptype
= intern ("color");
5388 if (NILP (Fframe_parameter (frame
, Qdisplay_type
)))
5390 AUTO_FRAME_ARG (arg
, Qdisplay_type
, disptype
);
5391 Fmodify_frame_parameters (frame
, arg
);
5395 /* Set up faces after all frame parameters are known. This call
5396 also merges in face attributes specified for new frames.
5398 Frame parameters may be changed if .Xdefaults contains
5399 specifications for the default font. For example, if there is an
5400 `Emacs.default.attributeBackground: pink', the `background-color'
5401 attribute of the frame get's set, which let's the internal border
5402 of the tooltip frame appear in pink. Prevent this. */
5404 Lisp_Object bg
= Fframe_parameter (frame
, Qbackground_color
);
5406 /* Set tip_frame here, so that */
5408 call2 (Qface_set_after_frame_default
, frame
, Qnil
);
5410 if (!EQ (bg
, Fframe_parameter (frame
, Qbackground_color
)))
5412 AUTO_FRAME_ARG (arg
, Qbackground_color
, bg
);
5413 Fmodify_frame_parameters (frame
, arg
);
5419 /* Now that the frame will be official, it counts as a reference to
5420 its display and terminal. */
5421 FRAME_DISPLAY_INFO (f
)->reference_count
++;
5422 f
->terminal
->reference_count
++;
5424 /* It is now ok to make the frame official even if we get an error
5425 below. And the frame needs to be on Vframe_list or making it
5426 visible won't work. */
5427 Vframe_list
= Fcons (frame
, Vframe_list
);
5428 f
->can_x_set_window_size
= true;
5430 /* Setting attributes of faces of the tooltip frame from resources
5431 and similar will set face_change, which leads to the clearing of
5432 all current matrices. Since this isn't necessary here, avoid it
5433 by resetting face_change to the value it had before we created
5435 face_change
= face_change_before
;
5437 /* Discard the unwind_protect. */
5438 return unbind_to (count
, frame
);
5442 /* Compute where to display tip frame F. PARMS is the list of frame
5443 parameters for F. DX and DY are specified offsets from the current
5444 location of the mouse. WIDTH and HEIGHT are the width and height
5445 of the tooltip. Return coordinates relative to the root window of
5446 the display in *ROOT_X, and *ROOT_Y. */
5449 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
)
5451 Lisp_Object left
, top
, right
, bottom
;
5456 /* User-specified position? */
5457 left
= Fcdr (Fassq (Qleft
, parms
));
5458 top
= Fcdr (Fassq (Qtop
, parms
));
5459 right
= Fcdr (Fassq (Qright
, parms
));
5460 bottom
= Fcdr (Fassq (Qbottom
, parms
));
5462 /* Move the tooltip window where the mouse pointer is. Resize and
5464 if ((!INTEGERP (left
) && !INTEGERP (right
))
5465 || (!INTEGERP (top
) && !INTEGERP (bottom
)))
5468 XQueryPointer (FRAME_X_DISPLAY (f
), FRAME_DISPLAY_INFO (f
)->root_window
,
5469 &root
, &child
, root_x
, root_y
, &win_x
, &win_y
, &pmask
);
5474 *root_y
= XINT (top
);
5475 else if (INTEGERP (bottom
))
5476 *root_y
= XINT (bottom
) - height
;
5477 else if (*root_y
+ XINT (dy
) <= 0)
5478 *root_y
= 0; /* Can happen for negative dy */
5479 else if (*root_y
+ XINT (dy
) + height
5480 <= x_display_pixel_height (FRAME_DISPLAY_INFO (f
)))
5481 /* It fits below the pointer */
5482 *root_y
+= XINT (dy
);
5483 else if (height
+ XINT (dy
) <= *root_y
)
5484 /* It fits above the pointer. */
5485 *root_y
-= height
+ XINT (dy
);
5487 /* Put it on the top. */
5490 if (INTEGERP (left
))
5491 *root_x
= XINT (left
);
5492 else if (INTEGERP (right
))
5493 *root_y
= XINT (right
) - width
;
5494 else if (*root_x
+ XINT (dx
) <= 0)
5495 *root_x
= 0; /* Can happen for negative dx */
5496 else if (*root_x
+ XINT (dx
) + width
5497 <= x_display_pixel_width (FRAME_DISPLAY_INFO (f
)))
5498 /* It fits to the right of the pointer. */
5499 *root_x
+= XINT (dx
);
5500 else if (width
+ XINT (dx
) <= *root_x
)
5501 /* It fits to the left of the pointer. */
5502 *root_x
-= width
+ XINT (dx
);
5504 /* Put it left-justified on the screen--it ought to fit that way. */
5509 DEFUN ("x-show-tip", Fx_show_tip
, Sx_show_tip
, 1, 6, 0,
5510 doc
: /* Show STRING in a "tooltip" window on frame FRAME.
5511 A tooltip window is a small X window displaying a string.
5513 This is an internal function; Lisp code should call `tooltip-show'.
5515 FRAME nil or omitted means use the selected frame.
5517 PARMS is an optional list of frame parameters which can be used to
5518 change the tooltip's appearance.
5520 Automatically hide the tooltip after TIMEOUT seconds. TIMEOUT nil
5521 means use the default timeout of 5 seconds.
5523 If the list of frame parameters PARMS contains a `left' parameter,
5524 display the tooltip at that x-position. If the list of frame parameters
5525 PARMS contains no `left' but a `right' parameter, display the tooltip
5526 right-adjusted at that x-position. Otherwise display it at the
5527 x-position of the mouse, with offset DX added (default is 5 if DX isn't
5530 Likewise for the y-position: If a `top' frame parameter is specified, it
5531 determines the position of the upper edge of the tooltip window. If a
5532 `bottom' parameter but no `top' frame parameter is specified, it
5533 determines the position of the lower edge of the tooltip window.
5534 Otherwise display the tooltip window at the y-position of the mouse,
5535 with offset DY added (default is -10).
5537 A tooltip's maximum size is specified by `x-max-tooltip-size'.
5538 Text larger than the specified size is clipped. */)
5539 (Lisp_Object string
, Lisp_Object frame
, Lisp_Object parms
, Lisp_Object timeout
, Lisp_Object dx
, Lisp_Object dy
)
5544 struct buffer
*old_buffer
;
5545 struct text_pos pos
;
5546 int i
, width
, height
;
5547 bool seen_reversed_p
;
5548 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
5549 ptrdiff_t count
= SPECPDL_INDEX ();
5551 specbind (Qinhibit_redisplay
, Qt
);
5553 CHECK_STRING (string
);
5554 if (SCHARS (string
) == 0)
5555 string
= make_unibyte_string (" ", 1);
5557 f
= decode_window_system_frame (frame
);
5559 timeout
= make_number (5);
5561 CHECK_NATNUM (timeout
);
5564 dx
= make_number (5);
5569 dy
= make_number (-10);
5574 if (x_gtk_use_system_tooltips
)
5578 /* Hide a previous tip, if any. */
5582 ok
= xg_prepare_tooltip (f
, string
, &width
, &height
);
5585 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5586 xg_show_tooltip (f
, root_x
, root_y
);
5587 /* This is used in Fx_hide_tip. */
5588 XSETFRAME (tip_frame
, f
);
5591 if (ok
) goto start_timer
;
5593 #endif /* USE_GTK */
5595 if (NILP (last_show_tip_args
))
5596 last_show_tip_args
= Fmake_vector (make_number (3), Qnil
);
5598 if (!NILP (tip_frame
))
5600 Lisp_Object last_string
= AREF (last_show_tip_args
, 0);
5601 Lisp_Object last_frame
= AREF (last_show_tip_args
, 1);
5602 Lisp_Object last_parms
= AREF (last_show_tip_args
, 2);
5604 if (EQ (frame
, last_frame
)
5605 && !NILP (Fequal (last_string
, string
))
5606 && !NILP (Fequal (last_parms
, parms
)))
5608 struct frame
*tip_f
= XFRAME (tip_frame
);
5610 /* Only DX and DY have changed. */
5611 if (!NILP (tip_timer
))
5613 Lisp_Object timer
= tip_timer
;
5615 call1 (Qcancel_timer
, timer
);
5619 compute_tip_xy (tip_f
, parms
, dx
, dy
, FRAME_PIXEL_WIDTH (tip_f
),
5620 FRAME_PIXEL_HEIGHT (tip_f
), &root_x
, &root_y
);
5621 XMoveWindow (FRAME_X_DISPLAY (tip_f
), FRAME_X_WINDOW (tip_f
),
5628 /* Hide a previous tip, if any. */
5631 ASET (last_show_tip_args
, 0, string
);
5632 ASET (last_show_tip_args
, 1, frame
);
5633 ASET (last_show_tip_args
, 2, parms
);
5635 /* Add default values to frame parameters. */
5636 if (NILP (Fassq (Qname
, parms
)))
5637 parms
= Fcons (Fcons (Qname
, build_string ("tooltip")), parms
);
5638 if (NILP (Fassq (Qinternal_border_width
, parms
)))
5639 parms
= Fcons (Fcons (Qinternal_border_width
, make_number (3)), parms
);
5640 if (NILP (Fassq (Qborder_width
, parms
)))
5641 parms
= Fcons (Fcons (Qborder_width
, make_number (1)), parms
);
5642 if (NILP (Fassq (Qbottom_divider_width
, parms
)))
5643 parms
= Fcons (Fcons (Qbottom_divider_width
, make_number (0)), parms
);
5644 if (NILP (Fassq (Qright_divider_width
, parms
)))
5645 parms
= Fcons (Fcons (Qright_divider_width
, make_number (0)), parms
);
5646 if (NILP (Fassq (Qborder_color
, parms
)))
5647 parms
= Fcons (Fcons (Qborder_color
, build_string ("lightyellow")), parms
);
5648 if (NILP (Fassq (Qbackground_color
, parms
)))
5649 parms
= Fcons (Fcons (Qbackground_color
, build_string ("lightyellow")),
5652 /* Create a frame for the tooltip, and record it in the global
5653 variable tip_frame. */
5654 frame
= x_create_tip_frame (FRAME_DISPLAY_INFO (f
), parms
, string
);
5657 /* Set up the frame's root window. */
5658 w
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5664 if (CONSP (Vx_max_tooltip_size
)
5665 && RANGED_INTEGERP (1, XCAR (Vx_max_tooltip_size
), INT_MAX
)
5666 && RANGED_INTEGERP (1, XCDR (Vx_max_tooltip_size
), INT_MAX
))
5668 w
->total_cols
= XFASTINT (XCAR (Vx_max_tooltip_size
));
5669 w
->total_lines
= XFASTINT (XCDR (Vx_max_tooltip_size
));
5674 w
->total_lines
= 40;
5677 w
->pixel_width
= w
->total_cols
* FRAME_COLUMN_WIDTH (f
);
5678 w
->pixel_height
= w
->total_lines
* FRAME_LINE_HEIGHT (f
);
5680 FRAME_TOTAL_COLS (f
) = w
->total_cols
;
5681 adjust_frame_glyphs (f
);
5682 w
->pseudo_window_p
= true;
5684 /* Display the tooltip text in a temporary buffer. */
5685 old_buffer
= current_buffer
;
5686 set_buffer_internal_1 (XBUFFER (XWINDOW (FRAME_ROOT_WINDOW (f
))->contents
));
5687 bset_truncate_lines (current_buffer
, Qnil
);
5688 clear_glyph_matrix (w
->desired_matrix
);
5689 clear_glyph_matrix (w
->current_matrix
);
5690 SET_TEXT_POS (pos
, BEGV
, BEGV_BYTE
);
5691 try_window (FRAME_ROOT_WINDOW (f
), pos
, TRY_WINDOW_IGNORE_FONTS_CHANGE
);
5693 /* Compute width and height of the tooltip. */
5695 seen_reversed_p
= false;
5696 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5698 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5702 /* Stop at the first empty row at the end. */
5703 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5706 /* Let the row go over the full width of the frame. */
5707 row
->full_width_p
= true;
5709 row_width
= row
->pixel_width
;
5710 if (row
->used
[TEXT_AREA
])
5712 /* There's a glyph at the end of rows that is used to place
5713 the cursor there. Don't include the width of this glyph. */
5714 if (!row
->reversed_p
)
5716 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5717 if (NILP (last
->object
))
5718 row_width
-= last
->pixel_width
;
5722 /* There could be a stretch glyph at the beginning of R2L
5723 rows that is produced by extend_face_to_end_of_line.
5724 Don't count that glyph. */
5725 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
5727 if (g
->type
== STRETCH_GLYPH
&& NILP (g
->object
))
5729 row_width
-= g
->pixel_width
;
5730 seen_reversed_p
= true;
5735 height
+= row
->height
;
5736 width
= max (width
, row_width
);
5739 /* If we've seen partial-length R2L rows, we need to re-adjust the
5740 tool-tip frame width and redisplay it again, to avoid over-wide
5741 tips due to the stretch glyph that extends R2L lines to full
5742 width of the frame. */
5743 if (seen_reversed_p
)
5745 /* w->total_cols and FRAME_TOTAL_COLS want the width in columns,
5747 w
->pixel_width
= width
;
5748 width
/= WINDOW_FRAME_COLUMN_WIDTH (w
);
5749 w
->total_cols
= width
;
5750 FRAME_TOTAL_COLS (f
) = width
;
5751 SET_FRAME_WIDTH (f
, width
);
5752 adjust_frame_glyphs (f
);
5753 clear_glyph_matrix (w
->desired_matrix
);
5754 clear_glyph_matrix (w
->current_matrix
);
5755 try_window (FRAME_ROOT_WINDOW (f
), pos
, 0);
5757 /* Recompute width and height of the tooltip. */
5758 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
5760 struct glyph_row
*row
= &w
->desired_matrix
->rows
[i
];
5764 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
5766 row
->full_width_p
= true;
5767 row_width
= row
->pixel_width
;
5768 if (row
->used
[TEXT_AREA
] && !row
->reversed_p
)
5770 last
= &row
->glyphs
[TEXT_AREA
][row
->used
[TEXT_AREA
] - 1];
5771 if (NILP (last
->object
))
5772 row_width
-= last
->pixel_width
;
5775 height
+= row
->height
;
5776 width
= max (width
, row_width
);
5780 /* Add the frame's internal border to the width and height the X
5781 window should have. */
5782 height
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5783 width
+= 2 * FRAME_INTERNAL_BORDER_WIDTH (f
);
5785 /* Move the tooltip window where the mouse pointer is. Resize and
5787 compute_tip_xy (f
, parms
, dx
, dy
, width
, height
, &root_x
, &root_y
);
5790 XMoveResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5791 root_x
, root_y
, width
, height
);
5792 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
5795 /* Draw into the window. */
5796 w
->must_be_updated_p
= true;
5797 update_single_window (w
);
5799 /* Restore original current buffer. */
5800 set_buffer_internal_1 (old_buffer
);
5801 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
5804 /* Let the tip disappear after timeout seconds. */
5805 tip_timer
= call3 (intern ("run-at-time"), timeout
, Qnil
,
5806 intern ("x-hide-tip"));
5808 return unbind_to (count
, Qnil
);
5812 DEFUN ("x-hide-tip", Fx_hide_tip
, Sx_hide_tip
, 0, 0, 0,
5813 doc
: /* Hide the current tooltip window, if there is any.
5814 Value is t if tooltip was open, nil otherwise. */)
5818 Lisp_Object deleted
, frame
, timer
;
5820 /* Return quickly if nothing to do. */
5821 if (NILP (tip_timer
) && NILP (tip_frame
))
5826 tip_frame
= tip_timer
= deleted
= Qnil
;
5828 count
= SPECPDL_INDEX ();
5829 specbind (Qinhibit_redisplay
, Qt
);
5830 specbind (Qinhibit_quit
, Qt
);
5833 call1 (Qcancel_timer
, timer
);
5837 /* When using system tooltip, tip_frame is the Emacs frame on which
5838 the tip is shown. */
5839 struct frame
*f
= XFRAME (frame
);
5840 if (FRAME_LIVE_P (f
) && xg_hide_tooltip (f
))
5847 delete_frame (frame
, Qnil
);
5851 /* Bloodcurdling hack alert: The Lucid menu bar widget's
5852 redisplay procedure is not called when a tip frame over menu
5853 items is unmapped. Redisplay the menu manually... */
5856 struct frame
*f
= SELECTED_FRAME ();
5857 w
= f
->output_data
.x
->menubar_widget
;
5859 if (!DoesSaveUnders (FRAME_DISPLAY_INFO (f
)->screen
)
5863 xlwmenu_redisplay (w
);
5867 #endif /* USE_LUCID */
5870 return unbind_to (count
, deleted
);
5875 /***********************************************************************
5876 File selection dialog
5877 ***********************************************************************/
5879 DEFUN ("x-uses-old-gtk-dialog", Fx_uses_old_gtk_dialog
,
5880 Sx_uses_old_gtk_dialog
,
5882 doc
: /* Return t if the old Gtk+ file selection dialog is used. */)
5888 && window_system_available (SELECTED_FRAME ())
5889 && xg_uses_old_file_dialog ())
5897 /* Callback for "OK" and "Cancel" on file selection dialog. */
5900 file_dialog_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5902 int *result
= client_data
;
5903 XmAnyCallbackStruct
*cb
= call_data
;
5904 *result
= cb
->reason
;
5908 /* Callback for unmapping a file selection dialog. This is used to
5909 capture the case where a dialog is closed via a window manager's
5910 closer button, for example. Using a XmNdestroyCallback didn't work
5914 file_dialog_unmap_cb (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5916 int *result
= client_data
;
5917 *result
= XmCR_CANCEL
;
5921 clean_up_file_dialog (void *arg
)
5923 Widget dialog
= arg
;
5927 XtUnmanageChild (dialog
);
5928 XtDestroyWidget (dialog
);
5929 x_menu_set_in_use (false);
5934 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
5935 doc
: /* Read file name, prompting with PROMPT in directory DIR.
5936 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
5937 selection box, if specified. If MUSTMATCH is non-nil, the returned file
5938 or directory must exist.
5940 This function is only defined on NS, MS Windows, and X Windows with the
5941 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
5942 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.
5943 On Windows 7 and later, the file selection dialog "remembers" the last
5944 directory where the user selected a file, and will open that directory
5945 instead of DIR on subsequent invocations of this function with the same
5946 value of DIR as in previous invocations; this is standard Windows behavior. */)
5947 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
,
5948 Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
5951 struct frame
*f
= SELECTED_FRAME ();
5952 Lisp_Object file
= Qnil
;
5953 Lisp_Object decoded_file
;
5954 Widget dialog
, text
, help
;
5957 XmString dir_xmstring
, pattern_xmstring
;
5958 ptrdiff_t count
= SPECPDL_INDEX ();
5960 check_window_system (f
);
5962 if (popup_activated ())
5963 error ("Trying to use a menu from within a menu-entry");
5965 CHECK_STRING (prompt
);
5968 /* Prevent redisplay. */
5969 specbind (Qinhibit_redisplay
, Qt
);
5973 /* Create the dialog with PROMPT as title, using DIR as initial
5974 directory and using "*" as pattern. */
5975 dir
= Fexpand_file_name (dir
, Qnil
);
5976 dir_xmstring
= XmStringCreateLocalized (SSDATA (dir
));
5977 pattern_xmstring
= XmStringCreateLocalized ("*");
5979 XtSetArg (al
[ac
], XmNtitle
, SDATA (prompt
)); ++ac
;
5980 XtSetArg (al
[ac
], XmNdirectory
, dir_xmstring
); ++ac
;
5981 XtSetArg (al
[ac
], XmNpattern
, pattern_xmstring
); ++ac
;
5982 XtSetArg (al
[ac
], XmNresizePolicy
, XmRESIZE_GROW
); ++ac
;
5983 XtSetArg (al
[ac
], XmNdialogStyle
, XmDIALOG_APPLICATION_MODAL
); ++ac
;
5984 dialog
= XmCreateFileSelectionDialog (f
->output_data
.x
->widget
,
5986 XmStringFree (dir_xmstring
);
5987 XmStringFree (pattern_xmstring
);
5989 /* Add callbacks for OK and Cancel. */
5990 XtAddCallback (dialog
, XmNokCallback
, file_dialog_cb
,
5991 (XtPointer
) &result
);
5992 XtAddCallback (dialog
, XmNcancelCallback
, file_dialog_cb
,
5993 (XtPointer
) &result
);
5994 XtAddCallback (dialog
, XmNunmapCallback
, file_dialog_unmap_cb
,
5995 (XtPointer
) &result
);
5997 /* Remove the help button since we can't display help. */
5998 help
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_HELP_BUTTON
);
5999 XtUnmanageChild (help
);
6001 /* Mark OK button as default. */
6002 XtVaSetValues (XmFileSelectionBoxGetChild (dialog
, XmDIALOG_OK_BUTTON
),
6003 XmNshowAsDefault
, True
, NULL
);
6005 /* If MUSTMATCH is non-nil, disable the file entry field of the
6006 dialog, so that the user must select a file from the files list
6007 box. We can't remove it because we wouldn't have a way to get at
6008 the result file name, then. */
6009 text
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
6010 if (!NILP (mustmatch
))
6013 label
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_SELECTION_LABEL
);
6014 XtSetSensitive (text
, False
);
6015 XtSetSensitive (label
, False
);
6018 /* Manage the dialog, so that list boxes get filled. */
6019 XtManageChild (dialog
);
6021 if (STRINGP (default_filename
))
6023 XmString default_xmstring
;
6024 Widget wtext
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_TEXT
);
6025 Widget list
= XmFileSelectionBoxGetChild (dialog
, XmDIALOG_LIST
);
6027 XmTextPosition last_pos
= XmTextFieldGetLastPosition (wtext
);
6028 XmTextFieldReplace (wtext
, 0, last_pos
,
6029 (SSDATA (Ffile_name_nondirectory (default_filename
))));
6031 /* Select DEFAULT_FILENAME in the files list box. DEFAULT_FILENAME
6032 must include the path for this to work. */
6034 default_xmstring
= XmStringCreateLocalized (SSDATA (default_filename
));
6036 if (XmListItemExists (list
, default_xmstring
))
6038 int item_pos
= XmListItemPos (list
, default_xmstring
);
6039 /* Select the item and scroll it into view. */
6040 XmListSelectPos (list
, item_pos
, True
);
6041 XmListSetPos (list
, item_pos
);
6044 XmStringFree (default_xmstring
);
6047 record_unwind_protect_ptr (clean_up_file_dialog
, dialog
);
6049 /* Process events until the user presses Cancel or OK. */
6050 x_menu_set_in_use (true);
6055 x_menu_wait_for_event (0);
6056 XtAppNextEvent (Xt_app_con
, &event
);
6057 if (event
.type
== KeyPress
6058 && FRAME_X_DISPLAY (f
) == event
.xkey
.display
)
6060 KeySym keysym
= XLookupKeysym (&event
.xkey
, 0);
6062 /* Pop down on C-g. */
6063 if (keysym
== XK_g
&& (event
.xkey
.state
& ControlMask
) != 0)
6064 XtUnmanageChild (dialog
);
6067 (void) x_dispatch_event (&event
, FRAME_X_DISPLAY (f
));
6070 /* Get the result. */
6071 if (result
== XmCR_OK
)
6073 XmString text_string
;
6076 XtVaGetValues (dialog
, XmNtextString
, &text_string
, NULL
);
6077 XmStringGetLtoR (text_string
, XmFONTLIST_DEFAULT_TAG
, &data
);
6078 XmStringFree (text_string
);
6079 file
= build_string (data
);
6087 /* Make "Cancel" equivalent to C-g. */
6089 Fsignal (Qquit
, Qnil
);
6091 decoded_file
= DECODE_FILE (file
);
6093 return unbind_to (count
, decoded_file
);
6096 #endif /* USE_MOTIF */
6101 clean_up_dialog (void)
6103 x_menu_set_in_use (false);
6106 DEFUN ("x-file-dialog", Fx_file_dialog
, Sx_file_dialog
, 2, 5, 0,
6107 doc
: /* Read file name, prompting with PROMPT in directory DIR.
6108 Use a file selection dialog. Select DEFAULT-FILENAME in the dialog's file
6109 selection box, if specified. If MUSTMATCH is non-nil, the returned file
6110 or directory must exist.
6112 This function is only defined on NS, MS Windows, and X Windows with the
6113 Motif or Gtk toolkits. With the Motif toolkit, ONLY-DIR-P is ignored.
6114 Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories.
6115 On Windows 7 and later, the file selection dialog "remembers" the last
6116 directory where the user selected a file, and will open that directory
6117 instead of DIR on subsequent invocations of this function with the same
6118 value of DIR as in previous invocations; this is standard Windows behavior. */)
6119 (Lisp_Object prompt
, Lisp_Object dir
, Lisp_Object default_filename
, Lisp_Object mustmatch
, Lisp_Object only_dir_p
)
6121 struct frame
*f
= SELECTED_FRAME ();
6123 Lisp_Object file
= Qnil
;
6124 Lisp_Object decoded_file
;
6125 ptrdiff_t count
= SPECPDL_INDEX ();
6128 check_window_system (f
);
6130 if (popup_activated ())
6131 error ("Trying to use a menu from within a menu-entry");
6133 CHECK_STRING (prompt
);
6136 /* Prevent redisplay. */
6137 specbind (Qinhibit_redisplay
, Qt
);
6138 record_unwind_protect_void (clean_up_dialog
);
6142 if (STRINGP (default_filename
))
6143 cdef_file
= SSDATA (default_filename
);
6145 cdef_file
= SSDATA (dir
);
6147 fn
= xg_get_file_name (f
, SSDATA (prompt
), cdef_file
,
6149 ! NILP (only_dir_p
));
6153 file
= build_string (fn
);
6159 /* Make "Cancel" equivalent to C-g. */
6161 Fsignal (Qquit
, Qnil
);
6163 decoded_file
= DECODE_FILE (file
);
6165 return unbind_to (count
, decoded_file
);
6169 #ifdef HAVE_FREETYPE
6171 DEFUN ("x-select-font", Fx_select_font
, Sx_select_font
, 0, 2, 0,
6172 doc
: /* Read a font using a GTK dialog.
6173 Return either a font spec (for GTK versions >= 3.2) or a string
6174 containing a GTK-style font name.
6176 FRAME is the frame on which to pop up the font chooser. If omitted or
6177 nil, it defaults to the selected frame. */)
6178 (Lisp_Object frame
, Lisp_Object ignored
)
6180 struct frame
*f
= decode_window_system_frame (frame
);
6182 Lisp_Object font_param
;
6183 char *default_name
= NULL
;
6184 ptrdiff_t count
= SPECPDL_INDEX ();
6186 if (popup_activated ())
6187 error ("Trying to use a menu from within a menu-entry");
6189 /* Prevent redisplay. */
6190 specbind (Qinhibit_redisplay
, Qt
);
6191 record_unwind_protect_void (clean_up_dialog
);
6195 XSETFONT (font
, FRAME_FONT (f
));
6196 font_param
= Ffont_get (font
, QCname
);
6197 if (STRINGP (font_param
))
6198 default_name
= xlispstrdup (font_param
);
6201 font_param
= Fframe_parameter (frame
, Qfont_param
);
6202 if (STRINGP (font_param
))
6203 default_name
= xlispstrdup (font_param
);
6206 font
= xg_get_font (f
, default_name
);
6207 xfree (default_name
);
6212 Fsignal (Qquit
, Qnil
);
6214 return unbind_to (count
, font
);
6216 #endif /* HAVE_FREETYPE */
6218 #endif /* USE_GTK */
6221 /***********************************************************************
6223 ***********************************************************************/
6226 #include <X11/XKBlib.h>
6227 #include <X11/keysym.h>
6230 DEFUN ("x-backspace-delete-keys-p", Fx_backspace_delete_keys_p
,
6231 Sx_backspace_delete_keys_p
, 0, 1, 0,
6232 doc
: /* Check if both Backspace and Delete keys are on the keyboard of FRAME.
6233 FRAME nil means use the selected frame.
6234 Value is t if we know that both keys are present, and are mapped to the
6235 usual X keysyms. Value is `lambda' if we cannot determine if both keys are
6236 present and mapped to the usual X keysyms. */)
6243 struct frame
*f
= decode_window_system_frame (frame
);
6244 Display
*dpy
= FRAME_X_DISPLAY (f
);
6245 Lisp_Object have_keys
;
6246 int major
, minor
, op
, event
, error_code
;
6250 /* Check library version in case we're dynamically linked. */
6251 major
= XkbMajorVersion
;
6252 minor
= XkbMinorVersion
;
6253 if (!XkbLibraryVersion (&major
, &minor
))
6259 /* Check that the server supports XKB. */
6260 major
= XkbMajorVersion
;
6261 minor
= XkbMinorVersion
;
6262 if (!XkbQueryExtension (dpy
, &op
, &event
, &error_code
, &major
, &minor
))
6268 /* In this code we check that the keyboard has physical keys with names
6269 that start with BKSP (Backspace) and DELE (Delete), and that they
6270 generate keysym XK_BackSpace and XK_Delete respectively.
6271 This function is used to test if normal-erase-is-backspace should be
6273 An alternative approach would be to just check if XK_BackSpace and
6274 XK_Delete are mapped to any key. But if any of those are mapped to
6275 some non-intuitive key combination (Meta-Shift-Ctrl-whatever) and the
6276 user doesn't know about it, it is better to return false here.
6277 It is more obvious to the user what to do if she/he has two keys
6278 clearly marked with names/symbols and one key does something not
6279 expected (i.e. she/he then tries the other).
6280 The cases where Backspace/Delete is mapped to some other key combination
6281 are rare, and in those cases, normal-erase-is-backspace can be turned on
6285 kb
= XkbGetMap (dpy
, XkbAllMapComponentsMask
, XkbUseCoreKbd
);
6288 int delete_keycode
= 0, backspace_keycode
= 0, i
;
6290 if (XkbGetNames (dpy
, XkbAllNamesMask
, kb
) == Success
)
6292 for (i
= kb
->min_key_code
;
6293 (i
< kb
->max_key_code
6294 && (delete_keycode
== 0 || backspace_keycode
== 0));
6297 /* The XKB symbolic key names can be seen most easily in
6298 the PS file generated by `xkbprint -label name
6300 if (memcmp ("DELE", kb
->names
->keys
[i
].name
, 4) == 0)
6302 else if (memcmp ("BKSP", kb
->names
->keys
[i
].name
, 4) == 0)
6303 backspace_keycode
= i
;
6306 XkbFreeNames (kb
, 0, True
);
6309 /* As of libX11-1.6.2, XkbGetMap manual says that you should use
6310 XkbFreeClientMap to free the data returned by XkbGetMap. But
6311 this function just frees the data referenced from KB and not
6312 KB itself. To free KB as well, call XkbFreeKeyboard. */
6313 XkbFreeKeyboard (kb
, XkbAllMapComponentsMask
, True
);
6316 && backspace_keycode
6317 && XKeysymToKeycode (dpy
, XK_Delete
) == delete_keycode
6318 && XKeysymToKeycode (dpy
, XK_BackSpace
) == backspace_keycode
)
6328 /***********************************************************************
6330 ***********************************************************************/
6333 DEFUN ("x-export-frames", Fx_export_frames
, Sx_export_frames
, 0, 2, 0,
6334 doc
: /* XXX Experimental. Return image data of FRAMES in TYPE format.
6335 FRAMES should be nil (the selected frame), a frame, or a list of
6336 frames (each of which corresponds to one page). Optional arg TYPE
6337 should be either `pdf' (default), `png', `ps', or `svg'. Supported
6338 types are determined by the compile-time configuration of cairo. */)
6339 (Lisp_Object frames
, Lisp_Object type
)
6341 Lisp_Object result
, rest
, tmp
;
6342 cairo_surface_type_t surface_type
;
6345 frames
= selected_frame
;
6346 if (!CONSP (frames
))
6347 frames
= list1 (frames
);
6350 for (rest
= frames
; CONSP (rest
); rest
= XCDR (rest
))
6352 struct frame
*f
= XFRAME (XCAR (rest
));
6354 if (! FRAME_LIVE_P (f
) || ! FRAME_X_P (f
) || ! FRAME_LIVE_P (f
))
6355 error ("Invalid frame");
6359 XSETFRAME (frame
, f
);
6360 tmp
= Fcons (frame
, tmp
);
6362 frames
= Fnreverse (tmp
);
6364 #ifdef CAIRO_HAS_PDF_SURFACE
6365 if (NILP (type
) || EQ (type
, intern ("pdf"))) /* XXX: Qpdf */
6366 surface_type
= CAIRO_SURFACE_TYPE_PDF
;
6369 #ifdef CAIRO_HAS_PNG_FUNCTIONS
6370 if (EQ (type
, intern ("png")))
6372 if (!NILP (XCDR (frames
)))
6373 error ("PNG export cannot handle multiple frames.");
6374 surface_type
= CAIRO_SURFACE_TYPE_IMAGE
;
6378 #ifdef CAIRO_HAS_PS_SURFACE
6379 if (EQ (type
, intern ("ps")))
6380 surface_type
= CAIRO_SURFACE_TYPE_PS
;
6383 #ifdef CAIRO_HAS_SVG_SURFACE
6384 if (EQ (type
, intern ("svg")))
6386 /* For now, we stick to SVG 1.1. */
6387 if (!NILP (XCDR (frames
)))
6388 error ("SVG export cannot handle multiple frames.");
6389 surface_type
= CAIRO_SURFACE_TYPE_SVG
;
6393 error ("Unsupported export type");
6395 result
= x_cr_export_frames (frames
, surface_type
);
6401 DEFUN ("x-page-setup-dialog", Fx_page_setup_dialog
, Sx_page_setup_dialog
, 0, 0, 0,
6402 doc
: /* Pop up a page setup dialog.
6403 The current page setup can be obtained using `x-get-page-setup'. */)
6407 xg_page_setup_dialog ();
6413 DEFUN ("x-get-page-setup", Fx_get_page_setup
, Sx_get_page_setup
, 0, 0, 0,
6414 doc
: /* Return the value of the current page setup.
6415 The return value is an alist containing the following keys:
6417 orientation: page orientation (symbol `portrait', `landscape',
6418 `reverse-portrait', or `reverse-landscape').
6419 width, height: page width/height in points not including margins.
6420 left-margin, right-margin, top-margin, bottom-margin: print margins,
6421 which is the parts of the page that the printer cannot print
6424 The paper width can be obtained as the sum of width, left-margin, and
6425 right-margin values. Likewise, the paper height is the sum of height,
6426 top-margin, and bottom-margin values. */)
6432 result
= xg_get_page_setup ();
6438 DEFUN ("x-print-frames-dialog", Fx_print_frames_dialog
, Sx_print_frames_dialog
, 0, 1, "",
6439 doc
: /* Pop up a print dialog to print the current contents of FRAMES.
6440 FRAMES should be nil (the selected frame), a frame, or a list of
6441 frames (each of which corresponds to one page). Each frame should be
6443 (Lisp_Object frames
)
6445 Lisp_Object rest
, tmp
;
6448 frames
= selected_frame
;
6449 if (!CONSP (frames
))
6450 frames
= list1 (frames
);
6453 for (rest
= frames
; CONSP (rest
); rest
= XCDR (rest
))
6455 struct frame
*f
= XFRAME (XCAR (rest
));
6456 if (! FRAME_LIVE_P (f
) || ! FRAME_X_P (f
) || ! FRAME_LIVE_P (f
))
6457 error ("Invalid frame");
6460 XSETFRAME (frame
, f
);
6461 if (!EQ (Fframe_visible_p (frame
), Qt
))
6462 error ("Frames to be printed must be visible.");
6463 tmp
= Fcons (frame
, tmp
);
6465 frames
= Fnreverse (tmp
);
6467 /* Make sure the current matrices are up-to-date. */
6471 xg_print_frames_dialog (frames
);
6476 #endif /* USE_GTK */
6477 #endif /* USE_CAIRO */
6480 /***********************************************************************
6482 ***********************************************************************/
6484 /* Keep this list in the same order as frame_parms in frame.c.
6485 Use 0 for unsupported frame parameters. */
6487 frame_parm_handler x_frame_parm_handlers
[] =
6491 x_set_background_color
,
6497 x_set_foreground_color
,
6500 x_set_internal_border_width
,
6501 x_set_right_divider_width
,
6502 x_set_bottom_divider_width
,
6503 x_set_menu_bar_lines
,
6505 x_explicitly_set_name
,
6506 x_set_scroll_bar_width
,
6507 x_set_scroll_bar_height
,
6510 x_set_vertical_scroll_bars
,
6511 x_set_horizontal_scroll_bars
,
6513 x_set_tool_bar_lines
,
6514 x_set_scroll_bar_foreground
,
6515 x_set_scroll_bar_background
,
6525 x_set_tool_bar_position
,
6531 DEFSYM (Qundefined_color
, "undefined-color");
6532 DEFSYM (Qcompound_text
, "compound-text");
6533 DEFSYM (Qcancel_timer
, "cancel-timer");
6534 DEFSYM (Qfont_param
, "font-parameter");
6535 DEFSYM (Qmono
, "mono");
6538 DEFSYM (Qorientation
, "orientation");
6539 DEFSYM (Qtop_margin
, "top-margin");
6540 DEFSYM (Qbottom_margin
, "bottom-margin");
6541 DEFSYM (Qportrait
, "portrait");
6542 DEFSYM (Qlandscape
, "landscape");
6543 DEFSYM (Qreverse_portrait
, "reverse-portrait");
6544 DEFSYM (Qreverse_landscape
, "reverse-landscape");
6547 Fput (Qundefined_color
, Qerror_conditions
,
6548 listn (CONSTYPE_PURE
, 2, Qundefined_color
, Qerror
));
6549 Fput (Qundefined_color
, Qerror_message
,
6550 build_pure_c_string ("Undefined color"));
6552 DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape
,
6553 doc
: /* The shape of the pointer when over text.
6554 Changing the value does not affect existing frames
6555 unless you set the mouse color. */);
6556 Vx_pointer_shape
= Qnil
;
6558 #if false /* This doesn't really do anything. */
6559 DEFVAR_LISP ("x-nontext-pointer-shape", Vx_nontext_pointer_shape
,
6560 doc
: /* The shape of the pointer when not over text.
6561 This variable takes effect when you create a new frame
6562 or when you set the mouse color. */);
6564 Vx_nontext_pointer_shape
= Qnil
;
6566 DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape
,
6567 doc
: /* The shape of the pointer when Emacs is busy.
6568 This variable takes effect when you create a new frame
6569 or when you set the mouse color. */);
6570 Vx_hourglass_pointer_shape
= Qnil
;
6572 #if false /* This doesn't really do anything. */
6573 DEFVAR_LISP ("x-mode-pointer-shape", Vx_mode_pointer_shape
,
6574 doc
: /* The shape of the pointer when over the mode line.
6575 This variable takes effect when you create a new frame
6576 or when you set the mouse color. */);
6578 Vx_mode_pointer_shape
= Qnil
;
6580 DEFVAR_LISP ("x-sensitive-text-pointer-shape",
6581 Vx_sensitive_text_pointer_shape
,
6582 doc
: /* The shape of the pointer when over mouse-sensitive text.
6583 This variable takes effect when you create a new frame
6584 or when you set the mouse color. */);
6585 Vx_sensitive_text_pointer_shape
= Qnil
;
6587 DEFVAR_LISP ("x-window-horizontal-drag-cursor",
6588 Vx_window_horizontal_drag_shape
,
6589 doc
: /* Pointer shape to use for indicating a window can be dragged horizontally.
6590 This variable takes effect when you create a new frame
6591 or when you set the mouse color. */);
6592 Vx_window_horizontal_drag_shape
= Qnil
;
6594 DEFVAR_LISP ("x-window-vertical-drag-cursor",
6595 Vx_window_vertical_drag_shape
,
6596 doc
: /* Pointer shape to use for indicating a window can be dragged vertically.
6597 This variable takes effect when you create a new frame
6598 or when you set the mouse color. */);
6599 Vx_window_vertical_drag_shape
= Qnil
;
6601 DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel
,
6602 doc
: /* A string indicating the foreground color of the cursor box. */);
6603 Vx_cursor_fore_pixel
= Qnil
;
6605 DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size
,
6606 doc
: /* Maximum size for tooltips.
6607 Value is a pair (COLUMNS . ROWS). Text larger than this is clipped. */);
6608 Vx_max_tooltip_size
= Fcons (make_number (80), make_number (40));
6610 DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager
,
6611 doc
: /* Non-nil if no X window manager is in use.
6612 Emacs doesn't try to figure this out; this is always nil
6613 unless you set it to something else. */);
6614 /* We don't have any way to find this out, so set it to nil
6615 and maybe the user would like to set it to t. */
6616 Vx_no_window_manager
= Qnil
;
6618 DEFVAR_LISP ("x-pixel-size-width-font-regexp",
6619 Vx_pixel_size_width_font_regexp
,
6620 doc
: /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'.
6622 Since Emacs gets width of a font matching with this regexp from
6623 PIXEL_SIZE field of the name, font finding mechanism gets faster for
6624 such a font. This is especially effective for such large fonts as
6625 Chinese, Japanese, and Korean. */);
6626 Vx_pixel_size_width_font_regexp
= Qnil
;
6628 /* This is not ifdef:ed, so other builds than GTK can customize it. */
6629 DEFVAR_BOOL ("x-gtk-use-old-file-dialog", x_gtk_use_old_file_dialog
,
6630 doc
: /* Non-nil means prompt with the old GTK file selection dialog.
6631 If nil or if the file selection dialog is not available, the new GTK file
6632 chooser is used instead. To turn off all file dialogs set the
6633 variable `use-file-dialog'. */);
6634 x_gtk_use_old_file_dialog
= false;
6636 DEFVAR_BOOL ("x-gtk-show-hidden-files", x_gtk_show_hidden_files
,
6637 doc
: /* If non-nil, the GTK file chooser will by default show hidden files.
6638 Note that this is just the default, there is a toggle button on the file
6639 chooser to show or not show hidden files on a case by case basis. */);
6640 x_gtk_show_hidden_files
= false;
6642 DEFVAR_BOOL ("x-gtk-file-dialog-help-text", x_gtk_file_dialog_help_text
,
6643 doc
: /* If non-nil, the GTK file chooser will show additional help text.
6644 If more space for files in the file chooser dialog is wanted, set this to nil
6645 to turn the additional text off. */);
6646 x_gtk_file_dialog_help_text
= true;
6648 DEFVAR_BOOL ("x-gtk-use-system-tooltips", x_gtk_use_system_tooltips
,
6649 doc
: /* If non-nil with a Gtk+ built Emacs, the Gtk+ tooltip is used.
6650 Otherwise use Emacs own tooltip implementation.
6651 When using Gtk+ tooltips, the tooltip face is not used. */);
6652 x_gtk_use_system_tooltips
= true;
6654 /* Tell Emacs about this window system. */
6655 Fprovide (Qx
, Qnil
);
6657 #ifdef USE_X_TOOLKIT
6658 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
6660 Fprovide (intern_c_string ("motif"), Qnil
);
6662 DEFVAR_LISP ("motif-version-string", Vmotif_version_string
,
6663 doc
: /* Version info for LessTif/Motif. */);
6664 Vmotif_version_string
= build_string (XmVERSION_STRING
);
6665 #endif /* USE_MOTIF */
6666 #endif /* USE_X_TOOLKIT */
6669 /* Provide x-toolkit also for GTK. Internally GTK does not use Xt so it
6670 is not an X toolkit in that sense (USE_X_TOOLKIT is not defined).
6671 But for a user it is a toolkit for X, and indeed, configure
6672 accepts --with-x-toolkit=gtk. */
6673 Fprovide (intern_c_string ("x-toolkit"), Qnil
);
6674 Fprovide (intern_c_string ("gtk"), Qnil
);
6675 Fprovide (intern_c_string ("move-toolbar"), Qnil
);
6677 DEFVAR_LISP ("gtk-version-string", Vgtk_version_string
,
6678 doc
: /* Version info for GTK+. */);
6680 char gtk_version
[sizeof ".." + 3 * INT_STRLEN_BOUND (int)];
6681 int len
= sprintf (gtk_version
, "%d.%d.%d",
6682 GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
);
6683 Vgtk_version_string
= make_pure_string (gtk_version
, len
, len
, false);
6685 #endif /* USE_GTK */
6688 Fprovide (intern_c_string ("cairo"), Qnil
);
6690 DEFVAR_LISP ("cairo-version-string", Vcairo_version_string
,
6691 doc
: /* Version info for cairo. */);
6693 char cairo_version
[sizeof ".." + 3 * INT_STRLEN_BOUND (int)];
6694 int len
= sprintf (cairo_version
, "%d.%d.%d",
6695 CAIRO_VERSION_MAJOR
, CAIRO_VERSION_MINOR
,
6696 CAIRO_VERSION_MICRO
);
6697 Vcairo_version_string
= make_pure_string (cairo_version
, len
, len
, false);
6701 /* X window properties. */
6702 defsubr (&Sx_change_window_property
);
6703 defsubr (&Sx_delete_window_property
);
6704 defsubr (&Sx_window_property
);
6706 defsubr (&Sxw_display_color_p
);
6707 defsubr (&Sx_display_grayscale_p
);
6708 defsubr (&Sxw_color_defined_p
);
6709 defsubr (&Sxw_color_values
);
6710 defsubr (&Sx_server_max_request_size
);
6711 defsubr (&Sx_server_vendor
);
6712 defsubr (&Sx_server_version
);
6713 defsubr (&Sx_display_pixel_width
);
6714 defsubr (&Sx_display_pixel_height
);
6715 defsubr (&Sx_display_mm_width
);
6716 defsubr (&Sx_display_mm_height
);
6717 defsubr (&Sx_display_screens
);
6718 defsubr (&Sx_display_planes
);
6719 defsubr (&Sx_display_color_cells
);
6720 defsubr (&Sx_display_visual_class
);
6721 defsubr (&Sx_display_backing_store
);
6722 defsubr (&Sx_display_save_under
);
6723 defsubr (&Sx_display_monitor_attributes_list
);
6724 defsubr (&Sx_frame_geometry
);
6725 defsubr (&Sx_frame_edges
);
6726 defsubr (&Sx_mouse_absolute_pixel_position
);
6727 defsubr (&Sx_set_mouse_absolute_pixel_position
);
6728 defsubr (&Sx_wm_set_size_hint
);
6729 defsubr (&Sx_create_frame
);
6730 defsubr (&Sx_open_connection
);
6731 defsubr (&Sx_close_connection
);
6732 defsubr (&Sx_display_list
);
6733 defsubr (&Sx_synchronize
);
6734 defsubr (&Sx_backspace_delete_keys_p
);
6736 defsubr (&Sx_show_tip
);
6737 defsubr (&Sx_hide_tip
);
6739 staticpro (&tip_timer
);
6741 staticpro (&tip_frame
);
6743 last_show_tip_args
= Qnil
;
6744 staticpro (&last_show_tip_args
);
6746 defsubr (&Sx_uses_old_gtk_dialog
);
6747 #if defined (USE_MOTIF) || defined (USE_GTK)
6748 defsubr (&Sx_file_dialog
);
6751 #if defined (USE_GTK) && defined (HAVE_FREETYPE)
6752 defsubr (&Sx_select_font
);
6756 defsubr (&Sx_export_frames
);
6758 defsubr (&Sx_page_setup_dialog
);
6759 defsubr (&Sx_get_page_setup
);
6760 defsubr (&Sx_print_frames_dialog
);